[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 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 | |
danakj | 6496cba | 2014-10-16 01:31:08 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 8 | #include <set> |
| 9 | |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 10 | #include "cc/animation/layer_animation_controller.h" |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 11 | #include "cc/animation/transform_operations.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 12 | #include "cc/base/math_util.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 13 | #include "cc/layers/content_layer.h" |
| 14 | #include "cc/layers/content_layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 15 | #include "cc/layers/layer.h" |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 16 | #include "cc/layers/layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 17 | #include "cc/layers/layer_impl.h" |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 18 | #include "cc/layers/layer_iterator.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 19 | #include "cc/layers/render_surface.h" |
| 20 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 21 | #include "cc/output/copy_output_request.h" |
| 22 | #include "cc/output/copy_output_result.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 23 | #include "cc/test/animation_test_common.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 24 | #include "cc/test/fake_impl_proxy.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 25 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 26 | #include "cc/test/fake_layer_tree_host_impl.h" |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 27 | #include "cc/test/fake_picture_layer.h" |
| 28 | #include "cc/test/fake_picture_layer_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 29 | #include "cc/test/geometry_test_utils.h" |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 30 | #include "cc/test/layer_tree_host_common_test.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 31 | #include "cc/test/test_task_graph_runner.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 32 | #include "cc/trees/layer_tree_impl.h" |
| 33 | #include "cc/trees/proxy.h" |
| 34 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 35 | #include "testing/gmock/include/gmock/gmock.h" |
| 36 | #include "testing/gtest/include/gtest/gtest.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 37 | #include "ui/gfx/geometry/quad_f.h" |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 38 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 39 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 40 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 41 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 42 | namespace { |
| 43 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 44 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 45 | public: |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 46 | LayerWithForcedDrawsContent() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 47 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 48 | bool DrawsContent() const override; |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 49 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 50 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 51 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 52 | }; |
| 53 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 54 | bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 55 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 56 | class MockContentLayerClient : public ContentLayerClient { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 57 | public: |
| 58 | MockContentLayerClient() {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 59 | ~MockContentLayerClient() override {} |
schenney | 0154bfa | 2015-02-05 19:46:49 | [diff] [blame] | 60 | void PaintContents(SkCanvas* canvas, |
| 61 | const gfx::Rect& clip, |
| 62 | PaintingControlSetting picture_control) override {} |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 63 | scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| 64 | const gfx::Rect& clip, |
schenney | 0154bfa | 2015-02-05 19:46:49 | [diff] [blame] | 65 | PaintingControlSetting picture_control) override { |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 66 | NOTIMPLEMENTED(); |
| 67 | return DisplayItemList::Create(); |
| 68 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 69 | bool FillsBoundsCompletely() const override { return false; } |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 70 | }; |
| 71 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 72 | scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer( |
| 73 | ContentLayerClient* delegate) { |
| 74 | scoped_refptr<FakePictureLayer> to_return = |
| 75 | FakePictureLayer::Create(delegate); |
| 76 | to_return->SetIsDrawable(true); |
| 77 | return to_return; |
| 78 | } |
| 79 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 80 | scoped_refptr<ContentLayer> CreateDrawableContentLayer( |
| 81 | ContentLayerClient* delegate) { |
| 82 | scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate); |
| 83 | to_return->SetIsDrawable(true); |
| 84 | return to_return; |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 85 | } |
| 86 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 87 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 88 | do { \ |
| 89 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 90 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 91 | } while (false) |
| 92 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 93 | #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \ |
| 94 | do { \ |
| 95 | EXPECT_FLOAT_EQ(expected, layer->draw_properties().ideal_contents_scale); \ |
| 96 | } while (false) |
| 97 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 98 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 99 | // Sanity check: For layers positioned at zero, with zero size, |
| 100 | // and with identity transforms, then the draw transform, |
| 101 | // screen space transform, and the hierarchy passed on to children |
| 102 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 103 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 104 | scoped_refptr<Layer> parent = Layer::Create(); |
| 105 | scoped_refptr<Layer> child = Layer::Create(); |
| 106 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 107 | parent->AddChild(child); |
| 108 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 109 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 110 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 111 | host->SetRootLayer(parent); |
| 112 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 113 | gfx::Transform identity_matrix; |
| 114 | SetLayerPropertiesForTesting(parent.get(), |
| 115 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 116 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 117 | gfx::PointF(), |
| 118 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 119 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 120 | false); |
| 121 | SetLayerPropertiesForTesting(child.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(), |
[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(grand_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); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 135 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 136 | ExecuteCalculateDrawProperties(parent.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 137 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 138 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 139 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 140 | child->screen_space_transform()); |
| 141 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 142 | grand_child->draw_transform()); |
| 143 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 144 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 145 | } |
| 146 | |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 147 | TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) { |
| 148 | scoped_refptr<Layer> parent = Layer::Create(); |
| 149 | scoped_refptr<Layer> child = Layer::Create(); |
| 150 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 151 | parent->AddChild(child); |
| 152 | child->AddChild(grand_child); |
| 153 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 154 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 155 | host->SetRootLayer(parent); |
| 156 | |
| 157 | gfx::Transform identity_matrix; |
| 158 | SetLayerPropertiesForTesting(parent.get(), |
| 159 | identity_matrix, |
| 160 | gfx::Point3F(), |
| 161 | gfx::PointF(), |
| 162 | gfx::Size(100, 100), |
| 163 | true, |
| 164 | false); |
| 165 | SetLayerPropertiesForTesting(child.get(), |
| 166 | identity_matrix, |
| 167 | gfx::Point3F(), |
| 168 | gfx::PointF(10, 10), |
| 169 | gfx::Size(100, 100), |
| 170 | true, |
| 171 | false); |
| 172 | // This would have previously caused us to skip our subtree, but this would be |
| 173 | // wrong; we need up-to-date draw properties to do hit testing on the layers |
| 174 | // with handlers. |
| 175 | child->SetOpacity(0.f); |
| 176 | SetLayerPropertiesForTesting(grand_child.get(), |
| 177 | identity_matrix, |
| 178 | gfx::Point3F(), |
| 179 | gfx::PointF(10, 10), |
| 180 | gfx::Size(100, 100), |
| 181 | true, |
| 182 | false); |
| 183 | grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
| 184 | |
| 185 | ExecuteCalculateDrawProperties(parent.get()); |
| 186 | |
| 187 | // Check that we've computed draw properties for the subtree rooted at |
| 188 | // |child|. |
| 189 | EXPECT_FALSE(child->draw_transform().IsIdentity()); |
| 190 | EXPECT_FALSE(grand_child->draw_transform().IsIdentity()); |
| 191 | } |
| 192 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 193 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 194 | gfx::Transform identity_matrix; |
| 195 | scoped_refptr<Layer> layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 196 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 197 | scoped_refptr<Layer> root = Layer::Create(); |
| 198 | SetLayerPropertiesForTesting(root.get(), |
| 199 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 200 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 201 | gfx::PointF(), |
| 202 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 203 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 204 | false); |
| 205 | root->AddChild(layer); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 206 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 207 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 208 | host->SetRootLayer(root); |
| 209 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 210 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 211 | // transform or the screenspace transform. |
| 212 | gfx::Transform translation_to_center; |
| 213 | translation_to_center.Translate(5.0, 6.0); |
| 214 | SetLayerPropertiesForTesting(layer.get(), |
| 215 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 216 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 217 | gfx::PointF(), |
| 218 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 219 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 220 | false); |
| 221 | ExecuteCalculateDrawProperties(root.get()); |
| 222 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 223 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 224 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 225 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 226 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 227 | // no effect on the transforms. |
| 228 | SetLayerPropertiesForTesting(layer.get(), |
| 229 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 230 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 231 | gfx::PointF(), |
| 232 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 233 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 234 | false); |
| 235 | ExecuteCalculateDrawProperties(root.get()); |
| 236 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 237 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 238 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 239 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 240 | // Case 4: A change in actual position affects both the draw transform and |
| 241 | // screen space transform. |
| 242 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 243 | position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 244 | SetLayerPropertiesForTesting(layer.get(), |
| 245 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 246 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 247 | gfx::PointF(0.f, 1.2f), |
| 248 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 249 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 250 | false); |
| 251 | ExecuteCalculateDrawProperties(root.get()); |
| 252 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform()); |
| 253 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, |
| 254 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 255 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 256 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 257 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 258 | // scale transform, because scale and translation are not commutative. |
| 259 | gfx::Transform layer_transform; |
| 260 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 261 | SetLayerPropertiesForTesting(layer.get(), |
| 262 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 263 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 264 | gfx::PointF(), |
| 265 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 266 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 267 | false); |
| 268 | ExecuteCalculateDrawProperties(root.get()); |
| 269 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform()); |
| 270 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, |
| 271 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 272 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 273 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 274 | gfx::Transform translation_to_anchor; |
| 275 | translation_to_anchor.Translate(5.0, 0.0); |
| 276 | gfx::Transform expected_result = |
| 277 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
| 278 | SetLayerPropertiesForTesting(layer.get(), |
| 279 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 280 | gfx::Point3F(5.0f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 281 | gfx::PointF(), |
| 282 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 283 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 284 | false); |
| 285 | ExecuteCalculateDrawProperties(root.get()); |
| 286 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 287 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 288 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 289 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 290 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 291 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 292 | // it is still worth testing to detect accidental regressions. |
| 293 | expected_result = position_transform * translation_to_anchor * |
| 294 | layer_transform * Inverse(translation_to_anchor); |
| 295 | SetLayerPropertiesForTesting(layer.get(), |
| 296 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 297 | gfx::Point3F(5.0f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 298 | gfx::PointF(0.f, 1.2f), |
| 299 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 300 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 301 | false); |
| 302 | ExecuteCalculateDrawProperties(root.get()); |
| 303 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 304 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 305 | layer->screen_space_transform()); |
[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 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 317 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 318 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 319 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 320 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 321 | gfx::Transform identity_matrix; |
| 322 | scoped_ptr<LayerImpl> sublayer_scoped_ptr( |
| 323 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 324 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
| 325 | sublayer->SetContentsScale(kPageScale * kDeviceScale, |
| 326 | kPageScale * kDeviceScale); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 327 | SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(), |
| 328 | gfx::PointF(), gfx::Size(500, 500), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 329 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 330 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 331 | scoped_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 332 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 333 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 334 | SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(), |
| 335 | gfx::PointF(), gfx::Size(10, 20), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 336 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 337 | scoped_ptr<LayerImpl> clip_layer_scoped_ptr( |
| 338 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 339 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 340 | |
| 341 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 342 | clip_layer->SetBounds( |
| 343 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 344 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 345 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 346 | scroll_layer->SetScrollDelta(kScrollDelta); |
| 347 | gfx::Transform impl_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 348 | scroll_layer->AddChild(sublayer_scoped_ptr.Pass()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 349 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
| 350 | clip_layer->AddChild(scroll_layer_scoped_ptr.Pass()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 351 | scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 352 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 353 | scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 354 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 355 | gfx::PointF(), gfx::Size(3, 4), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 356 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 357 | root->AddChild(clip_layer_scoped_ptr.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 358 | root->SetHasRenderSurface(true); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 359 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 360 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 361 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 362 | gfx::Transform expected_transform = identity_matrix; |
| 363 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
| 364 | sub_layer_screen_position.Scale(kPageScale * kDeviceScale); |
| 365 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()), |
| 366 | MathUtil::Round(sub_layer_screen_position.y())); |
| 367 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 368 | sublayer->draw_transform()); |
| 369 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 370 | sublayer->screen_space_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 371 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 372 | gfx::Transform arbitrary_translate; |
| 373 | const float kTranslateX = 10.6f; |
| 374 | const float kTranslateY = 20.6f; |
| 375 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 376 | SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate, |
| 377 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20), |
| 378 | true, false, false); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 379 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 380 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 381 | expected_transform.MakeIdentity(); |
| 382 | expected_transform.Translate( |
| 383 | MathUtil::Round(kTranslateX * kPageScale * kDeviceScale + |
| 384 | sub_layer_screen_position.x()), |
| 385 | MathUtil::Round(kTranslateY * kPageScale * kDeviceScale + |
| 386 | sub_layer_screen_position.y())); |
| 387 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 388 | sublayer->draw_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 389 | } |
| 390 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 391 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 392 | gfx::Transform identity_matrix; |
| 393 | scoped_refptr<Layer> root = Layer::Create(); |
| 394 | scoped_refptr<Layer> parent = Layer::Create(); |
| 395 | scoped_refptr<Layer> child = Layer::Create(); |
| 396 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 397 | root->AddChild(parent); |
| 398 | parent->AddChild(child); |
| 399 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 400 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 401 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 402 | host->SetRootLayer(root); |
| 403 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 404 | // One-time setup of root layer |
| 405 | SetLayerPropertiesForTesting(root.get(), |
| 406 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 407 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 408 | gfx::PointF(), |
| 409 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 410 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 411 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 412 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 413 | // Case 1: parent's anchor point should not affect child or grand_child. |
| 414 | SetLayerPropertiesForTesting(parent.get(), |
| 415 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 416 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 417 | gfx::PointF(), |
| 418 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 419 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 420 | false); |
| 421 | SetLayerPropertiesForTesting(child.get(), |
| 422 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 423 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 424 | gfx::PointF(), |
| 425 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 426 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 427 | false); |
| 428 | SetLayerPropertiesForTesting(grand_child.get(), |
| 429 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 430 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 431 | gfx::PointF(), |
| 432 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 433 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 434 | false); |
| 435 | ExecuteCalculateDrawProperties(root.get()); |
| 436 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 437 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 438 | child->screen_space_transform()); |
| 439 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 440 | grand_child->draw_transform()); |
| 441 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 442 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 443 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 444 | // Case 2: parent's position affects child and grand_child. |
| 445 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 446 | parent_position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 447 | SetLayerPropertiesForTesting(parent.get(), |
| 448 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 449 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 450 | gfx::PointF(0.f, 1.2f), |
| 451 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 452 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 453 | false); |
| 454 | SetLayerPropertiesForTesting(child.get(), |
| 455 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 456 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 457 | gfx::PointF(), |
| 458 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 459 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 460 | false); |
| 461 | SetLayerPropertiesForTesting(grand_child.get(), |
| 462 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 463 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 464 | gfx::PointF(), |
| 465 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 466 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 467 | false); |
| 468 | ExecuteCalculateDrawProperties(root.get()); |
| 469 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 470 | child->draw_transform()); |
| 471 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 472 | child->screen_space_transform()); |
| 473 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 474 | grand_child->draw_transform()); |
| 475 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 476 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 477 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 478 | // Case 3: parent's local transform affects child and grandchild |
| 479 | gfx::Transform parent_layer_transform; |
| 480 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 481 | gfx::Transform parent_translation_to_anchor; |
| 482 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 483 | gfx::Transform parent_composite_transform = |
| 484 | parent_translation_to_anchor * parent_layer_transform * |
| 485 | Inverse(parent_translation_to_anchor); |
| 486 | SetLayerPropertiesForTesting(parent.get(), |
| 487 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 488 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 489 | gfx::PointF(), |
| 490 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 491 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 492 | false); |
| 493 | SetLayerPropertiesForTesting(child.get(), |
| 494 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 495 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 496 | gfx::PointF(), |
| 497 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 498 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 499 | false); |
| 500 | SetLayerPropertiesForTesting(grand_child.get(), |
| 501 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 502 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 503 | gfx::PointF(), |
| 504 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 505 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 506 | false); |
| 507 | ExecuteCalculateDrawProperties(root.get()); |
| 508 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 509 | child->draw_transform()); |
| 510 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 511 | child->screen_space_transform()); |
| 512 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 513 | grand_child->draw_transform()); |
| 514 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 515 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 516 | } |
| 517 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 518 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 519 | scoped_refptr<Layer> root = Layer::Create(); |
| 520 | scoped_refptr<Layer> parent = Layer::Create(); |
| 521 | scoped_refptr<Layer> child = Layer::Create(); |
| 522 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 523 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 524 | root->AddChild(parent); |
| 525 | parent->AddChild(child); |
| 526 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 527 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 528 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 529 | host->SetRootLayer(root); |
| 530 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 531 | // One-time setup of root layer |
| 532 | gfx::Transform identity_matrix; |
| 533 | SetLayerPropertiesForTesting(root.get(), |
| 534 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 535 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 536 | gfx::PointF(), |
| 537 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 538 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 539 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 540 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 541 | // Child is set up so that a new render surface should be created. |
| 542 | child->SetOpacity(0.5f); |
| 543 | child->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 544 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 545 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 546 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 547 | gfx::Transform parent_translation_to_anchor; |
| 548 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 549 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 550 | gfx::Transform parent_composite_transform = |
| 551 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 552 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 553 | gfx::Vector2dF parent_composite_scale = |
| 554 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 555 | 1.f); |
| 556 | gfx::Transform surface_sublayer_transform; |
| 557 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 558 | parent_composite_scale.y()); |
| 559 | gfx::Transform surface_sublayer_composite_transform = |
| 560 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 561 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 562 | // Child's render surface should not exist yet. |
| 563 | ASSERT_FALSE(child->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 564 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 565 | SetLayerPropertiesForTesting(parent.get(), |
| 566 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 567 | gfx::Point3F(25.0f, 30.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 568 | gfx::PointF(), |
| 569 | gfx::Size(100, 120), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 570 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 571 | false); |
| 572 | SetLayerPropertiesForTesting(child.get(), |
| 573 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 574 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 575 | gfx::PointF(), |
| 576 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 577 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 578 | false); |
| 579 | SetLayerPropertiesForTesting(grand_child.get(), |
| 580 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 581 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 582 | gfx::PointF(), |
| 583 | gfx::Size(8, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 584 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 585 | false); |
| 586 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 587 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 588 | // Render surface should have been created now. |
| 589 | ASSERT_TRUE(child->render_surface()); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 590 | ASSERT_EQ(child.get(), child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 591 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 592 | // The child layer's draw transform should refer to its new render surface. |
| 593 | // The screen-space transform, however, should still refer to the root. |
| 594 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
| 595 | child->draw_transform()); |
| 596 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 597 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 598 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 599 | // Because the grand_child is the only drawable content, the child's render |
| 600 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 601 | // surface's subtree is drawn must be removed from the composite transform. |
| 602 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 603 | surface_sublayer_composite_transform, |
| 604 | child->render_target()->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 605 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 606 | // The screen space is the same as the target since the child surface draws |
| 607 | // into the root. |
| 608 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 609 | surface_sublayer_composite_transform, |
| 610 | child->render_target()->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 611 | } |
| 612 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 613 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 614 | scoped_refptr<Layer> root = Layer::Create(); |
| 615 | scoped_refptr<Layer> parent = Layer::Create(); |
| 616 | scoped_refptr<Layer> child = Layer::Create(); |
| 617 | scoped_refptr<Layer> child_replica = Layer::Create(); |
| 618 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 619 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 620 | root->AddChild(parent); |
| 621 | parent->AddChild(child); |
| 622 | child->AddChild(grand_child); |
| 623 | child->SetReplicaLayer(child_replica.get()); |
| 624 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 625 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 626 | host->SetRootLayer(root); |
| 627 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 628 | // One-time setup of root layer |
| 629 | gfx::Transform identity_matrix; |
| 630 | SetLayerPropertiesForTesting(root.get(), |
| 631 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 632 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 633 | gfx::PointF(), |
| 634 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 635 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 636 | false); |
| 637 | |
| 638 | // Child is set up so that a new render surface should be created. |
| 639 | child->SetOpacity(0.5f); |
| 640 | |
| 641 | gfx::Transform parent_layer_transform; |
| 642 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 643 | gfx::Transform parent_translation_to_anchor; |
| 644 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 645 | gfx::Transform parent_composite_transform = |
| 646 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 647 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 648 | gfx::Transform replica_layer_transform; |
| 649 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 650 | gfx::Vector2dF parent_composite_scale = |
| 651 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 652 | 1.f); |
| 653 | gfx::Transform surface_sublayer_transform; |
| 654 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 655 | parent_composite_scale.y()); |
| 656 | gfx::Transform replica_composite_transform = |
| 657 | parent_composite_transform * replica_layer_transform * |
| 658 | Inverse(surface_sublayer_transform); |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 659 | child_replica->SetIsDrawable(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 660 | // Child's render surface should not exist yet. |
| 661 | ASSERT_FALSE(child->render_surface()); |
| 662 | |
| 663 | SetLayerPropertiesForTesting(parent.get(), |
| 664 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 665 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 666 | gfx::PointF(), |
| 667 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 668 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 669 | false); |
| 670 | SetLayerPropertiesForTesting(child.get(), |
| 671 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 672 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 673 | gfx::PointF(), |
| 674 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 675 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 676 | false); |
| 677 | SetLayerPropertiesForTesting(grand_child.get(), |
| 678 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 679 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 680 | gfx::PointF(-0.5f, -0.5f), |
| 681 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 682 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 683 | false); |
| 684 | SetLayerPropertiesForTesting(child_replica.get(), |
| 685 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 686 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 687 | gfx::PointF(), |
| 688 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 689 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 690 | false); |
| 691 | ExecuteCalculateDrawProperties(root.get()); |
| 692 | |
| 693 | // Render surface should have been created now. |
| 694 | ASSERT_TRUE(child->render_surface()); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 695 | ASSERT_EQ(child.get(), child->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 696 | |
| 697 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 698 | replica_composite_transform, |
| 699 | child->render_target()->render_surface()->replica_draw_transform()); |
| 700 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 701 | child->render_target() |
| 702 | ->render_surface() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 703 | ->replica_screen_space_transform()); |
| 704 | } |
| 705 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 706 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 707 | // This test creates a more complex tree and verifies it all at once. This |
| 708 | // covers the following cases: |
| 709 | // - layers that are described w.r.t. a render surface: should have draw |
| 710 | // transforms described w.r.t. that surface |
| 711 | // - A render surface described w.r.t. an ancestor render surface: should |
| 712 | // have a draw transform described w.r.t. that ancestor surface |
| 713 | // - Replicas of a render surface are described w.r.t. the replica's |
| 714 | // transform around its anchor, along with the surface itself. |
| 715 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 716 | // a render surface that is described w.r.t. an ancestor render surface. |
| 717 | // - verifying that each layer has a reference to the correct render surface |
| 718 | // and render target values. |
| 719 | |
| 720 | scoped_refptr<Layer> root = Layer::Create(); |
| 721 | scoped_refptr<Layer> parent = Layer::Create(); |
| 722 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 723 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 724 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 725 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 726 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 727 | scoped_refptr<Layer> replica_of_rs1 = Layer::Create(); |
| 728 | scoped_refptr<Layer> replica_of_rs2 = Layer::Create(); |
| 729 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 730 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 731 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 732 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 733 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 734 | root->AddChild(parent); |
| 735 | parent->AddChild(render_surface1); |
| 736 | parent->AddChild(child_of_root); |
| 737 | render_surface1->AddChild(child_of_rs1); |
| 738 | render_surface1->AddChild(render_surface2); |
| 739 | render_surface2->AddChild(child_of_rs2); |
| 740 | child_of_root->AddChild(grand_child_of_root); |
| 741 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 742 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 743 | render_surface1->SetReplicaLayer(replica_of_rs1.get()); |
| 744 | render_surface2->SetReplicaLayer(replica_of_rs2.get()); |
| 745 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 746 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 747 | host->SetRootLayer(root); |
| 748 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 749 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 750 | // to have a new render surface. |
| 751 | render_surface1->SetOpacity(0.5f); |
| 752 | render_surface2->SetOpacity(0.33f); |
| 753 | |
| 754 | // One-time setup of root layer |
| 755 | gfx::Transform identity_matrix; |
| 756 | SetLayerPropertiesForTesting(root.get(), |
| 757 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 758 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 759 | gfx::PointF(), |
| 760 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 761 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 762 | false); |
| 763 | |
| 764 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 765 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 766 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 767 | gfx::Transform translation_to_anchor; |
| 768 | translation_to_anchor.Translate(2.5, 0.0); |
| 769 | gfx::Transform layer_transform; |
| 770 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 771 | gfx::Transform replica_layer_transform; |
| 772 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 773 | |
| 774 | gfx::Transform A = |
| 775 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 776 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 777 | Inverse(translation_to_anchor); |
| 778 | |
| 779 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 780 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 781 | gfx::Transform surface1_sublayer_transform; |
| 782 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 783 | surface1_parent_transform_scale.y()); |
| 784 | |
| 785 | // SS1 = transform given to the subtree of render_surface1 |
| 786 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 787 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 788 | // the owning layer |
| 789 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 790 | |
| 791 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 792 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 793 | gfx::Transform surface2_sublayer_transform; |
| 794 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 795 | surface2_parent_transform_scale.y()); |
| 796 | |
| 797 | // SS2 = transform given to the subtree of render_surface2 |
| 798 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 799 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 800 | // the owning layer |
| 801 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 802 | |
| 803 | SetLayerPropertiesForTesting(parent.get(), |
| 804 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 805 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 806 | gfx::PointF(), |
| 807 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 808 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 809 | false); |
| 810 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 811 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 812 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 813 | gfx::PointF(), |
| 814 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 815 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 816 | false); |
| 817 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 818 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 819 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 820 | gfx::PointF(), |
| 821 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 822 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 823 | false); |
| 824 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 825 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 826 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 827 | gfx::PointF(), |
| 828 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 829 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 830 | false); |
| 831 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 832 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 833 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 834 | gfx::PointF(), |
| 835 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 836 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 837 | false); |
| 838 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 839 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 840 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 841 | gfx::PointF(), |
| 842 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 843 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 844 | false); |
| 845 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 846 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 847 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 848 | gfx::PointF(), |
| 849 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 850 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 851 | false); |
| 852 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 853 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 854 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 855 | gfx::PointF(), |
| 856 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 857 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 858 | false); |
| 859 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 860 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 861 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 862 | gfx::PointF(), |
| 863 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 864 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 865 | false); |
| 866 | SetLayerPropertiesForTesting(replica_of_rs1.get(), |
| 867 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 868 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 869 | gfx::PointF(), |
| 870 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 871 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 872 | false); |
| 873 | SetLayerPropertiesForTesting(replica_of_rs2.get(), |
| 874 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 875 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 876 | gfx::PointF(), |
| 877 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 878 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 879 | false); |
| 880 | |
| 881 | ExecuteCalculateDrawProperties(root.get()); |
| 882 | |
| 883 | // Only layers that are associated with render surfaces should have an actual |
| 884 | // RenderSurface() value. |
| 885 | ASSERT_TRUE(root->render_surface()); |
| 886 | ASSERT_FALSE(child_of_root->render_surface()); |
| 887 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 888 | |
| 889 | ASSERT_TRUE(render_surface1->render_surface()); |
| 890 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 891 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 892 | |
| 893 | ASSERT_TRUE(render_surface2->render_surface()); |
| 894 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 895 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 896 | |
| 897 | // Verify all render target accessors |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 898 | EXPECT_EQ(root.get(), parent->render_target()); |
| 899 | EXPECT_EQ(root.get(), child_of_root->render_target()); |
| 900 | EXPECT_EQ(root.get(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 901 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 902 | EXPECT_EQ(render_surface1.get(), render_surface1->render_target()); |
| 903 | EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target()); |
| 904 | EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 905 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 906 | EXPECT_EQ(render_surface2.get(), render_surface2->render_target()); |
| 907 | EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target()); |
| 908 | EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 909 | |
| 910 | // Verify layer draw transforms note that draw transforms are described with |
| 911 | // respect to the nearest ancestor render surface but screen space transforms |
| 912 | // are described with respect to the root. |
| 913 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 914 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform()); |
| 915 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 916 | grand_child_of_root->draw_transform()); |
| 917 | |
| 918 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 919 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform()); |
| 920 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 921 | grand_child_of_rs1->draw_transform()); |
| 922 | |
| 923 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 924 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform()); |
| 925 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 926 | grand_child_of_rs2->draw_transform()); |
| 927 | |
| 928 | // Verify layer screen-space transforms |
| 929 | // |
| 930 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 931 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 932 | child_of_root->screen_space_transform()); |
| 933 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 934 | A * A * A, grand_child_of_root->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 935 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 936 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 937 | render_surface1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 938 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 939 | child_of_rs1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 940 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 941 | grand_child_of_rs1->screen_space_transform()); |
| 942 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 943 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 944 | render_surface2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 945 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 946 | child_of_rs2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 947 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 948 | grand_child_of_rs2->screen_space_transform()); |
| 949 | |
| 950 | // Verify render surface transforms. |
| 951 | // |
| 952 | // Draw transform of render surface 1 is described with respect to root. |
| 953 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 954 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 955 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 956 | A * R * S1, render_surface1->render_surface()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 957 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 958 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 959 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 960 | A * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 961 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 962 | // Draw transform of render surface 2 is described with respect to render |
| 963 | // surface 1. |
| 964 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 965 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 966 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 967 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 968 | render_surface2->render_surface()->replica_draw_transform()); |
| 969 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 970 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 971 | render_surface2->render_surface()->screen_space_transform()); |
| 972 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 973 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 974 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 975 | |
| 976 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 977 | // is expected that we correctly set up transforms so that the y-component of |
| 978 | // the screen-space transform encodes the "depth" of the layer in the tree. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 979 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 980 | EXPECT_FLOAT_EQ(2.0, |
| 981 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 982 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 983 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 984 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 985 | EXPECT_FLOAT_EQ(2.0, |
| 986 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 987 | EXPECT_FLOAT_EQ(3.0, |
| 988 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 989 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 990 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 991 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 992 | EXPECT_FLOAT_EQ(3.0, |
| 993 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 994 | EXPECT_FLOAT_EQ(4.0, |
| 995 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 996 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 997 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 998 | } |
| 999 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1000 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1001 | // For layers that flatten their subtree, there should be an orthographic |
| 1002 | // projection (for x and y values) in the middle of the transform sequence. |
| 1003 | // Note that the way the code is currently implemented, it is not expected to |
| 1004 | // use a canonical orthographic projection. |
| 1005 | |
| 1006 | scoped_refptr<Layer> root = Layer::Create(); |
| 1007 | scoped_refptr<Layer> child = Layer::Create(); |
| 1008 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1009 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1010 | scoped_refptr<LayerWithForcedDrawsContent> great_grand_child = |
| 1011 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1012 | |
| 1013 | gfx::Transform rotation_about_y_axis; |
| 1014 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1015 | |
| 1016 | const gfx::Transform identity_matrix; |
| 1017 | SetLayerPropertiesForTesting(root.get(), |
| 1018 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1019 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1020 | gfx::PointF(), |
| 1021 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1022 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1023 | false); |
| 1024 | SetLayerPropertiesForTesting(child.get(), |
| 1025 | rotation_about_y_axis, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1026 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1027 | gfx::PointF(), |
| 1028 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1029 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1030 | false); |
| 1031 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1032 | rotation_about_y_axis, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1033 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1034 | gfx::PointF(), |
| 1035 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1036 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1037 | false); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1038 | SetLayerPropertiesForTesting(great_grand_child.get(), identity_matrix, |
| 1039 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1040 | true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1041 | |
| 1042 | root->AddChild(child); |
| 1043 | child->AddChild(grand_child); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1044 | grand_child->AddChild(great_grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1045 | child->SetForceRenderSurface(true); |
| 1046 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1047 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1048 | host->SetRootLayer(root); |
| 1049 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1050 | // No layers in this test should preserve 3d. |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1051 | ASSERT_TRUE(root->should_flatten_transform()); |
| 1052 | ASSERT_TRUE(child->should_flatten_transform()); |
| 1053 | ASSERT_TRUE(grand_child->should_flatten_transform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1054 | ASSERT_TRUE(great_grand_child->should_flatten_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1055 | |
| 1056 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1057 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1058 | gfx::Transform expected_grand_child_draw_transform = |
| 1059 | rotation_about_y_axis; // draws onto child's render surface |
| 1060 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1061 | flattened_rotation_about_y.FlattenTo2d(); |
| 1062 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1063 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1064 | gfx::Transform expected_great_grand_child_draw_transform = |
| 1065 | flattened_rotation_about_y; |
| 1066 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 1067 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1068 | |
| 1069 | ExecuteCalculateDrawProperties(root.get()); |
| 1070 | |
| 1071 | // The child's draw transform should have been taken by its surface. |
| 1072 | ASSERT_TRUE(child->render_surface()); |
| 1073 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1074 | child->render_surface()->draw_transform()); |
| 1075 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1076 | expected_child_screen_space_transform, |
| 1077 | child->render_surface()->screen_space_transform()); |
| 1078 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1079 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
| 1080 | child->screen_space_transform()); |
| 1081 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
| 1082 | grand_child->draw_transform()); |
| 1083 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
| 1084 | grand_child->screen_space_transform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1085 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
| 1086 | great_grand_child->draw_transform()); |
| 1087 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1088 | expected_great_grand_child_screen_space_transform, |
| 1089 | great_grand_child->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1090 | } |
| 1091 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1092 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1093 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1094 | // skipping a necessary translation. Without that translation, the coordinate |
| 1095 | // space of the layer's draw transform is incorrect. |
| 1096 | // |
| 1097 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1098 | // but if that layer becomes a render surface, then its draw transform is |
| 1099 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1100 | // incorrectly as a result. |
| 1101 | |
| 1102 | scoped_refptr<Layer> root = Layer::Create(); |
| 1103 | scoped_refptr<Layer> child = Layer::Create(); |
| 1104 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1105 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1106 | |
| 1107 | // The child height is zero, but has non-zero width that should be accounted |
| 1108 | // for while computing draw transforms. |
| 1109 | const gfx::Transform identity_matrix; |
| 1110 | SetLayerPropertiesForTesting(root.get(), |
| 1111 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1112 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1113 | gfx::PointF(), |
| 1114 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1115 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1116 | false); |
| 1117 | SetLayerPropertiesForTesting(child.get(), |
| 1118 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1119 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1120 | gfx::PointF(), |
| 1121 | gfx::Size(10, 0), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1122 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1123 | false); |
| 1124 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1125 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1126 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1127 | gfx::PointF(), |
| 1128 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1129 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1130 | false); |
| 1131 | |
| 1132 | root->AddChild(child); |
| 1133 | child->AddChild(grand_child); |
| 1134 | child->SetForceRenderSurface(true); |
| 1135 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1136 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1137 | host->SetRootLayer(root); |
| 1138 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1139 | ExecuteCalculateDrawProperties(root.get()); |
| 1140 | |
| 1141 | ASSERT_TRUE(child->render_surface()); |
| 1142 | // This is the real test, the rest are sanity checks. |
| 1143 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1144 | child->render_surface()->draw_transform()); |
| 1145 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1146 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1147 | grand_child->draw_transform()); |
| 1148 | } |
| 1149 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1150 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1151 | // Transformations applied at the root of the tree should be forwarded |
| 1152 | // to child layers instead of applied to the root RenderSurface. |
| 1153 | const gfx::Transform identity_matrix; |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1154 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 1155 | new LayerWithForcedDrawsContent; |
| 1156 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1157 | new LayerWithForcedDrawsContent; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1158 | child->SetScrollClipLayerId(root->id()); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1159 | root->AddChild(child); |
| 1160 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1161 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1162 | host->SetRootLayer(root); |
| 1163 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1164 | SetLayerPropertiesForTesting(root.get(), |
| 1165 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1166 | gfx::Point3F(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1167 | gfx::PointF(), |
| 1168 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1169 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1170 | false); |
| 1171 | SetLayerPropertiesForTesting(child.get(), |
| 1172 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1173 | gfx::Point3F(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1174 | gfx::PointF(), |
| 1175 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1176 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1177 | false); |
| 1178 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1179 | gfx::Transform translate; |
| 1180 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1181 | { |
| 1182 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1183 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1184 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1185 | inputs.can_adjust_raster_scales = true; |
| 1186 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1187 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1188 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1189 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1190 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1191 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1192 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1193 | |
| 1194 | gfx::Transform scale; |
| 1195 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1196 | { |
| 1197 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1198 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1199 | root.get(), root->bounds(), scale, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1200 | inputs.can_adjust_raster_scales = true; |
| 1201 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1202 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1203 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1204 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1205 | EXPECT_EQ(2.f, root->draw_properties().device_scale_factor); |
| 1206 | EXPECT_EQ(2.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1207 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1208 | |
| 1209 | gfx::Transform rotate; |
| 1210 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1211 | { |
| 1212 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1213 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1214 | root.get(), root->bounds(), rotate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1215 | inputs.can_adjust_raster_scales = true; |
| 1216 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1217 | EXPECT_EQ(rotate, root->draw_properties().target_space_transform); |
| 1218 | EXPECT_EQ(rotate, child->draw_properties().target_space_transform); |
| 1219 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1220 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1221 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1222 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1223 | |
| 1224 | gfx::Transform composite; |
| 1225 | composite.ConcatTransform(translate); |
| 1226 | composite.ConcatTransform(scale); |
| 1227 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1228 | { |
| 1229 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1230 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1231 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1232 | inputs.can_adjust_raster_scales = true; |
| 1233 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1234 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1235 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1236 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1237 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1238 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1239 | // Verify it composes correctly with device scale. |
| 1240 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1241 | |
| 1242 | { |
| 1243 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1244 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1245 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1246 | inputs.device_scale_factor = device_scale_factor; |
| 1247 | inputs.can_adjust_raster_scales = true; |
| 1248 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1249 | gfx::Transform device_scaled_translate = translate; |
| 1250 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1251 | EXPECT_EQ(device_scaled_translate, |
| 1252 | root->draw_properties().target_space_transform); |
| 1253 | EXPECT_EQ(device_scaled_translate, |
| 1254 | child->draw_properties().target_space_transform); |
| 1255 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1256 | EXPECT_EQ(device_scale_factor, root->draw_properties().device_scale_factor); |
| 1257 | EXPECT_EQ(device_scale_factor, |
| 1258 | child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1259 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1260 | |
| 1261 | // Verify it composes correctly with page scale. |
| 1262 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1263 | |
| 1264 | { |
| 1265 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1266 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1267 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1268 | inputs.page_scale_factor = page_scale_factor; |
| 1269 | inputs.page_scale_application_layer = root.get(); |
| 1270 | inputs.can_adjust_raster_scales = true; |
| 1271 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1272 | gfx::Transform page_scaled_translate = translate; |
| 1273 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
| 1274 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1275 | EXPECT_EQ(page_scaled_translate, |
| 1276 | child->draw_properties().target_space_transform); |
| 1277 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1278 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1279 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1280 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1281 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1282 | // Verify that it composes correctly with transforms directly on root layer. |
| 1283 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1284 | |
| 1285 | { |
| 1286 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1287 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1288 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1289 | inputs.can_adjust_raster_scales = true; |
| 1290 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1291 | gfx::Transform compositeSquared = composite; |
| 1292 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1293 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1294 | compositeSquared, root->draw_properties().target_space_transform); |
| 1295 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1296 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1297 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1298 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1299 | } |
| 1300 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1301 | TEST_F(LayerTreeHostCommonTest, |
| 1302 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1303 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1304 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1305 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1306 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1307 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1308 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1309 | host->SetRootLayer(parent); |
| 1310 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1311 | const gfx::Transform identity_matrix; |
| 1312 | SetLayerPropertiesForTesting(parent.get(), |
| 1313 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1314 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1315 | gfx::PointF(), |
| 1316 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1317 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1318 | false); |
| 1319 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1320 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1321 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1322 | gfx::PointF(), |
| 1323 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1324 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1325 | false); |
| 1326 | SetLayerPropertiesForTesting(child.get(), |
| 1327 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1328 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1329 | gfx::PointF(30.f, 30.f), |
| 1330 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1331 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1332 | false); |
| 1333 | |
| 1334 | parent->AddChild(render_surface1); |
| 1335 | parent->SetMasksToBounds(true); |
| 1336 | render_surface1->AddChild(child); |
| 1337 | render_surface1->SetForceRenderSurface(true); |
| 1338 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1339 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1340 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1341 | parent.get(), |
| 1342 | parent->bounds(), |
| 1343 | gfx::Transform(), |
| 1344 | &render_surface_layer_list); |
| 1345 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1346 | |
| 1347 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1348 | // the intermediate render surface should not be listed here, even if it was |
| 1349 | // forced to be created. Render surfaces without children or visible content |
| 1350 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1351 | // of size 0). |
| 1352 | ASSERT_TRUE(parent->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1353 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1354 | } |
| 1355 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1356 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1357 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1358 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1359 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1360 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1361 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1362 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1363 | host->SetRootLayer(parent); |
| 1364 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1365 | const gfx::Transform identity_matrix; |
| 1366 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1367 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1368 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1369 | gfx::PointF(), |
| 1370 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1371 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1372 | false); |
| 1373 | SetLayerPropertiesForTesting(child.get(), |
| 1374 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1375 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1376 | gfx::PointF(), |
| 1377 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1378 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1379 | false); |
| 1380 | |
| 1381 | parent->AddChild(render_surface1); |
| 1382 | render_surface1->AddChild(child); |
| 1383 | render_surface1->SetForceRenderSurface(true); |
| 1384 | render_surface1->SetOpacity(0.f); |
| 1385 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1386 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1387 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1388 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1389 | inputs.can_adjust_raster_scales = true; |
| 1390 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1391 | |
| 1392 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1393 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1394 | // have been extended by the children. |
| 1395 | ASSERT_TRUE(parent->render_surface()); |
| 1396 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1397 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1398 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1399 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1400 | } |
| 1401 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1402 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
| 1403 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1404 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1405 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1406 | |
| 1407 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 1408 | host->SetRootLayer(parent); |
| 1409 | |
| 1410 | const gfx::Transform identity_matrix; |
| 1411 | const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode; |
| 1412 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 1413 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1414 | |
| 1415 | parent->AddChild(child); |
| 1416 | child->SetBlendMode(blend_mode); |
| 1417 | |
| 1418 | RenderSurfaceLayerList render_surface_layer_list; |
| 1419 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1420 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1421 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 1422 | |
| 1423 | // Since the child layer has a blend mode other than normal, it should get |
| 1424 | // its own render surface. Also, layer's draw_properties should contain the |
| 1425 | // default blend mode, since the render surface becomes responsible for |
| 1426 | // applying the blend mode. |
| 1427 | ASSERT_TRUE(child->render_surface()); |
| 1428 | EXPECT_EQ(1U, child->render_surface()->layer_list().size()); |
| 1429 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_properties().blend_mode); |
| 1430 | } |
| 1431 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1432 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1433 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1434 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1435 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1436 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1437 | render_surface1->SetForceRenderSurface(true); |
| 1438 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1439 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1440 | host->SetRootLayer(parent); |
| 1441 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1442 | const gfx::Transform identity_matrix; |
| 1443 | SetLayerPropertiesForTesting(parent.get(), |
| 1444 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1445 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1446 | gfx::PointF(), |
| 1447 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1448 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1449 | false); |
| 1450 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1451 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1452 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1453 | gfx::PointF(), |
| 1454 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1455 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1456 | false); |
| 1457 | SetLayerPropertiesForTesting(child.get(), |
| 1458 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1459 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1460 | gfx::PointF(), |
| 1461 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1462 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1463 | false); |
| 1464 | |
| 1465 | parent->AddChild(render_surface1); |
| 1466 | render_surface1->AddChild(child); |
| 1467 | |
| 1468 | // Sanity check before the actual test |
| 1469 | EXPECT_FALSE(parent->render_surface()); |
| 1470 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1471 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1472 | { |
| 1473 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1474 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1475 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1476 | inputs.can_adjust_raster_scales = true; |
| 1477 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1478 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1479 | // The root layer always creates a render surface |
| 1480 | EXPECT_TRUE(parent->render_surface()); |
| 1481 | EXPECT_TRUE(render_surface1->render_surface()); |
| 1482 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1483 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1484 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1485 | { |
| 1486 | RenderSurfaceLayerList render_surface_layer_list; |
| 1487 | render_surface1->SetForceRenderSurface(false); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1488 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1489 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1490 | inputs.can_adjust_raster_scales = true; |
| 1491 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1492 | EXPECT_TRUE(parent->render_surface()); |
| 1493 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1494 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1495 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1496 | } |
| 1497 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1498 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1499 | // Render surfaces act as a flattening point for their subtree, so should |
| 1500 | // always flatten the target-to-screen space transform seen by descendants. |
| 1501 | |
| 1502 | scoped_refptr<Layer> root = Layer::Create(); |
| 1503 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1504 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1505 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1506 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1507 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1508 | |
| 1509 | gfx::Transform rotation_about_y_axis; |
| 1510 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1511 | // Make |parent| have a render surface. |
| 1512 | parent->SetOpacity(0.9f); |
| 1513 | |
| 1514 | const gfx::Transform identity_matrix; |
| 1515 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 1516 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 1517 | SetLayerPropertiesForTesting(parent.get(), rotation_about_y_axis, |
| 1518 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1519 | true, false); |
| 1520 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 1521 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1522 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 1523 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1524 | true, false); |
| 1525 | |
| 1526 | root->AddChild(parent); |
| 1527 | parent->AddChild(child); |
| 1528 | child->AddChild(grand_child); |
| 1529 | |
| 1530 | grand_child->SetShouldFlattenTransform(false); |
| 1531 | |
| 1532 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 1533 | host->SetRootLayer(root); |
| 1534 | |
| 1535 | // Only grand_child should preserve 3d. |
| 1536 | EXPECT_TRUE(root->should_flatten_transform()); |
| 1537 | EXPECT_TRUE(parent->should_flatten_transform()); |
| 1538 | EXPECT_TRUE(child->should_flatten_transform()); |
| 1539 | EXPECT_FALSE(grand_child->should_flatten_transform()); |
| 1540 | |
| 1541 | gfx::Transform expected_child_draw_transform = identity_matrix; |
| 1542 | gfx::Transform expected_grand_child_draw_transform = identity_matrix; |
| 1543 | |
| 1544 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1545 | flattened_rotation_about_y.FlattenTo2d(); |
| 1546 | |
| 1547 | ExecuteCalculateDrawProperties(root.get()); |
| 1548 | |
| 1549 | EXPECT_TRUE(parent->render_surface()); |
| 1550 | EXPECT_FALSE(child->render_surface()); |
| 1551 | EXPECT_FALSE(grand_child->render_surface()); |
| 1552 | |
| 1553 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1554 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1555 | grand_child->draw_transform()); |
| 1556 | |
| 1557 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1558 | // have been flattened at their render target. In particular, the fact that |
| 1559 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
| 1560 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
| 1561 | child->screen_space_transform()); |
| 1562 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
| 1563 | grand_child->screen_space_transform()); |
| 1564 | } |
| 1565 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1566 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1567 | // The entire subtree of layers that are outside the clip rect should be |
| 1568 | // culled away, and should not affect the render_surface_layer_list. |
| 1569 | // |
| 1570 | // The test tree is set up as follows: |
| 1571 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1572 | // that have something to draw. |
| 1573 | // - parent is a large container layer. |
| 1574 | // - child has masksToBounds=true to cause clipping. |
| 1575 | // - grand_child is positioned outside of the child's bounds |
| 1576 | // - great_grand_child is also kept outside child's bounds. |
| 1577 | // |
| 1578 | // In this configuration, grand_child and great_grand_child are completely |
| 1579 | // outside the clip rect, and they should never get scheduled on the list of |
| 1580 | // render surfaces. |
| 1581 | // |
| 1582 | |
| 1583 | const gfx::Transform identity_matrix; |
| 1584 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1585 | scoped_refptr<Layer> child = Layer::Create(); |
| 1586 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1587 | scoped_refptr<Layer> great_grand_child = Layer::Create(); |
| 1588 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1589 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1590 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1591 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1592 | parent->AddChild(child); |
| 1593 | child->AddChild(grand_child); |
| 1594 | grand_child->AddChild(great_grand_child); |
| 1595 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1596 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1597 | host->SetRootLayer(parent); |
| 1598 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1599 | // leaf_node1 ensures that parent and child are kept on the |
| 1600 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1601 | // should be clipped. |
| 1602 | child->AddChild(leaf_node1); |
| 1603 | great_grand_child->AddChild(leaf_node2); |
| 1604 | |
| 1605 | SetLayerPropertiesForTesting(parent.get(), |
| 1606 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1607 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1608 | gfx::PointF(), |
| 1609 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1610 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1611 | false); |
| 1612 | SetLayerPropertiesForTesting(child.get(), |
| 1613 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1614 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1615 | gfx::PointF(), |
| 1616 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1617 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1618 | false); |
| 1619 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1620 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1621 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1622 | gfx::PointF(45.f, 45.f), |
| 1623 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1624 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1625 | false); |
| 1626 | SetLayerPropertiesForTesting(great_grand_child.get(), |
| 1627 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1628 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1629 | gfx::PointF(), |
| 1630 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1631 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1632 | false); |
| 1633 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1634 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1635 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1636 | gfx::PointF(), |
| 1637 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1638 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1639 | false); |
| 1640 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1641 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1642 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1643 | gfx::PointF(), |
| 1644 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1645 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1646 | false); |
| 1647 | |
| 1648 | child->SetMasksToBounds(true); |
| 1649 | child->SetOpacity(0.4f); |
| 1650 | child->SetForceRenderSurface(true); |
| 1651 | grand_child->SetOpacity(0.5f); |
| 1652 | great_grand_child->SetOpacity(0.4f); |
| 1653 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1654 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1655 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1656 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1657 | inputs.can_adjust_raster_scales = true; |
| 1658 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1659 | |
| 1660 | ASSERT_EQ(2U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1661 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1662 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1663 | } |
| 1664 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1665 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1666 | // When a render surface has a clip rect, it is used to clip the content rect |
| 1667 | // of the surface. When the render surface is animating its transforms, then |
| 1668 | // the content rect's position in the clip rect is not defined on the main |
| 1669 | // thread, and its content rect should not be clipped. |
| 1670 | |
| 1671 | // The test tree is set up as follows: |
| 1672 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1673 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1674 | // the parent. |
| 1675 | // - grand_child is a render surface, and the only visible content in child. |
| 1676 | // It is positioned outside of the clip rect from parent. |
| 1677 | |
| 1678 | // In this configuration, grand_child should be outside the clipped |
| 1679 | // content rect of the child, making grand_child not appear in the |
| 1680 | // render_surface_layer_list. However, when we place an animation on the |
| 1681 | // child, this clipping should be avoided and we should keep the grand_child |
| 1682 | // in the render_surface_layer_list. |
| 1683 | |
| 1684 | const gfx::Transform identity_matrix; |
| 1685 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1686 | scoped_refptr<Layer> child = Layer::Create(); |
| 1687 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1688 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node = |
| 1689 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1690 | parent->AddChild(child); |
| 1691 | child->AddChild(grand_child); |
| 1692 | grand_child->AddChild(leaf_node); |
| 1693 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1694 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1695 | host->SetRootLayer(parent); |
| 1696 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1697 | SetLayerPropertiesForTesting(parent.get(), |
| 1698 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1699 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1700 | gfx::PointF(), |
| 1701 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1702 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1703 | false); |
| 1704 | SetLayerPropertiesForTesting(child.get(), |
| 1705 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1706 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1707 | gfx::PointF(), |
| 1708 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1709 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1710 | false); |
| 1711 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1712 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1713 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1714 | gfx::PointF(200.f, 200.f), |
| 1715 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1716 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1717 | false); |
| 1718 | SetLayerPropertiesForTesting(leaf_node.get(), |
| 1719 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1720 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1721 | gfx::PointF(), |
| 1722 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1723 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1724 | false); |
| 1725 | |
| 1726 | parent->SetMasksToBounds(true); |
| 1727 | child->SetOpacity(0.4f); |
| 1728 | child->SetForceRenderSurface(true); |
| 1729 | grand_child->SetOpacity(0.4f); |
| 1730 | grand_child->SetForceRenderSurface(true); |
| 1731 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1732 | { |
| 1733 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1734 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1735 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1736 | inputs.can_adjust_raster_scales = true; |
| 1737 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1738 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1739 | // Without an animation, we should cull child and grand_child from the |
| 1740 | // render_surface_layer_list. |
| 1741 | ASSERT_EQ(1U, render_surface_layer_list.size()); |
| 1742 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1743 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1744 | |
| 1745 | // Now put an animating transform on child. |
| 1746 | AddAnimatedTransformToController( |
| 1747 | child->layer_animation_controller(), 10.0, 30, 0); |
| 1748 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1749 | { |
| 1750 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1751 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1752 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1753 | inputs.can_adjust_raster_scales = true; |
| 1754 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1755 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1756 | // With an animating transform, we should keep child and grand_child in the |
| 1757 | // render_surface_layer_list. |
| 1758 | ASSERT_EQ(3U, render_surface_layer_list.size()); |
| 1759 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1760 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
| 1761 | EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id()); |
| 1762 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1763 | } |
| 1764 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1765 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1766 | // Layer's IsClipped() property is set to true when: |
| 1767 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1768 | // - the layer is clipped by an ancestor that contributes to the same |
| 1769 | // render target, |
| 1770 | // - a surface is clipped by an ancestor that contributes to the same |
| 1771 | // render target. |
| 1772 | // |
| 1773 | // In particular, for a layer that owns a render surface: |
| 1774 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1775 | // pass that clipped status to the layer itself. |
| 1776 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1777 | // and propagates the clip to the subtree. |
| 1778 | |
| 1779 | const gfx::Transform identity_matrix; |
| 1780 | scoped_refptr<Layer> root = Layer::Create(); |
| 1781 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1782 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 1783 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 1784 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1785 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1786 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1787 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1788 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1789 | root->AddChild(parent); |
| 1790 | parent->AddChild(child1); |
| 1791 | parent->AddChild(child2); |
| 1792 | child1->AddChild(grand_child); |
| 1793 | child2->AddChild(leaf_node2); |
| 1794 | grand_child->AddChild(leaf_node1); |
| 1795 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1796 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1797 | host->SetRootLayer(root); |
| 1798 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1799 | child2->SetForceRenderSurface(true); |
| 1800 | |
| 1801 | SetLayerPropertiesForTesting(root.get(), |
| 1802 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1803 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1804 | gfx::PointF(), |
| 1805 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1806 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1807 | false); |
| 1808 | SetLayerPropertiesForTesting(parent.get(), |
| 1809 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1810 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1811 | gfx::PointF(), |
| 1812 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1813 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1814 | false); |
| 1815 | SetLayerPropertiesForTesting(child1.get(), |
| 1816 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1817 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1818 | gfx::PointF(), |
| 1819 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1820 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1821 | false); |
| 1822 | SetLayerPropertiesForTesting(child2.get(), |
| 1823 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1824 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1825 | gfx::PointF(), |
| 1826 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1827 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1828 | false); |
| 1829 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1830 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1831 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1832 | gfx::PointF(), |
| 1833 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1834 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1835 | false); |
| 1836 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1837 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1838 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1839 | gfx::PointF(), |
| 1840 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1841 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1842 | false); |
| 1843 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1844 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1845 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1846 | gfx::PointF(), |
| 1847 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1848 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1849 | false); |
| 1850 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1851 | // Case 1: nothing is clipped except the root render surface. |
| 1852 | { |
| 1853 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1854 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1855 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1856 | inputs.can_adjust_raster_scales = true; |
| 1857 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1858 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1859 | ASSERT_TRUE(root->render_surface()); |
| 1860 | ASSERT_TRUE(child2->render_surface()); |
| 1861 | |
| 1862 | EXPECT_FALSE(root->is_clipped()); |
| 1863 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1864 | EXPECT_FALSE(parent->is_clipped()); |
| 1865 | EXPECT_FALSE(child1->is_clipped()); |
| 1866 | EXPECT_FALSE(child2->is_clipped()); |
| 1867 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1868 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1869 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1870 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1871 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1872 | |
| 1873 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1874 | // surface are clipped. But layers that contribute to child2's surface are |
| 1875 | // not clipped explicitly because child2's surface already accounts for |
| 1876 | // that clip. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1877 | { |
| 1878 | RenderSurfaceLayerList render_surface_layer_list; |
| 1879 | parent->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1880 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1881 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1882 | inputs.can_adjust_raster_scales = true; |
| 1883 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1884 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1885 | ASSERT_TRUE(root->render_surface()); |
| 1886 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1887 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1888 | EXPECT_FALSE(root->is_clipped()); |
| 1889 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1890 | EXPECT_TRUE(parent->is_clipped()); |
| 1891 | EXPECT_TRUE(child1->is_clipped()); |
| 1892 | EXPECT_FALSE(child2->is_clipped()); |
| 1893 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1894 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1895 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1896 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1897 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1898 | |
| 1899 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1900 | // child2's render surface is not clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1901 | { |
| 1902 | RenderSurfaceLayerList render_surface_layer_list; |
| 1903 | parent->SetMasksToBounds(false); |
| 1904 | child2->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1905 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1906 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1907 | inputs.can_adjust_raster_scales = true; |
| 1908 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1909 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1910 | ASSERT_TRUE(root->render_surface()); |
| 1911 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1912 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1913 | EXPECT_FALSE(root->is_clipped()); |
| 1914 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1915 | EXPECT_FALSE(parent->is_clipped()); |
| 1916 | EXPECT_FALSE(child1->is_clipped()); |
| 1917 | EXPECT_TRUE(child2->is_clipped()); |
| 1918 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1919 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1920 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1921 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1922 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1923 | } |
| 1924 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 1925 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1926 | // Verify that layers get the appropriate DrawableContentRect when their |
| 1927 | // parent masksToBounds is true. |
| 1928 | // |
| 1929 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 1930 | // be the layer rect expressed in target space. |
| 1931 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 1932 | // will be the intersection of layer bounds and the mask region. |
| 1933 | // grand_child3 - partially clipped and masksToBounds; the |
| 1934 | // DrawableContentRect will still be the intersection of layer bounds and |
| 1935 | // the mask region. |
| 1936 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 1937 | // be empty. |
| 1938 | // |
| 1939 | |
| 1940 | const gfx::Transform identity_matrix; |
| 1941 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1942 | scoped_refptr<Layer> child = Layer::Create(); |
| 1943 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 1944 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 1945 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 1946 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 1947 | |
| 1948 | parent->AddChild(child); |
| 1949 | child->AddChild(grand_child1); |
| 1950 | child->AddChild(grand_child2); |
| 1951 | child->AddChild(grand_child3); |
| 1952 | child->AddChild(grand_child4); |
| 1953 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1954 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1955 | host->SetRootLayer(parent); |
| 1956 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1957 | SetLayerPropertiesForTesting(parent.get(), |
| 1958 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1959 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1960 | gfx::PointF(), |
| 1961 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1962 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1963 | false); |
| 1964 | SetLayerPropertiesForTesting(child.get(), |
| 1965 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1966 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1967 | gfx::PointF(), |
| 1968 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1969 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1970 | false); |
| 1971 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 1972 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1973 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1974 | gfx::PointF(5.f, 5.f), |
| 1975 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1976 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1977 | false); |
| 1978 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 1979 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1980 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1981 | gfx::PointF(15.f, 15.f), |
| 1982 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1983 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1984 | false); |
| 1985 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 1986 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1987 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1988 | gfx::PointF(15.f, 15.f), |
| 1989 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1990 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1991 | false); |
| 1992 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 1993 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1994 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1995 | gfx::PointF(45.f, 45.f), |
| 1996 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1997 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1998 | false); |
| 1999 | |
| 2000 | child->SetMasksToBounds(true); |
| 2001 | grand_child3->SetMasksToBounds(true); |
| 2002 | |
| 2003 | // Force everyone to be a render surface. |
| 2004 | child->SetOpacity(0.4f); |
| 2005 | grand_child1->SetOpacity(0.5f); |
| 2006 | grand_child2->SetOpacity(0.5f); |
| 2007 | grand_child3->SetOpacity(0.5f); |
| 2008 | grand_child4->SetOpacity(0.5f); |
| 2009 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2010 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2011 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2012 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2013 | inputs.can_adjust_raster_scales = true; |
| 2014 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2015 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2016 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 2017 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 2018 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2019 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2020 | } |
| 2021 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2022 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2023 | // Verify that render surfaces (and their layers) get the appropriate |
| 2024 | // clip rects when their parent masksToBounds is true. |
| 2025 | // |
| 2026 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2027 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2028 | // They may still have a clip rect of their own layer bounds, however, if |
| 2029 | // masksToBounds was true. |
| 2030 | const gfx::Transform identity_matrix; |
| 2031 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2032 | scoped_refptr<Layer> child = Layer::Create(); |
| 2033 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 2034 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 2035 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 2036 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 2037 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 2038 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2039 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 2040 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2041 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 = |
| 2042 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2043 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 = |
| 2044 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2045 | |
| 2046 | parent->AddChild(child); |
| 2047 | child->AddChild(grand_child1); |
| 2048 | child->AddChild(grand_child2); |
| 2049 | child->AddChild(grand_child3); |
| 2050 | child->AddChild(grand_child4); |
| 2051 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2052 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2053 | host->SetRootLayer(parent); |
| 2054 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2055 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 2056 | // this test. |
| 2057 | grand_child1->AddChild(leaf_node1); |
| 2058 | grand_child2->AddChild(leaf_node2); |
| 2059 | grand_child3->AddChild(leaf_node3); |
| 2060 | grand_child4->AddChild(leaf_node4); |
| 2061 | |
| 2062 | SetLayerPropertiesForTesting(parent.get(), |
| 2063 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2064 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2065 | gfx::PointF(), |
| 2066 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2067 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2068 | false); |
| 2069 | SetLayerPropertiesForTesting(child.get(), |
| 2070 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2071 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2072 | gfx::PointF(), |
| 2073 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2074 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2075 | false); |
| 2076 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2077 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2078 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2079 | gfx::PointF(5.f, 5.f), |
| 2080 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2081 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2082 | false); |
| 2083 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2084 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2085 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2086 | gfx::PointF(15.f, 15.f), |
| 2087 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2088 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2089 | false); |
| 2090 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2091 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2092 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2093 | gfx::PointF(15.f, 15.f), |
| 2094 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2095 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2096 | false); |
| 2097 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2098 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2099 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2100 | gfx::PointF(45.f, 45.f), |
| 2101 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2102 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2103 | false); |
| 2104 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 2105 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2106 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2107 | gfx::PointF(), |
| 2108 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2109 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2110 | false); |
| 2111 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 2112 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2113 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2114 | gfx::PointF(), |
| 2115 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2116 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2117 | false); |
| 2118 | SetLayerPropertiesForTesting(leaf_node3.get(), |
| 2119 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2120 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2121 | gfx::PointF(), |
| 2122 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2123 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2124 | false); |
| 2125 | SetLayerPropertiesForTesting(leaf_node4.get(), |
| 2126 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2127 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2128 | gfx::PointF(), |
| 2129 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2130 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2131 | false); |
| 2132 | |
| 2133 | child->SetMasksToBounds(true); |
| 2134 | grand_child3->SetMasksToBounds(true); |
| 2135 | grand_child4->SetMasksToBounds(true); |
| 2136 | |
| 2137 | // Force everyone to be a render surface. |
| 2138 | child->SetOpacity(0.4f); |
| 2139 | child->SetForceRenderSurface(true); |
| 2140 | grand_child1->SetOpacity(0.5f); |
| 2141 | grand_child1->SetForceRenderSurface(true); |
| 2142 | grand_child2->SetOpacity(0.5f); |
| 2143 | grand_child2->SetForceRenderSurface(true); |
| 2144 | grand_child3->SetOpacity(0.5f); |
| 2145 | grand_child3->SetForceRenderSurface(true); |
| 2146 | grand_child4->SetOpacity(0.5f); |
| 2147 | grand_child4->SetForceRenderSurface(true); |
| 2148 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2149 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2150 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2151 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2152 | inputs.can_adjust_raster_scales = true; |
| 2153 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2154 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2155 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2156 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2157 | |
| 2158 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2159 | // masksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2160 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2161 | grand_child1->render_surface()->clip_rect()); |
| 2162 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2163 | grand_child2->render_surface()->clip_rect()); |
| 2164 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2165 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2166 | } |
| 2167 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2168 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2169 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2170 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2171 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 2172 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 2173 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 2174 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 2175 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 2176 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 2177 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2178 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 2179 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2180 | parent->AddChild(render_surface1); |
| 2181 | parent->AddChild(child_of_root); |
| 2182 | render_surface1->AddChild(child_of_rs1); |
| 2183 | render_surface1->AddChild(render_surface2); |
| 2184 | render_surface2->AddChild(child_of_rs2); |
| 2185 | child_of_root->AddChild(grand_child_of_root); |
| 2186 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 2187 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 2188 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2189 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2190 | host->SetRootLayer(parent); |
| 2191 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2192 | // Make our render surfaces. |
| 2193 | render_surface1->SetForceRenderSurface(true); |
| 2194 | render_surface2->SetForceRenderSurface(true); |
| 2195 | |
| 2196 | gfx::Transform layer_transform; |
| 2197 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2198 | |
| 2199 | SetLayerPropertiesForTesting(parent.get(), |
| 2200 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2201 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2202 | gfx::PointF(2.5f, 0.f), |
| 2203 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2204 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2205 | false); |
| 2206 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2207 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2208 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2209 | gfx::PointF(2.5f, 0.f), |
| 2210 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2211 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2212 | false); |
| 2213 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 2214 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2215 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2216 | gfx::PointF(2.5f, 0.f), |
| 2217 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2218 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2219 | false); |
| 2220 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 2221 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2222 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2223 | gfx::PointF(2.5f, 0.f), |
| 2224 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2225 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2226 | false); |
| 2227 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 2228 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2229 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2230 | gfx::PointF(2.5f, 0.f), |
| 2231 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2232 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2233 | false); |
| 2234 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 2235 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2236 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2237 | gfx::PointF(2.5f, 0.f), |
| 2238 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2239 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2240 | false); |
| 2241 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 2242 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2243 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2244 | gfx::PointF(2.5f, 0.f), |
| 2245 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2246 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2247 | false); |
| 2248 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 2249 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2250 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2251 | gfx::PointF(2.5f, 0.f), |
| 2252 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2253 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2254 | false); |
| 2255 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 2256 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2257 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2258 | gfx::PointF(2.5f, 0.f), |
| 2259 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2260 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2261 | false); |
| 2262 | |
| 2263 | // Put an animated opacity on the render surface. |
| 2264 | AddOpacityTransitionToController( |
| 2265 | render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2266 | |
| 2267 | // Also put an animated opacity on a layer without descendants. |
| 2268 | AddOpacityTransitionToController( |
| 2269 | grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2270 | |
| 2271 | // Put a transform animation on the render surface. |
| 2272 | AddAnimatedTransformToController( |
| 2273 | render_surface2->layer_animation_controller(), 10.0, 30, 0); |
| 2274 | |
| 2275 | // Also put transform animations on grand_child_of_root, and |
| 2276 | // grand_child_of_rs2 |
| 2277 | AddAnimatedTransformToController( |
| 2278 | grand_child_of_root->layer_animation_controller(), 10.0, 30, 0); |
| 2279 | AddAnimatedTransformToController( |
| 2280 | grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0); |
| 2281 | |
| 2282 | ExecuteCalculateDrawProperties(parent.get()); |
| 2283 | |
| 2284 | // Only layers that are associated with render surfaces should have an actual |
| 2285 | // RenderSurface() value. |
| 2286 | ASSERT_TRUE(parent->render_surface()); |
| 2287 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2288 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2289 | |
| 2290 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2291 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2292 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2293 | |
| 2294 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2295 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2296 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2297 | |
| 2298 | // Verify all render target accessors |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2299 | EXPECT_EQ(parent.get(), parent->render_target()); |
| 2300 | EXPECT_EQ(parent.get(), child_of_root->render_target()); |
| 2301 | EXPECT_EQ(parent.get(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2302 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2303 | EXPECT_EQ(render_surface1.get(), render_surface1->render_target()); |
| 2304 | EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target()); |
| 2305 | EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2306 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2307 | EXPECT_EQ(render_surface2.get(), render_surface2->render_target()); |
| 2308 | EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target()); |
| 2309 | EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2310 | |
| 2311 | // Verify draw_opacity_is_animating values |
| 2312 | EXPECT_FALSE(parent->draw_opacity_is_animating()); |
| 2313 | EXPECT_FALSE(child_of_root->draw_opacity_is_animating()); |
| 2314 | EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating()); |
| 2315 | EXPECT_FALSE(render_surface1->draw_opacity_is_animating()); |
| 2316 | EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating()); |
| 2317 | EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating()); |
| 2318 | EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating()); |
| 2319 | EXPECT_FALSE(render_surface2->draw_opacity_is_animating()); |
| 2320 | EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating()); |
| 2321 | EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating()); |
| 2322 | EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating()); |
| 2323 | |
| 2324 | // Verify draw_transform_is_animating values |
| 2325 | EXPECT_FALSE(parent->draw_transform_is_animating()); |
| 2326 | EXPECT_FALSE(child_of_root->draw_transform_is_animating()); |
| 2327 | EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating()); |
| 2328 | EXPECT_FALSE(render_surface1->draw_transform_is_animating()); |
| 2329 | EXPECT_FALSE(render_surface1->render_surface() |
| 2330 | ->target_surface_transforms_are_animating()); |
| 2331 | EXPECT_FALSE(child_of_rs1->draw_transform_is_animating()); |
| 2332 | EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating()); |
| 2333 | EXPECT_FALSE(render_surface2->draw_transform_is_animating()); |
| 2334 | EXPECT_TRUE(render_surface2->render_surface() |
| 2335 | ->target_surface_transforms_are_animating()); |
| 2336 | EXPECT_FALSE(child_of_rs2->draw_transform_is_animating()); |
| 2337 | EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating()); |
| 2338 | |
| 2339 | // Verify screen_space_transform_is_animating values |
| 2340 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2341 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2342 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2343 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
| 2344 | EXPECT_FALSE(render_surface1->render_surface() |
| 2345 | ->screen_space_transforms_are_animating()); |
| 2346 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2347 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2348 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
| 2349 | EXPECT_TRUE(render_surface2->render_surface() |
| 2350 | ->screen_space_transforms_are_animating()); |
| 2351 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2352 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2353 | |
| 2354 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2355 | // It is expected that we correctly set up transforms so that the y-component |
| 2356 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2357 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 2358 | EXPECT_FLOAT_EQ(2.0, |
| 2359 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2360 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2361 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2362 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2363 | EXPECT_FLOAT_EQ(2.0, |
| 2364 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 2365 | EXPECT_FLOAT_EQ(3.0, |
| 2366 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2367 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2368 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2369 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2370 | EXPECT_FLOAT_EQ(3.0, |
| 2371 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 2372 | EXPECT_FLOAT_EQ(4.0, |
| 2373 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2374 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2375 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2376 | } |
| 2377 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2378 | TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2379 | // Test the calculateVisibleRect() function works correctly for identity |
| 2380 | // transforms. |
| 2381 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2382 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2383 | gfx::Transform layer_to_surface_transform; |
| 2384 | |
| 2385 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2386 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2387 | gfx::Rect expected = gfx::Rect(10, 10, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2388 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2389 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2390 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2391 | |
| 2392 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2393 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2394 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2395 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2396 | EXPECT_TRUE(actual.IsEmpty()); |
| 2397 | |
| 2398 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2399 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
| 2400 | expected = gfx::Rect(80, 80, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2401 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2402 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2403 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2404 | } |
| 2405 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2406 | TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2407 | // Test the calculateVisibleRect() function works correctly for scaling |
| 2408 | // transforms. |
| 2409 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2410 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2411 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2412 | gfx::Transform layer_to_surface_transform; |
| 2413 | |
| 2414 | // Case 1: Layer is contained within the surface. |
| 2415 | layer_to_surface_transform.MakeIdentity(); |
| 2416 | layer_to_surface_transform.Translate(10.0, 10.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2417 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2418 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2419 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2420 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2421 | |
| 2422 | // Case 2: Layer is outside the surface rect. |
| 2423 | layer_to_surface_transform.MakeIdentity(); |
| 2424 | layer_to_surface_transform.Translate(120.0, 120.0); |
| 2425 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2426 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2427 | EXPECT_TRUE(actual.IsEmpty()); |
| 2428 | |
| 2429 | // Case 3: Layer is partially overlapping the surface rect. |
| 2430 | layer_to_surface_transform.MakeIdentity(); |
| 2431 | layer_to_surface_transform.Translate(80.0, 80.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2432 | expected = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2433 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2434 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2435 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2436 | } |
| 2437 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2438 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2439 | // Test the calculateVisibleRect() function works correctly for rotations |
| 2440 | // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() |
| 2441 | // should return the g in the layer's space. |
| 2442 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2443 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2444 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2445 | gfx::Transform layer_to_surface_transform; |
| 2446 | |
| 2447 | // Case 1: Layer is contained within the surface. |
| 2448 | layer_to_surface_transform.MakeIdentity(); |
| 2449 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2450 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2451 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2452 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2453 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2454 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2455 | |
| 2456 | // Case 2: Layer is outside the surface rect. |
| 2457 | layer_to_surface_transform.MakeIdentity(); |
| 2458 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2459 | layer_to_surface_transform.Rotate(45.0); |
| 2460 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2461 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2462 | EXPECT_TRUE(actual.IsEmpty()); |
| 2463 | |
| 2464 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2465 | // the layer is oriented diagonally, with the left half outside of the render |
| 2466 | // surface. In this case, the g should still be the entire layer |
| 2467 | // (remember the g is computed in layer space); both the top-left |
| 2468 | // and bottom-right corners of the layer are still visible. |
| 2469 | layer_to_surface_transform.MakeIdentity(); |
| 2470 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2471 | expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2472 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2473 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2474 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2475 | |
| 2476 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2477 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2478 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2479 | // surface overlaps the right side of the layer. The g should be |
| 2480 | // the layer's right half. |
| 2481 | layer_to_surface_transform.MakeIdentity(); |
| 2482 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2483 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2484 | expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2485 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2486 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2487 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2488 | } |
| 2489 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2490 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2491 | // Test that the calculateVisibleRect() function works correctly for 3d |
| 2492 | // transforms. |
| 2493 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2494 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2495 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2496 | gfx::Transform layer_to_surface_transform; |
| 2497 | |
| 2498 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2499 | // degrees, should be fully contained in the render surface. |
| 2500 | layer_to_surface_transform.MakeIdentity(); |
| 2501 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2502 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2503 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2504 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2505 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2506 | |
| 2507 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2508 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2509 | // visible on the surface. |
| 2510 | // 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] | 2511 | SkMScalar half_width_of_rotated_layer = |
| 2512 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2513 | layer_to_surface_transform.MakeIdentity(); |
| 2514 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2515 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2516 | // edge of the layer. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2517 | expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2518 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2519 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2520 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2521 | } |
| 2522 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2523 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2524 | // Test the calculateVisibleRect() function works correctly when the layer has |
| 2525 | // a perspective projection onto the target surface. |
| 2526 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2527 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2528 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2529 | gfx::Transform layer_to_surface_transform; |
| 2530 | |
| 2531 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2532 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2533 | // its translated more than the perspective amount. |
| 2534 | layer_to_surface_transform.MakeIdentity(); |
| 2535 | |
| 2536 | // The following sequence of transforms applies the perspective about the |
| 2537 | // center of the surface. |
| 2538 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2539 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2540 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2541 | |
| 2542 | // This translate places the layer in front of the surface's projection plane. |
| 2543 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2544 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2545 | gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2546 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2547 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2548 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2549 | |
| 2550 | // Case 2: same projection as before, except that the layer is also translated |
| 2551 | // to the side, so that only the right half of the layer should be visible. |
| 2552 | // |
| 2553 | // Explanation of expected result: The perspective ratio is (z distance |
| 2554 | // between layer and camera origin) / (z distance between projection plane and |
| 2555 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
| 2556 | // move a layer by translating -50 units in projected surface units (so that |
| 2557 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
| 2558 | // -50 == -200 in the layer's units. |
| 2559 | layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2560 | expected = gfx::Rect(gfx::Point(50, -50), |
| 2561 | gfx::Size(100, 200)); // The right half of the layer's |
| 2562 | // bounding rect. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2563 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2564 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2565 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2566 | } |
| 2567 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2568 | TEST_F(LayerTreeHostCommonTest, |
| 2569 | VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2570 | // There is currently no explicit concept of an orthographic projection plane |
| 2571 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2572 | // are technically behind the surface in an orthographic world should not be |
| 2573 | // clipped when they are flattened to the surface. |
| 2574 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2575 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2576 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2577 | gfx::Transform layer_to_surface_transform; |
| 2578 | |
| 2579 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2580 | // at the center of the layer. |
| 2581 | layer_to_surface_transform.MakeIdentity(); |
| 2582 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2583 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2584 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2585 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2586 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2587 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2588 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2589 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2590 | } |
| 2591 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2592 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2593 | // Test the calculateVisibleRect() function works correctly when projecting a |
| 2594 | // surface onto a layer, but the layer is partially behind the camera (not |
| 2595 | // just behind the projection plane). In this case, the cartesian coordinates |
| 2596 | // may seem to be valid, but actually they are not. The visible rect needs to |
| 2597 | // be properly clipped by the w = 0 plane in homogeneous coordinates before |
| 2598 | // converting to cartesian coordinates. |
| 2599 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2600 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2601 | gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2602 | gfx::Transform layer_to_surface_transform; |
| 2603 | |
| 2604 | // The layer is positioned so that the right half of the layer should be in |
| 2605 | // front of the camera, while the other half is behind the surface's |
| 2606 | // projection plane. The following sequence of transforms applies the |
| 2607 | // perspective and rotation about the center of the layer. |
| 2608 | layer_to_surface_transform.MakeIdentity(); |
| 2609 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2610 | layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); |
| 2611 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2612 | |
| 2613 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2614 | // transform, otherwise this code is not testing the intended scenario. |
| 2615 | bool clipped; |
| 2616 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2617 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2618 | &clipped); |
| 2619 | ASSERT_TRUE(clipped); |
| 2620 | |
| 2621 | int expected_x_position = 0; |
| 2622 | int expected_width = 10; |
| 2623 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2624 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2625 | EXPECT_EQ(expected_x_position, actual.x()); |
| 2626 | EXPECT_EQ(expected_width, actual.width()); |
| 2627 | } |
| 2628 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2629 | TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2630 | // To determine visible rect in layer space, there needs to be an |
| 2631 | // un-projection from surface space to layer space. When the original |
| 2632 | // transform was a perspective projection that was clipped, it returns a rect |
| 2633 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2634 | // clipping again. |
| 2635 | |
| 2636 | // This sequence of transforms causes one corner of the layer to protrude |
| 2637 | // across the w = 0 plane, and should be clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2638 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
| 2639 | gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2640 | gfx::Transform layer_to_surface_transform; |
| 2641 | layer_to_surface_transform.MakeIdentity(); |
| 2642 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2643 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2644 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2645 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2646 | |
| 2647 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2648 | // code is not testing the intended scenario. |
| 2649 | bool clipped; |
| 2650 | gfx::RectF clipped_rect = |
| 2651 | MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); |
| 2652 | MathUtil::ProjectQuad( |
| 2653 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2654 | ASSERT_TRUE(clipped); |
| 2655 | |
| 2656 | // Only the corner of the layer is not visible on the surface because of being |
| 2657 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2658 | // rect is that the entire layer should still be considered visible. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2659 | gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
[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 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2665 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2666 | scoped_refptr<Layer> root = Layer::Create(); |
| 2667 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2668 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2669 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2670 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2671 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2672 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2673 | root->AddChild(child1); |
| 2674 | root->AddChild(child2); |
| 2675 | root->AddChild(child3); |
| 2676 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2677 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2678 | host->SetRootLayer(root); |
| 2679 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2680 | gfx::Transform identity_matrix; |
| 2681 | SetLayerPropertiesForTesting(root.get(), |
| 2682 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2683 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2684 | gfx::PointF(), |
| 2685 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2686 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2687 | false); |
| 2688 | SetLayerPropertiesForTesting(child1.get(), |
| 2689 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2690 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2691 | gfx::PointF(), |
| 2692 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2693 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2694 | false); |
| 2695 | SetLayerPropertiesForTesting(child2.get(), |
| 2696 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2697 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2698 | gfx::PointF(75.f, 75.f), |
| 2699 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2700 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2701 | false); |
| 2702 | SetLayerPropertiesForTesting(child3.get(), |
| 2703 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2704 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2705 | gfx::PointF(125.f, 125.f), |
| 2706 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2707 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2708 | false); |
| 2709 | |
| 2710 | ExecuteCalculateDrawProperties(root.get()); |
| 2711 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2712 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2713 | root->render_surface()->DrawableContentRect()); |
| 2714 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2715 | |
| 2716 | // Layers that do not draw content should have empty visible_content_rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2717 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2718 | |
| 2719 | // layer visible_content_rects are clipped by their target surface. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2720 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2721 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2722 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 2723 | |
| 2724 | // layer drawable_content_rects are not clipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2725 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect()); |
| 2726 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2727 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2728 | } |
| 2729 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2730 | TEST_F(LayerTreeHostCommonTest, |
| 2731 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2732 | scoped_refptr<Layer> root = Layer::Create(); |
| 2733 | scoped_refptr<Layer> child = Layer::Create(); |
| 2734 | scoped_refptr<LayerWithForcedDrawsContent> grand_child1 = |
| 2735 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2736 | scoped_refptr<LayerWithForcedDrawsContent> grand_child2 = |
| 2737 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2738 | scoped_refptr<LayerWithForcedDrawsContent> grand_child3 = |
| 2739 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2740 | root->AddChild(child); |
| 2741 | child->AddChild(grand_child1); |
| 2742 | child->AddChild(grand_child2); |
| 2743 | child->AddChild(grand_child3); |
| 2744 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2745 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2746 | host->SetRootLayer(root); |
| 2747 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2748 | gfx::Transform identity_matrix; |
| 2749 | SetLayerPropertiesForTesting(root.get(), |
| 2750 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2751 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2752 | gfx::PointF(), |
| 2753 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2754 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2755 | false); |
| 2756 | SetLayerPropertiesForTesting(child.get(), |
| 2757 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2758 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2759 | gfx::PointF(), |
| 2760 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2761 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2762 | false); |
| 2763 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2764 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2765 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2766 | gfx::PointF(5.f, 5.f), |
| 2767 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2768 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2769 | false); |
| 2770 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2771 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2772 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2773 | gfx::PointF(75.f, 75.f), |
| 2774 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2775 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2776 | false); |
| 2777 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2778 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2779 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2780 | gfx::PointF(125.f, 125.f), |
| 2781 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2782 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2783 | false); |
| 2784 | |
| 2785 | child->SetMasksToBounds(true); |
| 2786 | ExecuteCalculateDrawProperties(root.get()); |
| 2787 | |
| 2788 | ASSERT_FALSE(child->render_surface()); |
| 2789 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2790 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2791 | root->render_surface()->DrawableContentRect()); |
| 2792 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2793 | |
| 2794 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2795 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2796 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2797 | |
| 2798 | // All grandchild visible content rects should be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2799 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect()); |
| 2800 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2801 | EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty()); |
| 2802 | |
| 2803 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2804 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 2805 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2806 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 2807 | } |
| 2808 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame^] | 2809 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { |
| 2810 | scoped_refptr<Layer> root = Layer::Create(); |
| 2811 | scoped_refptr<Layer> child = Layer::Create(); |
| 2812 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 2813 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2814 | root->AddChild(child); |
| 2815 | child->AddChild(grand_child); |
| 2816 | |
| 2817 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 2818 | host->SetRootLayer(root); |
| 2819 | |
| 2820 | gfx::Transform identity_matrix; |
| 2821 | gfx::Transform child_scale_matrix; |
| 2822 | child_scale_matrix.Scale(0.25f, 0.25f); |
| 2823 | gfx::Transform grand_child_scale_matrix; |
| 2824 | grand_child_scale_matrix.Scale(0.246f, 0.246f); |
| 2825 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 2826 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 2827 | SetLayerPropertiesForTesting(child.get(), child_scale_matrix, gfx::Point3F(), |
| 2828 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 2829 | SetLayerPropertiesForTesting(grand_child.get(), grand_child_scale_matrix, |
| 2830 | gfx::Point3F(), gfx::PointF(), |
| 2831 | gfx::Size(100, 100), true, false); |
| 2832 | |
| 2833 | child->SetMasksToBounds(true); |
| 2834 | ExecuteCalculateDrawProperties(root.get()); |
| 2835 | |
| 2836 | // The visible rect is expanded to integer coordinates in target space before |
| 2837 | // being projected back to layer space, where it is once again expanded to |
| 2838 | // integer coordinates. |
| 2839 | EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_rect_from_property_trees()); |
| 2840 | } |
| 2841 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2842 | TEST_F(LayerTreeHostCommonTest, |
| 2843 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2844 | scoped_refptr<Layer> root = Layer::Create(); |
| 2845 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2846 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2847 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2848 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2849 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2850 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2851 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2852 | root->AddChild(render_surface1); |
| 2853 | render_surface1->AddChild(child1); |
| 2854 | render_surface1->AddChild(child2); |
| 2855 | render_surface1->AddChild(child3); |
| 2856 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2857 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2858 | host->SetRootLayer(root); |
| 2859 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2860 | gfx::Transform identity_matrix; |
| 2861 | SetLayerPropertiesForTesting(root.get(), |
| 2862 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2863 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2864 | gfx::PointF(), |
| 2865 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2866 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2867 | false); |
| 2868 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2869 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2870 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2871 | gfx::PointF(), |
| 2872 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2873 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2874 | false); |
| 2875 | SetLayerPropertiesForTesting(child1.get(), |
| 2876 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2877 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2878 | gfx::PointF(5.f, 5.f), |
| 2879 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2880 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2881 | false); |
| 2882 | SetLayerPropertiesForTesting(child2.get(), |
| 2883 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2884 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2885 | gfx::PointF(75.f, 75.f), |
| 2886 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2887 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2888 | false); |
| 2889 | SetLayerPropertiesForTesting(child3.get(), |
| 2890 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2891 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2892 | gfx::PointF(125.f, 125.f), |
| 2893 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2894 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2895 | false); |
| 2896 | |
| 2897 | render_surface1->SetForceRenderSurface(true); |
| 2898 | ExecuteCalculateDrawProperties(root.get()); |
| 2899 | |
| 2900 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2901 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2902 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2903 | root->render_surface()->DrawableContentRect()); |
| 2904 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2905 | |
| 2906 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2907 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2908 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2909 | |
| 2910 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 2911 | // regions of the subtree. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2912 | EXPECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 2913 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2914 | |
| 2915 | // All layers that draw content into the unclipped surface are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2916 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2917 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 2918 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2919 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2920 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 2921 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2922 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2923 | } |
| 2924 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2925 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2926 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
| 2927 | scoped_refptr<Layer> root = Layer::Create(); |
| 2928 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2929 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2930 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2931 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2932 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2933 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2934 | root->AddChild(child1); |
| 2935 | root->AddChild(child2); |
| 2936 | root->AddChild(child3); |
| 2937 | |
| 2938 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 2939 | host->SetRootLayer(root); |
| 2940 | |
| 2941 | gfx::Transform identity_matrix; |
| 2942 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 2943 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 2944 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(), |
| 2945 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 2946 | false); |
| 2947 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(), |
| 2948 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 2949 | false); |
| 2950 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, gfx::Point3F(), |
| 2951 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 2952 | true, false); |
| 2953 | |
| 2954 | RenderSurfaceLayerList render_surface_layer_list; |
| 2955 | // Now set the root render surface an empty clip. |
| 2956 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2957 | root.get(), gfx::Size(), &render_surface_layer_list); |
| 2958 | |
| 2959 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 2960 | ASSERT_TRUE(root->render_surface()); |
| 2961 | EXPECT_FALSE(root->is_clipped()); |
| 2962 | |
| 2963 | gfx::Rect empty; |
| 2964 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 2965 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2966 | |
| 2967 | // Visible content rect calculation will check if the target surface is |
| 2968 | // clipped or not. An empty clip rect does not indicate the render surface |
| 2969 | // is unclipped. |
| 2970 | EXPECT_EQ(empty, child1->visible_content_rect()); |
| 2971 | EXPECT_EQ(empty, child2->visible_content_rect()); |
| 2972 | EXPECT_EQ(empty, child3->visible_content_rect()); |
| 2973 | } |
| 2974 | |
| 2975 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2976 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2977 | scoped_refptr<Layer> root = Layer::Create(); |
| 2978 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2979 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2980 | root->AddChild(child); |
| 2981 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2982 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2983 | host->SetRootLayer(root); |
| 2984 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2985 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2986 | gfx::Transform identity_matrix; |
| 2987 | 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] | 2988 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2989 | |
| 2990 | SetLayerPropertiesForTesting(root.get(), |
| 2991 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2992 | gfx::Point3F(), |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2993 | gfx::PointF(), |
| 2994 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2995 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2996 | false); |
| 2997 | SetLayerPropertiesForTesting(child.get(), |
| 2998 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2999 | gfx::Point3F(), |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3000 | gfx::PointF(5.f, 5.f), |
| 3001 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3002 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3003 | false); |
| 3004 | |
| 3005 | ExecuteCalculateDrawProperties(root.get()); |
| 3006 | |
| 3007 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 3008 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3009 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3010 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 3011 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3012 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3013 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3014 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3015 | |
| 3016 | SetLayerPropertiesForTesting(child.get(), |
| 3017 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3018 | gfx::Point3F(), |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3019 | gfx::PointF(5.f, 5.f), |
| 3020 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3021 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3022 | false); |
| 3023 | |
| 3024 | ExecuteCalculateDrawProperties(root.get()); |
| 3025 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3026 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 3027 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3028 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3029 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3030 | uninvertible_matrix.MakeIdentity(); |
| 3031 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3032 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3033 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3034 | |
| 3035 | SetLayerPropertiesForTesting(child.get(), |
| 3036 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3037 | gfx::Point3F(), |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3038 | gfx::PointF(5.f, 5.f), |
| 3039 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3040 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3041 | false); |
| 3042 | |
| 3043 | ExecuteCalculateDrawProperties(root.get()); |
| 3044 | |
| 3045 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3046 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3047 | } |
| 3048 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3049 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3050 | SingularTransformDoesNotPreventClearingDrawProperties) { |
| 3051 | scoped_refptr<Layer> root = Layer::Create(); |
| 3052 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 3053 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3054 | root->AddChild(child); |
| 3055 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3056 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3057 | host->SetRootLayer(root); |
| 3058 | |
| 3059 | gfx::Transform identity_matrix; |
| 3060 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 3061 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3062 | |
| 3063 | SetLayerPropertiesForTesting(root.get(), |
| 3064 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3065 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3066 | gfx::PointF(), |
| 3067 | gfx::Size(100, 100), |
| 3068 | true, |
| 3069 | false); |
| 3070 | SetLayerPropertiesForTesting(child.get(), |
| 3071 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3072 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3073 | gfx::PointF(5.f, 5.f), |
| 3074 | gfx::Size(50, 50), |
| 3075 | true, |
| 3076 | false); |
| 3077 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 3078 | child->draw_properties().sorted_for_recursion = true; |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3079 | |
| 3080 | TransformOperations start_transform_operations; |
| 3081 | start_transform_operations.AppendScale(1.f, 0.f, 0.f); |
| 3082 | |
| 3083 | TransformOperations end_transform_operations; |
| 3084 | end_transform_operations.AppendScale(1.f, 1.f, 0.f); |
| 3085 | |
| 3086 | AddAnimatedTransformToLayer( |
| 3087 | root.get(), 10.0, start_transform_operations, end_transform_operations); |
| 3088 | |
| 3089 | EXPECT_TRUE(root->TransformIsAnimating()); |
| 3090 | |
| 3091 | ExecuteCalculateDrawProperties(root.get()); |
| 3092 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 3093 | EXPECT_FALSE(child->draw_properties().sorted_for_recursion); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3094 | } |
| 3095 | |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3096 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3097 | SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) { |
| 3098 | scoped_refptr<Layer> root = Layer::Create(); |
| 3099 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3100 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3101 | host->SetRootLayer(root); |
| 3102 | |
| 3103 | gfx::Transform identity_matrix; |
| 3104 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 3105 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3106 | |
| 3107 | SetLayerPropertiesForTesting(root.get(), |
| 3108 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3109 | gfx::Point3F(), |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3110 | gfx::PointF(), |
| 3111 | gfx::Size(100, 100), |
| 3112 | true, |
| 3113 | false); |
| 3114 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 3115 | root->draw_properties().sorted_for_recursion = true; |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3116 | |
| 3117 | EXPECT_FALSE(root->TransformIsAnimating()); |
| 3118 | |
| 3119 | ExecuteCalculateDrawProperties(root.get()); |
| 3120 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 3121 | EXPECT_FALSE(root->draw_properties().sorted_for_recursion); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3122 | } |
| 3123 | |
| 3124 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3125 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3126 | scoped_refptr<Layer> root = Layer::Create(); |
| 3127 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3128 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3129 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3130 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3131 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3132 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3133 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3134 | root->AddChild(render_surface1); |
| 3135 | render_surface1->AddChild(child1); |
| 3136 | render_surface1->AddChild(child2); |
| 3137 | render_surface1->AddChild(child3); |
| 3138 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3139 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3140 | host->SetRootLayer(root); |
| 3141 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3142 | gfx::Transform identity_matrix; |
| 3143 | SetLayerPropertiesForTesting(root.get(), |
| 3144 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3145 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3146 | gfx::PointF(), |
| 3147 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3148 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3149 | false); |
| 3150 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3151 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3152 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3153 | gfx::PointF(), |
| 3154 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3155 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3156 | false); |
| 3157 | SetLayerPropertiesForTesting(child1.get(), |
| 3158 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3159 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3160 | gfx::PointF(5.f, 5.f), |
| 3161 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3162 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3163 | false); |
| 3164 | SetLayerPropertiesForTesting(child2.get(), |
| 3165 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3166 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3167 | gfx::PointF(75.f, 75.f), |
| 3168 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3169 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3170 | false); |
| 3171 | SetLayerPropertiesForTesting(child3.get(), |
| 3172 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3173 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3174 | gfx::PointF(125.f, 125.f), |
| 3175 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3176 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3177 | false); |
| 3178 | |
| 3179 | root->SetMasksToBounds(true); |
| 3180 | render_surface1->SetForceRenderSurface(true); |
| 3181 | ExecuteCalculateDrawProperties(root.get()); |
| 3182 | |
| 3183 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3184 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3185 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3186 | root->render_surface()->DrawableContentRect()); |
| 3187 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3188 | |
| 3189 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3190 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3191 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3192 | |
| 3193 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3194 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3195 | EXPECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3196 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3197 | |
| 3198 | // All layers that draw content into the surface have their visible content |
| 3199 | // rect clipped by the surface clip rect. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3200 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3201 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3202 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 3203 | |
| 3204 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3205 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3206 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3207 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3208 | } |
| 3209 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3210 | TEST_F(LayerTreeHostCommonTest, |
| 3211 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3212 | // Check that clipping does not propagate down surfaces. |
| 3213 | scoped_refptr<Layer> root = Layer::Create(); |
| 3214 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3215 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 3216 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3217 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3218 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3219 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3220 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3221 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3222 | root->AddChild(render_surface1); |
| 3223 | render_surface1->AddChild(render_surface2); |
| 3224 | render_surface2->AddChild(child1); |
| 3225 | render_surface2->AddChild(child2); |
| 3226 | render_surface2->AddChild(child3); |
| 3227 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3228 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3229 | host->SetRootLayer(root); |
| 3230 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3231 | gfx::Transform identity_matrix; |
| 3232 | SetLayerPropertiesForTesting(root.get(), |
| 3233 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3234 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3235 | gfx::PointF(), |
| 3236 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3237 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3238 | false); |
| 3239 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3240 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3241 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3242 | gfx::PointF(), |
| 3243 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3244 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3245 | false); |
| 3246 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3247 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3248 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3249 | gfx::PointF(), |
| 3250 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3251 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3252 | false); |
| 3253 | SetLayerPropertiesForTesting(child1.get(), |
| 3254 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3255 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3256 | gfx::PointF(5.f, 5.f), |
| 3257 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3258 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3259 | false); |
| 3260 | SetLayerPropertiesForTesting(child2.get(), |
| 3261 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3262 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3263 | gfx::PointF(75.f, 75.f), |
| 3264 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3265 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3266 | false); |
| 3267 | SetLayerPropertiesForTesting(child3.get(), |
| 3268 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3269 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3270 | gfx::PointF(125.f, 125.f), |
| 3271 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3272 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3273 | false); |
| 3274 | |
| 3275 | root->SetMasksToBounds(true); |
| 3276 | render_surface1->SetForceRenderSurface(true); |
| 3277 | render_surface2->SetForceRenderSurface(true); |
| 3278 | ExecuteCalculateDrawProperties(root.get()); |
| 3279 | |
| 3280 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3281 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3282 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3283 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3284 | root->render_surface()->DrawableContentRect()); |
| 3285 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3286 | |
| 3287 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3288 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3289 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
| 3290 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3291 | |
| 3292 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3293 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3294 | EXPECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3295 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3296 | |
| 3297 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3298 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3299 | // render_surface2 grows to enclose all drawable content of its subtree. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3300 | EXPECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 3301 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3302 | |
| 3303 | // All layers that draw content into render_surface2 think they are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3304 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3305 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3306 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3307 | |
| 3308 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3309 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3310 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3311 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3312 | } |
| 3313 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3314 | TEST_F(LayerTreeHostCommonTest, |
| 3315 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3316 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3317 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3318 | |
| 3319 | scoped_refptr<Layer> root = Layer::Create(); |
| 3320 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3321 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3322 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3323 | root->AddChild(render_surface1); |
| 3324 | render_surface1->AddChild(child1); |
| 3325 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3326 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3327 | host->SetRootLayer(root); |
| 3328 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3329 | gfx::Transform identity_matrix; |
| 3330 | gfx::Transform child_rotation; |
| 3331 | child_rotation.Rotate(45.0); |
| 3332 | SetLayerPropertiesForTesting(root.get(), |
| 3333 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3334 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3335 | gfx::PointF(), |
| 3336 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3337 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3338 | false); |
| 3339 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3340 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3341 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3342 | gfx::PointF(), |
| 3343 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3344 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3345 | false); |
| 3346 | SetLayerPropertiesForTesting(child1.get(), |
| 3347 | child_rotation, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3348 | gfx::Point3F(25, 25, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3349 | gfx::PointF(25.f, 25.f), |
| 3350 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3351 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3352 | false); |
| 3353 | |
| 3354 | render_surface1->SetForceRenderSurface(true); |
| 3355 | ExecuteCalculateDrawProperties(root.get()); |
| 3356 | |
| 3357 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3358 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3359 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3360 | root->render_surface()->DrawableContentRect()); |
| 3361 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3362 | |
| 3363 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3364 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3365 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3366 | |
| 3367 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3368 | // regions of the subtree. |
| 3369 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3370 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3371 | gfx::Rect(50 - diagonal_radius, |
| 3372 | 50 - diagonal_radius, |
| 3373 | diagonal_radius * 2, |
| 3374 | diagonal_radius * 2); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3375 | EXPECT_EQ(expected_surface_drawable_content, |
| 3376 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3377 | |
| 3378 | // All layers that draw content into the unclipped surface are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3379 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3380 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3381 | } |
| 3382 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3383 | TEST_F(LayerTreeHostCommonTest, |
| 3384 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3385 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3386 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3387 | |
| 3388 | scoped_refptr<Layer> root = Layer::Create(); |
| 3389 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3390 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3391 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3392 | root->AddChild(render_surface1); |
| 3393 | render_surface1->AddChild(child1); |
| 3394 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3395 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3396 | host->SetRootLayer(root); |
| 3397 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3398 | gfx::Transform identity_matrix; |
| 3399 | gfx::Transform child_rotation; |
| 3400 | child_rotation.Rotate(45.0); |
| 3401 | SetLayerPropertiesForTesting(root.get(), |
| 3402 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3403 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3404 | gfx::PointF(), |
| 3405 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3406 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3407 | false); |
| 3408 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3409 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3410 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3411 | gfx::PointF(), |
| 3412 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3413 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3414 | false); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3415 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3416 | SetLayerPropertiesForTesting(child1.get(), |
| 3417 | child_rotation, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3418 | gfx::Point3F(25, 25, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3419 | gfx::PointF(25.f, 25.f), |
| 3420 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3421 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3422 | false); |
| 3423 | |
| 3424 | root->SetMasksToBounds(true); |
| 3425 | render_surface1->SetForceRenderSurface(true); |
| 3426 | ExecuteCalculateDrawProperties(root.get()); |
| 3427 | |
| 3428 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3429 | |
| 3430 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 3431 | // rotated layer. |
| 3432 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3433 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 3434 | 50 - diagonal_radius, |
| 3435 | diagonal_radius * 2, |
| 3436 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3437 | gfx::Rect expected_surface_drawable_content = |
| 3438 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3439 | EXPECT_EQ(expected_surface_drawable_content, |
| 3440 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3441 | |
| 3442 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3443 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 3444 | // up covering the full left half of child1. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3445 | // |
| 3446 | // Given the floating point math, this number is a little bit fuzzy. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3447 | EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3448 | |
| 3449 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3450 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3451 | } |
| 3452 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3453 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3454 | MockContentLayerClient client; |
| 3455 | |
| 3456 | scoped_refptr<Layer> root = Layer::Create(); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 3457 | scoped_refptr<FakePictureLayer> render_surface1 = |
| 3458 | CreateDrawablePictureLayer(&client); |
| 3459 | scoped_refptr<FakePictureLayer> render_surface2 = |
| 3460 | CreateDrawablePictureLayer(&client); |
| 3461 | scoped_refptr<FakePictureLayer> child1 = CreateDrawablePictureLayer(&client); |
| 3462 | scoped_refptr<FakePictureLayer> child2 = CreateDrawablePictureLayer(&client); |
| 3463 | scoped_refptr<FakePictureLayer> child3 = CreateDrawablePictureLayer(&client); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3464 | root->AddChild(render_surface1); |
| 3465 | render_surface1->AddChild(render_surface2); |
| 3466 | render_surface2->AddChild(child1); |
| 3467 | render_surface2->AddChild(child2); |
| 3468 | render_surface2->AddChild(child3); |
| 3469 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3470 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3471 | host->SetRootLayer(root); |
| 3472 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3473 | gfx::Transform identity_matrix; |
| 3474 | SetLayerPropertiesForTesting(root.get(), |
| 3475 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3476 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3477 | gfx::PointF(), |
| 3478 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3479 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3480 | false); |
| 3481 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3482 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3483 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3484 | gfx::PointF(5.f, 5.f), |
| 3485 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3486 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3487 | false); |
| 3488 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3489 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3490 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3491 | gfx::PointF(5.f, 5.f), |
| 3492 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3493 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3494 | false); |
| 3495 | SetLayerPropertiesForTesting(child1.get(), |
| 3496 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3497 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3498 | gfx::PointF(5.f, 5.f), |
| 3499 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3500 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3501 | false); |
| 3502 | SetLayerPropertiesForTesting(child2.get(), |
| 3503 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3504 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3505 | gfx::PointF(75.f, 75.f), |
| 3506 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3507 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3508 | false); |
| 3509 | SetLayerPropertiesForTesting(child3.get(), |
| 3510 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3511 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3512 | gfx::PointF(125.f, 125.f), |
| 3513 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3514 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3515 | false); |
| 3516 | |
| 3517 | float device_scale_factor = 2.f; |
| 3518 | |
| 3519 | root->SetMasksToBounds(true); |
| 3520 | render_surface1->SetForceRenderSurface(true); |
| 3521 | render_surface2->SetForceRenderSurface(true); |
| 3522 | ExecuteCalculateDrawProperties(root.get(), device_scale_factor); |
| 3523 | |
| 3524 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3525 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3526 | |
| 3527 | // drawable_content_rects for all layers and surfaces are scaled by |
| 3528 | // device_scale_factor. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3529 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 3530 | root->render_surface()->DrawableContentRect()); |
| 3531 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); |
| 3532 | EXPECT_EQ(gfx::Rect(10, 10, 190, 190), |
| 3533 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3534 | |
| 3535 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 3536 | // is only implicitly clipped by render_surface1. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3537 | EXPECT_EQ(gfx::Rect(10, 10, 350, 350), |
| 3538 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3539 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3540 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3541 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 3542 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3543 | |
| 3544 | // The root layer does not actually draw content of its own. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3545 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3546 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 3547 | // All layer visible content rects are not expressed in content space of each |
| 3548 | // layer, so they are not scaled by the device_scale_factor. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3549 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_content_rect()); |
| 3550 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_content_rect()); |
| 3551 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3552 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3553 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3554 | } |
| 3555 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3556 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3557 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 3558 | // layers. Note that 3d transforms still apply in this case, but they are |
| 3559 | // "flattened" to each parent layer according to current W3C spec. |
| 3560 | |
| 3561 | const gfx::Transform identity_matrix; |
| 3562 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3563 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3564 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3565 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3566 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3567 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3568 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3569 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3570 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3571 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3572 | front_facing_child_of_front_facing_surface = |
| 3573 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3574 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3575 | back_facing_child_of_front_facing_surface = |
| 3576 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3577 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3578 | front_facing_child_of_back_facing_surface = |
| 3579 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3580 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3581 | back_facing_child_of_back_facing_surface = |
| 3582 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3583 | |
| 3584 | parent->AddChild(front_facing_child); |
| 3585 | parent->AddChild(back_facing_child); |
| 3586 | parent->AddChild(front_facing_surface); |
| 3587 | parent->AddChild(back_facing_surface); |
| 3588 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3589 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3590 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3591 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3592 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3593 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3594 | host->SetRootLayer(parent); |
| 3595 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3596 | // Nothing is double-sided |
| 3597 | front_facing_child->SetDoubleSided(false); |
| 3598 | back_facing_child->SetDoubleSided(false); |
| 3599 | front_facing_surface->SetDoubleSided(false); |
| 3600 | back_facing_surface->SetDoubleSided(false); |
| 3601 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3602 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3603 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3604 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3605 | |
| 3606 | gfx::Transform backface_matrix; |
| 3607 | backface_matrix.Translate(50.0, 50.0); |
| 3608 | backface_matrix.RotateAboutYAxis(180.0); |
| 3609 | backface_matrix.Translate(-50.0, -50.0); |
| 3610 | |
| 3611 | // Having a descendant and opacity will force these to have render surfaces. |
| 3612 | front_facing_surface->SetOpacity(0.5f); |
| 3613 | back_facing_surface->SetOpacity(0.5f); |
| 3614 | |
| 3615 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 3616 | // these layers should blindly use their own local transforms to determine |
| 3617 | // back-face culling. |
| 3618 | SetLayerPropertiesForTesting(parent.get(), |
| 3619 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3620 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3621 | gfx::PointF(), |
| 3622 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3623 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3624 | false); |
| 3625 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3626 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3627 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3628 | gfx::PointF(), |
| 3629 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3630 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3631 | false); |
| 3632 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3633 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3634 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3635 | gfx::PointF(), |
| 3636 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3637 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3638 | false); |
| 3639 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3640 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3641 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3642 | gfx::PointF(), |
| 3643 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3644 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3645 | false); |
| 3646 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3647 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3648 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3649 | gfx::PointF(), |
| 3650 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3651 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3652 | false); |
| 3653 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3654 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3655 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3656 | gfx::PointF(), |
| 3657 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3658 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3659 | false); |
| 3660 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3661 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3662 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3663 | gfx::PointF(), |
| 3664 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3665 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3666 | false); |
| 3667 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3668 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3669 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3670 | gfx::PointF(), |
| 3671 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3672 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3673 | false); |
| 3674 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3675 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3676 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3677 | gfx::PointF(), |
| 3678 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3679 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3680 | false); |
| 3681 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3682 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3683 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3684 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3685 | inputs.can_adjust_raster_scales = true; |
| 3686 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3687 | |
| 3688 | // Verify which render surfaces were created. |
| 3689 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3690 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3691 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3692 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 3693 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3694 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3695 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3696 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3697 | |
| 3698 | // Verify the render_surface_layer_list. |
| 3699 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3700 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3701 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3702 | // Even though the back facing surface LAYER gets culled, the other |
| 3703 | // descendants should still be added, so the SURFACE should not be culled. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3704 | EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3705 | |
| 3706 | // Verify root surface's layer list. |
| 3707 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3708 | 3u, |
| 3709 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3710 | EXPECT_EQ(front_facing_child->id(), |
| 3711 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3712 | ->render_surface() |
| 3713 | ->layer_list() |
| 3714 | .at(0) |
| 3715 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3716 | EXPECT_EQ(front_facing_surface->id(), |
| 3717 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3718 | ->render_surface() |
| 3719 | ->layer_list() |
| 3720 | .at(1) |
| 3721 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3722 | EXPECT_EQ(back_facing_surface->id(), |
| 3723 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3724 | ->render_surface() |
| 3725 | ->layer_list() |
| 3726 | .at(2) |
| 3727 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3728 | |
| 3729 | // Verify front_facing_surface's layer list. |
| 3730 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3731 | 2u, |
| 3732 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3733 | EXPECT_EQ(front_facing_surface->id(), |
| 3734 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3735 | ->render_surface() |
| 3736 | ->layer_list() |
| 3737 | .at(0) |
| 3738 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3739 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3740 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3741 | ->render_surface() |
| 3742 | ->layer_list() |
| 3743 | .at(1) |
| 3744 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3745 | |
| 3746 | // Verify back_facing_surface's layer list; its own layer should be culled |
| 3747 | // from the surface list. |
| 3748 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3749 | 1u, |
| 3750 | render_surface_layer_list.at(2)->render_surface()->layer_list().size()); |
| 3751 | EXPECT_EQ(front_facing_child_of_back_facing_surface->id(), |
| 3752 | render_surface_layer_list.at(2) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3753 | ->render_surface() |
| 3754 | ->layer_list() |
| 3755 | .at(0) |
| 3756 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3757 | } |
| 3758 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3759 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3760 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 3761 | // is used. |
| 3762 | |
| 3763 | const gfx::Transform identity_matrix; |
| 3764 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3765 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3766 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3767 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3768 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3769 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3770 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3771 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3772 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3773 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3774 | front_facing_child_of_front_facing_surface = |
| 3775 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3776 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3777 | back_facing_child_of_front_facing_surface = |
| 3778 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3779 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3780 | front_facing_child_of_back_facing_surface = |
| 3781 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3782 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3783 | back_facing_child_of_back_facing_surface = |
| 3784 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3785 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 = |
| 3786 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3787 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 = |
| 3788 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3789 | |
| 3790 | parent->AddChild(front_facing_child); |
| 3791 | parent->AddChild(back_facing_child); |
| 3792 | parent->AddChild(front_facing_surface); |
| 3793 | parent->AddChild(back_facing_surface); |
| 3794 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3795 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3796 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3797 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3798 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3799 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3800 | host->SetRootLayer(parent); |
| 3801 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3802 | // Nothing is double-sided |
| 3803 | front_facing_child->SetDoubleSided(false); |
| 3804 | back_facing_child->SetDoubleSided(false); |
| 3805 | front_facing_surface->SetDoubleSided(false); |
| 3806 | back_facing_surface->SetDoubleSided(false); |
| 3807 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3808 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3809 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3810 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3811 | |
| 3812 | gfx::Transform backface_matrix; |
| 3813 | backface_matrix.Translate(50.0, 50.0); |
| 3814 | backface_matrix.RotateAboutYAxis(180.0); |
| 3815 | backface_matrix.Translate(-50.0, -50.0); |
| 3816 | |
| 3817 | // Opacity will not force creation of render surfaces in this case because of |
| 3818 | // the preserve-3d transform style. Instead, an example of when a surface |
| 3819 | // would be created with preserve-3d is when there is a replica layer. |
| 3820 | front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get()); |
| 3821 | back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get()); |
| 3822 | |
| 3823 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 3824 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 3825 | // rendering context should use the transform with respect to that context. |
| 3826 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 3827 | // and (b) the layer's transform style is preserve-3d. |
| 3828 | SetLayerPropertiesForTesting(parent.get(), |
| 3829 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3830 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3831 | gfx::PointF(), |
| 3832 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3833 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3834 | false); // parent transform style is flat. |
| 3835 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3836 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3837 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3838 | gfx::PointF(), |
| 3839 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3840 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3841 | false); |
| 3842 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3843 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3844 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3845 | gfx::PointF(), |
| 3846 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3847 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3848 | false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3849 | // surface transform style is preserve-3d. |
| 3850 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3851 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3852 | gfx::Point3F(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3853 | gfx::PointF(), |
| 3854 | gfx::Size(100, 100), |
| 3855 | false, |
| 3856 | true); |
| 3857 | // surface transform style is preserve-3d. |
| 3858 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3859 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3860 | gfx::Point3F(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3861 | gfx::PointF(), |
| 3862 | gfx::Size(100, 100), |
| 3863 | false, |
| 3864 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3865 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3866 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3867 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3868 | gfx::PointF(), |
| 3869 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3870 | true, |
| 3871 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3872 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3873 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3874 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3875 | gfx::PointF(), |
| 3876 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3877 | true, |
| 3878 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3879 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3880 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3881 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3882 | gfx::PointF(), |
| 3883 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3884 | true, |
| 3885 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3886 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3887 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3888 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3889 | gfx::PointF(), |
| 3890 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3891 | true, |
| 3892 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3893 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3894 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3895 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3896 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3897 | inputs.can_adjust_raster_scales = true; |
| 3898 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3899 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3900 | // Verify which render surfaces were created and used. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3901 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3902 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3903 | EXPECT_TRUE(front_facing_surface->render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3904 | EXPECT_NE(back_facing_surface->render_target(), back_facing_surface); |
| 3905 | // We expect that a render_surface was created but not used. |
| 3906 | EXPECT_TRUE(back_facing_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3907 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3908 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3909 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3910 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3911 | |
| 3912 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 3913 | // culled. |
| 3914 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3915 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3916 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3917 | |
| 3918 | // Verify root surface's layer list. |
| 3919 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3920 | 2u, |
| 3921 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3922 | EXPECT_EQ(front_facing_child->id(), |
| 3923 | render_surface_layer_list.at(0) |
| 3924 | ->render_surface()->layer_list().at(0)->id()); |
| 3925 | EXPECT_EQ(front_facing_surface->id(), |
| 3926 | render_surface_layer_list.at(0) |
| 3927 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3928 | |
| 3929 | // Verify front_facing_surface's layer list. |
| 3930 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3931 | 2u, |
| 3932 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3933 | EXPECT_EQ(front_facing_surface->id(), |
| 3934 | render_surface_layer_list.at(1) |
| 3935 | ->render_surface()->layer_list().at(0)->id()); |
| 3936 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3937 | render_surface_layer_list.at(1) |
| 3938 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3939 | } |
| 3940 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3941 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3942 | // Verify that layers are appropriately culled when their back face is showing |
| 3943 | // and they are not double sided, while animations are going on. |
| 3944 | // |
| 3945 | // Layers that are animating do not get culled on the main thread, as their |
| 3946 | // transforms should be treated as "unknown" so we can not be sure that their |
| 3947 | // back face is really showing. |
| 3948 | const gfx::Transform identity_matrix; |
| 3949 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3950 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 3951 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3952 | scoped_refptr<LayerWithForcedDrawsContent> animating_surface = |
| 3953 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3954 | scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = |
| 3955 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3956 | scoped_refptr<LayerWithForcedDrawsContent> animating_child = |
| 3957 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3958 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3959 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3960 | |
| 3961 | parent->AddChild(child); |
| 3962 | parent->AddChild(animating_surface); |
| 3963 | animating_surface->AddChild(child_of_animating_surface); |
| 3964 | parent->AddChild(animating_child); |
| 3965 | parent->AddChild(child2); |
| 3966 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3967 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3968 | host->SetRootLayer(parent); |
| 3969 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3970 | // Nothing is double-sided |
| 3971 | child->SetDoubleSided(false); |
| 3972 | child2->SetDoubleSided(false); |
| 3973 | animating_surface->SetDoubleSided(false); |
| 3974 | child_of_animating_surface->SetDoubleSided(false); |
| 3975 | animating_child->SetDoubleSided(false); |
| 3976 | |
| 3977 | gfx::Transform backface_matrix; |
| 3978 | backface_matrix.Translate(50.0, 50.0); |
| 3979 | backface_matrix.RotateAboutYAxis(180.0); |
| 3980 | backface_matrix.Translate(-50.0, -50.0); |
| 3981 | |
| 3982 | // Make our render surface. |
| 3983 | animating_surface->SetForceRenderSurface(true); |
| 3984 | |
| 3985 | // Animate the transform on the render surface. |
| 3986 | AddAnimatedTransformToController( |
| 3987 | animating_surface->layer_animation_controller(), 10.0, 30, 0); |
| 3988 | // This is just an animating layer, not a surface. |
| 3989 | AddAnimatedTransformToController( |
| 3990 | animating_child->layer_animation_controller(), 10.0, 30, 0); |
| 3991 | |
| 3992 | SetLayerPropertiesForTesting(parent.get(), |
| 3993 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3994 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3995 | gfx::PointF(), |
| 3996 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3997 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3998 | false); |
| 3999 | SetLayerPropertiesForTesting(child.get(), |
| 4000 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4001 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4002 | gfx::PointF(), |
| 4003 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4004 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4005 | false); |
| 4006 | SetLayerPropertiesForTesting(animating_surface.get(), |
| 4007 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4008 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4009 | gfx::PointF(), |
| 4010 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4011 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4012 | false); |
| 4013 | SetLayerPropertiesForTesting(child_of_animating_surface.get(), |
| 4014 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4015 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4016 | gfx::PointF(), |
| 4017 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4018 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4019 | false); |
| 4020 | SetLayerPropertiesForTesting(animating_child.get(), |
| 4021 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4022 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4023 | gfx::PointF(), |
| 4024 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4025 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4026 | false); |
| 4027 | SetLayerPropertiesForTesting(child2.get(), |
| 4028 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4029 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4030 | gfx::PointF(), |
| 4031 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4032 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4033 | false); |
| 4034 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4035 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4036 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4037 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4038 | inputs.can_adjust_raster_scales = true; |
| 4039 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4040 | |
| 4041 | EXPECT_FALSE(child->render_surface()); |
| 4042 | EXPECT_TRUE(animating_surface->render_surface()); |
| 4043 | EXPECT_FALSE(child_of_animating_surface->render_surface()); |
| 4044 | EXPECT_FALSE(animating_child->render_surface()); |
| 4045 | EXPECT_FALSE(child2->render_surface()); |
| 4046 | |
| 4047 | // Verify that the animating_child and child_of_animating_surface were not |
| 4048 | // culled, but that child was. |
| 4049 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4050 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4051 | EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4052 | |
| 4053 | // The non-animating child be culled from the layer list for the parent render |
| 4054 | // surface. |
| 4055 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4056 | 3u, |
| 4057 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4058 | EXPECT_EQ(animating_surface->id(), |
| 4059 | render_surface_layer_list.at(0) |
| 4060 | ->render_surface()->layer_list().at(0)->id()); |
| 4061 | EXPECT_EQ(animating_child->id(), |
| 4062 | render_surface_layer_list.at(0) |
| 4063 | ->render_surface()->layer_list().at(1)->id()); |
| 4064 | EXPECT_EQ(child2->id(), |
| 4065 | render_surface_layer_list.at(0) |
| 4066 | ->render_surface()->layer_list().at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4067 | |
| 4068 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4069 | 2u, |
| 4070 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4071 | EXPECT_EQ(animating_surface->id(), |
| 4072 | render_surface_layer_list.at(1) |
| 4073 | ->render_surface()->layer_list().at(0)->id()); |
| 4074 | EXPECT_EQ(child_of_animating_surface->id(), |
| 4075 | render_surface_layer_list.at(1) |
| 4076 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4077 | |
| 4078 | EXPECT_FALSE(child2->visible_content_rect().IsEmpty()); |
| 4079 | |
| 4080 | // The animating layers should have a visible content rect that represents the |
| 4081 | // area of the front face that is within the viewport. |
| 4082 | EXPECT_EQ(animating_child->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4083 | gfx::Rect(animating_child->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4084 | EXPECT_EQ(animating_surface->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4085 | gfx::Rect(animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4086 | // And layers in the subtree of the animating layer should have valid visible |
| 4087 | // content rects also. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4088 | EXPECT_EQ(child_of_animating_surface->visible_content_rect(), |
| 4089 | gfx::Rect(child_of_animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4090 | } |
| 4091 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4092 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4093 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4094 | // Verify the behavior of back-face culling for a render surface that is |
| 4095 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4096 | |
| 4097 | const gfx::Transform identity_matrix; |
| 4098 | scoped_refptr<Layer> parent = Layer::Create(); |
| 4099 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 4100 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4101 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 4102 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4103 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 4104 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4105 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 4106 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4107 | |
| 4108 | parent->AddChild(front_facing_surface); |
| 4109 | parent->AddChild(back_facing_surface); |
| 4110 | front_facing_surface->AddChild(child1); |
| 4111 | back_facing_surface->AddChild(child2); |
| 4112 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4113 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4114 | host->SetRootLayer(parent); |
| 4115 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4116 | // RenderSurfaces are not double-sided |
| 4117 | front_facing_surface->SetDoubleSided(false); |
| 4118 | back_facing_surface->SetDoubleSided(false); |
| 4119 | |
| 4120 | gfx::Transform backface_matrix; |
| 4121 | backface_matrix.Translate(50.0, 50.0); |
| 4122 | backface_matrix.RotateAboutYAxis(180.0); |
| 4123 | backface_matrix.Translate(-50.0, -50.0); |
| 4124 | |
| 4125 | SetLayerPropertiesForTesting(parent.get(), |
| 4126 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4127 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4128 | gfx::PointF(), |
| 4129 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4130 | false, |
| 4131 | true); // parent transform style is preserve3d. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4132 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 4133 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4134 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4135 | gfx::PointF(), |
| 4136 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4137 | true, |
| 4138 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4139 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4140 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4141 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4142 | gfx::PointF(), |
| 4143 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4144 | true, |
| 4145 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4146 | SetLayerPropertiesForTesting(child1.get(), |
| 4147 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4148 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4149 | gfx::PointF(), |
| 4150 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4151 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4152 | false); |
| 4153 | SetLayerPropertiesForTesting(child2.get(), |
| 4154 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4155 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4156 | gfx::PointF(), |
| 4157 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4158 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4159 | false); |
| 4160 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4161 | front_facing_surface->Set3dSortingContextId(1); |
| 4162 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4163 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4164 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4165 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4166 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4167 | inputs.can_adjust_raster_scales = true; |
| 4168 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4169 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4170 | // Verify which render surfaces were created and used. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4171 | EXPECT_TRUE(front_facing_surface->render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4172 | |
| 4173 | // We expect the render surface to have been created, but remain unused. |
| 4174 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 4175 | EXPECT_NE(back_facing_surface->render_target(), |
| 4176 | back_facing_surface); // because it should be culled |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4177 | EXPECT_FALSE(child1->render_surface()); |
| 4178 | EXPECT_FALSE(child2->render_surface()); |
| 4179 | |
| 4180 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 4181 | // culled. |
| 4182 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4183 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4184 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4185 | |
| 4186 | // Verify root surface's layer list. |
| 4187 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4188 | 1u, |
| 4189 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4190 | EXPECT_EQ(front_facing_surface->id(), |
| 4191 | render_surface_layer_list.at(0) |
| 4192 | ->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4193 | |
| 4194 | // Verify front_facing_surface's layer list. |
| 4195 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4196 | 2u, |
| 4197 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4198 | EXPECT_EQ(front_facing_surface->id(), |
| 4199 | render_surface_layer_list.at(1) |
| 4200 | ->render_surface()->layer_list().at(0)->id()); |
| 4201 | EXPECT_EQ(child1->id(), |
| 4202 | render_surface_layer_list.at(1) |
| 4203 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4204 | } |
| 4205 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4206 | class NoScaleContentLayer : public ContentLayer { |
| 4207 | public: |
| 4208 | static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
| 4209 | return make_scoped_refptr(new NoScaleContentLayer(client)); |
| 4210 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4211 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 4212 | void CalculateContentsScale(float ideal_contents_scale, |
| 4213 | float* contents_scale_x, |
| 4214 | float* contents_scale_y, |
| 4215 | gfx::Size* content_bounds) override { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4216 | // Skip over the ContentLayer to the base Layer class. |
| 4217 | Layer::CalculateContentsScale(ideal_contents_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4218 | contents_scale_x, |
| 4219 | contents_scale_y, |
| 4220 | content_bounds); |
| 4221 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4222 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4223 | protected: |
| 4224 | explicit NoScaleContentLayer(ContentLayerClient* client) |
| 4225 | : ContentLayer(client) {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 4226 | ~NoScaleContentLayer() override {} |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4227 | }; |
| 4228 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4229 | scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer( |
| 4230 | ContentLayerClient* delegate) { |
| 4231 | scoped_refptr<NoScaleContentLayer> to_return = |
| 4232 | NoScaleContentLayer::Create(delegate); |
| 4233 | to_return->SetIsDrawable(true); |
| 4234 | return to_return; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4235 | } |
| 4236 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4237 | TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4238 | // Verify draw and screen space transforms of layers not in a surface. |
| 4239 | MockContentLayerClient delegate; |
| 4240 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4241 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4242 | scoped_refptr<FakePictureLayer> parent = |
| 4243 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4244 | SetLayerPropertiesForTesting(parent.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 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4250 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4251 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4252 | scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4253 | SetLayerPropertiesForTesting(child.get(), |
| 4254 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4255 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4256 | gfx::PointF(2.f, 2.f), |
| 4257 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4258 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4259 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4260 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4261 | scoped_refptr<FakePictureLayer> child_empty = |
| 4262 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4263 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4264 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4265 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4266 | gfx::PointF(2.f, 2.f), |
| 4267 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4268 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4269 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4270 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4271 | parent->AddChild(child); |
| 4272 | parent->AddChild(child_empty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4273 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4274 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4275 | host->SetRootLayer(parent); |
| 4276 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4277 | float device_scale_factor = 2.5f; |
| 4278 | float page_scale_factor = 1.f; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4279 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4280 | RenderSurfaceLayerList render_surface_layer_list; |
| 4281 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4282 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4283 | inputs.device_scale_factor = device_scale_factor; |
| 4284 | inputs.page_scale_factor = page_scale_factor; |
| 4285 | inputs.can_adjust_raster_scales = true; |
| 4286 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4287 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4288 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4289 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4290 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child_empty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4291 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4292 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4293 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4294 | // Verify parent transforms |
| 4295 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4296 | expected_parent_transform.Scale(device_scale_factor * page_scale_factor, |
| 4297 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4298 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4299 | parent->screen_space_transform()); |
| 4300 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4301 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4302 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4303 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4304 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4305 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4306 | gfx::RectF parent_draw_rect = |
| 4307 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4308 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4309 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4310 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4311 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4312 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4313 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4314 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4315 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4316 | // Verify child and child_empty transforms. They should match. |
| 4317 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4318 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4319 | expected_child_transform.Translate(child->position().x(), |
| 4320 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4321 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4322 | child->draw_transform()); |
| 4323 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4324 | child->screen_space_transform()); |
| 4325 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4326 | child_empty->draw_transform()); |
| 4327 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4328 | child_empty->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4329 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4330 | // Verify results of transformed child and child_empty rects. They should |
| 4331 | // match. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4332 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4333 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4334 | gfx::RectF child_draw_rect = |
| 4335 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4336 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4337 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4338 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4339 | gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( |
| 4340 | child_empty->draw_transform(), child_content_bounds); |
| 4341 | gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( |
| 4342 | child_empty->screen_space_transform(), child_content_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4343 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4344 | gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); |
| 4345 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4346 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4347 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
| 4348 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); |
| 4349 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4350 | } |
| 4351 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4352 | TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4353 | // Verify draw and screen space transforms of layers in a surface. |
| 4354 | MockContentLayerClient delegate; |
| 4355 | gfx::Transform identity_matrix; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4356 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4357 | gfx::Transform perspective_matrix; |
| 4358 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4359 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4360 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4361 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4362 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4363 | scoped_refptr<Layer> root = Layer::Create(); |
| 4364 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4365 | scoped_refptr<FakePictureLayer> parent = |
| 4366 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4367 | SetLayerPropertiesForTesting(parent.get(), |
| 4368 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4369 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4370 | gfx::PointF(), |
| 4371 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4372 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4373 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4374 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4375 | scoped_refptr<FakePictureLayer> perspective_surface = |
| 4376 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4377 | SetLayerPropertiesForTesting(perspective_surface.get(), |
| 4378 | perspective_matrix * scale_small_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4379 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4380 | gfx::PointF(2.f, 2.f), |
| 4381 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4382 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4383 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4384 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4385 | scoped_refptr<FakePictureLayer> scale_surface = |
| 4386 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4387 | SetLayerPropertiesForTesting(scale_surface.get(), |
| 4388 | scale_small_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4389 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4390 | gfx::PointF(2.f, 2.f), |
| 4391 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4392 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4393 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4394 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4395 | perspective_surface->SetForceRenderSurface(true); |
| 4396 | scale_surface->SetForceRenderSurface(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4397 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4398 | parent->AddChild(perspective_surface); |
| 4399 | parent->AddChild(scale_surface); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4400 | root->AddChild(parent); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4401 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4402 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4403 | host->SetRootLayer(root); |
| 4404 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4405 | float device_scale_factor = 2.5f; |
| 4406 | float page_scale_factor = 3.f; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4407 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4408 | RenderSurfaceLayerList render_surface_layer_list; |
| 4409 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4410 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 4411 | inputs.device_scale_factor = device_scale_factor; |
| 4412 | inputs.page_scale_factor = page_scale_factor; |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 4413 | inputs.page_scale_application_layer = root.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4414 | inputs.can_adjust_raster_scales = true; |
| 4415 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4416 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4417 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4418 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4419 | perspective_surface); |
| 4420 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4421 | // the nearest render target. Here this includes the layer transform as well |
| 4422 | // as the device and page scale factors. |
| 4423 | gfx::Transform transform = scale_small_matrix; |
| 4424 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4425 | device_scale_factor * page_scale_factor); |
| 4426 | gfx::Vector2dF scales = |
| 4427 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4428 | float max_2d_scale = std::max(scales.x(), scales.y()); |
| 4429 | EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface); |
| 4430 | |
| 4431 | // The ideal scale will draw 1:1 with its render target space along |
| 4432 | // the larger-scale axis. |
| 4433 | gfx::Vector2dF target_space_transform_scales = |
| 4434 | MathUtil::ComputeTransform2dScaleComponents( |
| 4435 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4436 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4437 | std::max(target_space_transform_scales.x(), |
| 4438 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4439 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4440 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4441 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4442 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4443 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4444 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4445 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
| 4446 | parent->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4447 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4448 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4449 | // with the screen, and then scaled during drawing. |
| 4450 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4451 | expected_perspective_surface_draw_transform.Translate( |
| 4452 | device_scale_factor * page_scale_factor * |
| 4453 | perspective_surface->position().x(), |
| 4454 | device_scale_factor * page_scale_factor * |
| 4455 | perspective_surface->position().y()); |
| 4456 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4457 | perspective_matrix); |
| 4458 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4459 | scale_small_matrix); |
| 4460 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4461 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4462 | device_scale_factor * page_scale_factor, |
| 4463 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4464 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4465 | expected_perspective_surface_draw_transform, |
| 4466 | perspective_surface->render_surface()->draw_transform()); |
| 4467 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4468 | expected_perspective_surface_layer_draw_transform, |
| 4469 | perspective_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4470 | } |
| 4471 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4472 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4473 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4474 | LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { |
| 4475 | // Verify draw and screen space transforms of layers not in a surface. |
| 4476 | MockContentLayerClient delegate; |
| 4477 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4478 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4479 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4480 | SetLayerPropertiesForTesting(parent.get(), |
| 4481 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4482 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4483 | gfx::PointF(), |
| 4484 | gfx::Size(133, 133), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4485 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4486 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4487 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4488 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 4489 | SetLayerPropertiesForTesting(child.get(), |
| 4490 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4491 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4492 | gfx::PointF(), |
| 4493 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4494 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4495 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4496 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4497 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4498 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4499 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4500 | identity_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(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4504 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4505 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4506 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4507 | parent->AddChild(child); |
| 4508 | parent->AddChild(child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4509 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4510 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4511 | host->SetRootLayer(parent); |
| 4512 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4513 | float device_scale_factor = 1.7f; |
| 4514 | float page_scale_factor = 1.f; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4515 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4516 | RenderSurfaceLayerList render_surface_layer_list; |
| 4517 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4518 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4519 | inputs.device_scale_factor = device_scale_factor; |
| 4520 | inputs.page_scale_factor = page_scale_factor; |
| 4521 | inputs.page_scale_application_layer = parent.get(); |
| 4522 | inputs.can_adjust_raster_scales = true; |
| 4523 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4524 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4525 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4526 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4527 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4528 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4529 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4530 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4531 | // Verify parent transforms |
| 4532 | gfx::Transform expected_parent_transform; |
| 4533 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4534 | parent->screen_space_transform()); |
| 4535 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4536 | parent->draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4537 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4538 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4539 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4540 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4541 | gfx::RectF parent_draw_rect = |
| 4542 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4543 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4544 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4545 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4546 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4547 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4548 | expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width())); |
| 4549 | expected_parent_draw_rect.set_height( |
| 4550 | ceil(expected_parent_draw_rect.height())); |
| 4551 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4552 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4553 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4554 | // Verify child transforms |
| 4555 | gfx::Transform expected_child_transform; |
| 4556 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4557 | child->draw_transform()); |
| 4558 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4559 | child->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4560 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4561 | // Verify results of transformed child rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4562 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4563 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4564 | gfx::RectF child_draw_rect = |
| 4565 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4566 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4567 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4568 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4569 | gfx::RectF expected_child_draw_rect(child->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4570 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4571 | expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width())); |
| 4572 | expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height())); |
| 4573 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4574 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4575 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4576 | // Verify child_no_scale transforms |
| 4577 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 4578 | // All transforms operate on content rects. The child's content rect |
| 4579 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 4580 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 4581 | device_scale_factor); |
| 4582 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4583 | child_no_scale->draw_transform()); |
| 4584 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4585 | child_no_scale->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4586 | } |
| 4587 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4588 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4589 | TEST_F(LayerTreeHostCommonTest, ContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4590 | MockContentLayerClient delegate; |
| 4591 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4592 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4593 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4594 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4595 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4596 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4597 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4598 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4599 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4600 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4601 | scoped_refptr<Layer> root = Layer::Create(); |
| 4602 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4603 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4604 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4605 | SetLayerPropertiesForTesting(parent.get(), |
| 4606 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4607 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4608 | gfx::PointF(), |
| 4609 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4610 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4611 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4612 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4613 | scoped_refptr<ContentLayer> child_scale = |
| 4614 | CreateDrawableContentLayer(&delegate); |
| 4615 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4616 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4617 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4618 | gfx::PointF(2.f, 2.f), |
| 4619 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4620 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4621 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4622 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4623 | scoped_refptr<ContentLayer> child_empty = |
| 4624 | CreateDrawableContentLayer(&delegate); |
| 4625 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4626 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4627 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4628 | gfx::PointF(2.f, 2.f), |
| 4629 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4630 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4631 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4632 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4633 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4634 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4635 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4636 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4637 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4638 | gfx::PointF(12.f, 12.f), |
| 4639 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4640 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4641 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4642 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4643 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4644 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4645 | parent->AddChild(child_scale); |
| 4646 | parent->AddChild(child_empty); |
| 4647 | parent->AddChild(child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4648 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4649 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4650 | host->SetRootLayer(root); |
| 4651 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4652 | float device_scale_factor = 2.5f; |
| 4653 | float page_scale_factor = 1.f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4654 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4655 | { |
| 4656 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4657 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4658 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4659 | inputs.device_scale_factor = device_scale_factor; |
| 4660 | inputs.page_scale_factor = page_scale_factor; |
| 4661 | inputs.page_scale_application_layer = root.get(); |
| 4662 | inputs.can_adjust_raster_scales = true; |
| 4663 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4664 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4665 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4666 | initial_parent_scale, parent); |
| 4667 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4668 | initial_parent_scale * initial_child_scale, |
| 4669 | child_scale); |
| 4670 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4671 | initial_parent_scale * initial_child_scale, |
| 4672 | child_empty); |
| 4673 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4674 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4675 | // The parent is scaled up and shouldn't need to scale during draw. The |
| 4676 | // child that can scale its contents should also not need to scale during |
| 4677 | // draw. This shouldn't change if the child has empty bounds. The other |
| 4678 | // children should. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4679 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 4680 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
| 4681 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0)); |
| 4682 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1)); |
| 4683 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0)); |
| 4684 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4685 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 4686 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4687 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4688 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4689 | initial_parent_scale * initial_child_scale, |
| 4690 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4691 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4692 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4693 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 4694 | // updated using the initial transform as the raster scale. |
| 4695 | device_scale_factor = 2.25f; |
| 4696 | page_scale_factor = 1.25f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4697 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4698 | { |
| 4699 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4700 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4701 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4702 | inputs.device_scale_factor = device_scale_factor; |
| 4703 | inputs.page_scale_factor = page_scale_factor; |
| 4704 | inputs.page_scale_application_layer = root.get(); |
| 4705 | inputs.can_adjust_raster_scales = true; |
| 4706 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 4707 | |
| 4708 | EXPECT_CONTENTS_SCALE_EQ( |
| 4709 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4710 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4711 | initial_parent_scale * initial_child_scale, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4712 | child_scale); |
| 4713 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4714 | initial_parent_scale * initial_child_scale, |
| 4715 | child_empty); |
| 4716 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4717 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4718 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4719 | // If the transform changes, we expect the raster scale to be reset to 1.0. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4720 | SkMScalar second_child_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4721 | child_scale_matrix.Scale(second_child_scale / initial_child_scale, |
| 4722 | second_child_scale / initial_child_scale); |
| 4723 | child_scale->SetTransform(child_scale_matrix); |
| 4724 | child_empty->SetTransform(child_scale_matrix); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4725 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4726 | { |
| 4727 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4728 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4729 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4730 | inputs.device_scale_factor = device_scale_factor; |
| 4731 | inputs.page_scale_factor = page_scale_factor; |
| 4732 | inputs.page_scale_application_layer = root.get(); |
| 4733 | inputs.can_adjust_raster_scales = true; |
| 4734 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4735 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4736 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4737 | initial_parent_scale, |
| 4738 | parent); |
| 4739 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4740 | child_scale); |
| 4741 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4742 | child_empty); |
| 4743 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4744 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4745 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4746 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 4747 | // updated, but still using 1.0 as the raster scale. |
| 4748 | device_scale_factor = 2.75f; |
| 4749 | page_scale_factor = 1.75f; |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4750 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4751 | { |
| 4752 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4753 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4754 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4755 | inputs.device_scale_factor = device_scale_factor; |
| 4756 | inputs.page_scale_factor = page_scale_factor; |
| 4757 | inputs.page_scale_application_layer = root.get(); |
| 4758 | inputs.can_adjust_raster_scales = true; |
| 4759 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4760 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4761 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4762 | initial_parent_scale, |
| 4763 | parent); |
| 4764 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4765 | child_scale); |
| 4766 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4767 | child_empty); |
| 4768 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4769 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4770 | } |
| 4771 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4772 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4773 | TEST_F(LayerTreeHostCommonTest, |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4774 | ContentsScale_LayerTransformsDontAffectContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4775 | MockContentLayerClient delegate; |
| 4776 | gfx::Transform identity_matrix; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4777 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4778 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4779 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4780 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4781 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4782 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4783 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4784 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4785 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4786 | scoped_refptr<Layer> root = Layer::Create(); |
| 4787 | root->SetBounds(gfx::Size(100, 100)); |
| 4788 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4789 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4790 | SetLayerPropertiesForTesting(parent.get(), |
| 4791 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4792 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4793 | gfx::PointF(), |
| 4794 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4795 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4796 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4797 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4798 | scoped_refptr<ContentLayer> child_scale = |
| 4799 | CreateDrawableContentLayer(&delegate); |
| 4800 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4801 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4802 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4803 | gfx::PointF(2.f, 2.f), |
| 4804 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4805 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4806 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4807 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4808 | scoped_refptr<ContentLayer> child_empty = |
| 4809 | CreateDrawableContentLayer(&delegate); |
| 4810 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4811 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4812 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4813 | gfx::PointF(2.f, 2.f), |
| 4814 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4815 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4816 | true); |
| 4817 | |
| 4818 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4819 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4820 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4821 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4822 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4823 | gfx::PointF(12.f, 12.f), |
| 4824 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4825 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4826 | true); |
| 4827 | |
| 4828 | root->AddChild(parent); |
| 4829 | |
| 4830 | parent->AddChild(child_scale); |
| 4831 | parent->AddChild(child_empty); |
| 4832 | parent->AddChild(child_no_scale); |
| 4833 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4834 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4835 | host->SetRootLayer(root); |
| 4836 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4837 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4838 | |
| 4839 | float device_scale_factor = 2.5f; |
| 4840 | float page_scale_factor = 1.f; |
| 4841 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4842 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4843 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4844 | inputs.device_scale_factor = device_scale_factor; |
| 4845 | inputs.page_scale_factor = page_scale_factor; |
| 4846 | inputs.page_scale_application_layer = root.get(), |
| 4847 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4848 | |
| 4849 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4850 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4851 | child_scale); |
| 4852 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4853 | child_empty); |
| 4854 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4855 | |
| 4856 | // Since the transform scale does not affect contents scale, it should affect |
| 4857 | // the draw transform instead. |
| 4858 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4859 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4860 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4861 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4862 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4863 | child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4864 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4865 | child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4866 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4867 | child_empty->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4868 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4869 | child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4870 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4871 | initial_parent_scale * initial_child_scale, |
| 4872 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4873 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4874 | initial_parent_scale * initial_child_scale, |
| 4875 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4876 | } |
| 4877 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4878 | TEST_F(LayerTreeHostCommonTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4879 | MockContentLayerClient delegate; |
| 4880 | gfx::Transform identity_matrix; |
| 4881 | |
| 4882 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4883 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4884 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4885 | |
| 4886 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4887 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4888 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4889 | |
| 4890 | scoped_refptr<Layer> root = Layer::Create(); |
| 4891 | root->SetBounds(gfx::Size(100, 100)); |
| 4892 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4893 | scoped_refptr<FakePictureLayer> parent = |
| 4894 | CreateDrawablePictureLayer(&delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4895 | SetLayerPropertiesForTesting(parent.get(), |
| 4896 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4897 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4898 | gfx::PointF(), |
| 4899 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4900 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4901 | true); |
| 4902 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4903 | scoped_refptr<FakePictureLayer> child_scale = |
| 4904 | CreateDrawablePictureLayer(&delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4905 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4906 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4907 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4908 | gfx::PointF(2.f, 2.f), |
| 4909 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4910 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4911 | true); |
| 4912 | |
| 4913 | root->AddChild(parent); |
| 4914 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4915 | parent->AddChild(child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4916 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4917 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4918 | host->SetRootLayer(root); |
| 4919 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4920 | float device_scale_factor = 2.5f; |
| 4921 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4922 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4923 | { |
| 4924 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4925 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4926 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4927 | inputs.device_scale_factor = device_scale_factor; |
| 4928 | inputs.page_scale_factor = page_scale_factor; |
| 4929 | inputs.page_scale_application_layer = root.get(); |
| 4930 | inputs.can_adjust_raster_scales = true; |
| 4931 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4932 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4933 | // The ideal scale is able to go below 1. |
| 4934 | float expected_ideal_scale = |
| 4935 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4936 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4937 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4938 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4939 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4940 | initial_parent_scale * initial_child_scale; |
| 4941 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4942 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4943 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4944 | } |
| 4945 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4946 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4947 | MockContentLayerClient delegate; |
| 4948 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4949 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4950 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4951 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4952 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4953 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4954 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4955 | SkMScalar initial_child_scale = 3.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4956 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4957 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4958 | scoped_refptr<Layer> root = Layer::Create(); |
| 4959 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4960 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4961 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4962 | SetLayerPropertiesForTesting(parent.get(), |
| 4963 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4964 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4965 | gfx::PointF(), |
| 4966 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4967 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4968 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4969 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4970 | scoped_refptr<ContentLayer> surface_scale = |
| 4971 | CreateDrawableContentLayer(&delegate); |
| 4972 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 4973 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4974 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4975 | gfx::PointF(2.f, 2.f), |
| 4976 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4977 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4978 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4979 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4980 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 4981 | CreateDrawableContentLayer(&delegate); |
| 4982 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 4983 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4984 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4985 | gfx::PointF(), |
| 4986 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4987 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4988 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4989 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4990 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 4991 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4992 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 4993 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4994 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4995 | gfx::PointF(), |
| 4996 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4997 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4998 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4999 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5000 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 5001 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5002 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 5003 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5004 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5005 | gfx::PointF(12.f, 12.f), |
| 5006 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5007 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5008 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5009 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5010 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 5011 | CreateDrawableContentLayer(&delegate); |
| 5012 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 5013 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5014 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5015 | gfx::PointF(), |
| 5016 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5017 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5018 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5019 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5020 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 5021 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5022 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 5023 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5024 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5025 | gfx::PointF(), |
| 5026 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5027 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5028 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5029 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5030 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5031 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5032 | parent->AddChild(surface_scale); |
| 5033 | parent->AddChild(surface_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5034 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5035 | surface_scale->SetForceRenderSurface(true); |
| 5036 | surface_scale->AddChild(surface_scale_child_scale); |
| 5037 | surface_scale->AddChild(surface_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5038 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5039 | surface_no_scale->SetForceRenderSurface(true); |
| 5040 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 5041 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5042 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5043 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5044 | host->SetRootLayer(root); |
| 5045 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5046 | SkMScalar device_scale_factor = 5; |
| 5047 | SkMScalar page_scale_factor = 7; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5048 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5049 | RenderSurfaceLayerList render_surface_layer_list; |
| 5050 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5051 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5052 | inputs.device_scale_factor = device_scale_factor; |
| 5053 | inputs.page_scale_factor = page_scale_factor; |
| 5054 | inputs.page_scale_application_layer = root.get(); |
| 5055 | inputs.can_adjust_raster_scales = true; |
| 5056 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5057 | |
| 5058 | EXPECT_CONTENTS_SCALE_EQ( |
| 5059 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5060 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5061 | initial_parent_scale * initial_child_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5062 | surface_scale); |
| 5063 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale); |
| 5064 | EXPECT_CONTENTS_SCALE_EQ( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5065 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5066 | initial_child_scale * initial_child_scale, |
| 5067 | surface_scale_child_scale); |
| 5068 | EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale); |
| 5069 | EXPECT_CONTENTS_SCALE_EQ( |
| 5070 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5071 | initial_child_scale * initial_child_scale, |
| 5072 | surface_no_scale_child_scale); |
| 5073 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5074 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5075 | // The parent is scaled up and shouldn't need to scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5076 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 5077 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5078 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5079 | // RenderSurfaces should always be 1:1 with their target. |
| 5080 | EXPECT_FLOAT_EQ( |
| 5081 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5082 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5083 | EXPECT_FLOAT_EQ( |
| 5084 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5085 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5086 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5087 | // The surface_scale can apply contents scale so the layer shouldn't need to |
| 5088 | // scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5089 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 5090 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5091 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5092 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 5093 | // to scale during draw. |
| 5094 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5095 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5096 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5097 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5098 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5099 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 5100 | // to be scaled during draw. |
| 5101 | EXPECT_FLOAT_EQ( |
| 5102 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5103 | initial_child_scale * initial_child_scale, |
| 5104 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5105 | EXPECT_FLOAT_EQ( |
| 5106 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5107 | initial_child_scale * initial_child_scale, |
| 5108 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5109 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5110 | // RenderSurfaces should always be 1:1 with their target. |
| 5111 | EXPECT_FLOAT_EQ( |
| 5112 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5113 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5114 | EXPECT_FLOAT_EQ( |
| 5115 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5116 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5117 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5118 | // The surface_no_scale layer can not apply contents scale, so it needs to be |
| 5119 | // scaled during draw. |
| 5120 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5121 | initial_parent_scale * initial_child_scale, |
| 5122 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5123 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5124 | initial_parent_scale * initial_child_scale, |
| 5125 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5126 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5127 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 5128 | // to scale during draw. |
| 5129 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5130 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5131 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5132 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5133 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5134 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 5135 | // to be scaled during draw. |
| 5136 | EXPECT_FLOAT_EQ( |
| 5137 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5138 | initial_child_scale * initial_child_scale, |
| 5139 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5140 | EXPECT_FLOAT_EQ( |
| 5141 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5142 | initial_child_scale * initial_child_scale, |
| 5143 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5144 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5145 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5146 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5147 | TEST_F(LayerTreeHostCommonTest, |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5148 | ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5149 | MockContentLayerClient delegate; |
| 5150 | gfx::Transform identity_matrix; |
| 5151 | |
| 5152 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5153 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5154 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 5155 | |
| 5156 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5157 | SkMScalar initial_child_scale = 3.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5158 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 5159 | |
| 5160 | scoped_refptr<Layer> root = Layer::Create(); |
| 5161 | root->SetBounds(gfx::Size(100, 100)); |
| 5162 | |
| 5163 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 5164 | SetLayerPropertiesForTesting(parent.get(), |
| 5165 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5166 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5167 | gfx::PointF(), |
| 5168 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5169 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5170 | true); |
| 5171 | |
| 5172 | scoped_refptr<ContentLayer> surface_scale = |
| 5173 | CreateDrawableContentLayer(&delegate); |
| 5174 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 5175 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5176 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5177 | gfx::PointF(2.f, 2.f), |
| 5178 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5179 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5180 | true); |
| 5181 | |
| 5182 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 5183 | CreateDrawableContentLayer(&delegate); |
| 5184 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 5185 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5186 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5187 | gfx::PointF(), |
| 5188 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5189 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5190 | true); |
| 5191 | |
| 5192 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 5193 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5194 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 5195 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5196 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5197 | gfx::PointF(), |
| 5198 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5199 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5200 | true); |
| 5201 | |
| 5202 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 5203 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5204 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 5205 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5206 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5207 | gfx::PointF(12.f, 12.f), |
| 5208 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5209 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5210 | true); |
| 5211 | |
| 5212 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 5213 | CreateDrawableContentLayer(&delegate); |
| 5214 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 5215 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5216 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5217 | gfx::PointF(), |
| 5218 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5219 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5220 | true); |
| 5221 | |
| 5222 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 5223 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5224 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 5225 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5226 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5227 | gfx::PointF(), |
| 5228 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5229 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5230 | true); |
| 5231 | |
| 5232 | root->AddChild(parent); |
| 5233 | |
| 5234 | parent->AddChild(surface_scale); |
| 5235 | parent->AddChild(surface_no_scale); |
| 5236 | |
| 5237 | surface_scale->SetForceRenderSurface(true); |
| 5238 | surface_scale->AddChild(surface_scale_child_scale); |
| 5239 | surface_scale->AddChild(surface_scale_child_no_scale); |
| 5240 | |
| 5241 | surface_no_scale->SetForceRenderSurface(true); |
| 5242 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 5243 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
| 5244 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5245 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5246 | host->SetRootLayer(root); |
| 5247 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5248 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5249 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5250 | SkMScalar device_scale_factor = 5.0; |
| 5251 | SkMScalar page_scale_factor = 7.0; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5252 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5253 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5254 | inputs.device_scale_factor = device_scale_factor; |
| 5255 | inputs.page_scale_factor = page_scale_factor; |
| 5256 | inputs.page_scale_application_layer = root.get(); |
| 5257 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5258 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5259 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5260 | parent); |
| 5261 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5262 | surface_scale); |
| 5263 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale); |
| 5264 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5265 | surface_scale_child_scale); |
| 5266 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale); |
| 5267 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5268 | surface_no_scale_child_scale); |
| 5269 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale); |
| 5270 | |
| 5271 | // The parent is scaled up during draw, since its contents are not scaled by |
| 5272 | // the transform hierarchy. |
| 5273 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5274 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5275 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5276 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5277 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5278 | // The child surface is not scaled up during draw since its subtree is scaled |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5279 | // by the transform hierarchy. |
| 5280 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5281 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5282 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5283 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5284 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5285 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5286 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5287 | // The surface_scale's RenderSurface is not scaled during draw, so the layer |
| 5288 | // needs to be scaled when drawing into its surface. |
| 5289 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 5290 | surface_scale->draw_transform().matrix().get(0, 0)); |
| 5291 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 5292 | surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5293 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5294 | // The surface_scale_child_scale is not scaled when drawing into its surface, |
| 5295 | // since its content bounds are scaled by the transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5296 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5297 | initial_child_scale * initial_child_scale * initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5298 | surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5299 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5300 | initial_child_scale * initial_child_scale * initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5301 | surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5302 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5303 | // The surface_scale_child_no_scale is scaled by the device scale, page scale |
| 5304 | // and transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5305 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5306 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5307 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5308 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5309 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5310 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5311 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5312 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5313 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5314 | // The child surface is not scaled up during draw since its subtree is scaled |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5315 | // by the transform hierarchy. |
| 5316 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5317 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5318 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5319 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5320 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5321 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5322 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5323 | // The surface_no_scale layer has a fixed contents scale of 1, so it needs to |
| 5324 | // be scaled by the device and page scale factors. Its surface is already |
| 5325 | // scaled by the transform hierarchy so those don't need to scale the layer's |
| 5326 | // drawing. |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5327 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale * |
| 5328 | device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5329 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5330 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale * |
| 5331 | device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5332 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5333 | |
| 5334 | // The surface_no_scale_child_scale has its contents scaled by the page and |
| 5335 | // device scale factors, but needs to be scaled by the transform hierarchy |
| 5336 | // when drawing. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5337 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5338 | initial_parent_scale * initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5339 | surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5340 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5341 | initial_parent_scale * initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5342 | surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5343 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5344 | // The surface_no_scale_child_no_scale needs to be scaled by the device and |
| 5345 | // page scale factors and by any transform heirarchy below its target surface. |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5346 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5347 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5348 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5349 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5350 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5351 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5352 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5353 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5354 | } |
| 5355 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5356 | TEST_F(LayerTreeHostCommonTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5357 | MockContentLayerClient delegate; |
| 5358 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5359 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5360 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5361 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5362 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5363 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5364 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5365 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5366 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5367 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5368 | scoped_refptr<Layer> root = Layer::Create(); |
| 5369 | root->SetBounds(gfx::Size(100, 100)); |
| 5370 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5371 | scoped_refptr<FakePictureLayer> parent = |
| 5372 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5373 | SetLayerPropertiesForTesting(parent.get(), |
| 5374 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5375 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5376 | gfx::PointF(), |
| 5377 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5378 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5379 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5380 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5381 | scoped_refptr<FakePictureLayer> child_scale = |
| 5382 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5383 | SetLayerPropertiesForTesting(child_scale.get(), |
| 5384 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5385 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5386 | gfx::PointF(2.f, 2.f), |
| 5387 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5388 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5389 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5390 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5391 | root->AddChild(parent); |
| 5392 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5393 | parent->AddChild(child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5394 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5395 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5396 | host->SetRootLayer(root); |
| 5397 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5398 | { |
| 5399 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5400 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5401 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5402 | inputs.can_adjust_raster_scales = true; |
| 5403 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5404 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5405 | EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); |
| 5406 | // Animating layers compute ideal scale in the same way as when |
| 5407 | // they are static. |
| 5408 | EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, |
| 5409 | child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5410 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5411 | } |
| 5412 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5413 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5414 | TEST_F(LayerTreeHostCommonTest, |
| 5415 | ChangeInContentBoundsOrScaleTriggersPushProperties) { |
| 5416 | MockContentLayerClient delegate; |
| 5417 | scoped_refptr<Layer> root = Layer::Create(); |
| 5418 | scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate); |
| 5419 | root->AddChild(child); |
| 5420 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5421 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5422 | host->SetRootLayer(root); |
| 5423 | |
| 5424 | gfx::Transform identity_matrix; |
| 5425 | SetLayerPropertiesForTesting(root.get(), |
| 5426 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5427 | gfx::Point3F(), |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5428 | gfx::PointF(), |
| 5429 | gfx::Size(100, 100), |
| 5430 | true, |
| 5431 | false); |
| 5432 | SetLayerPropertiesForTesting(child.get(), |
| 5433 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5434 | gfx::Point3F(), |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5435 | gfx::PointF(), |
| 5436 | gfx::Size(100, 100), |
| 5437 | true, |
| 5438 | false); |
| 5439 | |
| 5440 | root->reset_needs_push_properties_for_testing(); |
| 5441 | child->reset_needs_push_properties_for_testing(); |
| 5442 | |
| 5443 | // This will change both layers' content bounds. |
| 5444 | ExecuteCalculateDrawProperties(root.get()); |
| 5445 | EXPECT_TRUE(root->needs_push_properties()); |
| 5446 | EXPECT_TRUE(child->needs_push_properties()); |
| 5447 | |
| 5448 | root->reset_needs_push_properties_for_testing(); |
| 5449 | child->reset_needs_push_properties_for_testing(); |
| 5450 | |
| 5451 | // This will change only the child layer's contents scale and content bounds, |
| 5452 | // since the root layer is not a ContentsScalingLayer. |
| 5453 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 5454 | EXPECT_FALSE(root->needs_push_properties()); |
| 5455 | EXPECT_TRUE(child->needs_push_properties()); |
| 5456 | |
| 5457 | root->reset_needs_push_properties_for_testing(); |
| 5458 | child->reset_needs_push_properties_for_testing(); |
| 5459 | |
| 5460 | // This will not change either layer's contents scale or content bounds. |
| 5461 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 5462 | EXPECT_FALSE(root->needs_push_properties()); |
| 5463 | EXPECT_FALSE(child->needs_push_properties()); |
| 5464 | } |
| 5465 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5466 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5467 | MockContentLayerClient delegate; |
| 5468 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5469 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5470 | scoped_refptr<FakePictureLayer> parent = |
| 5471 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5472 | SetLayerPropertiesForTesting(parent.get(), |
| 5473 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5474 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5475 | gfx::PointF(), |
| 5476 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5477 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5478 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5479 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5480 | scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5481 | SetLayerPropertiesForTesting(child.get(), |
| 5482 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5483 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5484 | gfx::PointF(2.f, 2.f), |
| 5485 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5486 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5487 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5488 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5489 | gfx::Transform replica_transform; |
| 5490 | replica_transform.Scale(1.0, -1.0); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5491 | scoped_refptr<FakePictureLayer> replica = |
| 5492 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5493 | SetLayerPropertiesForTesting(replica.get(), |
| 5494 | replica_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5495 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5496 | gfx::PointF(2.f, 2.f), |
| 5497 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5498 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5499 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5500 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5501 | // This layer should end up in the same surface as child, with the same draw |
| 5502 | // and screen space transforms. |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5503 | scoped_refptr<FakePictureLayer> duplicate_child_non_owner = |
| 5504 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5505 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 5506 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5507 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5508 | gfx::PointF(), |
| 5509 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5510 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5511 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5512 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5513 | parent->AddChild(child); |
| 5514 | child->AddChild(duplicate_child_non_owner); |
| 5515 | child->SetReplicaLayer(replica.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5516 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5517 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5518 | host->SetRootLayer(parent); |
| 5519 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5520 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5521 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5522 | float device_scale_factor = 1.5f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5523 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5524 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5525 | inputs.device_scale_factor = device_scale_factor; |
| 5526 | inputs.can_adjust_raster_scales = true; |
| 5527 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5528 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5529 | // We should have two render surfaces. The root's render surface and child's |
| 5530 | // render surface (it needs one because it has a replica layer). |
| 5531 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5532 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5533 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5534 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5535 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5536 | parent->screen_space_transform()); |
| 5537 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5538 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5539 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5540 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5541 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5542 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
| 5543 | child->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5544 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5545 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5546 | expected_screen_space_transform.Scale(device_scale_factor, |
| 5547 | device_scale_factor); |
| 5548 | expected_screen_space_transform.Translate(child->position().x(), |
| 5549 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5550 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 5551 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5552 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5553 | gfx::Transform expected_duplicate_child_draw_transform = |
| 5554 | child->draw_transform(); |
| 5555 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), |
| 5556 | duplicate_child_non_owner->draw_transform()); |
| 5557 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5558 | child->screen_space_transform(), |
| 5559 | duplicate_child_non_owner->screen_space_transform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 5560 | EXPECT_EQ(child->drawable_content_rect(), |
| 5561 | duplicate_child_non_owner->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5562 | EXPECT_EQ(child->content_bounds(), |
| 5563 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5564 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5565 | gfx::Transform expected_render_surface_draw_transform; |
| 5566 | expected_render_surface_draw_transform.Translate( |
| 5567 | device_scale_factor * child->position().x(), |
| 5568 | device_scale_factor * child->position().y()); |
| 5569 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 5570 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5571 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5572 | gfx::Transform expected_surface_draw_transform; |
| 5573 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 5574 | device_scale_factor * 2.f); |
| 5575 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 5576 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5577 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5578 | gfx::Transform expected_surface_screen_space_transform; |
| 5579 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 5580 | device_scale_factor * 2.f); |
| 5581 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5582 | expected_surface_screen_space_transform, |
| 5583 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5584 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5585 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5586 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 5587 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 5588 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5589 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5590 | expected_replica_draw_transform, |
| 5591 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5592 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5593 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5594 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 5595 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 5596 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5597 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5598 | expected_replica_screen_space_transform, |
| 5599 | child->render_surface()->replica_screen_space_transform()); |
| 5600 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5601 | expected_replica_screen_space_transform, |
| 5602 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5603 | } |
| 5604 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5605 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5606 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
| 5607 | MockContentLayerClient delegate; |
| 5608 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5609 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5610 | scoped_refptr<FakePictureLayer> parent = |
| 5611 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5612 | SetLayerPropertiesForTesting(parent.get(), |
| 5613 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5614 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5615 | gfx::PointF(), |
| 5616 | gfx::Size(33, 31), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5617 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5618 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5619 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5620 | scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5621 | SetLayerPropertiesForTesting(child.get(), |
| 5622 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5623 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5624 | gfx::PointF(), |
| 5625 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5626 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5627 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5628 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5629 | gfx::Transform replica_transform; |
| 5630 | replica_transform.Scale(1.0, -1.0); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5631 | scoped_refptr<FakePictureLayer> replica = |
| 5632 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5633 | SetLayerPropertiesForTesting(replica.get(), |
| 5634 | replica_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5635 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5636 | gfx::PointF(), |
| 5637 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5638 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5639 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5640 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5641 | parent->AddChild(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5642 | child->SetReplicaLayer(replica.get()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5643 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5644 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5645 | host->SetRootLayer(parent); |
| 5646 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 5647 | float device_scale_factor = 1.7f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5648 | |
| 5649 | RenderSurfaceLayerList render_surface_layer_list; |
| 5650 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5651 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5652 | inputs.device_scale_factor = device_scale_factor; |
| 5653 | inputs.can_adjust_raster_scales = true; |
| 5654 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5655 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5656 | // We should have two render surfaces. The root's render surface and child's |
| 5657 | // render surface (it needs one because it has a replica layer). |
| 5658 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5659 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5660 | gfx::Transform identity_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5661 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5662 | child->render_surface()->draw_transform()); |
| 5663 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5664 | child->render_surface()->draw_transform()); |
| 5665 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5666 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5667 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5668 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5669 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5670 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5671 | expected_replica_draw_transform, |
| 5672 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5673 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5674 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5675 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5676 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5677 | expected_replica_screen_space_transform, |
| 5678 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5679 | } |
| 5680 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5681 | TEST_F(LayerTreeHostCommonTest, SubtreeSearch) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5682 | scoped_refptr<Layer> root = Layer::Create(); |
| 5683 | scoped_refptr<Layer> child = Layer::Create(); |
| 5684 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5685 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 5686 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5687 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5688 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 5689 | child->AddChild(grand_child.get()); |
| 5690 | child->SetMaskLayer(mask_layer.get()); |
| 5691 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5692 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5693 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5694 | host->SetRootLayer(root); |
| 5695 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5696 | int nonexistent_id = -1; |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5697 | EXPECT_EQ(root.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5698 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id())); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5699 | EXPECT_EQ(child.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5700 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id())); |
| 5701 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5702 | grand_child.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5703 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id())); |
| 5704 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5705 | mask_layer.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5706 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id())); |
| 5707 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5708 | replica_layer.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5709 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id())); |
| 5710 | EXPECT_EQ( |
| 5711 | 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5712 | } |
| 5713 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5714 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5715 | scoped_refptr<Layer> root = Layer::Create(); |
| 5716 | scoped_refptr<Layer> child = Layer::Create(); |
| 5717 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 5718 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5719 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5720 | const gfx::Transform identity_matrix; |
| 5721 | SetLayerPropertiesForTesting(root.get(), |
| 5722 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5723 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5724 | gfx::PointF(), |
| 5725 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5726 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5727 | false); |
| 5728 | SetLayerPropertiesForTesting(child.get(), |
| 5729 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5730 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5731 | gfx::PointF(), |
| 5732 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5733 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5734 | false); |
| 5735 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5736 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5737 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5738 | gfx::PointF(), |
| 5739 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5740 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5741 | false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5742 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5743 | root->AddChild(child); |
| 5744 | child->AddChild(grand_child); |
| 5745 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5746 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5747 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5748 | host->SetRootLayer(root); |
| 5749 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5750 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5751 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5752 | EXPECT_FALSE(child->render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5753 | } |
| 5754 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5755 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5756 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5757 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5758 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5759 | host_impl.CreatePendingTree(); |
| 5760 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5761 | |
| 5762 | const gfx::Transform identity_matrix; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5763 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5764 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5765 | false); |
| 5766 | root->SetDrawsContent(true); |
| 5767 | |
| 5768 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5769 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5770 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5771 | false); |
| 5772 | child->SetDrawsContent(true); |
| 5773 | child->SetOpacity(0.0f); |
| 5774 | |
| 5775 | // Add opacity animation. |
| 5776 | AddOpacityTransitionToController( |
| 5777 | child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false); |
| 5778 | |
| 5779 | root->AddChild(child.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5780 | root->SetHasRenderSurface(true); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5781 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5782 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5783 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5784 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5785 | inputs.can_adjust_raster_scales = true; |
| 5786 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5787 | |
| 5788 | // We should have one render surface and two layers. The child |
| 5789 | // layer should be included even though it is transparent. |
| 5790 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5791 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 5792 | } |
| 5793 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5794 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5795 | class LCDTextTest |
| 5796 | : public LayerTreeHostCommonTestBase, |
| 5797 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5798 | public: |
| 5799 | LCDTextTest() |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5800 | : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_), |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5801 | root_(nullptr), |
| 5802 | child_(nullptr), |
| 5803 | grand_child_(nullptr) {} |
| 5804 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5805 | protected: |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 5806 | void SetUp() override { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5807 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5808 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5809 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5810 | scoped_ptr<LayerImpl> root_ptr = |
| 5811 | LayerImpl::Create(host_impl_.active_tree(), 1); |
| 5812 | scoped_ptr<LayerImpl> child_ptr = |
| 5813 | LayerImpl::Create(host_impl_.active_tree(), 2); |
| 5814 | scoped_ptr<LayerImpl> grand_child_ptr = |
| 5815 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 5816 | |
| 5817 | // Stash raw pointers to look at later. |
| 5818 | root_ = root_ptr.get(); |
| 5819 | child_ = child_ptr.get(); |
| 5820 | grand_child_ = grand_child_ptr.get(); |
| 5821 | |
| 5822 | child_->AddChild(grand_child_ptr.Pass()); |
| 5823 | root_->AddChild(child_ptr.Pass()); |
| 5824 | host_impl_.active_tree()->SetRootLayer(root_ptr.Pass()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5825 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5826 | root_->SetContentsOpaque(true); |
| 5827 | child_->SetContentsOpaque(true); |
| 5828 | grand_child_->SetContentsOpaque(true); |
| 5829 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5830 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5831 | SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(), |
| 5832 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5833 | true); |
| 5834 | SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(), |
| 5835 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5836 | std::tr1::get<2>(GetParam())); |
| 5837 | SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(), |
| 5838 | gfx::PointF(), gfx::Size(1, 1), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5839 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5840 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5841 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5842 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5843 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5844 | |
| 5845 | FakeImplProxy proxy_; |
| 5846 | TestSharedBitmapManager shared_bitmap_manager_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5847 | TestTaskGraphRunner task_graph_runner_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5848 | FakeLayerTreeHostImpl host_impl_; |
| 5849 | |
| 5850 | LayerImpl* root_; |
| 5851 | LayerImpl* child_; |
| 5852 | LayerImpl* grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5853 | }; |
| 5854 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5855 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5856 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5857 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5858 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5859 | // Case 1: Identity transform. |
| 5860 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5861 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5862 | layers_always_allowed_lcd_text_); |
| 5863 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5864 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5865 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5866 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5867 | // Case 2: Integral translation. |
| 5868 | gfx::Transform integral_translation; |
| 5869 | integral_translation.Translate(1.0, 2.0); |
| 5870 | child_->SetTransform(integral_translation); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5871 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5872 | layers_always_allowed_lcd_text_); |
| 5873 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5874 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5875 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5876 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5877 | // Case 3: Non-integral translation. |
| 5878 | gfx::Transform non_integral_translation; |
| 5879 | non_integral_translation.Translate(1.5, 2.5); |
| 5880 | child_->SetTransform(non_integral_translation); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5881 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5882 | layers_always_allowed_lcd_text_); |
| 5883 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5884 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5885 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5886 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5887 | // Case 4: Rotation. |
| 5888 | gfx::Transform rotation; |
| 5889 | rotation.Rotate(10.0); |
| 5890 | child_->SetTransform(rotation); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5891 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5892 | layers_always_allowed_lcd_text_); |
| 5893 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5894 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5895 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5896 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5897 | // Case 5: Scale. |
| 5898 | gfx::Transform scale; |
| 5899 | scale.Scale(2.0, 2.0); |
| 5900 | child_->SetTransform(scale); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5901 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5902 | layers_always_allowed_lcd_text_); |
| 5903 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5904 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5905 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5906 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5907 | // Case 6: Skew. |
| 5908 | gfx::Transform skew; |
| 5909 | skew.SkewX(10.0); |
| 5910 | child_->SetTransform(skew); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5911 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5912 | layers_always_allowed_lcd_text_); |
| 5913 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5914 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5915 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5916 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5917 | // Case 7: Translucent. |
| 5918 | child_->SetTransform(identity_matrix); |
| 5919 | child_->SetOpacity(0.5f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5920 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5921 | layers_always_allowed_lcd_text_); |
| 5922 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5923 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5924 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5925 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5926 | // Case 8: Sanity check: restore transform and opacity. |
| 5927 | child_->SetTransform(identity_matrix); |
| 5928 | child_->SetOpacity(1.f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5929 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5930 | layers_always_allowed_lcd_text_); |
| 5931 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5932 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5933 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5934 | |
| 5935 | // Case 9: Non-opaque content. |
| 5936 | child_->SetContentsOpaque(false); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5937 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5938 | layers_always_allowed_lcd_text_); |
| 5939 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5940 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5941 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
| 5942 | |
| 5943 | // Case 10: Sanity check: restore content opaqueness. |
| 5944 | child_->SetContentsOpaque(true); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5945 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5946 | layers_always_allowed_lcd_text_); |
| 5947 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5948 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5949 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5950 | } |
| 5951 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5952 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5953 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5954 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5955 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5956 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5957 | layers_always_allowed_lcd_text_); |
| 5958 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5959 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5960 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5961 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5962 | // Add opacity animation. |
| 5963 | child_->SetOpacity(0.9f); |
| 5964 | AddOpacityTransitionToController( |
| 5965 | child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5966 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5967 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5968 | layers_always_allowed_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5969 | // Text AA should not be adjusted while animation is active. |
| 5970 | // Make sure LCD text AA setting remains unchanged. |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5971 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5972 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5973 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5977 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5978 | testing::Combine(testing::Bool(), |
| 5979 | testing::Bool(), |
| 5980 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5981 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5982 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5983 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5984 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5985 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5986 | host_impl.CreatePendingTree(); |
| 5987 | const gfx::Transform identity_matrix; |
| 5988 | |
| 5989 | scoped_refptr<Layer> root = Layer::Create(); |
| 5990 | SetLayerPropertiesForTesting(root.get(), |
| 5991 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5992 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5993 | gfx::PointF(), |
| 5994 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5995 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5996 | false); |
| 5997 | root->SetIsDrawable(true); |
| 5998 | |
| 5999 | scoped_refptr<Layer> child = Layer::Create(); |
| 6000 | SetLayerPropertiesForTesting(child.get(), |
| 6001 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6002 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6003 | gfx::PointF(), |
| 6004 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6005 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6006 | false); |
| 6007 | child->SetIsDrawable(true); |
| 6008 | |
| 6009 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 6010 | SetLayerPropertiesForTesting(grand_child.get(), |
| 6011 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6012 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6013 | gfx::PointF(), |
| 6014 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6015 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6016 | false); |
| 6017 | grand_child->SetIsDrawable(true); |
| 6018 | grand_child->SetHideLayerAndSubtree(true); |
| 6019 | |
| 6020 | child->AddChild(grand_child); |
| 6021 | root->AddChild(child); |
| 6022 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6023 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6024 | host->SetRootLayer(root); |
| 6025 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6026 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6027 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6028 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6029 | inputs.can_adjust_raster_scales = true; |
| 6030 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6031 | |
| 6032 | // We should have one render surface and two layers. The grand child has |
| 6033 | // hidden itself. |
| 6034 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6035 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6036 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 6037 | EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6038 | } |
| 6039 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6040 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6041 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6042 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6043 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6044 | host_impl.CreatePendingTree(); |
| 6045 | const gfx::Transform identity_matrix; |
| 6046 | |
| 6047 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6048 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 6049 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6050 | false); |
| 6051 | root->SetDrawsContent(true); |
| 6052 | |
| 6053 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6054 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 6055 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6056 | false); |
| 6057 | child->SetDrawsContent(true); |
| 6058 | |
| 6059 | scoped_ptr<LayerImpl> grand_child = |
| 6060 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6061 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 6062 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6063 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6064 | grand_child->SetDrawsContent(true); |
| 6065 | grand_child->SetHideLayerAndSubtree(true); |
| 6066 | |
| 6067 | child->AddChild(grand_child.Pass()); |
| 6068 | root->AddChild(child.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6069 | root->SetHasRenderSurface(true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6070 | |
| 6071 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6072 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6073 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6074 | inputs.can_adjust_raster_scales = true; |
| 6075 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6076 | |
| 6077 | // We should have one render surface and two layers. The grand child has |
| 6078 | // hidden itself. |
| 6079 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6080 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6081 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
| 6082 | EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6083 | } |
| 6084 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6085 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6086 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6087 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6088 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6089 | host_impl.CreatePendingTree(); |
| 6090 | const gfx::Transform identity_matrix; |
| 6091 | |
| 6092 | scoped_refptr<Layer> root = Layer::Create(); |
| 6093 | SetLayerPropertiesForTesting(root.get(), |
| 6094 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6095 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6096 | gfx::PointF(), |
| 6097 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6098 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6099 | false); |
| 6100 | root->SetIsDrawable(true); |
| 6101 | |
| 6102 | scoped_refptr<Layer> child = Layer::Create(); |
| 6103 | SetLayerPropertiesForTesting(child.get(), |
| 6104 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6105 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6106 | gfx::PointF(), |
| 6107 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6108 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6109 | false); |
| 6110 | child->SetIsDrawable(true); |
| 6111 | child->SetHideLayerAndSubtree(true); |
| 6112 | |
| 6113 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 6114 | SetLayerPropertiesForTesting(grand_child.get(), |
| 6115 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6116 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6117 | gfx::PointF(), |
| 6118 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6119 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6120 | false); |
| 6121 | grand_child->SetIsDrawable(true); |
| 6122 | |
| 6123 | child->AddChild(grand_child); |
| 6124 | root->AddChild(child); |
| 6125 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6126 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6127 | host->SetRootLayer(root); |
| 6128 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6129 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6130 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6131 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6132 | inputs.can_adjust_raster_scales = true; |
| 6133 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6134 | |
| 6135 | // We should have one render surface and one layers. The child has |
| 6136 | // hidden itself and the grand child. |
| 6137 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6138 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6139 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6140 | } |
| 6141 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6142 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6143 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6144 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6145 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6146 | host_impl.CreatePendingTree(); |
| 6147 | const gfx::Transform identity_matrix; |
| 6148 | |
| 6149 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6150 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 6151 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6152 | true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6153 | root->SetDrawsContent(true); |
| 6154 | |
| 6155 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6156 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 6157 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6158 | false); |
| 6159 | child->SetDrawsContent(true); |
| 6160 | child->SetHideLayerAndSubtree(true); |
| 6161 | |
| 6162 | scoped_ptr<LayerImpl> grand_child = |
| 6163 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6164 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 6165 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6166 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6167 | grand_child->SetDrawsContent(true); |
| 6168 | |
| 6169 | child->AddChild(grand_child.Pass()); |
| 6170 | root->AddChild(child.Pass()); |
| 6171 | |
| 6172 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6173 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6174 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6175 | inputs.can_adjust_raster_scales = true; |
| 6176 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6177 | |
| 6178 | // We should have one render surface and one layers. The child has |
| 6179 | // hidden itself and the grand child. |
| 6180 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6181 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6182 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6183 | } |
| 6184 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6185 | void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 6186 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6187 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6188 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6189 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6190 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6191 | host_impl.CreatePendingTree(); |
| 6192 | const gfx::Transform identity_matrix; |
| 6193 | |
| 6194 | scoped_refptr<Layer> root = Layer::Create(); |
| 6195 | SetLayerPropertiesForTesting(root.get(), |
| 6196 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6197 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6198 | gfx::PointF(), |
| 6199 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6200 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6201 | false); |
| 6202 | root->SetIsDrawable(true); |
| 6203 | |
| 6204 | scoped_refptr<Layer> copy_grand_parent = Layer::Create(); |
| 6205 | SetLayerPropertiesForTesting(copy_grand_parent.get(), |
| 6206 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6207 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6208 | gfx::PointF(), |
| 6209 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6210 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6211 | false); |
| 6212 | copy_grand_parent->SetIsDrawable(true); |
| 6213 | |
| 6214 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 6215 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 6216 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6217 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6218 | gfx::PointF(), |
| 6219 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6220 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6221 | false); |
| 6222 | copy_parent->SetIsDrawable(true); |
| 6223 | copy_parent->SetForceRenderSurface(true); |
| 6224 | |
| 6225 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 6226 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 6227 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6228 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6229 | gfx::PointF(), |
| 6230 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6231 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6232 | false); |
| 6233 | copy_layer->SetIsDrawable(true); |
| 6234 | |
| 6235 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 6236 | SetLayerPropertiesForTesting(copy_child.get(), |
| 6237 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6238 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6239 | gfx::PointF(), |
| 6240 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6241 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6242 | false); |
| 6243 | copy_child->SetIsDrawable(true); |
| 6244 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6245 | scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create(); |
| 6246 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
| 6247 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6248 | gfx::Point3F(), |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6249 | gfx::PointF(), |
| 6250 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6251 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6252 | false); |
| 6253 | copy_grand_parent_sibling_before->SetIsDrawable(true); |
| 6254 | |
| 6255 | scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create(); |
| 6256 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
| 6257 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6258 | gfx::Point3F(), |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6259 | gfx::PointF(), |
| 6260 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6261 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6262 | false); |
| 6263 | copy_grand_parent_sibling_after->SetIsDrawable(true); |
| 6264 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6265 | copy_layer->AddChild(copy_child); |
| 6266 | copy_parent->AddChild(copy_layer); |
| 6267 | copy_grand_parent->AddChild(copy_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6268 | root->AddChild(copy_grand_parent_sibling_before); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6269 | root->AddChild(copy_grand_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6270 | root->AddChild(copy_grand_parent_sibling_after); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6271 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6272 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6273 | host->SetRootLayer(root); |
| 6274 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6275 | // Hide the copy_grand_parent and its subtree. But make a copy request in that |
| 6276 | // hidden subtree on copy_layer. |
| 6277 | copy_grand_parent->SetHideLayerAndSubtree(true); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6278 | copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true); |
| 6279 | copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6280 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 6281 | base::Bind(&EmptyCopyOutputCallback))); |
| 6282 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 6283 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6284 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6285 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6286 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6287 | inputs.can_adjust_raster_scales = true; |
| 6288 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6289 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6290 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request); |
| 6291 | EXPECT_TRUE(copy_grand_parent->draw_properties(). |
| 6292 | layer_or_descendant_has_copy_request); |
| 6293 | EXPECT_TRUE(copy_parent->draw_properties(). |
| 6294 | layer_or_descendant_has_copy_request); |
| 6295 | EXPECT_TRUE(copy_layer->draw_properties(). |
| 6296 | layer_or_descendant_has_copy_request); |
| 6297 | EXPECT_FALSE(copy_child->draw_properties(). |
| 6298 | layer_or_descendant_has_copy_request); |
| 6299 | EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties(). |
| 6300 | layer_or_descendant_has_copy_request); |
| 6301 | EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties(). |
| 6302 | layer_or_descendant_has_copy_request); |
| 6303 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6304 | // We should have three render surfaces, one for the root, one for the parent |
| 6305 | // since it owns a surface, and one for the copy_layer. |
| 6306 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6307 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 6308 | EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id()); |
| 6309 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6310 | |
| 6311 | // The root render surface should have 2 contributing layers. The |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6312 | // copy_grand_parent is hidden along with its siblings, but the copy_parent |
| 6313 | // will appear since something in its subtree needs to be drawn for a copy |
| 6314 | // request. |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6315 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6316 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 6317 | EXPECT_EQ(copy_parent->id(), |
| 6318 | root->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6319 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 6320 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6321 | // appear in its list, since it needs to be drawn for the copy request. |
| 6322 | ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size()); |
| 6323 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6324 | copy_parent->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6325 | |
| 6326 | // The copy_layer's render surface should have two contributing layers. |
| 6327 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 6328 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6329 | copy_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6330 | EXPECT_EQ(copy_child->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6331 | copy_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6332 | } |
| 6333 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6334 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6335 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6336 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6337 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6338 | host_impl.CreatePendingTree(); |
| 6339 | const gfx::Transform identity_matrix; |
| 6340 | |
| 6341 | scoped_refptr<Layer> root = Layer::Create(); |
| 6342 | SetLayerPropertiesForTesting(root.get(), |
| 6343 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6344 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6345 | gfx::PointF(), |
| 6346 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6347 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6348 | false); |
| 6349 | root->SetIsDrawable(true); |
| 6350 | |
| 6351 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 6352 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 6353 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6354 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6355 | gfx::PointF(), |
| 6356 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6357 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6358 | false); |
| 6359 | copy_parent->SetIsDrawable(true); |
| 6360 | copy_parent->SetMasksToBounds(true); |
| 6361 | |
| 6362 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 6363 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 6364 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6365 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6366 | gfx::PointF(), |
| 6367 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6368 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6369 | false); |
| 6370 | copy_layer->SetIsDrawable(true); |
| 6371 | |
| 6372 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 6373 | SetLayerPropertiesForTesting(copy_child.get(), |
| 6374 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6375 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6376 | gfx::PointF(), |
| 6377 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6378 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6379 | false); |
| 6380 | copy_child->SetIsDrawable(true); |
| 6381 | |
| 6382 | copy_layer->AddChild(copy_child); |
| 6383 | copy_parent->AddChild(copy_layer); |
| 6384 | root->AddChild(copy_parent); |
| 6385 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6386 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6387 | host->SetRootLayer(root); |
| 6388 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6389 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 6390 | base::Bind(&EmptyCopyOutputCallback))); |
| 6391 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 6392 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6393 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6394 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6395 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6396 | inputs.can_adjust_raster_scales = true; |
| 6397 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6398 | |
| 6399 | // We should have one render surface, as the others are clipped out. |
| 6400 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6401 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6402 | |
| 6403 | // The root render surface should only have 1 contributing layer, since the |
| 6404 | // other layers are empty/clipped away. |
| 6405 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6406 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6407 | } |
| 6408 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6409 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
| 6410 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6411 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6412 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6413 | host_impl.CreatePendingTree(); |
| 6414 | const gfx::Transform identity_matrix; |
| 6415 | |
| 6416 | scoped_refptr<Layer> root = Layer::Create(); |
| 6417 | SetLayerPropertiesForTesting(root.get(), |
| 6418 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6419 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6420 | gfx::PointF(), |
| 6421 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6422 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6423 | false); |
| 6424 | root->SetIsDrawable(true); |
| 6425 | |
| 6426 | // The surface is moved slightly outside of the viewport. |
| 6427 | scoped_refptr<Layer> surface = Layer::Create(); |
| 6428 | SetLayerPropertiesForTesting(surface.get(), |
| 6429 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6430 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6431 | gfx::PointF(-10, -20), |
| 6432 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6433 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6434 | false); |
| 6435 | surface->SetForceRenderSurface(true); |
| 6436 | |
| 6437 | scoped_refptr<Layer> surface_child = Layer::Create(); |
| 6438 | SetLayerPropertiesForTesting(surface_child.get(), |
| 6439 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6440 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6441 | gfx::PointF(), |
| 6442 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6443 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6444 | false); |
| 6445 | surface_child->SetIsDrawable(true); |
| 6446 | |
| 6447 | surface->AddChild(surface_child); |
| 6448 | root->AddChild(surface); |
| 6449 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6450 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6451 | host->SetRootLayer(root); |
| 6452 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6453 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6454 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6455 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6456 | inputs.can_adjust_raster_scales = true; |
| 6457 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6458 | |
| 6459 | // The visible_content_rect for the |surface_child| should not be clipped by |
| 6460 | // the viewport. |
| 6461 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 6462 | surface_child->visible_content_rect().ToString()); |
| 6463 | } |
| 6464 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6465 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 6466 | // Ensure that a transform between the layer and its render surface is not a |
| 6467 | // problem. Constructs the following layer tree. |
| 6468 | // |
| 6469 | // root (a render surface) |
| 6470 | // + render_surface |
| 6471 | // + clip_parent (scaled) |
| 6472 | // + intervening_clipping_layer |
| 6473 | // + clip_child |
| 6474 | // |
| 6475 | // The render surface should be resized correctly and the clip child should |
| 6476 | // inherit the right clip rect. |
| 6477 | scoped_refptr<Layer> root = Layer::Create(); |
| 6478 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 6479 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6480 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6481 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6482 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6483 | |
| 6484 | root->AddChild(render_surface); |
| 6485 | render_surface->AddChild(clip_parent); |
| 6486 | clip_parent->AddChild(intervening); |
| 6487 | intervening->AddChild(clip_child); |
| 6488 | |
| 6489 | clip_child->SetClipParent(clip_parent.get()); |
| 6490 | |
| 6491 | intervening->SetMasksToBounds(true); |
| 6492 | clip_parent->SetMasksToBounds(true); |
| 6493 | |
| 6494 | render_surface->SetForceRenderSurface(true); |
| 6495 | |
| 6496 | gfx::Transform scale_transform; |
| 6497 | scale_transform.Scale(2, 2); |
| 6498 | |
| 6499 | gfx::Transform identity_transform; |
| 6500 | |
| 6501 | SetLayerPropertiesForTesting(root.get(), |
| 6502 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6503 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6504 | gfx::PointF(), |
| 6505 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6506 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6507 | false); |
| 6508 | SetLayerPropertiesForTesting(render_surface.get(), |
| 6509 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6510 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6511 | gfx::PointF(), |
| 6512 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6513 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6514 | false); |
| 6515 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6516 | scale_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6517 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6518 | gfx::PointF(1.f, 1.f), |
| 6519 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6520 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6521 | false); |
| 6522 | SetLayerPropertiesForTesting(intervening.get(), |
| 6523 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6524 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6525 | gfx::PointF(1.f, 1.f), |
| 6526 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6527 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6528 | false); |
| 6529 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6530 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6531 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6532 | gfx::PointF(1.f, 1.f), |
| 6533 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6534 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6535 | false); |
| 6536 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6537 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6538 | host->SetRootLayer(root); |
| 6539 | |
| 6540 | ExecuteCalculateDrawProperties(root.get()); |
| 6541 | |
| 6542 | ASSERT_TRUE(root->render_surface()); |
| 6543 | ASSERT_TRUE(render_surface->render_surface()); |
| 6544 | |
| 6545 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 6546 | // by the intervening clip layer. |
| 6547 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
| 6548 | clip_parent->clip_rect().ToString()); |
| 6549 | ASSERT_EQ(clip_parent->clip_rect().ToString(), |
| 6550 | clip_child->clip_rect().ToString()); |
| 6551 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(), |
| 6552 | intervening->clip_rect().ToString()); |
| 6553 | |
| 6554 | // Ensure that the render surface reports a content rect that has been grown |
| 6555 | // to accomodate for the clip child. |
| 6556 | ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(), |
| 6557 | render_surface->render_surface()->content_rect().ToString()); |
| 6558 | |
| 6559 | // The above check implies the two below, but they nicely demonstrate that |
| 6560 | // we've grown, despite the intervening layer's clip. |
| 6561 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 6562 | render_surface->render_surface()->content_rect())); |
| 6563 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 6564 | render_surface->render_surface()->content_rect())); |
| 6565 | } |
| 6566 | |
| 6567 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 6568 | // Ensure that intervening render surfaces are not a problem in the basic |
| 6569 | // case. In the following tree, both render surfaces should be resized to |
| 6570 | // accomodate for the clip child, despite an intervening clip. |
| 6571 | // |
| 6572 | // root (a render surface) |
| 6573 | // + clip_parent (masks to bounds) |
| 6574 | // + render_surface1 (sets opacity) |
| 6575 | // + intervening (masks to bounds) |
| 6576 | // + render_surface2 (also sets opacity) |
| 6577 | // + clip_child |
| 6578 | // |
| 6579 | scoped_refptr<Layer> root = Layer::Create(); |
| 6580 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6581 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6582 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6583 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6584 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6585 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6586 | |
| 6587 | root->AddChild(clip_parent); |
| 6588 | clip_parent->AddChild(render_surface1); |
| 6589 | render_surface1->AddChild(intervening); |
| 6590 | intervening->AddChild(render_surface2); |
| 6591 | render_surface2->AddChild(clip_child); |
| 6592 | |
| 6593 | clip_child->SetClipParent(clip_parent.get()); |
| 6594 | |
| 6595 | intervening->SetMasksToBounds(true); |
| 6596 | clip_parent->SetMasksToBounds(true); |
| 6597 | |
| 6598 | render_surface1->SetForceRenderSurface(true); |
| 6599 | render_surface2->SetForceRenderSurface(true); |
| 6600 | |
| 6601 | gfx::Transform translation_transform; |
| 6602 | translation_transform.Translate(2, 2); |
| 6603 | |
| 6604 | gfx::Transform identity_transform; |
| 6605 | SetLayerPropertiesForTesting(root.get(), |
| 6606 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6607 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6608 | gfx::PointF(), |
| 6609 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6610 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6611 | false); |
| 6612 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6613 | translation_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6614 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6615 | gfx::PointF(1.f, 1.f), |
| 6616 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6617 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6618 | false); |
| 6619 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6620 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6621 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6622 | gfx::PointF(), |
| 6623 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6624 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6625 | false); |
| 6626 | SetLayerPropertiesForTesting(intervening.get(), |
| 6627 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6628 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6629 | gfx::PointF(1.f, 1.f), |
| 6630 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6631 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6632 | false); |
| 6633 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6634 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6635 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6636 | gfx::PointF(), |
| 6637 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6638 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6639 | false); |
| 6640 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6641 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6642 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6643 | gfx::PointF(-10.f, -10.f), |
| 6644 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6645 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6646 | false); |
| 6647 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6648 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6649 | host->SetRootLayer(root); |
| 6650 | |
| 6651 | ExecuteCalculateDrawProperties(root.get()); |
| 6652 | |
| 6653 | EXPECT_TRUE(root->render_surface()); |
| 6654 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6655 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6656 | |
| 6657 | // Since the render surfaces could have expanded, they should not clip (their |
| 6658 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6659 | // in this case. |
| 6660 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6661 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6662 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6663 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6664 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6665 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6666 | |
| 6667 | // NB: clip rects are in target space. |
| 6668 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6669 | render_surface1->clip_rect().ToString()); |
| 6670 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6671 | |
| 6672 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6673 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6674 | render_surface2->clip_rect().ToString()); |
| 6675 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6676 | |
| 6677 | // The content rects of both render surfaces should both have expanded to |
| 6678 | // contain the clip child. |
| 6679 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6680 | render_surface1->render_surface()->content_rect().ToString()); |
| 6681 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6682 | render_surface2->render_surface()->content_rect().ToString()); |
| 6683 | |
| 6684 | // The clip child should have inherited the clip parent's clip (projected to |
| 6685 | // the right space, of course), and should have the correctly sized visible |
| 6686 | // content rect. |
| 6687 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6688 | clip_child->clip_rect().ToString()); |
| 6689 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(), |
| 6690 | clip_child->visible_content_rect().ToString()); |
| 6691 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6692 | } |
| 6693 | |
| 6694 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 6695 | // Ensure that intervening render surfaces are not a problem, even if there |
| 6696 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 6697 | // of transform. |
| 6698 | // |
| 6699 | // root (a render surface) |
| 6700 | // + clip_parent (masks to bounds) |
| 6701 | // + render_surface1 (sets opacity) |
| 6702 | // + intervening (masks to bounds AND scrolls) |
| 6703 | // + render_surface2 (also sets opacity) |
| 6704 | // + clip_child |
| 6705 | // |
| 6706 | scoped_refptr<Layer> root = Layer::Create(); |
| 6707 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6708 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6709 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6710 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6711 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6712 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6713 | |
| 6714 | root->AddChild(clip_parent); |
| 6715 | clip_parent->AddChild(render_surface1); |
| 6716 | render_surface1->AddChild(intervening); |
| 6717 | intervening->AddChild(render_surface2); |
| 6718 | render_surface2->AddChild(clip_child); |
| 6719 | |
| 6720 | clip_child->SetClipParent(clip_parent.get()); |
| 6721 | |
| 6722 | intervening->SetMasksToBounds(true); |
| 6723 | clip_parent->SetMasksToBounds(true); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6724 | intervening->SetScrollClipLayerId(clip_parent->id()); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 6725 | intervening->SetScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6726 | |
| 6727 | render_surface1->SetForceRenderSurface(true); |
| 6728 | render_surface2->SetForceRenderSurface(true); |
| 6729 | |
| 6730 | gfx::Transform translation_transform; |
| 6731 | translation_transform.Translate(2, 2); |
| 6732 | |
| 6733 | gfx::Transform identity_transform; |
| 6734 | SetLayerPropertiesForTesting(root.get(), |
| 6735 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6736 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6737 | gfx::PointF(), |
| 6738 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6739 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6740 | false); |
| 6741 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6742 | translation_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6743 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6744 | gfx::PointF(1.f, 1.f), |
| 6745 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6746 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6747 | false); |
| 6748 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6749 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6750 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6751 | gfx::PointF(), |
| 6752 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6753 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6754 | false); |
| 6755 | SetLayerPropertiesForTesting(intervening.get(), |
| 6756 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6757 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6758 | gfx::PointF(1.f, 1.f), |
| 6759 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6760 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6761 | false); |
| 6762 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6763 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6764 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6765 | gfx::PointF(), |
| 6766 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6767 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6768 | false); |
| 6769 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6770 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6771 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6772 | gfx::PointF(-10.f, -10.f), |
| 6773 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6774 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6775 | false); |
| 6776 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6777 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6778 | host->SetRootLayer(root); |
| 6779 | |
| 6780 | ExecuteCalculateDrawProperties(root.get()); |
| 6781 | |
| 6782 | EXPECT_TRUE(root->render_surface()); |
| 6783 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6784 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6785 | |
| 6786 | // Since the render surfaces could have expanded, they should not clip (their |
| 6787 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6788 | // in this case. |
| 6789 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6790 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6791 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6792 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6793 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6794 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6795 | |
| 6796 | // NB: clip rects are in target space. |
| 6797 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6798 | render_surface1->clip_rect().ToString()); |
| 6799 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6800 | |
| 6801 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6802 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(), |
| 6803 | render_surface2->clip_rect().ToString()); |
| 6804 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6805 | |
| 6806 | // The content rects of both render surfaces should both have expanded to |
| 6807 | // contain the clip child. |
| 6808 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6809 | render_surface1->render_surface()->content_rect().ToString()); |
| 6810 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6811 | render_surface2->render_surface()->content_rect().ToString()); |
| 6812 | |
| 6813 | // The clip child should have inherited the clip parent's clip (projected to |
| 6814 | // the right space, of course), and should have the correctly sized visible |
| 6815 | // content rect. |
| 6816 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6817 | clip_child->clip_rect().ToString()); |
| 6818 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), |
| 6819 | clip_child->visible_content_rect().ToString()); |
| 6820 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6821 | } |
| 6822 | |
| 6823 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 6824 | // Ensures that descendants of the clip child inherit the correct clip. |
| 6825 | // |
| 6826 | // root (a render surface) |
| 6827 | // + clip_parent (masks to bounds) |
| 6828 | // + intervening (masks to bounds) |
| 6829 | // + clip_child |
| 6830 | // + child |
| 6831 | // |
| 6832 | scoped_refptr<Layer> root = Layer::Create(); |
| 6833 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6834 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6835 | scoped_refptr<Layer> clip_child = Layer::Create(); |
| 6836 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 6837 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6838 | |
| 6839 | root->AddChild(clip_parent); |
| 6840 | clip_parent->AddChild(intervening); |
| 6841 | intervening->AddChild(clip_child); |
| 6842 | clip_child->AddChild(child); |
| 6843 | |
| 6844 | clip_child->SetClipParent(clip_parent.get()); |
| 6845 | |
| 6846 | intervening->SetMasksToBounds(true); |
| 6847 | clip_parent->SetMasksToBounds(true); |
| 6848 | |
| 6849 | gfx::Transform identity_transform; |
| 6850 | SetLayerPropertiesForTesting(root.get(), |
| 6851 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6852 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6853 | gfx::PointF(), |
| 6854 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6855 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6856 | false); |
| 6857 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6858 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6859 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6860 | gfx::PointF(), |
| 6861 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6862 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6863 | false); |
| 6864 | SetLayerPropertiesForTesting(intervening.get(), |
| 6865 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6866 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6867 | gfx::PointF(), |
| 6868 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6869 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6870 | false); |
| 6871 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6872 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6873 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6874 | gfx::PointF(), |
| 6875 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6876 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6877 | false); |
| 6878 | SetLayerPropertiesForTesting(child.get(), |
| 6879 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6880 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6881 | gfx::PointF(), |
| 6882 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6883 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6884 | false); |
| 6885 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6886 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6887 | host->SetRootLayer(root); |
| 6888 | |
| 6889 | ExecuteCalculateDrawProperties(root.get()); |
| 6890 | |
| 6891 | EXPECT_TRUE(root->render_surface()); |
| 6892 | |
| 6893 | // Neither the clip child nor its descendant should have inherited the clip |
| 6894 | // from |intervening|. |
| 6895 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6896 | clip_child->clip_rect().ToString()); |
| 6897 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6898 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6899 | child->visible_content_rect().ToString()); |
| 6900 | EXPECT_TRUE(child->is_clipped()); |
| 6901 | } |
| 6902 | |
| 6903 | TEST_F(LayerTreeHostCommonTest, |
| 6904 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 6905 | // Ensures that non-descendant clip children in the tree do not affect |
| 6906 | // render surfaces. |
| 6907 | // |
| 6908 | // root (a render surface) |
| 6909 | // + clip_parent (masks to bounds) |
| 6910 | // + render_surface1 |
| 6911 | // + clip_child |
| 6912 | // + render_surface2 |
| 6913 | // + non_clip_child |
| 6914 | // |
| 6915 | // In this example render_surface2 should be unaffected by clip_child. |
| 6916 | scoped_refptr<Layer> root = Layer::Create(); |
| 6917 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6918 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6919 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6920 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6921 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6922 | scoped_refptr<LayerWithForcedDrawsContent> non_clip_child = |
| 6923 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6924 | |
| 6925 | root->AddChild(clip_parent); |
| 6926 | clip_parent->AddChild(render_surface1); |
| 6927 | render_surface1->AddChild(clip_child); |
| 6928 | clip_parent->AddChild(render_surface2); |
| 6929 | render_surface2->AddChild(non_clip_child); |
| 6930 | |
| 6931 | clip_child->SetClipParent(clip_parent.get()); |
| 6932 | |
| 6933 | clip_parent->SetMasksToBounds(true); |
| 6934 | render_surface1->SetMasksToBounds(true); |
| 6935 | |
| 6936 | gfx::Transform identity_transform; |
| 6937 | SetLayerPropertiesForTesting(root.get(), |
| 6938 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6939 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6940 | gfx::PointF(), |
| 6941 | gfx::Size(15, 15), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6942 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6943 | false); |
| 6944 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6945 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6946 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6947 | gfx::PointF(), |
| 6948 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6949 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6950 | false); |
| 6951 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6952 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6953 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6954 | gfx::PointF(5, 5), |
| 6955 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6956 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6957 | false); |
| 6958 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6959 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6960 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6961 | gfx::PointF(), |
| 6962 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6963 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6964 | false); |
| 6965 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6966 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6967 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6968 | gfx::PointF(-1, 1), |
| 6969 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6970 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6971 | false); |
| 6972 | SetLayerPropertiesForTesting(non_clip_child.get(), |
| 6973 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6974 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6975 | gfx::PointF(), |
| 6976 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6977 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6978 | false); |
| 6979 | |
| 6980 | render_surface1->SetForceRenderSurface(true); |
| 6981 | render_surface2->SetForceRenderSurface(true); |
| 6982 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6983 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6984 | host->SetRootLayer(root); |
| 6985 | |
| 6986 | ExecuteCalculateDrawProperties(root.get()); |
| 6987 | |
| 6988 | EXPECT_TRUE(root->render_surface()); |
| 6989 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6990 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6991 | |
| 6992 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6993 | render_surface1->clip_rect().ToString()); |
| 6994 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6995 | |
| 6996 | // The render surface should not clip (it has unclipped descendants), instead |
| 6997 | // it should rely on layer clipping. |
| 6998 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6999 | render_surface1->render_surface()->clip_rect().ToString()); |
| 7000 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 7001 | |
| 7002 | // That said, it should have grown to accomodate the unclipped descendant. |
| 7003 | EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(), |
| 7004 | render_surface1->render_surface()->content_rect().ToString()); |
| 7005 | |
| 7006 | // This render surface should clip. It has no unclipped descendants. |
| 7007 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 7008 | render_surface2->clip_rect().ToString()); |
| 7009 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
| 7010 | |
| 7011 | // It also shouldn't have grown to accomodate the clip child. |
| 7012 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 7013 | render_surface2->render_surface()->content_rect().ToString()); |
| 7014 | |
| 7015 | // Sanity check our num_unclipped_descendants values. |
| 7016 | EXPECT_EQ(1, render_surface1->num_unclipped_descendants()); |
| 7017 | EXPECT_EQ(0, render_surface2->num_unclipped_descendants()); |
| 7018 | } |
| 7019 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7020 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
| 7021 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7022 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 7023 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7024 | scoped_ptr<LayerImpl> root = |
| 7025 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 7026 | scoped_ptr<LayerImpl> child1 = |
| 7027 | LayerImpl::Create(host_impl.active_tree(), 123456); |
| 7028 | scoped_ptr<LayerImpl> child2 = |
| 7029 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
| 7030 | scoped_ptr<LayerImpl> child3 = |
| 7031 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 7032 | |
| 7033 | gfx::Transform identity_matrix; |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7034 | gfx::Point3F transform_origin; |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7035 | gfx::PointF position; |
| 7036 | gfx::Size bounds(100, 100); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7037 | SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 7038 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7039 | root->SetDrawsContent(true); |
| 7040 | |
| 7041 | // This layer structure normally forces render surface due to preserves3d |
| 7042 | // behavior. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7043 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin, |
| 7044 | position, bounds, false, true, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7045 | child1->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7046 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin, |
| 7047 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7048 | child2->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7049 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin, |
| 7050 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7051 | child3->SetDrawsContent(true); |
| 7052 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 7053 | child2->Set3dSortingContextId(1); |
| 7054 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7055 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7056 | child2->AddChild(child3.Pass()); |
| 7057 | child1->AddChild(child2.Pass()); |
| 7058 | root->AddChild(child1.Pass()); |
| 7059 | |
| 7060 | { |
| 7061 | LayerImplList render_surface_layer_list; |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 7062 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get()); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7063 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7064 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7065 | inputs.can_render_to_separate_surface = true; |
| 7066 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7067 | |
| 7068 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 7069 | |
| 7070 | int count_represents_target_render_surface = 0; |
| 7071 | int count_represents_contributing_render_surface = 0; |
| 7072 | int count_represents_itself = 0; |
| 7073 | auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list); |
| 7074 | for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list); |
| 7075 | it != end; ++it) { |
| 7076 | if (it.represents_target_render_surface()) |
| 7077 | count_represents_target_render_surface++; |
| 7078 | if (it.represents_contributing_render_surface()) |
| 7079 | count_represents_contributing_render_surface++; |
| 7080 | if (it.represents_itself()) |
| 7081 | count_represents_itself++; |
| 7082 | } |
| 7083 | |
| 7084 | // Two render surfaces. |
| 7085 | EXPECT_EQ(2, count_represents_target_render_surface); |
| 7086 | // Second render surface contributes to root render surface. |
| 7087 | EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 7088 | // All 4 layers represent itself. |
| 7089 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7090 | } |
| 7091 | |
| 7092 | { |
| 7093 | LayerImplList render_surface_layer_list; |
| 7094 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7095 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7096 | inputs.can_render_to_separate_surface = false; |
| 7097 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7098 | |
| 7099 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 7100 | |
| 7101 | int count_represents_target_render_surface = 0; |
| 7102 | int count_represents_contributing_render_surface = 0; |
| 7103 | int count_represents_itself = 0; |
| 7104 | auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list); |
| 7105 | for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list); |
| 7106 | it != end; ++it) { |
| 7107 | if (it.represents_target_render_surface()) |
| 7108 | count_represents_target_render_surface++; |
| 7109 | if (it.represents_contributing_render_surface()) |
| 7110 | count_represents_contributing_render_surface++; |
| 7111 | if (it.represents_itself()) |
| 7112 | count_represents_itself++; |
| 7113 | } |
| 7114 | |
| 7115 | // Only root layer has a render surface. |
| 7116 | EXPECT_EQ(1, count_represents_target_render_surface); |
| 7117 | // No layer contributes a render surface to root render surface. |
| 7118 | EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 7119 | // All 4 layers represent itself. |
| 7120 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7121 | } |
| 7122 | } |
| 7123 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7124 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
| 7125 | scoped_refptr<Layer> root = Layer::Create(); |
| 7126 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 7127 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 7128 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7129 | |
| 7130 | root->AddChild(render_surface); |
| 7131 | render_surface->AddChild(child); |
| 7132 | |
| 7133 | gfx::Transform identity_transform; |
| 7134 | SetLayerPropertiesForTesting(root.get(), |
| 7135 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7136 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7137 | gfx::PointF(), |
| 7138 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7139 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7140 | false); |
| 7141 | SetLayerPropertiesForTesting(render_surface.get(), |
| 7142 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7143 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7144 | gfx::PointF(), |
| 7145 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7146 | false, |
| 7147 | true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7148 | SetLayerPropertiesForTesting(child.get(), |
| 7149 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7150 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7151 | gfx::PointF(), |
| 7152 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7153 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7154 | false); |
| 7155 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7156 | root->SetShouldFlattenTransform(false); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 7157 | root->Set3dSortingContextId(1); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7158 | render_surface->SetDoubleSided(false); |
| 7159 | render_surface->SetForceRenderSurface(true); |
| 7160 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7161 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7162 | host->SetRootLayer(root); |
| 7163 | |
| 7164 | ExecuteCalculateDrawProperties(root.get()); |
| 7165 | |
| 7166 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 7167 | EXPECT_EQ(1u, |
| 7168 | render_surface_layer_list()->at(0) |
| 7169 | ->render_surface()->layer_list().size()); |
| 7170 | EXPECT_EQ(1u, |
| 7171 | render_surface_layer_list()->at(1) |
| 7172 | ->render_surface()->layer_list().size()); |
| 7173 | |
| 7174 | gfx::Transform rotation_transform = identity_transform; |
| 7175 | rotation_transform.RotateAboutXAxis(180.0); |
| 7176 | |
| 7177 | render_surface->SetTransform(rotation_transform); |
| 7178 | |
| 7179 | ExecuteCalculateDrawProperties(root.get()); |
| 7180 | |
| 7181 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 7182 | EXPECT_EQ(0u, |
| 7183 | render_surface_layer_list()->at(0) |
| 7184 | ->render_surface()->layer_list().size()); |
| 7185 | } |
| 7186 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7187 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 7188 | // Checks that the simple case (being clipped by a scroll parent that would |
| 7189 | // have been processed before you anyhow) results in the right clips. |
| 7190 | // |
| 7191 | // + root |
| 7192 | // + scroll_parent_border |
| 7193 | // | + scroll_parent_clip |
| 7194 | // | + scroll_parent |
| 7195 | // + scroll_child |
| 7196 | // |
| 7197 | scoped_refptr<Layer> root = Layer::Create(); |
| 7198 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7199 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7200 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7201 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7202 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7203 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7204 | |
| 7205 | root->AddChild(scroll_child); |
| 7206 | |
| 7207 | root->AddChild(scroll_parent_border); |
| 7208 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7209 | scroll_parent_clip->AddChild(scroll_parent); |
| 7210 | |
| 7211 | scroll_parent_clip->SetMasksToBounds(true); |
| 7212 | |
| 7213 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7214 | |
| 7215 | gfx::Transform identity_transform; |
| 7216 | SetLayerPropertiesForTesting(root.get(), |
| 7217 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7218 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7219 | gfx::PointF(), |
| 7220 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7221 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7222 | false); |
| 7223 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7224 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7225 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7226 | gfx::PointF(), |
| 7227 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7228 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7229 | false); |
| 7230 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7231 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7232 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7233 | gfx::PointF(), |
| 7234 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7235 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7236 | false); |
| 7237 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7238 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7239 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7240 | gfx::PointF(), |
| 7241 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7242 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7243 | false); |
| 7244 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7245 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7246 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7247 | gfx::PointF(), |
| 7248 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7249 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7250 | false); |
| 7251 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7252 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7253 | host->SetRootLayer(root); |
| 7254 | |
| 7255 | ExecuteCalculateDrawProperties(root.get()); |
| 7256 | |
| 7257 | EXPECT_TRUE(root->render_surface()); |
| 7258 | |
| 7259 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 7260 | scroll_child->clip_rect().ToString()); |
| 7261 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7262 | } |
| 7263 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7264 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
| 7265 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 7266 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7267 | scoped_refptr<LayerWithForcedDrawsContent> parent = |
| 7268 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7269 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 7270 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7271 | |
| 7272 | root->AddChild(parent); |
| 7273 | parent->AddChild(child); |
| 7274 | |
| 7275 | gfx::Transform identity_transform; |
| 7276 | SetLayerPropertiesForTesting(root.get(), |
| 7277 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7278 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7279 | gfx::PointF(), |
| 7280 | gfx::Size(50, 50), |
| 7281 | true, |
| 7282 | true); |
| 7283 | root->SetForceRenderSurface(true); |
| 7284 | SetLayerPropertiesForTesting(parent.get(), |
| 7285 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7286 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7287 | gfx::PointF(), |
| 7288 | gfx::Size(30, 30), |
| 7289 | true, |
| 7290 | true); |
| 7291 | parent->SetForceRenderSurface(true); |
| 7292 | SetLayerPropertiesForTesting(child.get(), |
| 7293 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7294 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7295 | gfx::PointF(), |
| 7296 | gfx::Size(20, 20), |
| 7297 | true, |
| 7298 | true); |
| 7299 | child->SetForceRenderSurface(true); |
| 7300 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7301 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7302 | host->SetRootLayer(root); |
| 7303 | |
| 7304 | ExecuteCalculateDrawProperties(root.get()); |
| 7305 | |
| 7306 | EXPECT_EQ(3u, render_surface_layer_list()->size()); |
| 7307 | |
| 7308 | gfx::Transform singular_transform; |
| 7309 | singular_transform.Scale3d( |
| 7310 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 7311 | |
| 7312 | child->SetTransform(singular_transform); |
| 7313 | |
| 7314 | ExecuteCalculateDrawProperties(root.get()); |
| 7315 | |
| 7316 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 7317 | |
| 7318 | // Ensure that the entire subtree under a layer with singular transform does |
| 7319 | // not get rendered. |
| 7320 | parent->SetTransform(singular_transform); |
| 7321 | child->SetTransform(identity_transform); |
| 7322 | |
| 7323 | ExecuteCalculateDrawProperties(root.get()); |
| 7324 | |
| 7325 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 7326 | } |
| 7327 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7328 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 7329 | // Checks that clipping by a scroll parent that follows you in paint order |
| 7330 | // still results in correct clipping. |
| 7331 | // |
| 7332 | // + root |
| 7333 | // + scroll_child |
| 7334 | // + scroll_parent_border |
| 7335 | // + scroll_parent_clip |
| 7336 | // + scroll_parent |
| 7337 | // |
| 7338 | scoped_refptr<Layer> root = Layer::Create(); |
| 7339 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7340 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7341 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7342 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7343 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7344 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7345 | |
| 7346 | root->AddChild(scroll_parent_border); |
| 7347 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7348 | scroll_parent_clip->AddChild(scroll_parent); |
| 7349 | |
| 7350 | root->AddChild(scroll_child); |
| 7351 | |
| 7352 | scroll_parent_clip->SetMasksToBounds(true); |
| 7353 | |
| 7354 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7355 | |
| 7356 | gfx::Transform identity_transform; |
| 7357 | SetLayerPropertiesForTesting(root.get(), |
| 7358 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7359 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7360 | gfx::PointF(), |
| 7361 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7362 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7363 | false); |
| 7364 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7365 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7366 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7367 | gfx::PointF(), |
| 7368 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7369 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7370 | false); |
| 7371 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7372 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7373 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7374 | gfx::PointF(), |
| 7375 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7376 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7377 | false); |
| 7378 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7379 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7380 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7381 | gfx::PointF(), |
| 7382 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7383 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7384 | false); |
| 7385 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7386 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7387 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7388 | gfx::PointF(), |
| 7389 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7390 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7391 | false); |
| 7392 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7393 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7394 | host->SetRootLayer(root); |
| 7395 | |
| 7396 | ExecuteCalculateDrawProperties(root.get()); |
| 7397 | |
| 7398 | EXPECT_TRUE(root->render_surface()); |
| 7399 | |
| 7400 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 7401 | scroll_child->clip_rect().ToString()); |
| 7402 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7403 | } |
| 7404 | |
| 7405 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 7406 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 7407 | // you in paint order still results in correct clipping. |
| 7408 | // |
| 7409 | // + root |
| 7410 | // + scroll_child |
| 7411 | // + scroll_parent_border |
| 7412 | // | + scroll_parent_clip |
| 7413 | // | + scroll_parent |
| 7414 | // + scroll_grandparent_border |
| 7415 | // + scroll_grandparent_clip |
| 7416 | // + scroll_grandparent |
| 7417 | // |
| 7418 | scoped_refptr<Layer> root = Layer::Create(); |
| 7419 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7420 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7421 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7422 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7423 | |
| 7424 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 7425 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 7426 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 7427 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7428 | |
| 7429 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7430 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7431 | |
| 7432 | root->AddChild(scroll_child); |
| 7433 | |
| 7434 | root->AddChild(scroll_parent_border); |
| 7435 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7436 | scroll_parent_clip->AddChild(scroll_parent); |
| 7437 | |
| 7438 | root->AddChild(scroll_grandparent_border); |
| 7439 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 7440 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 7441 | |
| 7442 | scroll_parent_clip->SetMasksToBounds(true); |
| 7443 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 7444 | |
| 7445 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7446 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 7447 | |
| 7448 | gfx::Transform identity_transform; |
| 7449 | SetLayerPropertiesForTesting(root.get(), |
| 7450 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7451 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7452 | gfx::PointF(), |
| 7453 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7454 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7455 | false); |
| 7456 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 7457 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7458 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7459 | gfx::PointF(), |
| 7460 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7461 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7462 | false); |
| 7463 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 7464 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7465 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7466 | gfx::PointF(), |
| 7467 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7468 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7469 | false); |
| 7470 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 7471 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7472 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7473 | gfx::PointF(), |
| 7474 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7475 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7476 | false); |
| 7477 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7478 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7479 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7480 | gfx::PointF(), |
| 7481 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7482 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7483 | false); |
| 7484 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7485 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7486 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7487 | gfx::PointF(), |
| 7488 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7489 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7490 | false); |
| 7491 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7492 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7493 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7494 | gfx::PointF(), |
| 7495 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7496 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7497 | false); |
| 7498 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7499 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7500 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7501 | gfx::PointF(), |
| 7502 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7503 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7504 | false); |
| 7505 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7506 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7507 | host->SetRootLayer(root); |
| 7508 | |
| 7509 | ExecuteCalculateDrawProperties(root.get()); |
| 7510 | |
| 7511 | EXPECT_TRUE(root->render_surface()); |
| 7512 | |
| 7513 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 7514 | scroll_child->clip_rect().ToString()); |
| 7515 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7516 | |
| 7517 | // Despite the fact that we visited the above layers out of order to get the |
| 7518 | // correct clip, the layer lists should be unaffected. |
| 7519 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 7520 | EXPECT_EQ(scroll_child.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7521 | root->render_surface()->layer_list().at(0).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7522 | EXPECT_EQ(scroll_parent.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7523 | root->render_surface()->layer_list().at(1).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7524 | EXPECT_EQ(scroll_grandparent.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7525 | root->render_surface()->layer_list().at(2).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7526 | } |
| 7527 | |
| 7528 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 7529 | // 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] | 7530 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7531 | // + root |
| 7532 | // + scroll_child |
| 7533 | // + scroll_parent_border |
| 7534 | // + scroll_parent_clip |
| 7535 | // + scroll_parent |
| 7536 | // + render_surface1 |
| 7537 | // + scroll_grandparent_border |
| 7538 | // + scroll_grandparent_clip |
| 7539 | // + scroll_grandparent |
| 7540 | // + render_surface2 |
| 7541 | // |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 7542 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 7543 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7544 | |
| 7545 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7546 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7547 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7548 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7549 | scoped_refptr<LayerWithForcedDrawsContent> render_surface1 = |
| 7550 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7551 | |
| 7552 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 7553 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 7554 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 7555 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7556 | scoped_refptr<LayerWithForcedDrawsContent> render_surface2 = |
| 7557 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7558 | |
| 7559 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7560 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7561 | |
| 7562 | root->AddChild(scroll_child); |
| 7563 | |
| 7564 | root->AddChild(scroll_parent_border); |
| 7565 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7566 | scroll_parent_clip->AddChild(scroll_parent); |
| 7567 | scroll_parent->AddChild(render_surface2); |
| 7568 | |
| 7569 | root->AddChild(scroll_grandparent_border); |
| 7570 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 7571 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 7572 | scroll_grandparent->AddChild(render_surface1); |
| 7573 | |
| 7574 | scroll_parent_clip->SetMasksToBounds(true); |
| 7575 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 7576 | |
| 7577 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7578 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 7579 | |
| 7580 | render_surface1->SetForceRenderSurface(true); |
| 7581 | render_surface2->SetForceRenderSurface(true); |
| 7582 | |
| 7583 | gfx::Transform identity_transform; |
| 7584 | SetLayerPropertiesForTesting(root.get(), |
| 7585 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7586 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7587 | gfx::PointF(), |
| 7588 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7589 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7590 | false); |
| 7591 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 7592 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7593 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7594 | gfx::PointF(), |
| 7595 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7596 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7597 | false); |
| 7598 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 7599 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7600 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7601 | gfx::PointF(), |
| 7602 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7603 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7604 | false); |
| 7605 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 7606 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7607 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7608 | gfx::PointF(), |
| 7609 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7610 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7611 | false); |
| 7612 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 7613 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7614 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7615 | gfx::PointF(), |
| 7616 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7617 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7618 | false); |
| 7619 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7620 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7621 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7622 | gfx::PointF(), |
| 7623 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7624 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7625 | false); |
| 7626 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7627 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7628 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7629 | gfx::PointF(), |
| 7630 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7631 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7632 | false); |
| 7633 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7634 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7635 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7636 | gfx::PointF(), |
| 7637 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7638 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7639 | false); |
| 7640 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 7641 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7642 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7643 | gfx::PointF(), |
| 7644 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7645 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7646 | false); |
| 7647 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7648 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7649 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7650 | gfx::PointF(), |
| 7651 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7652 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7653 | false); |
| 7654 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7655 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7656 | host->SetRootLayer(root); |
| 7657 | |
| 7658 | RenderSurfaceLayerList render_surface_layer_list; |
| 7659 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7660 | root.get(), |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7661 | root->bounds(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7662 | identity_transform, |
| 7663 | &render_surface_layer_list); |
| 7664 | |
| 7665 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7666 | |
| 7667 | EXPECT_TRUE(root->render_surface()); |
| 7668 | |
| 7669 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 7670 | scroll_child->clip_rect().ToString()); |
| 7671 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7672 | |
| 7673 | // Despite the fact that we had to process the layers out of order to get the |
| 7674 | // right clip, our render_surface_layer_list's order should be unaffected. |
| 7675 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
| 7676 | EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); |
| 7677 | EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); |
| 7678 | EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 7679 | EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); |
| 7680 | EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); |
| 7681 | EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7682 | } |
| 7683 | |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7684 | TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { |
| 7685 | // Ensures that when we have a render surface between a fixed position layer |
| 7686 | // and its container, we compute the fixed position layer's draw transform |
| 7687 | // with respect to that intervening render surface, not with respect to its |
| 7688 | // container's render target. |
| 7689 | // |
| 7690 | // + root |
| 7691 | // + render_surface |
| 7692 | // + fixed |
| 7693 | // |
| 7694 | scoped_refptr<Layer> root = Layer::Create(); |
| 7695 | scoped_refptr<LayerWithForcedDrawsContent> render_surface = |
| 7696 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 7697 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
| 7698 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 7699 | |
| 7700 | root->AddChild(render_surface); |
| 7701 | render_surface->AddChild(fixed); |
| 7702 | |
| 7703 | root->SetIsContainerForFixedPositionLayers(true); |
| 7704 | render_surface->SetForceRenderSurface(true); |
| 7705 | |
| 7706 | LayerPositionConstraint constraint; |
| 7707 | constraint.set_is_fixed_position(true); |
| 7708 | fixed->SetPositionConstraint(constraint); |
| 7709 | |
| 7710 | SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(), |
| 7711 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 7712 | SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(), |
| 7713 | gfx::Point3F(), gfx::PointF(7.f, 9.f), |
| 7714 | gfx::Size(50, 50), true, false); |
| 7715 | SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(), |
| 7716 | gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true, |
| 7717 | false); |
| 7718 | |
| 7719 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 7720 | host->SetRootLayer(root); |
| 7721 | |
| 7722 | ExecuteCalculateDrawProperties(root.get()); |
| 7723 | |
| 7724 | gfx::Transform expected_draw_transform; |
| 7725 | expected_draw_transform.Translate(10.f, 15.f); |
| 7726 | EXPECT_EQ(expected_draw_transform, fixed->draw_transform()); |
| 7727 | |
| 7728 | gfx::Transform expected_screen_space_transform; |
| 7729 | expected_screen_space_transform.Translate(17.f, 24.f); |
| 7730 | EXPECT_EQ(expected_screen_space_transform, fixed->screen_space_transform()); |
| 7731 | } |
| 7732 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7733 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 7734 | // This test verifies that a scrolling layer that gets snapped to |
| 7735 | // integer coordinates doesn't move a fixed position child. |
| 7736 | // |
| 7737 | // + root |
| 7738 | // + container |
| 7739 | // + scroller |
| 7740 | // + fixed |
| 7741 | // |
| 7742 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7743 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 7744 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7745 | host_impl.CreatePendingTree(); |
| 7746 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7747 | scoped_ptr<LayerImpl> container = |
| 7748 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7749 | LayerImpl* container_layer = container.get(); |
| 7750 | scoped_ptr<LayerImpl> scroller = |
| 7751 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7752 | LayerImpl* scroll_layer = scroller.get(); |
| 7753 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7754 | LayerImpl* fixed_layer = fixed.get(); |
| 7755 | |
| 7756 | container->SetIsContainerForFixedPositionLayers(true); |
| 7757 | |
| 7758 | LayerPositionConstraint constraint; |
| 7759 | constraint.set_is_fixed_position(true); |
| 7760 | fixed->SetPositionConstraint(constraint); |
| 7761 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 7762 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7763 | |
| 7764 | gfx::Transform identity_transform; |
| 7765 | gfx::Transform container_transform; |
| 7766 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7767 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7768 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7769 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7770 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7771 | true); |
| 7772 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7773 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7774 | true, false, false); |
| 7775 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7776 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 7777 | true, false, false); |
| 7778 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7779 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7780 | false); |
| 7781 | |
| 7782 | scroller->AddChild(fixed.Pass()); |
| 7783 | container->AddChild(scroller.Pass()); |
| 7784 | root->AddChild(container.Pass()); |
| 7785 | |
| 7786 | // Rounded to integers already. |
| 7787 | { |
| 7788 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
| 7789 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7790 | |
| 7791 | LayerImplList render_surface_layer_list; |
| 7792 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7793 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7794 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7795 | |
| 7796 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7797 | container_layer->draw_properties().screen_space_transform, |
| 7798 | fixed_layer->draw_properties().screen_space_transform); |
| 7799 | EXPECT_VECTOR_EQ( |
| 7800 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7801 | container_offset); |
| 7802 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7803 | .screen_space_transform.To2dTranslation(), |
| 7804 | container_offset - scroll_delta); |
| 7805 | } |
| 7806 | |
| 7807 | // Scroll delta requiring rounding. |
| 7808 | { |
| 7809 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
| 7810 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7811 | |
| 7812 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 7813 | |
| 7814 | LayerImplList render_surface_layer_list; |
| 7815 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7816 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7817 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7818 | |
| 7819 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7820 | container_layer->draw_properties().screen_space_transform, |
| 7821 | fixed_layer->draw_properties().screen_space_transform); |
| 7822 | EXPECT_VECTOR_EQ( |
| 7823 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7824 | container_offset); |
| 7825 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7826 | .screen_space_transform.To2dTranslation(), |
| 7827 | container_offset - rounded_scroll_delta); |
| 7828 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7829 | |
| 7830 | // Scale is applied earlier in the tree. |
| 7831 | { |
| 7832 | gfx::Transform scaled_container_transform = container_transform; |
| 7833 | scaled_container_transform.Scale3d(3.0, 3.0, 1.0); |
| 7834 | container_layer->SetTransform(scaled_container_transform); |
| 7835 | |
| 7836 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7837 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7838 | |
| 7839 | LayerImplList render_surface_layer_list; |
| 7840 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7841 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7842 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7843 | |
| 7844 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7845 | container_layer->draw_properties().screen_space_transform, |
| 7846 | fixed_layer->draw_properties().screen_space_transform); |
| 7847 | EXPECT_VECTOR_EQ( |
| 7848 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7849 | container_offset); |
| 7850 | |
| 7851 | container_layer->SetTransform(container_transform); |
| 7852 | } |
| 7853 | |
| 7854 | // Scale is applied on the scroll layer itself. |
| 7855 | { |
| 7856 | gfx::Transform scale_transform; |
| 7857 | scale_transform.Scale3d(3.0, 3.0, 1.0); |
| 7858 | scroll_layer->SetTransform(scale_transform); |
| 7859 | |
| 7860 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7861 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7862 | |
| 7863 | LayerImplList render_surface_layer_list; |
| 7864 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7865 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7866 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7867 | |
| 7868 | EXPECT_VECTOR_EQ( |
| 7869 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7870 | container_offset); |
| 7871 | |
| 7872 | scroll_layer->SetTransform(identity_transform); |
| 7873 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7874 | } |
| 7875 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7876 | TEST_F(LayerTreeHostCommonTest, |
| 7877 | ScrollCompensationMainScrollOffsetFractionalPart) { |
| 7878 | // This test verifies that a scrolling layer that has fractional scroll offset |
| 7879 | // from main doesn't move a fixed position child. |
| 7880 | // |
| 7881 | // + root |
| 7882 | // + container |
| 7883 | // + scroller |
| 7884 | // + fixed |
| 7885 | // |
| 7886 | FakeImplProxy proxy; |
| 7887 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 7888 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7889 | host_impl.CreatePendingTree(); |
| 7890 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7891 | scoped_ptr<LayerImpl> container = |
| 7892 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7893 | LayerImpl* container_layer = container.get(); |
| 7894 | scoped_ptr<LayerImpl> scroller = |
| 7895 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7896 | LayerImpl* scroll_layer = scroller.get(); |
| 7897 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7898 | LayerImpl* fixed_layer = fixed.get(); |
| 7899 | |
| 7900 | container->SetIsContainerForFixedPositionLayers(true); |
| 7901 | |
| 7902 | LayerPositionConstraint constraint; |
| 7903 | constraint.set_is_fixed_position(true); |
| 7904 | fixed->SetPositionConstraint(constraint); |
| 7905 | |
| 7906 | scroller->SetScrollClipLayer(container->id()); |
| 7907 | |
| 7908 | gfx::Transform identity_transform; |
| 7909 | gfx::Transform container_transform; |
| 7910 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7911 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7912 | |
| 7913 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7914 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7915 | true); |
| 7916 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7917 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7918 | true, false, false); |
| 7919 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7920 | gfx::Point3F(), gfx::PointF(0.0, 0.0), |
| 7921 | gfx::Size(30, 30), true, false, false); |
| 7922 | |
| 7923 | gfx::ScrollOffset scroll_offset(3.3, 4.2); |
| 7924 | gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f); |
| 7925 | gfx::Vector2dF scroll_delta(0.1f, 0.4f); |
| 7926 | // Blink only uses the integer part of the scroll_offset for fixed |
| 7927 | // position layer. |
| 7928 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7929 | gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true, |
| 7930 | false, false); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 7931 | scroll_layer->PushScrollOffsetFromMainThread(scroll_offset); |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 7932 | scroll_layer->SetScrollDelta(scroll_delta); |
miletus | ff93ab7 | 2015-01-30 04:30:44 | [diff] [blame] | 7933 | scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7934 | |
| 7935 | scroller->AddChild(fixed.Pass()); |
| 7936 | container->AddChild(scroller.Pass()); |
| 7937 | root->AddChild(container.Pass()); |
| 7938 | |
| 7939 | LayerImplList render_surface_layer_list; |
| 7940 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7941 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7942 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7943 | |
| 7944 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7945 | container_layer->draw_properties().screen_space_transform, |
| 7946 | fixed_layer->draw_properties().screen_space_transform); |
| 7947 | EXPECT_VECTOR_EQ( |
| 7948 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7949 | container_offset); |
| 7950 | |
| 7951 | gfx::ScrollOffset effective_scroll_offset = |
| 7952 | ScrollOffsetWithDelta(scroll_offset, scroll_delta); |
| 7953 | gfx::Vector2d rounded_effective_scroll_offset = |
| 7954 | ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset)); |
| 7955 | EXPECT_VECTOR_EQ( |
| 7956 | scroll_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7957 | container_offset - rounded_effective_scroll_offset); |
| 7958 | } |
| 7959 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7960 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7961 | public: |
| 7962 | static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
| 7963 | LayerTreeImpl* tree_impl, |
| 7964 | int id) { |
| 7965 | return make_scoped_ptr( |
| 7966 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7967 | } |
| 7968 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7969 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7970 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7971 | private: |
| 7972 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7973 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7974 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7975 | SetDrawsContent(true); |
| 7976 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7977 | }; |
| 7978 | |
| 7979 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
| 7980 | FakeImplProxy proxy; |
| 7981 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 7982 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7983 | gfx::Transform identity_matrix; |
| 7984 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
| 7985 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
| 7986 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
| 7987 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
| 7988 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
| 7989 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
| 7990 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
| 7991 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7992 | |
| 7993 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7994 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7995 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
| 7996 | |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 7997 | child->AddChild(grand_child.Pass()); |
| 7998 | parent->AddChild(child.Pass()); |
| 7999 | grand_parent->AddChild(parent.Pass()); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8000 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8001 | SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix, |
| 8002 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8003 | true, false, true); |
| 8004 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 8005 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8006 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8007 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 8008 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8009 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8010 | |
| 8011 | SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(), |
| 8012 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8013 | false); |
| 8014 | |
| 8015 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8016 | |
| 8017 | // No layers have animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8018 | EXPECT_EQ(0.f, |
| 8019 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8020 | EXPECT_EQ(0.f, |
| 8021 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8022 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8023 | EXPECT_EQ( |
| 8024 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8025 | |
| 8026 | TransformOperations translation; |
| 8027 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 8028 | |
| 8029 | AddAnimatedTransformToLayer( |
| 8030 | parent_raw, 1.0, TransformOperations(), translation); |
| 8031 | |
| 8032 | // No layers have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8033 | EXPECT_EQ(0.f, |
| 8034 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8035 | EXPECT_EQ(0.f, |
| 8036 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8037 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8038 | EXPECT_EQ( |
| 8039 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8040 | |
| 8041 | TransformOperations scale; |
| 8042 | scale.AppendScale(5.f, 4.f, 3.f); |
| 8043 | |
| 8044 | AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); |
| 8045 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8046 | |
| 8047 | // Only |child| has a scale-affecting animation. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8048 | EXPECT_EQ(0.f, |
| 8049 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8050 | EXPECT_EQ(0.f, |
| 8051 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8052 | EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8053 | EXPECT_EQ( |
| 8054 | 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8055 | |
| 8056 | AddAnimatedTransformToLayer( |
| 8057 | grand_parent.get(), 1.0, TransformOperations(), scale); |
| 8058 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8059 | |
| 8060 | // |grand_parent| and |child| have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8061 | EXPECT_EQ(5.f, |
| 8062 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8063 | EXPECT_EQ(5.f, |
| 8064 | parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8065 | // We don't support combining animated scales from two nodes; 0.f means |
| 8066 | // that the maximum scale could not be computed. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8067 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8068 | EXPECT_EQ( |
| 8069 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8070 | |
| 8071 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 8072 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8073 | |
| 8074 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8075 | EXPECT_EQ(5.f, |
| 8076 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8077 | EXPECT_EQ(0.f, |
| 8078 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8079 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8080 | EXPECT_EQ( |
| 8081 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8082 | |
| 8083 | grand_parent->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8084 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8085 | parent_raw->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8086 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8087 | child_raw->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8088 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8089 | |
| 8090 | TransformOperations perspective; |
| 8091 | perspective.AppendPerspective(10.f); |
| 8092 | |
| 8093 | AddAnimatedTransformToLayer( |
| 8094 | child_raw, 1.0, TransformOperations(), perspective); |
| 8095 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8096 | |
| 8097 | // |child| has a scale-affecting animation but computing the maximum of this |
| 8098 | // animation is not supported. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8099 | EXPECT_EQ(0.f, |
| 8100 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8101 | EXPECT_EQ(0.f, |
| 8102 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8103 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8104 | EXPECT_EQ( |
| 8105 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8106 | |
| 8107 | child_raw->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8108 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8109 | |
| 8110 | gfx::Transform scale_matrix; |
| 8111 | scale_matrix.Scale(1.f, 2.f); |
| 8112 | grand_parent->SetTransform(scale_matrix); |
| 8113 | parent_raw->SetTransform(scale_matrix); |
| 8114 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 8115 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8116 | |
| 8117 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 8118 | // animation with maximum scale 5.f. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8119 | EXPECT_EQ(0.f, |
| 8120 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8121 | EXPECT_EQ(10.f, |
| 8122 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8123 | EXPECT_EQ(10.f, |
| 8124 | child_raw->draw_properties().maximum_animation_contents_scale); |
| 8125 | EXPECT_EQ( |
| 8126 | 10.f, |
| 8127 | grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8128 | |
| 8129 | gfx::Transform perspective_matrix; |
| 8130 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 8131 | child_raw->SetTransform(perspective_matrix); |
| 8132 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8133 | |
| 8134 | // |child| has a transform that's neither a translation nor a scale. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8135 | EXPECT_EQ(0.f, |
| 8136 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8137 | EXPECT_EQ(10.f, |
| 8138 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8139 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8140 | EXPECT_EQ( |
| 8141 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8142 | |
| 8143 | parent_raw->SetTransform(perspective_matrix); |
| 8144 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8145 | |
| 8146 | // |parent| and |child| have transforms that are neither translations nor |
| 8147 | // scales. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8148 | EXPECT_EQ(0.f, |
| 8149 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8150 | EXPECT_EQ(0.f, |
| 8151 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8152 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8153 | EXPECT_EQ( |
| 8154 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8155 | |
| 8156 | parent_raw->SetTransform(identity_matrix); |
| 8157 | child_raw->SetTransform(identity_matrix); |
| 8158 | grand_parent->SetTransform(perspective_matrix); |
| 8159 | |
| 8160 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8161 | |
| 8162 | // |grand_parent| has a transform that's neither a translation nor a scale. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8163 | EXPECT_EQ(0.f, |
| 8164 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8165 | EXPECT_EQ(0.f, |
| 8166 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8167 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8168 | EXPECT_EQ( |
| 8169 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8170 | } |
| 8171 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8172 | static int membership_id(LayerImpl* layer) { |
| 8173 | return layer->draw_properties().last_drawn_render_surface_layer_list_id; |
| 8174 | } |
| 8175 | |
| 8176 | static void GatherDrawnLayers(LayerImplList* rsll, |
| 8177 | std::set<LayerImpl*>* drawn_layers) { |
| 8178 | for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll), |
| 8179 | end = LayerIterator<LayerImpl>::End(rsll); |
| 8180 | it != end; |
| 8181 | ++it) { |
| 8182 | LayerImpl* layer = *it; |
| 8183 | if (it.represents_itself()) |
| 8184 | drawn_layers->insert(layer); |
| 8185 | |
| 8186 | if (!it.represents_contributing_render_surface()) |
| 8187 | continue; |
| 8188 | |
| 8189 | if (layer->mask_layer()) |
| 8190 | drawn_layers->insert(layer->mask_layer()); |
| 8191 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 8192 | drawn_layers->insert(layer->replica_layer()->mask_layer()); |
| 8193 | } |
| 8194 | } |
| 8195 | |
| 8196 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
| 8197 | FakeImplProxy proxy; |
| 8198 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 8199 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8200 | gfx::Transform identity_matrix; |
| 8201 | |
| 8202 | scoped_ptr<LayerImpl> grand_parent = |
| 8203 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8204 | scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3); |
| 8205 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5); |
| 8206 | scoped_ptr<LayerImpl> grand_child1 = |
| 8207 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 8208 | scoped_ptr<LayerImpl> grand_child2 = |
| 8209 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 8210 | |
| 8211 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 8212 | LayerImpl* parent_raw = parent.get(); |
| 8213 | LayerImpl* child_raw = child.get(); |
| 8214 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 8215 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 8216 | |
| 8217 | child->AddChild(grand_child1.Pass()); |
| 8218 | child->AddChild(grand_child2.Pass()); |
| 8219 | parent->AddChild(child.Pass()); |
| 8220 | grand_parent->AddChild(parent.Pass()); |
| 8221 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8222 | SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, |
| 8223 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8224 | true, false, true); |
| 8225 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 8226 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8227 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8228 | |
| 8229 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 8230 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8231 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8232 | |
| 8233 | SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix, |
| 8234 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8235 | true, false, false); |
| 8236 | |
| 8237 | SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix, |
| 8238 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8239 | true, false, false); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8240 | |
| 8241 | // Start with nothing being drawn. |
| 8242 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8243 | int member_id = render_surface_layer_list_count(); |
| 8244 | |
| 8245 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8246 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8247 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8248 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8249 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8250 | |
| 8251 | std::set<LayerImpl*> expected; |
| 8252 | std::set<LayerImpl*> actual; |
| 8253 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8254 | EXPECT_EQ(expected, actual); |
| 8255 | |
| 8256 | // If we force render surface, but none of the layers are in the layer list, |
| 8257 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8258 | grand_child1_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8259 | |
| 8260 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8261 | member_id = render_surface_layer_list_count(); |
| 8262 | |
| 8263 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8264 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8265 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8266 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8267 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8268 | |
| 8269 | expected.clear(); |
| 8270 | actual.clear(); |
| 8271 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8272 | EXPECT_EQ(expected, actual); |
| 8273 | |
| 8274 | // However, if we say that this layer also draws content, it will appear in |
| 8275 | // RSLL. |
| 8276 | grand_child1_raw->SetDrawsContent(true); |
| 8277 | |
| 8278 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8279 | member_id = render_surface_layer_list_count(); |
| 8280 | |
| 8281 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8282 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8283 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8284 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 8285 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8286 | |
| 8287 | expected.clear(); |
| 8288 | expected.insert(grand_child1_raw); |
| 8289 | |
| 8290 | actual.clear(); |
| 8291 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8292 | EXPECT_EQ(expected, actual); |
| 8293 | |
| 8294 | // Now child is forced to have a render surface, and one if its children draws |
| 8295 | // content. |
| 8296 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8297 | grand_child1_raw->SetHasRenderSurface(false); |
| 8298 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8299 | grand_child2_raw->SetDrawsContent(true); |
| 8300 | |
| 8301 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8302 | member_id = render_surface_layer_list_count(); |
| 8303 | |
| 8304 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8305 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8306 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8307 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8308 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8309 | |
| 8310 | expected.clear(); |
| 8311 | expected.insert(grand_child2_raw); |
| 8312 | |
| 8313 | actual.clear(); |
| 8314 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8315 | EXPECT_EQ(expected, actual); |
| 8316 | |
| 8317 | // Add a mask layer to child. |
| 8318 | child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass()); |
| 8319 | |
| 8320 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8321 | member_id = render_surface_layer_list_count(); |
| 8322 | |
| 8323 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8324 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8325 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8326 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8327 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8328 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8329 | |
| 8330 | expected.clear(); |
| 8331 | expected.insert(grand_child2_raw); |
| 8332 | expected.insert(child_raw->mask_layer()); |
| 8333 | |
| 8334 | expected.clear(); |
| 8335 | expected.insert(grand_child2_raw); |
| 8336 | expected.insert(child_raw->mask_layer()); |
| 8337 | |
| 8338 | actual.clear(); |
| 8339 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8340 | EXPECT_EQ(expected, actual); |
| 8341 | |
| 8342 | // Add replica mask layer. |
| 8343 | scoped_ptr<LayerImpl> replica_layer = |
| 8344 | LayerImpl::Create(host_impl.active_tree(), 20); |
| 8345 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21)); |
| 8346 | child_raw->SetReplicaLayer(replica_layer.Pass()); |
| 8347 | |
| 8348 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8349 | member_id = render_surface_layer_list_count(); |
| 8350 | |
| 8351 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8352 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8353 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8354 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8355 | EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer())); |
| 8356 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8357 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8358 | |
| 8359 | expected.clear(); |
| 8360 | expected.insert(grand_child2_raw); |
| 8361 | expected.insert(child_raw->mask_layer()); |
| 8362 | expected.insert(child_raw->replica_layer()->mask_layer()); |
| 8363 | |
| 8364 | actual.clear(); |
| 8365 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8366 | EXPECT_EQ(expected, actual); |
| 8367 | |
| 8368 | child_raw->TakeReplicaLayer(); |
| 8369 | |
| 8370 | // With nothing drawing, we should have no layers. |
| 8371 | grand_child2_raw->SetDrawsContent(false); |
| 8372 | |
| 8373 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8374 | member_id = render_surface_layer_list_count(); |
| 8375 | |
| 8376 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8377 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8378 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8379 | EXPECT_NE(member_id, membership_id(child_raw->mask_layer())); |
| 8380 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8381 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8382 | |
| 8383 | expected.clear(); |
| 8384 | actual.clear(); |
| 8385 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8386 | EXPECT_EQ(expected, actual); |
| 8387 | |
| 8388 | // Child itself draws means that we should have the child and the mask in the |
| 8389 | // list. |
| 8390 | child_raw->SetDrawsContent(true); |
| 8391 | |
| 8392 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8393 | member_id = render_surface_layer_list_count(); |
| 8394 | |
| 8395 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8396 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8397 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 8398 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8399 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8400 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8401 | |
| 8402 | expected.clear(); |
| 8403 | expected.insert(child_raw); |
| 8404 | expected.insert(child_raw->mask_layer()); |
| 8405 | actual.clear(); |
| 8406 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8407 | EXPECT_EQ(expected, actual); |
| 8408 | |
| 8409 | child_raw->TakeMaskLayer(); |
| 8410 | |
| 8411 | // Now everyone's a member! |
| 8412 | grand_parent_raw->SetDrawsContent(true); |
| 8413 | parent_raw->SetDrawsContent(true); |
| 8414 | child_raw->SetDrawsContent(true); |
| 8415 | grand_child1_raw->SetDrawsContent(true); |
| 8416 | grand_child2_raw->SetDrawsContent(true); |
| 8417 | |
| 8418 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8419 | member_id = render_surface_layer_list_count(); |
| 8420 | |
| 8421 | EXPECT_EQ(member_id, membership_id(grand_parent_raw)); |
| 8422 | EXPECT_EQ(member_id, membership_id(parent_raw)); |
| 8423 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 8424 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 8425 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8426 | |
| 8427 | expected.clear(); |
| 8428 | expected.insert(grand_parent_raw); |
| 8429 | expected.insert(parent_raw); |
| 8430 | expected.insert(child_raw); |
| 8431 | expected.insert(grand_child1_raw); |
| 8432 | expected.insert(grand_child2_raw); |
| 8433 | |
| 8434 | actual.clear(); |
| 8435 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8436 | EXPECT_EQ(expected, actual); |
| 8437 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8438 | |
| 8439 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
| 8440 | FakeImplProxy proxy; |
| 8441 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 8442 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8443 | |
| 8444 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 8445 | LayerImpl* root_layer = root.get(); |
| 8446 | scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2); |
| 8447 | LayerImpl* child1_layer = child1.get(); |
| 8448 | scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3); |
| 8449 | LayerImpl* child2_layer = child2.get(); |
| 8450 | |
| 8451 | root->AddChild(child1.Pass()); |
| 8452 | root->AddChild(child2.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8453 | root->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8454 | |
| 8455 | gfx::Transform identity_matrix, scale_transform_child1, |
| 8456 | scale_transform_child2; |
| 8457 | scale_transform_child1.Scale(2, 3); |
| 8458 | scale_transform_child2.Scale(4, 5); |
| 8459 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8460 | SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(), |
| 8461 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 8462 | true); |
| 8463 | SetLayerPropertiesForTesting(child1_layer, scale_transform_child1, |
| 8464 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 8465 | false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8466 | |
| 8467 | child1_layer->SetMaskLayer( |
| 8468 | LayerImpl::Create(host_impl.active_tree(), 4).Pass()); |
| 8469 | |
| 8470 | scoped_ptr<LayerImpl> replica_layer = |
| 8471 | LayerImpl::Create(host_impl.active_tree(), 5); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8472 | replica_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8473 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
| 8474 | child1_layer->SetReplicaLayer(replica_layer.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8475 | child1_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8476 | |
| 8477 | ExecuteCalculateDrawProperties(root_layer); |
| 8478 | |
| 8479 | TransformOperations scale; |
| 8480 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8481 | |
| 8482 | AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8483 | SetLayerPropertiesForTesting(child2_layer, scale_transform_child2, |
| 8484 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 8485 | false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8486 | |
| 8487 | ExecuteCalculateDrawProperties(root_layer); |
| 8488 | |
| 8489 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); |
| 8490 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8491 | EXPECT_FLOAT_EQ( |
| 8492 | 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8493 | EXPECT_FLOAT_EQ(3.f, |
| 8494 | child1_layer->replica_layer() |
| 8495 | ->mask_layer() |
| 8496 | ->draw_properties() |
| 8497 | .ideal_contents_scale); |
| 8498 | EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8499 | |
| 8500 | EXPECT_FLOAT_EQ( |
| 8501 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8502 | EXPECT_FLOAT_EQ( |
| 8503 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8504 | EXPECT_FLOAT_EQ(0.f, |
| 8505 | child1_layer->mask_layer() |
| 8506 | ->draw_properties() |
| 8507 | .maximum_animation_contents_scale); |
| 8508 | EXPECT_FLOAT_EQ(0.f, |
| 8509 | child1_layer->replica_layer() |
| 8510 | ->mask_layer() |
| 8511 | ->draw_properties() |
| 8512 | .maximum_animation_contents_scale); |
| 8513 | EXPECT_FLOAT_EQ( |
| 8514 | 8.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8515 | |
| 8516 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8517 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor); |
| 8518 | EXPECT_FLOAT_EQ( |
| 8519 | 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8520 | EXPECT_FLOAT_EQ(1.f, |
| 8521 | child1_layer->replica_layer() |
| 8522 | ->mask_layer() |
| 8523 | ->draw_properties() |
| 8524 | .page_scale_factor); |
| 8525 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor); |
| 8526 | |
| 8527 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); |
| 8528 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); |
| 8529 | EXPECT_FLOAT_EQ( |
| 8530 | 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8531 | EXPECT_FLOAT_EQ(1.f, |
| 8532 | child1_layer->replica_layer() |
| 8533 | ->mask_layer() |
| 8534 | ->draw_properties() |
| 8535 | .device_scale_factor); |
| 8536 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); |
| 8537 | |
| 8538 | // Changing page-scale would affect ideal_contents_scale and |
| 8539 | // maximum_animation_contents_scale. |
| 8540 | |
| 8541 | float page_scale_factor = 3.f; |
| 8542 | float device_scale_factor = 1.0f; |
| 8543 | std::vector<LayerImpl*> render_surface_layer_list; |
| 8544 | gfx::Size device_viewport_size = |
| 8545 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 8546 | root_layer->bounds().height() * device_scale_factor); |
| 8547 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8548 | root_layer, device_viewport_size, &render_surface_layer_list); |
| 8549 | |
| 8550 | inputs.page_scale_factor = page_scale_factor; |
| 8551 | inputs.can_adjust_raster_scales = true; |
| 8552 | inputs.page_scale_application_layer = root_layer; |
| 8553 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8554 | |
| 8555 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); |
| 8556 | EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8557 | EXPECT_FLOAT_EQ( |
| 8558 | 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8559 | EXPECT_FLOAT_EQ(9.f, |
| 8560 | child1_layer->replica_layer() |
| 8561 | ->mask_layer() |
| 8562 | ->draw_properties() |
| 8563 | .ideal_contents_scale); |
| 8564 | EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8565 | |
| 8566 | EXPECT_FLOAT_EQ( |
| 8567 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8568 | EXPECT_FLOAT_EQ( |
| 8569 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8570 | EXPECT_FLOAT_EQ(0.f, |
| 8571 | child1_layer->mask_layer() |
| 8572 | ->draw_properties() |
| 8573 | .maximum_animation_contents_scale); |
| 8574 | EXPECT_FLOAT_EQ(0.f, |
| 8575 | child1_layer->replica_layer() |
| 8576 | ->mask_layer() |
| 8577 | ->draw_properties() |
| 8578 | .maximum_animation_contents_scale); |
| 8579 | EXPECT_FLOAT_EQ( |
| 8580 | 24.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8581 | |
| 8582 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8583 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); |
| 8584 | EXPECT_FLOAT_EQ( |
| 8585 | 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8586 | EXPECT_FLOAT_EQ(3.f, |
| 8587 | child1_layer->replica_layer() |
| 8588 | ->mask_layer() |
| 8589 | ->draw_properties() |
| 8590 | .page_scale_factor); |
| 8591 | EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); |
| 8592 | |
| 8593 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); |
| 8594 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); |
| 8595 | EXPECT_FLOAT_EQ( |
| 8596 | 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8597 | EXPECT_FLOAT_EQ(1.f, |
| 8598 | child1_layer->replica_layer() |
| 8599 | ->mask_layer() |
| 8600 | ->draw_properties() |
| 8601 | .device_scale_factor); |
| 8602 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); |
| 8603 | |
| 8604 | // Changing device-scale would affect ideal_contents_scale and |
| 8605 | // maximum_animation_contents_scale. |
| 8606 | |
| 8607 | device_scale_factor = 4.0f; |
| 8608 | inputs.device_scale_factor = device_scale_factor; |
| 8609 | inputs.can_adjust_raster_scales = true; |
| 8610 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8611 | |
| 8612 | EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale); |
| 8613 | EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8614 | EXPECT_FLOAT_EQ( |
| 8615 | 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8616 | EXPECT_FLOAT_EQ(36.f, |
| 8617 | child1_layer->replica_layer() |
| 8618 | ->mask_layer() |
| 8619 | ->draw_properties() |
| 8620 | .ideal_contents_scale); |
| 8621 | EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8622 | |
| 8623 | EXPECT_FLOAT_EQ( |
| 8624 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8625 | EXPECT_FLOAT_EQ( |
| 8626 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8627 | EXPECT_FLOAT_EQ(0.f, |
| 8628 | child1_layer->mask_layer() |
| 8629 | ->draw_properties() |
| 8630 | .maximum_animation_contents_scale); |
| 8631 | EXPECT_FLOAT_EQ(0.f, |
| 8632 | child1_layer->replica_layer() |
| 8633 | ->mask_layer() |
| 8634 | ->draw_properties() |
| 8635 | .maximum_animation_contents_scale); |
| 8636 | EXPECT_FLOAT_EQ( |
| 8637 | 96.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8638 | |
| 8639 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8640 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); |
| 8641 | EXPECT_FLOAT_EQ( |
| 8642 | 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8643 | EXPECT_FLOAT_EQ(3.f, |
| 8644 | child1_layer->replica_layer() |
| 8645 | ->mask_layer() |
| 8646 | ->draw_properties() |
| 8647 | .page_scale_factor); |
| 8648 | EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); |
| 8649 | |
| 8650 | EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor); |
| 8651 | EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor); |
| 8652 | EXPECT_FLOAT_EQ( |
| 8653 | 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8654 | EXPECT_FLOAT_EQ(4.f, |
| 8655 | child1_layer->replica_layer() |
| 8656 | ->mask_layer() |
| 8657 | ->draw_properties() |
| 8658 | .device_scale_factor); |
| 8659 | EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor); |
| 8660 | } |
| 8661 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8662 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
| 8663 | scoped_refptr<Layer> root = Layer::Create(); |
| 8664 | SetLayerPropertiesForTesting(root.get(), |
| 8665 | gfx::Transform(), |
| 8666 | gfx::Point3F(), |
| 8667 | gfx::PointF(), |
| 8668 | gfx::Size(768 / 2, 3000), |
| 8669 | true, |
| 8670 | false); |
| 8671 | root->SetIsDrawable(true); |
| 8672 | |
| 8673 | scoped_refptr<Layer> clip = Layer::Create(); |
| 8674 | SetLayerPropertiesForTesting(clip.get(), |
| 8675 | gfx::Transform(), |
| 8676 | gfx::Point3F(), |
| 8677 | gfx::PointF(), |
| 8678 | gfx::Size(768 / 2, 10000), |
| 8679 | true, |
| 8680 | false); |
| 8681 | clip->SetMasksToBounds(true); |
| 8682 | |
| 8683 | scoped_refptr<Layer> content = Layer::Create(); |
| 8684 | SetLayerPropertiesForTesting(content.get(), |
| 8685 | gfx::Transform(), |
| 8686 | gfx::Point3F(), |
| 8687 | gfx::PointF(), |
| 8688 | gfx::Size(768 / 2, 10000), |
| 8689 | true, |
| 8690 | false); |
| 8691 | content->SetIsDrawable(true); |
| 8692 | content->SetForceRenderSurface(true); |
| 8693 | |
| 8694 | root->AddChild(clip); |
| 8695 | clip->AddChild(content); |
| 8696 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 8697 | FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 8698 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8699 | host->SetRootLayer(root); |
| 8700 | |
| 8701 | gfx::Size device_viewport_size(768, 582); |
| 8702 | RenderSurfaceLayerList render_surface_layer_list; |
| 8703 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8704 | host->root_layer(), device_viewport_size, &render_surface_layer_list); |
| 8705 | inputs.device_scale_factor = 2.f; |
| 8706 | inputs.page_scale_factor = 1.f; |
| 8707 | inputs.page_scale_application_layer = NULL; |
| 8708 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8709 | |
| 8710 | // Layers in the root render surface have their visible content rect clipped |
| 8711 | // by the viewport. |
| 8712 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); |
| 8713 | |
| 8714 | // Layers drawing to a child render surface should still have their visible |
| 8715 | // content rect clipped by the viewport. |
| 8716 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); |
| 8717 | } |
| 8718 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8719 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
| 8720 | FakeImplProxy proxy; |
| 8721 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 8722 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8723 | |
| 8724 | // Set two layers: the root layer clips it's child, |
| 8725 | // the child draws its content. |
| 8726 | |
| 8727 | gfx::Size root_size = gfx::Size(300, 500); |
| 8728 | |
| 8729 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8730 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8731 | |
| 8732 | // Device viewport accomidated the root and the top controls. |
| 8733 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
| 8734 | gfx::Transform identity_matrix; |
| 8735 | |
| 8736 | host_impl.active_tree()->SetRootLayer( |
| 8737 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8738 | |
| 8739 | LayerImpl* root = host_impl.active_tree()->root_layer(); |
| 8740 | SetLayerPropertiesForTesting(root, |
| 8741 | identity_matrix, |
| 8742 | gfx::Point3F(), |
| 8743 | gfx::PointF(), |
| 8744 | root_size, |
| 8745 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8746 | false, |
| 8747 | true); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8748 | |
| 8749 | root->SetContentBounds(root_size); |
| 8750 | root->SetMasksToBounds(true); |
| 8751 | |
| 8752 | root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2)); |
| 8753 | |
| 8754 | LayerImpl* sublayer = root->child_at(0); |
| 8755 | SetLayerPropertiesForTesting(sublayer, |
| 8756 | identity_matrix, |
| 8757 | gfx::Point3F(), |
| 8758 | gfx::PointF(), |
| 8759 | sublayer_size, |
| 8760 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8761 | false, |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8762 | false); |
| 8763 | |
| 8764 | sublayer->SetContentBounds(sublayer_size); |
| 8765 | sublayer->SetDrawsContent(true); |
| 8766 | |
| 8767 | LayerImplList layer_impl_list; |
| 8768 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8769 | root, device_viewport_size, &layer_impl_list); |
| 8770 | |
| 8771 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8772 | |
| 8773 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_content_rect()); |
| 8774 | |
| 8775 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
| 8776 | |
| 8777 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8778 | |
| 8779 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8780 | root_size.height() + 50); |
| 8781 | EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect()); |
| 8782 | } |
| 8783 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8784 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
| 8785 | const gfx::Transform identity_matrix; |
| 8786 | scoped_refptr<Layer> root = Layer::Create(); |
| 8787 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 8788 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 8789 | |
| 8790 | root->AddChild(animated); |
| 8791 | |
| 8792 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8793 | host->SetRootLayer(root); |
| 8794 | |
| 8795 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8796 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8797 | SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 8798 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 8799 | |
| 8800 | root->SetMasksToBounds(true); |
| 8801 | root->SetForceRenderSurface(true); |
| 8802 | animated->SetOpacity(0.f); |
| 8803 | |
| 8804 | AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0, |
| 8805 | 0.f, 1.f, false); |
| 8806 | |
| 8807 | ExecuteCalculateDrawProperties(root.get()); |
| 8808 | |
| 8809 | EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty()); |
| 8810 | } |
| 8811 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8812 | // Verify that having an animated filter (but no current filter, as these |
| 8813 | // are mutually exclusive) correctly creates a render surface. |
| 8814 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
| 8815 | scoped_refptr<Layer> root = Layer::Create(); |
| 8816 | scoped_refptr<Layer> child = Layer::Create(); |
| 8817 | scoped_refptr<Layer> grandchild = Layer::Create(); |
| 8818 | root->AddChild(child); |
| 8819 | child->AddChild(grandchild); |
| 8820 | |
| 8821 | gfx::Transform identity_transform; |
| 8822 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8823 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8824 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8825 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8826 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8827 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 8828 | true, false); |
| 8829 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8830 | host->SetRootLayer(root); |
| 8831 | |
| 8832 | AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f); |
| 8833 | |
| 8834 | ExecuteCalculateDrawProperties(root.get()); |
| 8835 | |
| 8836 | EXPECT_TRUE(root->render_surface()); |
| 8837 | EXPECT_TRUE(child->render_surface()); |
| 8838 | EXPECT_FALSE(grandchild->render_surface()); |
| 8839 | |
| 8840 | EXPECT_TRUE(root->filters().IsEmpty()); |
| 8841 | EXPECT_TRUE(child->filters().IsEmpty()); |
| 8842 | EXPECT_TRUE(grandchild->filters().IsEmpty()); |
| 8843 | |
| 8844 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8845 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 8846 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8847 | } |
| 8848 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8849 | // Ensures that the property tree code accounts for offsets between fixed |
| 8850 | // position layers and their respective containers. |
| 8851 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
| 8852 | scoped_refptr<Layer> root = Layer::Create(); |
| 8853 | scoped_refptr<Layer> child = Layer::Create(); |
| 8854 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
| 8855 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 8856 | |
| 8857 | root->AddChild(child); |
| 8858 | child->AddChild(grandchild); |
| 8859 | |
| 8860 | gfx::Transform identity_transform; |
| 8861 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8862 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8863 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8864 | gfx::PointF(1000, 1000), gfx::Size(50, 50), true, |
| 8865 | false); |
| 8866 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8867 | gfx::Point3F(), gfx::PointF(-1000, -1000), |
| 8868 | gfx::Size(50, 50), true, false); |
| 8869 | |
| 8870 | root->SetMasksToBounds(true); |
| 8871 | root->SetIsContainerForFixedPositionLayers(true); |
| 8872 | LayerPositionConstraint constraint; |
| 8873 | constraint.set_is_fixed_position(true); |
| 8874 | grandchild->SetPositionConstraint(constraint); |
| 8875 | |
| 8876 | root->SetIsContainerForFixedPositionLayers(true); |
| 8877 | |
| 8878 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8879 | host->SetRootLayer(root); |
| 8880 | |
| 8881 | ExecuteCalculateDrawProperties(root.get()); |
| 8882 | |
| 8883 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), |
| 8884 | grandchild->visible_rect_from_property_trees()); |
| 8885 | } |
| 8886 | |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8887 | TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) { |
| 8888 | // In the following layer tree, the layer |box|'s render target is |surface|. |
| 8889 | // |surface| also creates a transform node. We want to combine clips for |box| |
| 8890 | // in the space of its target (i.e., |surface|), not its target's target. This |
| 8891 | // test ensures that happens. |
| 8892 | |
| 8893 | gfx::Transform rotate; |
| 8894 | rotate.Rotate(5); |
| 8895 | gfx::Transform identity; |
| 8896 | |
| 8897 | scoped_refptr<Layer> root = Layer::Create(); |
| 8898 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8899 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 8900 | false); |
| 8901 | |
| 8902 | scoped_refptr<Layer> frame_clip = Layer::Create(); |
| 8903 | SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), |
| 8904 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 8905 | false); |
| 8906 | frame_clip->SetMasksToBounds(true); |
| 8907 | |
| 8908 | scoped_refptr<Layer> rotated = Layer::Create(); |
| 8909 | SetLayerPropertiesForTesting(rotated.get(), rotate, |
| 8910 | gfx::Point3F(1250, 250, 0), gfx::PointF(), |
| 8911 | gfx::Size(2500, 500), true, false); |
| 8912 | |
| 8913 | scoped_refptr<Layer> surface = Layer::Create(); |
| 8914 | SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(), |
| 8915 | gfx::PointF(), gfx::Size(2500, 500), true, |
| 8916 | false); |
| 8917 | surface->SetOpacity(0.5); |
| 8918 | |
| 8919 | scoped_refptr<LayerWithForcedDrawsContent> container = |
| 8920 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 8921 | SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(), |
| 8922 | gfx::PointF(), gfx::Size(300, 300), true, false); |
| 8923 | |
| 8924 | scoped_refptr<LayerWithForcedDrawsContent> box = |
| 8925 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 8926 | SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(), |
| 8927 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8928 | |
| 8929 | root->AddChild(frame_clip); |
| 8930 | frame_clip->AddChild(rotated); |
| 8931 | rotated->AddChild(surface); |
| 8932 | surface->AddChild(container); |
| 8933 | surface->AddChild(box); |
| 8934 | |
| 8935 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8936 | host->SetRootLayer(root); |
| 8937 | |
| 8938 | ExecuteCalculateDrawProperties(root.get()); |
| 8939 | } |
| 8940 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 8941 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
| 8942 | gfx::Transform identity; |
| 8943 | gfx::Transform translate_z; |
| 8944 | translate_z.Translate3d(0, 0, 10); |
| 8945 | |
| 8946 | scoped_refptr<Layer> root = Layer::Create(); |
| 8947 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8948 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8949 | root->SetIsContainerForFixedPositionLayers(true); |
| 8950 | |
| 8951 | scoped_refptr<Layer> frame_clip = Layer::Create(); |
| 8952 | SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(), |
| 8953 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
| 8954 | false); |
| 8955 | frame_clip->SetMasksToBounds(true); |
| 8956 | |
| 8957 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
| 8958 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 8959 | SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(), |
| 8960 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 8961 | false); |
| 8962 | |
| 8963 | LayerPositionConstraint constraint; |
| 8964 | constraint.set_is_fixed_position(true); |
| 8965 | fixed->SetPositionConstraint(constraint); |
| 8966 | |
| 8967 | root->AddChild(frame_clip); |
| 8968 | frame_clip->AddChild(fixed); |
| 8969 | |
| 8970 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8971 | host->SetRootLayer(root); |
| 8972 | |
| 8973 | ExecuteCalculateDrawProperties(root.get()); |
| 8974 | |
| 8975 | gfx::Rect expected(0, 0, 100, 100); |
| 8976 | EXPECT_EQ(expected, fixed->visible_rect_from_property_trees()); |
| 8977 | } |
| 8978 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 8979 | } // namespace |
| 8980 | } // namespace cc |