[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" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 31 | #include "cc/trees/layer_tree_impl.h" |
| 32 | #include "cc/trees/proxy.h" |
| 33 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 34 | #include "testing/gmock/include/gmock/gmock.h" |
| 35 | #include "testing/gtest/include/gtest/gtest.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 36 | #include "ui/gfx/geometry/quad_f.h" |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 37 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 38 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 39 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 40 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 41 | namespace { |
| 42 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 43 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 44 | public: |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 45 | LayerWithForcedDrawsContent() {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 46 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 47 | bool DrawsContent() const override; |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 48 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 49 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 50 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 51 | }; |
| 52 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 53 | bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 54 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 55 | class MockContentLayerClient : public ContentLayerClient { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 56 | public: |
| 57 | MockContentLayerClient() {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 58 | ~MockContentLayerClient() override {} |
schenney | 0154bfa | 2015-02-05 19:46:49 | [diff] [blame] | 59 | void PaintContents(SkCanvas* canvas, |
| 60 | const gfx::Rect& clip, |
| 61 | PaintingControlSetting picture_control) override {} |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 62 | scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| 63 | const gfx::Rect& clip, |
schenney | 0154bfa | 2015-02-05 19:46:49 | [diff] [blame] | 64 | PaintingControlSetting picture_control) override { |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 65 | NOTIMPLEMENTED(); |
| 66 | return DisplayItemList::Create(); |
| 67 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 68 | bool FillsBoundsCompletely() const override { return false; } |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 69 | }; |
| 70 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 71 | scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer( |
| 72 | ContentLayerClient* delegate) { |
| 73 | scoped_refptr<FakePictureLayer> to_return = |
| 74 | FakePictureLayer::Create(delegate); |
| 75 | to_return->SetIsDrawable(true); |
| 76 | return to_return; |
| 77 | } |
| 78 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 79 | scoped_refptr<ContentLayer> CreateDrawableContentLayer( |
| 80 | ContentLayerClient* delegate) { |
| 81 | scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate); |
| 82 | to_return->SetIsDrawable(true); |
| 83 | return to_return; |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 84 | } |
| 85 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 86 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 87 | do { \ |
| 88 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 89 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 90 | } while (false) |
| 91 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 92 | #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \ |
| 93 | do { \ |
| 94 | EXPECT_FLOAT_EQ(expected, layer->draw_properties().ideal_contents_scale); \ |
| 95 | } while (false) |
| 96 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 97 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 98 | // Sanity check: For layers positioned at zero, with zero size, |
| 99 | // and with identity transforms, then the draw transform, |
| 100 | // screen space transform, and the hierarchy passed on to children |
| 101 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 102 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 103 | scoped_refptr<Layer> parent = Layer::Create(); |
| 104 | scoped_refptr<Layer> child = Layer::Create(); |
| 105 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 106 | parent->AddChild(child); |
| 107 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 108 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 109 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 110 | host->SetRootLayer(parent); |
| 111 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 112 | gfx::Transform identity_matrix; |
| 113 | SetLayerPropertiesForTesting(parent.get(), |
| 114 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 115 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 116 | gfx::PointF(), |
| 117 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 118 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 119 | false); |
| 120 | SetLayerPropertiesForTesting(child.get(), |
| 121 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 122 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 123 | gfx::PointF(), |
| 124 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 125 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 126 | false); |
| 127 | SetLayerPropertiesForTesting(grand_child.get(), |
| 128 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 129 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 130 | gfx::PointF(), |
| 131 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 132 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 133 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 134 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 135 | ExecuteCalculateDrawProperties(parent.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 136 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 137 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 138 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 139 | child->screen_space_transform()); |
| 140 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 141 | grand_child->draw_transform()); |
| 142 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 143 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 144 | } |
| 145 | |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 146 | TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) { |
| 147 | scoped_refptr<Layer> parent = Layer::Create(); |
| 148 | scoped_refptr<Layer> child = Layer::Create(); |
| 149 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 150 | parent->AddChild(child); |
| 151 | child->AddChild(grand_child); |
| 152 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 153 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 154 | host->SetRootLayer(parent); |
| 155 | |
| 156 | gfx::Transform identity_matrix; |
| 157 | SetLayerPropertiesForTesting(parent.get(), |
| 158 | identity_matrix, |
| 159 | gfx::Point3F(), |
| 160 | gfx::PointF(), |
| 161 | gfx::Size(100, 100), |
| 162 | true, |
| 163 | false); |
| 164 | SetLayerPropertiesForTesting(child.get(), |
| 165 | identity_matrix, |
| 166 | gfx::Point3F(), |
| 167 | gfx::PointF(10, 10), |
| 168 | gfx::Size(100, 100), |
| 169 | true, |
| 170 | false); |
| 171 | // This would have previously caused us to skip our subtree, but this would be |
| 172 | // wrong; we need up-to-date draw properties to do hit testing on the layers |
| 173 | // with handlers. |
| 174 | child->SetOpacity(0.f); |
| 175 | SetLayerPropertiesForTesting(grand_child.get(), |
| 176 | identity_matrix, |
| 177 | gfx::Point3F(), |
| 178 | gfx::PointF(10, 10), |
| 179 | gfx::Size(100, 100), |
| 180 | true, |
| 181 | false); |
| 182 | grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
| 183 | |
| 184 | ExecuteCalculateDrawProperties(parent.get()); |
| 185 | |
| 186 | // Check that we've computed draw properties for the subtree rooted at |
| 187 | // |child|. |
| 188 | EXPECT_FALSE(child->draw_transform().IsIdentity()); |
| 189 | EXPECT_FALSE(grand_child->draw_transform().IsIdentity()); |
| 190 | } |
| 191 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 192 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 193 | gfx::Transform identity_matrix; |
| 194 | scoped_refptr<Layer> layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 195 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 196 | scoped_refptr<Layer> root = Layer::Create(); |
| 197 | SetLayerPropertiesForTesting(root.get(), |
| 198 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 199 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 200 | gfx::PointF(), |
| 201 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 202 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 203 | false); |
| 204 | root->AddChild(layer); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 205 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 206 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 207 | host->SetRootLayer(root); |
| 208 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 209 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 210 | // transform or the screenspace transform. |
| 211 | gfx::Transform translation_to_center; |
| 212 | translation_to_center.Translate(5.0, 6.0); |
| 213 | SetLayerPropertiesForTesting(layer.get(), |
| 214 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 215 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 216 | gfx::PointF(), |
| 217 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 218 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 219 | false); |
| 220 | ExecuteCalculateDrawProperties(root.get()); |
| 221 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 222 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 223 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 224 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 225 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 226 | // no effect on the transforms. |
| 227 | SetLayerPropertiesForTesting(layer.get(), |
| 228 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 229 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 230 | gfx::PointF(), |
| 231 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 232 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 233 | false); |
| 234 | ExecuteCalculateDrawProperties(root.get()); |
| 235 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 236 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 237 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 238 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 239 | // Case 4: A change in actual position affects both the draw transform and |
| 240 | // screen space transform. |
| 241 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 242 | position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 243 | SetLayerPropertiesForTesting(layer.get(), |
| 244 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 245 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 246 | gfx::PointF(0.f, 1.2f), |
| 247 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 248 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 249 | false); |
| 250 | ExecuteCalculateDrawProperties(root.get()); |
| 251 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform()); |
| 252 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, |
| 253 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 254 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 255 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 256 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 257 | // scale transform, because scale and translation are not commutative. |
| 258 | gfx::Transform layer_transform; |
| 259 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 260 | SetLayerPropertiesForTesting(layer.get(), |
| 261 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 262 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 263 | gfx::PointF(), |
| 264 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 265 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 266 | false); |
| 267 | ExecuteCalculateDrawProperties(root.get()); |
| 268 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform()); |
| 269 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, |
| 270 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 271 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 272 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 273 | gfx::Transform translation_to_anchor; |
| 274 | translation_to_anchor.Translate(5.0, 0.0); |
| 275 | gfx::Transform expected_result = |
| 276 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
| 277 | SetLayerPropertiesForTesting(layer.get(), |
| 278 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 279 | gfx::Point3F(5.0f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 280 | gfx::PointF(), |
| 281 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 282 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 283 | false); |
| 284 | ExecuteCalculateDrawProperties(root.get()); |
| 285 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 286 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 287 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 288 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 289 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 290 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 291 | // it is still worth testing to detect accidental regressions. |
| 292 | expected_result = position_transform * translation_to_anchor * |
| 293 | layer_transform * Inverse(translation_to_anchor); |
| 294 | SetLayerPropertiesForTesting(layer.get(), |
| 295 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 296 | gfx::Point3F(5.0f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 297 | gfx::PointF(0.f, 1.2f), |
| 298 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 299 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 300 | false); |
| 301 | ExecuteCalculateDrawProperties(root.get()); |
| 302 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 303 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 304 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 305 | } |
| 306 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 307 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 308 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 309 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 310 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 311 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 312 | -kScrollOffset.y()); |
| 313 | const float kPageScale = 0.888f; |
| 314 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 315 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 316 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 317 | TestSharedBitmapManager shared_bitmap_manager; |
| 318 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 319 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 320 | gfx::Transform identity_matrix; |
| 321 | scoped_ptr<LayerImpl> sublayer_scoped_ptr( |
| 322 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 323 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
| 324 | sublayer->SetContentsScale(kPageScale * kDeviceScale, |
| 325 | kPageScale * kDeviceScale); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 326 | SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(), |
| 327 | gfx::PointF(), gfx::Size(500, 500), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 328 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 329 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 330 | scoped_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 331 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 332 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 333 | SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(), |
| 334 | gfx::PointF(), gfx::Size(10, 20), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 335 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 336 | scoped_ptr<LayerImpl> clip_layer_scoped_ptr( |
| 337 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 338 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 339 | |
| 340 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 341 | clip_layer->SetBounds( |
| 342 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 343 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 344 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 345 | scroll_layer->SetScrollDelta(kScrollDelta); |
| 346 | gfx::Transform impl_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 347 | scroll_layer->AddChild(sublayer_scoped_ptr.Pass()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 348 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
| 349 | clip_layer->AddChild(scroll_layer_scoped_ptr.Pass()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 350 | scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 351 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 352 | scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 353 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 354 | gfx::PointF(), gfx::Size(3, 4), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 355 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 356 | root->AddChild(clip_layer_scoped_ptr.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 357 | root->SetHasRenderSurface(true); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 358 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 359 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 360 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 361 | gfx::Transform expected_transform = identity_matrix; |
| 362 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
| 363 | sub_layer_screen_position.Scale(kPageScale * kDeviceScale); |
| 364 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()), |
| 365 | MathUtil::Round(sub_layer_screen_position.y())); |
| 366 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 367 | sublayer->draw_transform()); |
| 368 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 369 | sublayer->screen_space_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 370 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 371 | gfx::Transform arbitrary_translate; |
| 372 | const float kTranslateX = 10.6f; |
| 373 | const float kTranslateY = 20.6f; |
| 374 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 375 | SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate, |
| 376 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20), |
| 377 | true, false, false); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 378 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 379 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 380 | expected_transform.MakeIdentity(); |
| 381 | expected_transform.Translate( |
| 382 | MathUtil::Round(kTranslateX * kPageScale * kDeviceScale + |
| 383 | sub_layer_screen_position.x()), |
| 384 | MathUtil::Round(kTranslateY * kPageScale * kDeviceScale + |
| 385 | sub_layer_screen_position.y())); |
| 386 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 387 | sublayer->draw_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 388 | } |
| 389 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 390 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 391 | gfx::Transform identity_matrix; |
| 392 | scoped_refptr<Layer> root = Layer::Create(); |
| 393 | scoped_refptr<Layer> parent = Layer::Create(); |
| 394 | scoped_refptr<Layer> child = Layer::Create(); |
| 395 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 396 | root->AddChild(parent); |
| 397 | parent->AddChild(child); |
| 398 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 399 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 400 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 401 | host->SetRootLayer(root); |
| 402 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 403 | // One-time setup of root layer |
| 404 | SetLayerPropertiesForTesting(root.get(), |
| 405 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 406 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 407 | gfx::PointF(), |
| 408 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 409 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 410 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 411 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 412 | // Case 1: parent's anchor point should not affect child or grand_child. |
| 413 | SetLayerPropertiesForTesting(parent.get(), |
| 414 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 415 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 416 | gfx::PointF(), |
| 417 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 418 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 419 | false); |
| 420 | SetLayerPropertiesForTesting(child.get(), |
| 421 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 422 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 423 | gfx::PointF(), |
| 424 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 425 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 426 | false); |
| 427 | SetLayerPropertiesForTesting(grand_child.get(), |
| 428 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 429 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 430 | gfx::PointF(), |
| 431 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 432 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 433 | false); |
| 434 | ExecuteCalculateDrawProperties(root.get()); |
| 435 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 436 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 437 | child->screen_space_transform()); |
| 438 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 439 | grand_child->draw_transform()); |
| 440 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 441 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 442 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 443 | // Case 2: parent's position affects child and grand_child. |
| 444 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 445 | parent_position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 446 | SetLayerPropertiesForTesting(parent.get(), |
| 447 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 448 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 449 | gfx::PointF(0.f, 1.2f), |
| 450 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 451 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 452 | false); |
| 453 | SetLayerPropertiesForTesting(child.get(), |
| 454 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 455 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 456 | gfx::PointF(), |
| 457 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 458 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 459 | false); |
| 460 | SetLayerPropertiesForTesting(grand_child.get(), |
| 461 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 462 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 463 | gfx::PointF(), |
| 464 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 465 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 466 | false); |
| 467 | ExecuteCalculateDrawProperties(root.get()); |
| 468 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 469 | child->draw_transform()); |
| 470 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 471 | child->screen_space_transform()); |
| 472 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 473 | grand_child->draw_transform()); |
| 474 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 475 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 476 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 477 | // Case 3: parent's local transform affects child and grandchild |
| 478 | gfx::Transform parent_layer_transform; |
| 479 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 480 | gfx::Transform parent_translation_to_anchor; |
| 481 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 482 | gfx::Transform parent_composite_transform = |
| 483 | parent_translation_to_anchor * parent_layer_transform * |
| 484 | Inverse(parent_translation_to_anchor); |
| 485 | SetLayerPropertiesForTesting(parent.get(), |
| 486 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 487 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 488 | gfx::PointF(), |
| 489 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 490 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 491 | false); |
| 492 | SetLayerPropertiesForTesting(child.get(), |
| 493 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 494 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 495 | gfx::PointF(), |
| 496 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 497 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 498 | false); |
| 499 | SetLayerPropertiesForTesting(grand_child.get(), |
| 500 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 501 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 502 | gfx::PointF(), |
| 503 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 504 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 505 | false); |
| 506 | ExecuteCalculateDrawProperties(root.get()); |
| 507 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 508 | child->draw_transform()); |
| 509 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 510 | child->screen_space_transform()); |
| 511 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 512 | grand_child->draw_transform()); |
| 513 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 514 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 515 | } |
| 516 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 517 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 518 | scoped_refptr<Layer> root = Layer::Create(); |
| 519 | scoped_refptr<Layer> parent = Layer::Create(); |
| 520 | scoped_refptr<Layer> child = Layer::Create(); |
| 521 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 522 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 523 | root->AddChild(parent); |
| 524 | parent->AddChild(child); |
| 525 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 526 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 527 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 528 | host->SetRootLayer(root); |
| 529 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 530 | // One-time setup of root layer |
| 531 | gfx::Transform identity_matrix; |
| 532 | SetLayerPropertiesForTesting(root.get(), |
| 533 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 534 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 535 | gfx::PointF(), |
| 536 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 537 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 538 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 539 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 540 | // Child is set up so that a new render surface should be created. |
| 541 | child->SetOpacity(0.5f); |
| 542 | child->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 543 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 544 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 545 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 546 | gfx::Transform parent_translation_to_anchor; |
| 547 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 548 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 549 | gfx::Transform parent_composite_transform = |
| 550 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 551 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 552 | gfx::Vector2dF parent_composite_scale = |
| 553 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 554 | 1.f); |
| 555 | gfx::Transform surface_sublayer_transform; |
| 556 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 557 | parent_composite_scale.y()); |
| 558 | gfx::Transform surface_sublayer_composite_transform = |
| 559 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 560 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 561 | // Child's render surface should not exist yet. |
| 562 | ASSERT_FALSE(child->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 563 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 564 | SetLayerPropertiesForTesting(parent.get(), |
| 565 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 566 | gfx::Point3F(25.0f, 30.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 567 | gfx::PointF(), |
| 568 | gfx::Size(100, 120), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 569 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 570 | false); |
| 571 | SetLayerPropertiesForTesting(child.get(), |
| 572 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 573 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 574 | gfx::PointF(), |
| 575 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 576 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 577 | false); |
| 578 | SetLayerPropertiesForTesting(grand_child.get(), |
| 579 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 580 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 581 | gfx::PointF(), |
| 582 | gfx::Size(8, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 583 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 584 | false); |
| 585 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 586 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 587 | // Render surface should have been created now. |
| 588 | ASSERT_TRUE(child->render_surface()); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 589 | ASSERT_EQ(child.get(), child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 590 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 591 | // The child layer's draw transform should refer to its new render surface. |
| 592 | // The screen-space transform, however, should still refer to the root. |
| 593 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
| 594 | child->draw_transform()); |
| 595 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 596 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 597 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 598 | // Because the grand_child is the only drawable content, the child's render |
| 599 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 600 | // surface's subtree is drawn must be removed from the composite transform. |
| 601 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 602 | surface_sublayer_composite_transform, |
| 603 | child->render_target()->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 604 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 605 | // The screen space is the same as the target since the child surface draws |
| 606 | // into the root. |
| 607 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 608 | surface_sublayer_composite_transform, |
| 609 | child->render_target()->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 610 | } |
| 611 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 612 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 613 | scoped_refptr<Layer> root = Layer::Create(); |
| 614 | scoped_refptr<Layer> parent = Layer::Create(); |
| 615 | scoped_refptr<Layer> child = Layer::Create(); |
| 616 | scoped_refptr<Layer> child_replica = Layer::Create(); |
| 617 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 618 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 619 | root->AddChild(parent); |
| 620 | parent->AddChild(child); |
| 621 | child->AddChild(grand_child); |
| 622 | child->SetReplicaLayer(child_replica.get()); |
| 623 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 624 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 625 | host->SetRootLayer(root); |
| 626 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 627 | // One-time setup of root layer |
| 628 | gfx::Transform identity_matrix; |
| 629 | SetLayerPropertiesForTesting(root.get(), |
| 630 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 631 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 632 | gfx::PointF(), |
| 633 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 634 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 635 | false); |
| 636 | |
| 637 | // Child is set up so that a new render surface should be created. |
| 638 | child->SetOpacity(0.5f); |
| 639 | |
| 640 | gfx::Transform parent_layer_transform; |
| 641 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 642 | gfx::Transform parent_translation_to_anchor; |
| 643 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 644 | gfx::Transform parent_composite_transform = |
| 645 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 646 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 647 | gfx::Transform replica_layer_transform; |
| 648 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 649 | gfx::Vector2dF parent_composite_scale = |
| 650 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 651 | 1.f); |
| 652 | gfx::Transform surface_sublayer_transform; |
| 653 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 654 | parent_composite_scale.y()); |
| 655 | gfx::Transform replica_composite_transform = |
| 656 | parent_composite_transform * replica_layer_transform * |
| 657 | Inverse(surface_sublayer_transform); |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 658 | child_replica->SetIsDrawable(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 659 | // Child's render surface should not exist yet. |
| 660 | ASSERT_FALSE(child->render_surface()); |
| 661 | |
| 662 | SetLayerPropertiesForTesting(parent.get(), |
| 663 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 664 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 665 | gfx::PointF(), |
| 666 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 667 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 668 | false); |
| 669 | SetLayerPropertiesForTesting(child.get(), |
| 670 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 671 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 672 | gfx::PointF(), |
| 673 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 674 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 675 | false); |
| 676 | SetLayerPropertiesForTesting(grand_child.get(), |
| 677 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 678 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 679 | gfx::PointF(-0.5f, -0.5f), |
| 680 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 681 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 682 | false); |
| 683 | SetLayerPropertiesForTesting(child_replica.get(), |
| 684 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 685 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 686 | gfx::PointF(), |
| 687 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 688 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 689 | false); |
| 690 | ExecuteCalculateDrawProperties(root.get()); |
| 691 | |
| 692 | // Render surface should have been created now. |
| 693 | ASSERT_TRUE(child->render_surface()); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 694 | ASSERT_EQ(child.get(), child->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 695 | |
| 696 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 697 | replica_composite_transform, |
| 698 | child->render_target()->render_surface()->replica_draw_transform()); |
| 699 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 700 | child->render_target() |
| 701 | ->render_surface() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 702 | ->replica_screen_space_transform()); |
| 703 | } |
| 704 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 705 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 706 | // This test creates a more complex tree and verifies it all at once. This |
| 707 | // covers the following cases: |
| 708 | // - layers that are described w.r.t. a render surface: should have draw |
| 709 | // transforms described w.r.t. that surface |
| 710 | // - A render surface described w.r.t. an ancestor render surface: should |
| 711 | // have a draw transform described w.r.t. that ancestor surface |
| 712 | // - Replicas of a render surface are described w.r.t. the replica's |
| 713 | // transform around its anchor, along with the surface itself. |
| 714 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 715 | // a render surface that is described w.r.t. an ancestor render surface. |
| 716 | // - verifying that each layer has a reference to the correct render surface |
| 717 | // and render target values. |
| 718 | |
| 719 | scoped_refptr<Layer> root = Layer::Create(); |
| 720 | scoped_refptr<Layer> parent = Layer::Create(); |
| 721 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 722 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 723 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 724 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 725 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 726 | scoped_refptr<Layer> replica_of_rs1 = Layer::Create(); |
| 727 | scoped_refptr<Layer> replica_of_rs2 = Layer::Create(); |
| 728 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 729 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 730 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 731 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 732 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 733 | root->AddChild(parent); |
| 734 | parent->AddChild(render_surface1); |
| 735 | parent->AddChild(child_of_root); |
| 736 | render_surface1->AddChild(child_of_rs1); |
| 737 | render_surface1->AddChild(render_surface2); |
| 738 | render_surface2->AddChild(child_of_rs2); |
| 739 | child_of_root->AddChild(grand_child_of_root); |
| 740 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 741 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 742 | render_surface1->SetReplicaLayer(replica_of_rs1.get()); |
| 743 | render_surface2->SetReplicaLayer(replica_of_rs2.get()); |
| 744 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 745 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 746 | host->SetRootLayer(root); |
| 747 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 748 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 749 | // to have a new render surface. |
| 750 | render_surface1->SetOpacity(0.5f); |
| 751 | render_surface2->SetOpacity(0.33f); |
| 752 | |
| 753 | // One-time setup of root layer |
| 754 | gfx::Transform identity_matrix; |
| 755 | SetLayerPropertiesForTesting(root.get(), |
| 756 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 757 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 758 | gfx::PointF(), |
| 759 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 760 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 761 | false); |
| 762 | |
| 763 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 764 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 765 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 766 | gfx::Transform translation_to_anchor; |
| 767 | translation_to_anchor.Translate(2.5, 0.0); |
| 768 | gfx::Transform layer_transform; |
| 769 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 770 | gfx::Transform replica_layer_transform; |
| 771 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 772 | |
| 773 | gfx::Transform A = |
| 774 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 775 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 776 | Inverse(translation_to_anchor); |
| 777 | |
| 778 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 779 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 780 | gfx::Transform surface1_sublayer_transform; |
| 781 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 782 | surface1_parent_transform_scale.y()); |
| 783 | |
| 784 | // SS1 = transform given to the subtree of render_surface1 |
| 785 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 786 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 787 | // the owning layer |
| 788 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 789 | |
| 790 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 791 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 792 | gfx::Transform surface2_sublayer_transform; |
| 793 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 794 | surface2_parent_transform_scale.y()); |
| 795 | |
| 796 | // SS2 = transform given to the subtree of render_surface2 |
| 797 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 798 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 799 | // the owning layer |
| 800 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 801 | |
| 802 | SetLayerPropertiesForTesting(parent.get(), |
| 803 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 804 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 805 | gfx::PointF(), |
| 806 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 807 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 808 | false); |
| 809 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 810 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 811 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 812 | gfx::PointF(), |
| 813 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 814 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 815 | false); |
| 816 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 817 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 818 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 819 | gfx::PointF(), |
| 820 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 821 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 822 | false); |
| 823 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 824 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 825 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 826 | gfx::PointF(), |
| 827 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 828 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 829 | false); |
| 830 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 831 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 832 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 833 | gfx::PointF(), |
| 834 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 835 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 836 | false); |
| 837 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 838 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 839 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 840 | gfx::PointF(), |
| 841 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 842 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 843 | false); |
| 844 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 845 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 846 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 847 | gfx::PointF(), |
| 848 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 849 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 850 | false); |
| 851 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 852 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 853 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 854 | gfx::PointF(), |
| 855 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 856 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 857 | false); |
| 858 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 859 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 860 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 861 | gfx::PointF(), |
| 862 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 863 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 864 | false); |
| 865 | SetLayerPropertiesForTesting(replica_of_rs1.get(), |
| 866 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 867 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 868 | gfx::PointF(), |
| 869 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 870 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 871 | false); |
| 872 | SetLayerPropertiesForTesting(replica_of_rs2.get(), |
| 873 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 874 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 875 | gfx::PointF(), |
| 876 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 877 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 878 | false); |
| 879 | |
| 880 | ExecuteCalculateDrawProperties(root.get()); |
| 881 | |
| 882 | // Only layers that are associated with render surfaces should have an actual |
| 883 | // RenderSurface() value. |
| 884 | ASSERT_TRUE(root->render_surface()); |
| 885 | ASSERT_FALSE(child_of_root->render_surface()); |
| 886 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 887 | |
| 888 | ASSERT_TRUE(render_surface1->render_surface()); |
| 889 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 890 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 891 | |
| 892 | ASSERT_TRUE(render_surface2->render_surface()); |
| 893 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 894 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 895 | |
| 896 | // Verify all render target accessors |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 897 | EXPECT_EQ(root.get(), parent->render_target()); |
| 898 | EXPECT_EQ(root.get(), child_of_root->render_target()); |
| 899 | EXPECT_EQ(root.get(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 900 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 901 | EXPECT_EQ(render_surface1.get(), render_surface1->render_target()); |
| 902 | EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target()); |
| 903 | EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 904 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 905 | EXPECT_EQ(render_surface2.get(), render_surface2->render_target()); |
| 906 | EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target()); |
| 907 | EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 908 | |
| 909 | // Verify layer draw transforms note that draw transforms are described with |
| 910 | // respect to the nearest ancestor render surface but screen space transforms |
| 911 | // are described with respect to the root. |
| 912 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 913 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform()); |
| 914 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 915 | grand_child_of_root->draw_transform()); |
| 916 | |
| 917 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 918 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform()); |
| 919 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 920 | grand_child_of_rs1->draw_transform()); |
| 921 | |
| 922 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 923 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform()); |
| 924 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 925 | grand_child_of_rs2->draw_transform()); |
| 926 | |
| 927 | // Verify layer screen-space transforms |
| 928 | // |
| 929 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 930 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 931 | child_of_root->screen_space_transform()); |
| 932 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 933 | A * A * A, grand_child_of_root->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 934 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 935 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 936 | render_surface1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 937 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 938 | child_of_rs1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 939 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 940 | grand_child_of_rs1->screen_space_transform()); |
| 941 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 942 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 943 | render_surface2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 944 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 945 | child_of_rs2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 946 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 947 | grand_child_of_rs2->screen_space_transform()); |
| 948 | |
| 949 | // Verify render surface transforms. |
| 950 | // |
| 951 | // Draw transform of render surface 1 is described with respect to root. |
| 952 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 953 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 954 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 955 | A * R * S1, render_surface1->render_surface()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 956 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 957 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 958 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 959 | A * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 960 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 961 | // Draw transform of render surface 2 is described with respect to render |
| 962 | // surface 1. |
| 963 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 964 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 965 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 966 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 967 | render_surface2->render_surface()->replica_draw_transform()); |
| 968 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 969 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 970 | render_surface2->render_surface()->screen_space_transform()); |
| 971 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 972 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 973 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 974 | |
| 975 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 976 | // is expected that we correctly set up transforms so that the y-component of |
| 977 | // the screen-space transform encodes the "depth" of the layer in the tree. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 978 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 979 | EXPECT_FLOAT_EQ(2.0, |
| 980 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 981 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 982 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 983 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 984 | EXPECT_FLOAT_EQ(2.0, |
| 985 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 986 | EXPECT_FLOAT_EQ(3.0, |
| 987 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 988 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 989 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 990 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 991 | EXPECT_FLOAT_EQ(3.0, |
| 992 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 993 | EXPECT_FLOAT_EQ(4.0, |
| 994 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 995 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 996 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 997 | } |
| 998 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 999 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1000 | // For layers that flatten their subtree, there should be an orthographic |
| 1001 | // projection (for x and y values) in the middle of the transform sequence. |
| 1002 | // Note that the way the code is currently implemented, it is not expected to |
| 1003 | // use a canonical orthographic projection. |
| 1004 | |
| 1005 | scoped_refptr<Layer> root = Layer::Create(); |
| 1006 | scoped_refptr<Layer> child = Layer::Create(); |
| 1007 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1008 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1009 | scoped_refptr<LayerWithForcedDrawsContent> great_grand_child = |
| 1010 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1011 | |
| 1012 | gfx::Transform rotation_about_y_axis; |
| 1013 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1014 | |
| 1015 | const gfx::Transform identity_matrix; |
| 1016 | SetLayerPropertiesForTesting(root.get(), |
| 1017 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1018 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1019 | gfx::PointF(), |
| 1020 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1021 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1022 | false); |
| 1023 | SetLayerPropertiesForTesting(child.get(), |
| 1024 | rotation_about_y_axis, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1025 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1026 | gfx::PointF(), |
| 1027 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1028 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1029 | false); |
| 1030 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1031 | rotation_about_y_axis, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1032 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1033 | gfx::PointF(), |
| 1034 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1035 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1036 | false); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1037 | SetLayerPropertiesForTesting(great_grand_child.get(), identity_matrix, |
| 1038 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1039 | true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1040 | |
| 1041 | root->AddChild(child); |
| 1042 | child->AddChild(grand_child); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1043 | grand_child->AddChild(great_grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1044 | child->SetForceRenderSurface(true); |
| 1045 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1046 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1047 | host->SetRootLayer(root); |
| 1048 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1049 | // No layers in this test should preserve 3d. |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1050 | ASSERT_TRUE(root->should_flatten_transform()); |
| 1051 | ASSERT_TRUE(child->should_flatten_transform()); |
| 1052 | ASSERT_TRUE(grand_child->should_flatten_transform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1053 | ASSERT_TRUE(great_grand_child->should_flatten_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1054 | |
| 1055 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1056 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1057 | gfx::Transform expected_grand_child_draw_transform = |
| 1058 | rotation_about_y_axis; // draws onto child's render surface |
| 1059 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1060 | flattened_rotation_about_y.FlattenTo2d(); |
| 1061 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1062 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1063 | gfx::Transform expected_great_grand_child_draw_transform = |
| 1064 | flattened_rotation_about_y; |
| 1065 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 1066 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1067 | |
| 1068 | ExecuteCalculateDrawProperties(root.get()); |
| 1069 | |
| 1070 | // The child's draw transform should have been taken by its surface. |
| 1071 | ASSERT_TRUE(child->render_surface()); |
| 1072 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1073 | child->render_surface()->draw_transform()); |
| 1074 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1075 | expected_child_screen_space_transform, |
| 1076 | child->render_surface()->screen_space_transform()); |
| 1077 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1078 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
| 1079 | child->screen_space_transform()); |
| 1080 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
| 1081 | grand_child->draw_transform()); |
| 1082 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
| 1083 | grand_child->screen_space_transform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1084 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
| 1085 | great_grand_child->draw_transform()); |
| 1086 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1087 | expected_great_grand_child_screen_space_transform, |
| 1088 | great_grand_child->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1089 | } |
| 1090 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1091 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1092 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1093 | // skipping a necessary translation. Without that translation, the coordinate |
| 1094 | // space of the layer's draw transform is incorrect. |
| 1095 | // |
| 1096 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1097 | // but if that layer becomes a render surface, then its draw transform is |
| 1098 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1099 | // incorrectly as a result. |
| 1100 | |
| 1101 | scoped_refptr<Layer> root = Layer::Create(); |
| 1102 | scoped_refptr<Layer> child = Layer::Create(); |
| 1103 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1104 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1105 | |
| 1106 | // The child height is zero, but has non-zero width that should be accounted |
| 1107 | // for while computing draw transforms. |
| 1108 | const gfx::Transform identity_matrix; |
| 1109 | SetLayerPropertiesForTesting(root.get(), |
| 1110 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1111 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1112 | gfx::PointF(), |
| 1113 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1114 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1115 | false); |
| 1116 | SetLayerPropertiesForTesting(child.get(), |
| 1117 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1118 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1119 | gfx::PointF(), |
| 1120 | gfx::Size(10, 0), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1121 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1122 | false); |
| 1123 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1124 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1125 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1126 | gfx::PointF(), |
| 1127 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1128 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1129 | false); |
| 1130 | |
| 1131 | root->AddChild(child); |
| 1132 | child->AddChild(grand_child); |
| 1133 | child->SetForceRenderSurface(true); |
| 1134 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1135 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1136 | host->SetRootLayer(root); |
| 1137 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1138 | ExecuteCalculateDrawProperties(root.get()); |
| 1139 | |
| 1140 | ASSERT_TRUE(child->render_surface()); |
| 1141 | // This is the real test, the rest are sanity checks. |
| 1142 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1143 | child->render_surface()->draw_transform()); |
| 1144 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1145 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1146 | grand_child->draw_transform()); |
| 1147 | } |
| 1148 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1149 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1150 | // Transformations applied at the root of the tree should be forwarded |
| 1151 | // to child layers instead of applied to the root RenderSurface. |
| 1152 | const gfx::Transform identity_matrix; |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1153 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 1154 | new LayerWithForcedDrawsContent; |
| 1155 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1156 | new LayerWithForcedDrawsContent; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1157 | child->SetScrollClipLayerId(root->id()); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1158 | root->AddChild(child); |
| 1159 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1160 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1161 | host->SetRootLayer(root); |
| 1162 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1163 | SetLayerPropertiesForTesting(root.get(), |
| 1164 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1165 | gfx::Point3F(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1166 | gfx::PointF(), |
| 1167 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1168 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1169 | false); |
| 1170 | SetLayerPropertiesForTesting(child.get(), |
| 1171 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1172 | gfx::Point3F(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1173 | gfx::PointF(), |
| 1174 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1175 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1176 | false); |
| 1177 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1178 | gfx::Transform translate; |
| 1179 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1180 | { |
| 1181 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1182 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1183 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1184 | inputs.can_adjust_raster_scales = true; |
| 1185 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1186 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1187 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1188 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1189 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1190 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1191 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1192 | |
| 1193 | gfx::Transform scale; |
| 1194 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1195 | { |
| 1196 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1197 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1198 | root.get(), root->bounds(), scale, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1199 | inputs.can_adjust_raster_scales = true; |
| 1200 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1201 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1202 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1203 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1204 | EXPECT_EQ(2.f, root->draw_properties().device_scale_factor); |
| 1205 | EXPECT_EQ(2.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1206 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1207 | |
| 1208 | gfx::Transform rotate; |
| 1209 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1210 | { |
| 1211 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1212 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1213 | root.get(), root->bounds(), rotate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1214 | inputs.can_adjust_raster_scales = true; |
| 1215 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1216 | EXPECT_EQ(rotate, root->draw_properties().target_space_transform); |
| 1217 | EXPECT_EQ(rotate, child->draw_properties().target_space_transform); |
| 1218 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1219 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1220 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1221 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1222 | |
| 1223 | gfx::Transform composite; |
| 1224 | composite.ConcatTransform(translate); |
| 1225 | composite.ConcatTransform(scale); |
| 1226 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1227 | { |
| 1228 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1229 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1230 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1231 | inputs.can_adjust_raster_scales = true; |
| 1232 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1233 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1234 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1235 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1236 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1237 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1238 | // Verify it composes correctly with device scale. |
| 1239 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1240 | |
| 1241 | { |
| 1242 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1243 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1244 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1245 | inputs.device_scale_factor = device_scale_factor; |
| 1246 | inputs.can_adjust_raster_scales = true; |
| 1247 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1248 | gfx::Transform device_scaled_translate = translate; |
| 1249 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1250 | EXPECT_EQ(device_scaled_translate, |
| 1251 | root->draw_properties().target_space_transform); |
| 1252 | EXPECT_EQ(device_scaled_translate, |
| 1253 | child->draw_properties().target_space_transform); |
| 1254 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1255 | EXPECT_EQ(device_scale_factor, root->draw_properties().device_scale_factor); |
| 1256 | EXPECT_EQ(device_scale_factor, |
| 1257 | child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1258 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1259 | |
| 1260 | // Verify it composes correctly with page scale. |
| 1261 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1262 | |
| 1263 | { |
| 1264 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1265 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1266 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1267 | inputs.page_scale_factor = page_scale_factor; |
| 1268 | inputs.page_scale_application_layer = root.get(); |
| 1269 | inputs.can_adjust_raster_scales = true; |
| 1270 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1271 | gfx::Transform page_scaled_translate = translate; |
| 1272 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
| 1273 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1274 | EXPECT_EQ(page_scaled_translate, |
| 1275 | child->draw_properties().target_space_transform); |
| 1276 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1277 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1278 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1279 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1280 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1281 | // Verify that it composes correctly with transforms directly on root layer. |
| 1282 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1283 | |
| 1284 | { |
| 1285 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1286 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1287 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1288 | inputs.can_adjust_raster_scales = true; |
| 1289 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1290 | gfx::Transform compositeSquared = composite; |
| 1291 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1292 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1293 | compositeSquared, root->draw_properties().target_space_transform); |
| 1294 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1295 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1296 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1297 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1298 | } |
| 1299 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1300 | TEST_F(LayerTreeHostCommonTest, |
| 1301 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1302 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1303 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1304 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1305 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1306 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1307 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1308 | host->SetRootLayer(parent); |
| 1309 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1310 | const gfx::Transform identity_matrix; |
| 1311 | SetLayerPropertiesForTesting(parent.get(), |
| 1312 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1313 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1314 | gfx::PointF(), |
| 1315 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1316 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1317 | false); |
| 1318 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1319 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1320 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1321 | gfx::PointF(), |
| 1322 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1323 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1324 | false); |
| 1325 | SetLayerPropertiesForTesting(child.get(), |
| 1326 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1327 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1328 | gfx::PointF(30.f, 30.f), |
| 1329 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1330 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1331 | false); |
| 1332 | |
| 1333 | parent->AddChild(render_surface1); |
| 1334 | parent->SetMasksToBounds(true); |
| 1335 | render_surface1->AddChild(child); |
| 1336 | render_surface1->SetForceRenderSurface(true); |
| 1337 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1338 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1339 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1340 | parent.get(), |
| 1341 | parent->bounds(), |
| 1342 | gfx::Transform(), |
| 1343 | &render_surface_layer_list); |
| 1344 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1345 | |
| 1346 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1347 | // the intermediate render surface should not be listed here, even if it was |
| 1348 | // forced to be created. Render surfaces without children or visible content |
| 1349 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1350 | // of size 0). |
| 1351 | ASSERT_TRUE(parent->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1352 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1353 | } |
| 1354 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1355 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1356 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1357 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1358 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1359 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1360 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1361 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1362 | host->SetRootLayer(parent); |
| 1363 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1364 | const gfx::Transform identity_matrix; |
| 1365 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1366 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1367 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1368 | gfx::PointF(), |
| 1369 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1370 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1371 | false); |
| 1372 | SetLayerPropertiesForTesting(child.get(), |
| 1373 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1374 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1375 | gfx::PointF(), |
| 1376 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1377 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1378 | false); |
| 1379 | |
| 1380 | parent->AddChild(render_surface1); |
| 1381 | render_surface1->AddChild(child); |
| 1382 | render_surface1->SetForceRenderSurface(true); |
| 1383 | render_surface1->SetOpacity(0.f); |
| 1384 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1385 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1386 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1387 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1388 | inputs.can_adjust_raster_scales = true; |
| 1389 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1390 | |
| 1391 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1392 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1393 | // have been extended by the children. |
| 1394 | ASSERT_TRUE(parent->render_surface()); |
| 1395 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1396 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1397 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1398 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1399 | } |
| 1400 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1401 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
| 1402 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1403 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1404 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1405 | |
| 1406 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 1407 | host->SetRootLayer(parent); |
| 1408 | |
| 1409 | const gfx::Transform identity_matrix; |
| 1410 | const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode; |
| 1411 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 1412 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1413 | |
| 1414 | parent->AddChild(child); |
| 1415 | child->SetBlendMode(blend_mode); |
| 1416 | |
| 1417 | RenderSurfaceLayerList render_surface_layer_list; |
| 1418 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1419 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1420 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 1421 | |
| 1422 | // Since the child layer has a blend mode other than normal, it should get |
| 1423 | // its own render surface. Also, layer's draw_properties should contain the |
| 1424 | // default blend mode, since the render surface becomes responsible for |
| 1425 | // applying the blend mode. |
| 1426 | ASSERT_TRUE(child->render_surface()); |
| 1427 | EXPECT_EQ(1U, child->render_surface()->layer_list().size()); |
| 1428 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_properties().blend_mode); |
| 1429 | } |
| 1430 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1431 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1432 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1433 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1434 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1435 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1436 | render_surface1->SetForceRenderSurface(true); |
| 1437 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1438 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1439 | host->SetRootLayer(parent); |
| 1440 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1441 | const gfx::Transform identity_matrix; |
| 1442 | SetLayerPropertiesForTesting(parent.get(), |
| 1443 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1444 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1445 | gfx::PointF(), |
| 1446 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1447 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1448 | false); |
| 1449 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1450 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1451 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1452 | gfx::PointF(), |
| 1453 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1454 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1455 | false); |
| 1456 | SetLayerPropertiesForTesting(child.get(), |
| 1457 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1458 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1459 | gfx::PointF(), |
| 1460 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1461 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1462 | false); |
| 1463 | |
| 1464 | parent->AddChild(render_surface1); |
| 1465 | render_surface1->AddChild(child); |
| 1466 | |
| 1467 | // Sanity check before the actual test |
| 1468 | EXPECT_FALSE(parent->render_surface()); |
| 1469 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1470 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1471 | { |
| 1472 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1473 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1474 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1475 | inputs.can_adjust_raster_scales = true; |
| 1476 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1477 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1478 | // The root layer always creates a render surface |
| 1479 | EXPECT_TRUE(parent->render_surface()); |
| 1480 | EXPECT_TRUE(render_surface1->render_surface()); |
| 1481 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1482 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1483 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1484 | { |
| 1485 | RenderSurfaceLayerList render_surface_layer_list; |
| 1486 | render_surface1->SetForceRenderSurface(false); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1487 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1488 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1489 | inputs.can_adjust_raster_scales = true; |
| 1490 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1491 | EXPECT_TRUE(parent->render_surface()); |
| 1492 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1493 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1494 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1495 | } |
| 1496 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1497 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1498 | // Render surfaces act as a flattening point for their subtree, so should |
| 1499 | // always flatten the target-to-screen space transform seen by descendants. |
| 1500 | |
| 1501 | scoped_refptr<Layer> root = Layer::Create(); |
| 1502 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1503 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1504 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1505 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1506 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1507 | |
| 1508 | gfx::Transform rotation_about_y_axis; |
| 1509 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1510 | // Make |parent| have a render surface. |
| 1511 | parent->SetOpacity(0.9f); |
| 1512 | |
| 1513 | const gfx::Transform identity_matrix; |
| 1514 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 1515 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 1516 | SetLayerPropertiesForTesting(parent.get(), rotation_about_y_axis, |
| 1517 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1518 | true, false); |
| 1519 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 1520 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1521 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 1522 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1523 | true, false); |
| 1524 | |
| 1525 | root->AddChild(parent); |
| 1526 | parent->AddChild(child); |
| 1527 | child->AddChild(grand_child); |
| 1528 | |
| 1529 | grand_child->SetShouldFlattenTransform(false); |
| 1530 | |
| 1531 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 1532 | host->SetRootLayer(root); |
| 1533 | |
| 1534 | // Only grand_child should preserve 3d. |
| 1535 | EXPECT_TRUE(root->should_flatten_transform()); |
| 1536 | EXPECT_TRUE(parent->should_flatten_transform()); |
| 1537 | EXPECT_TRUE(child->should_flatten_transform()); |
| 1538 | EXPECT_FALSE(grand_child->should_flatten_transform()); |
| 1539 | |
| 1540 | gfx::Transform expected_child_draw_transform = identity_matrix; |
| 1541 | gfx::Transform expected_grand_child_draw_transform = identity_matrix; |
| 1542 | |
| 1543 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1544 | flattened_rotation_about_y.FlattenTo2d(); |
| 1545 | |
| 1546 | ExecuteCalculateDrawProperties(root.get()); |
| 1547 | |
| 1548 | EXPECT_TRUE(parent->render_surface()); |
| 1549 | EXPECT_FALSE(child->render_surface()); |
| 1550 | EXPECT_FALSE(grand_child->render_surface()); |
| 1551 | |
| 1552 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1553 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1554 | grand_child->draw_transform()); |
| 1555 | |
| 1556 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1557 | // have been flattened at their render target. In particular, the fact that |
| 1558 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
| 1559 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
| 1560 | child->screen_space_transform()); |
| 1561 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
| 1562 | grand_child->screen_space_transform()); |
| 1563 | } |
| 1564 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1565 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1566 | // The entire subtree of layers that are outside the clip rect should be |
| 1567 | // culled away, and should not affect the render_surface_layer_list. |
| 1568 | // |
| 1569 | // The test tree is set up as follows: |
| 1570 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1571 | // that have something to draw. |
| 1572 | // - parent is a large container layer. |
| 1573 | // - child has masksToBounds=true to cause clipping. |
| 1574 | // - grand_child is positioned outside of the child's bounds |
| 1575 | // - great_grand_child is also kept outside child's bounds. |
| 1576 | // |
| 1577 | // In this configuration, grand_child and great_grand_child are completely |
| 1578 | // outside the clip rect, and they should never get scheduled on the list of |
| 1579 | // render surfaces. |
| 1580 | // |
| 1581 | |
| 1582 | const gfx::Transform identity_matrix; |
| 1583 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1584 | scoped_refptr<Layer> child = Layer::Create(); |
| 1585 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1586 | scoped_refptr<Layer> great_grand_child = Layer::Create(); |
| 1587 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1588 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1589 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1590 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1591 | parent->AddChild(child); |
| 1592 | child->AddChild(grand_child); |
| 1593 | grand_child->AddChild(great_grand_child); |
| 1594 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1595 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1596 | host->SetRootLayer(parent); |
| 1597 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1598 | // leaf_node1 ensures that parent and child are kept on the |
| 1599 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1600 | // should be clipped. |
| 1601 | child->AddChild(leaf_node1); |
| 1602 | great_grand_child->AddChild(leaf_node2); |
| 1603 | |
| 1604 | SetLayerPropertiesForTesting(parent.get(), |
| 1605 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1606 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1607 | gfx::PointF(), |
| 1608 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1609 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1610 | false); |
| 1611 | SetLayerPropertiesForTesting(child.get(), |
| 1612 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1613 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1614 | gfx::PointF(), |
| 1615 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1616 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1617 | false); |
| 1618 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1619 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1620 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1621 | gfx::PointF(45.f, 45.f), |
| 1622 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1623 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1624 | false); |
| 1625 | SetLayerPropertiesForTesting(great_grand_child.get(), |
| 1626 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1627 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1628 | gfx::PointF(), |
| 1629 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1630 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1631 | false); |
| 1632 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1633 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1634 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1635 | gfx::PointF(), |
| 1636 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1637 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1638 | false); |
| 1639 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1640 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1641 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1642 | gfx::PointF(), |
| 1643 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1644 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1645 | false); |
| 1646 | |
| 1647 | child->SetMasksToBounds(true); |
| 1648 | child->SetOpacity(0.4f); |
| 1649 | child->SetForceRenderSurface(true); |
| 1650 | grand_child->SetOpacity(0.5f); |
| 1651 | great_grand_child->SetOpacity(0.4f); |
| 1652 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1653 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1654 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1655 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1656 | inputs.can_adjust_raster_scales = true; |
| 1657 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1658 | |
| 1659 | ASSERT_EQ(2U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1660 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1661 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1662 | } |
| 1663 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1664 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1665 | // When a render surface has a clip rect, it is used to clip the content rect |
| 1666 | // of the surface. When the render surface is animating its transforms, then |
| 1667 | // the content rect's position in the clip rect is not defined on the main |
| 1668 | // thread, and its content rect should not be clipped. |
| 1669 | |
| 1670 | // The test tree is set up as follows: |
| 1671 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1672 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1673 | // the parent. |
| 1674 | // - grand_child is a render surface, and the only visible content in child. |
| 1675 | // It is positioned outside of the clip rect from parent. |
| 1676 | |
| 1677 | // In this configuration, grand_child should be outside the clipped |
| 1678 | // content rect of the child, making grand_child not appear in the |
| 1679 | // render_surface_layer_list. However, when we place an animation on the |
| 1680 | // child, this clipping should be avoided and we should keep the grand_child |
| 1681 | // in the render_surface_layer_list. |
| 1682 | |
| 1683 | const gfx::Transform identity_matrix; |
| 1684 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1685 | scoped_refptr<Layer> child = Layer::Create(); |
| 1686 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1687 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node = |
| 1688 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1689 | parent->AddChild(child); |
| 1690 | child->AddChild(grand_child); |
| 1691 | grand_child->AddChild(leaf_node); |
| 1692 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1693 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1694 | host->SetRootLayer(parent); |
| 1695 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1696 | SetLayerPropertiesForTesting(parent.get(), |
| 1697 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1698 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1699 | gfx::PointF(), |
| 1700 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1701 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1702 | false); |
| 1703 | SetLayerPropertiesForTesting(child.get(), |
| 1704 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1705 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1706 | gfx::PointF(), |
| 1707 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1708 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1709 | false); |
| 1710 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1711 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1712 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1713 | gfx::PointF(200.f, 200.f), |
| 1714 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1715 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1716 | false); |
| 1717 | SetLayerPropertiesForTesting(leaf_node.get(), |
| 1718 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1719 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1720 | gfx::PointF(), |
| 1721 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1722 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1723 | false); |
| 1724 | |
| 1725 | parent->SetMasksToBounds(true); |
| 1726 | child->SetOpacity(0.4f); |
| 1727 | child->SetForceRenderSurface(true); |
| 1728 | grand_child->SetOpacity(0.4f); |
| 1729 | grand_child->SetForceRenderSurface(true); |
| 1730 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1731 | { |
| 1732 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1733 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1734 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1735 | inputs.can_adjust_raster_scales = true; |
| 1736 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1737 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1738 | // Without an animation, we should cull child and grand_child from the |
| 1739 | // render_surface_layer_list. |
| 1740 | ASSERT_EQ(1U, render_surface_layer_list.size()); |
| 1741 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1742 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1743 | |
| 1744 | // Now put an animating transform on child. |
| 1745 | AddAnimatedTransformToController( |
| 1746 | child->layer_animation_controller(), 10.0, 30, 0); |
| 1747 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1748 | { |
| 1749 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1750 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1751 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1752 | inputs.can_adjust_raster_scales = true; |
| 1753 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1754 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1755 | // With an animating transform, we should keep child and grand_child in the |
| 1756 | // render_surface_layer_list. |
| 1757 | ASSERT_EQ(3U, render_surface_layer_list.size()); |
| 1758 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1759 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
| 1760 | EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id()); |
| 1761 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1762 | } |
| 1763 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1764 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1765 | // Layer's IsClipped() property is set to true when: |
| 1766 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1767 | // - the layer is clipped by an ancestor that contributes to the same |
| 1768 | // render target, |
| 1769 | // - a surface is clipped by an ancestor that contributes to the same |
| 1770 | // render target. |
| 1771 | // |
| 1772 | // In particular, for a layer that owns a render surface: |
| 1773 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1774 | // pass that clipped status to the layer itself. |
| 1775 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1776 | // and propagates the clip to the subtree. |
| 1777 | |
| 1778 | const gfx::Transform identity_matrix; |
| 1779 | scoped_refptr<Layer> root = Layer::Create(); |
| 1780 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1781 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 1782 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 1783 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1784 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1785 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1786 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1787 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1788 | root->AddChild(parent); |
| 1789 | parent->AddChild(child1); |
| 1790 | parent->AddChild(child2); |
| 1791 | child1->AddChild(grand_child); |
| 1792 | child2->AddChild(leaf_node2); |
| 1793 | grand_child->AddChild(leaf_node1); |
| 1794 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1795 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1796 | host->SetRootLayer(root); |
| 1797 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1798 | child2->SetForceRenderSurface(true); |
| 1799 | |
| 1800 | SetLayerPropertiesForTesting(root.get(), |
| 1801 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1802 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1803 | gfx::PointF(), |
| 1804 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1805 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1806 | false); |
| 1807 | SetLayerPropertiesForTesting(parent.get(), |
| 1808 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1809 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1810 | gfx::PointF(), |
| 1811 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1812 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1813 | false); |
| 1814 | SetLayerPropertiesForTesting(child1.get(), |
| 1815 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1816 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1817 | gfx::PointF(), |
| 1818 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1819 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1820 | false); |
| 1821 | SetLayerPropertiesForTesting(child2.get(), |
| 1822 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1823 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1824 | gfx::PointF(), |
| 1825 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1826 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1827 | false); |
| 1828 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1829 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1830 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1831 | gfx::PointF(), |
| 1832 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1833 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1834 | false); |
| 1835 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1836 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1837 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1838 | gfx::PointF(), |
| 1839 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1840 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1841 | false); |
| 1842 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1843 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1844 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1845 | gfx::PointF(), |
| 1846 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1847 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1848 | false); |
| 1849 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1850 | // Case 1: nothing is clipped except the root render surface. |
| 1851 | { |
| 1852 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1853 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1854 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1855 | inputs.can_adjust_raster_scales = true; |
| 1856 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1857 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1858 | ASSERT_TRUE(root->render_surface()); |
| 1859 | ASSERT_TRUE(child2->render_surface()); |
| 1860 | |
| 1861 | EXPECT_FALSE(root->is_clipped()); |
| 1862 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1863 | EXPECT_FALSE(parent->is_clipped()); |
| 1864 | EXPECT_FALSE(child1->is_clipped()); |
| 1865 | EXPECT_FALSE(child2->is_clipped()); |
| 1866 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1867 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1868 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1869 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1870 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1871 | |
| 1872 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1873 | // surface are clipped. But layers that contribute to child2's surface are |
| 1874 | // not clipped explicitly because child2's surface already accounts for |
| 1875 | // that clip. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1876 | { |
| 1877 | RenderSurfaceLayerList render_surface_layer_list; |
| 1878 | parent->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1879 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1880 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1881 | inputs.can_adjust_raster_scales = true; |
| 1882 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1883 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1884 | ASSERT_TRUE(root->render_surface()); |
| 1885 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1886 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1887 | EXPECT_FALSE(root->is_clipped()); |
| 1888 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1889 | EXPECT_TRUE(parent->is_clipped()); |
| 1890 | EXPECT_TRUE(child1->is_clipped()); |
| 1891 | EXPECT_FALSE(child2->is_clipped()); |
| 1892 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1893 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1894 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1895 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1896 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1897 | |
| 1898 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1899 | // child2's render surface is not clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1900 | { |
| 1901 | RenderSurfaceLayerList render_surface_layer_list; |
| 1902 | parent->SetMasksToBounds(false); |
| 1903 | child2->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1904 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1905 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1906 | inputs.can_adjust_raster_scales = true; |
| 1907 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1908 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1909 | ASSERT_TRUE(root->render_surface()); |
| 1910 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1911 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1912 | EXPECT_FALSE(root->is_clipped()); |
| 1913 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1914 | EXPECT_FALSE(parent->is_clipped()); |
| 1915 | EXPECT_FALSE(child1->is_clipped()); |
| 1916 | EXPECT_TRUE(child2->is_clipped()); |
| 1917 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1918 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1919 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1920 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1921 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1922 | } |
| 1923 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 1924 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1925 | // Verify that layers get the appropriate DrawableContentRect when their |
| 1926 | // parent masksToBounds is true. |
| 1927 | // |
| 1928 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 1929 | // be the layer rect expressed in target space. |
| 1930 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 1931 | // will be the intersection of layer bounds and the mask region. |
| 1932 | // grand_child3 - partially clipped and masksToBounds; the |
| 1933 | // DrawableContentRect will still be the intersection of layer bounds and |
| 1934 | // the mask region. |
| 1935 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 1936 | // be empty. |
| 1937 | // |
| 1938 | |
| 1939 | const gfx::Transform identity_matrix; |
| 1940 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1941 | scoped_refptr<Layer> child = Layer::Create(); |
| 1942 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 1943 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 1944 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 1945 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 1946 | |
| 1947 | parent->AddChild(child); |
| 1948 | child->AddChild(grand_child1); |
| 1949 | child->AddChild(grand_child2); |
| 1950 | child->AddChild(grand_child3); |
| 1951 | child->AddChild(grand_child4); |
| 1952 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1953 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1954 | host->SetRootLayer(parent); |
| 1955 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1956 | SetLayerPropertiesForTesting(parent.get(), |
| 1957 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1958 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1959 | gfx::PointF(), |
| 1960 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1961 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1962 | false); |
| 1963 | SetLayerPropertiesForTesting(child.get(), |
| 1964 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1965 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1966 | gfx::PointF(), |
| 1967 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1968 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1969 | false); |
| 1970 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 1971 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1972 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1973 | gfx::PointF(5.f, 5.f), |
| 1974 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1975 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1976 | false); |
| 1977 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 1978 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1979 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1980 | gfx::PointF(15.f, 15.f), |
| 1981 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1982 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1983 | false); |
| 1984 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 1985 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1986 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1987 | gfx::PointF(15.f, 15.f), |
| 1988 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1989 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1990 | false); |
| 1991 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 1992 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1993 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1994 | gfx::PointF(45.f, 45.f), |
| 1995 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1996 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1997 | false); |
| 1998 | |
| 1999 | child->SetMasksToBounds(true); |
| 2000 | grand_child3->SetMasksToBounds(true); |
| 2001 | |
| 2002 | // Force everyone to be a render surface. |
| 2003 | child->SetOpacity(0.4f); |
| 2004 | grand_child1->SetOpacity(0.5f); |
| 2005 | grand_child2->SetOpacity(0.5f); |
| 2006 | grand_child3->SetOpacity(0.5f); |
| 2007 | grand_child4->SetOpacity(0.5f); |
| 2008 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2009 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2010 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2011 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2012 | inputs.can_adjust_raster_scales = true; |
| 2013 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2014 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2015 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 2016 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 2017 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2018 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2019 | } |
| 2020 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2021 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2022 | // Verify that render surfaces (and their layers) get the appropriate |
| 2023 | // clip rects when their parent masksToBounds is true. |
| 2024 | // |
| 2025 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2026 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2027 | // They may still have a clip rect of their own layer bounds, however, if |
| 2028 | // masksToBounds was true. |
| 2029 | const gfx::Transform identity_matrix; |
| 2030 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2031 | scoped_refptr<Layer> child = Layer::Create(); |
| 2032 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 2033 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 2034 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 2035 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 2036 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 2037 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2038 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 2039 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2040 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 = |
| 2041 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2042 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 = |
| 2043 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2044 | |
| 2045 | parent->AddChild(child); |
| 2046 | child->AddChild(grand_child1); |
| 2047 | child->AddChild(grand_child2); |
| 2048 | child->AddChild(grand_child3); |
| 2049 | child->AddChild(grand_child4); |
| 2050 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2051 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2052 | host->SetRootLayer(parent); |
| 2053 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2054 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 2055 | // this test. |
| 2056 | grand_child1->AddChild(leaf_node1); |
| 2057 | grand_child2->AddChild(leaf_node2); |
| 2058 | grand_child3->AddChild(leaf_node3); |
| 2059 | grand_child4->AddChild(leaf_node4); |
| 2060 | |
| 2061 | SetLayerPropertiesForTesting(parent.get(), |
| 2062 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2063 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2064 | gfx::PointF(), |
| 2065 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2066 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2067 | false); |
| 2068 | SetLayerPropertiesForTesting(child.get(), |
| 2069 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2070 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2071 | gfx::PointF(), |
| 2072 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2073 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2074 | false); |
| 2075 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2076 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2077 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2078 | gfx::PointF(5.f, 5.f), |
| 2079 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2080 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2081 | false); |
| 2082 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2083 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2084 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2085 | gfx::PointF(15.f, 15.f), |
| 2086 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2087 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2088 | false); |
| 2089 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2090 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2091 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2092 | gfx::PointF(15.f, 15.f), |
| 2093 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2094 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2095 | false); |
| 2096 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2097 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2098 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2099 | gfx::PointF(45.f, 45.f), |
| 2100 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2101 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2102 | false); |
| 2103 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 2104 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2105 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2106 | gfx::PointF(), |
| 2107 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2108 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2109 | false); |
| 2110 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 2111 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2112 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2113 | gfx::PointF(), |
| 2114 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2115 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2116 | false); |
| 2117 | SetLayerPropertiesForTesting(leaf_node3.get(), |
| 2118 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2119 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2120 | gfx::PointF(), |
| 2121 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2122 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2123 | false); |
| 2124 | SetLayerPropertiesForTesting(leaf_node4.get(), |
| 2125 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2126 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2127 | gfx::PointF(), |
| 2128 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2129 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2130 | false); |
| 2131 | |
| 2132 | child->SetMasksToBounds(true); |
| 2133 | grand_child3->SetMasksToBounds(true); |
| 2134 | grand_child4->SetMasksToBounds(true); |
| 2135 | |
| 2136 | // Force everyone to be a render surface. |
| 2137 | child->SetOpacity(0.4f); |
| 2138 | child->SetForceRenderSurface(true); |
| 2139 | grand_child1->SetOpacity(0.5f); |
| 2140 | grand_child1->SetForceRenderSurface(true); |
| 2141 | grand_child2->SetOpacity(0.5f); |
| 2142 | grand_child2->SetForceRenderSurface(true); |
| 2143 | grand_child3->SetOpacity(0.5f); |
| 2144 | grand_child3->SetForceRenderSurface(true); |
| 2145 | grand_child4->SetOpacity(0.5f); |
| 2146 | grand_child4->SetForceRenderSurface(true); |
| 2147 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2148 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2149 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2150 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2151 | inputs.can_adjust_raster_scales = true; |
| 2152 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2153 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2154 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2155 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2156 | |
| 2157 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2158 | // masksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2159 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2160 | grand_child1->render_surface()->clip_rect()); |
| 2161 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2162 | grand_child2->render_surface()->clip_rect()); |
| 2163 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2164 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2165 | } |
| 2166 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2167 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2168 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2169 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2170 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 2171 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 2172 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 2173 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 2174 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 2175 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 2176 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2177 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 2178 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2179 | parent->AddChild(render_surface1); |
| 2180 | parent->AddChild(child_of_root); |
| 2181 | render_surface1->AddChild(child_of_rs1); |
| 2182 | render_surface1->AddChild(render_surface2); |
| 2183 | render_surface2->AddChild(child_of_rs2); |
| 2184 | child_of_root->AddChild(grand_child_of_root); |
| 2185 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 2186 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 2187 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2188 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2189 | host->SetRootLayer(parent); |
| 2190 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2191 | // Make our render surfaces. |
| 2192 | render_surface1->SetForceRenderSurface(true); |
| 2193 | render_surface2->SetForceRenderSurface(true); |
| 2194 | |
| 2195 | gfx::Transform layer_transform; |
| 2196 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2197 | |
| 2198 | SetLayerPropertiesForTesting(parent.get(), |
| 2199 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2200 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2201 | gfx::PointF(2.5f, 0.f), |
| 2202 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2203 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2204 | false); |
| 2205 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2206 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2207 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2208 | gfx::PointF(2.5f, 0.f), |
| 2209 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2210 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2211 | false); |
| 2212 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 2213 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2214 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2215 | gfx::PointF(2.5f, 0.f), |
| 2216 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2217 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2218 | false); |
| 2219 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 2220 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2221 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2222 | gfx::PointF(2.5f, 0.f), |
| 2223 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2224 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2225 | false); |
| 2226 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 2227 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2228 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2229 | gfx::PointF(2.5f, 0.f), |
| 2230 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2231 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2232 | false); |
| 2233 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 2234 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2235 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2236 | gfx::PointF(2.5f, 0.f), |
| 2237 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2238 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2239 | false); |
| 2240 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 2241 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2242 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2243 | gfx::PointF(2.5f, 0.f), |
| 2244 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2245 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2246 | false); |
| 2247 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 2248 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2249 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2250 | gfx::PointF(2.5f, 0.f), |
| 2251 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2252 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2253 | false); |
| 2254 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 2255 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2256 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2257 | gfx::PointF(2.5f, 0.f), |
| 2258 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2259 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2260 | false); |
| 2261 | |
| 2262 | // Put an animated opacity on the render surface. |
| 2263 | AddOpacityTransitionToController( |
| 2264 | render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2265 | |
| 2266 | // Also put an animated opacity on a layer without descendants. |
| 2267 | AddOpacityTransitionToController( |
| 2268 | grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2269 | |
| 2270 | // Put a transform animation on the render surface. |
| 2271 | AddAnimatedTransformToController( |
| 2272 | render_surface2->layer_animation_controller(), 10.0, 30, 0); |
| 2273 | |
| 2274 | // Also put transform animations on grand_child_of_root, and |
| 2275 | // grand_child_of_rs2 |
| 2276 | AddAnimatedTransformToController( |
| 2277 | grand_child_of_root->layer_animation_controller(), 10.0, 30, 0); |
| 2278 | AddAnimatedTransformToController( |
| 2279 | grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0); |
| 2280 | |
| 2281 | ExecuteCalculateDrawProperties(parent.get()); |
| 2282 | |
| 2283 | // Only layers that are associated with render surfaces should have an actual |
| 2284 | // RenderSurface() value. |
| 2285 | ASSERT_TRUE(parent->render_surface()); |
| 2286 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2287 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2288 | |
| 2289 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2290 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2291 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2292 | |
| 2293 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2294 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2295 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2296 | |
| 2297 | // Verify all render target accessors |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2298 | EXPECT_EQ(parent.get(), parent->render_target()); |
| 2299 | EXPECT_EQ(parent.get(), child_of_root->render_target()); |
| 2300 | EXPECT_EQ(parent.get(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2301 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2302 | EXPECT_EQ(render_surface1.get(), render_surface1->render_target()); |
| 2303 | EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target()); |
| 2304 | EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2305 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2306 | EXPECT_EQ(render_surface2.get(), render_surface2->render_target()); |
| 2307 | EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target()); |
| 2308 | EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2309 | |
| 2310 | // Verify draw_opacity_is_animating values |
| 2311 | EXPECT_FALSE(parent->draw_opacity_is_animating()); |
| 2312 | EXPECT_FALSE(child_of_root->draw_opacity_is_animating()); |
| 2313 | EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating()); |
| 2314 | EXPECT_FALSE(render_surface1->draw_opacity_is_animating()); |
| 2315 | EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating()); |
| 2316 | EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating()); |
| 2317 | EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating()); |
| 2318 | EXPECT_FALSE(render_surface2->draw_opacity_is_animating()); |
| 2319 | EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating()); |
| 2320 | EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating()); |
| 2321 | EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating()); |
| 2322 | |
| 2323 | // Verify draw_transform_is_animating values |
| 2324 | EXPECT_FALSE(parent->draw_transform_is_animating()); |
| 2325 | EXPECT_FALSE(child_of_root->draw_transform_is_animating()); |
| 2326 | EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating()); |
| 2327 | EXPECT_FALSE(render_surface1->draw_transform_is_animating()); |
| 2328 | EXPECT_FALSE(render_surface1->render_surface() |
| 2329 | ->target_surface_transforms_are_animating()); |
| 2330 | EXPECT_FALSE(child_of_rs1->draw_transform_is_animating()); |
| 2331 | EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating()); |
| 2332 | EXPECT_FALSE(render_surface2->draw_transform_is_animating()); |
| 2333 | EXPECT_TRUE(render_surface2->render_surface() |
| 2334 | ->target_surface_transforms_are_animating()); |
| 2335 | EXPECT_FALSE(child_of_rs2->draw_transform_is_animating()); |
| 2336 | EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating()); |
| 2337 | |
| 2338 | // Verify screen_space_transform_is_animating values |
| 2339 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2340 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2341 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2342 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
| 2343 | EXPECT_FALSE(render_surface1->render_surface() |
| 2344 | ->screen_space_transforms_are_animating()); |
| 2345 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2346 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2347 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
| 2348 | EXPECT_TRUE(render_surface2->render_surface() |
| 2349 | ->screen_space_transforms_are_animating()); |
| 2350 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2351 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2352 | |
| 2353 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2354 | // It is expected that we correctly set up transforms so that the y-component |
| 2355 | // 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] | 2356 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 2357 | EXPECT_FLOAT_EQ(2.0, |
| 2358 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2359 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2360 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2361 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2362 | EXPECT_FLOAT_EQ(2.0, |
| 2363 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 2364 | EXPECT_FLOAT_EQ(3.0, |
| 2365 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2366 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2367 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2368 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2369 | EXPECT_FLOAT_EQ(3.0, |
| 2370 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 2371 | EXPECT_FLOAT_EQ(4.0, |
| 2372 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2373 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2374 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2375 | } |
| 2376 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2377 | TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2378 | // Test the calculateVisibleRect() function works correctly for identity |
| 2379 | // transforms. |
| 2380 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2381 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2382 | gfx::Transform layer_to_surface_transform; |
| 2383 | |
| 2384 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2385 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2386 | gfx::Rect expected = gfx::Rect(10, 10, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2387 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2388 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2389 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2390 | |
| 2391 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2392 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2393 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2394 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2395 | EXPECT_TRUE(actual.IsEmpty()); |
| 2396 | |
| 2397 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2398 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
| 2399 | expected = gfx::Rect(80, 80, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2400 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2401 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2402 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2403 | } |
| 2404 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2405 | TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2406 | // Test the calculateVisibleRect() function works correctly for scaling |
| 2407 | // transforms. |
| 2408 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2409 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2410 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2411 | gfx::Transform layer_to_surface_transform; |
| 2412 | |
| 2413 | // Case 1: Layer is contained within the surface. |
| 2414 | layer_to_surface_transform.MakeIdentity(); |
| 2415 | layer_to_surface_transform.Translate(10.0, 10.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2416 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2417 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2418 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2419 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2420 | |
| 2421 | // Case 2: Layer is outside the surface rect. |
| 2422 | layer_to_surface_transform.MakeIdentity(); |
| 2423 | layer_to_surface_transform.Translate(120.0, 120.0); |
| 2424 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2425 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2426 | EXPECT_TRUE(actual.IsEmpty()); |
| 2427 | |
| 2428 | // Case 3: Layer is partially overlapping the surface rect. |
| 2429 | layer_to_surface_transform.MakeIdentity(); |
| 2430 | layer_to_surface_transform.Translate(80.0, 80.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2431 | expected = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2432 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2433 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2434 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2435 | } |
| 2436 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2437 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2438 | // Test the calculateVisibleRect() function works correctly for rotations |
| 2439 | // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() |
| 2440 | // should return the g in the layer's space. |
| 2441 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2442 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2443 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2444 | gfx::Transform layer_to_surface_transform; |
| 2445 | |
| 2446 | // Case 1: Layer is contained within the surface. |
| 2447 | layer_to_surface_transform.MakeIdentity(); |
| 2448 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2449 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2450 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2451 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2452 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2453 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2454 | |
| 2455 | // Case 2: Layer is outside the surface rect. |
| 2456 | layer_to_surface_transform.MakeIdentity(); |
| 2457 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2458 | layer_to_surface_transform.Rotate(45.0); |
| 2459 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2460 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2461 | EXPECT_TRUE(actual.IsEmpty()); |
| 2462 | |
| 2463 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2464 | // the layer is oriented diagonally, with the left half outside of the render |
| 2465 | // surface. In this case, the g should still be the entire layer |
| 2466 | // (remember the g is computed in layer space); both the top-left |
| 2467 | // and bottom-right corners of the layer are still visible. |
| 2468 | layer_to_surface_transform.MakeIdentity(); |
| 2469 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2470 | expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2471 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2472 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2473 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2474 | |
| 2475 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2476 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2477 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2478 | // surface overlaps the right side of the layer. The g should be |
| 2479 | // the layer's right half. |
| 2480 | layer_to_surface_transform.MakeIdentity(); |
| 2481 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2482 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2483 | expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2484 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2485 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2486 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2487 | } |
| 2488 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2489 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2490 | // Test that the calculateVisibleRect() function works correctly for 3d |
| 2491 | // transforms. |
| 2492 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2493 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2494 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2495 | gfx::Transform layer_to_surface_transform; |
| 2496 | |
| 2497 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2498 | // degrees, should be fully contained in the render surface. |
| 2499 | layer_to_surface_transform.MakeIdentity(); |
| 2500 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2501 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2502 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2503 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2504 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2505 | |
| 2506 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2507 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2508 | // visible on the surface. |
| 2509 | // 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] | 2510 | SkMScalar half_width_of_rotated_layer = |
| 2511 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2512 | layer_to_surface_transform.MakeIdentity(); |
| 2513 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2514 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2515 | // edge of the layer. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2516 | expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2517 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2518 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2519 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2520 | } |
| 2521 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2522 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2523 | // Test the calculateVisibleRect() function works correctly when the layer has |
| 2524 | // a perspective projection onto the target surface. |
| 2525 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2526 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2527 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2528 | gfx::Transform layer_to_surface_transform; |
| 2529 | |
| 2530 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2531 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2532 | // its translated more than the perspective amount. |
| 2533 | layer_to_surface_transform.MakeIdentity(); |
| 2534 | |
| 2535 | // The following sequence of transforms applies the perspective about the |
| 2536 | // center of the surface. |
| 2537 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2538 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2539 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2540 | |
| 2541 | // This translate places the layer in front of the surface's projection plane. |
| 2542 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2543 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2544 | gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2545 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2546 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2547 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2548 | |
| 2549 | // Case 2: same projection as before, except that the layer is also translated |
| 2550 | // to the side, so that only the right half of the layer should be visible. |
| 2551 | // |
| 2552 | // Explanation of expected result: The perspective ratio is (z distance |
| 2553 | // between layer and camera origin) / (z distance between projection plane and |
| 2554 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
| 2555 | // move a layer by translating -50 units in projected surface units (so that |
| 2556 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
| 2557 | // -50 == -200 in the layer's units. |
| 2558 | layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2559 | expected = gfx::Rect(gfx::Point(50, -50), |
| 2560 | gfx::Size(100, 200)); // The right half of the layer's |
| 2561 | // bounding rect. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2562 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2563 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2564 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2565 | } |
| 2566 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2567 | TEST_F(LayerTreeHostCommonTest, |
| 2568 | VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2569 | // There is currently no explicit concept of an orthographic projection plane |
| 2570 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2571 | // are technically behind the surface in an orthographic world should not be |
| 2572 | // clipped when they are flattened to the surface. |
| 2573 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2574 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2575 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2576 | gfx::Transform layer_to_surface_transform; |
| 2577 | |
| 2578 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2579 | // at the center of the layer. |
| 2580 | layer_to_surface_transform.MakeIdentity(); |
| 2581 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2582 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2583 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2584 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2585 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2586 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2587 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2588 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2589 | } |
| 2590 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2591 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2592 | // Test the calculateVisibleRect() function works correctly when projecting a |
| 2593 | // surface onto a layer, but the layer is partially behind the camera (not |
| 2594 | // just behind the projection plane). In this case, the cartesian coordinates |
| 2595 | // may seem to be valid, but actually they are not. The visible rect needs to |
| 2596 | // be properly clipped by the w = 0 plane in homogeneous coordinates before |
| 2597 | // converting to cartesian coordinates. |
| 2598 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2599 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2600 | gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2601 | gfx::Transform layer_to_surface_transform; |
| 2602 | |
| 2603 | // The layer is positioned so that the right half of the layer should be in |
| 2604 | // front of the camera, while the other half is behind the surface's |
| 2605 | // projection plane. The following sequence of transforms applies the |
| 2606 | // perspective and rotation about the center of the layer. |
| 2607 | layer_to_surface_transform.MakeIdentity(); |
| 2608 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2609 | layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); |
| 2610 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2611 | |
| 2612 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2613 | // transform, otherwise this code is not testing the intended scenario. |
| 2614 | bool clipped; |
| 2615 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2616 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2617 | &clipped); |
| 2618 | ASSERT_TRUE(clipped); |
| 2619 | |
| 2620 | int expected_x_position = 0; |
| 2621 | int expected_width = 10; |
| 2622 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2623 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2624 | EXPECT_EQ(expected_x_position, actual.x()); |
| 2625 | EXPECT_EQ(expected_width, actual.width()); |
| 2626 | } |
| 2627 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2628 | TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2629 | // To determine visible rect in layer space, there needs to be an |
| 2630 | // un-projection from surface space to layer space. When the original |
| 2631 | // transform was a perspective projection that was clipped, it returns a rect |
| 2632 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2633 | // clipping again. |
| 2634 | |
| 2635 | // This sequence of transforms causes one corner of the layer to protrude |
| 2636 | // across the w = 0 plane, and should be clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2637 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
| 2638 | gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2639 | gfx::Transform layer_to_surface_transform; |
| 2640 | layer_to_surface_transform.MakeIdentity(); |
| 2641 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2642 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2643 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2644 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2645 | |
| 2646 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2647 | // code is not testing the intended scenario. |
| 2648 | bool clipped; |
| 2649 | gfx::RectF clipped_rect = |
| 2650 | MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); |
| 2651 | MathUtil::ProjectQuad( |
| 2652 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2653 | ASSERT_TRUE(clipped); |
| 2654 | |
| 2655 | // Only the corner of the layer is not visible on the surface because of being |
| 2656 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2657 | // rect is that the entire layer should still be considered visible. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2658 | gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2659 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2660 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2661 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2662 | } |
| 2663 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2664 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2665 | scoped_refptr<Layer> root = Layer::Create(); |
| 2666 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2667 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2668 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2669 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2670 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2671 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2672 | root->AddChild(child1); |
| 2673 | root->AddChild(child2); |
| 2674 | root->AddChild(child3); |
| 2675 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2676 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2677 | host->SetRootLayer(root); |
| 2678 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2679 | gfx::Transform identity_matrix; |
| 2680 | SetLayerPropertiesForTesting(root.get(), |
| 2681 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2682 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2683 | gfx::PointF(), |
| 2684 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2685 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2686 | false); |
| 2687 | SetLayerPropertiesForTesting(child1.get(), |
| 2688 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2689 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2690 | gfx::PointF(), |
| 2691 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2692 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2693 | false); |
| 2694 | SetLayerPropertiesForTesting(child2.get(), |
| 2695 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2696 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2697 | gfx::PointF(75.f, 75.f), |
| 2698 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2699 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2700 | false); |
| 2701 | SetLayerPropertiesForTesting(child3.get(), |
| 2702 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2703 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2704 | gfx::PointF(125.f, 125.f), |
| 2705 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2706 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2707 | false); |
| 2708 | |
| 2709 | ExecuteCalculateDrawProperties(root.get()); |
| 2710 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2711 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2712 | root->render_surface()->DrawableContentRect()); |
| 2713 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2714 | |
| 2715 | // Layers that do not draw content should have empty visible_content_rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2716 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2717 | |
| 2718 | // layer visible_content_rects are clipped by their target surface. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2719 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2720 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2721 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 2722 | |
| 2723 | // layer drawable_content_rects are not clipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2724 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect()); |
| 2725 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2726 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2727 | } |
| 2728 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2729 | TEST_F(LayerTreeHostCommonTest, |
| 2730 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2731 | scoped_refptr<Layer> root = Layer::Create(); |
| 2732 | scoped_refptr<Layer> child = Layer::Create(); |
| 2733 | scoped_refptr<LayerWithForcedDrawsContent> grand_child1 = |
| 2734 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2735 | scoped_refptr<LayerWithForcedDrawsContent> grand_child2 = |
| 2736 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2737 | scoped_refptr<LayerWithForcedDrawsContent> grand_child3 = |
| 2738 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2739 | root->AddChild(child); |
| 2740 | child->AddChild(grand_child1); |
| 2741 | child->AddChild(grand_child2); |
| 2742 | child->AddChild(grand_child3); |
| 2743 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2744 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2745 | host->SetRootLayer(root); |
| 2746 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2747 | gfx::Transform identity_matrix; |
| 2748 | SetLayerPropertiesForTesting(root.get(), |
| 2749 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2750 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2751 | gfx::PointF(), |
| 2752 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2753 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2754 | false); |
| 2755 | SetLayerPropertiesForTesting(child.get(), |
| 2756 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2757 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2758 | gfx::PointF(), |
| 2759 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2760 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2761 | false); |
| 2762 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2763 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2764 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2765 | gfx::PointF(5.f, 5.f), |
| 2766 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2767 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2768 | false); |
| 2769 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2770 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2771 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2772 | gfx::PointF(75.f, 75.f), |
| 2773 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2774 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2775 | false); |
| 2776 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2777 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2778 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2779 | gfx::PointF(125.f, 125.f), |
| 2780 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2781 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2782 | false); |
| 2783 | |
| 2784 | child->SetMasksToBounds(true); |
| 2785 | ExecuteCalculateDrawProperties(root.get()); |
| 2786 | |
| 2787 | ASSERT_FALSE(child->render_surface()); |
| 2788 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2789 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2790 | root->render_surface()->DrawableContentRect()); |
| 2791 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2792 | |
| 2793 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2794 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2795 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2796 | |
| 2797 | // All grandchild visible content rects should be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2798 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect()); |
| 2799 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2800 | EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty()); |
| 2801 | |
| 2802 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2803 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 2804 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2805 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 2806 | } |
| 2807 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2808 | TEST_F(LayerTreeHostCommonTest, |
| 2809 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2810 | scoped_refptr<Layer> root = Layer::Create(); |
| 2811 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2812 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2813 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2814 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2815 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2816 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2817 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2818 | root->AddChild(render_surface1); |
| 2819 | render_surface1->AddChild(child1); |
| 2820 | render_surface1->AddChild(child2); |
| 2821 | render_surface1->AddChild(child3); |
| 2822 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2823 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2824 | host->SetRootLayer(root); |
| 2825 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2826 | gfx::Transform identity_matrix; |
| 2827 | SetLayerPropertiesForTesting(root.get(), |
| 2828 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2829 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2830 | gfx::PointF(), |
| 2831 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2832 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2833 | false); |
| 2834 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2835 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2836 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2837 | gfx::PointF(), |
| 2838 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2839 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2840 | false); |
| 2841 | SetLayerPropertiesForTesting(child1.get(), |
| 2842 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2843 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2844 | gfx::PointF(5.f, 5.f), |
| 2845 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2846 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2847 | false); |
| 2848 | SetLayerPropertiesForTesting(child2.get(), |
| 2849 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2850 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2851 | gfx::PointF(75.f, 75.f), |
| 2852 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2853 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2854 | false); |
| 2855 | SetLayerPropertiesForTesting(child3.get(), |
| 2856 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2857 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2858 | gfx::PointF(125.f, 125.f), |
| 2859 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2860 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2861 | false); |
| 2862 | |
| 2863 | render_surface1->SetForceRenderSurface(true); |
| 2864 | ExecuteCalculateDrawProperties(root.get()); |
| 2865 | |
| 2866 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2867 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2868 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2869 | root->render_surface()->DrawableContentRect()); |
| 2870 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2871 | |
| 2872 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2873 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2874 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2875 | |
| 2876 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 2877 | // regions of the subtree. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2878 | EXPECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 2879 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2880 | |
| 2881 | // All layers that draw content into the unclipped surface are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2882 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2883 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 2884 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2885 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2886 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 2887 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2888 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2889 | } |
| 2890 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2891 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2892 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
| 2893 | scoped_refptr<Layer> root = Layer::Create(); |
| 2894 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2895 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2896 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2897 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2898 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2899 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2900 | root->AddChild(child1); |
| 2901 | root->AddChild(child2); |
| 2902 | root->AddChild(child3); |
| 2903 | |
| 2904 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 2905 | host->SetRootLayer(root); |
| 2906 | |
| 2907 | gfx::Transform identity_matrix; |
| 2908 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 2909 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 2910 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(), |
| 2911 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 2912 | false); |
| 2913 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(), |
| 2914 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 2915 | false); |
| 2916 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, gfx::Point3F(), |
| 2917 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 2918 | true, false); |
| 2919 | |
| 2920 | RenderSurfaceLayerList render_surface_layer_list; |
| 2921 | // Now set the root render surface an empty clip. |
| 2922 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2923 | root.get(), gfx::Size(), &render_surface_layer_list); |
| 2924 | |
| 2925 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 2926 | ASSERT_TRUE(root->render_surface()); |
| 2927 | EXPECT_FALSE(root->is_clipped()); |
| 2928 | |
| 2929 | gfx::Rect empty; |
| 2930 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 2931 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2932 | |
| 2933 | // Visible content rect calculation will check if the target surface is |
| 2934 | // clipped or not. An empty clip rect does not indicate the render surface |
| 2935 | // is unclipped. |
| 2936 | EXPECT_EQ(empty, child1->visible_content_rect()); |
| 2937 | EXPECT_EQ(empty, child2->visible_content_rect()); |
| 2938 | EXPECT_EQ(empty, child3->visible_content_rect()); |
| 2939 | } |
| 2940 | |
| 2941 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2942 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2943 | scoped_refptr<Layer> root = Layer::Create(); |
| 2944 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2945 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2946 | root->AddChild(child); |
| 2947 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2948 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2949 | host->SetRootLayer(root); |
| 2950 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2951 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2952 | gfx::Transform identity_matrix; |
| 2953 | 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] | 2954 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2955 | |
| 2956 | SetLayerPropertiesForTesting(root.get(), |
| 2957 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2958 | gfx::Point3F(), |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2959 | gfx::PointF(), |
| 2960 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2961 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2962 | false); |
| 2963 | SetLayerPropertiesForTesting(child.get(), |
| 2964 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2965 | gfx::Point3F(), |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2966 | gfx::PointF(5.f, 5.f), |
| 2967 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2968 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2969 | false); |
| 2970 | |
| 2971 | ExecuteCalculateDrawProperties(root.get()); |
| 2972 | |
| 2973 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2974 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2975 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2976 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 2977 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2978 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2979 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2980 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2981 | |
| 2982 | SetLayerPropertiesForTesting(child.get(), |
| 2983 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2984 | gfx::Point3F(), |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2985 | gfx::PointF(5.f, 5.f), |
| 2986 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2987 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2988 | false); |
| 2989 | |
| 2990 | ExecuteCalculateDrawProperties(root.get()); |
| 2991 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2992 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2993 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2994 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2995 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2996 | uninvertible_matrix.MakeIdentity(); |
| 2997 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2998 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2999 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3000 | |
| 3001 | SetLayerPropertiesForTesting(child.get(), |
| 3002 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3003 | gfx::Point3F(), |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3004 | gfx::PointF(5.f, 5.f), |
| 3005 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3006 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3007 | false); |
| 3008 | |
| 3009 | ExecuteCalculateDrawProperties(root.get()); |
| 3010 | |
| 3011 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3012 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3013 | } |
| 3014 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3015 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3016 | SingularTransformDoesNotPreventClearingDrawProperties) { |
| 3017 | scoped_refptr<Layer> root = Layer::Create(); |
| 3018 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 3019 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3020 | root->AddChild(child); |
| 3021 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3022 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3023 | host->SetRootLayer(root); |
| 3024 | |
| 3025 | gfx::Transform identity_matrix; |
| 3026 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 3027 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3028 | |
| 3029 | SetLayerPropertiesForTesting(root.get(), |
| 3030 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3031 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3032 | gfx::PointF(), |
| 3033 | gfx::Size(100, 100), |
| 3034 | true, |
| 3035 | false); |
| 3036 | SetLayerPropertiesForTesting(child.get(), |
| 3037 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3038 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3039 | gfx::PointF(5.f, 5.f), |
| 3040 | gfx::Size(50, 50), |
| 3041 | true, |
| 3042 | false); |
| 3043 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 3044 | child->draw_properties().sorted_for_recursion = true; |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3045 | |
| 3046 | TransformOperations start_transform_operations; |
| 3047 | start_transform_operations.AppendScale(1.f, 0.f, 0.f); |
| 3048 | |
| 3049 | TransformOperations end_transform_operations; |
| 3050 | end_transform_operations.AppendScale(1.f, 1.f, 0.f); |
| 3051 | |
| 3052 | AddAnimatedTransformToLayer( |
| 3053 | root.get(), 10.0, start_transform_operations, end_transform_operations); |
| 3054 | |
| 3055 | EXPECT_TRUE(root->TransformIsAnimating()); |
| 3056 | |
| 3057 | ExecuteCalculateDrawProperties(root.get()); |
| 3058 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 3059 | EXPECT_FALSE(child->draw_properties().sorted_for_recursion); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3060 | } |
| 3061 | |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3062 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3063 | SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) { |
| 3064 | scoped_refptr<Layer> root = Layer::Create(); |
| 3065 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3066 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3067 | host->SetRootLayer(root); |
| 3068 | |
| 3069 | gfx::Transform identity_matrix; |
| 3070 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 3071 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3072 | |
| 3073 | SetLayerPropertiesForTesting(root.get(), |
| 3074 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3075 | gfx::Point3F(), |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3076 | gfx::PointF(), |
| 3077 | gfx::Size(100, 100), |
| 3078 | true, |
| 3079 | false); |
| 3080 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 3081 | root->draw_properties().sorted_for_recursion = true; |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3082 | |
| 3083 | EXPECT_FALSE(root->TransformIsAnimating()); |
| 3084 | |
| 3085 | ExecuteCalculateDrawProperties(root.get()); |
| 3086 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 3087 | EXPECT_FALSE(root->draw_properties().sorted_for_recursion); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3091 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3092 | scoped_refptr<Layer> root = Layer::Create(); |
| 3093 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3094 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3095 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3096 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3097 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3098 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3099 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3100 | root->AddChild(render_surface1); |
| 3101 | render_surface1->AddChild(child1); |
| 3102 | render_surface1->AddChild(child2); |
| 3103 | render_surface1->AddChild(child3); |
| 3104 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3105 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3106 | host->SetRootLayer(root); |
| 3107 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3108 | gfx::Transform identity_matrix; |
| 3109 | SetLayerPropertiesForTesting(root.get(), |
| 3110 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3111 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3112 | gfx::PointF(), |
| 3113 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3114 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3115 | false); |
| 3116 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3117 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3118 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3119 | gfx::PointF(), |
| 3120 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3121 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3122 | false); |
| 3123 | SetLayerPropertiesForTesting(child1.get(), |
| 3124 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3125 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3126 | gfx::PointF(5.f, 5.f), |
| 3127 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3128 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3129 | false); |
| 3130 | SetLayerPropertiesForTesting(child2.get(), |
| 3131 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3132 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3133 | gfx::PointF(75.f, 75.f), |
| 3134 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3135 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3136 | false); |
| 3137 | SetLayerPropertiesForTesting(child3.get(), |
| 3138 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3139 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3140 | gfx::PointF(125.f, 125.f), |
| 3141 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3142 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3143 | false); |
| 3144 | |
| 3145 | root->SetMasksToBounds(true); |
| 3146 | render_surface1->SetForceRenderSurface(true); |
| 3147 | ExecuteCalculateDrawProperties(root.get()); |
| 3148 | |
| 3149 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3150 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3151 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3152 | root->render_surface()->DrawableContentRect()); |
| 3153 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3154 | |
| 3155 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3156 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3157 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3158 | |
| 3159 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3160 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3161 | EXPECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3162 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3163 | |
| 3164 | // All layers that draw content into the surface have their visible content |
| 3165 | // rect clipped by the surface clip rect. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3166 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3167 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3168 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 3169 | |
| 3170 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3171 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3172 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3173 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3174 | } |
| 3175 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3176 | TEST_F(LayerTreeHostCommonTest, |
| 3177 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3178 | // Check that clipping does not propagate down surfaces. |
| 3179 | scoped_refptr<Layer> root = Layer::Create(); |
| 3180 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3181 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 3182 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3183 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3184 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3185 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3186 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3187 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3188 | root->AddChild(render_surface1); |
| 3189 | render_surface1->AddChild(render_surface2); |
| 3190 | render_surface2->AddChild(child1); |
| 3191 | render_surface2->AddChild(child2); |
| 3192 | render_surface2->AddChild(child3); |
| 3193 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3194 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3195 | host->SetRootLayer(root); |
| 3196 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3197 | gfx::Transform identity_matrix; |
| 3198 | SetLayerPropertiesForTesting(root.get(), |
| 3199 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3200 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3201 | gfx::PointF(), |
| 3202 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3203 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3204 | false); |
| 3205 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3206 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3207 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3208 | gfx::PointF(), |
| 3209 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3210 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3211 | false); |
| 3212 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3213 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3214 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3215 | gfx::PointF(), |
| 3216 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3217 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3218 | false); |
| 3219 | SetLayerPropertiesForTesting(child1.get(), |
| 3220 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3221 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3222 | gfx::PointF(5.f, 5.f), |
| 3223 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3224 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3225 | false); |
| 3226 | SetLayerPropertiesForTesting(child2.get(), |
| 3227 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3228 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3229 | gfx::PointF(75.f, 75.f), |
| 3230 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3231 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3232 | false); |
| 3233 | SetLayerPropertiesForTesting(child3.get(), |
| 3234 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3235 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3236 | gfx::PointF(125.f, 125.f), |
| 3237 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3238 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3239 | false); |
| 3240 | |
| 3241 | root->SetMasksToBounds(true); |
| 3242 | render_surface1->SetForceRenderSurface(true); |
| 3243 | render_surface2->SetForceRenderSurface(true); |
| 3244 | ExecuteCalculateDrawProperties(root.get()); |
| 3245 | |
| 3246 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3247 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3248 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3249 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3250 | root->render_surface()->DrawableContentRect()); |
| 3251 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3252 | |
| 3253 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3254 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3255 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
| 3256 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3257 | |
| 3258 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3259 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3260 | EXPECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3261 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3262 | |
| 3263 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3264 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3265 | // render_surface2 grows to enclose all drawable content of its subtree. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3266 | EXPECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 3267 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3268 | |
| 3269 | // All layers that draw content into render_surface2 think they are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3270 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3271 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3272 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3273 | |
| 3274 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3275 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3276 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3277 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3278 | } |
| 3279 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3280 | TEST_F(LayerTreeHostCommonTest, |
| 3281 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3282 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3283 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3284 | |
| 3285 | scoped_refptr<Layer> root = Layer::Create(); |
| 3286 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3287 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3288 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3289 | root->AddChild(render_surface1); |
| 3290 | render_surface1->AddChild(child1); |
| 3291 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3292 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3293 | host->SetRootLayer(root); |
| 3294 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3295 | gfx::Transform identity_matrix; |
| 3296 | gfx::Transform child_rotation; |
| 3297 | child_rotation.Rotate(45.0); |
| 3298 | SetLayerPropertiesForTesting(root.get(), |
| 3299 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3300 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3301 | gfx::PointF(), |
| 3302 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3303 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3304 | false); |
| 3305 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3306 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3307 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3308 | gfx::PointF(), |
| 3309 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3310 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3311 | false); |
| 3312 | SetLayerPropertiesForTesting(child1.get(), |
| 3313 | child_rotation, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3314 | gfx::Point3F(25, 25, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3315 | gfx::PointF(25.f, 25.f), |
| 3316 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3317 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3318 | false); |
| 3319 | |
| 3320 | render_surface1->SetForceRenderSurface(true); |
| 3321 | ExecuteCalculateDrawProperties(root.get()); |
| 3322 | |
| 3323 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3324 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3325 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3326 | root->render_surface()->DrawableContentRect()); |
| 3327 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3328 | |
| 3329 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3330 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3331 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3332 | |
| 3333 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3334 | // regions of the subtree. |
| 3335 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3336 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3337 | gfx::Rect(50 - diagonal_radius, |
| 3338 | 50 - diagonal_radius, |
| 3339 | diagonal_radius * 2, |
| 3340 | diagonal_radius * 2); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3341 | EXPECT_EQ(expected_surface_drawable_content, |
| 3342 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3343 | |
| 3344 | // All layers that draw content into the unclipped surface are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3345 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3346 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3347 | } |
| 3348 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3349 | TEST_F(LayerTreeHostCommonTest, |
| 3350 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3351 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3352 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3353 | |
| 3354 | scoped_refptr<Layer> root = Layer::Create(); |
| 3355 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3356 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3357 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3358 | root->AddChild(render_surface1); |
| 3359 | render_surface1->AddChild(child1); |
| 3360 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3361 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3362 | host->SetRootLayer(root); |
| 3363 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3364 | gfx::Transform identity_matrix; |
| 3365 | gfx::Transform child_rotation; |
| 3366 | child_rotation.Rotate(45.0); |
| 3367 | SetLayerPropertiesForTesting(root.get(), |
| 3368 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3369 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3370 | gfx::PointF(), |
| 3371 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3372 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3373 | false); |
| 3374 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3375 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3376 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3377 | gfx::PointF(), |
| 3378 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3379 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3380 | false); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3381 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3382 | SetLayerPropertiesForTesting(child1.get(), |
| 3383 | child_rotation, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3384 | gfx::Point3F(25, 25, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3385 | gfx::PointF(25.f, 25.f), |
| 3386 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3387 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3388 | false); |
| 3389 | |
| 3390 | root->SetMasksToBounds(true); |
| 3391 | render_surface1->SetForceRenderSurface(true); |
| 3392 | ExecuteCalculateDrawProperties(root.get()); |
| 3393 | |
| 3394 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3395 | |
| 3396 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 3397 | // rotated layer. |
| 3398 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3399 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 3400 | 50 - diagonal_radius, |
| 3401 | diagonal_radius * 2, |
| 3402 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3403 | gfx::Rect expected_surface_drawable_content = |
| 3404 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3405 | EXPECT_EQ(expected_surface_drawable_content, |
| 3406 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3407 | |
| 3408 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3409 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 3410 | // up covering the full left half of child1. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3411 | // |
| 3412 | // Given the floating point math, this number is a little bit fuzzy. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3413 | EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3414 | |
| 3415 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3416 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3417 | } |
| 3418 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3419 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3420 | MockContentLayerClient client; |
| 3421 | |
| 3422 | scoped_refptr<Layer> root = Layer::Create(); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 3423 | scoped_refptr<FakePictureLayer> render_surface1 = |
| 3424 | CreateDrawablePictureLayer(&client); |
| 3425 | scoped_refptr<FakePictureLayer> render_surface2 = |
| 3426 | CreateDrawablePictureLayer(&client); |
| 3427 | scoped_refptr<FakePictureLayer> child1 = CreateDrawablePictureLayer(&client); |
| 3428 | scoped_refptr<FakePictureLayer> child2 = CreateDrawablePictureLayer(&client); |
| 3429 | scoped_refptr<FakePictureLayer> child3 = CreateDrawablePictureLayer(&client); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3430 | root->AddChild(render_surface1); |
| 3431 | render_surface1->AddChild(render_surface2); |
| 3432 | render_surface2->AddChild(child1); |
| 3433 | render_surface2->AddChild(child2); |
| 3434 | render_surface2->AddChild(child3); |
| 3435 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3436 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3437 | host->SetRootLayer(root); |
| 3438 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3439 | gfx::Transform identity_matrix; |
| 3440 | SetLayerPropertiesForTesting(root.get(), |
| 3441 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3442 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3443 | gfx::PointF(), |
| 3444 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3445 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3446 | false); |
| 3447 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3448 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3449 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3450 | gfx::PointF(5.f, 5.f), |
| 3451 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3452 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3453 | false); |
| 3454 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3455 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3456 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3457 | gfx::PointF(5.f, 5.f), |
| 3458 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3459 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3460 | false); |
| 3461 | SetLayerPropertiesForTesting(child1.get(), |
| 3462 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3463 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3464 | gfx::PointF(5.f, 5.f), |
| 3465 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3466 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3467 | false); |
| 3468 | SetLayerPropertiesForTesting(child2.get(), |
| 3469 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3470 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3471 | gfx::PointF(75.f, 75.f), |
| 3472 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3473 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3474 | false); |
| 3475 | SetLayerPropertiesForTesting(child3.get(), |
| 3476 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3477 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3478 | gfx::PointF(125.f, 125.f), |
| 3479 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3480 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3481 | false); |
| 3482 | |
| 3483 | float device_scale_factor = 2.f; |
| 3484 | |
| 3485 | root->SetMasksToBounds(true); |
| 3486 | render_surface1->SetForceRenderSurface(true); |
| 3487 | render_surface2->SetForceRenderSurface(true); |
| 3488 | ExecuteCalculateDrawProperties(root.get(), device_scale_factor); |
| 3489 | |
| 3490 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3491 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3492 | |
| 3493 | // drawable_content_rects for all layers and surfaces are scaled by |
| 3494 | // device_scale_factor. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3495 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 3496 | root->render_surface()->DrawableContentRect()); |
| 3497 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); |
| 3498 | EXPECT_EQ(gfx::Rect(10, 10, 190, 190), |
| 3499 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3500 | |
| 3501 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 3502 | // is only implicitly clipped by render_surface1. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3503 | EXPECT_EQ(gfx::Rect(10, 10, 350, 350), |
| 3504 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3505 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3506 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3507 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 3508 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3509 | |
| 3510 | // The root layer does not actually draw content of its own. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3511 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3512 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 3513 | // All layer visible content rects are not expressed in content space of each |
| 3514 | // layer, so they are not scaled by the device_scale_factor. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3515 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_content_rect()); |
| 3516 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_content_rect()); |
| 3517 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3518 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3519 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3520 | } |
| 3521 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3522 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3523 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 3524 | // layers. Note that 3d transforms still apply in this case, but they are |
| 3525 | // "flattened" to each parent layer according to current W3C spec. |
| 3526 | |
| 3527 | const gfx::Transform identity_matrix; |
| 3528 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3529 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3530 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3531 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3532 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3533 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3534 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3535 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3536 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3537 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3538 | front_facing_child_of_front_facing_surface = |
| 3539 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3540 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3541 | back_facing_child_of_front_facing_surface = |
| 3542 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3543 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3544 | front_facing_child_of_back_facing_surface = |
| 3545 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3546 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3547 | back_facing_child_of_back_facing_surface = |
| 3548 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3549 | |
| 3550 | parent->AddChild(front_facing_child); |
| 3551 | parent->AddChild(back_facing_child); |
| 3552 | parent->AddChild(front_facing_surface); |
| 3553 | parent->AddChild(back_facing_surface); |
| 3554 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3555 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3556 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3557 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3558 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3559 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3560 | host->SetRootLayer(parent); |
| 3561 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3562 | // Nothing is double-sided |
| 3563 | front_facing_child->SetDoubleSided(false); |
| 3564 | back_facing_child->SetDoubleSided(false); |
| 3565 | front_facing_surface->SetDoubleSided(false); |
| 3566 | back_facing_surface->SetDoubleSided(false); |
| 3567 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3568 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3569 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3570 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3571 | |
| 3572 | gfx::Transform backface_matrix; |
| 3573 | backface_matrix.Translate(50.0, 50.0); |
| 3574 | backface_matrix.RotateAboutYAxis(180.0); |
| 3575 | backface_matrix.Translate(-50.0, -50.0); |
| 3576 | |
| 3577 | // Having a descendant and opacity will force these to have render surfaces. |
| 3578 | front_facing_surface->SetOpacity(0.5f); |
| 3579 | back_facing_surface->SetOpacity(0.5f); |
| 3580 | |
| 3581 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 3582 | // these layers should blindly use their own local transforms to determine |
| 3583 | // back-face culling. |
| 3584 | SetLayerPropertiesForTesting(parent.get(), |
| 3585 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3586 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3587 | gfx::PointF(), |
| 3588 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3589 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3590 | false); |
| 3591 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3592 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3593 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3594 | gfx::PointF(), |
| 3595 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3596 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3597 | false); |
| 3598 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3599 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3600 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3601 | gfx::PointF(), |
| 3602 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3603 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3604 | false); |
| 3605 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3606 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3607 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3608 | gfx::PointF(), |
| 3609 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3610 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3611 | false); |
| 3612 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3613 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3614 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3615 | gfx::PointF(), |
| 3616 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3617 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3618 | false); |
| 3619 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3620 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3621 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3622 | gfx::PointF(), |
| 3623 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3624 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3625 | false); |
| 3626 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3627 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3628 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3629 | gfx::PointF(), |
| 3630 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3631 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3632 | false); |
| 3633 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3634 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3635 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3636 | gfx::PointF(), |
| 3637 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3638 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3639 | false); |
| 3640 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3641 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3642 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3643 | gfx::PointF(), |
| 3644 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3645 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3646 | false); |
| 3647 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3648 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3649 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3650 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3651 | inputs.can_adjust_raster_scales = true; |
| 3652 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3653 | |
| 3654 | // Verify which render surfaces were created. |
| 3655 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3656 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3657 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3658 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 3659 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3660 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3661 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3662 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3663 | |
| 3664 | // Verify the render_surface_layer_list. |
| 3665 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3666 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3667 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3668 | // Even though the back facing surface LAYER gets culled, the other |
| 3669 | // descendants should still be added, so the SURFACE should not be culled. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3670 | EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3671 | |
| 3672 | // Verify root surface's layer list. |
| 3673 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3674 | 3u, |
| 3675 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3676 | EXPECT_EQ(front_facing_child->id(), |
| 3677 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3678 | ->render_surface() |
| 3679 | ->layer_list() |
| 3680 | .at(0) |
| 3681 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3682 | EXPECT_EQ(front_facing_surface->id(), |
| 3683 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3684 | ->render_surface() |
| 3685 | ->layer_list() |
| 3686 | .at(1) |
| 3687 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3688 | EXPECT_EQ(back_facing_surface->id(), |
| 3689 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3690 | ->render_surface() |
| 3691 | ->layer_list() |
| 3692 | .at(2) |
| 3693 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3694 | |
| 3695 | // Verify front_facing_surface's layer list. |
| 3696 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3697 | 2u, |
| 3698 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3699 | EXPECT_EQ(front_facing_surface->id(), |
| 3700 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3701 | ->render_surface() |
| 3702 | ->layer_list() |
| 3703 | .at(0) |
| 3704 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3705 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3706 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3707 | ->render_surface() |
| 3708 | ->layer_list() |
| 3709 | .at(1) |
| 3710 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3711 | |
| 3712 | // Verify back_facing_surface's layer list; its own layer should be culled |
| 3713 | // from the surface list. |
| 3714 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3715 | 1u, |
| 3716 | render_surface_layer_list.at(2)->render_surface()->layer_list().size()); |
| 3717 | EXPECT_EQ(front_facing_child_of_back_facing_surface->id(), |
| 3718 | render_surface_layer_list.at(2) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3719 | ->render_surface() |
| 3720 | ->layer_list() |
| 3721 | .at(0) |
| 3722 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3723 | } |
| 3724 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3725 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3726 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 3727 | // is used. |
| 3728 | |
| 3729 | const gfx::Transform identity_matrix; |
| 3730 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3731 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3732 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3733 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3734 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3735 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3736 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3737 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3738 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3739 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3740 | front_facing_child_of_front_facing_surface = |
| 3741 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3742 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3743 | back_facing_child_of_front_facing_surface = |
| 3744 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3745 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3746 | front_facing_child_of_back_facing_surface = |
| 3747 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3748 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3749 | back_facing_child_of_back_facing_surface = |
| 3750 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3751 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 = |
| 3752 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3753 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 = |
| 3754 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3755 | |
| 3756 | parent->AddChild(front_facing_child); |
| 3757 | parent->AddChild(back_facing_child); |
| 3758 | parent->AddChild(front_facing_surface); |
| 3759 | parent->AddChild(back_facing_surface); |
| 3760 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3761 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3762 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3763 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3764 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3765 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3766 | host->SetRootLayer(parent); |
| 3767 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3768 | // Nothing is double-sided |
| 3769 | front_facing_child->SetDoubleSided(false); |
| 3770 | back_facing_child->SetDoubleSided(false); |
| 3771 | front_facing_surface->SetDoubleSided(false); |
| 3772 | back_facing_surface->SetDoubleSided(false); |
| 3773 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3774 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3775 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3776 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3777 | |
| 3778 | gfx::Transform backface_matrix; |
| 3779 | backface_matrix.Translate(50.0, 50.0); |
| 3780 | backface_matrix.RotateAboutYAxis(180.0); |
| 3781 | backface_matrix.Translate(-50.0, -50.0); |
| 3782 | |
| 3783 | // Opacity will not force creation of render surfaces in this case because of |
| 3784 | // the preserve-3d transform style. Instead, an example of when a surface |
| 3785 | // would be created with preserve-3d is when there is a replica layer. |
| 3786 | front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get()); |
| 3787 | back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get()); |
| 3788 | |
| 3789 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 3790 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 3791 | // rendering context should use the transform with respect to that context. |
| 3792 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 3793 | // and (b) the layer's transform style is preserve-3d. |
| 3794 | SetLayerPropertiesForTesting(parent.get(), |
| 3795 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3796 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3797 | gfx::PointF(), |
| 3798 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3799 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3800 | false); // parent transform style is flat. |
| 3801 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3802 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3803 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3804 | gfx::PointF(), |
| 3805 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3806 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3807 | false); |
| 3808 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3809 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3810 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3811 | gfx::PointF(), |
| 3812 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3813 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3814 | false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3815 | // surface transform style is preserve-3d. |
| 3816 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3817 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3818 | gfx::Point3F(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3819 | gfx::PointF(), |
| 3820 | gfx::Size(100, 100), |
| 3821 | false, |
| 3822 | true); |
| 3823 | // surface transform style is preserve-3d. |
| 3824 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3825 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3826 | gfx::Point3F(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3827 | gfx::PointF(), |
| 3828 | gfx::Size(100, 100), |
| 3829 | false, |
| 3830 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3831 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3832 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3833 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3834 | gfx::PointF(), |
| 3835 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3836 | true, |
| 3837 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3838 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3839 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3840 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3841 | gfx::PointF(), |
| 3842 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3843 | true, |
| 3844 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3845 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3846 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3847 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3848 | gfx::PointF(), |
| 3849 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3850 | true, |
| 3851 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3852 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3853 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3854 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3855 | gfx::PointF(), |
| 3856 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3857 | true, |
| 3858 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3859 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3860 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3861 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3862 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3863 | inputs.can_adjust_raster_scales = true; |
| 3864 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3865 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3866 | // Verify which render surfaces were created and used. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3867 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3868 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3869 | EXPECT_TRUE(front_facing_surface->render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3870 | EXPECT_NE(back_facing_surface->render_target(), back_facing_surface); |
| 3871 | // We expect that a render_surface was created but not used. |
| 3872 | EXPECT_TRUE(back_facing_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3873 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3874 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3875 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3876 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3877 | |
| 3878 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 3879 | // culled. |
| 3880 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3881 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3882 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3883 | |
| 3884 | // Verify root surface's layer list. |
| 3885 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3886 | 2u, |
| 3887 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3888 | EXPECT_EQ(front_facing_child->id(), |
| 3889 | render_surface_layer_list.at(0) |
| 3890 | ->render_surface()->layer_list().at(0)->id()); |
| 3891 | EXPECT_EQ(front_facing_surface->id(), |
| 3892 | render_surface_layer_list.at(0) |
| 3893 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3894 | |
| 3895 | // Verify front_facing_surface's layer list. |
| 3896 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3897 | 2u, |
| 3898 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3899 | EXPECT_EQ(front_facing_surface->id(), |
| 3900 | render_surface_layer_list.at(1) |
| 3901 | ->render_surface()->layer_list().at(0)->id()); |
| 3902 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3903 | render_surface_layer_list.at(1) |
| 3904 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3905 | } |
| 3906 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3907 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3908 | // Verify that layers are appropriately culled when their back face is showing |
| 3909 | // and they are not double sided, while animations are going on. |
| 3910 | // |
| 3911 | // Layers that are animating do not get culled on the main thread, as their |
| 3912 | // transforms should be treated as "unknown" so we can not be sure that their |
| 3913 | // back face is really showing. |
| 3914 | const gfx::Transform identity_matrix; |
| 3915 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3916 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 3917 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3918 | scoped_refptr<LayerWithForcedDrawsContent> animating_surface = |
| 3919 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3920 | scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = |
| 3921 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3922 | scoped_refptr<LayerWithForcedDrawsContent> animating_child = |
| 3923 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3924 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3925 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3926 | |
| 3927 | parent->AddChild(child); |
| 3928 | parent->AddChild(animating_surface); |
| 3929 | animating_surface->AddChild(child_of_animating_surface); |
| 3930 | parent->AddChild(animating_child); |
| 3931 | parent->AddChild(child2); |
| 3932 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3933 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3934 | host->SetRootLayer(parent); |
| 3935 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3936 | // Nothing is double-sided |
| 3937 | child->SetDoubleSided(false); |
| 3938 | child2->SetDoubleSided(false); |
| 3939 | animating_surface->SetDoubleSided(false); |
| 3940 | child_of_animating_surface->SetDoubleSided(false); |
| 3941 | animating_child->SetDoubleSided(false); |
| 3942 | |
| 3943 | gfx::Transform backface_matrix; |
| 3944 | backface_matrix.Translate(50.0, 50.0); |
| 3945 | backface_matrix.RotateAboutYAxis(180.0); |
| 3946 | backface_matrix.Translate(-50.0, -50.0); |
| 3947 | |
| 3948 | // Make our render surface. |
| 3949 | animating_surface->SetForceRenderSurface(true); |
| 3950 | |
| 3951 | // Animate the transform on the render surface. |
| 3952 | AddAnimatedTransformToController( |
| 3953 | animating_surface->layer_animation_controller(), 10.0, 30, 0); |
| 3954 | // This is just an animating layer, not a surface. |
| 3955 | AddAnimatedTransformToController( |
| 3956 | animating_child->layer_animation_controller(), 10.0, 30, 0); |
| 3957 | |
| 3958 | SetLayerPropertiesForTesting(parent.get(), |
| 3959 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3960 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3961 | gfx::PointF(), |
| 3962 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3963 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3964 | false); |
| 3965 | SetLayerPropertiesForTesting(child.get(), |
| 3966 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3967 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3968 | gfx::PointF(), |
| 3969 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3970 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3971 | false); |
| 3972 | SetLayerPropertiesForTesting(animating_surface.get(), |
| 3973 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3974 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3975 | gfx::PointF(), |
| 3976 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3977 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3978 | false); |
| 3979 | SetLayerPropertiesForTesting(child_of_animating_surface.get(), |
| 3980 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3981 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3982 | gfx::PointF(), |
| 3983 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3984 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3985 | false); |
| 3986 | SetLayerPropertiesForTesting(animating_child.get(), |
| 3987 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3988 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3989 | gfx::PointF(), |
| 3990 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3991 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3992 | false); |
| 3993 | SetLayerPropertiesForTesting(child2.get(), |
| 3994 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3995 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3996 | gfx::PointF(), |
| 3997 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3998 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3999 | false); |
| 4000 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4001 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4002 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4003 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4004 | inputs.can_adjust_raster_scales = true; |
| 4005 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4006 | |
| 4007 | EXPECT_FALSE(child->render_surface()); |
| 4008 | EXPECT_TRUE(animating_surface->render_surface()); |
| 4009 | EXPECT_FALSE(child_of_animating_surface->render_surface()); |
| 4010 | EXPECT_FALSE(animating_child->render_surface()); |
| 4011 | EXPECT_FALSE(child2->render_surface()); |
| 4012 | |
| 4013 | // Verify that the animating_child and child_of_animating_surface were not |
| 4014 | // culled, but that child was. |
| 4015 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4016 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4017 | EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4018 | |
| 4019 | // The non-animating child be culled from the layer list for the parent render |
| 4020 | // surface. |
| 4021 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4022 | 3u, |
| 4023 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4024 | EXPECT_EQ(animating_surface->id(), |
| 4025 | render_surface_layer_list.at(0) |
| 4026 | ->render_surface()->layer_list().at(0)->id()); |
| 4027 | EXPECT_EQ(animating_child->id(), |
| 4028 | render_surface_layer_list.at(0) |
| 4029 | ->render_surface()->layer_list().at(1)->id()); |
| 4030 | EXPECT_EQ(child2->id(), |
| 4031 | render_surface_layer_list.at(0) |
| 4032 | ->render_surface()->layer_list().at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4033 | |
| 4034 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4035 | 2u, |
| 4036 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4037 | EXPECT_EQ(animating_surface->id(), |
| 4038 | render_surface_layer_list.at(1) |
| 4039 | ->render_surface()->layer_list().at(0)->id()); |
| 4040 | EXPECT_EQ(child_of_animating_surface->id(), |
| 4041 | render_surface_layer_list.at(1) |
| 4042 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4043 | |
| 4044 | EXPECT_FALSE(child2->visible_content_rect().IsEmpty()); |
| 4045 | |
| 4046 | // The animating layers should have a visible content rect that represents the |
| 4047 | // area of the front face that is within the viewport. |
| 4048 | EXPECT_EQ(animating_child->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4049 | gfx::Rect(animating_child->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4050 | EXPECT_EQ(animating_surface->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4051 | gfx::Rect(animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4052 | // And layers in the subtree of the animating layer should have valid visible |
| 4053 | // content rects also. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4054 | EXPECT_EQ(child_of_animating_surface->visible_content_rect(), |
| 4055 | gfx::Rect(child_of_animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4056 | } |
| 4057 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4058 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4059 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4060 | // Verify the behavior of back-face culling for a render surface that is |
| 4061 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4062 | |
| 4063 | const gfx::Transform identity_matrix; |
| 4064 | scoped_refptr<Layer> parent = Layer::Create(); |
| 4065 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 4066 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4067 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 4068 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4069 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 4070 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4071 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 4072 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4073 | |
| 4074 | parent->AddChild(front_facing_surface); |
| 4075 | parent->AddChild(back_facing_surface); |
| 4076 | front_facing_surface->AddChild(child1); |
| 4077 | back_facing_surface->AddChild(child2); |
| 4078 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4079 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4080 | host->SetRootLayer(parent); |
| 4081 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4082 | // RenderSurfaces are not double-sided |
| 4083 | front_facing_surface->SetDoubleSided(false); |
| 4084 | back_facing_surface->SetDoubleSided(false); |
| 4085 | |
| 4086 | gfx::Transform backface_matrix; |
| 4087 | backface_matrix.Translate(50.0, 50.0); |
| 4088 | backface_matrix.RotateAboutYAxis(180.0); |
| 4089 | backface_matrix.Translate(-50.0, -50.0); |
| 4090 | |
| 4091 | SetLayerPropertiesForTesting(parent.get(), |
| 4092 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4093 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4094 | gfx::PointF(), |
| 4095 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4096 | false, |
| 4097 | true); // parent transform style is preserve3d. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4098 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 4099 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4100 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4101 | gfx::PointF(), |
| 4102 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4103 | true, |
| 4104 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4105 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4106 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4107 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4108 | gfx::PointF(), |
| 4109 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4110 | true, |
| 4111 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4112 | SetLayerPropertiesForTesting(child1.get(), |
| 4113 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4114 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4115 | gfx::PointF(), |
| 4116 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4117 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4118 | false); |
| 4119 | SetLayerPropertiesForTesting(child2.get(), |
| 4120 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4121 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4122 | gfx::PointF(), |
| 4123 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4124 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4125 | false); |
| 4126 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4127 | front_facing_surface->Set3dSortingContextId(1); |
| 4128 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4129 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4130 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4131 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4132 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4133 | inputs.can_adjust_raster_scales = true; |
| 4134 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4135 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4136 | // Verify which render surfaces were created and used. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4137 | EXPECT_TRUE(front_facing_surface->render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4138 | |
| 4139 | // We expect the render surface to have been created, but remain unused. |
| 4140 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 4141 | EXPECT_NE(back_facing_surface->render_target(), |
| 4142 | back_facing_surface); // because it should be culled |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4143 | EXPECT_FALSE(child1->render_surface()); |
| 4144 | EXPECT_FALSE(child2->render_surface()); |
| 4145 | |
| 4146 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 4147 | // culled. |
| 4148 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4149 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4150 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4151 | |
| 4152 | // Verify root surface's layer list. |
| 4153 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4154 | 1u, |
| 4155 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4156 | EXPECT_EQ(front_facing_surface->id(), |
| 4157 | render_surface_layer_list.at(0) |
| 4158 | ->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4159 | |
| 4160 | // Verify front_facing_surface's layer list. |
| 4161 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4162 | 2u, |
| 4163 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4164 | EXPECT_EQ(front_facing_surface->id(), |
| 4165 | render_surface_layer_list.at(1) |
| 4166 | ->render_surface()->layer_list().at(0)->id()); |
| 4167 | EXPECT_EQ(child1->id(), |
| 4168 | render_surface_layer_list.at(1) |
| 4169 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4170 | } |
| 4171 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4172 | class NoScaleContentLayer : public ContentLayer { |
| 4173 | public: |
| 4174 | static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
| 4175 | return make_scoped_refptr(new NoScaleContentLayer(client)); |
| 4176 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4177 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 4178 | void CalculateContentsScale(float ideal_contents_scale, |
| 4179 | float* contents_scale_x, |
| 4180 | float* contents_scale_y, |
| 4181 | gfx::Size* content_bounds) override { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4182 | // Skip over the ContentLayer to the base Layer class. |
| 4183 | Layer::CalculateContentsScale(ideal_contents_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4184 | contents_scale_x, |
| 4185 | contents_scale_y, |
| 4186 | content_bounds); |
| 4187 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4188 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4189 | protected: |
| 4190 | explicit NoScaleContentLayer(ContentLayerClient* client) |
| 4191 | : ContentLayer(client) {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 4192 | ~NoScaleContentLayer() override {} |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4193 | }; |
| 4194 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4195 | scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer( |
| 4196 | ContentLayerClient* delegate) { |
| 4197 | scoped_refptr<NoScaleContentLayer> to_return = |
| 4198 | NoScaleContentLayer::Create(delegate); |
| 4199 | to_return->SetIsDrawable(true); |
| 4200 | return to_return; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4201 | } |
| 4202 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4203 | TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4204 | // Verify draw and screen space transforms of layers not in a surface. |
| 4205 | MockContentLayerClient delegate; |
| 4206 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4207 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4208 | scoped_refptr<FakePictureLayer> parent = |
| 4209 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4210 | SetLayerPropertiesForTesting(parent.get(), |
| 4211 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4212 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4213 | gfx::PointF(), |
| 4214 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4215 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4216 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4217 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4218 | scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4219 | SetLayerPropertiesForTesting(child.get(), |
| 4220 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4221 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4222 | gfx::PointF(2.f, 2.f), |
| 4223 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4224 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4225 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4226 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4227 | scoped_refptr<FakePictureLayer> child_empty = |
| 4228 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4229 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4230 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4231 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4232 | gfx::PointF(2.f, 2.f), |
| 4233 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4234 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4235 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4236 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4237 | parent->AddChild(child); |
| 4238 | parent->AddChild(child_empty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4239 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4240 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4241 | host->SetRootLayer(parent); |
| 4242 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4243 | float device_scale_factor = 2.5f; |
| 4244 | float page_scale_factor = 1.f; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4245 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4246 | RenderSurfaceLayerList render_surface_layer_list; |
| 4247 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4248 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4249 | inputs.device_scale_factor = device_scale_factor; |
| 4250 | inputs.page_scale_factor = page_scale_factor; |
| 4251 | inputs.can_adjust_raster_scales = true; |
| 4252 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4253 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4254 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4255 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4256 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child_empty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4257 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4258 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4259 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4260 | // Verify parent transforms |
| 4261 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4262 | expected_parent_transform.Scale(device_scale_factor * page_scale_factor, |
| 4263 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4264 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4265 | parent->screen_space_transform()); |
| 4266 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4267 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4268 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4269 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4270 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4271 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4272 | gfx::RectF parent_draw_rect = |
| 4273 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4274 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4275 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4276 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4277 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4278 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4279 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4280 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4281 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4282 | // Verify child and child_empty transforms. They should match. |
| 4283 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4284 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4285 | expected_child_transform.Translate(child->position().x(), |
| 4286 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4287 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4288 | child->draw_transform()); |
| 4289 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4290 | child->screen_space_transform()); |
| 4291 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4292 | child_empty->draw_transform()); |
| 4293 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4294 | child_empty->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4295 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4296 | // Verify results of transformed child and child_empty rects. They should |
| 4297 | // match. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4298 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4299 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4300 | gfx::RectF child_draw_rect = |
| 4301 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4302 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4303 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4304 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4305 | gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( |
| 4306 | child_empty->draw_transform(), child_content_bounds); |
| 4307 | gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( |
| 4308 | child_empty->screen_space_transform(), child_content_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4309 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4310 | gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); |
| 4311 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4312 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4313 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
| 4314 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); |
| 4315 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4316 | } |
| 4317 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4318 | TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4319 | // Verify draw and screen space transforms of layers in a surface. |
| 4320 | MockContentLayerClient delegate; |
| 4321 | gfx::Transform identity_matrix; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4322 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4323 | gfx::Transform perspective_matrix; |
| 4324 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4325 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4326 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4327 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4328 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4329 | scoped_refptr<Layer> root = Layer::Create(); |
| 4330 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4331 | scoped_refptr<FakePictureLayer> parent = |
| 4332 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4333 | SetLayerPropertiesForTesting(parent.get(), |
| 4334 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4335 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4336 | gfx::PointF(), |
| 4337 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4338 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4339 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4340 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4341 | scoped_refptr<FakePictureLayer> perspective_surface = |
| 4342 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4343 | SetLayerPropertiesForTesting(perspective_surface.get(), |
| 4344 | perspective_matrix * scale_small_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4345 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4346 | gfx::PointF(2.f, 2.f), |
| 4347 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4348 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4349 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4350 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4351 | scoped_refptr<FakePictureLayer> scale_surface = |
| 4352 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4353 | SetLayerPropertiesForTesting(scale_surface.get(), |
| 4354 | scale_small_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4355 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4356 | gfx::PointF(2.f, 2.f), |
| 4357 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4358 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4359 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4360 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4361 | perspective_surface->SetForceRenderSurface(true); |
| 4362 | scale_surface->SetForceRenderSurface(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4363 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4364 | parent->AddChild(perspective_surface); |
| 4365 | parent->AddChild(scale_surface); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4366 | root->AddChild(parent); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4367 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4368 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4369 | host->SetRootLayer(root); |
| 4370 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4371 | float device_scale_factor = 2.5f; |
| 4372 | float page_scale_factor = 3.f; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4373 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4374 | RenderSurfaceLayerList render_surface_layer_list; |
| 4375 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4376 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 4377 | inputs.device_scale_factor = device_scale_factor; |
| 4378 | inputs.page_scale_factor = page_scale_factor; |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 4379 | inputs.page_scale_application_layer = root.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4380 | inputs.can_adjust_raster_scales = true; |
| 4381 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4382 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4383 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4384 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4385 | perspective_surface); |
| 4386 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4387 | // the nearest render target. Here this includes the layer transform as well |
| 4388 | // as the device and page scale factors. |
| 4389 | gfx::Transform transform = scale_small_matrix; |
| 4390 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4391 | device_scale_factor * page_scale_factor); |
| 4392 | gfx::Vector2dF scales = |
| 4393 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4394 | float max_2d_scale = std::max(scales.x(), scales.y()); |
| 4395 | EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface); |
| 4396 | |
| 4397 | // The ideal scale will draw 1:1 with its render target space along |
| 4398 | // the larger-scale axis. |
| 4399 | gfx::Vector2dF target_space_transform_scales = |
| 4400 | MathUtil::ComputeTransform2dScaleComponents( |
| 4401 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4402 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4403 | std::max(target_space_transform_scales.x(), |
| 4404 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4405 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4406 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4407 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4408 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4409 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4410 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4411 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
| 4412 | parent->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4413 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4414 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4415 | // with the screen, and then scaled during drawing. |
| 4416 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4417 | expected_perspective_surface_draw_transform.Translate( |
| 4418 | device_scale_factor * page_scale_factor * |
| 4419 | perspective_surface->position().x(), |
| 4420 | device_scale_factor * page_scale_factor * |
| 4421 | perspective_surface->position().y()); |
| 4422 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4423 | perspective_matrix); |
| 4424 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4425 | scale_small_matrix); |
| 4426 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4427 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4428 | device_scale_factor * page_scale_factor, |
| 4429 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4430 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4431 | expected_perspective_surface_draw_transform, |
| 4432 | perspective_surface->render_surface()->draw_transform()); |
| 4433 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4434 | expected_perspective_surface_layer_draw_transform, |
| 4435 | perspective_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4436 | } |
| 4437 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4438 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4439 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4440 | LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { |
| 4441 | // Verify draw and screen space transforms of layers not in a surface. |
| 4442 | MockContentLayerClient delegate; |
| 4443 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4444 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4445 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4446 | SetLayerPropertiesForTesting(parent.get(), |
| 4447 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4448 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4449 | gfx::PointF(), |
| 4450 | gfx::Size(133, 133), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4451 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4452 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4453 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4454 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 4455 | SetLayerPropertiesForTesting(child.get(), |
| 4456 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4457 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4458 | gfx::PointF(), |
| 4459 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4460 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4461 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4462 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4463 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4464 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4465 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4466 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4467 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4468 | gfx::PointF(), |
| 4469 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4470 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4471 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4472 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4473 | parent->AddChild(child); |
| 4474 | parent->AddChild(child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4475 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4476 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4477 | host->SetRootLayer(parent); |
| 4478 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4479 | float device_scale_factor = 1.7f; |
| 4480 | float page_scale_factor = 1.f; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4481 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4482 | RenderSurfaceLayerList render_surface_layer_list; |
| 4483 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4484 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4485 | inputs.device_scale_factor = device_scale_factor; |
| 4486 | inputs.page_scale_factor = page_scale_factor; |
| 4487 | inputs.page_scale_application_layer = parent.get(); |
| 4488 | inputs.can_adjust_raster_scales = true; |
| 4489 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4490 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4491 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4492 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4493 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4494 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4495 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4496 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4497 | // Verify parent transforms |
| 4498 | gfx::Transform expected_parent_transform; |
| 4499 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4500 | parent->screen_space_transform()); |
| 4501 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4502 | parent->draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4503 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4504 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4505 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4506 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4507 | gfx::RectF parent_draw_rect = |
| 4508 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4509 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4510 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4511 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4512 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4513 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4514 | expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width())); |
| 4515 | expected_parent_draw_rect.set_height( |
| 4516 | ceil(expected_parent_draw_rect.height())); |
| 4517 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4518 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4519 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4520 | // Verify child transforms |
| 4521 | gfx::Transform expected_child_transform; |
| 4522 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4523 | child->draw_transform()); |
| 4524 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4525 | child->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4526 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4527 | // Verify results of transformed child rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4528 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4529 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4530 | gfx::RectF child_draw_rect = |
| 4531 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4532 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4533 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4534 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4535 | gfx::RectF expected_child_draw_rect(child->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4536 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4537 | expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width())); |
| 4538 | expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height())); |
| 4539 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4540 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4541 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4542 | // Verify child_no_scale transforms |
| 4543 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 4544 | // All transforms operate on content rects. The child's content rect |
| 4545 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 4546 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 4547 | device_scale_factor); |
| 4548 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4549 | child_no_scale->draw_transform()); |
| 4550 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4551 | child_no_scale->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4552 | } |
| 4553 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4554 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4555 | TEST_F(LayerTreeHostCommonTest, ContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4556 | MockContentLayerClient delegate; |
| 4557 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4558 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4559 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4560 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4561 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4562 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4563 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4564 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4565 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4566 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4567 | scoped_refptr<Layer> root = Layer::Create(); |
| 4568 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4569 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4570 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4571 | SetLayerPropertiesForTesting(parent.get(), |
| 4572 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4573 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4574 | gfx::PointF(), |
| 4575 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4576 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4577 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4578 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4579 | scoped_refptr<ContentLayer> child_scale = |
| 4580 | CreateDrawableContentLayer(&delegate); |
| 4581 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4582 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4583 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4584 | gfx::PointF(2.f, 2.f), |
| 4585 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4586 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4587 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4588 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4589 | scoped_refptr<ContentLayer> child_empty = |
| 4590 | CreateDrawableContentLayer(&delegate); |
| 4591 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4592 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4593 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4594 | gfx::PointF(2.f, 2.f), |
| 4595 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4596 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4597 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4598 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4599 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4600 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4601 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4602 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4603 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4604 | gfx::PointF(12.f, 12.f), |
| 4605 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4606 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4607 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4608 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4609 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4610 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4611 | parent->AddChild(child_scale); |
| 4612 | parent->AddChild(child_empty); |
| 4613 | parent->AddChild(child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4614 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4615 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4616 | host->SetRootLayer(root); |
| 4617 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4618 | float device_scale_factor = 2.5f; |
| 4619 | float page_scale_factor = 1.f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4620 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4621 | { |
| 4622 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4623 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4624 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4625 | inputs.device_scale_factor = device_scale_factor; |
| 4626 | inputs.page_scale_factor = page_scale_factor; |
| 4627 | inputs.page_scale_application_layer = root.get(); |
| 4628 | inputs.can_adjust_raster_scales = true; |
| 4629 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4630 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4631 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4632 | initial_parent_scale, parent); |
| 4633 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4634 | initial_parent_scale * initial_child_scale, |
| 4635 | child_scale); |
| 4636 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4637 | initial_parent_scale * initial_child_scale, |
| 4638 | child_empty); |
| 4639 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4640 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4641 | // The parent is scaled up and shouldn't need to scale during draw. The |
| 4642 | // child that can scale its contents should also not need to scale during |
| 4643 | // draw. This shouldn't change if the child has empty bounds. The other |
| 4644 | // children should. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4645 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 4646 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
| 4647 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0)); |
| 4648 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1)); |
| 4649 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0)); |
| 4650 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4651 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 4652 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4653 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4654 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4655 | initial_parent_scale * initial_child_scale, |
| 4656 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4657 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4658 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4659 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 4660 | // updated using the initial transform as the raster scale. |
| 4661 | device_scale_factor = 2.25f; |
| 4662 | page_scale_factor = 1.25f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4663 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4664 | { |
| 4665 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4666 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4667 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4668 | inputs.device_scale_factor = device_scale_factor; |
| 4669 | inputs.page_scale_factor = page_scale_factor; |
| 4670 | inputs.page_scale_application_layer = root.get(); |
| 4671 | inputs.can_adjust_raster_scales = true; |
| 4672 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 4673 | |
| 4674 | EXPECT_CONTENTS_SCALE_EQ( |
| 4675 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4676 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4677 | initial_parent_scale * initial_child_scale, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4678 | child_scale); |
| 4679 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4680 | initial_parent_scale * initial_child_scale, |
| 4681 | child_empty); |
| 4682 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4683 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4684 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4685 | // 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] | 4686 | SkMScalar second_child_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4687 | child_scale_matrix.Scale(second_child_scale / initial_child_scale, |
| 4688 | second_child_scale / initial_child_scale); |
| 4689 | child_scale->SetTransform(child_scale_matrix); |
| 4690 | child_empty->SetTransform(child_scale_matrix); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4691 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4692 | { |
| 4693 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4694 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4695 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4696 | inputs.device_scale_factor = device_scale_factor; |
| 4697 | inputs.page_scale_factor = page_scale_factor; |
| 4698 | inputs.page_scale_application_layer = root.get(); |
| 4699 | inputs.can_adjust_raster_scales = true; |
| 4700 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4701 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4702 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4703 | initial_parent_scale, |
| 4704 | parent); |
| 4705 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4706 | child_scale); |
| 4707 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4708 | child_empty); |
| 4709 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4710 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4711 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4712 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 4713 | // updated, but still using 1.0 as the raster scale. |
| 4714 | device_scale_factor = 2.75f; |
| 4715 | page_scale_factor = 1.75f; |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4716 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4717 | { |
| 4718 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4719 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4720 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4721 | inputs.device_scale_factor = device_scale_factor; |
| 4722 | inputs.page_scale_factor = page_scale_factor; |
| 4723 | inputs.page_scale_application_layer = root.get(); |
| 4724 | inputs.can_adjust_raster_scales = true; |
| 4725 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4726 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4727 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4728 | initial_parent_scale, |
| 4729 | parent); |
| 4730 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4731 | child_scale); |
| 4732 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4733 | child_empty); |
| 4734 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4735 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4736 | } |
| 4737 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4738 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4739 | TEST_F(LayerTreeHostCommonTest, |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4740 | ContentsScale_LayerTransformsDontAffectContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4741 | MockContentLayerClient delegate; |
| 4742 | gfx::Transform identity_matrix; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4743 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4744 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4745 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4746 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4747 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4748 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4749 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4750 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4751 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4752 | scoped_refptr<Layer> root = Layer::Create(); |
| 4753 | root->SetBounds(gfx::Size(100, 100)); |
| 4754 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4755 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4756 | SetLayerPropertiesForTesting(parent.get(), |
| 4757 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4758 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4759 | gfx::PointF(), |
| 4760 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4761 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4762 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4763 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4764 | scoped_refptr<ContentLayer> child_scale = |
| 4765 | CreateDrawableContentLayer(&delegate); |
| 4766 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4767 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4768 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4769 | gfx::PointF(2.f, 2.f), |
| 4770 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4771 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4772 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4773 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4774 | scoped_refptr<ContentLayer> child_empty = |
| 4775 | CreateDrawableContentLayer(&delegate); |
| 4776 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4777 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4778 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4779 | gfx::PointF(2.f, 2.f), |
| 4780 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4781 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4782 | true); |
| 4783 | |
| 4784 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4785 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4786 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4787 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4788 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4789 | gfx::PointF(12.f, 12.f), |
| 4790 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4791 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4792 | true); |
| 4793 | |
| 4794 | root->AddChild(parent); |
| 4795 | |
| 4796 | parent->AddChild(child_scale); |
| 4797 | parent->AddChild(child_empty); |
| 4798 | parent->AddChild(child_no_scale); |
| 4799 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4800 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4801 | host->SetRootLayer(root); |
| 4802 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4803 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4804 | |
| 4805 | float device_scale_factor = 2.5f; |
| 4806 | float page_scale_factor = 1.f; |
| 4807 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4808 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4809 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4810 | inputs.device_scale_factor = device_scale_factor; |
| 4811 | inputs.page_scale_factor = page_scale_factor; |
| 4812 | inputs.page_scale_application_layer = root.get(), |
| 4813 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4814 | |
| 4815 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4816 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4817 | child_scale); |
| 4818 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4819 | child_empty); |
| 4820 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4821 | |
| 4822 | // Since the transform scale does not affect contents scale, it should affect |
| 4823 | // the draw transform instead. |
| 4824 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4825 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4826 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4827 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4828 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4829 | child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4830 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4831 | child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4832 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4833 | child_empty->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4834 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4835 | child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4836 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4837 | initial_parent_scale * initial_child_scale, |
| 4838 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4839 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4840 | initial_parent_scale * initial_child_scale, |
| 4841 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4842 | } |
| 4843 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4844 | TEST_F(LayerTreeHostCommonTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4845 | MockContentLayerClient delegate; |
| 4846 | gfx::Transform identity_matrix; |
| 4847 | |
| 4848 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4849 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4850 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4851 | |
| 4852 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4853 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4854 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4855 | |
| 4856 | scoped_refptr<Layer> root = Layer::Create(); |
| 4857 | root->SetBounds(gfx::Size(100, 100)); |
| 4858 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4859 | scoped_refptr<FakePictureLayer> parent = |
| 4860 | CreateDrawablePictureLayer(&delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4861 | SetLayerPropertiesForTesting(parent.get(), |
| 4862 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4863 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4864 | gfx::PointF(), |
| 4865 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4866 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4867 | true); |
| 4868 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4869 | scoped_refptr<FakePictureLayer> child_scale = |
| 4870 | CreateDrawablePictureLayer(&delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4871 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4872 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4873 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4874 | gfx::PointF(2.f, 2.f), |
| 4875 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4876 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4877 | true); |
| 4878 | |
| 4879 | root->AddChild(parent); |
| 4880 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4881 | parent->AddChild(child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4882 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4883 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4884 | host->SetRootLayer(root); |
| 4885 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4886 | float device_scale_factor = 2.5f; |
| 4887 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4888 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4889 | { |
| 4890 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4891 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4892 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4893 | inputs.device_scale_factor = device_scale_factor; |
| 4894 | inputs.page_scale_factor = page_scale_factor; |
| 4895 | inputs.page_scale_application_layer = root.get(); |
| 4896 | inputs.can_adjust_raster_scales = true; |
| 4897 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4898 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4899 | // The ideal scale is able to go below 1. |
| 4900 | float expected_ideal_scale = |
| 4901 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4902 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4903 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4904 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4905 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4906 | initial_parent_scale * initial_child_scale; |
| 4907 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4908 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4909 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4910 | } |
| 4911 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4912 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4913 | MockContentLayerClient delegate; |
| 4914 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4915 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4916 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4917 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4918 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4919 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4920 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4921 | SkMScalar initial_child_scale = 3.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4922 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4923 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4924 | scoped_refptr<Layer> root = Layer::Create(); |
| 4925 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4926 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4927 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4928 | SetLayerPropertiesForTesting(parent.get(), |
| 4929 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4930 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4931 | gfx::PointF(), |
| 4932 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4933 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4934 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4935 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4936 | scoped_refptr<ContentLayer> surface_scale = |
| 4937 | CreateDrawableContentLayer(&delegate); |
| 4938 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 4939 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4940 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4941 | gfx::PointF(2.f, 2.f), |
| 4942 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4943 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4944 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4945 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4946 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 4947 | CreateDrawableContentLayer(&delegate); |
| 4948 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 4949 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4950 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4951 | gfx::PointF(), |
| 4952 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4953 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4954 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4955 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4956 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 4957 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4958 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 4959 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4960 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4961 | gfx::PointF(), |
| 4962 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4963 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4964 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4965 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4966 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 4967 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4968 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 4969 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4970 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4971 | gfx::PointF(12.f, 12.f), |
| 4972 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4973 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4974 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4975 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4976 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 4977 | CreateDrawableContentLayer(&delegate); |
| 4978 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 4979 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4980 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4981 | gfx::PointF(), |
| 4982 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4983 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4984 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4985 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4986 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 4987 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4988 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 4989 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4990 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4991 | gfx::PointF(), |
| 4992 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4993 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4994 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4995 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4996 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4997 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4998 | parent->AddChild(surface_scale); |
| 4999 | parent->AddChild(surface_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5000 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5001 | surface_scale->SetForceRenderSurface(true); |
| 5002 | surface_scale->AddChild(surface_scale_child_scale); |
| 5003 | surface_scale->AddChild(surface_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5004 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5005 | surface_no_scale->SetForceRenderSurface(true); |
| 5006 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 5007 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5008 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5009 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5010 | host->SetRootLayer(root); |
| 5011 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5012 | SkMScalar device_scale_factor = 5; |
| 5013 | SkMScalar page_scale_factor = 7; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5014 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5015 | RenderSurfaceLayerList render_surface_layer_list; |
| 5016 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5017 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5018 | inputs.device_scale_factor = device_scale_factor; |
| 5019 | inputs.page_scale_factor = page_scale_factor; |
| 5020 | inputs.page_scale_application_layer = root.get(); |
| 5021 | inputs.can_adjust_raster_scales = true; |
| 5022 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5023 | |
| 5024 | EXPECT_CONTENTS_SCALE_EQ( |
| 5025 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5026 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5027 | initial_parent_scale * initial_child_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5028 | surface_scale); |
| 5029 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale); |
| 5030 | EXPECT_CONTENTS_SCALE_EQ( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5031 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5032 | initial_child_scale * initial_child_scale, |
| 5033 | surface_scale_child_scale); |
| 5034 | EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale); |
| 5035 | EXPECT_CONTENTS_SCALE_EQ( |
| 5036 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5037 | initial_child_scale * initial_child_scale, |
| 5038 | surface_no_scale_child_scale); |
| 5039 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5040 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5041 | // The parent is scaled up and shouldn't need to scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5042 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 5043 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5044 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5045 | // RenderSurfaces should always be 1:1 with their target. |
| 5046 | EXPECT_FLOAT_EQ( |
| 5047 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5048 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5049 | EXPECT_FLOAT_EQ( |
| 5050 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5051 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5052 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5053 | // The surface_scale can apply contents scale so the layer shouldn't need to |
| 5054 | // scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5055 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 5056 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5057 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5058 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 5059 | // to scale during draw. |
| 5060 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5061 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5062 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5063 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5064 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5065 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 5066 | // to be scaled during draw. |
| 5067 | EXPECT_FLOAT_EQ( |
| 5068 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5069 | initial_child_scale * initial_child_scale, |
| 5070 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5071 | EXPECT_FLOAT_EQ( |
| 5072 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5073 | initial_child_scale * initial_child_scale, |
| 5074 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5075 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5076 | // RenderSurfaces should always be 1:1 with their target. |
| 5077 | EXPECT_FLOAT_EQ( |
| 5078 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5079 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5080 | EXPECT_FLOAT_EQ( |
| 5081 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5082 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5083 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5084 | // The surface_no_scale layer can not apply contents scale, so it needs to be |
| 5085 | // scaled during draw. |
| 5086 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5087 | initial_parent_scale * initial_child_scale, |
| 5088 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5089 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5090 | initial_parent_scale * initial_child_scale, |
| 5091 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5092 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5093 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 5094 | // to scale during draw. |
| 5095 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5096 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5097 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5098 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5099 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5100 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 5101 | // to be scaled during draw. |
| 5102 | EXPECT_FLOAT_EQ( |
| 5103 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5104 | initial_child_scale * initial_child_scale, |
| 5105 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5106 | EXPECT_FLOAT_EQ( |
| 5107 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5108 | initial_child_scale * initial_child_scale, |
| 5109 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5110 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5111 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5112 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5113 | TEST_F(LayerTreeHostCommonTest, |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5114 | ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5115 | MockContentLayerClient delegate; |
| 5116 | gfx::Transform identity_matrix; |
| 5117 | |
| 5118 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5119 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5120 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 5121 | |
| 5122 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5123 | SkMScalar initial_child_scale = 3.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5124 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 5125 | |
| 5126 | scoped_refptr<Layer> root = Layer::Create(); |
| 5127 | root->SetBounds(gfx::Size(100, 100)); |
| 5128 | |
| 5129 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 5130 | SetLayerPropertiesForTesting(parent.get(), |
| 5131 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5132 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5133 | gfx::PointF(), |
| 5134 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5135 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5136 | true); |
| 5137 | |
| 5138 | scoped_refptr<ContentLayer> surface_scale = |
| 5139 | CreateDrawableContentLayer(&delegate); |
| 5140 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 5141 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5142 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5143 | gfx::PointF(2.f, 2.f), |
| 5144 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5145 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5146 | true); |
| 5147 | |
| 5148 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 5149 | CreateDrawableContentLayer(&delegate); |
| 5150 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 5151 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5152 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5153 | gfx::PointF(), |
| 5154 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5155 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5156 | true); |
| 5157 | |
| 5158 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 5159 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5160 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 5161 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5162 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5163 | gfx::PointF(), |
| 5164 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5165 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5166 | true); |
| 5167 | |
| 5168 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 5169 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5170 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 5171 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5172 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5173 | gfx::PointF(12.f, 12.f), |
| 5174 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5175 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5176 | true); |
| 5177 | |
| 5178 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 5179 | CreateDrawableContentLayer(&delegate); |
| 5180 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 5181 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5182 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5183 | gfx::PointF(), |
| 5184 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5185 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5186 | true); |
| 5187 | |
| 5188 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 5189 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5190 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 5191 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5192 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5193 | gfx::PointF(), |
| 5194 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5195 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5196 | true); |
| 5197 | |
| 5198 | root->AddChild(parent); |
| 5199 | |
| 5200 | parent->AddChild(surface_scale); |
| 5201 | parent->AddChild(surface_no_scale); |
| 5202 | |
| 5203 | surface_scale->SetForceRenderSurface(true); |
| 5204 | surface_scale->AddChild(surface_scale_child_scale); |
| 5205 | surface_scale->AddChild(surface_scale_child_no_scale); |
| 5206 | |
| 5207 | surface_no_scale->SetForceRenderSurface(true); |
| 5208 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 5209 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
| 5210 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5211 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5212 | host->SetRootLayer(root); |
| 5213 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5214 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5215 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5216 | SkMScalar device_scale_factor = 5.0; |
| 5217 | SkMScalar page_scale_factor = 7.0; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5218 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5219 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5220 | inputs.device_scale_factor = device_scale_factor; |
| 5221 | inputs.page_scale_factor = page_scale_factor; |
| 5222 | inputs.page_scale_application_layer = root.get(); |
| 5223 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5224 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5225 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5226 | parent); |
| 5227 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5228 | surface_scale); |
| 5229 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale); |
| 5230 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5231 | surface_scale_child_scale); |
| 5232 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale); |
| 5233 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5234 | surface_no_scale_child_scale); |
| 5235 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale); |
| 5236 | |
| 5237 | // The parent is scaled up during draw, since its contents are not scaled by |
| 5238 | // the transform hierarchy. |
| 5239 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5240 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5241 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5242 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5243 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5244 | // 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] | 5245 | // by the transform hierarchy. |
| 5246 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5247 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5248 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5249 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5250 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5251 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5252 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5253 | // The surface_scale's RenderSurface is not scaled during draw, so the layer |
| 5254 | // needs to be scaled when drawing into its surface. |
| 5255 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 5256 | surface_scale->draw_transform().matrix().get(0, 0)); |
| 5257 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 5258 | surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5259 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5260 | // The surface_scale_child_scale is not scaled when drawing into its surface, |
| 5261 | // since its content bounds are scaled by the transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5262 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5263 | initial_child_scale * initial_child_scale * initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5264 | surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5265 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5266 | initial_child_scale * initial_child_scale * initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5267 | surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5268 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5269 | // The surface_scale_child_no_scale is scaled by the device scale, page scale |
| 5270 | // and transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5271 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5272 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5273 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5274 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5275 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5276 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5277 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5278 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5279 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5280 | // 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] | 5281 | // by the transform hierarchy. |
| 5282 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5283 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5284 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5285 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5286 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5287 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5288 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5289 | // The surface_no_scale layer has a fixed contents scale of 1, so it needs to |
| 5290 | // be scaled by the device and page scale factors. Its surface is already |
| 5291 | // scaled by the transform hierarchy so those don't need to scale the layer's |
| 5292 | // drawing. |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5293 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale * |
| 5294 | device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5295 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5296 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale * |
| 5297 | device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5298 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5299 | |
| 5300 | // The surface_no_scale_child_scale has its contents scaled by the page and |
| 5301 | // device scale factors, but needs to be scaled by the transform hierarchy |
| 5302 | // when drawing. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5303 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5304 | initial_parent_scale * initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5305 | surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5306 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5307 | initial_parent_scale * initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5308 | surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5309 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5310 | // The surface_no_scale_child_no_scale needs to be scaled by the device and |
| 5311 | // page scale factors and by any transform heirarchy below its target surface. |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5312 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5313 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5314 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5315 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5316 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5317 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5318 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5319 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5320 | } |
| 5321 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5322 | TEST_F(LayerTreeHostCommonTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5323 | MockContentLayerClient delegate; |
| 5324 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5325 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5326 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5327 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5328 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5329 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5330 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5331 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5332 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5333 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5334 | scoped_refptr<Layer> root = Layer::Create(); |
| 5335 | root->SetBounds(gfx::Size(100, 100)); |
| 5336 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5337 | scoped_refptr<FakePictureLayer> parent = |
| 5338 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5339 | SetLayerPropertiesForTesting(parent.get(), |
| 5340 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5341 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5342 | gfx::PointF(), |
| 5343 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5344 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5345 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5346 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5347 | scoped_refptr<FakePictureLayer> child_scale = |
| 5348 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5349 | SetLayerPropertiesForTesting(child_scale.get(), |
| 5350 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5351 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5352 | gfx::PointF(2.f, 2.f), |
| 5353 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5354 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5355 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5356 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5357 | root->AddChild(parent); |
| 5358 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5359 | parent->AddChild(child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5360 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5361 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5362 | host->SetRootLayer(root); |
| 5363 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5364 | { |
| 5365 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5366 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5367 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5368 | inputs.can_adjust_raster_scales = true; |
| 5369 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5370 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5371 | EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); |
| 5372 | // Animating layers compute ideal scale in the same way as when |
| 5373 | // they are static. |
| 5374 | EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, |
| 5375 | child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5376 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5377 | } |
| 5378 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5379 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5380 | TEST_F(LayerTreeHostCommonTest, |
| 5381 | ChangeInContentBoundsOrScaleTriggersPushProperties) { |
| 5382 | MockContentLayerClient delegate; |
| 5383 | scoped_refptr<Layer> root = Layer::Create(); |
| 5384 | scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate); |
| 5385 | root->AddChild(child); |
| 5386 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5387 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5388 | host->SetRootLayer(root); |
| 5389 | |
| 5390 | gfx::Transform identity_matrix; |
| 5391 | SetLayerPropertiesForTesting(root.get(), |
| 5392 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5393 | gfx::Point3F(), |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5394 | gfx::PointF(), |
| 5395 | gfx::Size(100, 100), |
| 5396 | true, |
| 5397 | false); |
| 5398 | SetLayerPropertiesForTesting(child.get(), |
| 5399 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5400 | gfx::Point3F(), |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5401 | gfx::PointF(), |
| 5402 | gfx::Size(100, 100), |
| 5403 | true, |
| 5404 | false); |
| 5405 | |
| 5406 | root->reset_needs_push_properties_for_testing(); |
| 5407 | child->reset_needs_push_properties_for_testing(); |
| 5408 | |
| 5409 | // This will change both layers' content bounds. |
| 5410 | ExecuteCalculateDrawProperties(root.get()); |
| 5411 | EXPECT_TRUE(root->needs_push_properties()); |
| 5412 | EXPECT_TRUE(child->needs_push_properties()); |
| 5413 | |
| 5414 | root->reset_needs_push_properties_for_testing(); |
| 5415 | child->reset_needs_push_properties_for_testing(); |
| 5416 | |
| 5417 | // This will change only the child layer's contents scale and content bounds, |
| 5418 | // since the root layer is not a ContentsScalingLayer. |
| 5419 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 5420 | EXPECT_FALSE(root->needs_push_properties()); |
| 5421 | EXPECT_TRUE(child->needs_push_properties()); |
| 5422 | |
| 5423 | root->reset_needs_push_properties_for_testing(); |
| 5424 | child->reset_needs_push_properties_for_testing(); |
| 5425 | |
| 5426 | // This will not change either layer's contents scale or content bounds. |
| 5427 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 5428 | EXPECT_FALSE(root->needs_push_properties()); |
| 5429 | EXPECT_FALSE(child->needs_push_properties()); |
| 5430 | } |
| 5431 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5432 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5433 | MockContentLayerClient delegate; |
| 5434 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5435 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5436 | scoped_refptr<FakePictureLayer> parent = |
| 5437 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5438 | SetLayerPropertiesForTesting(parent.get(), |
| 5439 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5440 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5441 | gfx::PointF(), |
| 5442 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5443 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5444 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5445 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5446 | scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5447 | SetLayerPropertiesForTesting(child.get(), |
| 5448 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5449 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5450 | gfx::PointF(2.f, 2.f), |
| 5451 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5452 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5453 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5454 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5455 | gfx::Transform replica_transform; |
| 5456 | replica_transform.Scale(1.0, -1.0); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5457 | scoped_refptr<FakePictureLayer> replica = |
| 5458 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5459 | SetLayerPropertiesForTesting(replica.get(), |
| 5460 | replica_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5461 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5462 | gfx::PointF(2.f, 2.f), |
| 5463 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5464 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5465 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5466 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5467 | // This layer should end up in the same surface as child, with the same draw |
| 5468 | // and screen space transforms. |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5469 | scoped_refptr<FakePictureLayer> duplicate_child_non_owner = |
| 5470 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5471 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 5472 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5473 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5474 | gfx::PointF(), |
| 5475 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5476 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5477 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5478 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5479 | parent->AddChild(child); |
| 5480 | child->AddChild(duplicate_child_non_owner); |
| 5481 | child->SetReplicaLayer(replica.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5482 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5483 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5484 | host->SetRootLayer(parent); |
| 5485 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5486 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5487 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5488 | float device_scale_factor = 1.5f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5489 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5490 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5491 | inputs.device_scale_factor = device_scale_factor; |
| 5492 | inputs.can_adjust_raster_scales = true; |
| 5493 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5494 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5495 | // We should have two render surfaces. The root's render surface and child's |
| 5496 | // render surface (it needs one because it has a replica layer). |
| 5497 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5498 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5499 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5500 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5501 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5502 | parent->screen_space_transform()); |
| 5503 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5504 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5505 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5506 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5507 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5508 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
| 5509 | child->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5510 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5511 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5512 | expected_screen_space_transform.Scale(device_scale_factor, |
| 5513 | device_scale_factor); |
| 5514 | expected_screen_space_transform.Translate(child->position().x(), |
| 5515 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5516 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 5517 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5518 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5519 | gfx::Transform expected_duplicate_child_draw_transform = |
| 5520 | child->draw_transform(); |
| 5521 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), |
| 5522 | duplicate_child_non_owner->draw_transform()); |
| 5523 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5524 | child->screen_space_transform(), |
| 5525 | duplicate_child_non_owner->screen_space_transform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 5526 | EXPECT_EQ(child->drawable_content_rect(), |
| 5527 | duplicate_child_non_owner->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5528 | EXPECT_EQ(child->content_bounds(), |
| 5529 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5530 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5531 | gfx::Transform expected_render_surface_draw_transform; |
| 5532 | expected_render_surface_draw_transform.Translate( |
| 5533 | device_scale_factor * child->position().x(), |
| 5534 | device_scale_factor * child->position().y()); |
| 5535 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 5536 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5537 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5538 | gfx::Transform expected_surface_draw_transform; |
| 5539 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 5540 | device_scale_factor * 2.f); |
| 5541 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 5542 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5543 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5544 | gfx::Transform expected_surface_screen_space_transform; |
| 5545 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 5546 | device_scale_factor * 2.f); |
| 5547 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5548 | expected_surface_screen_space_transform, |
| 5549 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5550 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5551 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5552 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 5553 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 5554 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5555 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5556 | expected_replica_draw_transform, |
| 5557 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5558 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5559 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5560 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 5561 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 5562 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5563 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5564 | expected_replica_screen_space_transform, |
| 5565 | child->render_surface()->replica_screen_space_transform()); |
| 5566 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5567 | expected_replica_screen_space_transform, |
| 5568 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5569 | } |
| 5570 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5571 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5572 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
| 5573 | MockContentLayerClient delegate; |
| 5574 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5575 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5576 | scoped_refptr<FakePictureLayer> parent = |
| 5577 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5578 | SetLayerPropertiesForTesting(parent.get(), |
| 5579 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5580 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5581 | gfx::PointF(), |
| 5582 | gfx::Size(33, 31), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5583 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5584 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5585 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5586 | scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5587 | SetLayerPropertiesForTesting(child.get(), |
| 5588 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5589 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5590 | gfx::PointF(), |
| 5591 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5592 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5593 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5594 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5595 | gfx::Transform replica_transform; |
| 5596 | replica_transform.Scale(1.0, -1.0); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5597 | scoped_refptr<FakePictureLayer> replica = |
| 5598 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5599 | SetLayerPropertiesForTesting(replica.get(), |
| 5600 | replica_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5601 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5602 | gfx::PointF(), |
| 5603 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5604 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5605 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5606 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5607 | parent->AddChild(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5608 | child->SetReplicaLayer(replica.get()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5609 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5610 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5611 | host->SetRootLayer(parent); |
| 5612 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 5613 | float device_scale_factor = 1.7f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5614 | |
| 5615 | RenderSurfaceLayerList render_surface_layer_list; |
| 5616 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5617 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5618 | inputs.device_scale_factor = device_scale_factor; |
| 5619 | inputs.can_adjust_raster_scales = true; |
| 5620 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5621 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5622 | // We should have two render surfaces. The root's render surface and child's |
| 5623 | // render surface (it needs one because it has a replica layer). |
| 5624 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5625 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5626 | gfx::Transform identity_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5627 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5628 | child->render_surface()->draw_transform()); |
| 5629 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5630 | child->render_surface()->draw_transform()); |
| 5631 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5632 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5633 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5634 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5635 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5636 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5637 | expected_replica_draw_transform, |
| 5638 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5639 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5640 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5641 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5642 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5643 | expected_replica_screen_space_transform, |
| 5644 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5645 | } |
| 5646 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5647 | TEST_F(LayerTreeHostCommonTest, SubtreeSearch) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5648 | scoped_refptr<Layer> root = Layer::Create(); |
| 5649 | scoped_refptr<Layer> child = Layer::Create(); |
| 5650 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5651 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 5652 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5653 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5654 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 5655 | child->AddChild(grand_child.get()); |
| 5656 | child->SetMaskLayer(mask_layer.get()); |
| 5657 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5658 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5659 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5660 | host->SetRootLayer(root); |
| 5661 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5662 | int nonexistent_id = -1; |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5663 | EXPECT_EQ(root.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5664 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id())); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5665 | EXPECT_EQ(child.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5666 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id())); |
| 5667 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5668 | grand_child.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5669 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id())); |
| 5670 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5671 | mask_layer.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5672 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id())); |
| 5673 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5674 | replica_layer.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5675 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id())); |
| 5676 | EXPECT_EQ( |
| 5677 | 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5678 | } |
| 5679 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5680 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5681 | scoped_refptr<Layer> root = Layer::Create(); |
| 5682 | scoped_refptr<Layer> child = Layer::Create(); |
| 5683 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 5684 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5685 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5686 | const gfx::Transform identity_matrix; |
| 5687 | SetLayerPropertiesForTesting(root.get(), |
| 5688 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5689 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5690 | gfx::PointF(), |
| 5691 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5692 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5693 | false); |
| 5694 | SetLayerPropertiesForTesting(child.get(), |
| 5695 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5696 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5697 | gfx::PointF(), |
| 5698 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5699 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5700 | false); |
| 5701 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5702 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5703 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5704 | gfx::PointF(), |
| 5705 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5706 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5707 | false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5708 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5709 | root->AddChild(child); |
| 5710 | child->AddChild(grand_child); |
| 5711 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5712 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5713 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5714 | host->SetRootLayer(root); |
| 5715 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5716 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5717 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5718 | EXPECT_FALSE(child->render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5719 | } |
| 5720 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5721 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5722 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5723 | TestSharedBitmapManager shared_bitmap_manager; |
| 5724 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5725 | host_impl.CreatePendingTree(); |
| 5726 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5727 | |
| 5728 | const gfx::Transform identity_matrix; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5729 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5730 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5731 | false); |
| 5732 | root->SetDrawsContent(true); |
| 5733 | |
| 5734 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5735 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5736 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5737 | false); |
| 5738 | child->SetDrawsContent(true); |
| 5739 | child->SetOpacity(0.0f); |
| 5740 | |
| 5741 | // Add opacity animation. |
| 5742 | AddOpacityTransitionToController( |
| 5743 | child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false); |
| 5744 | |
| 5745 | root->AddChild(child.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5746 | root->SetHasRenderSurface(true); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5747 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5748 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5749 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5750 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5751 | inputs.can_adjust_raster_scales = true; |
| 5752 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5753 | |
| 5754 | // We should have one render surface and two layers. The child |
| 5755 | // layer should be included even though it is transparent. |
| 5756 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5757 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 5758 | } |
| 5759 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5760 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5761 | class LCDTextTest |
| 5762 | : public LayerTreeHostCommonTestBase, |
| 5763 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5764 | public: |
| 5765 | LCDTextTest() |
| 5766 | : host_impl_(&proxy_, &shared_bitmap_manager_), |
| 5767 | root_(nullptr), |
| 5768 | child_(nullptr), |
| 5769 | grand_child_(nullptr) {} |
| 5770 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5771 | protected: |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 5772 | void SetUp() override { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5773 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5774 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5775 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5776 | scoped_ptr<LayerImpl> root_ptr = |
| 5777 | LayerImpl::Create(host_impl_.active_tree(), 1); |
| 5778 | scoped_ptr<LayerImpl> child_ptr = |
| 5779 | LayerImpl::Create(host_impl_.active_tree(), 2); |
| 5780 | scoped_ptr<LayerImpl> grand_child_ptr = |
| 5781 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 5782 | |
| 5783 | // Stash raw pointers to look at later. |
| 5784 | root_ = root_ptr.get(); |
| 5785 | child_ = child_ptr.get(); |
| 5786 | grand_child_ = grand_child_ptr.get(); |
| 5787 | |
| 5788 | child_->AddChild(grand_child_ptr.Pass()); |
| 5789 | root_->AddChild(child_ptr.Pass()); |
| 5790 | host_impl_.active_tree()->SetRootLayer(root_ptr.Pass()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5791 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5792 | root_->SetContentsOpaque(true); |
| 5793 | child_->SetContentsOpaque(true); |
| 5794 | grand_child_->SetContentsOpaque(true); |
| 5795 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5796 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5797 | SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(), |
| 5798 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5799 | true); |
| 5800 | SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(), |
| 5801 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5802 | std::tr1::get<2>(GetParam())); |
| 5803 | SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(), |
| 5804 | gfx::PointF(), gfx::Size(1, 1), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5805 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5806 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5807 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5808 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5809 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5810 | |
| 5811 | FakeImplProxy proxy_; |
| 5812 | TestSharedBitmapManager shared_bitmap_manager_; |
| 5813 | FakeLayerTreeHostImpl host_impl_; |
| 5814 | |
| 5815 | LayerImpl* root_; |
| 5816 | LayerImpl* child_; |
| 5817 | LayerImpl* grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5818 | }; |
| 5819 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5820 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5821 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5822 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5823 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5824 | // Case 1: Identity transform. |
| 5825 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5826 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5827 | layers_always_allowed_lcd_text_); |
| 5828 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5829 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5830 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5831 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5832 | // Case 2: Integral translation. |
| 5833 | gfx::Transform integral_translation; |
| 5834 | integral_translation.Translate(1.0, 2.0); |
| 5835 | child_->SetTransform(integral_translation); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5836 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5837 | layers_always_allowed_lcd_text_); |
| 5838 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5839 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5840 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5841 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5842 | // Case 3: Non-integral translation. |
| 5843 | gfx::Transform non_integral_translation; |
| 5844 | non_integral_translation.Translate(1.5, 2.5); |
| 5845 | child_->SetTransform(non_integral_translation); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5846 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5847 | layers_always_allowed_lcd_text_); |
| 5848 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5849 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5850 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5851 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5852 | // Case 4: Rotation. |
| 5853 | gfx::Transform rotation; |
| 5854 | rotation.Rotate(10.0); |
| 5855 | child_->SetTransform(rotation); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5856 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5857 | layers_always_allowed_lcd_text_); |
| 5858 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5859 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5860 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5861 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5862 | // Case 5: Scale. |
| 5863 | gfx::Transform scale; |
| 5864 | scale.Scale(2.0, 2.0); |
| 5865 | child_->SetTransform(scale); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5866 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5867 | layers_always_allowed_lcd_text_); |
| 5868 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5869 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5870 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5871 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5872 | // Case 6: Skew. |
| 5873 | gfx::Transform skew; |
| 5874 | skew.SkewX(10.0); |
| 5875 | child_->SetTransform(skew); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5876 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5877 | layers_always_allowed_lcd_text_); |
| 5878 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5879 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5880 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5881 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5882 | // Case 7: Translucent. |
| 5883 | child_->SetTransform(identity_matrix); |
| 5884 | child_->SetOpacity(0.5f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5885 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5886 | layers_always_allowed_lcd_text_); |
| 5887 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5888 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5889 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5890 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5891 | // Case 8: Sanity check: restore transform and opacity. |
| 5892 | child_->SetTransform(identity_matrix); |
| 5893 | child_->SetOpacity(1.f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5894 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5895 | layers_always_allowed_lcd_text_); |
| 5896 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5897 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5898 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5899 | |
| 5900 | // Case 9: Non-opaque content. |
| 5901 | child_->SetContentsOpaque(false); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5902 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5903 | layers_always_allowed_lcd_text_); |
| 5904 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5905 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5906 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
| 5907 | |
| 5908 | // Case 10: Sanity check: restore content opaqueness. |
| 5909 | child_->SetContentsOpaque(true); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5910 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5911 | layers_always_allowed_lcd_text_); |
| 5912 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5913 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5914 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5915 | } |
| 5916 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5917 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5918 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5919 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5920 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5921 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5922 | layers_always_allowed_lcd_text_); |
| 5923 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5924 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5925 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5926 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5927 | // Add opacity animation. |
| 5928 | child_->SetOpacity(0.9f); |
| 5929 | AddOpacityTransitionToController( |
| 5930 | child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5931 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5932 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5933 | layers_always_allowed_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5934 | // Text AA should not be adjusted while animation is active. |
| 5935 | // Make sure LCD text AA setting remains unchanged. |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5936 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5937 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5938 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5942 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5943 | testing::Combine(testing::Bool(), |
| 5944 | testing::Bool(), |
| 5945 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5946 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5947 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5948 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5949 | TestSharedBitmapManager shared_bitmap_manager; |
| 5950 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5951 | host_impl.CreatePendingTree(); |
| 5952 | const gfx::Transform identity_matrix; |
| 5953 | |
| 5954 | scoped_refptr<Layer> root = Layer::Create(); |
| 5955 | SetLayerPropertiesForTesting(root.get(), |
| 5956 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5957 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5958 | gfx::PointF(), |
| 5959 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5960 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5961 | false); |
| 5962 | root->SetIsDrawable(true); |
| 5963 | |
| 5964 | scoped_refptr<Layer> child = Layer::Create(); |
| 5965 | SetLayerPropertiesForTesting(child.get(), |
| 5966 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5967 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5968 | gfx::PointF(), |
| 5969 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5970 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5971 | false); |
| 5972 | child->SetIsDrawable(true); |
| 5973 | |
| 5974 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5975 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5976 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5977 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5978 | gfx::PointF(), |
| 5979 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5980 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5981 | false); |
| 5982 | grand_child->SetIsDrawable(true); |
| 5983 | grand_child->SetHideLayerAndSubtree(true); |
| 5984 | |
| 5985 | child->AddChild(grand_child); |
| 5986 | root->AddChild(child); |
| 5987 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5988 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5989 | host->SetRootLayer(root); |
| 5990 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5991 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5992 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5993 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5994 | inputs.can_adjust_raster_scales = true; |
| 5995 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5996 | |
| 5997 | // We should have one render surface and two layers. The grand child has |
| 5998 | // hidden itself. |
| 5999 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6000 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6001 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 6002 | EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6003 | } |
| 6004 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6005 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6006 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6007 | TestSharedBitmapManager shared_bitmap_manager; |
| 6008 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6009 | host_impl.CreatePendingTree(); |
| 6010 | const gfx::Transform identity_matrix; |
| 6011 | |
| 6012 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6013 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 6014 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6015 | false); |
| 6016 | root->SetDrawsContent(true); |
| 6017 | |
| 6018 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6019 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 6020 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6021 | false); |
| 6022 | child->SetDrawsContent(true); |
| 6023 | |
| 6024 | scoped_ptr<LayerImpl> grand_child = |
| 6025 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6026 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 6027 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6028 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6029 | grand_child->SetDrawsContent(true); |
| 6030 | grand_child->SetHideLayerAndSubtree(true); |
| 6031 | |
| 6032 | child->AddChild(grand_child.Pass()); |
| 6033 | root->AddChild(child.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6034 | root->SetHasRenderSurface(true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6035 | |
| 6036 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6037 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6038 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6039 | inputs.can_adjust_raster_scales = true; |
| 6040 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6041 | |
| 6042 | // We should have one render surface and two layers. The grand child has |
| 6043 | // hidden itself. |
| 6044 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6045 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6046 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
| 6047 | EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6048 | } |
| 6049 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6050 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6051 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6052 | TestSharedBitmapManager shared_bitmap_manager; |
| 6053 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6054 | host_impl.CreatePendingTree(); |
| 6055 | const gfx::Transform identity_matrix; |
| 6056 | |
| 6057 | scoped_refptr<Layer> root = Layer::Create(); |
| 6058 | SetLayerPropertiesForTesting(root.get(), |
| 6059 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6060 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6061 | gfx::PointF(), |
| 6062 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6063 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6064 | false); |
| 6065 | root->SetIsDrawable(true); |
| 6066 | |
| 6067 | scoped_refptr<Layer> child = Layer::Create(); |
| 6068 | SetLayerPropertiesForTesting(child.get(), |
| 6069 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6070 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6071 | gfx::PointF(), |
| 6072 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6073 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6074 | false); |
| 6075 | child->SetIsDrawable(true); |
| 6076 | child->SetHideLayerAndSubtree(true); |
| 6077 | |
| 6078 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 6079 | SetLayerPropertiesForTesting(grand_child.get(), |
| 6080 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6081 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6082 | gfx::PointF(), |
| 6083 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6084 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6085 | false); |
| 6086 | grand_child->SetIsDrawable(true); |
| 6087 | |
| 6088 | child->AddChild(grand_child); |
| 6089 | root->AddChild(child); |
| 6090 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6091 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6092 | host->SetRootLayer(root); |
| 6093 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6094 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6095 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6096 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6097 | inputs.can_adjust_raster_scales = true; |
| 6098 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6099 | |
| 6100 | // We should have one render surface and one layers. The child has |
| 6101 | // hidden itself and the grand child. |
| 6102 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6103 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6104 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6105 | } |
| 6106 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6107 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6108 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6109 | TestSharedBitmapManager shared_bitmap_manager; |
| 6110 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6111 | host_impl.CreatePendingTree(); |
| 6112 | const gfx::Transform identity_matrix; |
| 6113 | |
| 6114 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6115 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 6116 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6117 | true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6118 | root->SetDrawsContent(true); |
| 6119 | |
| 6120 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6121 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 6122 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6123 | false); |
| 6124 | child->SetDrawsContent(true); |
| 6125 | child->SetHideLayerAndSubtree(true); |
| 6126 | |
| 6127 | scoped_ptr<LayerImpl> grand_child = |
| 6128 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6129 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 6130 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6131 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6132 | grand_child->SetDrawsContent(true); |
| 6133 | |
| 6134 | child->AddChild(grand_child.Pass()); |
| 6135 | root->AddChild(child.Pass()); |
| 6136 | |
| 6137 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6138 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6139 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6140 | inputs.can_adjust_raster_scales = true; |
| 6141 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6142 | |
| 6143 | // We should have one render surface and one layers. The child has |
| 6144 | // hidden itself and the grand child. |
| 6145 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6146 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6147 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6148 | } |
| 6149 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6150 | void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 6151 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6152 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6153 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6154 | TestSharedBitmapManager shared_bitmap_manager; |
| 6155 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6156 | host_impl.CreatePendingTree(); |
| 6157 | const gfx::Transform identity_matrix; |
| 6158 | |
| 6159 | scoped_refptr<Layer> root = Layer::Create(); |
| 6160 | SetLayerPropertiesForTesting(root.get(), |
| 6161 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6162 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6163 | gfx::PointF(), |
| 6164 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6165 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6166 | false); |
| 6167 | root->SetIsDrawable(true); |
| 6168 | |
| 6169 | scoped_refptr<Layer> copy_grand_parent = Layer::Create(); |
| 6170 | SetLayerPropertiesForTesting(copy_grand_parent.get(), |
| 6171 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6172 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6173 | gfx::PointF(), |
| 6174 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6175 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6176 | false); |
| 6177 | copy_grand_parent->SetIsDrawable(true); |
| 6178 | |
| 6179 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 6180 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 6181 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6182 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6183 | gfx::PointF(), |
| 6184 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6185 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6186 | false); |
| 6187 | copy_parent->SetIsDrawable(true); |
| 6188 | copy_parent->SetForceRenderSurface(true); |
| 6189 | |
| 6190 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 6191 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 6192 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6193 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6194 | gfx::PointF(), |
| 6195 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6196 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6197 | false); |
| 6198 | copy_layer->SetIsDrawable(true); |
| 6199 | |
| 6200 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 6201 | SetLayerPropertiesForTesting(copy_child.get(), |
| 6202 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6203 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6204 | gfx::PointF(), |
| 6205 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6206 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6207 | false); |
| 6208 | copy_child->SetIsDrawable(true); |
| 6209 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6210 | scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create(); |
| 6211 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
| 6212 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6213 | gfx::Point3F(), |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6214 | gfx::PointF(), |
| 6215 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6216 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6217 | false); |
| 6218 | copy_grand_parent_sibling_before->SetIsDrawable(true); |
| 6219 | |
| 6220 | scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create(); |
| 6221 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
| 6222 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6223 | gfx::Point3F(), |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6224 | gfx::PointF(), |
| 6225 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6226 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6227 | false); |
| 6228 | copy_grand_parent_sibling_after->SetIsDrawable(true); |
| 6229 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6230 | copy_layer->AddChild(copy_child); |
| 6231 | copy_parent->AddChild(copy_layer); |
| 6232 | copy_grand_parent->AddChild(copy_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6233 | root->AddChild(copy_grand_parent_sibling_before); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6234 | root->AddChild(copy_grand_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6235 | root->AddChild(copy_grand_parent_sibling_after); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6236 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6237 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6238 | host->SetRootLayer(root); |
| 6239 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6240 | // Hide the copy_grand_parent and its subtree. But make a copy request in that |
| 6241 | // hidden subtree on copy_layer. |
| 6242 | copy_grand_parent->SetHideLayerAndSubtree(true); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6243 | copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true); |
| 6244 | copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6245 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 6246 | base::Bind(&EmptyCopyOutputCallback))); |
| 6247 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 6248 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6249 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6250 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6251 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6252 | inputs.can_adjust_raster_scales = true; |
| 6253 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6254 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6255 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request); |
| 6256 | EXPECT_TRUE(copy_grand_parent->draw_properties(). |
| 6257 | layer_or_descendant_has_copy_request); |
| 6258 | EXPECT_TRUE(copy_parent->draw_properties(). |
| 6259 | layer_or_descendant_has_copy_request); |
| 6260 | EXPECT_TRUE(copy_layer->draw_properties(). |
| 6261 | layer_or_descendant_has_copy_request); |
| 6262 | EXPECT_FALSE(copy_child->draw_properties(). |
| 6263 | layer_or_descendant_has_copy_request); |
| 6264 | EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties(). |
| 6265 | layer_or_descendant_has_copy_request); |
| 6266 | EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties(). |
| 6267 | layer_or_descendant_has_copy_request); |
| 6268 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6269 | // We should have three render surfaces, one for the root, one for the parent |
| 6270 | // since it owns a surface, and one for the copy_layer. |
| 6271 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6272 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 6273 | EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id()); |
| 6274 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6275 | |
| 6276 | // The root render surface should have 2 contributing layers. The |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6277 | // copy_grand_parent is hidden along with its siblings, but the copy_parent |
| 6278 | // will appear since something in its subtree needs to be drawn for a copy |
| 6279 | // request. |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6280 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6281 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 6282 | EXPECT_EQ(copy_parent->id(), |
| 6283 | root->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6284 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 6285 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6286 | // appear in its list, since it needs to be drawn for the copy request. |
| 6287 | ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size()); |
| 6288 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6289 | copy_parent->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6290 | |
| 6291 | // The copy_layer's render surface should have two contributing layers. |
| 6292 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 6293 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6294 | copy_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6295 | EXPECT_EQ(copy_child->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6296 | copy_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6297 | } |
| 6298 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6299 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6300 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6301 | TestSharedBitmapManager shared_bitmap_manager; |
| 6302 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6303 | host_impl.CreatePendingTree(); |
| 6304 | const gfx::Transform identity_matrix; |
| 6305 | |
| 6306 | scoped_refptr<Layer> root = Layer::Create(); |
| 6307 | SetLayerPropertiesForTesting(root.get(), |
| 6308 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6309 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6310 | gfx::PointF(), |
| 6311 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6312 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6313 | false); |
| 6314 | root->SetIsDrawable(true); |
| 6315 | |
| 6316 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 6317 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 6318 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6319 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6320 | gfx::PointF(), |
| 6321 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6322 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6323 | false); |
| 6324 | copy_parent->SetIsDrawable(true); |
| 6325 | copy_parent->SetMasksToBounds(true); |
| 6326 | |
| 6327 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 6328 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 6329 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6330 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6331 | gfx::PointF(), |
| 6332 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6333 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6334 | false); |
| 6335 | copy_layer->SetIsDrawable(true); |
| 6336 | |
| 6337 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 6338 | SetLayerPropertiesForTesting(copy_child.get(), |
| 6339 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6340 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6341 | gfx::PointF(), |
| 6342 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6343 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6344 | false); |
| 6345 | copy_child->SetIsDrawable(true); |
| 6346 | |
| 6347 | copy_layer->AddChild(copy_child); |
| 6348 | copy_parent->AddChild(copy_layer); |
| 6349 | root->AddChild(copy_parent); |
| 6350 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6351 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6352 | host->SetRootLayer(root); |
| 6353 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6354 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 6355 | base::Bind(&EmptyCopyOutputCallback))); |
| 6356 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 6357 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6358 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6359 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6360 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6361 | inputs.can_adjust_raster_scales = true; |
| 6362 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6363 | |
| 6364 | // We should have one render surface, as the others are clipped out. |
| 6365 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6366 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6367 | |
| 6368 | // The root render surface should only have 1 contributing layer, since the |
| 6369 | // other layers are empty/clipped away. |
| 6370 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6371 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6372 | } |
| 6373 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6374 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
| 6375 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6376 | TestSharedBitmapManager shared_bitmap_manager; |
| 6377 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6378 | host_impl.CreatePendingTree(); |
| 6379 | const gfx::Transform identity_matrix; |
| 6380 | |
| 6381 | scoped_refptr<Layer> root = Layer::Create(); |
| 6382 | SetLayerPropertiesForTesting(root.get(), |
| 6383 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6384 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6385 | gfx::PointF(), |
| 6386 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6387 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6388 | false); |
| 6389 | root->SetIsDrawable(true); |
| 6390 | |
| 6391 | // The surface is moved slightly outside of the viewport. |
| 6392 | scoped_refptr<Layer> surface = Layer::Create(); |
| 6393 | SetLayerPropertiesForTesting(surface.get(), |
| 6394 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6395 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6396 | gfx::PointF(-10, -20), |
| 6397 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6398 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6399 | false); |
| 6400 | surface->SetForceRenderSurface(true); |
| 6401 | |
| 6402 | scoped_refptr<Layer> surface_child = Layer::Create(); |
| 6403 | SetLayerPropertiesForTesting(surface_child.get(), |
| 6404 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6405 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6406 | gfx::PointF(), |
| 6407 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6408 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6409 | false); |
| 6410 | surface_child->SetIsDrawable(true); |
| 6411 | |
| 6412 | surface->AddChild(surface_child); |
| 6413 | root->AddChild(surface); |
| 6414 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6415 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6416 | host->SetRootLayer(root); |
| 6417 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6418 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6419 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6420 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6421 | inputs.can_adjust_raster_scales = true; |
| 6422 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6423 | |
| 6424 | // The visible_content_rect for the |surface_child| should not be clipped by |
| 6425 | // the viewport. |
| 6426 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 6427 | surface_child->visible_content_rect().ToString()); |
| 6428 | } |
| 6429 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6430 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 6431 | // Ensure that a transform between the layer and its render surface is not a |
| 6432 | // problem. Constructs the following layer tree. |
| 6433 | // |
| 6434 | // root (a render surface) |
| 6435 | // + render_surface |
| 6436 | // + clip_parent (scaled) |
| 6437 | // + intervening_clipping_layer |
| 6438 | // + clip_child |
| 6439 | // |
| 6440 | // The render surface should be resized correctly and the clip child should |
| 6441 | // inherit the right clip rect. |
| 6442 | scoped_refptr<Layer> root = Layer::Create(); |
| 6443 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 6444 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6445 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6446 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6447 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6448 | |
| 6449 | root->AddChild(render_surface); |
| 6450 | render_surface->AddChild(clip_parent); |
| 6451 | clip_parent->AddChild(intervening); |
| 6452 | intervening->AddChild(clip_child); |
| 6453 | |
| 6454 | clip_child->SetClipParent(clip_parent.get()); |
| 6455 | |
| 6456 | intervening->SetMasksToBounds(true); |
| 6457 | clip_parent->SetMasksToBounds(true); |
| 6458 | |
| 6459 | render_surface->SetForceRenderSurface(true); |
| 6460 | |
| 6461 | gfx::Transform scale_transform; |
| 6462 | scale_transform.Scale(2, 2); |
| 6463 | |
| 6464 | gfx::Transform identity_transform; |
| 6465 | |
| 6466 | SetLayerPropertiesForTesting(root.get(), |
| 6467 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6468 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6469 | gfx::PointF(), |
| 6470 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6471 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6472 | false); |
| 6473 | SetLayerPropertiesForTesting(render_surface.get(), |
| 6474 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6475 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6476 | gfx::PointF(), |
| 6477 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6478 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6479 | false); |
| 6480 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6481 | scale_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6482 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6483 | gfx::PointF(1.f, 1.f), |
| 6484 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6485 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6486 | false); |
| 6487 | SetLayerPropertiesForTesting(intervening.get(), |
| 6488 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6489 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6490 | gfx::PointF(1.f, 1.f), |
| 6491 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6492 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6493 | false); |
| 6494 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6495 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6496 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6497 | gfx::PointF(1.f, 1.f), |
| 6498 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6499 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6500 | false); |
| 6501 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6502 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6503 | host->SetRootLayer(root); |
| 6504 | |
| 6505 | ExecuteCalculateDrawProperties(root.get()); |
| 6506 | |
| 6507 | ASSERT_TRUE(root->render_surface()); |
| 6508 | ASSERT_TRUE(render_surface->render_surface()); |
| 6509 | |
| 6510 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 6511 | // by the intervening clip layer. |
| 6512 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
| 6513 | clip_parent->clip_rect().ToString()); |
| 6514 | ASSERT_EQ(clip_parent->clip_rect().ToString(), |
| 6515 | clip_child->clip_rect().ToString()); |
| 6516 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(), |
| 6517 | intervening->clip_rect().ToString()); |
| 6518 | |
| 6519 | // Ensure that the render surface reports a content rect that has been grown |
| 6520 | // to accomodate for the clip child. |
| 6521 | ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(), |
| 6522 | render_surface->render_surface()->content_rect().ToString()); |
| 6523 | |
| 6524 | // The above check implies the two below, but they nicely demonstrate that |
| 6525 | // we've grown, despite the intervening layer's clip. |
| 6526 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 6527 | render_surface->render_surface()->content_rect())); |
| 6528 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 6529 | render_surface->render_surface()->content_rect())); |
| 6530 | } |
| 6531 | |
| 6532 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 6533 | // Ensure that intervening render surfaces are not a problem in the basic |
| 6534 | // case. In the following tree, both render surfaces should be resized to |
| 6535 | // accomodate for the clip child, despite an intervening clip. |
| 6536 | // |
| 6537 | // root (a render surface) |
| 6538 | // + clip_parent (masks to bounds) |
| 6539 | // + render_surface1 (sets opacity) |
| 6540 | // + intervening (masks to bounds) |
| 6541 | // + render_surface2 (also sets opacity) |
| 6542 | // + clip_child |
| 6543 | // |
| 6544 | scoped_refptr<Layer> root = Layer::Create(); |
| 6545 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6546 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6547 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6548 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6549 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6550 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6551 | |
| 6552 | root->AddChild(clip_parent); |
| 6553 | clip_parent->AddChild(render_surface1); |
| 6554 | render_surface1->AddChild(intervening); |
| 6555 | intervening->AddChild(render_surface2); |
| 6556 | render_surface2->AddChild(clip_child); |
| 6557 | |
| 6558 | clip_child->SetClipParent(clip_parent.get()); |
| 6559 | |
| 6560 | intervening->SetMasksToBounds(true); |
| 6561 | clip_parent->SetMasksToBounds(true); |
| 6562 | |
| 6563 | render_surface1->SetForceRenderSurface(true); |
| 6564 | render_surface2->SetForceRenderSurface(true); |
| 6565 | |
| 6566 | gfx::Transform translation_transform; |
| 6567 | translation_transform.Translate(2, 2); |
| 6568 | |
| 6569 | gfx::Transform identity_transform; |
| 6570 | SetLayerPropertiesForTesting(root.get(), |
| 6571 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6572 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6573 | gfx::PointF(), |
| 6574 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6575 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6576 | false); |
| 6577 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6578 | translation_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6579 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6580 | gfx::PointF(1.f, 1.f), |
| 6581 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6582 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6583 | false); |
| 6584 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6585 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6586 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6587 | gfx::PointF(), |
| 6588 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6589 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6590 | false); |
| 6591 | SetLayerPropertiesForTesting(intervening.get(), |
| 6592 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6593 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6594 | gfx::PointF(1.f, 1.f), |
| 6595 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6596 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6597 | false); |
| 6598 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6599 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6600 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6601 | gfx::PointF(), |
| 6602 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6603 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6604 | false); |
| 6605 | SetLayerPropertiesForTesting(clip_child.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(-10.f, -10.f), |
| 6609 | gfx::Size(60, 60), |
[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 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6613 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6614 | host->SetRootLayer(root); |
| 6615 | |
| 6616 | ExecuteCalculateDrawProperties(root.get()); |
| 6617 | |
| 6618 | EXPECT_TRUE(root->render_surface()); |
| 6619 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6620 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6621 | |
| 6622 | // Since the render surfaces could have expanded, they should not clip (their |
| 6623 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6624 | // in this case. |
| 6625 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6626 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6627 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6628 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6629 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6630 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6631 | |
| 6632 | // NB: clip rects are in target space. |
| 6633 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6634 | render_surface1->clip_rect().ToString()); |
| 6635 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6636 | |
| 6637 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6638 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6639 | render_surface2->clip_rect().ToString()); |
| 6640 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6641 | |
| 6642 | // The content rects of both render surfaces should both have expanded to |
| 6643 | // contain the clip child. |
| 6644 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6645 | render_surface1->render_surface()->content_rect().ToString()); |
| 6646 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6647 | render_surface2->render_surface()->content_rect().ToString()); |
| 6648 | |
| 6649 | // The clip child should have inherited the clip parent's clip (projected to |
| 6650 | // the right space, of course), and should have the correctly sized visible |
| 6651 | // content rect. |
| 6652 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6653 | clip_child->clip_rect().ToString()); |
| 6654 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(), |
| 6655 | clip_child->visible_content_rect().ToString()); |
| 6656 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6657 | } |
| 6658 | |
| 6659 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 6660 | // Ensure that intervening render surfaces are not a problem, even if there |
| 6661 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 6662 | // of transform. |
| 6663 | // |
| 6664 | // root (a render surface) |
| 6665 | // + clip_parent (masks to bounds) |
| 6666 | // + render_surface1 (sets opacity) |
| 6667 | // + intervening (masks to bounds AND scrolls) |
| 6668 | // + render_surface2 (also sets opacity) |
| 6669 | // + clip_child |
| 6670 | // |
| 6671 | scoped_refptr<Layer> root = Layer::Create(); |
| 6672 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6673 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6674 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6675 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6676 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6677 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6678 | |
| 6679 | root->AddChild(clip_parent); |
| 6680 | clip_parent->AddChild(render_surface1); |
| 6681 | render_surface1->AddChild(intervening); |
| 6682 | intervening->AddChild(render_surface2); |
| 6683 | render_surface2->AddChild(clip_child); |
| 6684 | |
| 6685 | clip_child->SetClipParent(clip_parent.get()); |
| 6686 | |
| 6687 | intervening->SetMasksToBounds(true); |
| 6688 | clip_parent->SetMasksToBounds(true); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6689 | intervening->SetScrollClipLayerId(clip_parent->id()); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 6690 | intervening->SetScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6691 | |
| 6692 | render_surface1->SetForceRenderSurface(true); |
| 6693 | render_surface2->SetForceRenderSurface(true); |
| 6694 | |
| 6695 | gfx::Transform translation_transform; |
| 6696 | translation_transform.Translate(2, 2); |
| 6697 | |
| 6698 | gfx::Transform identity_transform; |
| 6699 | SetLayerPropertiesForTesting(root.get(), |
| 6700 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6701 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6702 | gfx::PointF(), |
| 6703 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6704 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6705 | false); |
| 6706 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6707 | translation_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6708 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6709 | gfx::PointF(1.f, 1.f), |
| 6710 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6711 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6712 | false); |
| 6713 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6714 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6715 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6716 | gfx::PointF(), |
| 6717 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6718 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6719 | false); |
| 6720 | SetLayerPropertiesForTesting(intervening.get(), |
| 6721 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6722 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6723 | gfx::PointF(1.f, 1.f), |
| 6724 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6725 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6726 | false); |
| 6727 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6728 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6729 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6730 | gfx::PointF(), |
| 6731 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6732 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6733 | false); |
| 6734 | SetLayerPropertiesForTesting(clip_child.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(-10.f, -10.f), |
| 6738 | gfx::Size(60, 60), |
[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 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6742 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6743 | host->SetRootLayer(root); |
| 6744 | |
| 6745 | ExecuteCalculateDrawProperties(root.get()); |
| 6746 | |
| 6747 | EXPECT_TRUE(root->render_surface()); |
| 6748 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6749 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6750 | |
| 6751 | // Since the render surfaces could have expanded, they should not clip (their |
| 6752 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6753 | // in this case. |
| 6754 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6755 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6756 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6757 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6758 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6759 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6760 | |
| 6761 | // NB: clip rects are in target space. |
| 6762 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6763 | render_surface1->clip_rect().ToString()); |
| 6764 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6765 | |
| 6766 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6767 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(), |
| 6768 | render_surface2->clip_rect().ToString()); |
| 6769 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6770 | |
| 6771 | // The content rects of both render surfaces should both have expanded to |
| 6772 | // contain the clip child. |
| 6773 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6774 | render_surface1->render_surface()->content_rect().ToString()); |
| 6775 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6776 | render_surface2->render_surface()->content_rect().ToString()); |
| 6777 | |
| 6778 | // The clip child should have inherited the clip parent's clip (projected to |
| 6779 | // the right space, of course), and should have the correctly sized visible |
| 6780 | // content rect. |
| 6781 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6782 | clip_child->clip_rect().ToString()); |
| 6783 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), |
| 6784 | clip_child->visible_content_rect().ToString()); |
| 6785 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6786 | } |
| 6787 | |
| 6788 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 6789 | // Ensures that descendants of the clip child inherit the correct clip. |
| 6790 | // |
| 6791 | // root (a render surface) |
| 6792 | // + clip_parent (masks to bounds) |
| 6793 | // + intervening (masks to bounds) |
| 6794 | // + clip_child |
| 6795 | // + child |
| 6796 | // |
| 6797 | scoped_refptr<Layer> root = Layer::Create(); |
| 6798 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6799 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6800 | scoped_refptr<Layer> clip_child = Layer::Create(); |
| 6801 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 6802 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6803 | |
| 6804 | root->AddChild(clip_parent); |
| 6805 | clip_parent->AddChild(intervening); |
| 6806 | intervening->AddChild(clip_child); |
| 6807 | clip_child->AddChild(child); |
| 6808 | |
| 6809 | clip_child->SetClipParent(clip_parent.get()); |
| 6810 | |
| 6811 | intervening->SetMasksToBounds(true); |
| 6812 | clip_parent->SetMasksToBounds(true); |
| 6813 | |
| 6814 | gfx::Transform identity_transform; |
| 6815 | SetLayerPropertiesForTesting(root.get(), |
| 6816 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6817 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6818 | gfx::PointF(), |
| 6819 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6820 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6821 | false); |
| 6822 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6823 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6824 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6825 | gfx::PointF(), |
| 6826 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6827 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6828 | false); |
| 6829 | SetLayerPropertiesForTesting(intervening.get(), |
| 6830 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6831 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6832 | gfx::PointF(), |
| 6833 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6834 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6835 | false); |
| 6836 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6837 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6838 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6839 | gfx::PointF(), |
| 6840 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6841 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6842 | false); |
| 6843 | SetLayerPropertiesForTesting(child.get(), |
| 6844 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6845 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6846 | gfx::PointF(), |
| 6847 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6848 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6849 | false); |
| 6850 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6851 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6852 | host->SetRootLayer(root); |
| 6853 | |
| 6854 | ExecuteCalculateDrawProperties(root.get()); |
| 6855 | |
| 6856 | EXPECT_TRUE(root->render_surface()); |
| 6857 | |
| 6858 | // Neither the clip child nor its descendant should have inherited the clip |
| 6859 | // from |intervening|. |
| 6860 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6861 | clip_child->clip_rect().ToString()); |
| 6862 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6863 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6864 | child->visible_content_rect().ToString()); |
| 6865 | EXPECT_TRUE(child->is_clipped()); |
| 6866 | } |
| 6867 | |
| 6868 | TEST_F(LayerTreeHostCommonTest, |
| 6869 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 6870 | // Ensures that non-descendant clip children in the tree do not affect |
| 6871 | // render surfaces. |
| 6872 | // |
| 6873 | // root (a render surface) |
| 6874 | // + clip_parent (masks to bounds) |
| 6875 | // + render_surface1 |
| 6876 | // + clip_child |
| 6877 | // + render_surface2 |
| 6878 | // + non_clip_child |
| 6879 | // |
| 6880 | // In this example render_surface2 should be unaffected by clip_child. |
| 6881 | scoped_refptr<Layer> root = Layer::Create(); |
| 6882 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6883 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6884 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6885 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6886 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6887 | scoped_refptr<LayerWithForcedDrawsContent> non_clip_child = |
| 6888 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6889 | |
| 6890 | root->AddChild(clip_parent); |
| 6891 | clip_parent->AddChild(render_surface1); |
| 6892 | render_surface1->AddChild(clip_child); |
| 6893 | clip_parent->AddChild(render_surface2); |
| 6894 | render_surface2->AddChild(non_clip_child); |
| 6895 | |
| 6896 | clip_child->SetClipParent(clip_parent.get()); |
| 6897 | |
| 6898 | clip_parent->SetMasksToBounds(true); |
| 6899 | render_surface1->SetMasksToBounds(true); |
| 6900 | |
| 6901 | gfx::Transform identity_transform; |
| 6902 | SetLayerPropertiesForTesting(root.get(), |
| 6903 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6904 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6905 | gfx::PointF(), |
| 6906 | gfx::Size(15, 15), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6907 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6908 | false); |
| 6909 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6910 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6911 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6912 | gfx::PointF(), |
| 6913 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6914 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6915 | false); |
| 6916 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6917 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6918 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6919 | gfx::PointF(5, 5), |
| 6920 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6921 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6922 | false); |
| 6923 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6924 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6925 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6926 | gfx::PointF(), |
| 6927 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6928 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6929 | false); |
| 6930 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6931 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6932 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6933 | gfx::PointF(-1, 1), |
| 6934 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6935 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6936 | false); |
| 6937 | SetLayerPropertiesForTesting(non_clip_child.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(5, 5), |
[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 | |
| 6945 | render_surface1->SetForceRenderSurface(true); |
| 6946 | render_surface2->SetForceRenderSurface(true); |
| 6947 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6948 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6949 | host->SetRootLayer(root); |
| 6950 | |
| 6951 | ExecuteCalculateDrawProperties(root.get()); |
| 6952 | |
| 6953 | EXPECT_TRUE(root->render_surface()); |
| 6954 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6955 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6956 | |
| 6957 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6958 | render_surface1->clip_rect().ToString()); |
| 6959 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6960 | |
| 6961 | // The render surface should not clip (it has unclipped descendants), instead |
| 6962 | // it should rely on layer clipping. |
| 6963 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6964 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6965 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6966 | |
| 6967 | // That said, it should have grown to accomodate the unclipped descendant. |
| 6968 | EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(), |
| 6969 | render_surface1->render_surface()->content_rect().ToString()); |
| 6970 | |
| 6971 | // This render surface should clip. It has no unclipped descendants. |
| 6972 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6973 | render_surface2->clip_rect().ToString()); |
| 6974 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
| 6975 | |
| 6976 | // It also shouldn't have grown to accomodate the clip child. |
| 6977 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6978 | render_surface2->render_surface()->content_rect().ToString()); |
| 6979 | |
| 6980 | // Sanity check our num_unclipped_descendants values. |
| 6981 | EXPECT_EQ(1, render_surface1->num_unclipped_descendants()); |
| 6982 | EXPECT_EQ(0, render_surface2->num_unclipped_descendants()); |
| 6983 | } |
| 6984 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6985 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
| 6986 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6987 | TestSharedBitmapManager shared_bitmap_manager; |
| 6988 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6989 | scoped_ptr<LayerImpl> root = |
| 6990 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 6991 | scoped_ptr<LayerImpl> child1 = |
| 6992 | LayerImpl::Create(host_impl.active_tree(), 123456); |
| 6993 | scoped_ptr<LayerImpl> child2 = |
| 6994 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
| 6995 | scoped_ptr<LayerImpl> child3 = |
| 6996 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 6997 | |
| 6998 | gfx::Transform identity_matrix; |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6999 | gfx::Point3F transform_origin; |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7000 | gfx::PointF position; |
| 7001 | gfx::Size bounds(100, 100); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7002 | SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 7003 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7004 | root->SetDrawsContent(true); |
| 7005 | |
| 7006 | // This layer structure normally forces render surface due to preserves3d |
| 7007 | // behavior. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7008 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin, |
| 7009 | position, bounds, false, true, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7010 | child1->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7011 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin, |
| 7012 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7013 | child2->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7014 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin, |
| 7015 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7016 | child3->SetDrawsContent(true); |
| 7017 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 7018 | child2->Set3dSortingContextId(1); |
| 7019 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7020 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7021 | child2->AddChild(child3.Pass()); |
| 7022 | child1->AddChild(child2.Pass()); |
| 7023 | root->AddChild(child1.Pass()); |
| 7024 | |
| 7025 | { |
| 7026 | LayerImplList render_surface_layer_list; |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 7027 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get()); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7028 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7029 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7030 | inputs.can_render_to_separate_surface = true; |
| 7031 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7032 | |
| 7033 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 7034 | |
| 7035 | int count_represents_target_render_surface = 0; |
| 7036 | int count_represents_contributing_render_surface = 0; |
| 7037 | int count_represents_itself = 0; |
| 7038 | auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list); |
| 7039 | for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list); |
| 7040 | it != end; ++it) { |
| 7041 | if (it.represents_target_render_surface()) |
| 7042 | count_represents_target_render_surface++; |
| 7043 | if (it.represents_contributing_render_surface()) |
| 7044 | count_represents_contributing_render_surface++; |
| 7045 | if (it.represents_itself()) |
| 7046 | count_represents_itself++; |
| 7047 | } |
| 7048 | |
| 7049 | // Two render surfaces. |
| 7050 | EXPECT_EQ(2, count_represents_target_render_surface); |
| 7051 | // Second render surface contributes to root render surface. |
| 7052 | EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 7053 | // All 4 layers represent itself. |
| 7054 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7055 | } |
| 7056 | |
| 7057 | { |
| 7058 | LayerImplList render_surface_layer_list; |
| 7059 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7060 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7061 | inputs.can_render_to_separate_surface = false; |
| 7062 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7063 | |
| 7064 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 7065 | |
| 7066 | int count_represents_target_render_surface = 0; |
| 7067 | int count_represents_contributing_render_surface = 0; |
| 7068 | int count_represents_itself = 0; |
| 7069 | auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list); |
| 7070 | for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list); |
| 7071 | it != end; ++it) { |
| 7072 | if (it.represents_target_render_surface()) |
| 7073 | count_represents_target_render_surface++; |
| 7074 | if (it.represents_contributing_render_surface()) |
| 7075 | count_represents_contributing_render_surface++; |
| 7076 | if (it.represents_itself()) |
| 7077 | count_represents_itself++; |
| 7078 | } |
| 7079 | |
| 7080 | // Only root layer has a render surface. |
| 7081 | EXPECT_EQ(1, count_represents_target_render_surface); |
| 7082 | // No layer contributes a render surface to root render surface. |
| 7083 | EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 7084 | // All 4 layers represent itself. |
| 7085 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7086 | } |
| 7087 | } |
| 7088 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7089 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
| 7090 | scoped_refptr<Layer> root = Layer::Create(); |
| 7091 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 7092 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 7093 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7094 | |
| 7095 | root->AddChild(render_surface); |
| 7096 | render_surface->AddChild(child); |
| 7097 | |
| 7098 | gfx::Transform identity_transform; |
| 7099 | SetLayerPropertiesForTesting(root.get(), |
| 7100 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7101 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7102 | gfx::PointF(), |
| 7103 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7104 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7105 | false); |
| 7106 | SetLayerPropertiesForTesting(render_surface.get(), |
| 7107 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7108 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7109 | gfx::PointF(), |
| 7110 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7111 | false, |
| 7112 | true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7113 | SetLayerPropertiesForTesting(child.get(), |
| 7114 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7115 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7116 | gfx::PointF(), |
| 7117 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7118 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7119 | false); |
| 7120 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7121 | root->SetShouldFlattenTransform(false); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 7122 | root->Set3dSortingContextId(1); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7123 | render_surface->SetDoubleSided(false); |
| 7124 | render_surface->SetForceRenderSurface(true); |
| 7125 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7126 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7127 | host->SetRootLayer(root); |
| 7128 | |
| 7129 | ExecuteCalculateDrawProperties(root.get()); |
| 7130 | |
| 7131 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 7132 | EXPECT_EQ(1u, |
| 7133 | render_surface_layer_list()->at(0) |
| 7134 | ->render_surface()->layer_list().size()); |
| 7135 | EXPECT_EQ(1u, |
| 7136 | render_surface_layer_list()->at(1) |
| 7137 | ->render_surface()->layer_list().size()); |
| 7138 | |
| 7139 | gfx::Transform rotation_transform = identity_transform; |
| 7140 | rotation_transform.RotateAboutXAxis(180.0); |
| 7141 | |
| 7142 | render_surface->SetTransform(rotation_transform); |
| 7143 | |
| 7144 | ExecuteCalculateDrawProperties(root.get()); |
| 7145 | |
| 7146 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 7147 | EXPECT_EQ(0u, |
| 7148 | render_surface_layer_list()->at(0) |
| 7149 | ->render_surface()->layer_list().size()); |
| 7150 | } |
| 7151 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7152 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 7153 | // Checks that the simple case (being clipped by a scroll parent that would |
| 7154 | // have been processed before you anyhow) results in the right clips. |
| 7155 | // |
| 7156 | // + root |
| 7157 | // + scroll_parent_border |
| 7158 | // | + scroll_parent_clip |
| 7159 | // | + scroll_parent |
| 7160 | // + scroll_child |
| 7161 | // |
| 7162 | scoped_refptr<Layer> root = Layer::Create(); |
| 7163 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7164 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7165 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7166 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7167 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7168 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7169 | |
| 7170 | root->AddChild(scroll_child); |
| 7171 | |
| 7172 | root->AddChild(scroll_parent_border); |
| 7173 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7174 | scroll_parent_clip->AddChild(scroll_parent); |
| 7175 | |
| 7176 | scroll_parent_clip->SetMasksToBounds(true); |
| 7177 | |
| 7178 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7179 | |
| 7180 | gfx::Transform identity_transform; |
| 7181 | SetLayerPropertiesForTesting(root.get(), |
| 7182 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7183 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7184 | gfx::PointF(), |
| 7185 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7186 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7187 | false); |
| 7188 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7189 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7190 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7191 | gfx::PointF(), |
| 7192 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7193 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7194 | false); |
| 7195 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7196 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7197 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7198 | gfx::PointF(), |
| 7199 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7200 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7201 | false); |
| 7202 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7203 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7204 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7205 | gfx::PointF(), |
| 7206 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7207 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7208 | false); |
| 7209 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7210 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7211 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7212 | gfx::PointF(), |
| 7213 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7214 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7215 | false); |
| 7216 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7217 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7218 | host->SetRootLayer(root); |
| 7219 | |
| 7220 | ExecuteCalculateDrawProperties(root.get()); |
| 7221 | |
| 7222 | EXPECT_TRUE(root->render_surface()); |
| 7223 | |
| 7224 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 7225 | scroll_child->clip_rect().ToString()); |
| 7226 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7227 | } |
| 7228 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7229 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
| 7230 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 7231 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7232 | scoped_refptr<LayerWithForcedDrawsContent> parent = |
| 7233 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7234 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 7235 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7236 | |
| 7237 | root->AddChild(parent); |
| 7238 | parent->AddChild(child); |
| 7239 | |
| 7240 | gfx::Transform identity_transform; |
| 7241 | SetLayerPropertiesForTesting(root.get(), |
| 7242 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7243 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7244 | gfx::PointF(), |
| 7245 | gfx::Size(50, 50), |
| 7246 | true, |
| 7247 | true); |
| 7248 | root->SetForceRenderSurface(true); |
| 7249 | SetLayerPropertiesForTesting(parent.get(), |
| 7250 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7251 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7252 | gfx::PointF(), |
| 7253 | gfx::Size(30, 30), |
| 7254 | true, |
| 7255 | true); |
| 7256 | parent->SetForceRenderSurface(true); |
| 7257 | SetLayerPropertiesForTesting(child.get(), |
| 7258 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7259 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7260 | gfx::PointF(), |
| 7261 | gfx::Size(20, 20), |
| 7262 | true, |
| 7263 | true); |
| 7264 | child->SetForceRenderSurface(true); |
| 7265 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7266 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7267 | host->SetRootLayer(root); |
| 7268 | |
| 7269 | ExecuteCalculateDrawProperties(root.get()); |
| 7270 | |
| 7271 | EXPECT_EQ(3u, render_surface_layer_list()->size()); |
| 7272 | |
| 7273 | gfx::Transform singular_transform; |
| 7274 | singular_transform.Scale3d( |
| 7275 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 7276 | |
| 7277 | child->SetTransform(singular_transform); |
| 7278 | |
| 7279 | ExecuteCalculateDrawProperties(root.get()); |
| 7280 | |
| 7281 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 7282 | |
| 7283 | // Ensure that the entire subtree under a layer with singular transform does |
| 7284 | // not get rendered. |
| 7285 | parent->SetTransform(singular_transform); |
| 7286 | child->SetTransform(identity_transform); |
| 7287 | |
| 7288 | ExecuteCalculateDrawProperties(root.get()); |
| 7289 | |
| 7290 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 7291 | } |
| 7292 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7293 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 7294 | // Checks that clipping by a scroll parent that follows you in paint order |
| 7295 | // still results in correct clipping. |
| 7296 | // |
| 7297 | // + root |
| 7298 | // + scroll_child |
| 7299 | // + scroll_parent_border |
| 7300 | // + scroll_parent_clip |
| 7301 | // + scroll_parent |
| 7302 | // |
| 7303 | scoped_refptr<Layer> root = Layer::Create(); |
| 7304 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7305 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7306 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7307 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7308 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7309 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7310 | |
| 7311 | root->AddChild(scroll_parent_border); |
| 7312 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7313 | scroll_parent_clip->AddChild(scroll_parent); |
| 7314 | |
| 7315 | root->AddChild(scroll_child); |
| 7316 | |
| 7317 | scroll_parent_clip->SetMasksToBounds(true); |
| 7318 | |
| 7319 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7320 | |
| 7321 | gfx::Transform identity_transform; |
| 7322 | SetLayerPropertiesForTesting(root.get(), |
| 7323 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7324 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7325 | gfx::PointF(), |
| 7326 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7327 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7328 | false); |
| 7329 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7330 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7331 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7332 | gfx::PointF(), |
| 7333 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7334 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7335 | false); |
| 7336 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7337 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7338 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7339 | gfx::PointF(), |
| 7340 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7341 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7342 | false); |
| 7343 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7344 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7345 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7346 | gfx::PointF(), |
| 7347 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7348 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7349 | false); |
| 7350 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7351 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7352 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7353 | gfx::PointF(), |
| 7354 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7355 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7356 | false); |
| 7357 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7358 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7359 | host->SetRootLayer(root); |
| 7360 | |
| 7361 | ExecuteCalculateDrawProperties(root.get()); |
| 7362 | |
| 7363 | EXPECT_TRUE(root->render_surface()); |
| 7364 | |
| 7365 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 7366 | scroll_child->clip_rect().ToString()); |
| 7367 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7368 | } |
| 7369 | |
| 7370 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 7371 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 7372 | // you in paint order still results in correct clipping. |
| 7373 | // |
| 7374 | // + root |
| 7375 | // + scroll_child |
| 7376 | // + scroll_parent_border |
| 7377 | // | + scroll_parent_clip |
| 7378 | // | + scroll_parent |
| 7379 | // + scroll_grandparent_border |
| 7380 | // + scroll_grandparent_clip |
| 7381 | // + scroll_grandparent |
| 7382 | // |
| 7383 | scoped_refptr<Layer> root = Layer::Create(); |
| 7384 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7385 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7386 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7387 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7388 | |
| 7389 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 7390 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 7391 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 7392 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7393 | |
| 7394 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7395 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7396 | |
| 7397 | root->AddChild(scroll_child); |
| 7398 | |
| 7399 | root->AddChild(scroll_parent_border); |
| 7400 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7401 | scroll_parent_clip->AddChild(scroll_parent); |
| 7402 | |
| 7403 | root->AddChild(scroll_grandparent_border); |
| 7404 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 7405 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 7406 | |
| 7407 | scroll_parent_clip->SetMasksToBounds(true); |
| 7408 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 7409 | |
| 7410 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7411 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 7412 | |
| 7413 | gfx::Transform identity_transform; |
| 7414 | SetLayerPropertiesForTesting(root.get(), |
| 7415 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7416 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7417 | gfx::PointF(), |
| 7418 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7419 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7420 | false); |
| 7421 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 7422 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7423 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7424 | gfx::PointF(), |
| 7425 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7426 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7427 | false); |
| 7428 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 7429 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7430 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7431 | gfx::PointF(), |
| 7432 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7433 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7434 | false); |
| 7435 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 7436 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7437 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7438 | gfx::PointF(), |
| 7439 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7440 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7441 | false); |
| 7442 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7443 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7444 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7445 | gfx::PointF(), |
| 7446 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7447 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7448 | false); |
| 7449 | SetLayerPropertiesForTesting(scroll_parent_clip.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(30, 30), |
[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_parent.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(50, 50), |
[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_child.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(50, 50), |
[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 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7471 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7472 | host->SetRootLayer(root); |
| 7473 | |
| 7474 | ExecuteCalculateDrawProperties(root.get()); |
| 7475 | |
| 7476 | EXPECT_TRUE(root->render_surface()); |
| 7477 | |
| 7478 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 7479 | scroll_child->clip_rect().ToString()); |
| 7480 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7481 | |
| 7482 | // Despite the fact that we visited the above layers out of order to get the |
| 7483 | // correct clip, the layer lists should be unaffected. |
| 7484 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 7485 | EXPECT_EQ(scroll_child.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7486 | root->render_surface()->layer_list().at(0).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7487 | EXPECT_EQ(scroll_parent.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7488 | root->render_surface()->layer_list().at(1).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7489 | EXPECT_EQ(scroll_grandparent.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7490 | root->render_surface()->layer_list().at(2).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7491 | } |
| 7492 | |
| 7493 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 7494 | // 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] | 7495 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7496 | // + root |
| 7497 | // + scroll_child |
| 7498 | // + scroll_parent_border |
| 7499 | // + scroll_parent_clip |
| 7500 | // + scroll_parent |
| 7501 | // + render_surface1 |
| 7502 | // + scroll_grandparent_border |
| 7503 | // + scroll_grandparent_clip |
| 7504 | // + scroll_grandparent |
| 7505 | // + render_surface2 |
| 7506 | // |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 7507 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 7508 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7509 | |
| 7510 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7511 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7512 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7513 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7514 | scoped_refptr<LayerWithForcedDrawsContent> render_surface1 = |
| 7515 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7516 | |
| 7517 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 7518 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 7519 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 7520 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7521 | scoped_refptr<LayerWithForcedDrawsContent> render_surface2 = |
| 7522 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7523 | |
| 7524 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7525 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7526 | |
| 7527 | root->AddChild(scroll_child); |
| 7528 | |
| 7529 | root->AddChild(scroll_parent_border); |
| 7530 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7531 | scroll_parent_clip->AddChild(scroll_parent); |
| 7532 | scroll_parent->AddChild(render_surface2); |
| 7533 | |
| 7534 | root->AddChild(scroll_grandparent_border); |
| 7535 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 7536 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 7537 | scroll_grandparent->AddChild(render_surface1); |
| 7538 | |
| 7539 | scroll_parent_clip->SetMasksToBounds(true); |
| 7540 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 7541 | |
| 7542 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7543 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 7544 | |
| 7545 | render_surface1->SetForceRenderSurface(true); |
| 7546 | render_surface2->SetForceRenderSurface(true); |
| 7547 | |
| 7548 | gfx::Transform identity_transform; |
| 7549 | SetLayerPropertiesForTesting(root.get(), |
| 7550 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7551 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7552 | gfx::PointF(), |
| 7553 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7554 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7555 | false); |
| 7556 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 7557 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7558 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7559 | gfx::PointF(), |
| 7560 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7561 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7562 | false); |
| 7563 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 7564 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7565 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7566 | gfx::PointF(), |
| 7567 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7568 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7569 | false); |
| 7570 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 7571 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7572 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7573 | gfx::PointF(), |
| 7574 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7575 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7576 | false); |
| 7577 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 7578 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7579 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7580 | gfx::PointF(), |
| 7581 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7582 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7583 | false); |
| 7584 | SetLayerPropertiesForTesting(scroll_parent_border.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(40, 40), |
[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_parent_clip.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(30, 30), |
[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_parent.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(50, 50), |
[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(render_surface2.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(scroll_child.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 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7620 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7621 | host->SetRootLayer(root); |
| 7622 | |
| 7623 | RenderSurfaceLayerList render_surface_layer_list; |
| 7624 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7625 | root.get(), |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7626 | root->bounds(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7627 | identity_transform, |
| 7628 | &render_surface_layer_list); |
| 7629 | |
| 7630 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7631 | |
| 7632 | EXPECT_TRUE(root->render_surface()); |
| 7633 | |
| 7634 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 7635 | scroll_child->clip_rect().ToString()); |
| 7636 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7637 | |
| 7638 | // Despite the fact that we had to process the layers out of order to get the |
| 7639 | // right clip, our render_surface_layer_list's order should be unaffected. |
| 7640 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
| 7641 | EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); |
| 7642 | EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); |
| 7643 | EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 7644 | EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); |
| 7645 | EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); |
| 7646 | EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7647 | } |
| 7648 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7649 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 7650 | // This test verifies that a scrolling layer that gets snapped to |
| 7651 | // integer coordinates doesn't move a fixed position child. |
| 7652 | // |
| 7653 | // + root |
| 7654 | // + container |
| 7655 | // + scroller |
| 7656 | // + fixed |
| 7657 | // |
| 7658 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7659 | TestSharedBitmapManager shared_bitmap_manager; |
| 7660 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7661 | host_impl.CreatePendingTree(); |
| 7662 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7663 | scoped_ptr<LayerImpl> container = |
| 7664 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7665 | LayerImpl* container_layer = container.get(); |
| 7666 | scoped_ptr<LayerImpl> scroller = |
| 7667 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7668 | LayerImpl* scroll_layer = scroller.get(); |
| 7669 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7670 | LayerImpl* fixed_layer = fixed.get(); |
| 7671 | |
| 7672 | container->SetIsContainerForFixedPositionLayers(true); |
| 7673 | |
| 7674 | LayerPositionConstraint constraint; |
| 7675 | constraint.set_is_fixed_position(true); |
| 7676 | fixed->SetPositionConstraint(constraint); |
| 7677 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 7678 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7679 | |
| 7680 | gfx::Transform identity_transform; |
| 7681 | gfx::Transform container_transform; |
| 7682 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7683 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7684 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7685 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7686 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7687 | true); |
| 7688 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7689 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7690 | true, false, false); |
| 7691 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7692 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 7693 | true, false, false); |
| 7694 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7695 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7696 | false); |
| 7697 | |
| 7698 | scroller->AddChild(fixed.Pass()); |
| 7699 | container->AddChild(scroller.Pass()); |
| 7700 | root->AddChild(container.Pass()); |
| 7701 | |
| 7702 | // Rounded to integers already. |
| 7703 | { |
| 7704 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
| 7705 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7706 | |
| 7707 | LayerImplList render_surface_layer_list; |
| 7708 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7709 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7710 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7711 | |
| 7712 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7713 | container_layer->draw_properties().screen_space_transform, |
| 7714 | fixed_layer->draw_properties().screen_space_transform); |
| 7715 | EXPECT_VECTOR_EQ( |
| 7716 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7717 | container_offset); |
| 7718 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7719 | .screen_space_transform.To2dTranslation(), |
| 7720 | container_offset - scroll_delta); |
| 7721 | } |
| 7722 | |
| 7723 | // Scroll delta requiring rounding. |
| 7724 | { |
| 7725 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
| 7726 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7727 | |
| 7728 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 7729 | |
| 7730 | LayerImplList render_surface_layer_list; |
| 7731 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7732 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7733 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7734 | |
| 7735 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7736 | container_layer->draw_properties().screen_space_transform, |
| 7737 | fixed_layer->draw_properties().screen_space_transform); |
| 7738 | EXPECT_VECTOR_EQ( |
| 7739 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7740 | container_offset); |
| 7741 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7742 | .screen_space_transform.To2dTranslation(), |
| 7743 | container_offset - rounded_scroll_delta); |
| 7744 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7745 | |
| 7746 | // Scale is applied earlier in the tree. |
| 7747 | { |
| 7748 | gfx::Transform scaled_container_transform = container_transform; |
| 7749 | scaled_container_transform.Scale3d(3.0, 3.0, 1.0); |
| 7750 | container_layer->SetTransform(scaled_container_transform); |
| 7751 | |
| 7752 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7753 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7754 | |
| 7755 | LayerImplList render_surface_layer_list; |
| 7756 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7757 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7758 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7759 | |
| 7760 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7761 | container_layer->draw_properties().screen_space_transform, |
| 7762 | fixed_layer->draw_properties().screen_space_transform); |
| 7763 | EXPECT_VECTOR_EQ( |
| 7764 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7765 | container_offset); |
| 7766 | |
| 7767 | container_layer->SetTransform(container_transform); |
| 7768 | } |
| 7769 | |
| 7770 | // Scale is applied on the scroll layer itself. |
| 7771 | { |
| 7772 | gfx::Transform scale_transform; |
| 7773 | scale_transform.Scale3d(3.0, 3.0, 1.0); |
| 7774 | scroll_layer->SetTransform(scale_transform); |
| 7775 | |
| 7776 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7777 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7778 | |
| 7779 | LayerImplList render_surface_layer_list; |
| 7780 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7781 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7782 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7783 | |
| 7784 | EXPECT_VECTOR_EQ( |
| 7785 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7786 | container_offset); |
| 7787 | |
| 7788 | scroll_layer->SetTransform(identity_transform); |
| 7789 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7790 | } |
| 7791 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7792 | TEST_F(LayerTreeHostCommonTest, |
| 7793 | ScrollCompensationMainScrollOffsetFractionalPart) { |
| 7794 | // This test verifies that a scrolling layer that has fractional scroll offset |
| 7795 | // from main doesn't move a fixed position child. |
| 7796 | // |
| 7797 | // + root |
| 7798 | // + container |
| 7799 | // + scroller |
| 7800 | // + fixed |
| 7801 | // |
| 7802 | FakeImplProxy proxy; |
| 7803 | TestSharedBitmapManager shared_bitmap_manager; |
| 7804 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 7805 | host_impl.CreatePendingTree(); |
| 7806 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7807 | scoped_ptr<LayerImpl> container = |
| 7808 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7809 | LayerImpl* container_layer = container.get(); |
| 7810 | scoped_ptr<LayerImpl> scroller = |
| 7811 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7812 | LayerImpl* scroll_layer = scroller.get(); |
| 7813 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7814 | LayerImpl* fixed_layer = fixed.get(); |
| 7815 | |
| 7816 | container->SetIsContainerForFixedPositionLayers(true); |
| 7817 | |
| 7818 | LayerPositionConstraint constraint; |
| 7819 | constraint.set_is_fixed_position(true); |
| 7820 | fixed->SetPositionConstraint(constraint); |
| 7821 | |
| 7822 | scroller->SetScrollClipLayer(container->id()); |
| 7823 | |
| 7824 | gfx::Transform identity_transform; |
| 7825 | gfx::Transform container_transform; |
| 7826 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7827 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7828 | |
| 7829 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7830 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7831 | true); |
| 7832 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7833 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7834 | true, false, false); |
| 7835 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7836 | gfx::Point3F(), gfx::PointF(0.0, 0.0), |
| 7837 | gfx::Size(30, 30), true, false, false); |
| 7838 | |
| 7839 | gfx::ScrollOffset scroll_offset(3.3, 4.2); |
| 7840 | gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f); |
| 7841 | gfx::Vector2dF scroll_delta(0.1f, 0.4f); |
| 7842 | // Blink only uses the integer part of the scroll_offset for fixed |
| 7843 | // position layer. |
| 7844 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7845 | gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true, |
| 7846 | false, false); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 7847 | scroll_layer->PushScrollOffsetFromMainThread(scroll_offset); |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 7848 | scroll_layer->SetScrollDelta(scroll_delta); |
miletus | ff93ab7 | 2015-01-30 04:30:44 | [diff] [blame] | 7849 | scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7850 | |
| 7851 | scroller->AddChild(fixed.Pass()); |
| 7852 | container->AddChild(scroller.Pass()); |
| 7853 | root->AddChild(container.Pass()); |
| 7854 | |
| 7855 | LayerImplList render_surface_layer_list; |
| 7856 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7857 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7858 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7859 | |
| 7860 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7861 | container_layer->draw_properties().screen_space_transform, |
| 7862 | fixed_layer->draw_properties().screen_space_transform); |
| 7863 | EXPECT_VECTOR_EQ( |
| 7864 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7865 | container_offset); |
| 7866 | |
| 7867 | gfx::ScrollOffset effective_scroll_offset = |
| 7868 | ScrollOffsetWithDelta(scroll_offset, scroll_delta); |
| 7869 | gfx::Vector2d rounded_effective_scroll_offset = |
| 7870 | ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset)); |
| 7871 | EXPECT_VECTOR_EQ( |
| 7872 | scroll_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7873 | container_offset - rounded_effective_scroll_offset); |
| 7874 | } |
| 7875 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7876 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7877 | public: |
| 7878 | static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
| 7879 | LayerTreeImpl* tree_impl, |
| 7880 | int id) { |
| 7881 | return make_scoped_ptr( |
| 7882 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7883 | } |
| 7884 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7885 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7886 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7887 | private: |
| 7888 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7889 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7890 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7891 | SetDrawsContent(true); |
| 7892 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7893 | }; |
| 7894 | |
| 7895 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
| 7896 | FakeImplProxy proxy; |
| 7897 | TestSharedBitmapManager shared_bitmap_manager; |
| 7898 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 7899 | gfx::Transform identity_matrix; |
| 7900 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
| 7901 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
| 7902 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
| 7903 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
| 7904 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
| 7905 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
| 7906 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
| 7907 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7908 | |
| 7909 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7910 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7911 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
| 7912 | |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 7913 | child->AddChild(grand_child.Pass()); |
| 7914 | parent->AddChild(child.Pass()); |
| 7915 | grand_parent->AddChild(parent.Pass()); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7916 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7917 | SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix, |
| 7918 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7919 | true, false, true); |
| 7920 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 7921 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7922 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7923 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 7924 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7925 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7926 | |
| 7927 | SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(), |
| 7928 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7929 | false); |
| 7930 | |
| 7931 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7932 | |
| 7933 | // No layers have animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7934 | EXPECT_EQ(0.f, |
| 7935 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7936 | EXPECT_EQ(0.f, |
| 7937 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7938 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7939 | EXPECT_EQ( |
| 7940 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7941 | |
| 7942 | TransformOperations translation; |
| 7943 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7944 | |
| 7945 | AddAnimatedTransformToLayer( |
| 7946 | parent_raw, 1.0, TransformOperations(), translation); |
| 7947 | |
| 7948 | // No layers have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7949 | EXPECT_EQ(0.f, |
| 7950 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7951 | EXPECT_EQ(0.f, |
| 7952 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7953 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7954 | EXPECT_EQ( |
| 7955 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7956 | |
| 7957 | TransformOperations scale; |
| 7958 | scale.AppendScale(5.f, 4.f, 3.f); |
| 7959 | |
| 7960 | AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); |
| 7961 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7962 | |
| 7963 | // Only |child| has a scale-affecting animation. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7964 | EXPECT_EQ(0.f, |
| 7965 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7966 | EXPECT_EQ(0.f, |
| 7967 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7968 | EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7969 | EXPECT_EQ( |
| 7970 | 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7971 | |
| 7972 | AddAnimatedTransformToLayer( |
| 7973 | grand_parent.get(), 1.0, TransformOperations(), scale); |
| 7974 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7975 | |
| 7976 | // |grand_parent| and |child| have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7977 | EXPECT_EQ(5.f, |
| 7978 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7979 | EXPECT_EQ(5.f, |
| 7980 | parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7981 | // We don't support combining animated scales from two nodes; 0.f means |
| 7982 | // that the maximum scale could not be computed. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7983 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7984 | EXPECT_EQ( |
| 7985 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7986 | |
| 7987 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 7988 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7989 | |
| 7990 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7991 | EXPECT_EQ(5.f, |
| 7992 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7993 | EXPECT_EQ(0.f, |
| 7994 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7995 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7996 | EXPECT_EQ( |
| 7997 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7998 | |
| 7999 | grand_parent->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8000 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8001 | parent_raw->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8002 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8003 | child_raw->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8004 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8005 | |
| 8006 | TransformOperations perspective; |
| 8007 | perspective.AppendPerspective(10.f); |
| 8008 | |
| 8009 | AddAnimatedTransformToLayer( |
| 8010 | child_raw, 1.0, TransformOperations(), perspective); |
| 8011 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8012 | |
| 8013 | // |child| has a scale-affecting animation but computing the maximum of this |
| 8014 | // animation is not supported. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8015 | EXPECT_EQ(0.f, |
| 8016 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8017 | EXPECT_EQ(0.f, |
| 8018 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8019 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8020 | EXPECT_EQ( |
| 8021 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8022 | |
| 8023 | child_raw->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8024 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8025 | |
| 8026 | gfx::Transform scale_matrix; |
| 8027 | scale_matrix.Scale(1.f, 2.f); |
| 8028 | grand_parent->SetTransform(scale_matrix); |
| 8029 | parent_raw->SetTransform(scale_matrix); |
| 8030 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 8031 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8032 | |
| 8033 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 8034 | // animation with maximum scale 5.f. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8035 | EXPECT_EQ(0.f, |
| 8036 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8037 | EXPECT_EQ(10.f, |
| 8038 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8039 | EXPECT_EQ(10.f, |
| 8040 | child_raw->draw_properties().maximum_animation_contents_scale); |
| 8041 | EXPECT_EQ( |
| 8042 | 10.f, |
| 8043 | grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8044 | |
| 8045 | gfx::Transform perspective_matrix; |
| 8046 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 8047 | child_raw->SetTransform(perspective_matrix); |
| 8048 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8049 | |
| 8050 | // |child| has a transform that's neither a translation nor a scale. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8051 | EXPECT_EQ(0.f, |
| 8052 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8053 | EXPECT_EQ(10.f, |
| 8054 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8055 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8056 | EXPECT_EQ( |
| 8057 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8058 | |
| 8059 | parent_raw->SetTransform(perspective_matrix); |
| 8060 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8061 | |
| 8062 | // |parent| and |child| have transforms that are neither translations nor |
| 8063 | // scales. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8064 | EXPECT_EQ(0.f, |
| 8065 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8066 | EXPECT_EQ(0.f, |
| 8067 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8068 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8069 | EXPECT_EQ( |
| 8070 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8071 | |
| 8072 | parent_raw->SetTransform(identity_matrix); |
| 8073 | child_raw->SetTransform(identity_matrix); |
| 8074 | grand_parent->SetTransform(perspective_matrix); |
| 8075 | |
| 8076 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8077 | |
| 8078 | // |grand_parent| has a transform that's neither a translation nor a scale. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8079 | EXPECT_EQ(0.f, |
| 8080 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8081 | EXPECT_EQ(0.f, |
| 8082 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8083 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8084 | EXPECT_EQ( |
| 8085 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8086 | } |
| 8087 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8088 | static int membership_id(LayerImpl* layer) { |
| 8089 | return layer->draw_properties().last_drawn_render_surface_layer_list_id; |
| 8090 | } |
| 8091 | |
| 8092 | static void GatherDrawnLayers(LayerImplList* rsll, |
| 8093 | std::set<LayerImpl*>* drawn_layers) { |
| 8094 | for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll), |
| 8095 | end = LayerIterator<LayerImpl>::End(rsll); |
| 8096 | it != end; |
| 8097 | ++it) { |
| 8098 | LayerImpl* layer = *it; |
| 8099 | if (it.represents_itself()) |
| 8100 | drawn_layers->insert(layer); |
| 8101 | |
| 8102 | if (!it.represents_contributing_render_surface()) |
| 8103 | continue; |
| 8104 | |
| 8105 | if (layer->mask_layer()) |
| 8106 | drawn_layers->insert(layer->mask_layer()); |
| 8107 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 8108 | drawn_layers->insert(layer->replica_layer()->mask_layer()); |
| 8109 | } |
| 8110 | } |
| 8111 | |
| 8112 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
| 8113 | FakeImplProxy proxy; |
| 8114 | TestSharedBitmapManager shared_bitmap_manager; |
| 8115 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 8116 | gfx::Transform identity_matrix; |
| 8117 | |
| 8118 | scoped_ptr<LayerImpl> grand_parent = |
| 8119 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8120 | scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3); |
| 8121 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5); |
| 8122 | scoped_ptr<LayerImpl> grand_child1 = |
| 8123 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 8124 | scoped_ptr<LayerImpl> grand_child2 = |
| 8125 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 8126 | |
| 8127 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 8128 | LayerImpl* parent_raw = parent.get(); |
| 8129 | LayerImpl* child_raw = child.get(); |
| 8130 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 8131 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 8132 | |
| 8133 | child->AddChild(grand_child1.Pass()); |
| 8134 | child->AddChild(grand_child2.Pass()); |
| 8135 | parent->AddChild(child.Pass()); |
| 8136 | grand_parent->AddChild(parent.Pass()); |
| 8137 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8138 | SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, |
| 8139 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8140 | true, false, true); |
| 8141 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 8142 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8143 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8144 | |
| 8145 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 8146 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8147 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8148 | |
| 8149 | SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix, |
| 8150 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8151 | true, false, false); |
| 8152 | |
| 8153 | SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix, |
| 8154 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8155 | true, false, false); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8156 | |
| 8157 | // Start with nothing being drawn. |
| 8158 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8159 | int member_id = render_surface_layer_list_count(); |
| 8160 | |
| 8161 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8162 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8163 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8164 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8165 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8166 | |
| 8167 | std::set<LayerImpl*> expected; |
| 8168 | std::set<LayerImpl*> actual; |
| 8169 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8170 | EXPECT_EQ(expected, actual); |
| 8171 | |
| 8172 | // If we force render surface, but none of the layers are in the layer list, |
| 8173 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8174 | grand_child1_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8175 | |
| 8176 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8177 | member_id = render_surface_layer_list_count(); |
| 8178 | |
| 8179 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8180 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8181 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8182 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8183 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8184 | |
| 8185 | expected.clear(); |
| 8186 | actual.clear(); |
| 8187 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8188 | EXPECT_EQ(expected, actual); |
| 8189 | |
| 8190 | // However, if we say that this layer also draws content, it will appear in |
| 8191 | // RSLL. |
| 8192 | grand_child1_raw->SetDrawsContent(true); |
| 8193 | |
| 8194 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8195 | member_id = render_surface_layer_list_count(); |
| 8196 | |
| 8197 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8198 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8199 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8200 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 8201 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8202 | |
| 8203 | expected.clear(); |
| 8204 | expected.insert(grand_child1_raw); |
| 8205 | |
| 8206 | actual.clear(); |
| 8207 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8208 | EXPECT_EQ(expected, actual); |
| 8209 | |
| 8210 | // Now child is forced to have a render surface, and one if its children draws |
| 8211 | // content. |
| 8212 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8213 | grand_child1_raw->SetHasRenderSurface(false); |
| 8214 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8215 | grand_child2_raw->SetDrawsContent(true); |
| 8216 | |
| 8217 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8218 | member_id = render_surface_layer_list_count(); |
| 8219 | |
| 8220 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8221 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8222 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8223 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8224 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8225 | |
| 8226 | expected.clear(); |
| 8227 | expected.insert(grand_child2_raw); |
| 8228 | |
| 8229 | actual.clear(); |
| 8230 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8231 | EXPECT_EQ(expected, actual); |
| 8232 | |
| 8233 | // Add a mask layer to child. |
| 8234 | child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass()); |
| 8235 | |
| 8236 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8237 | member_id = render_surface_layer_list_count(); |
| 8238 | |
| 8239 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8240 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8241 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8242 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8243 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8244 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8245 | |
| 8246 | expected.clear(); |
| 8247 | expected.insert(grand_child2_raw); |
| 8248 | expected.insert(child_raw->mask_layer()); |
| 8249 | |
| 8250 | expected.clear(); |
| 8251 | expected.insert(grand_child2_raw); |
| 8252 | expected.insert(child_raw->mask_layer()); |
| 8253 | |
| 8254 | actual.clear(); |
| 8255 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8256 | EXPECT_EQ(expected, actual); |
| 8257 | |
| 8258 | // Add replica mask layer. |
| 8259 | scoped_ptr<LayerImpl> replica_layer = |
| 8260 | LayerImpl::Create(host_impl.active_tree(), 20); |
| 8261 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21)); |
| 8262 | child_raw->SetReplicaLayer(replica_layer.Pass()); |
| 8263 | |
| 8264 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8265 | member_id = render_surface_layer_list_count(); |
| 8266 | |
| 8267 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8268 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8269 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8270 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8271 | EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer())); |
| 8272 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8273 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8274 | |
| 8275 | expected.clear(); |
| 8276 | expected.insert(grand_child2_raw); |
| 8277 | expected.insert(child_raw->mask_layer()); |
| 8278 | expected.insert(child_raw->replica_layer()->mask_layer()); |
| 8279 | |
| 8280 | actual.clear(); |
| 8281 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8282 | EXPECT_EQ(expected, actual); |
| 8283 | |
| 8284 | child_raw->TakeReplicaLayer(); |
| 8285 | |
| 8286 | // With nothing drawing, we should have no layers. |
| 8287 | grand_child2_raw->SetDrawsContent(false); |
| 8288 | |
| 8289 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8290 | member_id = render_surface_layer_list_count(); |
| 8291 | |
| 8292 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8293 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8294 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8295 | EXPECT_NE(member_id, membership_id(child_raw->mask_layer())); |
| 8296 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8297 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8298 | |
| 8299 | expected.clear(); |
| 8300 | actual.clear(); |
| 8301 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8302 | EXPECT_EQ(expected, actual); |
| 8303 | |
| 8304 | // Child itself draws means that we should have the child and the mask in the |
| 8305 | // list. |
| 8306 | child_raw->SetDrawsContent(true); |
| 8307 | |
| 8308 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8309 | member_id = render_surface_layer_list_count(); |
| 8310 | |
| 8311 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8312 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8313 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 8314 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8315 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8316 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8317 | |
| 8318 | expected.clear(); |
| 8319 | expected.insert(child_raw); |
| 8320 | expected.insert(child_raw->mask_layer()); |
| 8321 | actual.clear(); |
| 8322 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8323 | EXPECT_EQ(expected, actual); |
| 8324 | |
| 8325 | child_raw->TakeMaskLayer(); |
| 8326 | |
| 8327 | // Now everyone's a member! |
| 8328 | grand_parent_raw->SetDrawsContent(true); |
| 8329 | parent_raw->SetDrawsContent(true); |
| 8330 | child_raw->SetDrawsContent(true); |
| 8331 | grand_child1_raw->SetDrawsContent(true); |
| 8332 | grand_child2_raw->SetDrawsContent(true); |
| 8333 | |
| 8334 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8335 | member_id = render_surface_layer_list_count(); |
| 8336 | |
| 8337 | EXPECT_EQ(member_id, membership_id(grand_parent_raw)); |
| 8338 | EXPECT_EQ(member_id, membership_id(parent_raw)); |
| 8339 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 8340 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 8341 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8342 | |
| 8343 | expected.clear(); |
| 8344 | expected.insert(grand_parent_raw); |
| 8345 | expected.insert(parent_raw); |
| 8346 | expected.insert(child_raw); |
| 8347 | expected.insert(grand_child1_raw); |
| 8348 | expected.insert(grand_child2_raw); |
| 8349 | |
| 8350 | actual.clear(); |
| 8351 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8352 | EXPECT_EQ(expected, actual); |
| 8353 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8354 | |
| 8355 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
| 8356 | FakeImplProxy proxy; |
| 8357 | TestSharedBitmapManager shared_bitmap_manager; |
| 8358 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 8359 | |
| 8360 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 8361 | LayerImpl* root_layer = root.get(); |
| 8362 | scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2); |
| 8363 | LayerImpl* child1_layer = child1.get(); |
| 8364 | scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3); |
| 8365 | LayerImpl* child2_layer = child2.get(); |
| 8366 | |
| 8367 | root->AddChild(child1.Pass()); |
| 8368 | root->AddChild(child2.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8369 | root->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8370 | |
| 8371 | gfx::Transform identity_matrix, scale_transform_child1, |
| 8372 | scale_transform_child2; |
| 8373 | scale_transform_child1.Scale(2, 3); |
| 8374 | scale_transform_child2.Scale(4, 5); |
| 8375 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8376 | SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(), |
| 8377 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 8378 | true); |
| 8379 | SetLayerPropertiesForTesting(child1_layer, scale_transform_child1, |
| 8380 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 8381 | false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8382 | |
| 8383 | child1_layer->SetMaskLayer( |
| 8384 | LayerImpl::Create(host_impl.active_tree(), 4).Pass()); |
| 8385 | |
| 8386 | scoped_ptr<LayerImpl> replica_layer = |
| 8387 | LayerImpl::Create(host_impl.active_tree(), 5); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8388 | replica_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8389 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
| 8390 | child1_layer->SetReplicaLayer(replica_layer.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8391 | child1_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8392 | |
| 8393 | ExecuteCalculateDrawProperties(root_layer); |
| 8394 | |
| 8395 | TransformOperations scale; |
| 8396 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8397 | |
| 8398 | AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8399 | SetLayerPropertiesForTesting(child2_layer, scale_transform_child2, |
| 8400 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 8401 | false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8402 | |
| 8403 | ExecuteCalculateDrawProperties(root_layer); |
| 8404 | |
| 8405 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); |
| 8406 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8407 | EXPECT_FLOAT_EQ( |
| 8408 | 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8409 | EXPECT_FLOAT_EQ(3.f, |
| 8410 | child1_layer->replica_layer() |
| 8411 | ->mask_layer() |
| 8412 | ->draw_properties() |
| 8413 | .ideal_contents_scale); |
| 8414 | EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8415 | |
| 8416 | EXPECT_FLOAT_EQ( |
| 8417 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8418 | EXPECT_FLOAT_EQ( |
| 8419 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8420 | EXPECT_FLOAT_EQ(0.f, |
| 8421 | child1_layer->mask_layer() |
| 8422 | ->draw_properties() |
| 8423 | .maximum_animation_contents_scale); |
| 8424 | EXPECT_FLOAT_EQ(0.f, |
| 8425 | child1_layer->replica_layer() |
| 8426 | ->mask_layer() |
| 8427 | ->draw_properties() |
| 8428 | .maximum_animation_contents_scale); |
| 8429 | EXPECT_FLOAT_EQ( |
| 8430 | 8.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8431 | |
| 8432 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8433 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor); |
| 8434 | EXPECT_FLOAT_EQ( |
| 8435 | 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8436 | EXPECT_FLOAT_EQ(1.f, |
| 8437 | child1_layer->replica_layer() |
| 8438 | ->mask_layer() |
| 8439 | ->draw_properties() |
| 8440 | .page_scale_factor); |
| 8441 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor); |
| 8442 | |
| 8443 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); |
| 8444 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); |
| 8445 | EXPECT_FLOAT_EQ( |
| 8446 | 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8447 | EXPECT_FLOAT_EQ(1.f, |
| 8448 | child1_layer->replica_layer() |
| 8449 | ->mask_layer() |
| 8450 | ->draw_properties() |
| 8451 | .device_scale_factor); |
| 8452 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); |
| 8453 | |
| 8454 | // Changing page-scale would affect ideal_contents_scale and |
| 8455 | // maximum_animation_contents_scale. |
| 8456 | |
| 8457 | float page_scale_factor = 3.f; |
| 8458 | float device_scale_factor = 1.0f; |
| 8459 | std::vector<LayerImpl*> render_surface_layer_list; |
| 8460 | gfx::Size device_viewport_size = |
| 8461 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 8462 | root_layer->bounds().height() * device_scale_factor); |
| 8463 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8464 | root_layer, device_viewport_size, &render_surface_layer_list); |
| 8465 | |
| 8466 | inputs.page_scale_factor = page_scale_factor; |
| 8467 | inputs.can_adjust_raster_scales = true; |
| 8468 | inputs.page_scale_application_layer = root_layer; |
| 8469 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8470 | |
| 8471 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); |
| 8472 | EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8473 | EXPECT_FLOAT_EQ( |
| 8474 | 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8475 | EXPECT_FLOAT_EQ(9.f, |
| 8476 | child1_layer->replica_layer() |
| 8477 | ->mask_layer() |
| 8478 | ->draw_properties() |
| 8479 | .ideal_contents_scale); |
| 8480 | EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8481 | |
| 8482 | EXPECT_FLOAT_EQ( |
| 8483 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8484 | EXPECT_FLOAT_EQ( |
| 8485 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8486 | EXPECT_FLOAT_EQ(0.f, |
| 8487 | child1_layer->mask_layer() |
| 8488 | ->draw_properties() |
| 8489 | .maximum_animation_contents_scale); |
| 8490 | EXPECT_FLOAT_EQ(0.f, |
| 8491 | child1_layer->replica_layer() |
| 8492 | ->mask_layer() |
| 8493 | ->draw_properties() |
| 8494 | .maximum_animation_contents_scale); |
| 8495 | EXPECT_FLOAT_EQ( |
| 8496 | 24.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8497 | |
| 8498 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8499 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); |
| 8500 | EXPECT_FLOAT_EQ( |
| 8501 | 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8502 | EXPECT_FLOAT_EQ(3.f, |
| 8503 | child1_layer->replica_layer() |
| 8504 | ->mask_layer() |
| 8505 | ->draw_properties() |
| 8506 | .page_scale_factor); |
| 8507 | EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); |
| 8508 | |
| 8509 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); |
| 8510 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); |
| 8511 | EXPECT_FLOAT_EQ( |
| 8512 | 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8513 | EXPECT_FLOAT_EQ(1.f, |
| 8514 | child1_layer->replica_layer() |
| 8515 | ->mask_layer() |
| 8516 | ->draw_properties() |
| 8517 | .device_scale_factor); |
| 8518 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); |
| 8519 | |
| 8520 | // Changing device-scale would affect ideal_contents_scale and |
| 8521 | // maximum_animation_contents_scale. |
| 8522 | |
| 8523 | device_scale_factor = 4.0f; |
| 8524 | inputs.device_scale_factor = device_scale_factor; |
| 8525 | inputs.can_adjust_raster_scales = true; |
| 8526 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8527 | |
| 8528 | EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale); |
| 8529 | EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8530 | EXPECT_FLOAT_EQ( |
| 8531 | 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8532 | EXPECT_FLOAT_EQ(36.f, |
| 8533 | child1_layer->replica_layer() |
| 8534 | ->mask_layer() |
| 8535 | ->draw_properties() |
| 8536 | .ideal_contents_scale); |
| 8537 | EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8538 | |
| 8539 | EXPECT_FLOAT_EQ( |
| 8540 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8541 | EXPECT_FLOAT_EQ( |
| 8542 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8543 | EXPECT_FLOAT_EQ(0.f, |
| 8544 | child1_layer->mask_layer() |
| 8545 | ->draw_properties() |
| 8546 | .maximum_animation_contents_scale); |
| 8547 | EXPECT_FLOAT_EQ(0.f, |
| 8548 | child1_layer->replica_layer() |
| 8549 | ->mask_layer() |
| 8550 | ->draw_properties() |
| 8551 | .maximum_animation_contents_scale); |
| 8552 | EXPECT_FLOAT_EQ( |
| 8553 | 96.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8554 | |
| 8555 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8556 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); |
| 8557 | EXPECT_FLOAT_EQ( |
| 8558 | 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8559 | EXPECT_FLOAT_EQ(3.f, |
| 8560 | child1_layer->replica_layer() |
| 8561 | ->mask_layer() |
| 8562 | ->draw_properties() |
| 8563 | .page_scale_factor); |
| 8564 | EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); |
| 8565 | |
| 8566 | EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor); |
| 8567 | EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor); |
| 8568 | EXPECT_FLOAT_EQ( |
| 8569 | 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8570 | EXPECT_FLOAT_EQ(4.f, |
| 8571 | child1_layer->replica_layer() |
| 8572 | ->mask_layer() |
| 8573 | ->draw_properties() |
| 8574 | .device_scale_factor); |
| 8575 | EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor); |
| 8576 | } |
| 8577 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8578 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
| 8579 | scoped_refptr<Layer> root = Layer::Create(); |
| 8580 | SetLayerPropertiesForTesting(root.get(), |
| 8581 | gfx::Transform(), |
| 8582 | gfx::Point3F(), |
| 8583 | gfx::PointF(), |
| 8584 | gfx::Size(768 / 2, 3000), |
| 8585 | true, |
| 8586 | false); |
| 8587 | root->SetIsDrawable(true); |
| 8588 | |
| 8589 | scoped_refptr<Layer> clip = Layer::Create(); |
| 8590 | SetLayerPropertiesForTesting(clip.get(), |
| 8591 | gfx::Transform(), |
| 8592 | gfx::Point3F(), |
| 8593 | gfx::PointF(), |
| 8594 | gfx::Size(768 / 2, 10000), |
| 8595 | true, |
| 8596 | false); |
| 8597 | clip->SetMasksToBounds(true); |
| 8598 | |
| 8599 | scoped_refptr<Layer> content = Layer::Create(); |
| 8600 | SetLayerPropertiesForTesting(content.get(), |
| 8601 | gfx::Transform(), |
| 8602 | gfx::Point3F(), |
| 8603 | gfx::PointF(), |
| 8604 | gfx::Size(768 / 2, 10000), |
| 8605 | true, |
| 8606 | false); |
| 8607 | content->SetIsDrawable(true); |
| 8608 | content->SetForceRenderSurface(true); |
| 8609 | |
| 8610 | root->AddChild(clip); |
| 8611 | clip->AddChild(content); |
| 8612 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 8613 | FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 8614 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8615 | host->SetRootLayer(root); |
| 8616 | |
| 8617 | gfx::Size device_viewport_size(768, 582); |
| 8618 | RenderSurfaceLayerList render_surface_layer_list; |
| 8619 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8620 | host->root_layer(), device_viewport_size, &render_surface_layer_list); |
| 8621 | inputs.device_scale_factor = 2.f; |
| 8622 | inputs.page_scale_factor = 1.f; |
| 8623 | inputs.page_scale_application_layer = NULL; |
| 8624 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8625 | |
| 8626 | // Layers in the root render surface have their visible content rect clipped |
| 8627 | // by the viewport. |
| 8628 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); |
| 8629 | |
| 8630 | // Layers drawing to a child render surface should still have their visible |
| 8631 | // content rect clipped by the viewport. |
| 8632 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); |
| 8633 | } |
| 8634 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8635 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
| 8636 | FakeImplProxy proxy; |
| 8637 | TestSharedBitmapManager shared_bitmap_manager; |
| 8638 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 8639 | |
| 8640 | // Set two layers: the root layer clips it's child, |
| 8641 | // the child draws its content. |
| 8642 | |
| 8643 | gfx::Size root_size = gfx::Size(300, 500); |
| 8644 | |
| 8645 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8646 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8647 | |
| 8648 | // Device viewport accomidated the root and the top controls. |
| 8649 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
| 8650 | gfx::Transform identity_matrix; |
| 8651 | |
| 8652 | host_impl.active_tree()->SetRootLayer( |
| 8653 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8654 | |
| 8655 | LayerImpl* root = host_impl.active_tree()->root_layer(); |
| 8656 | SetLayerPropertiesForTesting(root, |
| 8657 | identity_matrix, |
| 8658 | gfx::Point3F(), |
| 8659 | gfx::PointF(), |
| 8660 | root_size, |
| 8661 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8662 | false, |
| 8663 | true); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8664 | |
| 8665 | root->SetContentBounds(root_size); |
| 8666 | root->SetMasksToBounds(true); |
| 8667 | |
| 8668 | root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2)); |
| 8669 | |
| 8670 | LayerImpl* sublayer = root->child_at(0); |
| 8671 | SetLayerPropertiesForTesting(sublayer, |
| 8672 | identity_matrix, |
| 8673 | gfx::Point3F(), |
| 8674 | gfx::PointF(), |
| 8675 | sublayer_size, |
| 8676 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8677 | false, |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8678 | false); |
| 8679 | |
| 8680 | sublayer->SetContentBounds(sublayer_size); |
| 8681 | sublayer->SetDrawsContent(true); |
| 8682 | |
| 8683 | LayerImplList layer_impl_list; |
| 8684 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8685 | root, device_viewport_size, &layer_impl_list); |
| 8686 | |
| 8687 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8688 | |
| 8689 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_content_rect()); |
| 8690 | |
| 8691 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
| 8692 | |
| 8693 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8694 | |
| 8695 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8696 | root_size.height() + 50); |
| 8697 | EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect()); |
| 8698 | } |
| 8699 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8700 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
| 8701 | const gfx::Transform identity_matrix; |
| 8702 | scoped_refptr<Layer> root = Layer::Create(); |
| 8703 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 8704 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 8705 | |
| 8706 | root->AddChild(animated); |
| 8707 | |
| 8708 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8709 | host->SetRootLayer(root); |
| 8710 | |
| 8711 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8712 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8713 | SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 8714 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 8715 | |
| 8716 | root->SetMasksToBounds(true); |
| 8717 | root->SetForceRenderSurface(true); |
| 8718 | animated->SetOpacity(0.f); |
| 8719 | |
| 8720 | AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0, |
| 8721 | 0.f, 1.f, false); |
| 8722 | |
| 8723 | ExecuteCalculateDrawProperties(root.get()); |
| 8724 | |
| 8725 | EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty()); |
| 8726 | } |
| 8727 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8728 | // Verify that having an animated filter (but no current filter, as these |
| 8729 | // are mutually exclusive) correctly creates a render surface. |
| 8730 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
| 8731 | scoped_refptr<Layer> root = Layer::Create(); |
| 8732 | scoped_refptr<Layer> child = Layer::Create(); |
| 8733 | scoped_refptr<Layer> grandchild = Layer::Create(); |
| 8734 | root->AddChild(child); |
| 8735 | child->AddChild(grandchild); |
| 8736 | |
| 8737 | gfx::Transform identity_transform; |
| 8738 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8739 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8740 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8741 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8742 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8743 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 8744 | true, false); |
| 8745 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8746 | host->SetRootLayer(root); |
| 8747 | |
| 8748 | AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f); |
| 8749 | |
| 8750 | ExecuteCalculateDrawProperties(root.get()); |
| 8751 | |
| 8752 | EXPECT_TRUE(root->render_surface()); |
| 8753 | EXPECT_TRUE(child->render_surface()); |
| 8754 | EXPECT_FALSE(grandchild->render_surface()); |
| 8755 | |
| 8756 | EXPECT_TRUE(root->filters().IsEmpty()); |
| 8757 | EXPECT_TRUE(child->filters().IsEmpty()); |
| 8758 | EXPECT_TRUE(grandchild->filters().IsEmpty()); |
| 8759 | |
| 8760 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8761 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 8762 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8763 | } |
| 8764 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8765 | // Ensures that the property tree code accounts for offsets between fixed |
| 8766 | // position layers and their respective containers. |
| 8767 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
| 8768 | scoped_refptr<Layer> root = Layer::Create(); |
| 8769 | scoped_refptr<Layer> child = Layer::Create(); |
| 8770 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
| 8771 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 8772 | |
| 8773 | root->AddChild(child); |
| 8774 | child->AddChild(grandchild); |
| 8775 | |
| 8776 | gfx::Transform identity_transform; |
| 8777 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8778 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8779 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8780 | gfx::PointF(1000, 1000), gfx::Size(50, 50), true, |
| 8781 | false); |
| 8782 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8783 | gfx::Point3F(), gfx::PointF(-1000, -1000), |
| 8784 | gfx::Size(50, 50), true, false); |
| 8785 | |
| 8786 | root->SetMasksToBounds(true); |
| 8787 | root->SetIsContainerForFixedPositionLayers(true); |
| 8788 | LayerPositionConstraint constraint; |
| 8789 | constraint.set_is_fixed_position(true); |
| 8790 | grandchild->SetPositionConstraint(constraint); |
| 8791 | |
| 8792 | root->SetIsContainerForFixedPositionLayers(true); |
| 8793 | |
| 8794 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8795 | host->SetRootLayer(root); |
| 8796 | |
| 8797 | ExecuteCalculateDrawProperties(root.get()); |
| 8798 | |
| 8799 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), |
| 8800 | grandchild->visible_rect_from_property_trees()); |
| 8801 | } |
| 8802 | |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 8803 | TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) { |
| 8804 | // In the following layer tree, the layer |box|'s render target is |surface|. |
| 8805 | // |surface| also creates a transform node. We want to combine clips for |box| |
| 8806 | // in the space of its target (i.e., |surface|), not its target's target. This |
| 8807 | // test ensures that happens. |
| 8808 | |
| 8809 | gfx::Transform rotate; |
| 8810 | rotate.Rotate(5); |
| 8811 | gfx::Transform identity; |
| 8812 | |
| 8813 | scoped_refptr<Layer> root = Layer::Create(); |
| 8814 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8815 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 8816 | false); |
| 8817 | |
| 8818 | scoped_refptr<Layer> frame_clip = Layer::Create(); |
| 8819 | SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), |
| 8820 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 8821 | false); |
| 8822 | frame_clip->SetMasksToBounds(true); |
| 8823 | |
| 8824 | scoped_refptr<Layer> rotated = Layer::Create(); |
| 8825 | SetLayerPropertiesForTesting(rotated.get(), rotate, |
| 8826 | gfx::Point3F(1250, 250, 0), gfx::PointF(), |
| 8827 | gfx::Size(2500, 500), true, false); |
| 8828 | |
| 8829 | scoped_refptr<Layer> surface = Layer::Create(); |
| 8830 | SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(), |
| 8831 | gfx::PointF(), gfx::Size(2500, 500), true, |
| 8832 | false); |
| 8833 | surface->SetOpacity(0.5); |
| 8834 | |
| 8835 | scoped_refptr<LayerWithForcedDrawsContent> container = |
| 8836 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 8837 | SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(), |
| 8838 | gfx::PointF(), gfx::Size(300, 300), true, false); |
| 8839 | |
| 8840 | scoped_refptr<LayerWithForcedDrawsContent> box = |
| 8841 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 8842 | SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(), |
| 8843 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8844 | |
| 8845 | root->AddChild(frame_clip); |
| 8846 | frame_clip->AddChild(rotated); |
| 8847 | rotated->AddChild(surface); |
| 8848 | surface->AddChild(container); |
| 8849 | surface->AddChild(box); |
| 8850 | |
| 8851 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8852 | host->SetRootLayer(root); |
| 8853 | |
| 8854 | ExecuteCalculateDrawProperties(root.get()); |
| 8855 | } |
| 8856 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame^] | 8857 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
| 8858 | gfx::Transform identity; |
| 8859 | gfx::Transform translate_z; |
| 8860 | translate_z.Translate3d(0, 0, 10); |
| 8861 | |
| 8862 | scoped_refptr<Layer> root = Layer::Create(); |
| 8863 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8864 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8865 | root->SetIsContainerForFixedPositionLayers(true); |
| 8866 | |
| 8867 | scoped_refptr<Layer> frame_clip = Layer::Create(); |
| 8868 | SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(), |
| 8869 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
| 8870 | false); |
| 8871 | frame_clip->SetMasksToBounds(true); |
| 8872 | |
| 8873 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
| 8874 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 8875 | SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(), |
| 8876 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 8877 | false); |
| 8878 | |
| 8879 | LayerPositionConstraint constraint; |
| 8880 | constraint.set_is_fixed_position(true); |
| 8881 | fixed->SetPositionConstraint(constraint); |
| 8882 | |
| 8883 | root->AddChild(frame_clip); |
| 8884 | frame_clip->AddChild(fixed); |
| 8885 | |
| 8886 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8887 | host->SetRootLayer(root); |
| 8888 | |
| 8889 | ExecuteCalculateDrawProperties(root.get()); |
| 8890 | |
| 8891 | gfx::Rect expected(0, 0, 100, 100); |
| 8892 | EXPECT_EQ(expected, fixed->visible_rect_from_property_trees()); |
| 8893 | } |
| 8894 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 8895 | } // namespace |
| 8896 | } // namespace cc |