[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()); |
| 1009 | |
| 1010 | gfx::Transform rotation_about_y_axis; |
| 1011 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1012 | |
| 1013 | const gfx::Transform identity_matrix; |
| 1014 | SetLayerPropertiesForTesting(root.get(), |
| 1015 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1016 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1017 | gfx::PointF(), |
| 1018 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1019 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1020 | false); |
| 1021 | SetLayerPropertiesForTesting(child.get(), |
| 1022 | rotation_about_y_axis, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1023 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1024 | gfx::PointF(), |
| 1025 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1026 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1027 | false); |
| 1028 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1029 | rotation_about_y_axis, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1030 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1031 | gfx::PointF(), |
| 1032 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1033 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1034 | false); |
| 1035 | |
| 1036 | root->AddChild(child); |
| 1037 | child->AddChild(grand_child); |
| 1038 | child->SetForceRenderSurface(true); |
| 1039 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1040 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1041 | host->SetRootLayer(root); |
| 1042 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1043 | // No layers in this test should preserve 3d. |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1044 | ASSERT_TRUE(root->should_flatten_transform()); |
| 1045 | ASSERT_TRUE(child->should_flatten_transform()); |
| 1046 | ASSERT_TRUE(grand_child->should_flatten_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1047 | |
| 1048 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1049 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1050 | gfx::Transform expected_grand_child_draw_transform = |
| 1051 | rotation_about_y_axis; // draws onto child's render surface |
| 1052 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1053 | flattened_rotation_about_y.FlattenTo2d(); |
| 1054 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1055 | flattened_rotation_about_y * rotation_about_y_axis; |
| 1056 | |
| 1057 | ExecuteCalculateDrawProperties(root.get()); |
| 1058 | |
| 1059 | // The child's draw transform should have been taken by its surface. |
| 1060 | ASSERT_TRUE(child->render_surface()); |
| 1061 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1062 | child->render_surface()->draw_transform()); |
| 1063 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1064 | expected_child_screen_space_transform, |
| 1065 | child->render_surface()->screen_space_transform()); |
| 1066 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1067 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
| 1068 | child->screen_space_transform()); |
| 1069 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
| 1070 | grand_child->draw_transform()); |
| 1071 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
| 1072 | grand_child->screen_space_transform()); |
| 1073 | } |
| 1074 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1075 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1076 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1077 | // skipping a necessary translation. Without that translation, the coordinate |
| 1078 | // space of the layer's draw transform is incorrect. |
| 1079 | // |
| 1080 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1081 | // but if that layer becomes a render surface, then its draw transform is |
| 1082 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1083 | // incorrectly as a result. |
| 1084 | |
| 1085 | scoped_refptr<Layer> root = Layer::Create(); |
| 1086 | scoped_refptr<Layer> child = Layer::Create(); |
| 1087 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1088 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1089 | |
| 1090 | // The child height is zero, but has non-zero width that should be accounted |
| 1091 | // for while computing draw transforms. |
| 1092 | const gfx::Transform identity_matrix; |
| 1093 | SetLayerPropertiesForTesting(root.get(), |
| 1094 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1095 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1096 | gfx::PointF(), |
| 1097 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1098 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1099 | false); |
| 1100 | SetLayerPropertiesForTesting(child.get(), |
| 1101 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1102 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1103 | gfx::PointF(), |
| 1104 | gfx::Size(10, 0), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1105 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1106 | false); |
| 1107 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1108 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1109 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1110 | gfx::PointF(), |
| 1111 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1112 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1113 | false); |
| 1114 | |
| 1115 | root->AddChild(child); |
| 1116 | child->AddChild(grand_child); |
| 1117 | child->SetForceRenderSurface(true); |
| 1118 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1119 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1120 | host->SetRootLayer(root); |
| 1121 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1122 | ExecuteCalculateDrawProperties(root.get()); |
| 1123 | |
| 1124 | ASSERT_TRUE(child->render_surface()); |
| 1125 | // This is the real test, the rest are sanity checks. |
| 1126 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1127 | child->render_surface()->draw_transform()); |
| 1128 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1129 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1130 | grand_child->draw_transform()); |
| 1131 | } |
| 1132 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1133 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1134 | // Transformations applied at the root of the tree should be forwarded |
| 1135 | // to child layers instead of applied to the root RenderSurface. |
| 1136 | const gfx::Transform identity_matrix; |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1137 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 1138 | new LayerWithForcedDrawsContent; |
| 1139 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1140 | new LayerWithForcedDrawsContent; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1141 | child->SetScrollClipLayerId(root->id()); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1142 | root->AddChild(child); |
| 1143 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1144 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1145 | host->SetRootLayer(root); |
| 1146 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1147 | SetLayerPropertiesForTesting(root.get(), |
| 1148 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1149 | gfx::Point3F(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1150 | gfx::PointF(), |
| 1151 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1152 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1153 | false); |
| 1154 | SetLayerPropertiesForTesting(child.get(), |
| 1155 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1156 | gfx::Point3F(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1157 | gfx::PointF(), |
| 1158 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1159 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1160 | false); |
| 1161 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1162 | gfx::Transform translate; |
| 1163 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1164 | { |
| 1165 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1166 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1167 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1168 | inputs.can_adjust_raster_scales = true; |
| 1169 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1170 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1171 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1172 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1173 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1174 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1175 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1176 | |
| 1177 | gfx::Transform scale; |
| 1178 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1179 | { |
| 1180 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1181 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1182 | root.get(), root->bounds(), scale, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1183 | inputs.can_adjust_raster_scales = true; |
| 1184 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1185 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1186 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1187 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1188 | EXPECT_EQ(2.f, root->draw_properties().device_scale_factor); |
| 1189 | EXPECT_EQ(2.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1190 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1191 | |
| 1192 | gfx::Transform rotate; |
| 1193 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1194 | { |
| 1195 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1196 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1197 | root.get(), root->bounds(), rotate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1198 | inputs.can_adjust_raster_scales = true; |
| 1199 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1200 | EXPECT_EQ(rotate, root->draw_properties().target_space_transform); |
| 1201 | EXPECT_EQ(rotate, child->draw_properties().target_space_transform); |
| 1202 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1203 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1204 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1205 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1206 | |
| 1207 | gfx::Transform composite; |
| 1208 | composite.ConcatTransform(translate); |
| 1209 | composite.ConcatTransform(scale); |
| 1210 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1211 | { |
| 1212 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1213 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1214 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1215 | inputs.can_adjust_raster_scales = true; |
| 1216 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1217 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1218 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1219 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1220 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1221 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1222 | // Verify it composes correctly with device scale. |
| 1223 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1224 | |
| 1225 | { |
| 1226 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1227 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1228 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1229 | inputs.device_scale_factor = device_scale_factor; |
| 1230 | inputs.can_adjust_raster_scales = true; |
| 1231 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1232 | gfx::Transform device_scaled_translate = translate; |
| 1233 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1234 | EXPECT_EQ(device_scaled_translate, |
| 1235 | root->draw_properties().target_space_transform); |
| 1236 | EXPECT_EQ(device_scaled_translate, |
| 1237 | child->draw_properties().target_space_transform); |
| 1238 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1239 | EXPECT_EQ(device_scale_factor, root->draw_properties().device_scale_factor); |
| 1240 | EXPECT_EQ(device_scale_factor, |
| 1241 | child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1242 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1243 | |
| 1244 | // Verify it composes correctly with page scale. |
| 1245 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1246 | |
| 1247 | { |
| 1248 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1249 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1250 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1251 | inputs.page_scale_factor = page_scale_factor; |
| 1252 | inputs.page_scale_application_layer = root.get(); |
| 1253 | inputs.can_adjust_raster_scales = true; |
| 1254 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1255 | gfx::Transform page_scaled_translate = translate; |
| 1256 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
| 1257 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1258 | EXPECT_EQ(page_scaled_translate, |
| 1259 | child->draw_properties().target_space_transform); |
| 1260 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1261 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1262 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1263 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1264 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1265 | // Verify that it composes correctly with transforms directly on root layer. |
| 1266 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1267 | |
| 1268 | { |
| 1269 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1270 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1271 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1272 | inputs.can_adjust_raster_scales = true; |
| 1273 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1274 | gfx::Transform compositeSquared = composite; |
| 1275 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1276 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1277 | compositeSquared, root->draw_properties().target_space_transform); |
| 1278 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1279 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1280 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1281 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1282 | } |
| 1283 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1284 | TEST_F(LayerTreeHostCommonTest, |
| 1285 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1286 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1287 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1288 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1289 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1290 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1291 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1292 | host->SetRootLayer(parent); |
| 1293 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1294 | const gfx::Transform identity_matrix; |
| 1295 | SetLayerPropertiesForTesting(parent.get(), |
| 1296 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1297 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1298 | gfx::PointF(), |
| 1299 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1300 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1301 | false); |
| 1302 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1303 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1304 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1305 | gfx::PointF(), |
| 1306 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1307 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1308 | false); |
| 1309 | SetLayerPropertiesForTesting(child.get(), |
| 1310 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1311 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1312 | gfx::PointF(30.f, 30.f), |
| 1313 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1314 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1315 | false); |
| 1316 | |
| 1317 | parent->AddChild(render_surface1); |
| 1318 | parent->SetMasksToBounds(true); |
| 1319 | render_surface1->AddChild(child); |
| 1320 | render_surface1->SetForceRenderSurface(true); |
| 1321 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1322 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1323 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1324 | parent.get(), |
| 1325 | parent->bounds(), |
| 1326 | gfx::Transform(), |
| 1327 | &render_surface_layer_list); |
| 1328 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1329 | |
| 1330 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1331 | // the intermediate render surface should not be listed here, even if it was |
| 1332 | // forced to be created. Render surfaces without children or visible content |
| 1333 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1334 | // of size 0). |
| 1335 | ASSERT_TRUE(parent->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1336 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1337 | } |
| 1338 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1339 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1340 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1341 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1342 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1343 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1344 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1345 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1346 | host->SetRootLayer(parent); |
| 1347 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1348 | const gfx::Transform identity_matrix; |
| 1349 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1350 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1351 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1352 | gfx::PointF(), |
| 1353 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1354 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1355 | false); |
| 1356 | SetLayerPropertiesForTesting(child.get(), |
| 1357 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1358 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1359 | gfx::PointF(), |
| 1360 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1361 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1362 | false); |
| 1363 | |
| 1364 | parent->AddChild(render_surface1); |
| 1365 | render_surface1->AddChild(child); |
| 1366 | render_surface1->SetForceRenderSurface(true); |
| 1367 | render_surface1->SetOpacity(0.f); |
| 1368 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1369 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1370 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1371 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1372 | inputs.can_adjust_raster_scales = true; |
| 1373 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1374 | |
| 1375 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1376 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1377 | // have been extended by the children. |
| 1378 | ASSERT_TRUE(parent->render_surface()); |
| 1379 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1380 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1381 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1382 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1383 | } |
| 1384 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1385 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
| 1386 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1387 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1388 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1389 | |
| 1390 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 1391 | host->SetRootLayer(parent); |
| 1392 | |
| 1393 | const gfx::Transform identity_matrix; |
| 1394 | const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode; |
| 1395 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 1396 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1397 | |
| 1398 | parent->AddChild(child); |
| 1399 | child->SetBlendMode(blend_mode); |
| 1400 | |
| 1401 | RenderSurfaceLayerList render_surface_layer_list; |
| 1402 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1403 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1404 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 1405 | |
| 1406 | // Since the child layer has a blend mode other than normal, it should get |
| 1407 | // its own render surface. Also, layer's draw_properties should contain the |
| 1408 | // default blend mode, since the render surface becomes responsible for |
| 1409 | // applying the blend mode. |
| 1410 | ASSERT_TRUE(child->render_surface()); |
| 1411 | EXPECT_EQ(1U, child->render_surface()->layer_list().size()); |
| 1412 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_properties().blend_mode); |
| 1413 | } |
| 1414 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1415 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1416 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1417 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1418 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1419 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1420 | render_surface1->SetForceRenderSurface(true); |
| 1421 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1422 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1423 | host->SetRootLayer(parent); |
| 1424 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1425 | const gfx::Transform identity_matrix; |
| 1426 | SetLayerPropertiesForTesting(parent.get(), |
| 1427 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1428 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1429 | gfx::PointF(), |
| 1430 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1431 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1432 | false); |
| 1433 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1434 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1435 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1436 | gfx::PointF(), |
| 1437 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1438 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1439 | false); |
| 1440 | SetLayerPropertiesForTesting(child.get(), |
| 1441 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1442 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1443 | gfx::PointF(), |
| 1444 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1445 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1446 | false); |
| 1447 | |
| 1448 | parent->AddChild(render_surface1); |
| 1449 | render_surface1->AddChild(child); |
| 1450 | |
| 1451 | // Sanity check before the actual test |
| 1452 | EXPECT_FALSE(parent->render_surface()); |
| 1453 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1454 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1455 | { |
| 1456 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1457 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1458 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1459 | inputs.can_adjust_raster_scales = true; |
| 1460 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1461 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1462 | // The root layer always creates a render surface |
| 1463 | EXPECT_TRUE(parent->render_surface()); |
| 1464 | EXPECT_TRUE(render_surface1->render_surface()); |
| 1465 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1466 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1467 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1468 | { |
| 1469 | RenderSurfaceLayerList render_surface_layer_list; |
| 1470 | render_surface1->SetForceRenderSurface(false); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1471 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1472 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1473 | inputs.can_adjust_raster_scales = true; |
| 1474 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1475 | EXPECT_TRUE(parent->render_surface()); |
| 1476 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1477 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1478 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1479 | } |
| 1480 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1481 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1482 | // The entire subtree of layers that are outside the clip rect should be |
| 1483 | // culled away, and should not affect the render_surface_layer_list. |
| 1484 | // |
| 1485 | // The test tree is set up as follows: |
| 1486 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1487 | // that have something to draw. |
| 1488 | // - parent is a large container layer. |
| 1489 | // - child has masksToBounds=true to cause clipping. |
| 1490 | // - grand_child is positioned outside of the child's bounds |
| 1491 | // - great_grand_child is also kept outside child's bounds. |
| 1492 | // |
| 1493 | // In this configuration, grand_child and great_grand_child are completely |
| 1494 | // outside the clip rect, and they should never get scheduled on the list of |
| 1495 | // render surfaces. |
| 1496 | // |
| 1497 | |
| 1498 | const gfx::Transform identity_matrix; |
| 1499 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1500 | scoped_refptr<Layer> child = Layer::Create(); |
| 1501 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1502 | scoped_refptr<Layer> great_grand_child = Layer::Create(); |
| 1503 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1504 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1505 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1506 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1507 | parent->AddChild(child); |
| 1508 | child->AddChild(grand_child); |
| 1509 | grand_child->AddChild(great_grand_child); |
| 1510 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1511 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1512 | host->SetRootLayer(parent); |
| 1513 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1514 | // leaf_node1 ensures that parent and child are kept on the |
| 1515 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1516 | // should be clipped. |
| 1517 | child->AddChild(leaf_node1); |
| 1518 | great_grand_child->AddChild(leaf_node2); |
| 1519 | |
| 1520 | SetLayerPropertiesForTesting(parent.get(), |
| 1521 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1522 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1523 | gfx::PointF(), |
| 1524 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1525 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1526 | false); |
| 1527 | SetLayerPropertiesForTesting(child.get(), |
| 1528 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1529 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1530 | gfx::PointF(), |
| 1531 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1532 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1533 | false); |
| 1534 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1535 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1536 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1537 | gfx::PointF(45.f, 45.f), |
| 1538 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1539 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1540 | false); |
| 1541 | SetLayerPropertiesForTesting(great_grand_child.get(), |
| 1542 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1543 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1544 | gfx::PointF(), |
| 1545 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1546 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1547 | false); |
| 1548 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1549 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1550 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1551 | gfx::PointF(), |
| 1552 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1553 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1554 | false); |
| 1555 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1556 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1557 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1558 | gfx::PointF(), |
| 1559 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1560 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1561 | false); |
| 1562 | |
| 1563 | child->SetMasksToBounds(true); |
| 1564 | child->SetOpacity(0.4f); |
| 1565 | child->SetForceRenderSurface(true); |
| 1566 | grand_child->SetOpacity(0.5f); |
| 1567 | great_grand_child->SetOpacity(0.4f); |
| 1568 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1569 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1570 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1571 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1572 | inputs.can_adjust_raster_scales = true; |
| 1573 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1574 | |
| 1575 | ASSERT_EQ(2U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1576 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1577 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1578 | } |
| 1579 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1580 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1581 | // When a render surface has a clip rect, it is used to clip the content rect |
| 1582 | // of the surface. When the render surface is animating its transforms, then |
| 1583 | // the content rect's position in the clip rect is not defined on the main |
| 1584 | // thread, and its content rect should not be clipped. |
| 1585 | |
| 1586 | // The test tree is set up as follows: |
| 1587 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1588 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1589 | // the parent. |
| 1590 | // - grand_child is a render surface, and the only visible content in child. |
| 1591 | // It is positioned outside of the clip rect from parent. |
| 1592 | |
| 1593 | // In this configuration, grand_child should be outside the clipped |
| 1594 | // content rect of the child, making grand_child not appear in the |
| 1595 | // render_surface_layer_list. However, when we place an animation on the |
| 1596 | // child, this clipping should be avoided and we should keep the grand_child |
| 1597 | // in the render_surface_layer_list. |
| 1598 | |
| 1599 | const gfx::Transform identity_matrix; |
| 1600 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1601 | scoped_refptr<Layer> child = Layer::Create(); |
| 1602 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1603 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node = |
| 1604 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1605 | parent->AddChild(child); |
| 1606 | child->AddChild(grand_child); |
| 1607 | grand_child->AddChild(leaf_node); |
| 1608 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1609 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1610 | host->SetRootLayer(parent); |
| 1611 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1612 | SetLayerPropertiesForTesting(parent.get(), |
| 1613 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1614 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1615 | gfx::PointF(), |
| 1616 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1617 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1618 | false); |
| 1619 | SetLayerPropertiesForTesting(child.get(), |
| 1620 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1621 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1622 | gfx::PointF(), |
| 1623 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1624 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1625 | false); |
| 1626 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1627 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1628 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1629 | gfx::PointF(200.f, 200.f), |
| 1630 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1631 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1632 | false); |
| 1633 | SetLayerPropertiesForTesting(leaf_node.get(), |
| 1634 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1635 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1636 | gfx::PointF(), |
| 1637 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1638 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1639 | false); |
| 1640 | |
| 1641 | parent->SetMasksToBounds(true); |
| 1642 | child->SetOpacity(0.4f); |
| 1643 | child->SetForceRenderSurface(true); |
| 1644 | grand_child->SetOpacity(0.4f); |
| 1645 | grand_child->SetForceRenderSurface(true); |
| 1646 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1647 | { |
| 1648 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1649 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1650 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1651 | inputs.can_adjust_raster_scales = true; |
| 1652 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1653 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1654 | // Without an animation, we should cull child and grand_child from the |
| 1655 | // render_surface_layer_list. |
| 1656 | ASSERT_EQ(1U, render_surface_layer_list.size()); |
| 1657 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1658 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1659 | |
| 1660 | // Now put an animating transform on child. |
| 1661 | AddAnimatedTransformToController( |
| 1662 | child->layer_animation_controller(), 10.0, 30, 0); |
| 1663 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1664 | { |
| 1665 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1666 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1667 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1668 | inputs.can_adjust_raster_scales = true; |
| 1669 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1670 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1671 | // With an animating transform, we should keep child and grand_child in the |
| 1672 | // render_surface_layer_list. |
| 1673 | ASSERT_EQ(3U, render_surface_layer_list.size()); |
| 1674 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1675 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
| 1676 | EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id()); |
| 1677 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1678 | } |
| 1679 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1680 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1681 | // Layer's IsClipped() property is set to true when: |
| 1682 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1683 | // - the layer is clipped by an ancestor that contributes to the same |
| 1684 | // render target, |
| 1685 | // - a surface is clipped by an ancestor that contributes to the same |
| 1686 | // render target. |
| 1687 | // |
| 1688 | // In particular, for a layer that owns a render surface: |
| 1689 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1690 | // pass that clipped status to the layer itself. |
| 1691 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1692 | // and propagates the clip to the subtree. |
| 1693 | |
| 1694 | const gfx::Transform identity_matrix; |
| 1695 | scoped_refptr<Layer> root = Layer::Create(); |
| 1696 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1697 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 1698 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 1699 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1700 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1701 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1702 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1703 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1704 | root->AddChild(parent); |
| 1705 | parent->AddChild(child1); |
| 1706 | parent->AddChild(child2); |
| 1707 | child1->AddChild(grand_child); |
| 1708 | child2->AddChild(leaf_node2); |
| 1709 | grand_child->AddChild(leaf_node1); |
| 1710 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1711 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1712 | host->SetRootLayer(root); |
| 1713 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1714 | child2->SetForceRenderSurface(true); |
| 1715 | |
| 1716 | SetLayerPropertiesForTesting(root.get(), |
| 1717 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1718 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1719 | gfx::PointF(), |
| 1720 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1721 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1722 | false); |
| 1723 | SetLayerPropertiesForTesting(parent.get(), |
| 1724 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1725 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1726 | gfx::PointF(), |
| 1727 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1728 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1729 | false); |
| 1730 | SetLayerPropertiesForTesting(child1.get(), |
| 1731 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1732 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1733 | gfx::PointF(), |
| 1734 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1735 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1736 | false); |
| 1737 | SetLayerPropertiesForTesting(child2.get(), |
| 1738 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1739 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1740 | gfx::PointF(), |
| 1741 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1742 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1743 | false); |
| 1744 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1745 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1746 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1747 | gfx::PointF(), |
| 1748 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1749 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1750 | false); |
| 1751 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1752 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1753 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1754 | gfx::PointF(), |
| 1755 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1756 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1757 | false); |
| 1758 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1759 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1760 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1761 | gfx::PointF(), |
| 1762 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1763 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1764 | false); |
| 1765 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1766 | // Case 1: nothing is clipped except the root render surface. |
| 1767 | { |
| 1768 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1769 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1770 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1771 | inputs.can_adjust_raster_scales = true; |
| 1772 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1773 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1774 | ASSERT_TRUE(root->render_surface()); |
| 1775 | ASSERT_TRUE(child2->render_surface()); |
| 1776 | |
| 1777 | EXPECT_FALSE(root->is_clipped()); |
| 1778 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1779 | EXPECT_FALSE(parent->is_clipped()); |
| 1780 | EXPECT_FALSE(child1->is_clipped()); |
| 1781 | EXPECT_FALSE(child2->is_clipped()); |
| 1782 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1783 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1784 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1785 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1786 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1787 | |
| 1788 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1789 | // surface are clipped. But layers that contribute to child2's surface are |
| 1790 | // not clipped explicitly because child2's surface already accounts for |
| 1791 | // that clip. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1792 | { |
| 1793 | RenderSurfaceLayerList render_surface_layer_list; |
| 1794 | parent->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1795 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1796 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1797 | inputs.can_adjust_raster_scales = true; |
| 1798 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1799 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1800 | ASSERT_TRUE(root->render_surface()); |
| 1801 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1802 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1803 | EXPECT_FALSE(root->is_clipped()); |
| 1804 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1805 | EXPECT_TRUE(parent->is_clipped()); |
| 1806 | EXPECT_TRUE(child1->is_clipped()); |
| 1807 | EXPECT_FALSE(child2->is_clipped()); |
| 1808 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1809 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1810 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1811 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1812 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1813 | |
| 1814 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1815 | // child2's render surface is not clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1816 | { |
| 1817 | RenderSurfaceLayerList render_surface_layer_list; |
| 1818 | parent->SetMasksToBounds(false); |
| 1819 | child2->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1820 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1821 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1822 | inputs.can_adjust_raster_scales = true; |
| 1823 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1824 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1825 | ASSERT_TRUE(root->render_surface()); |
| 1826 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1827 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1828 | EXPECT_FALSE(root->is_clipped()); |
| 1829 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1830 | EXPECT_FALSE(parent->is_clipped()); |
| 1831 | EXPECT_FALSE(child1->is_clipped()); |
| 1832 | EXPECT_TRUE(child2->is_clipped()); |
| 1833 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1834 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1835 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1836 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1837 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1838 | } |
| 1839 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 1840 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1841 | // Verify that layers get the appropriate DrawableContentRect when their |
| 1842 | // parent masksToBounds is true. |
| 1843 | // |
| 1844 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 1845 | // be the layer rect expressed in target space. |
| 1846 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 1847 | // will be the intersection of layer bounds and the mask region. |
| 1848 | // grand_child3 - partially clipped and masksToBounds; the |
| 1849 | // DrawableContentRect will still be the intersection of layer bounds and |
| 1850 | // the mask region. |
| 1851 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 1852 | // be empty. |
| 1853 | // |
| 1854 | |
| 1855 | const gfx::Transform identity_matrix; |
| 1856 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1857 | scoped_refptr<Layer> child = Layer::Create(); |
| 1858 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 1859 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 1860 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 1861 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 1862 | |
| 1863 | parent->AddChild(child); |
| 1864 | child->AddChild(grand_child1); |
| 1865 | child->AddChild(grand_child2); |
| 1866 | child->AddChild(grand_child3); |
| 1867 | child->AddChild(grand_child4); |
| 1868 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1869 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1870 | host->SetRootLayer(parent); |
| 1871 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1872 | SetLayerPropertiesForTesting(parent.get(), |
| 1873 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1874 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1875 | gfx::PointF(), |
| 1876 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1877 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1878 | false); |
| 1879 | SetLayerPropertiesForTesting(child.get(), |
| 1880 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1881 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1882 | gfx::PointF(), |
| 1883 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1884 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1885 | false); |
| 1886 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 1887 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1888 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1889 | gfx::PointF(5.f, 5.f), |
| 1890 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1891 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1892 | false); |
| 1893 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 1894 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1895 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1896 | gfx::PointF(15.f, 15.f), |
| 1897 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1898 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1899 | false); |
| 1900 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 1901 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1902 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1903 | gfx::PointF(15.f, 15.f), |
| 1904 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1905 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1906 | false); |
| 1907 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 1908 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1909 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1910 | gfx::PointF(45.f, 45.f), |
| 1911 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1912 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1913 | false); |
| 1914 | |
| 1915 | child->SetMasksToBounds(true); |
| 1916 | grand_child3->SetMasksToBounds(true); |
| 1917 | |
| 1918 | // Force everyone to be a render surface. |
| 1919 | child->SetOpacity(0.4f); |
| 1920 | grand_child1->SetOpacity(0.5f); |
| 1921 | grand_child2->SetOpacity(0.5f); |
| 1922 | grand_child3->SetOpacity(0.5f); |
| 1923 | grand_child4->SetOpacity(0.5f); |
| 1924 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1925 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1926 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1927 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1928 | inputs.can_adjust_raster_scales = true; |
| 1929 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1930 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 1931 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 1932 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 1933 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1934 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 1935 | } |
| 1936 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1937 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1938 | // Verify that render surfaces (and their layers) get the appropriate |
| 1939 | // clip rects when their parent masksToBounds is true. |
| 1940 | // |
| 1941 | // Layers that own render surfaces (at least for now) do not inherit any |
| 1942 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 1943 | // They may still have a clip rect of their own layer bounds, however, if |
| 1944 | // masksToBounds was true. |
| 1945 | const gfx::Transform identity_matrix; |
| 1946 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1947 | scoped_refptr<Layer> child = Layer::Create(); |
| 1948 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 1949 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 1950 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 1951 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 1952 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1953 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1954 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1955 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1956 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 = |
| 1957 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1958 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 = |
| 1959 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1960 | |
| 1961 | parent->AddChild(child); |
| 1962 | child->AddChild(grand_child1); |
| 1963 | child->AddChild(grand_child2); |
| 1964 | child->AddChild(grand_child3); |
| 1965 | child->AddChild(grand_child4); |
| 1966 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1967 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1968 | host->SetRootLayer(parent); |
| 1969 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1970 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 1971 | // this test. |
| 1972 | grand_child1->AddChild(leaf_node1); |
| 1973 | grand_child2->AddChild(leaf_node2); |
| 1974 | grand_child3->AddChild(leaf_node3); |
| 1975 | grand_child4->AddChild(leaf_node4); |
| 1976 | |
| 1977 | SetLayerPropertiesForTesting(parent.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(), |
| 1981 | gfx::Size(500, 500), |
[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(child.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(), |
| 1988 | gfx::Size(20, 20), |
[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_child1.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(5.f, 5.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 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 1999 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2000 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2001 | gfx::PointF(15.f, 15.f), |
| 2002 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2003 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2004 | false); |
| 2005 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2006 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2007 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2008 | gfx::PointF(15.f, 15.f), |
| 2009 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2010 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2011 | false); |
| 2012 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2013 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2014 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2015 | gfx::PointF(45.f, 45.f), |
| 2016 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2017 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2018 | false); |
| 2019 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 2020 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2021 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2022 | gfx::PointF(), |
| 2023 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2024 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2025 | false); |
| 2026 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 2027 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2028 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2029 | gfx::PointF(), |
| 2030 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2031 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2032 | false); |
| 2033 | SetLayerPropertiesForTesting(leaf_node3.get(), |
| 2034 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2035 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2036 | gfx::PointF(), |
| 2037 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2038 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2039 | false); |
| 2040 | SetLayerPropertiesForTesting(leaf_node4.get(), |
| 2041 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2042 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2043 | gfx::PointF(), |
| 2044 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2045 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2046 | false); |
| 2047 | |
| 2048 | child->SetMasksToBounds(true); |
| 2049 | grand_child3->SetMasksToBounds(true); |
| 2050 | grand_child4->SetMasksToBounds(true); |
| 2051 | |
| 2052 | // Force everyone to be a render surface. |
| 2053 | child->SetOpacity(0.4f); |
| 2054 | child->SetForceRenderSurface(true); |
| 2055 | grand_child1->SetOpacity(0.5f); |
| 2056 | grand_child1->SetForceRenderSurface(true); |
| 2057 | grand_child2->SetOpacity(0.5f); |
| 2058 | grand_child2->SetForceRenderSurface(true); |
| 2059 | grand_child3->SetOpacity(0.5f); |
| 2060 | grand_child3->SetForceRenderSurface(true); |
| 2061 | grand_child4->SetOpacity(0.5f); |
| 2062 | grand_child4->SetForceRenderSurface(true); |
| 2063 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2064 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2065 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2066 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2067 | inputs.can_adjust_raster_scales = true; |
| 2068 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2069 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2070 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2071 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2072 | |
| 2073 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2074 | // masksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2075 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2076 | grand_child1->render_surface()->clip_rect()); |
| 2077 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2078 | grand_child2->render_surface()->clip_rect()); |
| 2079 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2080 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2081 | } |
| 2082 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2083 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2084 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2085 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2086 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 2087 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 2088 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 2089 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 2090 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 2091 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 2092 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2093 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 2094 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2095 | parent->AddChild(render_surface1); |
| 2096 | parent->AddChild(child_of_root); |
| 2097 | render_surface1->AddChild(child_of_rs1); |
| 2098 | render_surface1->AddChild(render_surface2); |
| 2099 | render_surface2->AddChild(child_of_rs2); |
| 2100 | child_of_root->AddChild(grand_child_of_root); |
| 2101 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 2102 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 2103 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2104 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2105 | host->SetRootLayer(parent); |
| 2106 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2107 | // Make our render surfaces. |
| 2108 | render_surface1->SetForceRenderSurface(true); |
| 2109 | render_surface2->SetForceRenderSurface(true); |
| 2110 | |
| 2111 | gfx::Transform layer_transform; |
| 2112 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2113 | |
| 2114 | SetLayerPropertiesForTesting(parent.get(), |
| 2115 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2116 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2117 | gfx::PointF(2.5f, 0.f), |
| 2118 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2119 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2120 | false); |
| 2121 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2122 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2123 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2124 | gfx::PointF(2.5f, 0.f), |
| 2125 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2126 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2127 | false); |
| 2128 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 2129 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2130 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2131 | gfx::PointF(2.5f, 0.f), |
| 2132 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2133 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2134 | false); |
| 2135 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 2136 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2137 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2138 | gfx::PointF(2.5f, 0.f), |
| 2139 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2140 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2141 | false); |
| 2142 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 2143 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2144 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2145 | gfx::PointF(2.5f, 0.f), |
| 2146 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2147 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2148 | false); |
| 2149 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 2150 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2151 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2152 | gfx::PointF(2.5f, 0.f), |
| 2153 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2154 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2155 | false); |
| 2156 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 2157 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2158 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2159 | gfx::PointF(2.5f, 0.f), |
| 2160 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2161 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2162 | false); |
| 2163 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 2164 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2165 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2166 | gfx::PointF(2.5f, 0.f), |
| 2167 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2168 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2169 | false); |
| 2170 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 2171 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2172 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2173 | gfx::PointF(2.5f, 0.f), |
| 2174 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2175 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2176 | false); |
| 2177 | |
| 2178 | // Put an animated opacity on the render surface. |
| 2179 | AddOpacityTransitionToController( |
| 2180 | render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2181 | |
| 2182 | // Also put an animated opacity on a layer without descendants. |
| 2183 | AddOpacityTransitionToController( |
| 2184 | grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2185 | |
| 2186 | // Put a transform animation on the render surface. |
| 2187 | AddAnimatedTransformToController( |
| 2188 | render_surface2->layer_animation_controller(), 10.0, 30, 0); |
| 2189 | |
| 2190 | // Also put transform animations on grand_child_of_root, and |
| 2191 | // grand_child_of_rs2 |
| 2192 | AddAnimatedTransformToController( |
| 2193 | grand_child_of_root->layer_animation_controller(), 10.0, 30, 0); |
| 2194 | AddAnimatedTransformToController( |
| 2195 | grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0); |
| 2196 | |
| 2197 | ExecuteCalculateDrawProperties(parent.get()); |
| 2198 | |
| 2199 | // Only layers that are associated with render surfaces should have an actual |
| 2200 | // RenderSurface() value. |
| 2201 | ASSERT_TRUE(parent->render_surface()); |
| 2202 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2203 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2204 | |
| 2205 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2206 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2207 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2208 | |
| 2209 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2210 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2211 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2212 | |
| 2213 | // Verify all render target accessors |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2214 | EXPECT_EQ(parent.get(), parent->render_target()); |
| 2215 | EXPECT_EQ(parent.get(), child_of_root->render_target()); |
| 2216 | EXPECT_EQ(parent.get(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2217 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2218 | EXPECT_EQ(render_surface1.get(), render_surface1->render_target()); |
| 2219 | EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target()); |
| 2220 | EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2221 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2222 | EXPECT_EQ(render_surface2.get(), render_surface2->render_target()); |
| 2223 | EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target()); |
| 2224 | EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2225 | |
| 2226 | // Verify draw_opacity_is_animating values |
| 2227 | EXPECT_FALSE(parent->draw_opacity_is_animating()); |
| 2228 | EXPECT_FALSE(child_of_root->draw_opacity_is_animating()); |
| 2229 | EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating()); |
| 2230 | EXPECT_FALSE(render_surface1->draw_opacity_is_animating()); |
| 2231 | EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating()); |
| 2232 | EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating()); |
| 2233 | EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating()); |
| 2234 | EXPECT_FALSE(render_surface2->draw_opacity_is_animating()); |
| 2235 | EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating()); |
| 2236 | EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating()); |
| 2237 | EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating()); |
| 2238 | |
| 2239 | // Verify draw_transform_is_animating values |
| 2240 | EXPECT_FALSE(parent->draw_transform_is_animating()); |
| 2241 | EXPECT_FALSE(child_of_root->draw_transform_is_animating()); |
| 2242 | EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating()); |
| 2243 | EXPECT_FALSE(render_surface1->draw_transform_is_animating()); |
| 2244 | EXPECT_FALSE(render_surface1->render_surface() |
| 2245 | ->target_surface_transforms_are_animating()); |
| 2246 | EXPECT_FALSE(child_of_rs1->draw_transform_is_animating()); |
| 2247 | EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating()); |
| 2248 | EXPECT_FALSE(render_surface2->draw_transform_is_animating()); |
| 2249 | EXPECT_TRUE(render_surface2->render_surface() |
| 2250 | ->target_surface_transforms_are_animating()); |
| 2251 | EXPECT_FALSE(child_of_rs2->draw_transform_is_animating()); |
| 2252 | EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating()); |
| 2253 | |
| 2254 | // Verify screen_space_transform_is_animating values |
| 2255 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2256 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2257 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2258 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
| 2259 | EXPECT_FALSE(render_surface1->render_surface() |
| 2260 | ->screen_space_transforms_are_animating()); |
| 2261 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2262 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2263 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
| 2264 | EXPECT_TRUE(render_surface2->render_surface() |
| 2265 | ->screen_space_transforms_are_animating()); |
| 2266 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2267 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2268 | |
| 2269 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2270 | // It is expected that we correctly set up transforms so that the y-component |
| 2271 | // 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] | 2272 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 2273 | EXPECT_FLOAT_EQ(2.0, |
| 2274 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2275 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2276 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2277 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2278 | EXPECT_FLOAT_EQ(2.0, |
| 2279 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 2280 | EXPECT_FLOAT_EQ(3.0, |
| 2281 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2282 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2283 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2284 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2285 | EXPECT_FLOAT_EQ(3.0, |
| 2286 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 2287 | EXPECT_FLOAT_EQ(4.0, |
| 2288 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2289 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2290 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2291 | } |
| 2292 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2293 | TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2294 | // Test the calculateVisibleRect() function works correctly for identity |
| 2295 | // transforms. |
| 2296 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2297 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2298 | gfx::Transform layer_to_surface_transform; |
| 2299 | |
| 2300 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2301 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2302 | gfx::Rect expected = gfx::Rect(10, 10, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2303 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2304 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2305 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2306 | |
| 2307 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2308 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2309 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2310 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2311 | EXPECT_TRUE(actual.IsEmpty()); |
| 2312 | |
| 2313 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2314 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
| 2315 | expected = gfx::Rect(80, 80, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2316 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2317 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2318 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2319 | } |
| 2320 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2321 | TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2322 | // Test the calculateVisibleRect() function works correctly for scaling |
| 2323 | // transforms. |
| 2324 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2325 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2326 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2327 | gfx::Transform layer_to_surface_transform; |
| 2328 | |
| 2329 | // Case 1: Layer is contained within the surface. |
| 2330 | layer_to_surface_transform.MakeIdentity(); |
| 2331 | layer_to_surface_transform.Translate(10.0, 10.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2332 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2333 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2334 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2335 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2336 | |
| 2337 | // Case 2: Layer is outside the surface rect. |
| 2338 | layer_to_surface_transform.MakeIdentity(); |
| 2339 | layer_to_surface_transform.Translate(120.0, 120.0); |
| 2340 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2341 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2342 | EXPECT_TRUE(actual.IsEmpty()); |
| 2343 | |
| 2344 | // Case 3: Layer is partially overlapping the surface rect. |
| 2345 | layer_to_surface_transform.MakeIdentity(); |
| 2346 | layer_to_surface_transform.Translate(80.0, 80.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2347 | expected = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2348 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2349 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2350 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2351 | } |
| 2352 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2353 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2354 | // Test the calculateVisibleRect() function works correctly for rotations |
| 2355 | // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() |
| 2356 | // should return the g in the layer's space. |
| 2357 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2358 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2359 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2360 | gfx::Transform layer_to_surface_transform; |
| 2361 | |
| 2362 | // Case 1: Layer is contained within the surface. |
| 2363 | layer_to_surface_transform.MakeIdentity(); |
| 2364 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2365 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2366 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2367 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2368 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2369 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2370 | |
| 2371 | // Case 2: Layer is outside the surface rect. |
| 2372 | layer_to_surface_transform.MakeIdentity(); |
| 2373 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2374 | layer_to_surface_transform.Rotate(45.0); |
| 2375 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2376 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2377 | EXPECT_TRUE(actual.IsEmpty()); |
| 2378 | |
| 2379 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2380 | // the layer is oriented diagonally, with the left half outside of the render |
| 2381 | // surface. In this case, the g should still be the entire layer |
| 2382 | // (remember the g is computed in layer space); both the top-left |
| 2383 | // and bottom-right corners of the layer are still visible. |
| 2384 | layer_to_surface_transform.MakeIdentity(); |
| 2385 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2386 | expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2387 | 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 4: The layer is rotated about its top-left corner, and translated |
| 2392 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2393 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2394 | // surface overlaps the right side of the layer. The g should be |
| 2395 | // the layer's right half. |
| 2396 | layer_to_surface_transform.MakeIdentity(); |
| 2397 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2398 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2399 | expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. |
[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, VisibleRectFor3dOrthographicTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2406 | // Test that the calculateVisibleRect() function works correctly for 3d |
| 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, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2411 | gfx::Transform layer_to_surface_transform; |
| 2412 | |
| 2413 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2414 | // degrees, should be fully contained in the render surface. |
| 2415 | layer_to_surface_transform.MakeIdentity(); |
| 2416 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2417 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2418 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2419 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2420 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2421 | |
| 2422 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2423 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2424 | // visible on the surface. |
| 2425 | // 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] | 2426 | SkMScalar half_width_of_rotated_layer = |
| 2427 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2428 | layer_to_surface_transform.MakeIdentity(); |
| 2429 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2430 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2431 | // edge of the layer. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2432 | expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2433 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2434 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2435 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2436 | } |
| 2437 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2438 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2439 | // Test the calculateVisibleRect() function works correctly when the layer has |
| 2440 | // a perspective projection onto the target surface. |
| 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(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2444 | gfx::Transform layer_to_surface_transform; |
| 2445 | |
| 2446 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2447 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2448 | // its translated more than the perspective amount. |
| 2449 | layer_to_surface_transform.MakeIdentity(); |
| 2450 | |
| 2451 | // The following sequence of transforms applies the perspective about the |
| 2452 | // center of the surface. |
| 2453 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2454 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2455 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2456 | |
| 2457 | // This translate places the layer in front of the surface's projection plane. |
| 2458 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2459 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2460 | gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2461 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2462 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2463 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2464 | |
| 2465 | // Case 2: same projection as before, except that the layer is also translated |
| 2466 | // to the side, so that only the right half of the layer should be visible. |
| 2467 | // |
| 2468 | // Explanation of expected result: The perspective ratio is (z distance |
| 2469 | // between layer and camera origin) / (z distance between projection plane and |
| 2470 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
| 2471 | // move a layer by translating -50 units in projected surface units (so that |
| 2472 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
| 2473 | // -50 == -200 in the layer's units. |
| 2474 | layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2475 | expected = gfx::Rect(gfx::Point(50, -50), |
| 2476 | gfx::Size(100, 200)); // The right half of the layer's |
| 2477 | // bounding rect. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2478 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2479 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2480 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2481 | } |
| 2482 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2483 | TEST_F(LayerTreeHostCommonTest, |
| 2484 | VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2485 | // There is currently no explicit concept of an orthographic projection plane |
| 2486 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2487 | // are technically behind the surface in an orthographic world should not be |
| 2488 | // clipped when they are flattened to the surface. |
| 2489 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2490 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2491 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2492 | gfx::Transform layer_to_surface_transform; |
| 2493 | |
| 2494 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2495 | // at the center of the layer. |
| 2496 | layer_to_surface_transform.MakeIdentity(); |
| 2497 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2498 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2499 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2500 | |
[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 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2507 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2508 | // Test the calculateVisibleRect() function works correctly when projecting a |
| 2509 | // surface onto a layer, but the layer is partially behind the camera (not |
| 2510 | // just behind the projection plane). In this case, the cartesian coordinates |
| 2511 | // may seem to be valid, but actually they are not. The visible rect needs to |
| 2512 | // be properly clipped by the w = 0 plane in homogeneous coordinates before |
| 2513 | // converting to cartesian coordinates. |
| 2514 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2515 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2516 | gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2517 | gfx::Transform layer_to_surface_transform; |
| 2518 | |
| 2519 | // The layer is positioned so that the right half of the layer should be in |
| 2520 | // front of the camera, while the other half is behind the surface's |
| 2521 | // projection plane. The following sequence of transforms applies the |
| 2522 | // perspective and rotation about the center of the layer. |
| 2523 | layer_to_surface_transform.MakeIdentity(); |
| 2524 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2525 | layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); |
| 2526 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2527 | |
| 2528 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2529 | // transform, otherwise this code is not testing the intended scenario. |
| 2530 | bool clipped; |
| 2531 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2532 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2533 | &clipped); |
| 2534 | ASSERT_TRUE(clipped); |
| 2535 | |
| 2536 | int expected_x_position = 0; |
| 2537 | int expected_width = 10; |
| 2538 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2539 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2540 | EXPECT_EQ(expected_x_position, actual.x()); |
| 2541 | EXPECT_EQ(expected_width, actual.width()); |
| 2542 | } |
| 2543 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2544 | TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2545 | // To determine visible rect in layer space, there needs to be an |
| 2546 | // un-projection from surface space to layer space. When the original |
| 2547 | // transform was a perspective projection that was clipped, it returns a rect |
| 2548 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2549 | // clipping again. |
| 2550 | |
| 2551 | // This sequence of transforms causes one corner of the layer to protrude |
| 2552 | // across the w = 0 plane, and should be clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2553 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
| 2554 | gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2555 | gfx::Transform layer_to_surface_transform; |
| 2556 | layer_to_surface_transform.MakeIdentity(); |
| 2557 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2558 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2559 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2560 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2561 | |
| 2562 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2563 | // code is not testing the intended scenario. |
| 2564 | bool clipped; |
| 2565 | gfx::RectF clipped_rect = |
| 2566 | MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); |
| 2567 | MathUtil::ProjectQuad( |
| 2568 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2569 | ASSERT_TRUE(clipped); |
| 2570 | |
| 2571 | // Only the corner of the layer is not visible on the surface because of being |
| 2572 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2573 | // rect is that the entire layer should still be considered visible. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2574 | gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2575 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2576 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2577 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2578 | } |
| 2579 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2580 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2581 | scoped_refptr<Layer> root = Layer::Create(); |
| 2582 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2583 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2584 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2585 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2586 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2587 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2588 | root->AddChild(child1); |
| 2589 | root->AddChild(child2); |
| 2590 | root->AddChild(child3); |
| 2591 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2592 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2593 | host->SetRootLayer(root); |
| 2594 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2595 | gfx::Transform identity_matrix; |
| 2596 | SetLayerPropertiesForTesting(root.get(), |
| 2597 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2598 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2599 | gfx::PointF(), |
| 2600 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2601 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2602 | false); |
| 2603 | SetLayerPropertiesForTesting(child1.get(), |
| 2604 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2605 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2606 | gfx::PointF(), |
| 2607 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2608 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2609 | false); |
| 2610 | SetLayerPropertiesForTesting(child2.get(), |
| 2611 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2612 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2613 | gfx::PointF(75.f, 75.f), |
| 2614 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2615 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2616 | false); |
| 2617 | SetLayerPropertiesForTesting(child3.get(), |
| 2618 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2619 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2620 | gfx::PointF(125.f, 125.f), |
| 2621 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2622 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2623 | false); |
| 2624 | |
| 2625 | ExecuteCalculateDrawProperties(root.get()); |
| 2626 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2627 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2628 | root->render_surface()->DrawableContentRect()); |
| 2629 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2630 | |
| 2631 | // Layers that do not draw content should have empty visible_content_rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2632 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2633 | |
| 2634 | // layer visible_content_rects are clipped by their target surface. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2635 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2636 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2637 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 2638 | |
| 2639 | // layer drawable_content_rects are not clipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2640 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect()); |
| 2641 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2642 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2643 | } |
| 2644 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2645 | TEST_F(LayerTreeHostCommonTest, |
| 2646 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2647 | scoped_refptr<Layer> root = Layer::Create(); |
| 2648 | scoped_refptr<Layer> child = Layer::Create(); |
| 2649 | scoped_refptr<LayerWithForcedDrawsContent> grand_child1 = |
| 2650 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2651 | scoped_refptr<LayerWithForcedDrawsContent> grand_child2 = |
| 2652 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2653 | scoped_refptr<LayerWithForcedDrawsContent> grand_child3 = |
| 2654 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2655 | root->AddChild(child); |
| 2656 | child->AddChild(grand_child1); |
| 2657 | child->AddChild(grand_child2); |
| 2658 | child->AddChild(grand_child3); |
| 2659 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2660 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2661 | host->SetRootLayer(root); |
| 2662 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2663 | gfx::Transform identity_matrix; |
| 2664 | SetLayerPropertiesForTesting(root.get(), |
| 2665 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2666 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2667 | gfx::PointF(), |
| 2668 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2669 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2670 | false); |
| 2671 | SetLayerPropertiesForTesting(child.get(), |
| 2672 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2673 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2674 | gfx::PointF(), |
| 2675 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2676 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2677 | false); |
| 2678 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2679 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2680 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2681 | gfx::PointF(5.f, 5.f), |
| 2682 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2683 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2684 | false); |
| 2685 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2686 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2687 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2688 | gfx::PointF(75.f, 75.f), |
| 2689 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2690 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2691 | false); |
| 2692 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2693 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2694 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2695 | gfx::PointF(125.f, 125.f), |
| 2696 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2697 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2698 | false); |
| 2699 | |
| 2700 | child->SetMasksToBounds(true); |
| 2701 | ExecuteCalculateDrawProperties(root.get()); |
| 2702 | |
| 2703 | ASSERT_FALSE(child->render_surface()); |
| 2704 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2705 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2706 | root->render_surface()->DrawableContentRect()); |
| 2707 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2708 | |
| 2709 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2710 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2711 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2712 | |
| 2713 | // All grandchild visible content rects should be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2714 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect()); |
| 2715 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2716 | EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty()); |
| 2717 | |
| 2718 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2719 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 2720 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2721 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 2722 | } |
| 2723 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2724 | TEST_F(LayerTreeHostCommonTest, |
| 2725 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2726 | scoped_refptr<Layer> root = Layer::Create(); |
| 2727 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2728 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2729 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2730 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2731 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2732 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2733 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2734 | root->AddChild(render_surface1); |
| 2735 | render_surface1->AddChild(child1); |
| 2736 | render_surface1->AddChild(child2); |
| 2737 | render_surface1->AddChild(child3); |
| 2738 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2739 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2740 | host->SetRootLayer(root); |
| 2741 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2742 | gfx::Transform identity_matrix; |
| 2743 | SetLayerPropertiesForTesting(root.get(), |
| 2744 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2745 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2746 | gfx::PointF(), |
| 2747 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2748 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2749 | false); |
| 2750 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2751 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2752 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2753 | gfx::PointF(), |
| 2754 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2755 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2756 | false); |
| 2757 | SetLayerPropertiesForTesting(child1.get(), |
| 2758 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2759 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2760 | gfx::PointF(5.f, 5.f), |
| 2761 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2762 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2763 | false); |
| 2764 | SetLayerPropertiesForTesting(child2.get(), |
| 2765 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2766 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2767 | gfx::PointF(75.f, 75.f), |
| 2768 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2769 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2770 | false); |
| 2771 | SetLayerPropertiesForTesting(child3.get(), |
| 2772 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2773 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2774 | gfx::PointF(125.f, 125.f), |
| 2775 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2776 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2777 | false); |
| 2778 | |
| 2779 | render_surface1->SetForceRenderSurface(true); |
| 2780 | ExecuteCalculateDrawProperties(root.get()); |
| 2781 | |
| 2782 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2783 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2784 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2785 | root->render_surface()->DrawableContentRect()); |
| 2786 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2787 | |
| 2788 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2789 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2790 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2791 | |
| 2792 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 2793 | // regions of the subtree. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2794 | EXPECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 2795 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2796 | |
| 2797 | // All layers that draw content into the unclipped surface are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2798 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2799 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 2800 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2801 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2802 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 2803 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2804 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2805 | } |
| 2806 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2807 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2808 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
| 2809 | scoped_refptr<Layer> root = Layer::Create(); |
| 2810 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2811 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2812 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2813 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2814 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2815 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2816 | root->AddChild(child1); |
| 2817 | root->AddChild(child2); |
| 2818 | root->AddChild(child3); |
| 2819 | |
| 2820 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 2821 | host->SetRootLayer(root); |
| 2822 | |
| 2823 | gfx::Transform identity_matrix; |
| 2824 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 2825 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 2826 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(), |
| 2827 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 2828 | false); |
| 2829 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(), |
| 2830 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 2831 | false); |
| 2832 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, gfx::Point3F(), |
| 2833 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 2834 | true, false); |
| 2835 | |
| 2836 | RenderSurfaceLayerList render_surface_layer_list; |
| 2837 | // Now set the root render surface an empty clip. |
| 2838 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2839 | root.get(), gfx::Size(), &render_surface_layer_list); |
| 2840 | |
| 2841 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 2842 | ASSERT_TRUE(root->render_surface()); |
| 2843 | EXPECT_FALSE(root->is_clipped()); |
| 2844 | |
| 2845 | gfx::Rect empty; |
| 2846 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 2847 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2848 | |
| 2849 | // Visible content rect calculation will check if the target surface is |
| 2850 | // clipped or not. An empty clip rect does not indicate the render surface |
| 2851 | // is unclipped. |
| 2852 | EXPECT_EQ(empty, child1->visible_content_rect()); |
| 2853 | EXPECT_EQ(empty, child2->visible_content_rect()); |
| 2854 | EXPECT_EQ(empty, child3->visible_content_rect()); |
| 2855 | } |
| 2856 | |
| 2857 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2858 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2859 | scoped_refptr<Layer> root = Layer::Create(); |
| 2860 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2861 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2862 | root->AddChild(child); |
| 2863 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2864 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2865 | host->SetRootLayer(root); |
| 2866 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2867 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2868 | gfx::Transform identity_matrix; |
| 2869 | 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] | 2870 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2871 | |
| 2872 | SetLayerPropertiesForTesting(root.get(), |
| 2873 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2874 | gfx::Point3F(), |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2875 | gfx::PointF(), |
| 2876 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2877 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2878 | false); |
| 2879 | SetLayerPropertiesForTesting(child.get(), |
| 2880 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2881 | gfx::Point3F(), |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2882 | gfx::PointF(5.f, 5.f), |
| 2883 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2884 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2885 | false); |
| 2886 | |
| 2887 | ExecuteCalculateDrawProperties(root.get()); |
| 2888 | |
| 2889 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2890 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2891 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2892 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 2893 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2894 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2895 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2896 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2897 | |
| 2898 | SetLayerPropertiesForTesting(child.get(), |
| 2899 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2900 | gfx::Point3F(), |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2901 | gfx::PointF(5.f, 5.f), |
| 2902 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2903 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2904 | false); |
| 2905 | |
| 2906 | ExecuteCalculateDrawProperties(root.get()); |
| 2907 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2908 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2909 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2910 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2911 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2912 | uninvertible_matrix.MakeIdentity(); |
| 2913 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2914 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2915 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2916 | |
| 2917 | SetLayerPropertiesForTesting(child.get(), |
| 2918 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2919 | gfx::Point3F(), |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2920 | gfx::PointF(5.f, 5.f), |
| 2921 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2922 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2923 | false); |
| 2924 | |
| 2925 | ExecuteCalculateDrawProperties(root.get()); |
| 2926 | |
| 2927 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2928 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2929 | } |
| 2930 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2931 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2932 | SingularTransformDoesNotPreventClearingDrawProperties) { |
| 2933 | scoped_refptr<Layer> root = Layer::Create(); |
| 2934 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2935 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2936 | root->AddChild(child); |
| 2937 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2938 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2939 | host->SetRootLayer(root); |
| 2940 | |
| 2941 | gfx::Transform identity_matrix; |
| 2942 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 2943 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2944 | |
| 2945 | SetLayerPropertiesForTesting(root.get(), |
| 2946 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2947 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2948 | gfx::PointF(), |
| 2949 | gfx::Size(100, 100), |
| 2950 | true, |
| 2951 | false); |
| 2952 | SetLayerPropertiesForTesting(child.get(), |
| 2953 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2954 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2955 | gfx::PointF(5.f, 5.f), |
| 2956 | gfx::Size(50, 50), |
| 2957 | true, |
| 2958 | false); |
| 2959 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 2960 | child->draw_properties().sorted_for_recursion = true; |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2961 | |
| 2962 | TransformOperations start_transform_operations; |
| 2963 | start_transform_operations.AppendScale(1.f, 0.f, 0.f); |
| 2964 | |
| 2965 | TransformOperations end_transform_operations; |
| 2966 | end_transform_operations.AppendScale(1.f, 1.f, 0.f); |
| 2967 | |
| 2968 | AddAnimatedTransformToLayer( |
| 2969 | root.get(), 10.0, start_transform_operations, end_transform_operations); |
| 2970 | |
| 2971 | EXPECT_TRUE(root->TransformIsAnimating()); |
| 2972 | |
| 2973 | ExecuteCalculateDrawProperties(root.get()); |
| 2974 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 2975 | EXPECT_FALSE(child->draw_properties().sorted_for_recursion); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2976 | } |
| 2977 | |
eroman | 822f0dc3 | 2015-02-27 22:12:26 | [diff] [blame] | 2978 | TEST_F(LayerTreeHostCommonTest, WillSortAtContextBoundary) { |
| 2979 | // Creates a layer tree that looks as follows: |
| 2980 | // * root (sorting-context-id1) |
| 2981 | // * parent (sorting-context-id2) |
| 2982 | // * child1 (sorting-context-id2) |
| 2983 | // * child2 (sorting-context-id2) |
| 2984 | // |
| 2985 | // This test ensures that we sort at |parent| even though both it and root are |
| 2986 | // set to be 3d sorted. |
| 2987 | FakeImplProxy proxy; |
| 2988 | TestSharedBitmapManager shared_bitmap_manager; |
| 2989 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 2990 | |
| 2991 | scoped_ptr<LayerImpl> root_ptr(LayerImpl::Create(host_impl.active_tree(), 1)); |
| 2992 | LayerImpl* root = root_ptr.get(); |
| 2993 | scoped_ptr<LayerImpl> parent_ptr( |
| 2994 | LayerImpl::Create(host_impl.active_tree(), 2)); |
| 2995 | LayerImpl* parent = parent_ptr.get(); |
| 2996 | scoped_ptr<LayerImpl> child1_ptr( |
| 2997 | LayerImpl::Create(host_impl.active_tree(), 3)); |
| 2998 | LayerImpl* child1 = child1_ptr.get(); |
| 2999 | scoped_ptr<LayerImpl> child2_ptr( |
| 3000 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 3001 | LayerImpl* child2 = child2_ptr.get(); |
| 3002 | |
| 3003 | gfx::Transform identity_matrix; |
| 3004 | gfx::Transform below_matrix; |
| 3005 | below_matrix.Translate3d(0.f, 0.f, -10.f); |
| 3006 | gfx::Transform above_matrix; |
| 3007 | above_matrix.Translate3d(0.f, 0.f, 10.f); |
| 3008 | |
| 3009 | SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), |
| 3010 | gfx::PointF(), gfx::Size(100, 100), true, true, |
| 3011 | true); |
| 3012 | SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), |
| 3013 | gfx::PointF(), gfx::Size(50, 50), true, true, |
| 3014 | true); |
| 3015 | SetLayerPropertiesForTesting(child1, above_matrix, gfx::Point3F(), |
| 3016 | gfx::PointF(), gfx::Size(50, 50), true, true, |
| 3017 | false); |
| 3018 | SetLayerPropertiesForTesting(child2, below_matrix, gfx::Point3F(), |
| 3019 | gfx::PointF(), gfx::Size(50, 50), true, true, |
| 3020 | false); |
| 3021 | |
| 3022 | root->Set3dSortingContextId(3); |
| 3023 | root->SetDrawsContent(true); |
| 3024 | parent->Set3dSortingContextId(7); |
| 3025 | parent->SetDrawsContent(true); |
| 3026 | child1->Set3dSortingContextId(7); |
| 3027 | child1->SetDrawsContent(true); |
| 3028 | child2->Set3dSortingContextId(7); |
| 3029 | child2->SetDrawsContent(true); |
| 3030 | |
| 3031 | parent->AddChild(child1_ptr.Pass()); |
| 3032 | parent->AddChild(child2_ptr.Pass()); |
| 3033 | root->AddChild(parent_ptr.Pass()); |
| 3034 | |
| 3035 | LayerImplList render_surface_layer_list; |
| 3036 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 3037 | root_ptr.get(), root->bounds(), &render_surface_layer_list); |
| 3038 | inputs.can_adjust_raster_scales = true; |
| 3039 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 3040 | |
| 3041 | EXPECT_TRUE(root->render_surface()); |
| 3042 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
| 3043 | |
| 3044 | EXPECT_EQ(3u, parent->render_surface()->layer_list().size()); |
| 3045 | EXPECT_EQ(child2->id(), parent->render_surface()->layer_list().at(0)->id()); |
| 3046 | EXPECT_EQ(parent->id(), parent->render_surface()->layer_list().at(1)->id()); |
| 3047 | EXPECT_EQ(child1->id(), parent->render_surface()->layer_list().at(2)->id()); |
| 3048 | } |
| 3049 | |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3050 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3051 | SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) { |
| 3052 | scoped_refptr<Layer> root = Layer::Create(); |
| 3053 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3054 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3055 | host->SetRootLayer(root); |
| 3056 | |
| 3057 | gfx::Transform identity_matrix; |
| 3058 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 3059 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3060 | |
| 3061 | SetLayerPropertiesForTesting(root.get(), |
| 3062 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3063 | gfx::Point3F(), |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3064 | gfx::PointF(), |
| 3065 | gfx::Size(100, 100), |
| 3066 | true, |
| 3067 | false); |
| 3068 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 3069 | root->draw_properties().sorted_for_recursion = true; |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3070 | |
| 3071 | EXPECT_FALSE(root->TransformIsAnimating()); |
| 3072 | |
| 3073 | ExecuteCalculateDrawProperties(root.get()); |
| 3074 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 3075 | EXPECT_FALSE(root->draw_properties().sorted_for_recursion); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3079 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3080 | scoped_refptr<Layer> root = Layer::Create(); |
| 3081 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3082 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3083 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3084 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3085 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3086 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3087 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3088 | root->AddChild(render_surface1); |
| 3089 | render_surface1->AddChild(child1); |
| 3090 | render_surface1->AddChild(child2); |
| 3091 | render_surface1->AddChild(child3); |
| 3092 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3093 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3094 | host->SetRootLayer(root); |
| 3095 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3096 | gfx::Transform identity_matrix; |
| 3097 | SetLayerPropertiesForTesting(root.get(), |
| 3098 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3099 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3100 | gfx::PointF(), |
| 3101 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3102 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3103 | false); |
| 3104 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3105 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3106 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3107 | gfx::PointF(), |
| 3108 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3109 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3110 | false); |
| 3111 | SetLayerPropertiesForTesting(child1.get(), |
| 3112 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3113 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3114 | gfx::PointF(5.f, 5.f), |
| 3115 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3116 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3117 | false); |
| 3118 | SetLayerPropertiesForTesting(child2.get(), |
| 3119 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3120 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3121 | gfx::PointF(75.f, 75.f), |
| 3122 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3123 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3124 | false); |
| 3125 | SetLayerPropertiesForTesting(child3.get(), |
| 3126 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3127 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3128 | gfx::PointF(125.f, 125.f), |
| 3129 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3130 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3131 | false); |
| 3132 | |
| 3133 | root->SetMasksToBounds(true); |
| 3134 | render_surface1->SetForceRenderSurface(true); |
| 3135 | ExecuteCalculateDrawProperties(root.get()); |
| 3136 | |
| 3137 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3138 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3139 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3140 | root->render_surface()->DrawableContentRect()); |
| 3141 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3142 | |
| 3143 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3144 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3145 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3146 | |
| 3147 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3148 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3149 | EXPECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3150 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3151 | |
| 3152 | // All layers that draw content into the surface have their visible content |
| 3153 | // rect clipped by the surface clip rect. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3154 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3155 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3156 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 3157 | |
| 3158 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3159 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3160 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3161 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3162 | } |
| 3163 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3164 | TEST_F(LayerTreeHostCommonTest, |
| 3165 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3166 | // Check that clipping does not propagate down surfaces. |
| 3167 | scoped_refptr<Layer> root = Layer::Create(); |
| 3168 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3169 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 3170 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3171 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3172 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3173 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3174 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3175 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3176 | root->AddChild(render_surface1); |
| 3177 | render_surface1->AddChild(render_surface2); |
| 3178 | render_surface2->AddChild(child1); |
| 3179 | render_surface2->AddChild(child2); |
| 3180 | render_surface2->AddChild(child3); |
| 3181 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3182 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3183 | host->SetRootLayer(root); |
| 3184 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3185 | gfx::Transform identity_matrix; |
| 3186 | SetLayerPropertiesForTesting(root.get(), |
| 3187 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3188 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3189 | gfx::PointF(), |
| 3190 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3191 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3192 | false); |
| 3193 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3194 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3195 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3196 | gfx::PointF(), |
| 3197 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3198 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3199 | false); |
| 3200 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3201 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3202 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3203 | gfx::PointF(), |
| 3204 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3205 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3206 | false); |
| 3207 | SetLayerPropertiesForTesting(child1.get(), |
| 3208 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3209 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3210 | gfx::PointF(5.f, 5.f), |
| 3211 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3212 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3213 | false); |
| 3214 | SetLayerPropertiesForTesting(child2.get(), |
| 3215 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3216 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3217 | gfx::PointF(75.f, 75.f), |
| 3218 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3219 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3220 | false); |
| 3221 | SetLayerPropertiesForTesting(child3.get(), |
| 3222 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3223 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3224 | gfx::PointF(125.f, 125.f), |
| 3225 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3226 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3227 | false); |
| 3228 | |
| 3229 | root->SetMasksToBounds(true); |
| 3230 | render_surface1->SetForceRenderSurface(true); |
| 3231 | render_surface2->SetForceRenderSurface(true); |
| 3232 | ExecuteCalculateDrawProperties(root.get()); |
| 3233 | |
| 3234 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3235 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3236 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3237 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3238 | root->render_surface()->DrawableContentRect()); |
| 3239 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3240 | |
| 3241 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3242 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3243 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
| 3244 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3245 | |
| 3246 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3247 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3248 | EXPECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3249 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3250 | |
| 3251 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3252 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3253 | // render_surface2 grows to enclose all drawable content of its subtree. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3254 | EXPECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 3255 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3256 | |
| 3257 | // All layers that draw content into render_surface2 think they are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3258 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3259 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3260 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3261 | |
| 3262 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3263 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3264 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3265 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3266 | } |
| 3267 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3268 | TEST_F(LayerTreeHostCommonTest, |
| 3269 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3270 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3271 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3272 | |
| 3273 | scoped_refptr<Layer> root = Layer::Create(); |
| 3274 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3275 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3276 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3277 | root->AddChild(render_surface1); |
| 3278 | render_surface1->AddChild(child1); |
| 3279 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3280 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3281 | host->SetRootLayer(root); |
| 3282 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3283 | gfx::Transform identity_matrix; |
| 3284 | gfx::Transform child_rotation; |
| 3285 | child_rotation.Rotate(45.0); |
| 3286 | SetLayerPropertiesForTesting(root.get(), |
| 3287 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3288 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3289 | gfx::PointF(), |
| 3290 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3291 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3292 | false); |
| 3293 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3294 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3295 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3296 | gfx::PointF(), |
| 3297 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3298 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3299 | false); |
| 3300 | SetLayerPropertiesForTesting(child1.get(), |
| 3301 | child_rotation, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3302 | gfx::Point3F(25, 25, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3303 | gfx::PointF(25.f, 25.f), |
| 3304 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3305 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3306 | false); |
| 3307 | |
| 3308 | render_surface1->SetForceRenderSurface(true); |
| 3309 | ExecuteCalculateDrawProperties(root.get()); |
| 3310 | |
| 3311 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3312 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3313 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3314 | root->render_surface()->DrawableContentRect()); |
| 3315 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3316 | |
| 3317 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3318 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3319 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3320 | |
| 3321 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3322 | // regions of the subtree. |
| 3323 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3324 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3325 | gfx::Rect(50 - diagonal_radius, |
| 3326 | 50 - diagonal_radius, |
| 3327 | diagonal_radius * 2, |
| 3328 | diagonal_radius * 2); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3329 | EXPECT_EQ(expected_surface_drawable_content, |
| 3330 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3331 | |
| 3332 | // All layers that draw content into the unclipped surface are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3333 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3334 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3335 | } |
| 3336 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3337 | TEST_F(LayerTreeHostCommonTest, |
| 3338 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3339 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3340 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3341 | |
| 3342 | scoped_refptr<Layer> root = Layer::Create(); |
| 3343 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3344 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3345 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3346 | root->AddChild(render_surface1); |
| 3347 | render_surface1->AddChild(child1); |
| 3348 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3349 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3350 | host->SetRootLayer(root); |
| 3351 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3352 | gfx::Transform identity_matrix; |
| 3353 | gfx::Transform child_rotation; |
| 3354 | child_rotation.Rotate(45.0); |
| 3355 | SetLayerPropertiesForTesting(root.get(), |
| 3356 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3357 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3358 | gfx::PointF(), |
| 3359 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3360 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3361 | false); |
| 3362 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3363 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3364 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3365 | gfx::PointF(), |
| 3366 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3367 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3368 | false); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3369 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3370 | SetLayerPropertiesForTesting(child1.get(), |
| 3371 | child_rotation, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3372 | gfx::Point3F(25, 25, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3373 | gfx::PointF(25.f, 25.f), |
| 3374 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3375 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3376 | false); |
| 3377 | |
| 3378 | root->SetMasksToBounds(true); |
| 3379 | render_surface1->SetForceRenderSurface(true); |
| 3380 | ExecuteCalculateDrawProperties(root.get()); |
| 3381 | |
| 3382 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3383 | |
| 3384 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 3385 | // rotated layer. |
| 3386 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3387 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 3388 | 50 - diagonal_radius, |
| 3389 | diagonal_radius * 2, |
| 3390 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3391 | gfx::Rect expected_surface_drawable_content = |
| 3392 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3393 | EXPECT_EQ(expected_surface_drawable_content, |
| 3394 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3395 | |
| 3396 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3397 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 3398 | // up covering the full left half of child1. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3399 | // |
| 3400 | // Given the floating point math, this number is a little bit fuzzy. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3401 | EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3402 | |
| 3403 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3404 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3405 | } |
| 3406 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3407 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3408 | MockContentLayerClient client; |
| 3409 | |
| 3410 | scoped_refptr<Layer> root = Layer::Create(); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 3411 | scoped_refptr<FakePictureLayer> render_surface1 = |
| 3412 | CreateDrawablePictureLayer(&client); |
| 3413 | scoped_refptr<FakePictureLayer> render_surface2 = |
| 3414 | CreateDrawablePictureLayer(&client); |
| 3415 | scoped_refptr<FakePictureLayer> child1 = CreateDrawablePictureLayer(&client); |
| 3416 | scoped_refptr<FakePictureLayer> child2 = CreateDrawablePictureLayer(&client); |
| 3417 | scoped_refptr<FakePictureLayer> child3 = CreateDrawablePictureLayer(&client); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3418 | root->AddChild(render_surface1); |
| 3419 | render_surface1->AddChild(render_surface2); |
| 3420 | render_surface2->AddChild(child1); |
| 3421 | render_surface2->AddChild(child2); |
| 3422 | render_surface2->AddChild(child3); |
| 3423 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3424 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3425 | host->SetRootLayer(root); |
| 3426 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3427 | gfx::Transform identity_matrix; |
| 3428 | SetLayerPropertiesForTesting(root.get(), |
| 3429 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3430 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3431 | gfx::PointF(), |
| 3432 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3433 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3434 | false); |
| 3435 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3436 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3437 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3438 | gfx::PointF(5.f, 5.f), |
| 3439 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3440 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3441 | false); |
| 3442 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3443 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3444 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3445 | gfx::PointF(5.f, 5.f), |
| 3446 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3447 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3448 | false); |
| 3449 | SetLayerPropertiesForTesting(child1.get(), |
| 3450 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3451 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3452 | gfx::PointF(5.f, 5.f), |
| 3453 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3454 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3455 | false); |
| 3456 | SetLayerPropertiesForTesting(child2.get(), |
| 3457 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3458 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3459 | gfx::PointF(75.f, 75.f), |
| 3460 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3461 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3462 | false); |
| 3463 | SetLayerPropertiesForTesting(child3.get(), |
| 3464 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3465 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3466 | gfx::PointF(125.f, 125.f), |
| 3467 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3468 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3469 | false); |
| 3470 | |
| 3471 | float device_scale_factor = 2.f; |
| 3472 | |
| 3473 | root->SetMasksToBounds(true); |
| 3474 | render_surface1->SetForceRenderSurface(true); |
| 3475 | render_surface2->SetForceRenderSurface(true); |
| 3476 | ExecuteCalculateDrawProperties(root.get(), device_scale_factor); |
| 3477 | |
| 3478 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3479 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3480 | |
| 3481 | // drawable_content_rects for all layers and surfaces are scaled by |
| 3482 | // device_scale_factor. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3483 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 3484 | root->render_surface()->DrawableContentRect()); |
| 3485 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); |
| 3486 | EXPECT_EQ(gfx::Rect(10, 10, 190, 190), |
| 3487 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3488 | |
| 3489 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 3490 | // is only implicitly clipped by render_surface1. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3491 | EXPECT_EQ(gfx::Rect(10, 10, 350, 350), |
| 3492 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3493 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3494 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3495 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 3496 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3497 | |
| 3498 | // The root layer does not actually draw content of its own. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3499 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3500 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 3501 | // All layer visible content rects are not expressed in content space of each |
| 3502 | // layer, so they are not scaled by the device_scale_factor. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3503 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_content_rect()); |
| 3504 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_content_rect()); |
| 3505 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3506 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3507 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3508 | } |
| 3509 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3510 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3511 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 3512 | // layers. Note that 3d transforms still apply in this case, but they are |
| 3513 | // "flattened" to each parent layer according to current W3C spec. |
| 3514 | |
| 3515 | const gfx::Transform identity_matrix; |
| 3516 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3517 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3518 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3519 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3520 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3521 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3522 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3523 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3524 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3525 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3526 | front_facing_child_of_front_facing_surface = |
| 3527 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3528 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3529 | back_facing_child_of_front_facing_surface = |
| 3530 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3531 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3532 | front_facing_child_of_back_facing_surface = |
| 3533 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3534 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3535 | back_facing_child_of_back_facing_surface = |
| 3536 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3537 | |
| 3538 | parent->AddChild(front_facing_child); |
| 3539 | parent->AddChild(back_facing_child); |
| 3540 | parent->AddChild(front_facing_surface); |
| 3541 | parent->AddChild(back_facing_surface); |
| 3542 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3543 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3544 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3545 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3546 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3547 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3548 | host->SetRootLayer(parent); |
| 3549 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3550 | // Nothing is double-sided |
| 3551 | front_facing_child->SetDoubleSided(false); |
| 3552 | back_facing_child->SetDoubleSided(false); |
| 3553 | front_facing_surface->SetDoubleSided(false); |
| 3554 | back_facing_surface->SetDoubleSided(false); |
| 3555 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3556 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3557 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3558 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3559 | |
| 3560 | gfx::Transform backface_matrix; |
| 3561 | backface_matrix.Translate(50.0, 50.0); |
| 3562 | backface_matrix.RotateAboutYAxis(180.0); |
| 3563 | backface_matrix.Translate(-50.0, -50.0); |
| 3564 | |
| 3565 | // Having a descendant and opacity will force these to have render surfaces. |
| 3566 | front_facing_surface->SetOpacity(0.5f); |
| 3567 | back_facing_surface->SetOpacity(0.5f); |
| 3568 | |
| 3569 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 3570 | // these layers should blindly use their own local transforms to determine |
| 3571 | // back-face culling. |
| 3572 | SetLayerPropertiesForTesting(parent.get(), |
| 3573 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3574 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3575 | gfx::PointF(), |
| 3576 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3577 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3578 | false); |
| 3579 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3580 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3581 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3582 | gfx::PointF(), |
| 3583 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3584 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3585 | false); |
| 3586 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3587 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3588 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3589 | gfx::PointF(), |
| 3590 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3591 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3592 | false); |
| 3593 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3594 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3595 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3596 | gfx::PointF(), |
| 3597 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3598 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3599 | false); |
| 3600 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3601 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3602 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3603 | gfx::PointF(), |
| 3604 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3605 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3606 | false); |
| 3607 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3608 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3609 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3610 | gfx::PointF(), |
| 3611 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3612 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3613 | false); |
| 3614 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3615 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3616 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3617 | gfx::PointF(), |
| 3618 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3619 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3620 | false); |
| 3621 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3622 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3623 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3624 | gfx::PointF(), |
| 3625 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3626 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3627 | false); |
| 3628 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3629 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3630 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3631 | gfx::PointF(), |
| 3632 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3633 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3634 | false); |
| 3635 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3636 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3637 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3638 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3639 | inputs.can_adjust_raster_scales = true; |
| 3640 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3641 | |
| 3642 | // Verify which render surfaces were created. |
| 3643 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3644 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3645 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3646 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 3647 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3648 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3649 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3650 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3651 | |
| 3652 | // Verify the render_surface_layer_list. |
| 3653 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3654 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3655 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3656 | // Even though the back facing surface LAYER gets culled, the other |
| 3657 | // descendants should still be added, so the SURFACE should not be culled. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3658 | EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3659 | |
| 3660 | // Verify root surface's layer list. |
| 3661 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3662 | 3u, |
| 3663 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3664 | EXPECT_EQ(front_facing_child->id(), |
| 3665 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3666 | ->render_surface() |
| 3667 | ->layer_list() |
| 3668 | .at(0) |
| 3669 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3670 | EXPECT_EQ(front_facing_surface->id(), |
| 3671 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3672 | ->render_surface() |
| 3673 | ->layer_list() |
| 3674 | .at(1) |
| 3675 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3676 | EXPECT_EQ(back_facing_surface->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(2) |
| 3681 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3682 | |
| 3683 | // Verify front_facing_surface's layer list. |
| 3684 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3685 | 2u, |
| 3686 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3687 | EXPECT_EQ(front_facing_surface->id(), |
| 3688 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3689 | ->render_surface() |
| 3690 | ->layer_list() |
| 3691 | .at(0) |
| 3692 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3693 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3694 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3695 | ->render_surface() |
| 3696 | ->layer_list() |
| 3697 | .at(1) |
| 3698 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3699 | |
| 3700 | // Verify back_facing_surface's layer list; its own layer should be culled |
| 3701 | // from the surface list. |
| 3702 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3703 | 1u, |
| 3704 | render_surface_layer_list.at(2)->render_surface()->layer_list().size()); |
| 3705 | EXPECT_EQ(front_facing_child_of_back_facing_surface->id(), |
| 3706 | render_surface_layer_list.at(2) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3707 | ->render_surface() |
| 3708 | ->layer_list() |
| 3709 | .at(0) |
| 3710 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3711 | } |
| 3712 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3713 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3714 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 3715 | // is used. |
| 3716 | |
| 3717 | const gfx::Transform identity_matrix; |
| 3718 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3719 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3720 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3721 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3722 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3723 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3724 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3725 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3726 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3727 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3728 | front_facing_child_of_front_facing_surface = |
| 3729 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3730 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3731 | back_facing_child_of_front_facing_surface = |
| 3732 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3733 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3734 | front_facing_child_of_back_facing_surface = |
| 3735 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3736 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3737 | back_facing_child_of_back_facing_surface = |
| 3738 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3739 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 = |
| 3740 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3741 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 = |
| 3742 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3743 | |
| 3744 | parent->AddChild(front_facing_child); |
| 3745 | parent->AddChild(back_facing_child); |
| 3746 | parent->AddChild(front_facing_surface); |
| 3747 | parent->AddChild(back_facing_surface); |
| 3748 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3749 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3750 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3751 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3752 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3753 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3754 | host->SetRootLayer(parent); |
| 3755 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3756 | // Nothing is double-sided |
| 3757 | front_facing_child->SetDoubleSided(false); |
| 3758 | back_facing_child->SetDoubleSided(false); |
| 3759 | front_facing_surface->SetDoubleSided(false); |
| 3760 | back_facing_surface->SetDoubleSided(false); |
| 3761 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3762 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3763 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3764 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3765 | |
| 3766 | gfx::Transform backface_matrix; |
| 3767 | backface_matrix.Translate(50.0, 50.0); |
| 3768 | backface_matrix.RotateAboutYAxis(180.0); |
| 3769 | backface_matrix.Translate(-50.0, -50.0); |
| 3770 | |
| 3771 | // Opacity will not force creation of render surfaces in this case because of |
| 3772 | // the preserve-3d transform style. Instead, an example of when a surface |
| 3773 | // would be created with preserve-3d is when there is a replica layer. |
| 3774 | front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get()); |
| 3775 | back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get()); |
| 3776 | |
| 3777 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 3778 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 3779 | // rendering context should use the transform with respect to that context. |
| 3780 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 3781 | // and (b) the layer's transform style is preserve-3d. |
| 3782 | SetLayerPropertiesForTesting(parent.get(), |
| 3783 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3784 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3785 | gfx::PointF(), |
| 3786 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3787 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3788 | false); // parent transform style is flat. |
| 3789 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3790 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3791 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3792 | gfx::PointF(), |
| 3793 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3794 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3795 | false); |
| 3796 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3797 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3798 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3799 | gfx::PointF(), |
| 3800 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3801 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3802 | false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3803 | // surface transform style is preserve-3d. |
| 3804 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3805 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3806 | gfx::Point3F(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3807 | gfx::PointF(), |
| 3808 | gfx::Size(100, 100), |
| 3809 | false, |
| 3810 | true); |
| 3811 | // surface transform style is preserve-3d. |
| 3812 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3813 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3814 | gfx::Point3F(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3815 | gfx::PointF(), |
| 3816 | gfx::Size(100, 100), |
| 3817 | false, |
| 3818 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3819 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3820 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3821 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3822 | gfx::PointF(), |
| 3823 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3824 | true, |
| 3825 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3826 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3827 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3828 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3829 | gfx::PointF(), |
| 3830 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3831 | true, |
| 3832 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3833 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3834 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3835 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3836 | gfx::PointF(), |
| 3837 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3838 | true, |
| 3839 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3840 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3841 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3842 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3843 | gfx::PointF(), |
| 3844 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3845 | true, |
| 3846 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3847 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3848 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3849 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3850 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3851 | inputs.can_adjust_raster_scales = true; |
| 3852 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3853 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3854 | // Verify which render surfaces were created and used. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3855 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3856 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3857 | EXPECT_TRUE(front_facing_surface->render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3858 | EXPECT_NE(back_facing_surface->render_target(), back_facing_surface); |
| 3859 | // We expect that a render_surface was created but not used. |
| 3860 | EXPECT_TRUE(back_facing_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3861 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3862 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3863 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3864 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3865 | |
| 3866 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 3867 | // culled. |
| 3868 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3869 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3870 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3871 | |
| 3872 | // Verify root surface's layer list. |
| 3873 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3874 | 2u, |
| 3875 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3876 | EXPECT_EQ(front_facing_child->id(), |
| 3877 | render_surface_layer_list.at(0) |
| 3878 | ->render_surface()->layer_list().at(0)->id()); |
| 3879 | EXPECT_EQ(front_facing_surface->id(), |
| 3880 | render_surface_layer_list.at(0) |
| 3881 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3882 | |
| 3883 | // Verify front_facing_surface's layer list. |
| 3884 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3885 | 2u, |
| 3886 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3887 | EXPECT_EQ(front_facing_surface->id(), |
| 3888 | render_surface_layer_list.at(1) |
| 3889 | ->render_surface()->layer_list().at(0)->id()); |
| 3890 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3891 | render_surface_layer_list.at(1) |
| 3892 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3893 | } |
| 3894 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3895 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3896 | // Verify that layers are appropriately culled when their back face is showing |
| 3897 | // and they are not double sided, while animations are going on. |
| 3898 | // |
| 3899 | // Layers that are animating do not get culled on the main thread, as their |
| 3900 | // transforms should be treated as "unknown" so we can not be sure that their |
| 3901 | // back face is really showing. |
| 3902 | const gfx::Transform identity_matrix; |
| 3903 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3904 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 3905 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3906 | scoped_refptr<LayerWithForcedDrawsContent> animating_surface = |
| 3907 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3908 | scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = |
| 3909 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3910 | scoped_refptr<LayerWithForcedDrawsContent> animating_child = |
| 3911 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3912 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3913 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3914 | |
| 3915 | parent->AddChild(child); |
| 3916 | parent->AddChild(animating_surface); |
| 3917 | animating_surface->AddChild(child_of_animating_surface); |
| 3918 | parent->AddChild(animating_child); |
| 3919 | parent->AddChild(child2); |
| 3920 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3921 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3922 | host->SetRootLayer(parent); |
| 3923 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3924 | // Nothing is double-sided |
| 3925 | child->SetDoubleSided(false); |
| 3926 | child2->SetDoubleSided(false); |
| 3927 | animating_surface->SetDoubleSided(false); |
| 3928 | child_of_animating_surface->SetDoubleSided(false); |
| 3929 | animating_child->SetDoubleSided(false); |
| 3930 | |
| 3931 | gfx::Transform backface_matrix; |
| 3932 | backface_matrix.Translate(50.0, 50.0); |
| 3933 | backface_matrix.RotateAboutYAxis(180.0); |
| 3934 | backface_matrix.Translate(-50.0, -50.0); |
| 3935 | |
| 3936 | // Make our render surface. |
| 3937 | animating_surface->SetForceRenderSurface(true); |
| 3938 | |
| 3939 | // Animate the transform on the render surface. |
| 3940 | AddAnimatedTransformToController( |
| 3941 | animating_surface->layer_animation_controller(), 10.0, 30, 0); |
| 3942 | // This is just an animating layer, not a surface. |
| 3943 | AddAnimatedTransformToController( |
| 3944 | animating_child->layer_animation_controller(), 10.0, 30, 0); |
| 3945 | |
| 3946 | SetLayerPropertiesForTesting(parent.get(), |
| 3947 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3948 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3949 | gfx::PointF(), |
| 3950 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3951 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3952 | false); |
| 3953 | SetLayerPropertiesForTesting(child.get(), |
| 3954 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3955 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3956 | gfx::PointF(), |
| 3957 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3958 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3959 | false); |
| 3960 | SetLayerPropertiesForTesting(animating_surface.get(), |
| 3961 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3962 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3963 | gfx::PointF(), |
| 3964 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3965 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3966 | false); |
| 3967 | SetLayerPropertiesForTesting(child_of_animating_surface.get(), |
| 3968 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3969 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3970 | gfx::PointF(), |
| 3971 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3972 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3973 | false); |
| 3974 | SetLayerPropertiesForTesting(animating_child.get(), |
| 3975 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3976 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3977 | gfx::PointF(), |
| 3978 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3979 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3980 | false); |
| 3981 | SetLayerPropertiesForTesting(child2.get(), |
| 3982 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3983 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3984 | gfx::PointF(), |
| 3985 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3986 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3987 | false); |
| 3988 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3989 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3990 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3991 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3992 | inputs.can_adjust_raster_scales = true; |
| 3993 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3994 | |
| 3995 | EXPECT_FALSE(child->render_surface()); |
| 3996 | EXPECT_TRUE(animating_surface->render_surface()); |
| 3997 | EXPECT_FALSE(child_of_animating_surface->render_surface()); |
| 3998 | EXPECT_FALSE(animating_child->render_surface()); |
| 3999 | EXPECT_FALSE(child2->render_surface()); |
| 4000 | |
| 4001 | // Verify that the animating_child and child_of_animating_surface were not |
| 4002 | // culled, but that child was. |
| 4003 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4004 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4005 | EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4006 | |
| 4007 | // The non-animating child be culled from the layer list for the parent render |
| 4008 | // surface. |
| 4009 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4010 | 3u, |
| 4011 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4012 | EXPECT_EQ(animating_surface->id(), |
| 4013 | render_surface_layer_list.at(0) |
| 4014 | ->render_surface()->layer_list().at(0)->id()); |
| 4015 | EXPECT_EQ(animating_child->id(), |
| 4016 | render_surface_layer_list.at(0) |
| 4017 | ->render_surface()->layer_list().at(1)->id()); |
| 4018 | EXPECT_EQ(child2->id(), |
| 4019 | render_surface_layer_list.at(0) |
| 4020 | ->render_surface()->layer_list().at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4021 | |
| 4022 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4023 | 2u, |
| 4024 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4025 | EXPECT_EQ(animating_surface->id(), |
| 4026 | render_surface_layer_list.at(1) |
| 4027 | ->render_surface()->layer_list().at(0)->id()); |
| 4028 | EXPECT_EQ(child_of_animating_surface->id(), |
| 4029 | render_surface_layer_list.at(1) |
| 4030 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4031 | |
| 4032 | EXPECT_FALSE(child2->visible_content_rect().IsEmpty()); |
| 4033 | |
| 4034 | // The animating layers should have a visible content rect that represents the |
| 4035 | // area of the front face that is within the viewport. |
| 4036 | EXPECT_EQ(animating_child->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4037 | gfx::Rect(animating_child->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4038 | EXPECT_EQ(animating_surface->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4039 | gfx::Rect(animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4040 | // And layers in the subtree of the animating layer should have valid visible |
| 4041 | // content rects also. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4042 | EXPECT_EQ(child_of_animating_surface->visible_content_rect(), |
| 4043 | gfx::Rect(child_of_animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4044 | } |
| 4045 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4046 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4047 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4048 | // Verify the behavior of back-face culling for a render surface that is |
| 4049 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4050 | |
| 4051 | const gfx::Transform identity_matrix; |
| 4052 | scoped_refptr<Layer> parent = Layer::Create(); |
| 4053 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 4054 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4055 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 4056 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4057 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 4058 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4059 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 4060 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 4061 | |
| 4062 | parent->AddChild(front_facing_surface); |
| 4063 | parent->AddChild(back_facing_surface); |
| 4064 | front_facing_surface->AddChild(child1); |
| 4065 | back_facing_surface->AddChild(child2); |
| 4066 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4067 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4068 | host->SetRootLayer(parent); |
| 4069 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4070 | // RenderSurfaces are not double-sided |
| 4071 | front_facing_surface->SetDoubleSided(false); |
| 4072 | back_facing_surface->SetDoubleSided(false); |
| 4073 | |
| 4074 | gfx::Transform backface_matrix; |
| 4075 | backface_matrix.Translate(50.0, 50.0); |
| 4076 | backface_matrix.RotateAboutYAxis(180.0); |
| 4077 | backface_matrix.Translate(-50.0, -50.0); |
| 4078 | |
| 4079 | SetLayerPropertiesForTesting(parent.get(), |
| 4080 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4081 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4082 | gfx::PointF(), |
| 4083 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4084 | false, |
| 4085 | true); // parent transform style is preserve3d. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4086 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 4087 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4088 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4089 | gfx::PointF(), |
| 4090 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4091 | true, |
| 4092 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4093 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4094 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4095 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4096 | gfx::PointF(), |
| 4097 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4098 | true, |
| 4099 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4100 | SetLayerPropertiesForTesting(child1.get(), |
| 4101 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4102 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4103 | gfx::PointF(), |
| 4104 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4105 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4106 | false); |
| 4107 | SetLayerPropertiesForTesting(child2.get(), |
| 4108 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4109 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4110 | gfx::PointF(), |
| 4111 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4112 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4113 | false); |
| 4114 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4115 | front_facing_surface->Set3dSortingContextId(1); |
| 4116 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4117 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4118 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4119 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4120 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4121 | inputs.can_adjust_raster_scales = true; |
| 4122 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4123 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4124 | // Verify which render surfaces were created and used. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4125 | EXPECT_TRUE(front_facing_surface->render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4126 | |
| 4127 | // We expect the render surface to have been created, but remain unused. |
| 4128 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 4129 | EXPECT_NE(back_facing_surface->render_target(), |
| 4130 | back_facing_surface); // because it should be culled |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4131 | EXPECT_FALSE(child1->render_surface()); |
| 4132 | EXPECT_FALSE(child2->render_surface()); |
| 4133 | |
| 4134 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 4135 | // culled. |
| 4136 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4137 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4138 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4139 | |
| 4140 | // Verify root surface's layer list. |
| 4141 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4142 | 1u, |
| 4143 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4144 | EXPECT_EQ(front_facing_surface->id(), |
| 4145 | render_surface_layer_list.at(0) |
| 4146 | ->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4147 | |
| 4148 | // Verify front_facing_surface's layer list. |
| 4149 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4150 | 2u, |
| 4151 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4152 | EXPECT_EQ(front_facing_surface->id(), |
| 4153 | render_surface_layer_list.at(1) |
| 4154 | ->render_surface()->layer_list().at(0)->id()); |
| 4155 | EXPECT_EQ(child1->id(), |
| 4156 | render_surface_layer_list.at(1) |
| 4157 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4158 | } |
| 4159 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4160 | class NoScaleContentLayer : public ContentLayer { |
| 4161 | public: |
| 4162 | static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
| 4163 | return make_scoped_refptr(new NoScaleContentLayer(client)); |
| 4164 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4165 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 4166 | void CalculateContentsScale(float ideal_contents_scale, |
| 4167 | float* contents_scale_x, |
| 4168 | float* contents_scale_y, |
| 4169 | gfx::Size* content_bounds) override { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4170 | // Skip over the ContentLayer to the base Layer class. |
| 4171 | Layer::CalculateContentsScale(ideal_contents_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4172 | contents_scale_x, |
| 4173 | contents_scale_y, |
| 4174 | content_bounds); |
| 4175 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4176 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4177 | protected: |
| 4178 | explicit NoScaleContentLayer(ContentLayerClient* client) |
| 4179 | : ContentLayer(client) {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 4180 | ~NoScaleContentLayer() override {} |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4181 | }; |
| 4182 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4183 | scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer( |
| 4184 | ContentLayerClient* delegate) { |
| 4185 | scoped_refptr<NoScaleContentLayer> to_return = |
| 4186 | NoScaleContentLayer::Create(delegate); |
| 4187 | to_return->SetIsDrawable(true); |
| 4188 | return to_return; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4189 | } |
| 4190 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4191 | TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4192 | // Verify draw and screen space transforms of layers not in a surface. |
| 4193 | MockContentLayerClient delegate; |
| 4194 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4195 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4196 | scoped_refptr<FakePictureLayer> parent = |
| 4197 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4198 | SetLayerPropertiesForTesting(parent.get(), |
| 4199 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4200 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4201 | gfx::PointF(), |
| 4202 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4203 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4204 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4205 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4206 | scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4207 | SetLayerPropertiesForTesting(child.get(), |
| 4208 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4209 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4210 | gfx::PointF(2.f, 2.f), |
| 4211 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4212 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4213 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4214 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4215 | scoped_refptr<FakePictureLayer> child_empty = |
| 4216 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4217 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4218 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4219 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4220 | gfx::PointF(2.f, 2.f), |
| 4221 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4222 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4223 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4224 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4225 | parent->AddChild(child); |
| 4226 | parent->AddChild(child_empty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4227 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4228 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4229 | host->SetRootLayer(parent); |
| 4230 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4231 | float device_scale_factor = 2.5f; |
| 4232 | float page_scale_factor = 1.f; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4233 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4234 | RenderSurfaceLayerList render_surface_layer_list; |
| 4235 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4236 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4237 | inputs.device_scale_factor = device_scale_factor; |
| 4238 | inputs.page_scale_factor = page_scale_factor; |
| 4239 | inputs.can_adjust_raster_scales = true; |
| 4240 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4241 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4242 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4243 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4244 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child_empty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4245 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4246 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4247 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4248 | // Verify parent transforms |
| 4249 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4250 | expected_parent_transform.Scale(device_scale_factor * page_scale_factor, |
| 4251 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4252 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4253 | parent->screen_space_transform()); |
| 4254 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4255 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4256 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4257 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4258 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4259 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4260 | gfx::RectF parent_draw_rect = |
| 4261 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4262 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4263 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4264 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4265 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4266 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4267 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4268 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4269 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4270 | // Verify child and child_empty transforms. They should match. |
| 4271 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4272 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4273 | expected_child_transform.Translate(child->position().x(), |
| 4274 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4275 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4276 | child->draw_transform()); |
| 4277 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4278 | child->screen_space_transform()); |
| 4279 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4280 | child_empty->draw_transform()); |
| 4281 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4282 | child_empty->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4283 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4284 | // Verify results of transformed child and child_empty rects. They should |
| 4285 | // match. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4286 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4287 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4288 | gfx::RectF child_draw_rect = |
| 4289 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4290 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4291 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4292 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4293 | gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( |
| 4294 | child_empty->draw_transform(), child_content_bounds); |
| 4295 | gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( |
| 4296 | child_empty->screen_space_transform(), child_content_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4297 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4298 | gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); |
| 4299 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4300 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4301 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
| 4302 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); |
| 4303 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4304 | } |
| 4305 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4306 | TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4307 | // Verify draw and screen space transforms of layers in a surface. |
| 4308 | MockContentLayerClient delegate; |
| 4309 | gfx::Transform identity_matrix; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4310 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4311 | gfx::Transform perspective_matrix; |
| 4312 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4313 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4314 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4315 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4316 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4317 | scoped_refptr<Layer> root = Layer::Create(); |
| 4318 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4319 | scoped_refptr<FakePictureLayer> parent = |
| 4320 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4321 | SetLayerPropertiesForTesting(parent.get(), |
| 4322 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4323 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4324 | gfx::PointF(), |
| 4325 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4326 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4327 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4328 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4329 | scoped_refptr<FakePictureLayer> perspective_surface = |
| 4330 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4331 | SetLayerPropertiesForTesting(perspective_surface.get(), |
| 4332 | perspective_matrix * scale_small_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4333 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4334 | gfx::PointF(2.f, 2.f), |
| 4335 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4336 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4337 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4338 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4339 | scoped_refptr<FakePictureLayer> scale_surface = |
| 4340 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4341 | SetLayerPropertiesForTesting(scale_surface.get(), |
| 4342 | scale_small_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4343 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4344 | gfx::PointF(2.f, 2.f), |
| 4345 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4346 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4347 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4348 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4349 | perspective_surface->SetForceRenderSurface(true); |
| 4350 | scale_surface->SetForceRenderSurface(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4351 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4352 | parent->AddChild(perspective_surface); |
| 4353 | parent->AddChild(scale_surface); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4354 | root->AddChild(parent); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4355 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4356 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4357 | host->SetRootLayer(root); |
| 4358 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4359 | float device_scale_factor = 2.5f; |
| 4360 | float page_scale_factor = 3.f; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4361 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4362 | RenderSurfaceLayerList render_surface_layer_list; |
| 4363 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4364 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 4365 | inputs.device_scale_factor = device_scale_factor; |
| 4366 | inputs.page_scale_factor = page_scale_factor; |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 4367 | inputs.page_scale_application_layer = root.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4368 | inputs.can_adjust_raster_scales = true; |
| 4369 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4370 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4371 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4372 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4373 | perspective_surface); |
| 4374 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4375 | // the nearest render target. Here this includes the layer transform as well |
| 4376 | // as the device and page scale factors. |
| 4377 | gfx::Transform transform = scale_small_matrix; |
| 4378 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4379 | device_scale_factor * page_scale_factor); |
| 4380 | gfx::Vector2dF scales = |
| 4381 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4382 | float max_2d_scale = std::max(scales.x(), scales.y()); |
| 4383 | EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface); |
| 4384 | |
| 4385 | // The ideal scale will draw 1:1 with its render target space along |
| 4386 | // the larger-scale axis. |
| 4387 | gfx::Vector2dF target_space_transform_scales = |
| 4388 | MathUtil::ComputeTransform2dScaleComponents( |
| 4389 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4390 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4391 | std::max(target_space_transform_scales.x(), |
| 4392 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4393 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4394 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4395 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4396 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4397 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4398 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4399 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
| 4400 | parent->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4401 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4402 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4403 | // with the screen, and then scaled during drawing. |
| 4404 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4405 | expected_perspective_surface_draw_transform.Translate( |
| 4406 | device_scale_factor * page_scale_factor * |
| 4407 | perspective_surface->position().x(), |
| 4408 | device_scale_factor * page_scale_factor * |
| 4409 | perspective_surface->position().y()); |
| 4410 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4411 | perspective_matrix); |
| 4412 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4413 | scale_small_matrix); |
| 4414 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4415 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4416 | device_scale_factor * page_scale_factor, |
| 4417 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4418 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4419 | expected_perspective_surface_draw_transform, |
| 4420 | perspective_surface->render_surface()->draw_transform()); |
| 4421 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4422 | expected_perspective_surface_layer_draw_transform, |
| 4423 | perspective_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4424 | } |
| 4425 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4426 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4427 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4428 | LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { |
| 4429 | // Verify draw and screen space transforms of layers not in a surface. |
| 4430 | MockContentLayerClient delegate; |
| 4431 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4432 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4433 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4434 | SetLayerPropertiesForTesting(parent.get(), |
| 4435 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4436 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4437 | gfx::PointF(), |
| 4438 | gfx::Size(133, 133), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4439 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4440 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4441 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4442 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 4443 | SetLayerPropertiesForTesting(child.get(), |
| 4444 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4445 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4446 | gfx::PointF(), |
| 4447 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4448 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4449 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4450 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4451 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4452 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4453 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4454 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4455 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4456 | gfx::PointF(), |
| 4457 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4458 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4459 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4460 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4461 | parent->AddChild(child); |
| 4462 | parent->AddChild(child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4463 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4464 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4465 | host->SetRootLayer(parent); |
| 4466 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4467 | float device_scale_factor = 1.7f; |
| 4468 | float page_scale_factor = 1.f; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4469 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4470 | RenderSurfaceLayerList render_surface_layer_list; |
| 4471 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4472 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4473 | inputs.device_scale_factor = device_scale_factor; |
| 4474 | inputs.page_scale_factor = page_scale_factor; |
| 4475 | inputs.page_scale_application_layer = parent.get(); |
| 4476 | inputs.can_adjust_raster_scales = true; |
| 4477 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4478 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4479 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4480 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4481 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4482 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4483 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4484 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4485 | // Verify parent transforms |
| 4486 | gfx::Transform expected_parent_transform; |
| 4487 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4488 | parent->screen_space_transform()); |
| 4489 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4490 | parent->draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4491 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4492 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4493 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4494 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4495 | gfx::RectF parent_draw_rect = |
| 4496 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4497 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4498 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4499 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4500 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4501 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4502 | expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width())); |
| 4503 | expected_parent_draw_rect.set_height( |
| 4504 | ceil(expected_parent_draw_rect.height())); |
| 4505 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4506 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4507 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4508 | // Verify child transforms |
| 4509 | gfx::Transform expected_child_transform; |
| 4510 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4511 | child->draw_transform()); |
| 4512 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4513 | child->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4514 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4515 | // Verify results of transformed child rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4516 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4517 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4518 | gfx::RectF child_draw_rect = |
| 4519 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4520 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4521 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4522 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4523 | gfx::RectF expected_child_draw_rect(child->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4524 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4525 | expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width())); |
| 4526 | expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height())); |
| 4527 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4528 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4529 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4530 | // Verify child_no_scale transforms |
| 4531 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 4532 | // All transforms operate on content rects. The child's content rect |
| 4533 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 4534 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 4535 | device_scale_factor); |
| 4536 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4537 | child_no_scale->draw_transform()); |
| 4538 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4539 | child_no_scale->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4540 | } |
| 4541 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4542 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4543 | TEST_F(LayerTreeHostCommonTest, ContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4544 | MockContentLayerClient delegate; |
| 4545 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4546 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4547 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4548 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4549 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4550 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4551 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4552 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4553 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4554 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4555 | scoped_refptr<Layer> root = Layer::Create(); |
| 4556 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4557 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4558 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4559 | SetLayerPropertiesForTesting(parent.get(), |
| 4560 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4561 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4562 | gfx::PointF(), |
| 4563 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4564 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4565 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4566 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4567 | scoped_refptr<ContentLayer> child_scale = |
| 4568 | CreateDrawableContentLayer(&delegate); |
| 4569 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4570 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4571 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4572 | gfx::PointF(2.f, 2.f), |
| 4573 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4574 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4575 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4576 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4577 | scoped_refptr<ContentLayer> child_empty = |
| 4578 | CreateDrawableContentLayer(&delegate); |
| 4579 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4580 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4581 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4582 | gfx::PointF(2.f, 2.f), |
| 4583 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4584 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4585 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4586 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4587 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4588 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4589 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4590 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4591 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4592 | gfx::PointF(12.f, 12.f), |
| 4593 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4594 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4595 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4596 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4597 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4598 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4599 | parent->AddChild(child_scale); |
| 4600 | parent->AddChild(child_empty); |
| 4601 | parent->AddChild(child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4602 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4603 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4604 | host->SetRootLayer(root); |
| 4605 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4606 | float device_scale_factor = 2.5f; |
| 4607 | float page_scale_factor = 1.f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4608 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4609 | { |
| 4610 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4611 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4612 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4613 | inputs.device_scale_factor = device_scale_factor; |
| 4614 | inputs.page_scale_factor = page_scale_factor; |
| 4615 | inputs.page_scale_application_layer = root.get(); |
| 4616 | inputs.can_adjust_raster_scales = true; |
| 4617 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4618 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4619 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4620 | initial_parent_scale, parent); |
| 4621 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4622 | initial_parent_scale * initial_child_scale, |
| 4623 | child_scale); |
| 4624 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4625 | initial_parent_scale * initial_child_scale, |
| 4626 | child_empty); |
| 4627 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4628 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4629 | // The parent is scaled up and shouldn't need to scale during draw. The |
| 4630 | // child that can scale its contents should also not need to scale during |
| 4631 | // draw. This shouldn't change if the child has empty bounds. The other |
| 4632 | // children should. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4633 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 4634 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
| 4635 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0)); |
| 4636 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1)); |
| 4637 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0)); |
| 4638 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4639 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 4640 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4641 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4642 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4643 | initial_parent_scale * initial_child_scale, |
| 4644 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4645 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4646 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4647 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 4648 | // updated using the initial transform as the raster scale. |
| 4649 | device_scale_factor = 2.25f; |
| 4650 | page_scale_factor = 1.25f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4651 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4652 | { |
| 4653 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4654 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4655 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4656 | inputs.device_scale_factor = device_scale_factor; |
| 4657 | inputs.page_scale_factor = page_scale_factor; |
| 4658 | inputs.page_scale_application_layer = root.get(); |
| 4659 | inputs.can_adjust_raster_scales = true; |
| 4660 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 4661 | |
| 4662 | EXPECT_CONTENTS_SCALE_EQ( |
| 4663 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4664 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4665 | initial_parent_scale * initial_child_scale, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4666 | child_scale); |
| 4667 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4668 | initial_parent_scale * initial_child_scale, |
| 4669 | child_empty); |
| 4670 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4671 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4672 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4673 | // 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] | 4674 | SkMScalar second_child_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4675 | child_scale_matrix.Scale(second_child_scale / initial_child_scale, |
| 4676 | second_child_scale / initial_child_scale); |
| 4677 | child_scale->SetTransform(child_scale_matrix); |
| 4678 | child_empty->SetTransform(child_scale_matrix); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4679 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4680 | { |
| 4681 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4682 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4683 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4684 | inputs.device_scale_factor = device_scale_factor; |
| 4685 | inputs.page_scale_factor = page_scale_factor; |
| 4686 | inputs.page_scale_application_layer = root.get(); |
| 4687 | inputs.can_adjust_raster_scales = true; |
| 4688 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4689 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4690 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4691 | initial_parent_scale, |
| 4692 | parent); |
| 4693 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4694 | child_scale); |
| 4695 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4696 | child_empty); |
| 4697 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4698 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4699 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4700 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 4701 | // updated, but still using 1.0 as the raster scale. |
| 4702 | device_scale_factor = 2.75f; |
| 4703 | page_scale_factor = 1.75f; |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4704 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4705 | { |
| 4706 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4707 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4708 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4709 | inputs.device_scale_factor = device_scale_factor; |
| 4710 | inputs.page_scale_factor = page_scale_factor; |
| 4711 | inputs.page_scale_application_layer = root.get(); |
| 4712 | inputs.can_adjust_raster_scales = true; |
| 4713 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4714 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4715 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4716 | initial_parent_scale, |
| 4717 | parent); |
| 4718 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4719 | child_scale); |
| 4720 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4721 | child_empty); |
| 4722 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4723 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4724 | } |
| 4725 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4726 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4727 | TEST_F(LayerTreeHostCommonTest, |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4728 | ContentsScale_LayerTransformsDontAffectContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4729 | MockContentLayerClient delegate; |
| 4730 | gfx::Transform identity_matrix; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4731 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4732 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4733 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4734 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4735 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4736 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4737 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4738 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4739 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4740 | scoped_refptr<Layer> root = Layer::Create(); |
| 4741 | root->SetBounds(gfx::Size(100, 100)); |
| 4742 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4743 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4744 | SetLayerPropertiesForTesting(parent.get(), |
| 4745 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4746 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4747 | gfx::PointF(), |
| 4748 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4749 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4750 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4751 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4752 | scoped_refptr<ContentLayer> child_scale = |
| 4753 | CreateDrawableContentLayer(&delegate); |
| 4754 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4755 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4756 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4757 | gfx::PointF(2.f, 2.f), |
| 4758 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4759 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4760 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4761 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4762 | scoped_refptr<ContentLayer> child_empty = |
| 4763 | CreateDrawableContentLayer(&delegate); |
| 4764 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4765 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4766 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4767 | gfx::PointF(2.f, 2.f), |
| 4768 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4769 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4770 | true); |
| 4771 | |
| 4772 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4773 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4774 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4775 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4776 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4777 | gfx::PointF(12.f, 12.f), |
| 4778 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4779 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4780 | true); |
| 4781 | |
| 4782 | root->AddChild(parent); |
| 4783 | |
| 4784 | parent->AddChild(child_scale); |
| 4785 | parent->AddChild(child_empty); |
| 4786 | parent->AddChild(child_no_scale); |
| 4787 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4788 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4789 | host->SetRootLayer(root); |
| 4790 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4791 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4792 | |
| 4793 | float device_scale_factor = 2.5f; |
| 4794 | float page_scale_factor = 1.f; |
| 4795 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4796 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4797 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4798 | inputs.device_scale_factor = device_scale_factor; |
| 4799 | inputs.page_scale_factor = page_scale_factor; |
| 4800 | inputs.page_scale_application_layer = root.get(), |
| 4801 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4802 | |
| 4803 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4804 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4805 | child_scale); |
| 4806 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4807 | child_empty); |
| 4808 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4809 | |
| 4810 | // Since the transform scale does not affect contents scale, it should affect |
| 4811 | // the draw transform instead. |
| 4812 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4813 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4814 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4815 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4816 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4817 | child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4818 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4819 | child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4820 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4821 | child_empty->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4822 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4823 | child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4824 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4825 | initial_parent_scale * initial_child_scale, |
| 4826 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4827 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4828 | initial_parent_scale * initial_child_scale, |
| 4829 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4830 | } |
| 4831 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4832 | TEST_F(LayerTreeHostCommonTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4833 | MockContentLayerClient delegate; |
| 4834 | gfx::Transform identity_matrix; |
| 4835 | |
| 4836 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4837 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4838 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4839 | |
| 4840 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4841 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4842 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4843 | |
| 4844 | scoped_refptr<Layer> root = Layer::Create(); |
| 4845 | root->SetBounds(gfx::Size(100, 100)); |
| 4846 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4847 | scoped_refptr<FakePictureLayer> parent = |
| 4848 | CreateDrawablePictureLayer(&delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4849 | SetLayerPropertiesForTesting(parent.get(), |
| 4850 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4851 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4852 | gfx::PointF(), |
| 4853 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4854 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4855 | true); |
| 4856 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4857 | scoped_refptr<FakePictureLayer> child_scale = |
| 4858 | CreateDrawablePictureLayer(&delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4859 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4860 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4861 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4862 | gfx::PointF(2.f, 2.f), |
| 4863 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4864 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4865 | true); |
| 4866 | |
| 4867 | root->AddChild(parent); |
| 4868 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4869 | parent->AddChild(child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4870 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4871 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4872 | host->SetRootLayer(root); |
| 4873 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4874 | float device_scale_factor = 2.5f; |
| 4875 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4876 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4877 | { |
| 4878 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4879 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4880 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4881 | inputs.device_scale_factor = device_scale_factor; |
| 4882 | inputs.page_scale_factor = page_scale_factor; |
| 4883 | inputs.page_scale_application_layer = root.get(); |
| 4884 | inputs.can_adjust_raster_scales = true; |
| 4885 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4886 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4887 | // The ideal scale is able to go below 1. |
| 4888 | float expected_ideal_scale = |
| 4889 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4890 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4891 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4892 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4893 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4894 | initial_parent_scale * initial_child_scale; |
| 4895 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4896 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4897 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4898 | } |
| 4899 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4900 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4901 | MockContentLayerClient delegate; |
| 4902 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4903 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4904 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4905 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4906 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4907 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4908 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4909 | SkMScalar initial_child_scale = 3.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4910 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4911 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4912 | scoped_refptr<Layer> root = Layer::Create(); |
| 4913 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4914 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4915 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4916 | SetLayerPropertiesForTesting(parent.get(), |
| 4917 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4918 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4919 | gfx::PointF(), |
| 4920 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4921 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4922 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4923 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4924 | scoped_refptr<ContentLayer> surface_scale = |
| 4925 | CreateDrawableContentLayer(&delegate); |
| 4926 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 4927 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4928 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4929 | gfx::PointF(2.f, 2.f), |
| 4930 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4931 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4932 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4933 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4934 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 4935 | CreateDrawableContentLayer(&delegate); |
| 4936 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 4937 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4938 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4939 | gfx::PointF(), |
| 4940 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4941 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4942 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4943 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4944 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 4945 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4946 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 4947 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4948 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4949 | gfx::PointF(), |
| 4950 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4951 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4952 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4953 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4954 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 4955 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4956 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 4957 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4958 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4959 | gfx::PointF(12.f, 12.f), |
| 4960 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4961 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4962 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4963 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4964 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 4965 | CreateDrawableContentLayer(&delegate); |
| 4966 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 4967 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4968 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4969 | gfx::PointF(), |
| 4970 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4971 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4972 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4973 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4974 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 4975 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4976 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 4977 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4978 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4979 | gfx::PointF(), |
| 4980 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4981 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4982 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4983 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4984 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4985 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4986 | parent->AddChild(surface_scale); |
| 4987 | parent->AddChild(surface_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4988 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4989 | surface_scale->SetForceRenderSurface(true); |
| 4990 | surface_scale->AddChild(surface_scale_child_scale); |
| 4991 | surface_scale->AddChild(surface_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4992 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4993 | surface_no_scale->SetForceRenderSurface(true); |
| 4994 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 4995 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4996 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4997 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4998 | host->SetRootLayer(root); |
| 4999 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5000 | SkMScalar device_scale_factor = 5; |
| 5001 | SkMScalar page_scale_factor = 7; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5002 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5003 | RenderSurfaceLayerList render_surface_layer_list; |
| 5004 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5005 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5006 | inputs.device_scale_factor = device_scale_factor; |
| 5007 | inputs.page_scale_factor = page_scale_factor; |
| 5008 | inputs.page_scale_application_layer = root.get(); |
| 5009 | inputs.can_adjust_raster_scales = true; |
| 5010 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5011 | |
| 5012 | EXPECT_CONTENTS_SCALE_EQ( |
| 5013 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5014 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5015 | initial_parent_scale * initial_child_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5016 | surface_scale); |
| 5017 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale); |
| 5018 | EXPECT_CONTENTS_SCALE_EQ( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5019 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5020 | initial_child_scale * initial_child_scale, |
| 5021 | surface_scale_child_scale); |
| 5022 | EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale); |
| 5023 | EXPECT_CONTENTS_SCALE_EQ( |
| 5024 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5025 | initial_child_scale * initial_child_scale, |
| 5026 | surface_no_scale_child_scale); |
| 5027 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5028 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5029 | // The parent is scaled up and shouldn't need to scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5030 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 5031 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5032 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5033 | // RenderSurfaces should always be 1:1 with their target. |
| 5034 | EXPECT_FLOAT_EQ( |
| 5035 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5036 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5037 | EXPECT_FLOAT_EQ( |
| 5038 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5039 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[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 surface_scale can apply contents scale so the layer shouldn't need to |
| 5042 | // scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5043 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 5044 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5045 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5046 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 5047 | // to scale during draw. |
| 5048 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5049 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5050 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5051 | 1.0, surface_scale_child_scale->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_child_no_scale can not apply contents scale, so it needs |
| 5054 | // to be scaled during draw. |
| 5055 | EXPECT_FLOAT_EQ( |
| 5056 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5057 | initial_child_scale * initial_child_scale, |
| 5058 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5059 | EXPECT_FLOAT_EQ( |
| 5060 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5061 | initial_child_scale * initial_child_scale, |
| 5062 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5063 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5064 | // RenderSurfaces should always be 1:1 with their target. |
| 5065 | EXPECT_FLOAT_EQ( |
| 5066 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5067 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5068 | EXPECT_FLOAT_EQ( |
| 5069 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5070 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5071 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5072 | // The surface_no_scale layer can not apply contents scale, so it needs to be |
| 5073 | // scaled during draw. |
| 5074 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5075 | initial_parent_scale * initial_child_scale, |
| 5076 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5077 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5078 | initial_parent_scale * initial_child_scale, |
| 5079 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5080 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5081 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 5082 | // to scale during draw. |
| 5083 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5084 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5085 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5086 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5087 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5088 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 5089 | // to be scaled during draw. |
| 5090 | EXPECT_FLOAT_EQ( |
| 5091 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5092 | initial_child_scale * initial_child_scale, |
| 5093 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5094 | EXPECT_FLOAT_EQ( |
| 5095 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5096 | initial_child_scale * initial_child_scale, |
| 5097 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5098 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5099 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5100 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5101 | TEST_F(LayerTreeHostCommonTest, |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5102 | ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5103 | MockContentLayerClient delegate; |
| 5104 | gfx::Transform identity_matrix; |
| 5105 | |
| 5106 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5107 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5108 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 5109 | |
| 5110 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5111 | SkMScalar initial_child_scale = 3.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5112 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 5113 | |
| 5114 | scoped_refptr<Layer> root = Layer::Create(); |
| 5115 | root->SetBounds(gfx::Size(100, 100)); |
| 5116 | |
| 5117 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 5118 | SetLayerPropertiesForTesting(parent.get(), |
| 5119 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5120 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5121 | gfx::PointF(), |
| 5122 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5123 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5124 | true); |
| 5125 | |
| 5126 | scoped_refptr<ContentLayer> surface_scale = |
| 5127 | CreateDrawableContentLayer(&delegate); |
| 5128 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 5129 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5130 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5131 | gfx::PointF(2.f, 2.f), |
| 5132 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5133 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5134 | true); |
| 5135 | |
| 5136 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 5137 | CreateDrawableContentLayer(&delegate); |
| 5138 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 5139 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5140 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5141 | gfx::PointF(), |
| 5142 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5143 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5144 | true); |
| 5145 | |
| 5146 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 5147 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5148 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 5149 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5150 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5151 | gfx::PointF(), |
| 5152 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5153 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5154 | true); |
| 5155 | |
| 5156 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 5157 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5158 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 5159 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5160 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5161 | gfx::PointF(12.f, 12.f), |
| 5162 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5163 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5164 | true); |
| 5165 | |
| 5166 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 5167 | CreateDrawableContentLayer(&delegate); |
| 5168 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 5169 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5170 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5171 | gfx::PointF(), |
| 5172 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5173 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5174 | true); |
| 5175 | |
| 5176 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 5177 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5178 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 5179 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5180 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5181 | gfx::PointF(), |
| 5182 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5183 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5184 | true); |
| 5185 | |
| 5186 | root->AddChild(parent); |
| 5187 | |
| 5188 | parent->AddChild(surface_scale); |
| 5189 | parent->AddChild(surface_no_scale); |
| 5190 | |
| 5191 | surface_scale->SetForceRenderSurface(true); |
| 5192 | surface_scale->AddChild(surface_scale_child_scale); |
| 5193 | surface_scale->AddChild(surface_scale_child_no_scale); |
| 5194 | |
| 5195 | surface_no_scale->SetForceRenderSurface(true); |
| 5196 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 5197 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
| 5198 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5199 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5200 | host->SetRootLayer(root); |
| 5201 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5202 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5203 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5204 | SkMScalar device_scale_factor = 5.0; |
| 5205 | SkMScalar page_scale_factor = 7.0; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5206 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5207 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5208 | inputs.device_scale_factor = device_scale_factor; |
| 5209 | inputs.page_scale_factor = page_scale_factor; |
| 5210 | inputs.page_scale_application_layer = root.get(); |
| 5211 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5212 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5213 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5214 | parent); |
| 5215 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5216 | surface_scale); |
| 5217 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale); |
| 5218 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5219 | surface_scale_child_scale); |
| 5220 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale); |
| 5221 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5222 | surface_no_scale_child_scale); |
| 5223 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale); |
| 5224 | |
| 5225 | // The parent is scaled up during draw, since its contents are not scaled by |
| 5226 | // the transform hierarchy. |
| 5227 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5228 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5229 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5230 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5231 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5232 | // 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] | 5233 | // by the transform hierarchy. |
| 5234 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5235 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5236 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5237 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5238 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5239 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5240 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5241 | // The surface_scale's RenderSurface is not scaled during draw, so the layer |
| 5242 | // needs to be scaled when drawing into its surface. |
| 5243 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 5244 | surface_scale->draw_transform().matrix().get(0, 0)); |
| 5245 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 5246 | surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5247 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5248 | // The surface_scale_child_scale is not scaled when drawing into its surface, |
| 5249 | // since its content bounds are scaled by the transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5250 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5251 | initial_child_scale * initial_child_scale * initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5252 | surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5253 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5254 | initial_child_scale * initial_child_scale * initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5255 | surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5256 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5257 | // The surface_scale_child_no_scale is scaled by the device scale, page scale |
| 5258 | // and transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5259 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5260 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5261 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5262 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5263 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5264 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5265 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5266 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5267 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5268 | // 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] | 5269 | // by the transform hierarchy. |
| 5270 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5271 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5272 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5273 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5274 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5275 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5276 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5277 | // The surface_no_scale layer has a fixed contents scale of 1, so it needs to |
| 5278 | // be scaled by the device and page scale factors. Its surface is already |
| 5279 | // scaled by the transform hierarchy so those don't need to scale the layer's |
| 5280 | // drawing. |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5281 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale * |
| 5282 | device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5283 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5284 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale * |
| 5285 | device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5286 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5287 | |
| 5288 | // The surface_no_scale_child_scale has its contents scaled by the page and |
| 5289 | // device scale factors, but needs to be scaled by the transform hierarchy |
| 5290 | // when drawing. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5291 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5292 | initial_parent_scale * initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5293 | surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5294 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5295 | initial_parent_scale * initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5296 | surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5297 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5298 | // The surface_no_scale_child_no_scale needs to be scaled by the device and |
| 5299 | // page scale factors and by any transform heirarchy below its target surface. |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5300 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5301 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5302 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5303 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5304 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5305 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5306 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5307 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5308 | } |
| 5309 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5310 | TEST_F(LayerTreeHostCommonTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5311 | MockContentLayerClient delegate; |
| 5312 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5313 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5314 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5315 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5316 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5317 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5318 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5319 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5320 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5321 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5322 | scoped_refptr<Layer> root = Layer::Create(); |
| 5323 | root->SetBounds(gfx::Size(100, 100)); |
| 5324 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5325 | scoped_refptr<FakePictureLayer> parent = |
| 5326 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5327 | SetLayerPropertiesForTesting(parent.get(), |
| 5328 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5329 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5330 | gfx::PointF(), |
| 5331 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5332 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5333 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5334 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5335 | scoped_refptr<FakePictureLayer> child_scale = |
| 5336 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5337 | SetLayerPropertiesForTesting(child_scale.get(), |
| 5338 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5339 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5340 | gfx::PointF(2.f, 2.f), |
| 5341 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5342 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5343 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5344 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5345 | root->AddChild(parent); |
| 5346 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5347 | parent->AddChild(child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5348 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5349 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5350 | host->SetRootLayer(root); |
| 5351 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5352 | { |
| 5353 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5354 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5355 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5356 | inputs.can_adjust_raster_scales = true; |
| 5357 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5358 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5359 | EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); |
| 5360 | // Animating layers compute ideal scale in the same way as when |
| 5361 | // they are static. |
| 5362 | EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, |
| 5363 | child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5364 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5365 | } |
| 5366 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5367 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5368 | TEST_F(LayerTreeHostCommonTest, |
| 5369 | ChangeInContentBoundsOrScaleTriggersPushProperties) { |
| 5370 | MockContentLayerClient delegate; |
| 5371 | scoped_refptr<Layer> root = Layer::Create(); |
| 5372 | scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate); |
| 5373 | root->AddChild(child); |
| 5374 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5375 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5376 | host->SetRootLayer(root); |
| 5377 | |
| 5378 | gfx::Transform identity_matrix; |
| 5379 | SetLayerPropertiesForTesting(root.get(), |
| 5380 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5381 | gfx::Point3F(), |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5382 | gfx::PointF(), |
| 5383 | gfx::Size(100, 100), |
| 5384 | true, |
| 5385 | false); |
| 5386 | SetLayerPropertiesForTesting(child.get(), |
| 5387 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5388 | gfx::Point3F(), |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5389 | gfx::PointF(), |
| 5390 | gfx::Size(100, 100), |
| 5391 | true, |
| 5392 | false); |
| 5393 | |
| 5394 | root->reset_needs_push_properties_for_testing(); |
| 5395 | child->reset_needs_push_properties_for_testing(); |
| 5396 | |
| 5397 | // This will change both layers' content bounds. |
| 5398 | ExecuteCalculateDrawProperties(root.get()); |
| 5399 | EXPECT_TRUE(root->needs_push_properties()); |
| 5400 | EXPECT_TRUE(child->needs_push_properties()); |
| 5401 | |
| 5402 | root->reset_needs_push_properties_for_testing(); |
| 5403 | child->reset_needs_push_properties_for_testing(); |
| 5404 | |
| 5405 | // This will change only the child layer's contents scale and content bounds, |
| 5406 | // since the root layer is not a ContentsScalingLayer. |
| 5407 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 5408 | EXPECT_FALSE(root->needs_push_properties()); |
| 5409 | EXPECT_TRUE(child->needs_push_properties()); |
| 5410 | |
| 5411 | root->reset_needs_push_properties_for_testing(); |
| 5412 | child->reset_needs_push_properties_for_testing(); |
| 5413 | |
| 5414 | // This will not change either layer's contents scale or content bounds. |
| 5415 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 5416 | EXPECT_FALSE(root->needs_push_properties()); |
| 5417 | EXPECT_FALSE(child->needs_push_properties()); |
| 5418 | } |
| 5419 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5420 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5421 | MockContentLayerClient delegate; |
| 5422 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5423 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5424 | scoped_refptr<FakePictureLayer> parent = |
| 5425 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5426 | SetLayerPropertiesForTesting(parent.get(), |
| 5427 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5428 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5429 | gfx::PointF(), |
| 5430 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5431 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5432 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5433 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5434 | scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5435 | SetLayerPropertiesForTesting(child.get(), |
| 5436 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5437 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5438 | gfx::PointF(2.f, 2.f), |
| 5439 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5440 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5441 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5442 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5443 | gfx::Transform replica_transform; |
| 5444 | replica_transform.Scale(1.0, -1.0); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5445 | scoped_refptr<FakePictureLayer> replica = |
| 5446 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5447 | SetLayerPropertiesForTesting(replica.get(), |
| 5448 | replica_transform, |
[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 | // This layer should end up in the same surface as child, with the same draw |
| 5456 | // and screen space transforms. |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5457 | scoped_refptr<FakePictureLayer> duplicate_child_non_owner = |
| 5458 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5459 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 5460 | identity_matrix, |
[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(), |
| 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 | parent->AddChild(child); |
| 5468 | child->AddChild(duplicate_child_non_owner); |
| 5469 | child->SetReplicaLayer(replica.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5470 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5471 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5472 | host->SetRootLayer(parent); |
| 5473 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5474 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5475 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5476 | float device_scale_factor = 1.5f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5477 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5478 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5479 | inputs.device_scale_factor = device_scale_factor; |
| 5480 | inputs.can_adjust_raster_scales = true; |
| 5481 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5482 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5483 | // We should have two render surfaces. The root's render surface and child's |
| 5484 | // render surface (it needs one because it has a replica layer). |
| 5485 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5486 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5487 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5488 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5489 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5490 | parent->screen_space_transform()); |
| 5491 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5492 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5493 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5494 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5495 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5496 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
| 5497 | child->draw_transform()); |
[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_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5500 | expected_screen_space_transform.Scale(device_scale_factor, |
| 5501 | device_scale_factor); |
| 5502 | expected_screen_space_transform.Translate(child->position().x(), |
| 5503 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5504 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 5505 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5506 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5507 | gfx::Transform expected_duplicate_child_draw_transform = |
| 5508 | child->draw_transform(); |
| 5509 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), |
| 5510 | duplicate_child_non_owner->draw_transform()); |
| 5511 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5512 | child->screen_space_transform(), |
| 5513 | duplicate_child_non_owner->screen_space_transform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 5514 | EXPECT_EQ(child->drawable_content_rect(), |
| 5515 | duplicate_child_non_owner->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5516 | EXPECT_EQ(child->content_bounds(), |
| 5517 | duplicate_child_non_owner->content_bounds()); |
[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_render_surface_draw_transform; |
| 5520 | expected_render_surface_draw_transform.Translate( |
| 5521 | device_scale_factor * child->position().x(), |
| 5522 | device_scale_factor * child->position().y()); |
| 5523 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 5524 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5525 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5526 | gfx::Transform expected_surface_draw_transform; |
| 5527 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 5528 | device_scale_factor * 2.f); |
| 5529 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 5530 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5531 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5532 | gfx::Transform expected_surface_screen_space_transform; |
| 5533 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 5534 | device_scale_factor * 2.f); |
| 5535 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5536 | expected_surface_screen_space_transform, |
| 5537 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5538 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5539 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5540 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 5541 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 5542 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5543 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5544 | expected_replica_draw_transform, |
| 5545 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5546 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5547 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5548 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 5549 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 5550 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5551 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5552 | expected_replica_screen_space_transform, |
| 5553 | child->render_surface()->replica_screen_space_transform()); |
| 5554 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5555 | expected_replica_screen_space_transform, |
| 5556 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5557 | } |
| 5558 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5559 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5560 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
| 5561 | MockContentLayerClient delegate; |
| 5562 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5563 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5564 | scoped_refptr<FakePictureLayer> parent = |
| 5565 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5566 | SetLayerPropertiesForTesting(parent.get(), |
| 5567 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5568 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5569 | gfx::PointF(), |
| 5570 | gfx::Size(33, 31), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5571 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5572 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5573 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5574 | scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5575 | SetLayerPropertiesForTesting(child.get(), |
| 5576 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5577 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5578 | gfx::PointF(), |
| 5579 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5580 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5581 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5582 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5583 | gfx::Transform replica_transform; |
| 5584 | replica_transform.Scale(1.0, -1.0); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5585 | scoped_refptr<FakePictureLayer> replica = |
| 5586 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5587 | SetLayerPropertiesForTesting(replica.get(), |
| 5588 | replica_transform, |
[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 | parent->AddChild(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5596 | child->SetReplicaLayer(replica.get()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5597 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5598 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5599 | host->SetRootLayer(parent); |
| 5600 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 5601 | float device_scale_factor = 1.7f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5602 | |
| 5603 | RenderSurfaceLayerList render_surface_layer_list; |
| 5604 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5605 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5606 | inputs.device_scale_factor = device_scale_factor; |
| 5607 | inputs.can_adjust_raster_scales = true; |
| 5608 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5609 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5610 | // We should have two render surfaces. The root's render surface and child's |
| 5611 | // render surface (it needs one because it has a replica layer). |
| 5612 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5613 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5614 | gfx::Transform identity_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5615 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5616 | child->render_surface()->draw_transform()); |
| 5617 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5618 | child->render_surface()->draw_transform()); |
| 5619 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5620 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5621 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5622 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5623 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5624 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5625 | expected_replica_draw_transform, |
| 5626 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5627 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5628 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5629 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5630 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5631 | expected_replica_screen_space_transform, |
| 5632 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5633 | } |
| 5634 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5635 | TEST_F(LayerTreeHostCommonTest, SubtreeSearch) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5636 | scoped_refptr<Layer> root = Layer::Create(); |
| 5637 | scoped_refptr<Layer> child = Layer::Create(); |
| 5638 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5639 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 5640 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5641 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5642 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 5643 | child->AddChild(grand_child.get()); |
| 5644 | child->SetMaskLayer(mask_layer.get()); |
| 5645 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5646 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5647 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5648 | host->SetRootLayer(root); |
| 5649 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5650 | int nonexistent_id = -1; |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5651 | EXPECT_EQ(root.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5652 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id())); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5653 | EXPECT_EQ(child.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5654 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id())); |
| 5655 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5656 | grand_child.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5657 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id())); |
| 5658 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5659 | mask_layer.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5660 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id())); |
| 5661 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5662 | replica_layer.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5663 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id())); |
| 5664 | EXPECT_EQ( |
| 5665 | 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5666 | } |
| 5667 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5668 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5669 | scoped_refptr<Layer> root = Layer::Create(); |
| 5670 | scoped_refptr<Layer> child = Layer::Create(); |
| 5671 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 5672 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5673 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5674 | const gfx::Transform identity_matrix; |
| 5675 | SetLayerPropertiesForTesting(root.get(), |
| 5676 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5677 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5678 | gfx::PointF(), |
| 5679 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5680 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5681 | false); |
| 5682 | SetLayerPropertiesForTesting(child.get(), |
| 5683 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5684 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5685 | gfx::PointF(), |
| 5686 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5687 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5688 | false); |
| 5689 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5690 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5691 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5692 | gfx::PointF(), |
| 5693 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5694 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5695 | false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5696 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5697 | root->AddChild(child); |
| 5698 | child->AddChild(grand_child); |
| 5699 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5700 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5701 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5702 | host->SetRootLayer(root); |
| 5703 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5704 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5705 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5706 | EXPECT_FALSE(child->render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5707 | } |
| 5708 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5709 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5710 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5711 | TestSharedBitmapManager shared_bitmap_manager; |
| 5712 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5713 | host_impl.CreatePendingTree(); |
| 5714 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5715 | |
| 5716 | const gfx::Transform identity_matrix; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5717 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5718 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5719 | false); |
| 5720 | root->SetDrawsContent(true); |
| 5721 | |
| 5722 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5723 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5724 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5725 | false); |
| 5726 | child->SetDrawsContent(true); |
| 5727 | child->SetOpacity(0.0f); |
| 5728 | |
| 5729 | // Add opacity animation. |
| 5730 | AddOpacityTransitionToController( |
| 5731 | child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false); |
| 5732 | |
| 5733 | root->AddChild(child.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5734 | root->SetHasRenderSurface(true); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5735 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5736 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5737 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5738 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5739 | inputs.can_adjust_raster_scales = true; |
| 5740 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5741 | |
| 5742 | // We should have one render surface and two layers. The child |
| 5743 | // layer should be included even though it is transparent. |
| 5744 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5745 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 5746 | } |
| 5747 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5748 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5749 | class LCDTextTest |
| 5750 | : public LayerTreeHostCommonTestBase, |
| 5751 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5752 | public: |
| 5753 | LCDTextTest() |
| 5754 | : host_impl_(&proxy_, &shared_bitmap_manager_), |
| 5755 | root_(nullptr), |
| 5756 | child_(nullptr), |
| 5757 | grand_child_(nullptr) {} |
| 5758 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5759 | protected: |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 5760 | void SetUp() override { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5761 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5762 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5763 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5764 | scoped_ptr<LayerImpl> root_ptr = |
| 5765 | LayerImpl::Create(host_impl_.active_tree(), 1); |
| 5766 | scoped_ptr<LayerImpl> child_ptr = |
| 5767 | LayerImpl::Create(host_impl_.active_tree(), 2); |
| 5768 | scoped_ptr<LayerImpl> grand_child_ptr = |
| 5769 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 5770 | |
| 5771 | // Stash raw pointers to look at later. |
| 5772 | root_ = root_ptr.get(); |
| 5773 | child_ = child_ptr.get(); |
| 5774 | grand_child_ = grand_child_ptr.get(); |
| 5775 | |
| 5776 | child_->AddChild(grand_child_ptr.Pass()); |
| 5777 | root_->AddChild(child_ptr.Pass()); |
| 5778 | host_impl_.active_tree()->SetRootLayer(root_ptr.Pass()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5779 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5780 | root_->SetContentsOpaque(true); |
| 5781 | child_->SetContentsOpaque(true); |
| 5782 | grand_child_->SetContentsOpaque(true); |
| 5783 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5784 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5785 | SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(), |
| 5786 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5787 | true); |
| 5788 | SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(), |
| 5789 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5790 | std::tr1::get<2>(GetParam())); |
| 5791 | SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(), |
| 5792 | gfx::PointF(), gfx::Size(1, 1), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5793 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5794 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5795 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5796 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5797 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5798 | |
| 5799 | FakeImplProxy proxy_; |
| 5800 | TestSharedBitmapManager shared_bitmap_manager_; |
| 5801 | FakeLayerTreeHostImpl host_impl_; |
| 5802 | |
| 5803 | LayerImpl* root_; |
| 5804 | LayerImpl* child_; |
| 5805 | LayerImpl* grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5806 | }; |
| 5807 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5808 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5809 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5810 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5811 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5812 | // Case 1: Identity transform. |
| 5813 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5814 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5815 | layers_always_allowed_lcd_text_); |
| 5816 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5817 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5818 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5819 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5820 | // Case 2: Integral translation. |
| 5821 | gfx::Transform integral_translation; |
| 5822 | integral_translation.Translate(1.0, 2.0); |
| 5823 | child_->SetTransform(integral_translation); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5824 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5825 | layers_always_allowed_lcd_text_); |
| 5826 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5827 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5828 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5829 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5830 | // Case 3: Non-integral translation. |
| 5831 | gfx::Transform non_integral_translation; |
| 5832 | non_integral_translation.Translate(1.5, 2.5); |
| 5833 | child_->SetTransform(non_integral_translation); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5834 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5835 | layers_always_allowed_lcd_text_); |
| 5836 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5837 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5838 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5839 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5840 | // Case 4: Rotation. |
| 5841 | gfx::Transform rotation; |
| 5842 | rotation.Rotate(10.0); |
| 5843 | child_->SetTransform(rotation); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5844 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5845 | layers_always_allowed_lcd_text_); |
| 5846 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5847 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5848 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5849 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5850 | // Case 5: Scale. |
| 5851 | gfx::Transform scale; |
| 5852 | scale.Scale(2.0, 2.0); |
| 5853 | child_->SetTransform(scale); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5854 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5855 | layers_always_allowed_lcd_text_); |
| 5856 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5857 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5858 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5859 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5860 | // Case 6: Skew. |
| 5861 | gfx::Transform skew; |
| 5862 | skew.SkewX(10.0); |
| 5863 | child_->SetTransform(skew); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5864 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5865 | layers_always_allowed_lcd_text_); |
| 5866 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5867 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5868 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5869 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5870 | // Case 7: Translucent. |
| 5871 | child_->SetTransform(identity_matrix); |
| 5872 | child_->SetOpacity(0.5f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5873 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5874 | layers_always_allowed_lcd_text_); |
| 5875 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5876 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5877 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5878 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5879 | // Case 8: Sanity check: restore transform and opacity. |
| 5880 | child_->SetTransform(identity_matrix); |
| 5881 | child_->SetOpacity(1.f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5882 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5883 | layers_always_allowed_lcd_text_); |
| 5884 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5885 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5886 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5887 | |
| 5888 | // Case 9: Non-opaque content. |
| 5889 | child_->SetContentsOpaque(false); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5890 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5891 | layers_always_allowed_lcd_text_); |
| 5892 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5893 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5894 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
| 5895 | |
| 5896 | // Case 10: Sanity check: restore content opaqueness. |
| 5897 | child_->SetContentsOpaque(true); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5898 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5899 | layers_always_allowed_lcd_text_); |
| 5900 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5901 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5902 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5903 | } |
| 5904 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5905 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5906 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5907 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5908 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5909 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5910 | layers_always_allowed_lcd_text_); |
| 5911 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5912 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5913 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5914 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5915 | // Add opacity animation. |
| 5916 | child_->SetOpacity(0.9f); |
| 5917 | AddOpacityTransitionToController( |
| 5918 | child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5919 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5920 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5921 | layers_always_allowed_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5922 | // Text AA should not be adjusted while animation is active. |
| 5923 | // Make sure LCD text AA setting remains unchanged. |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5924 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5925 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5926 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5927 | } |
| 5928 | |
| 5929 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5930 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5931 | testing::Combine(testing::Bool(), |
| 5932 | testing::Bool(), |
| 5933 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5934 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5935 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5936 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5937 | TestSharedBitmapManager shared_bitmap_manager; |
| 5938 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5939 | host_impl.CreatePendingTree(); |
| 5940 | const gfx::Transform identity_matrix; |
| 5941 | |
| 5942 | scoped_refptr<Layer> root = Layer::Create(); |
| 5943 | SetLayerPropertiesForTesting(root.get(), |
| 5944 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5945 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5946 | gfx::PointF(), |
| 5947 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5948 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5949 | false); |
| 5950 | root->SetIsDrawable(true); |
| 5951 | |
| 5952 | scoped_refptr<Layer> child = Layer::Create(); |
| 5953 | SetLayerPropertiesForTesting(child.get(), |
| 5954 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5955 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5956 | gfx::PointF(), |
| 5957 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5958 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5959 | false); |
| 5960 | child->SetIsDrawable(true); |
| 5961 | |
| 5962 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5963 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5964 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5965 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5966 | gfx::PointF(), |
| 5967 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5968 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5969 | false); |
| 5970 | grand_child->SetIsDrawable(true); |
| 5971 | grand_child->SetHideLayerAndSubtree(true); |
| 5972 | |
| 5973 | child->AddChild(grand_child); |
| 5974 | root->AddChild(child); |
| 5975 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5976 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5977 | host->SetRootLayer(root); |
| 5978 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5979 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5980 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5981 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5982 | inputs.can_adjust_raster_scales = true; |
| 5983 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5984 | |
| 5985 | // We should have one render surface and two layers. The grand child has |
| 5986 | // hidden itself. |
| 5987 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5988 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5989 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 5990 | EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5991 | } |
| 5992 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5993 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5994 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5995 | TestSharedBitmapManager shared_bitmap_manager; |
| 5996 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5997 | host_impl.CreatePendingTree(); |
| 5998 | const gfx::Transform identity_matrix; |
| 5999 | |
| 6000 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6001 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 6002 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6003 | false); |
| 6004 | root->SetDrawsContent(true); |
| 6005 | |
| 6006 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6007 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 6008 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6009 | false); |
| 6010 | child->SetDrawsContent(true); |
| 6011 | |
| 6012 | scoped_ptr<LayerImpl> grand_child = |
| 6013 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6014 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 6015 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6016 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6017 | grand_child->SetDrawsContent(true); |
| 6018 | grand_child->SetHideLayerAndSubtree(true); |
| 6019 | |
| 6020 | child->AddChild(grand_child.Pass()); |
| 6021 | root->AddChild(child.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6022 | root->SetHasRenderSurface(true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6023 | |
| 6024 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6025 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6026 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6027 | inputs.can_adjust_raster_scales = true; |
| 6028 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6029 | |
| 6030 | // We should have one render surface and two layers. The grand child has |
| 6031 | // hidden itself. |
| 6032 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6033 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6034 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
| 6035 | EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6036 | } |
| 6037 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6038 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6039 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6040 | TestSharedBitmapManager shared_bitmap_manager; |
| 6041 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6042 | host_impl.CreatePendingTree(); |
| 6043 | const gfx::Transform identity_matrix; |
| 6044 | |
| 6045 | scoped_refptr<Layer> root = Layer::Create(); |
| 6046 | SetLayerPropertiesForTesting(root.get(), |
| 6047 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6048 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6049 | gfx::PointF(), |
| 6050 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6051 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6052 | false); |
| 6053 | root->SetIsDrawable(true); |
| 6054 | |
| 6055 | scoped_refptr<Layer> child = Layer::Create(); |
| 6056 | SetLayerPropertiesForTesting(child.get(), |
| 6057 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6058 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6059 | gfx::PointF(), |
| 6060 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6061 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6062 | false); |
| 6063 | child->SetIsDrawable(true); |
| 6064 | child->SetHideLayerAndSubtree(true); |
| 6065 | |
| 6066 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 6067 | SetLayerPropertiesForTesting(grand_child.get(), |
| 6068 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6069 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6070 | gfx::PointF(), |
| 6071 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6072 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6073 | false); |
| 6074 | grand_child->SetIsDrawable(true); |
| 6075 | |
| 6076 | child->AddChild(grand_child); |
| 6077 | root->AddChild(child); |
| 6078 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6079 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6080 | host->SetRootLayer(root); |
| 6081 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6082 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6083 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6084 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6085 | inputs.can_adjust_raster_scales = true; |
| 6086 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6087 | |
| 6088 | // We should have one render surface and one layers. The child has |
| 6089 | // hidden itself and the grand child. |
| 6090 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6091 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6092 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6093 | } |
| 6094 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6095 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6096 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6097 | TestSharedBitmapManager shared_bitmap_manager; |
| 6098 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6099 | host_impl.CreatePendingTree(); |
| 6100 | const gfx::Transform identity_matrix; |
| 6101 | |
| 6102 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6103 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 6104 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6105 | true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6106 | root->SetDrawsContent(true); |
| 6107 | |
| 6108 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6109 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 6110 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6111 | false); |
| 6112 | child->SetDrawsContent(true); |
| 6113 | child->SetHideLayerAndSubtree(true); |
| 6114 | |
| 6115 | scoped_ptr<LayerImpl> grand_child = |
| 6116 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6117 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 6118 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6119 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6120 | grand_child->SetDrawsContent(true); |
| 6121 | |
| 6122 | child->AddChild(grand_child.Pass()); |
| 6123 | root->AddChild(child.Pass()); |
| 6124 | |
| 6125 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6126 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6127 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6128 | inputs.can_adjust_raster_scales = true; |
| 6129 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6130 | |
| 6131 | // We should have one render surface and one layers. The child has |
| 6132 | // hidden itself and the grand child. |
| 6133 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6134 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6135 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6136 | } |
| 6137 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6138 | void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 6139 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6140 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6141 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6142 | TestSharedBitmapManager shared_bitmap_manager; |
| 6143 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6144 | host_impl.CreatePendingTree(); |
| 6145 | const gfx::Transform identity_matrix; |
| 6146 | |
| 6147 | scoped_refptr<Layer> root = Layer::Create(); |
| 6148 | SetLayerPropertiesForTesting(root.get(), |
| 6149 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6150 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6151 | gfx::PointF(), |
| 6152 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6153 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6154 | false); |
| 6155 | root->SetIsDrawable(true); |
| 6156 | |
| 6157 | scoped_refptr<Layer> copy_grand_parent = Layer::Create(); |
| 6158 | SetLayerPropertiesForTesting(copy_grand_parent.get(), |
| 6159 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6160 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6161 | gfx::PointF(), |
| 6162 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6163 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6164 | false); |
| 6165 | copy_grand_parent->SetIsDrawable(true); |
| 6166 | |
| 6167 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 6168 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 6169 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6170 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6171 | gfx::PointF(), |
| 6172 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6173 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6174 | false); |
| 6175 | copy_parent->SetIsDrawable(true); |
| 6176 | copy_parent->SetForceRenderSurface(true); |
| 6177 | |
| 6178 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 6179 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 6180 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6181 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6182 | gfx::PointF(), |
| 6183 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6184 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6185 | false); |
| 6186 | copy_layer->SetIsDrawable(true); |
| 6187 | |
| 6188 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 6189 | SetLayerPropertiesForTesting(copy_child.get(), |
| 6190 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6191 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6192 | gfx::PointF(), |
| 6193 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6194 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6195 | false); |
| 6196 | copy_child->SetIsDrawable(true); |
| 6197 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6198 | scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create(); |
| 6199 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
| 6200 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6201 | gfx::Point3F(), |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6202 | gfx::PointF(), |
| 6203 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6204 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6205 | false); |
| 6206 | copy_grand_parent_sibling_before->SetIsDrawable(true); |
| 6207 | |
| 6208 | scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create(); |
| 6209 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
| 6210 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6211 | gfx::Point3F(), |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6212 | gfx::PointF(), |
| 6213 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6214 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6215 | false); |
| 6216 | copy_grand_parent_sibling_after->SetIsDrawable(true); |
| 6217 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6218 | copy_layer->AddChild(copy_child); |
| 6219 | copy_parent->AddChild(copy_layer); |
| 6220 | copy_grand_parent->AddChild(copy_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6221 | root->AddChild(copy_grand_parent_sibling_before); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6222 | root->AddChild(copy_grand_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6223 | root->AddChild(copy_grand_parent_sibling_after); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6224 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6225 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6226 | host->SetRootLayer(root); |
| 6227 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6228 | // Hide the copy_grand_parent and its subtree. But make a copy request in that |
| 6229 | // hidden subtree on copy_layer. |
| 6230 | copy_grand_parent->SetHideLayerAndSubtree(true); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6231 | copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true); |
| 6232 | copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6233 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 6234 | base::Bind(&EmptyCopyOutputCallback))); |
| 6235 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 6236 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6237 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6238 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6239 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6240 | inputs.can_adjust_raster_scales = true; |
| 6241 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6242 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6243 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request); |
| 6244 | EXPECT_TRUE(copy_grand_parent->draw_properties(). |
| 6245 | layer_or_descendant_has_copy_request); |
| 6246 | EXPECT_TRUE(copy_parent->draw_properties(). |
| 6247 | layer_or_descendant_has_copy_request); |
| 6248 | EXPECT_TRUE(copy_layer->draw_properties(). |
| 6249 | layer_or_descendant_has_copy_request); |
| 6250 | EXPECT_FALSE(copy_child->draw_properties(). |
| 6251 | layer_or_descendant_has_copy_request); |
| 6252 | EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties(). |
| 6253 | layer_or_descendant_has_copy_request); |
| 6254 | EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties(). |
| 6255 | layer_or_descendant_has_copy_request); |
| 6256 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6257 | // We should have three render surfaces, one for the root, one for the parent |
| 6258 | // since it owns a surface, and one for the copy_layer. |
| 6259 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6260 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 6261 | EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id()); |
| 6262 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6263 | |
| 6264 | // The root render surface should have 2 contributing layers. The |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6265 | // copy_grand_parent is hidden along with its siblings, but the copy_parent |
| 6266 | // will appear since something in its subtree needs to be drawn for a copy |
| 6267 | // request. |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6268 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6269 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 6270 | EXPECT_EQ(copy_parent->id(), |
| 6271 | root->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6272 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 6273 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6274 | // appear in its list, since it needs to be drawn for the copy request. |
| 6275 | ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size()); |
| 6276 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6277 | copy_parent->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6278 | |
| 6279 | // The copy_layer's render surface should have two contributing layers. |
| 6280 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 6281 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6282 | copy_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6283 | EXPECT_EQ(copy_child->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6284 | copy_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6285 | } |
| 6286 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6287 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6288 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6289 | TestSharedBitmapManager shared_bitmap_manager; |
| 6290 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6291 | host_impl.CreatePendingTree(); |
| 6292 | const gfx::Transform identity_matrix; |
| 6293 | |
| 6294 | scoped_refptr<Layer> root = Layer::Create(); |
| 6295 | SetLayerPropertiesForTesting(root.get(), |
| 6296 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6297 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6298 | gfx::PointF(), |
| 6299 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6300 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6301 | false); |
| 6302 | root->SetIsDrawable(true); |
| 6303 | |
| 6304 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 6305 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 6306 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6307 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6308 | gfx::PointF(), |
| 6309 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6310 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6311 | false); |
| 6312 | copy_parent->SetIsDrawable(true); |
| 6313 | copy_parent->SetMasksToBounds(true); |
| 6314 | |
| 6315 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 6316 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 6317 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6318 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6319 | gfx::PointF(), |
| 6320 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6321 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6322 | false); |
| 6323 | copy_layer->SetIsDrawable(true); |
| 6324 | |
| 6325 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 6326 | SetLayerPropertiesForTesting(copy_child.get(), |
| 6327 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6328 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6329 | gfx::PointF(), |
| 6330 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6331 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6332 | false); |
| 6333 | copy_child->SetIsDrawable(true); |
| 6334 | |
| 6335 | copy_layer->AddChild(copy_child); |
| 6336 | copy_parent->AddChild(copy_layer); |
| 6337 | root->AddChild(copy_parent); |
| 6338 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6339 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6340 | host->SetRootLayer(root); |
| 6341 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6342 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 6343 | base::Bind(&EmptyCopyOutputCallback))); |
| 6344 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 6345 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6346 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6347 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6348 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6349 | inputs.can_adjust_raster_scales = true; |
| 6350 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6351 | |
| 6352 | // We should have one render surface, as the others are clipped out. |
| 6353 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6354 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6355 | |
| 6356 | // The root render surface should only have 1 contributing layer, since the |
| 6357 | // other layers are empty/clipped away. |
| 6358 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6359 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6360 | } |
| 6361 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6362 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
| 6363 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6364 | TestSharedBitmapManager shared_bitmap_manager; |
| 6365 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6366 | host_impl.CreatePendingTree(); |
| 6367 | const gfx::Transform identity_matrix; |
| 6368 | |
| 6369 | scoped_refptr<Layer> root = Layer::Create(); |
| 6370 | SetLayerPropertiesForTesting(root.get(), |
| 6371 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6372 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6373 | gfx::PointF(), |
| 6374 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6375 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6376 | false); |
| 6377 | root->SetIsDrawable(true); |
| 6378 | |
| 6379 | // The surface is moved slightly outside of the viewport. |
| 6380 | scoped_refptr<Layer> surface = Layer::Create(); |
| 6381 | SetLayerPropertiesForTesting(surface.get(), |
| 6382 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6383 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6384 | gfx::PointF(-10, -20), |
| 6385 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6386 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6387 | false); |
| 6388 | surface->SetForceRenderSurface(true); |
| 6389 | |
| 6390 | scoped_refptr<Layer> surface_child = Layer::Create(); |
| 6391 | SetLayerPropertiesForTesting(surface_child.get(), |
| 6392 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6393 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6394 | gfx::PointF(), |
| 6395 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6396 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6397 | false); |
| 6398 | surface_child->SetIsDrawable(true); |
| 6399 | |
| 6400 | surface->AddChild(surface_child); |
| 6401 | root->AddChild(surface); |
| 6402 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6403 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6404 | host->SetRootLayer(root); |
| 6405 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6406 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6407 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6408 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6409 | inputs.can_adjust_raster_scales = true; |
| 6410 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6411 | |
| 6412 | // The visible_content_rect for the |surface_child| should not be clipped by |
| 6413 | // the viewport. |
| 6414 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 6415 | surface_child->visible_content_rect().ToString()); |
| 6416 | } |
| 6417 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6418 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 6419 | // Ensure that a transform between the layer and its render surface is not a |
| 6420 | // problem. Constructs the following layer tree. |
| 6421 | // |
| 6422 | // root (a render surface) |
| 6423 | // + render_surface |
| 6424 | // + clip_parent (scaled) |
| 6425 | // + intervening_clipping_layer |
| 6426 | // + clip_child |
| 6427 | // |
| 6428 | // The render surface should be resized correctly and the clip child should |
| 6429 | // inherit the right clip rect. |
| 6430 | scoped_refptr<Layer> root = Layer::Create(); |
| 6431 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 6432 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6433 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6434 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6435 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6436 | |
| 6437 | root->AddChild(render_surface); |
| 6438 | render_surface->AddChild(clip_parent); |
| 6439 | clip_parent->AddChild(intervening); |
| 6440 | intervening->AddChild(clip_child); |
| 6441 | |
| 6442 | clip_child->SetClipParent(clip_parent.get()); |
| 6443 | |
| 6444 | intervening->SetMasksToBounds(true); |
| 6445 | clip_parent->SetMasksToBounds(true); |
| 6446 | |
| 6447 | render_surface->SetForceRenderSurface(true); |
| 6448 | |
| 6449 | gfx::Transform scale_transform; |
| 6450 | scale_transform.Scale(2, 2); |
| 6451 | |
| 6452 | gfx::Transform identity_transform; |
| 6453 | |
| 6454 | SetLayerPropertiesForTesting(root.get(), |
| 6455 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6456 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6457 | gfx::PointF(), |
| 6458 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6459 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6460 | false); |
| 6461 | SetLayerPropertiesForTesting(render_surface.get(), |
| 6462 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6463 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6464 | gfx::PointF(), |
| 6465 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6466 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6467 | false); |
| 6468 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6469 | scale_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6470 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6471 | gfx::PointF(1.f, 1.f), |
| 6472 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6473 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6474 | false); |
| 6475 | SetLayerPropertiesForTesting(intervening.get(), |
| 6476 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6477 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6478 | gfx::PointF(1.f, 1.f), |
| 6479 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6480 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6481 | false); |
| 6482 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6483 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6484 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6485 | gfx::PointF(1.f, 1.f), |
| 6486 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6487 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6488 | false); |
| 6489 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6490 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6491 | host->SetRootLayer(root); |
| 6492 | |
| 6493 | ExecuteCalculateDrawProperties(root.get()); |
| 6494 | |
| 6495 | ASSERT_TRUE(root->render_surface()); |
| 6496 | ASSERT_TRUE(render_surface->render_surface()); |
| 6497 | |
| 6498 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 6499 | // by the intervening clip layer. |
| 6500 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
| 6501 | clip_parent->clip_rect().ToString()); |
| 6502 | ASSERT_EQ(clip_parent->clip_rect().ToString(), |
| 6503 | clip_child->clip_rect().ToString()); |
| 6504 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(), |
| 6505 | intervening->clip_rect().ToString()); |
| 6506 | |
| 6507 | // Ensure that the render surface reports a content rect that has been grown |
| 6508 | // to accomodate for the clip child. |
| 6509 | ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(), |
| 6510 | render_surface->render_surface()->content_rect().ToString()); |
| 6511 | |
| 6512 | // The above check implies the two below, but they nicely demonstrate that |
| 6513 | // we've grown, despite the intervening layer's clip. |
| 6514 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 6515 | render_surface->render_surface()->content_rect())); |
| 6516 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 6517 | render_surface->render_surface()->content_rect())); |
| 6518 | } |
| 6519 | |
| 6520 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 6521 | // Ensure that intervening render surfaces are not a problem in the basic |
| 6522 | // case. In the following tree, both render surfaces should be resized to |
| 6523 | // accomodate for the clip child, despite an intervening clip. |
| 6524 | // |
| 6525 | // root (a render surface) |
| 6526 | // + clip_parent (masks to bounds) |
| 6527 | // + render_surface1 (sets opacity) |
| 6528 | // + intervening (masks to bounds) |
| 6529 | // + render_surface2 (also sets opacity) |
| 6530 | // + clip_child |
| 6531 | // |
| 6532 | scoped_refptr<Layer> root = Layer::Create(); |
| 6533 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6534 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6535 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6536 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6537 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6538 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6539 | |
| 6540 | root->AddChild(clip_parent); |
| 6541 | clip_parent->AddChild(render_surface1); |
| 6542 | render_surface1->AddChild(intervening); |
| 6543 | intervening->AddChild(render_surface2); |
| 6544 | render_surface2->AddChild(clip_child); |
| 6545 | |
| 6546 | clip_child->SetClipParent(clip_parent.get()); |
| 6547 | |
| 6548 | intervening->SetMasksToBounds(true); |
| 6549 | clip_parent->SetMasksToBounds(true); |
| 6550 | |
| 6551 | render_surface1->SetForceRenderSurface(true); |
| 6552 | render_surface2->SetForceRenderSurface(true); |
| 6553 | |
| 6554 | gfx::Transform translation_transform; |
| 6555 | translation_transform.Translate(2, 2); |
| 6556 | |
| 6557 | gfx::Transform identity_transform; |
| 6558 | SetLayerPropertiesForTesting(root.get(), |
| 6559 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6560 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6561 | gfx::PointF(), |
| 6562 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6563 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6564 | false); |
| 6565 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6566 | translation_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6567 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6568 | gfx::PointF(1.f, 1.f), |
| 6569 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6570 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6571 | false); |
| 6572 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6573 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6574 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6575 | gfx::PointF(), |
| 6576 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6577 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6578 | false); |
| 6579 | SetLayerPropertiesForTesting(intervening.get(), |
| 6580 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6581 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6582 | gfx::PointF(1.f, 1.f), |
| 6583 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6584 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6585 | false); |
| 6586 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6587 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6588 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6589 | gfx::PointF(), |
| 6590 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6591 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6592 | false); |
| 6593 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6594 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6595 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6596 | gfx::PointF(-10.f, -10.f), |
| 6597 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6598 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6599 | false); |
| 6600 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6601 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6602 | host->SetRootLayer(root); |
| 6603 | |
| 6604 | ExecuteCalculateDrawProperties(root.get()); |
| 6605 | |
| 6606 | EXPECT_TRUE(root->render_surface()); |
| 6607 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6608 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6609 | |
| 6610 | // Since the render surfaces could have expanded, they should not clip (their |
| 6611 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6612 | // in this case. |
| 6613 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6614 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6615 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6616 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6617 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6618 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6619 | |
| 6620 | // NB: clip rects are in target space. |
| 6621 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6622 | render_surface1->clip_rect().ToString()); |
| 6623 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6624 | |
| 6625 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6626 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6627 | render_surface2->clip_rect().ToString()); |
| 6628 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6629 | |
| 6630 | // The content rects of both render surfaces should both have expanded to |
| 6631 | // contain the clip child. |
| 6632 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6633 | render_surface1->render_surface()->content_rect().ToString()); |
| 6634 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6635 | render_surface2->render_surface()->content_rect().ToString()); |
| 6636 | |
| 6637 | // The clip child should have inherited the clip parent's clip (projected to |
| 6638 | // the right space, of course), and should have the correctly sized visible |
| 6639 | // content rect. |
| 6640 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6641 | clip_child->clip_rect().ToString()); |
| 6642 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(), |
| 6643 | clip_child->visible_content_rect().ToString()); |
| 6644 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6645 | } |
| 6646 | |
| 6647 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 6648 | // Ensure that intervening render surfaces are not a problem, even if there |
| 6649 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 6650 | // of transform. |
| 6651 | // |
| 6652 | // root (a render surface) |
| 6653 | // + clip_parent (masks to bounds) |
| 6654 | // + render_surface1 (sets opacity) |
| 6655 | // + intervening (masks to bounds AND scrolls) |
| 6656 | // + render_surface2 (also sets opacity) |
| 6657 | // + clip_child |
| 6658 | // |
| 6659 | scoped_refptr<Layer> root = Layer::Create(); |
| 6660 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6661 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6662 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6663 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6664 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6665 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6666 | |
| 6667 | root->AddChild(clip_parent); |
| 6668 | clip_parent->AddChild(render_surface1); |
| 6669 | render_surface1->AddChild(intervening); |
| 6670 | intervening->AddChild(render_surface2); |
| 6671 | render_surface2->AddChild(clip_child); |
| 6672 | |
| 6673 | clip_child->SetClipParent(clip_parent.get()); |
| 6674 | |
| 6675 | intervening->SetMasksToBounds(true); |
| 6676 | clip_parent->SetMasksToBounds(true); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6677 | intervening->SetScrollClipLayerId(clip_parent->id()); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 6678 | intervening->SetScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6679 | |
| 6680 | render_surface1->SetForceRenderSurface(true); |
| 6681 | render_surface2->SetForceRenderSurface(true); |
| 6682 | |
| 6683 | gfx::Transform translation_transform; |
| 6684 | translation_transform.Translate(2, 2); |
| 6685 | |
| 6686 | gfx::Transform identity_transform; |
| 6687 | SetLayerPropertiesForTesting(root.get(), |
| 6688 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6689 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6690 | gfx::PointF(), |
| 6691 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6692 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6693 | false); |
| 6694 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6695 | translation_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6696 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6697 | gfx::PointF(1.f, 1.f), |
| 6698 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6699 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6700 | false); |
| 6701 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6702 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6703 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6704 | gfx::PointF(), |
| 6705 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6706 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6707 | false); |
| 6708 | SetLayerPropertiesForTesting(intervening.get(), |
| 6709 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6710 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6711 | gfx::PointF(1.f, 1.f), |
| 6712 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6713 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6714 | false); |
| 6715 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6716 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6717 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6718 | gfx::PointF(), |
| 6719 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6720 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6721 | false); |
| 6722 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6723 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6724 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6725 | gfx::PointF(-10.f, -10.f), |
| 6726 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6727 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6728 | false); |
| 6729 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6730 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6731 | host->SetRootLayer(root); |
| 6732 | |
| 6733 | ExecuteCalculateDrawProperties(root.get()); |
| 6734 | |
| 6735 | EXPECT_TRUE(root->render_surface()); |
| 6736 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6737 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6738 | |
| 6739 | // Since the render surfaces could have expanded, they should not clip (their |
| 6740 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6741 | // in this case. |
| 6742 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6743 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6744 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6745 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6746 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6747 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6748 | |
| 6749 | // NB: clip rects are in target space. |
| 6750 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6751 | render_surface1->clip_rect().ToString()); |
| 6752 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6753 | |
| 6754 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6755 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(), |
| 6756 | render_surface2->clip_rect().ToString()); |
| 6757 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6758 | |
| 6759 | // The content rects of both render surfaces should both have expanded to |
| 6760 | // contain the clip child. |
| 6761 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6762 | render_surface1->render_surface()->content_rect().ToString()); |
| 6763 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6764 | render_surface2->render_surface()->content_rect().ToString()); |
| 6765 | |
| 6766 | // The clip child should have inherited the clip parent's clip (projected to |
| 6767 | // the right space, of course), and should have the correctly sized visible |
| 6768 | // content rect. |
| 6769 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6770 | clip_child->clip_rect().ToString()); |
| 6771 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), |
| 6772 | clip_child->visible_content_rect().ToString()); |
| 6773 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6774 | } |
| 6775 | |
| 6776 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 6777 | // Ensures that descendants of the clip child inherit the correct clip. |
| 6778 | // |
| 6779 | // root (a render surface) |
| 6780 | // + clip_parent (masks to bounds) |
| 6781 | // + intervening (masks to bounds) |
| 6782 | // + clip_child |
| 6783 | // + child |
| 6784 | // |
| 6785 | scoped_refptr<Layer> root = Layer::Create(); |
| 6786 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6787 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6788 | scoped_refptr<Layer> clip_child = Layer::Create(); |
| 6789 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 6790 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6791 | |
| 6792 | root->AddChild(clip_parent); |
| 6793 | clip_parent->AddChild(intervening); |
| 6794 | intervening->AddChild(clip_child); |
| 6795 | clip_child->AddChild(child); |
| 6796 | |
| 6797 | clip_child->SetClipParent(clip_parent.get()); |
| 6798 | |
| 6799 | intervening->SetMasksToBounds(true); |
| 6800 | clip_parent->SetMasksToBounds(true); |
| 6801 | |
| 6802 | gfx::Transform identity_transform; |
| 6803 | SetLayerPropertiesForTesting(root.get(), |
| 6804 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6805 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6806 | gfx::PointF(), |
| 6807 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6808 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6809 | false); |
| 6810 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6811 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6812 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6813 | gfx::PointF(), |
| 6814 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6815 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6816 | false); |
| 6817 | SetLayerPropertiesForTesting(intervening.get(), |
| 6818 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6819 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6820 | gfx::PointF(), |
| 6821 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6822 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6823 | false); |
| 6824 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6825 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6826 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6827 | gfx::PointF(), |
| 6828 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6829 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6830 | false); |
| 6831 | SetLayerPropertiesForTesting(child.get(), |
| 6832 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6833 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6834 | gfx::PointF(), |
| 6835 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6836 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6837 | false); |
| 6838 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6839 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6840 | host->SetRootLayer(root); |
| 6841 | |
| 6842 | ExecuteCalculateDrawProperties(root.get()); |
| 6843 | |
| 6844 | EXPECT_TRUE(root->render_surface()); |
| 6845 | |
| 6846 | // Neither the clip child nor its descendant should have inherited the clip |
| 6847 | // from |intervening|. |
| 6848 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6849 | clip_child->clip_rect().ToString()); |
| 6850 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6851 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6852 | child->visible_content_rect().ToString()); |
| 6853 | EXPECT_TRUE(child->is_clipped()); |
| 6854 | } |
| 6855 | |
| 6856 | TEST_F(LayerTreeHostCommonTest, |
| 6857 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 6858 | // Ensures that non-descendant clip children in the tree do not affect |
| 6859 | // render surfaces. |
| 6860 | // |
| 6861 | // root (a render surface) |
| 6862 | // + clip_parent (masks to bounds) |
| 6863 | // + render_surface1 |
| 6864 | // + clip_child |
| 6865 | // + render_surface2 |
| 6866 | // + non_clip_child |
| 6867 | // |
| 6868 | // In this example render_surface2 should be unaffected by clip_child. |
| 6869 | scoped_refptr<Layer> root = Layer::Create(); |
| 6870 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6871 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6872 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6873 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6874 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6875 | scoped_refptr<LayerWithForcedDrawsContent> non_clip_child = |
| 6876 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6877 | |
| 6878 | root->AddChild(clip_parent); |
| 6879 | clip_parent->AddChild(render_surface1); |
| 6880 | render_surface1->AddChild(clip_child); |
| 6881 | clip_parent->AddChild(render_surface2); |
| 6882 | render_surface2->AddChild(non_clip_child); |
| 6883 | |
| 6884 | clip_child->SetClipParent(clip_parent.get()); |
| 6885 | |
| 6886 | clip_parent->SetMasksToBounds(true); |
| 6887 | render_surface1->SetMasksToBounds(true); |
| 6888 | |
| 6889 | gfx::Transform identity_transform; |
| 6890 | SetLayerPropertiesForTesting(root.get(), |
| 6891 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6892 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6893 | gfx::PointF(), |
| 6894 | gfx::Size(15, 15), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6895 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6896 | false); |
| 6897 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6898 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6899 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6900 | gfx::PointF(), |
| 6901 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6902 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6903 | false); |
| 6904 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6905 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6906 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6907 | gfx::PointF(5, 5), |
| 6908 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6909 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6910 | false); |
| 6911 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6912 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6913 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6914 | gfx::PointF(), |
| 6915 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6916 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6917 | false); |
| 6918 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6919 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6920 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6921 | gfx::PointF(-1, 1), |
| 6922 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6923 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6924 | false); |
| 6925 | SetLayerPropertiesForTesting(non_clip_child.get(), |
| 6926 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6927 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6928 | gfx::PointF(), |
| 6929 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6930 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6931 | false); |
| 6932 | |
| 6933 | render_surface1->SetForceRenderSurface(true); |
| 6934 | render_surface2->SetForceRenderSurface(true); |
| 6935 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6936 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6937 | host->SetRootLayer(root); |
| 6938 | |
| 6939 | ExecuteCalculateDrawProperties(root.get()); |
| 6940 | |
| 6941 | EXPECT_TRUE(root->render_surface()); |
| 6942 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6943 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6944 | |
| 6945 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6946 | render_surface1->clip_rect().ToString()); |
| 6947 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6948 | |
| 6949 | // The render surface should not clip (it has unclipped descendants), instead |
| 6950 | // it should rely on layer clipping. |
| 6951 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6952 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6953 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6954 | |
| 6955 | // That said, it should have grown to accomodate the unclipped descendant. |
| 6956 | EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(), |
| 6957 | render_surface1->render_surface()->content_rect().ToString()); |
| 6958 | |
| 6959 | // This render surface should clip. It has no unclipped descendants. |
| 6960 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6961 | render_surface2->clip_rect().ToString()); |
| 6962 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
| 6963 | |
| 6964 | // It also shouldn't have grown to accomodate the clip child. |
| 6965 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6966 | render_surface2->render_surface()->content_rect().ToString()); |
| 6967 | |
| 6968 | // Sanity check our num_unclipped_descendants values. |
| 6969 | EXPECT_EQ(1, render_surface1->num_unclipped_descendants()); |
| 6970 | EXPECT_EQ(0, render_surface2->num_unclipped_descendants()); |
| 6971 | } |
| 6972 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6973 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
| 6974 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6975 | TestSharedBitmapManager shared_bitmap_manager; |
| 6976 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6977 | scoped_ptr<LayerImpl> root = |
| 6978 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 6979 | scoped_ptr<LayerImpl> child1 = |
| 6980 | LayerImpl::Create(host_impl.active_tree(), 123456); |
| 6981 | scoped_ptr<LayerImpl> child2 = |
| 6982 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
| 6983 | scoped_ptr<LayerImpl> child3 = |
| 6984 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 6985 | |
| 6986 | gfx::Transform identity_matrix; |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6987 | gfx::Point3F transform_origin; |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6988 | gfx::PointF position; |
| 6989 | gfx::Size bounds(100, 100); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6990 | SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 6991 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6992 | root->SetDrawsContent(true); |
| 6993 | |
| 6994 | // This layer structure normally forces render surface due to preserves3d |
| 6995 | // behavior. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6996 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin, |
| 6997 | position, bounds, false, true, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6998 | child1->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6999 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin, |
| 7000 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7001 | child2->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7002 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin, |
| 7003 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7004 | child3->SetDrawsContent(true); |
| 7005 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 7006 | child2->Set3dSortingContextId(1); |
| 7007 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7008 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7009 | child2->AddChild(child3.Pass()); |
| 7010 | child1->AddChild(child2.Pass()); |
| 7011 | root->AddChild(child1.Pass()); |
| 7012 | |
| 7013 | { |
| 7014 | LayerImplList render_surface_layer_list; |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 7015 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get()); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7016 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7017 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7018 | inputs.can_render_to_separate_surface = true; |
| 7019 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7020 | |
| 7021 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
| 7022 | } |
| 7023 | |
| 7024 | { |
| 7025 | LayerImplList render_surface_layer_list; |
| 7026 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7027 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7028 | inputs.can_render_to_separate_surface = false; |
| 7029 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7030 | |
| 7031 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
| 7032 | } |
| 7033 | } |
| 7034 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7035 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
| 7036 | scoped_refptr<Layer> root = Layer::Create(); |
| 7037 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 7038 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 7039 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7040 | |
| 7041 | root->AddChild(render_surface); |
| 7042 | render_surface->AddChild(child); |
| 7043 | |
| 7044 | gfx::Transform identity_transform; |
| 7045 | SetLayerPropertiesForTesting(root.get(), |
| 7046 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7047 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7048 | gfx::PointF(), |
| 7049 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7050 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7051 | false); |
| 7052 | SetLayerPropertiesForTesting(render_surface.get(), |
| 7053 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7054 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7055 | gfx::PointF(), |
| 7056 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7057 | false, |
| 7058 | true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7059 | SetLayerPropertiesForTesting(child.get(), |
| 7060 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7061 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7062 | gfx::PointF(), |
| 7063 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7064 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7065 | false); |
| 7066 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7067 | root->SetShouldFlattenTransform(false); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 7068 | root->Set3dSortingContextId(1); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7069 | render_surface->SetDoubleSided(false); |
| 7070 | render_surface->SetForceRenderSurface(true); |
| 7071 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7072 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7073 | host->SetRootLayer(root); |
| 7074 | |
| 7075 | ExecuteCalculateDrawProperties(root.get()); |
| 7076 | |
| 7077 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 7078 | EXPECT_EQ(1u, |
| 7079 | render_surface_layer_list()->at(0) |
| 7080 | ->render_surface()->layer_list().size()); |
| 7081 | EXPECT_EQ(1u, |
| 7082 | render_surface_layer_list()->at(1) |
| 7083 | ->render_surface()->layer_list().size()); |
| 7084 | |
| 7085 | gfx::Transform rotation_transform = identity_transform; |
| 7086 | rotation_transform.RotateAboutXAxis(180.0); |
| 7087 | |
| 7088 | render_surface->SetTransform(rotation_transform); |
| 7089 | |
| 7090 | ExecuteCalculateDrawProperties(root.get()); |
| 7091 | |
| 7092 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 7093 | EXPECT_EQ(0u, |
| 7094 | render_surface_layer_list()->at(0) |
| 7095 | ->render_surface()->layer_list().size()); |
| 7096 | } |
| 7097 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7098 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 7099 | // Checks that the simple case (being clipped by a scroll parent that would |
| 7100 | // have been processed before you anyhow) results in the right clips. |
| 7101 | // |
| 7102 | // + root |
| 7103 | // + scroll_parent_border |
| 7104 | // | + scroll_parent_clip |
| 7105 | // | + scroll_parent |
| 7106 | // + scroll_child |
| 7107 | // |
| 7108 | scoped_refptr<Layer> root = Layer::Create(); |
| 7109 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7110 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7111 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7112 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7113 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7114 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7115 | |
| 7116 | root->AddChild(scroll_child); |
| 7117 | |
| 7118 | root->AddChild(scroll_parent_border); |
| 7119 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7120 | scroll_parent_clip->AddChild(scroll_parent); |
| 7121 | |
| 7122 | scroll_parent_clip->SetMasksToBounds(true); |
| 7123 | |
| 7124 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7125 | |
| 7126 | gfx::Transform identity_transform; |
| 7127 | SetLayerPropertiesForTesting(root.get(), |
| 7128 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7129 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7130 | gfx::PointF(), |
| 7131 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7132 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7133 | false); |
| 7134 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7135 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7136 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7137 | gfx::PointF(), |
| 7138 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7139 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7140 | false); |
| 7141 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7142 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7143 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7144 | gfx::PointF(), |
| 7145 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7146 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7147 | false); |
| 7148 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7149 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7150 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7151 | gfx::PointF(), |
| 7152 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7153 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7154 | false); |
| 7155 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7156 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7157 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7158 | gfx::PointF(), |
| 7159 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7160 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7161 | false); |
| 7162 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7163 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7164 | host->SetRootLayer(root); |
| 7165 | |
| 7166 | ExecuteCalculateDrawProperties(root.get()); |
| 7167 | |
| 7168 | EXPECT_TRUE(root->render_surface()); |
| 7169 | |
| 7170 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 7171 | scroll_child->clip_rect().ToString()); |
| 7172 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7173 | } |
| 7174 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7175 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
| 7176 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 7177 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7178 | scoped_refptr<LayerWithForcedDrawsContent> parent = |
| 7179 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7180 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 7181 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7182 | |
| 7183 | root->AddChild(parent); |
| 7184 | parent->AddChild(child); |
| 7185 | |
| 7186 | gfx::Transform identity_transform; |
| 7187 | SetLayerPropertiesForTesting(root.get(), |
| 7188 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7189 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7190 | gfx::PointF(), |
| 7191 | gfx::Size(50, 50), |
| 7192 | true, |
| 7193 | true); |
| 7194 | root->SetForceRenderSurface(true); |
| 7195 | SetLayerPropertiesForTesting(parent.get(), |
| 7196 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7197 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7198 | gfx::PointF(), |
| 7199 | gfx::Size(30, 30), |
| 7200 | true, |
| 7201 | true); |
| 7202 | parent->SetForceRenderSurface(true); |
| 7203 | SetLayerPropertiesForTesting(child.get(), |
| 7204 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7205 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7206 | gfx::PointF(), |
| 7207 | gfx::Size(20, 20), |
| 7208 | true, |
| 7209 | true); |
| 7210 | child->SetForceRenderSurface(true); |
| 7211 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7212 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7213 | host->SetRootLayer(root); |
| 7214 | |
| 7215 | ExecuteCalculateDrawProperties(root.get()); |
| 7216 | |
| 7217 | EXPECT_EQ(3u, render_surface_layer_list()->size()); |
| 7218 | |
| 7219 | gfx::Transform singular_transform; |
| 7220 | singular_transform.Scale3d( |
| 7221 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 7222 | |
| 7223 | child->SetTransform(singular_transform); |
| 7224 | |
| 7225 | ExecuteCalculateDrawProperties(root.get()); |
| 7226 | |
| 7227 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 7228 | |
| 7229 | // Ensure that the entire subtree under a layer with singular transform does |
| 7230 | // not get rendered. |
| 7231 | parent->SetTransform(singular_transform); |
| 7232 | child->SetTransform(identity_transform); |
| 7233 | |
| 7234 | ExecuteCalculateDrawProperties(root.get()); |
| 7235 | |
| 7236 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 7237 | } |
| 7238 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7239 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 7240 | // Checks that clipping by a scroll parent that follows you in paint order |
| 7241 | // still results in correct clipping. |
| 7242 | // |
| 7243 | // + root |
| 7244 | // + scroll_child |
| 7245 | // + scroll_parent_border |
| 7246 | // + scroll_parent_clip |
| 7247 | // + scroll_parent |
| 7248 | // |
| 7249 | scoped_refptr<Layer> root = Layer::Create(); |
| 7250 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7251 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7252 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7253 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7254 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7255 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7256 | |
| 7257 | root->AddChild(scroll_parent_border); |
| 7258 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7259 | scroll_parent_clip->AddChild(scroll_parent); |
| 7260 | |
| 7261 | root->AddChild(scroll_child); |
| 7262 | |
| 7263 | scroll_parent_clip->SetMasksToBounds(true); |
| 7264 | |
| 7265 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7266 | |
| 7267 | gfx::Transform identity_transform; |
| 7268 | SetLayerPropertiesForTesting(root.get(), |
| 7269 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7270 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7271 | gfx::PointF(), |
| 7272 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7273 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7274 | false); |
| 7275 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7276 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7277 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7278 | gfx::PointF(), |
| 7279 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7280 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7281 | false); |
| 7282 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7283 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7284 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7285 | gfx::PointF(), |
| 7286 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7287 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7288 | false); |
| 7289 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7290 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7291 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7292 | gfx::PointF(), |
| 7293 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7294 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7295 | false); |
| 7296 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7297 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7298 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7299 | gfx::PointF(), |
| 7300 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7301 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7302 | false); |
| 7303 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7304 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7305 | host->SetRootLayer(root); |
| 7306 | |
| 7307 | ExecuteCalculateDrawProperties(root.get()); |
| 7308 | |
| 7309 | EXPECT_TRUE(root->render_surface()); |
| 7310 | |
| 7311 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 7312 | scroll_child->clip_rect().ToString()); |
| 7313 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7314 | } |
| 7315 | |
| 7316 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 7317 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 7318 | // you in paint order still results in correct clipping. |
| 7319 | // |
| 7320 | // + root |
| 7321 | // + scroll_child |
| 7322 | // + scroll_parent_border |
| 7323 | // | + scroll_parent_clip |
| 7324 | // | + scroll_parent |
| 7325 | // + scroll_grandparent_border |
| 7326 | // + scroll_grandparent_clip |
| 7327 | // + scroll_grandparent |
| 7328 | // |
| 7329 | scoped_refptr<Layer> root = Layer::Create(); |
| 7330 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7331 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7332 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7333 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7334 | |
| 7335 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 7336 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 7337 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 7338 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7339 | |
| 7340 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7341 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7342 | |
| 7343 | root->AddChild(scroll_child); |
| 7344 | |
| 7345 | root->AddChild(scroll_parent_border); |
| 7346 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7347 | scroll_parent_clip->AddChild(scroll_parent); |
| 7348 | |
| 7349 | root->AddChild(scroll_grandparent_border); |
| 7350 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 7351 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 7352 | |
| 7353 | scroll_parent_clip->SetMasksToBounds(true); |
| 7354 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 7355 | |
| 7356 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7357 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 7358 | |
| 7359 | gfx::Transform identity_transform; |
| 7360 | SetLayerPropertiesForTesting(root.get(), |
| 7361 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7362 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7363 | gfx::PointF(), |
| 7364 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7365 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7366 | false); |
| 7367 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 7368 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7369 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7370 | gfx::PointF(), |
| 7371 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7372 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7373 | false); |
| 7374 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 7375 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7376 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7377 | gfx::PointF(), |
| 7378 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7379 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7380 | false); |
| 7381 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 7382 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7383 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7384 | gfx::PointF(), |
| 7385 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7386 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7387 | false); |
| 7388 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7389 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7390 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7391 | gfx::PointF(), |
| 7392 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7393 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7394 | false); |
| 7395 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7396 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7397 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7398 | gfx::PointF(), |
| 7399 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7400 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7401 | false); |
| 7402 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7403 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7404 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7405 | gfx::PointF(), |
| 7406 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7407 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7408 | false); |
| 7409 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7410 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7411 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7412 | gfx::PointF(), |
| 7413 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7414 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7415 | false); |
| 7416 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7417 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7418 | host->SetRootLayer(root); |
| 7419 | |
| 7420 | ExecuteCalculateDrawProperties(root.get()); |
| 7421 | |
| 7422 | EXPECT_TRUE(root->render_surface()); |
| 7423 | |
| 7424 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 7425 | scroll_child->clip_rect().ToString()); |
| 7426 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7427 | |
| 7428 | // Despite the fact that we visited the above layers out of order to get the |
| 7429 | // correct clip, the layer lists should be unaffected. |
| 7430 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 7431 | EXPECT_EQ(scroll_child.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7432 | root->render_surface()->layer_list().at(0).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7433 | EXPECT_EQ(scroll_parent.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7434 | root->render_surface()->layer_list().at(1).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7435 | EXPECT_EQ(scroll_grandparent.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7436 | root->render_surface()->layer_list().at(2).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7437 | } |
| 7438 | |
| 7439 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 7440 | // 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] | 7441 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7442 | // + root |
| 7443 | // + scroll_child |
| 7444 | // + scroll_parent_border |
| 7445 | // + scroll_parent_clip |
| 7446 | // + scroll_parent |
| 7447 | // + render_surface1 |
| 7448 | // + scroll_grandparent_border |
| 7449 | // + scroll_grandparent_clip |
| 7450 | // + scroll_grandparent |
| 7451 | // + render_surface2 |
| 7452 | // |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 7453 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 7454 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7455 | |
| 7456 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7457 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7458 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7459 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7460 | scoped_refptr<LayerWithForcedDrawsContent> render_surface1 = |
| 7461 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7462 | |
| 7463 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 7464 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 7465 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 7466 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7467 | scoped_refptr<LayerWithForcedDrawsContent> render_surface2 = |
| 7468 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7469 | |
| 7470 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7471 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7472 | |
| 7473 | root->AddChild(scroll_child); |
| 7474 | |
| 7475 | root->AddChild(scroll_parent_border); |
| 7476 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7477 | scroll_parent_clip->AddChild(scroll_parent); |
| 7478 | scroll_parent->AddChild(render_surface2); |
| 7479 | |
| 7480 | root->AddChild(scroll_grandparent_border); |
| 7481 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 7482 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 7483 | scroll_grandparent->AddChild(render_surface1); |
| 7484 | |
| 7485 | scroll_parent_clip->SetMasksToBounds(true); |
| 7486 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 7487 | |
| 7488 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7489 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 7490 | |
| 7491 | render_surface1->SetForceRenderSurface(true); |
| 7492 | render_surface2->SetForceRenderSurface(true); |
| 7493 | |
| 7494 | gfx::Transform identity_transform; |
| 7495 | SetLayerPropertiesForTesting(root.get(), |
| 7496 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7497 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7498 | gfx::PointF(), |
| 7499 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7500 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7501 | false); |
| 7502 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 7503 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7504 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7505 | gfx::PointF(), |
| 7506 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7507 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7508 | false); |
| 7509 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 7510 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7511 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7512 | gfx::PointF(), |
| 7513 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7514 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7515 | false); |
| 7516 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 7517 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7518 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7519 | gfx::PointF(), |
| 7520 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7521 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7522 | false); |
| 7523 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 7524 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7525 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7526 | gfx::PointF(), |
| 7527 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7528 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7529 | false); |
| 7530 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7531 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7532 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7533 | gfx::PointF(), |
| 7534 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7535 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7536 | false); |
| 7537 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7538 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7539 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7540 | gfx::PointF(), |
| 7541 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7542 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7543 | false); |
| 7544 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7545 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7546 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7547 | gfx::PointF(), |
| 7548 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7549 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7550 | false); |
| 7551 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 7552 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7553 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7554 | gfx::PointF(), |
| 7555 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7556 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7557 | false); |
| 7558 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7559 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7560 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7561 | gfx::PointF(), |
| 7562 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7563 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7564 | false); |
| 7565 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7566 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7567 | host->SetRootLayer(root); |
| 7568 | |
| 7569 | RenderSurfaceLayerList render_surface_layer_list; |
| 7570 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7571 | root.get(), |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7572 | root->bounds(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7573 | identity_transform, |
| 7574 | &render_surface_layer_list); |
| 7575 | |
| 7576 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7577 | |
| 7578 | EXPECT_TRUE(root->render_surface()); |
| 7579 | |
| 7580 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 7581 | scroll_child->clip_rect().ToString()); |
| 7582 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7583 | |
| 7584 | // Despite the fact that we had to process the layers out of order to get the |
| 7585 | // right clip, our render_surface_layer_list's order should be unaffected. |
| 7586 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
| 7587 | EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); |
| 7588 | EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); |
| 7589 | EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 7590 | EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); |
| 7591 | EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); |
| 7592 | EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7593 | } |
| 7594 | |
eroman | 822f0dc3 | 2015-02-27 22:12:26 | [diff] [blame] | 7595 | TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) { |
| 7596 | // We rearrange layer list contributions if we have to visit children out of |
| 7597 | // order, but it should be a 'stable' rearrangement. That is, the layer list |
| 7598 | // additions for a single layer should not be reordered, though their position |
| 7599 | // wrt to the contributions due to a sibling may vary. |
| 7600 | // |
| 7601 | // + root |
| 7602 | // + scroll_child |
| 7603 | // + top_content |
| 7604 | // + bottom_content |
| 7605 | // + scroll_parent_border |
| 7606 | // + scroll_parent_clip |
| 7607 | // + scroll_parent |
| 7608 | // |
| 7609 | FakeImplProxy proxy; |
| 7610 | TestSharedBitmapManager shared_bitmap_manager; |
| 7611 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 7612 | host_impl.CreatePendingTree(); |
| 7613 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7614 | scoped_ptr<LayerImpl> scroll_parent_border = |
| 7615 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7616 | scoped_ptr<LayerImpl> scroll_parent_clip = |
| 7617 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7618 | scoped_ptr<LayerImpl> scroll_parent = |
| 7619 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 7620 | scoped_ptr<LayerImpl> scroll_child = |
| 7621 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 7622 | scoped_ptr<LayerImpl> bottom_content = |
| 7623 | LayerImpl::Create(host_impl.active_tree(), 6); |
| 7624 | scoped_ptr<LayerImpl> top_content = |
| 7625 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 7626 | |
| 7627 | scroll_parent_clip->SetMasksToBounds(true); |
| 7628 | |
| 7629 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7630 | scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); |
| 7631 | scroll_children->insert(scroll_child.get()); |
| 7632 | scroll_parent->SetScrollChildren(scroll_children.release()); |
| 7633 | |
| 7634 | scroll_child->SetDrawsContent(true); |
| 7635 | scroll_parent->SetDrawsContent(true); |
| 7636 | top_content->SetDrawsContent(true); |
| 7637 | bottom_content->SetDrawsContent(true); |
| 7638 | |
| 7639 | gfx::Transform identity_transform; |
| 7640 | gfx::Transform top_transform; |
| 7641 | top_transform.Translate3d(0.0, 0.0, 5.0); |
| 7642 | gfx::Transform bottom_transform; |
| 7643 | bottom_transform.Translate3d(0.0, 0.0, 3.0); |
| 7644 | |
| 7645 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7646 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7647 | true); |
| 7648 | SetLayerPropertiesForTesting(scroll_parent_border.get(), identity_transform, |
| 7649 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7650 | true, false, false); |
| 7651 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), identity_transform, |
| 7652 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 7653 | true, false, false); |
| 7654 | SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform, |
| 7655 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 7656 | true, false, false); |
| 7657 | SetLayerPropertiesForTesting(scroll_child.get(), identity_transform, |
| 7658 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 7659 | true, false, false); |
| 7660 | SetLayerPropertiesForTesting(top_content.get(), top_transform, gfx::Point3F(), |
| 7661 | gfx::PointF(), gfx::Size(50, 50), false, true, |
| 7662 | true); |
| 7663 | SetLayerPropertiesForTesting(bottom_content.get(), bottom_transform, |
| 7664 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 7665 | false, true, true); |
| 7666 | |
| 7667 | scroll_child->SetShouldFlattenTransform(false); |
| 7668 | scroll_child->Set3dSortingContextId(1); |
| 7669 | |
| 7670 | scroll_child->AddChild(top_content.Pass()); |
| 7671 | scroll_child->AddChild(bottom_content.Pass()); |
| 7672 | root->AddChild(scroll_child.Pass()); |
| 7673 | |
| 7674 | scroll_parent_clip->AddChild(scroll_parent.Pass()); |
| 7675 | scroll_parent_border->AddChild(scroll_parent_clip.Pass()); |
| 7676 | root->AddChild(scroll_parent_border.Pass()); |
| 7677 | |
| 7678 | LayerImplList render_surface_layer_list; |
| 7679 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7680 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7681 | |
| 7682 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7683 | |
| 7684 | EXPECT_TRUE(root->render_surface()); |
| 7685 | |
| 7686 | // If we don't sort by depth and let the layers get added in the order they |
| 7687 | // would normally be visited in, then layers 6 and 7 will be out of order. In |
| 7688 | // other words, although we've had to shift 5, 6, and 7 to appear before 4 |
| 7689 | // in the list (because of the scroll parent relationship), this should not |
| 7690 | // have an effect on the the order of 5, 6, and 7 (which had been reordered |
| 7691 | // due to layer sorting). |
| 7692 | EXPECT_EQ(4u, root->render_surface()->layer_list().size()); |
| 7693 | EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id()); |
| 7694 | EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id()); |
| 7695 | EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id()); |
| 7696 | EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id()); |
| 7697 | } |
| 7698 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7699 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 7700 | // This test verifies that a scrolling layer that gets snapped to |
| 7701 | // integer coordinates doesn't move a fixed position child. |
| 7702 | // |
| 7703 | // + root |
| 7704 | // + container |
| 7705 | // + scroller |
| 7706 | // + fixed |
| 7707 | // |
| 7708 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7709 | TestSharedBitmapManager shared_bitmap_manager; |
| 7710 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7711 | host_impl.CreatePendingTree(); |
| 7712 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7713 | scoped_ptr<LayerImpl> container = |
| 7714 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7715 | LayerImpl* container_layer = container.get(); |
| 7716 | scoped_ptr<LayerImpl> scroller = |
| 7717 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7718 | LayerImpl* scroll_layer = scroller.get(); |
| 7719 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7720 | LayerImpl* fixed_layer = fixed.get(); |
| 7721 | |
| 7722 | container->SetIsContainerForFixedPositionLayers(true); |
| 7723 | |
| 7724 | LayerPositionConstraint constraint; |
| 7725 | constraint.set_is_fixed_position(true); |
| 7726 | fixed->SetPositionConstraint(constraint); |
| 7727 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 7728 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7729 | |
| 7730 | gfx::Transform identity_transform; |
| 7731 | gfx::Transform container_transform; |
| 7732 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7733 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7734 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7735 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7736 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7737 | true); |
| 7738 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7739 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7740 | true, false, false); |
| 7741 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7742 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 7743 | true, false, false); |
| 7744 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7745 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7746 | false); |
| 7747 | |
| 7748 | scroller->AddChild(fixed.Pass()); |
| 7749 | container->AddChild(scroller.Pass()); |
| 7750 | root->AddChild(container.Pass()); |
| 7751 | |
| 7752 | // Rounded to integers already. |
| 7753 | { |
| 7754 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
| 7755 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7756 | |
| 7757 | LayerImplList render_surface_layer_list; |
| 7758 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7759 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7760 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7761 | |
| 7762 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7763 | container_layer->draw_properties().screen_space_transform, |
| 7764 | fixed_layer->draw_properties().screen_space_transform); |
| 7765 | EXPECT_VECTOR_EQ( |
| 7766 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7767 | container_offset); |
| 7768 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7769 | .screen_space_transform.To2dTranslation(), |
| 7770 | container_offset - scroll_delta); |
| 7771 | } |
| 7772 | |
| 7773 | // Scroll delta requiring rounding. |
| 7774 | { |
| 7775 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
| 7776 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7777 | |
| 7778 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 7779 | |
| 7780 | LayerImplList render_surface_layer_list; |
| 7781 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7782 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7783 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7784 | |
| 7785 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7786 | container_layer->draw_properties().screen_space_transform, |
| 7787 | fixed_layer->draw_properties().screen_space_transform); |
| 7788 | EXPECT_VECTOR_EQ( |
| 7789 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7790 | container_offset); |
| 7791 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7792 | .screen_space_transform.To2dTranslation(), |
| 7793 | container_offset - rounded_scroll_delta); |
| 7794 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7795 | |
| 7796 | // Scale is applied earlier in the tree. |
| 7797 | { |
| 7798 | gfx::Transform scaled_container_transform = container_transform; |
| 7799 | scaled_container_transform.Scale3d(3.0, 3.0, 1.0); |
| 7800 | container_layer->SetTransform(scaled_container_transform); |
| 7801 | |
| 7802 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7803 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7804 | |
| 7805 | LayerImplList render_surface_layer_list; |
| 7806 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7807 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7808 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7809 | |
| 7810 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7811 | container_layer->draw_properties().screen_space_transform, |
| 7812 | fixed_layer->draw_properties().screen_space_transform); |
| 7813 | EXPECT_VECTOR_EQ( |
| 7814 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7815 | container_offset); |
| 7816 | |
| 7817 | container_layer->SetTransform(container_transform); |
| 7818 | } |
| 7819 | |
| 7820 | // Scale is applied on the scroll layer itself. |
| 7821 | { |
| 7822 | gfx::Transform scale_transform; |
| 7823 | scale_transform.Scale3d(3.0, 3.0, 1.0); |
| 7824 | scroll_layer->SetTransform(scale_transform); |
| 7825 | |
| 7826 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7827 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7828 | |
| 7829 | LayerImplList render_surface_layer_list; |
| 7830 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7831 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7832 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7833 | |
| 7834 | EXPECT_VECTOR_EQ( |
| 7835 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7836 | container_offset); |
| 7837 | |
| 7838 | scroll_layer->SetTransform(identity_transform); |
| 7839 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7840 | } |
| 7841 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7842 | TEST_F(LayerTreeHostCommonTest, |
| 7843 | ScrollCompensationMainScrollOffsetFractionalPart) { |
| 7844 | // This test verifies that a scrolling layer that has fractional scroll offset |
| 7845 | // from main doesn't move a fixed position child. |
| 7846 | // |
| 7847 | // + root |
| 7848 | // + container |
| 7849 | // + scroller |
| 7850 | // + fixed |
| 7851 | // |
| 7852 | FakeImplProxy proxy; |
| 7853 | TestSharedBitmapManager shared_bitmap_manager; |
| 7854 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 7855 | host_impl.CreatePendingTree(); |
| 7856 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7857 | scoped_ptr<LayerImpl> container = |
| 7858 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7859 | LayerImpl* container_layer = container.get(); |
| 7860 | scoped_ptr<LayerImpl> scroller = |
| 7861 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7862 | LayerImpl* scroll_layer = scroller.get(); |
| 7863 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7864 | LayerImpl* fixed_layer = fixed.get(); |
| 7865 | |
| 7866 | container->SetIsContainerForFixedPositionLayers(true); |
| 7867 | |
| 7868 | LayerPositionConstraint constraint; |
| 7869 | constraint.set_is_fixed_position(true); |
| 7870 | fixed->SetPositionConstraint(constraint); |
| 7871 | |
| 7872 | scroller->SetScrollClipLayer(container->id()); |
| 7873 | |
| 7874 | gfx::Transform identity_transform; |
| 7875 | gfx::Transform container_transform; |
| 7876 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7877 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7878 | |
| 7879 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7880 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7881 | true); |
| 7882 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7883 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7884 | true, false, false); |
| 7885 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7886 | gfx::Point3F(), gfx::PointF(0.0, 0.0), |
| 7887 | gfx::Size(30, 30), true, false, false); |
| 7888 | |
| 7889 | gfx::ScrollOffset scroll_offset(3.3, 4.2); |
| 7890 | gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f); |
| 7891 | gfx::Vector2dF scroll_delta(0.1f, 0.4f); |
| 7892 | // Blink only uses the integer part of the scroll_offset for fixed |
| 7893 | // position layer. |
| 7894 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7895 | gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true, |
| 7896 | false, false); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 7897 | scroll_layer->PushScrollOffsetFromMainThread(scroll_offset); |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 7898 | scroll_layer->SetScrollDelta(scroll_delta); |
miletus | ff93ab7 | 2015-01-30 04:30:44 | [diff] [blame] | 7899 | scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7900 | |
| 7901 | scroller->AddChild(fixed.Pass()); |
| 7902 | container->AddChild(scroller.Pass()); |
| 7903 | root->AddChild(container.Pass()); |
| 7904 | |
| 7905 | LayerImplList render_surface_layer_list; |
| 7906 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7907 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7908 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7909 | |
| 7910 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7911 | container_layer->draw_properties().screen_space_transform, |
| 7912 | fixed_layer->draw_properties().screen_space_transform); |
| 7913 | EXPECT_VECTOR_EQ( |
| 7914 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7915 | container_offset); |
| 7916 | |
| 7917 | gfx::ScrollOffset effective_scroll_offset = |
| 7918 | ScrollOffsetWithDelta(scroll_offset, scroll_delta); |
| 7919 | gfx::Vector2d rounded_effective_scroll_offset = |
| 7920 | ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset)); |
| 7921 | EXPECT_VECTOR_EQ( |
| 7922 | scroll_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7923 | container_offset - rounded_effective_scroll_offset); |
| 7924 | } |
| 7925 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7926 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7927 | public: |
| 7928 | static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
| 7929 | LayerTreeImpl* tree_impl, |
| 7930 | int id) { |
| 7931 | return make_scoped_ptr( |
| 7932 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7933 | } |
| 7934 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7935 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7936 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7937 | private: |
| 7938 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7939 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7940 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7941 | SetDrawsContent(true); |
| 7942 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7943 | }; |
| 7944 | |
| 7945 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
| 7946 | FakeImplProxy proxy; |
| 7947 | TestSharedBitmapManager shared_bitmap_manager; |
| 7948 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 7949 | gfx::Transform identity_matrix; |
| 7950 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
| 7951 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
| 7952 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
| 7953 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
| 7954 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
| 7955 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
| 7956 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
| 7957 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7958 | |
| 7959 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7960 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7961 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
| 7962 | |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 7963 | child->AddChild(grand_child.Pass()); |
| 7964 | parent->AddChild(child.Pass()); |
| 7965 | grand_parent->AddChild(parent.Pass()); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7966 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7967 | SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix, |
| 7968 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7969 | true, false, true); |
| 7970 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 7971 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7972 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7973 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 7974 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7975 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7976 | |
| 7977 | SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(), |
| 7978 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7979 | false); |
| 7980 | |
| 7981 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7982 | |
| 7983 | // No layers have animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7984 | EXPECT_EQ(0.f, |
| 7985 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7986 | EXPECT_EQ(0.f, |
| 7987 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7988 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7989 | EXPECT_EQ( |
| 7990 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7991 | |
| 7992 | TransformOperations translation; |
| 7993 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7994 | |
| 7995 | AddAnimatedTransformToLayer( |
| 7996 | parent_raw, 1.0, TransformOperations(), translation); |
| 7997 | |
| 7998 | // No layers have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7999 | EXPECT_EQ(0.f, |
| 8000 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8001 | EXPECT_EQ(0.f, |
| 8002 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8003 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8004 | EXPECT_EQ( |
| 8005 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8006 | |
| 8007 | TransformOperations scale; |
| 8008 | scale.AppendScale(5.f, 4.f, 3.f); |
| 8009 | |
| 8010 | AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); |
| 8011 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8012 | |
| 8013 | // Only |child| has a scale-affecting animation. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8014 | EXPECT_EQ(0.f, |
| 8015 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8016 | EXPECT_EQ(0.f, |
| 8017 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8018 | EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8019 | EXPECT_EQ( |
| 8020 | 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8021 | |
| 8022 | AddAnimatedTransformToLayer( |
| 8023 | grand_parent.get(), 1.0, TransformOperations(), scale); |
| 8024 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8025 | |
| 8026 | // |grand_parent| and |child| have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8027 | EXPECT_EQ(5.f, |
| 8028 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8029 | EXPECT_EQ(5.f, |
| 8030 | parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8031 | // We don't support combining animated scales from two nodes; 0.f means |
| 8032 | // that the maximum scale could not be computed. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8033 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8034 | EXPECT_EQ( |
| 8035 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8036 | |
| 8037 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 8038 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8039 | |
| 8040 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8041 | EXPECT_EQ(5.f, |
| 8042 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8043 | EXPECT_EQ(0.f, |
| 8044 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8045 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8046 | EXPECT_EQ( |
| 8047 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8048 | |
| 8049 | grand_parent->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8050 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8051 | parent_raw->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8052 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8053 | child_raw->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8054 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8055 | |
| 8056 | TransformOperations perspective; |
| 8057 | perspective.AppendPerspective(10.f); |
| 8058 | |
| 8059 | AddAnimatedTransformToLayer( |
| 8060 | child_raw, 1.0, TransformOperations(), perspective); |
| 8061 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8062 | |
| 8063 | // |child| has a scale-affecting animation but computing the maximum of this |
| 8064 | // animation is not supported. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8065 | EXPECT_EQ(0.f, |
| 8066 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8067 | EXPECT_EQ(0.f, |
| 8068 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8069 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8070 | EXPECT_EQ( |
| 8071 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8072 | |
| 8073 | child_raw->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8074 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8075 | |
| 8076 | gfx::Transform scale_matrix; |
| 8077 | scale_matrix.Scale(1.f, 2.f); |
| 8078 | grand_parent->SetTransform(scale_matrix); |
| 8079 | parent_raw->SetTransform(scale_matrix); |
| 8080 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 8081 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8082 | |
| 8083 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 8084 | // animation with maximum scale 5.f. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8085 | EXPECT_EQ(0.f, |
| 8086 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8087 | EXPECT_EQ(10.f, |
| 8088 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8089 | EXPECT_EQ(10.f, |
| 8090 | child_raw->draw_properties().maximum_animation_contents_scale); |
| 8091 | EXPECT_EQ( |
| 8092 | 10.f, |
| 8093 | grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8094 | |
| 8095 | gfx::Transform perspective_matrix; |
| 8096 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 8097 | child_raw->SetTransform(perspective_matrix); |
| 8098 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8099 | |
| 8100 | // |child| has a transform that's neither a translation nor a scale. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8101 | EXPECT_EQ(0.f, |
| 8102 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8103 | EXPECT_EQ(10.f, |
| 8104 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8105 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8106 | EXPECT_EQ( |
| 8107 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8108 | |
| 8109 | parent_raw->SetTransform(perspective_matrix); |
| 8110 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8111 | |
| 8112 | // |parent| and |child| have transforms that are neither translations nor |
| 8113 | // scales. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8114 | EXPECT_EQ(0.f, |
| 8115 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8116 | EXPECT_EQ(0.f, |
| 8117 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8118 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8119 | EXPECT_EQ( |
| 8120 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8121 | |
| 8122 | parent_raw->SetTransform(identity_matrix); |
| 8123 | child_raw->SetTransform(identity_matrix); |
| 8124 | grand_parent->SetTransform(perspective_matrix); |
| 8125 | |
| 8126 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8127 | |
| 8128 | // |grand_parent| has a transform that's neither a translation nor a scale. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8129 | EXPECT_EQ(0.f, |
| 8130 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8131 | EXPECT_EQ(0.f, |
| 8132 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8133 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8134 | EXPECT_EQ( |
| 8135 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8136 | } |
| 8137 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8138 | static int membership_id(LayerImpl* layer) { |
| 8139 | return layer->draw_properties().last_drawn_render_surface_layer_list_id; |
| 8140 | } |
| 8141 | |
| 8142 | static void GatherDrawnLayers(LayerImplList* rsll, |
| 8143 | std::set<LayerImpl*>* drawn_layers) { |
| 8144 | for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll), |
| 8145 | end = LayerIterator<LayerImpl>::End(rsll); |
| 8146 | it != end; |
| 8147 | ++it) { |
| 8148 | LayerImpl* layer = *it; |
| 8149 | if (it.represents_itself()) |
| 8150 | drawn_layers->insert(layer); |
| 8151 | |
| 8152 | if (!it.represents_contributing_render_surface()) |
| 8153 | continue; |
| 8154 | |
| 8155 | if (layer->mask_layer()) |
| 8156 | drawn_layers->insert(layer->mask_layer()); |
| 8157 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 8158 | drawn_layers->insert(layer->replica_layer()->mask_layer()); |
| 8159 | } |
| 8160 | } |
| 8161 | |
| 8162 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
| 8163 | FakeImplProxy proxy; |
| 8164 | TestSharedBitmapManager shared_bitmap_manager; |
| 8165 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 8166 | gfx::Transform identity_matrix; |
| 8167 | |
| 8168 | scoped_ptr<LayerImpl> grand_parent = |
| 8169 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8170 | scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3); |
| 8171 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5); |
| 8172 | scoped_ptr<LayerImpl> grand_child1 = |
| 8173 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 8174 | scoped_ptr<LayerImpl> grand_child2 = |
| 8175 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 8176 | |
| 8177 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 8178 | LayerImpl* parent_raw = parent.get(); |
| 8179 | LayerImpl* child_raw = child.get(); |
| 8180 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 8181 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 8182 | |
| 8183 | child->AddChild(grand_child1.Pass()); |
| 8184 | child->AddChild(grand_child2.Pass()); |
| 8185 | parent->AddChild(child.Pass()); |
| 8186 | grand_parent->AddChild(parent.Pass()); |
| 8187 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8188 | SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, |
| 8189 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8190 | true, false, true); |
| 8191 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 8192 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8193 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8194 | |
| 8195 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 8196 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8197 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8198 | |
| 8199 | SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix, |
| 8200 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8201 | true, false, false); |
| 8202 | |
| 8203 | SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix, |
| 8204 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8205 | true, false, false); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8206 | |
| 8207 | // Start with nothing being drawn. |
| 8208 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8209 | int member_id = render_surface_layer_list_count(); |
| 8210 | |
| 8211 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8212 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8213 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8214 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8215 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8216 | |
| 8217 | std::set<LayerImpl*> expected; |
| 8218 | std::set<LayerImpl*> actual; |
| 8219 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8220 | EXPECT_EQ(expected, actual); |
| 8221 | |
| 8222 | // If we force render surface, but none of the layers are in the layer list, |
| 8223 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8224 | grand_child1_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8225 | |
| 8226 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8227 | member_id = render_surface_layer_list_count(); |
| 8228 | |
| 8229 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8230 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8231 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8232 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8233 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8234 | |
| 8235 | expected.clear(); |
| 8236 | actual.clear(); |
| 8237 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8238 | EXPECT_EQ(expected, actual); |
| 8239 | |
| 8240 | // However, if we say that this layer also draws content, it will appear in |
| 8241 | // RSLL. |
| 8242 | grand_child1_raw->SetDrawsContent(true); |
| 8243 | |
| 8244 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8245 | member_id = render_surface_layer_list_count(); |
| 8246 | |
| 8247 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8248 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8249 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8250 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 8251 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8252 | |
| 8253 | expected.clear(); |
| 8254 | expected.insert(grand_child1_raw); |
| 8255 | |
| 8256 | actual.clear(); |
| 8257 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8258 | EXPECT_EQ(expected, actual); |
| 8259 | |
| 8260 | // Now child is forced to have a render surface, and one if its children draws |
| 8261 | // content. |
| 8262 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8263 | grand_child1_raw->SetHasRenderSurface(false); |
| 8264 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8265 | grand_child2_raw->SetDrawsContent(true); |
| 8266 | |
| 8267 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8268 | member_id = render_surface_layer_list_count(); |
| 8269 | |
| 8270 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8271 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8272 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8273 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8274 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8275 | |
| 8276 | expected.clear(); |
| 8277 | expected.insert(grand_child2_raw); |
| 8278 | |
| 8279 | actual.clear(); |
| 8280 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8281 | EXPECT_EQ(expected, actual); |
| 8282 | |
| 8283 | // Add a mask layer to child. |
| 8284 | child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass()); |
| 8285 | |
| 8286 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8287 | member_id = render_surface_layer_list_count(); |
| 8288 | |
| 8289 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8290 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8291 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8292 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8293 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8294 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8295 | |
| 8296 | expected.clear(); |
| 8297 | expected.insert(grand_child2_raw); |
| 8298 | expected.insert(child_raw->mask_layer()); |
| 8299 | |
| 8300 | expected.clear(); |
| 8301 | expected.insert(grand_child2_raw); |
| 8302 | expected.insert(child_raw->mask_layer()); |
| 8303 | |
| 8304 | actual.clear(); |
| 8305 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8306 | EXPECT_EQ(expected, actual); |
| 8307 | |
| 8308 | // Add replica mask layer. |
| 8309 | scoped_ptr<LayerImpl> replica_layer = |
| 8310 | LayerImpl::Create(host_impl.active_tree(), 20); |
| 8311 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21)); |
| 8312 | child_raw->SetReplicaLayer(replica_layer.Pass()); |
| 8313 | |
| 8314 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8315 | member_id = render_surface_layer_list_count(); |
| 8316 | |
| 8317 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8318 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8319 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8320 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8321 | EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer())); |
| 8322 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8323 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8324 | |
| 8325 | expected.clear(); |
| 8326 | expected.insert(grand_child2_raw); |
| 8327 | expected.insert(child_raw->mask_layer()); |
| 8328 | expected.insert(child_raw->replica_layer()->mask_layer()); |
| 8329 | |
| 8330 | actual.clear(); |
| 8331 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8332 | EXPECT_EQ(expected, actual); |
| 8333 | |
| 8334 | child_raw->TakeReplicaLayer(); |
| 8335 | |
| 8336 | // With nothing drawing, we should have no layers. |
| 8337 | grand_child2_raw->SetDrawsContent(false); |
| 8338 | |
| 8339 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8340 | member_id = render_surface_layer_list_count(); |
| 8341 | |
| 8342 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8343 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8344 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8345 | EXPECT_NE(member_id, membership_id(child_raw->mask_layer())); |
| 8346 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8347 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8348 | |
| 8349 | expected.clear(); |
| 8350 | actual.clear(); |
| 8351 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8352 | EXPECT_EQ(expected, actual); |
| 8353 | |
| 8354 | // Child itself draws means that we should have the child and the mask in the |
| 8355 | // list. |
| 8356 | child_raw->SetDrawsContent(true); |
| 8357 | |
| 8358 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8359 | member_id = render_surface_layer_list_count(); |
| 8360 | |
| 8361 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8362 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8363 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 8364 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8365 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8366 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8367 | |
| 8368 | expected.clear(); |
| 8369 | expected.insert(child_raw); |
| 8370 | expected.insert(child_raw->mask_layer()); |
| 8371 | actual.clear(); |
| 8372 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8373 | EXPECT_EQ(expected, actual); |
| 8374 | |
| 8375 | child_raw->TakeMaskLayer(); |
| 8376 | |
| 8377 | // Now everyone's a member! |
| 8378 | grand_parent_raw->SetDrawsContent(true); |
| 8379 | parent_raw->SetDrawsContent(true); |
| 8380 | child_raw->SetDrawsContent(true); |
| 8381 | grand_child1_raw->SetDrawsContent(true); |
| 8382 | grand_child2_raw->SetDrawsContent(true); |
| 8383 | |
| 8384 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8385 | member_id = render_surface_layer_list_count(); |
| 8386 | |
| 8387 | EXPECT_EQ(member_id, membership_id(grand_parent_raw)); |
| 8388 | EXPECT_EQ(member_id, membership_id(parent_raw)); |
| 8389 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 8390 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 8391 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8392 | |
| 8393 | expected.clear(); |
| 8394 | expected.insert(grand_parent_raw); |
| 8395 | expected.insert(parent_raw); |
| 8396 | expected.insert(child_raw); |
| 8397 | expected.insert(grand_child1_raw); |
| 8398 | expected.insert(grand_child2_raw); |
| 8399 | |
| 8400 | actual.clear(); |
| 8401 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8402 | EXPECT_EQ(expected, actual); |
| 8403 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8404 | |
| 8405 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
| 8406 | FakeImplProxy proxy; |
| 8407 | TestSharedBitmapManager shared_bitmap_manager; |
| 8408 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 8409 | |
| 8410 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 8411 | LayerImpl* root_layer = root.get(); |
| 8412 | scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2); |
| 8413 | LayerImpl* child1_layer = child1.get(); |
| 8414 | scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3); |
| 8415 | LayerImpl* child2_layer = child2.get(); |
| 8416 | |
| 8417 | root->AddChild(child1.Pass()); |
| 8418 | root->AddChild(child2.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8419 | root->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8420 | |
| 8421 | gfx::Transform identity_matrix, scale_transform_child1, |
| 8422 | scale_transform_child2; |
| 8423 | scale_transform_child1.Scale(2, 3); |
| 8424 | scale_transform_child2.Scale(4, 5); |
| 8425 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8426 | SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(), |
| 8427 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 8428 | true); |
| 8429 | SetLayerPropertiesForTesting(child1_layer, scale_transform_child1, |
| 8430 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 8431 | false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8432 | |
| 8433 | child1_layer->SetMaskLayer( |
| 8434 | LayerImpl::Create(host_impl.active_tree(), 4).Pass()); |
| 8435 | |
| 8436 | scoped_ptr<LayerImpl> replica_layer = |
| 8437 | LayerImpl::Create(host_impl.active_tree(), 5); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8438 | replica_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8439 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
| 8440 | child1_layer->SetReplicaLayer(replica_layer.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8441 | child1_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8442 | |
| 8443 | ExecuteCalculateDrawProperties(root_layer); |
| 8444 | |
| 8445 | TransformOperations scale; |
| 8446 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8447 | |
| 8448 | AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8449 | SetLayerPropertiesForTesting(child2_layer, scale_transform_child2, |
| 8450 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 8451 | false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8452 | |
| 8453 | ExecuteCalculateDrawProperties(root_layer); |
| 8454 | |
| 8455 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); |
| 8456 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8457 | EXPECT_FLOAT_EQ( |
| 8458 | 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8459 | EXPECT_FLOAT_EQ(3.f, |
| 8460 | child1_layer->replica_layer() |
| 8461 | ->mask_layer() |
| 8462 | ->draw_properties() |
| 8463 | .ideal_contents_scale); |
| 8464 | EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8465 | |
| 8466 | EXPECT_FLOAT_EQ( |
| 8467 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8468 | EXPECT_FLOAT_EQ( |
| 8469 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8470 | EXPECT_FLOAT_EQ(0.f, |
| 8471 | child1_layer->mask_layer() |
| 8472 | ->draw_properties() |
| 8473 | .maximum_animation_contents_scale); |
| 8474 | EXPECT_FLOAT_EQ(0.f, |
| 8475 | child1_layer->replica_layer() |
| 8476 | ->mask_layer() |
| 8477 | ->draw_properties() |
| 8478 | .maximum_animation_contents_scale); |
| 8479 | EXPECT_FLOAT_EQ( |
| 8480 | 8.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8481 | |
| 8482 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8483 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor); |
| 8484 | EXPECT_FLOAT_EQ( |
| 8485 | 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8486 | EXPECT_FLOAT_EQ(1.f, |
| 8487 | child1_layer->replica_layer() |
| 8488 | ->mask_layer() |
| 8489 | ->draw_properties() |
| 8490 | .page_scale_factor); |
| 8491 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor); |
| 8492 | |
| 8493 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); |
| 8494 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); |
| 8495 | EXPECT_FLOAT_EQ( |
| 8496 | 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8497 | EXPECT_FLOAT_EQ(1.f, |
| 8498 | child1_layer->replica_layer() |
| 8499 | ->mask_layer() |
| 8500 | ->draw_properties() |
| 8501 | .device_scale_factor); |
| 8502 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); |
| 8503 | |
| 8504 | // Changing page-scale would affect ideal_contents_scale and |
| 8505 | // maximum_animation_contents_scale. |
| 8506 | |
| 8507 | float page_scale_factor = 3.f; |
| 8508 | float device_scale_factor = 1.0f; |
| 8509 | std::vector<LayerImpl*> render_surface_layer_list; |
| 8510 | gfx::Size device_viewport_size = |
| 8511 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 8512 | root_layer->bounds().height() * device_scale_factor); |
| 8513 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8514 | root_layer, device_viewport_size, &render_surface_layer_list); |
| 8515 | |
| 8516 | inputs.page_scale_factor = page_scale_factor; |
| 8517 | inputs.can_adjust_raster_scales = true; |
| 8518 | inputs.page_scale_application_layer = root_layer; |
| 8519 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8520 | |
| 8521 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); |
| 8522 | EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8523 | EXPECT_FLOAT_EQ( |
| 8524 | 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8525 | EXPECT_FLOAT_EQ(9.f, |
| 8526 | child1_layer->replica_layer() |
| 8527 | ->mask_layer() |
| 8528 | ->draw_properties() |
| 8529 | .ideal_contents_scale); |
| 8530 | EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8531 | |
| 8532 | EXPECT_FLOAT_EQ( |
| 8533 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8534 | EXPECT_FLOAT_EQ( |
| 8535 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8536 | EXPECT_FLOAT_EQ(0.f, |
| 8537 | child1_layer->mask_layer() |
| 8538 | ->draw_properties() |
| 8539 | .maximum_animation_contents_scale); |
| 8540 | EXPECT_FLOAT_EQ(0.f, |
| 8541 | child1_layer->replica_layer() |
| 8542 | ->mask_layer() |
| 8543 | ->draw_properties() |
| 8544 | .maximum_animation_contents_scale); |
| 8545 | EXPECT_FLOAT_EQ( |
| 8546 | 24.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8547 | |
| 8548 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8549 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); |
| 8550 | EXPECT_FLOAT_EQ( |
| 8551 | 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8552 | EXPECT_FLOAT_EQ(3.f, |
| 8553 | child1_layer->replica_layer() |
| 8554 | ->mask_layer() |
| 8555 | ->draw_properties() |
| 8556 | .page_scale_factor); |
| 8557 | EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); |
| 8558 | |
| 8559 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); |
| 8560 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); |
| 8561 | EXPECT_FLOAT_EQ( |
| 8562 | 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8563 | EXPECT_FLOAT_EQ(1.f, |
| 8564 | child1_layer->replica_layer() |
| 8565 | ->mask_layer() |
| 8566 | ->draw_properties() |
| 8567 | .device_scale_factor); |
| 8568 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); |
| 8569 | |
| 8570 | // Changing device-scale would affect ideal_contents_scale and |
| 8571 | // maximum_animation_contents_scale. |
| 8572 | |
| 8573 | device_scale_factor = 4.0f; |
| 8574 | inputs.device_scale_factor = device_scale_factor; |
| 8575 | inputs.can_adjust_raster_scales = true; |
| 8576 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8577 | |
| 8578 | EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale); |
| 8579 | EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8580 | EXPECT_FLOAT_EQ( |
| 8581 | 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8582 | EXPECT_FLOAT_EQ(36.f, |
| 8583 | child1_layer->replica_layer() |
| 8584 | ->mask_layer() |
| 8585 | ->draw_properties() |
| 8586 | .ideal_contents_scale); |
| 8587 | EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8588 | |
| 8589 | EXPECT_FLOAT_EQ( |
| 8590 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8591 | EXPECT_FLOAT_EQ( |
| 8592 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8593 | EXPECT_FLOAT_EQ(0.f, |
| 8594 | child1_layer->mask_layer() |
| 8595 | ->draw_properties() |
| 8596 | .maximum_animation_contents_scale); |
| 8597 | EXPECT_FLOAT_EQ(0.f, |
| 8598 | child1_layer->replica_layer() |
| 8599 | ->mask_layer() |
| 8600 | ->draw_properties() |
| 8601 | .maximum_animation_contents_scale); |
| 8602 | EXPECT_FLOAT_EQ( |
| 8603 | 96.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8604 | |
| 8605 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8606 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); |
| 8607 | EXPECT_FLOAT_EQ( |
| 8608 | 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8609 | EXPECT_FLOAT_EQ(3.f, |
| 8610 | child1_layer->replica_layer() |
| 8611 | ->mask_layer() |
| 8612 | ->draw_properties() |
| 8613 | .page_scale_factor); |
| 8614 | EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); |
| 8615 | |
| 8616 | EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor); |
| 8617 | EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor); |
| 8618 | EXPECT_FLOAT_EQ( |
| 8619 | 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8620 | EXPECT_FLOAT_EQ(4.f, |
| 8621 | child1_layer->replica_layer() |
| 8622 | ->mask_layer() |
| 8623 | ->draw_properties() |
| 8624 | .device_scale_factor); |
| 8625 | EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor); |
| 8626 | } |
| 8627 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8628 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
| 8629 | scoped_refptr<Layer> root = Layer::Create(); |
| 8630 | SetLayerPropertiesForTesting(root.get(), |
| 8631 | gfx::Transform(), |
| 8632 | gfx::Point3F(), |
| 8633 | gfx::PointF(), |
| 8634 | gfx::Size(768 / 2, 3000), |
| 8635 | true, |
| 8636 | false); |
| 8637 | root->SetIsDrawable(true); |
| 8638 | |
| 8639 | scoped_refptr<Layer> clip = Layer::Create(); |
| 8640 | SetLayerPropertiesForTesting(clip.get(), |
| 8641 | gfx::Transform(), |
| 8642 | gfx::Point3F(), |
| 8643 | gfx::PointF(), |
| 8644 | gfx::Size(768 / 2, 10000), |
| 8645 | true, |
| 8646 | false); |
| 8647 | clip->SetMasksToBounds(true); |
| 8648 | |
| 8649 | scoped_refptr<Layer> content = Layer::Create(); |
| 8650 | SetLayerPropertiesForTesting(content.get(), |
| 8651 | gfx::Transform(), |
| 8652 | gfx::Point3F(), |
| 8653 | gfx::PointF(), |
| 8654 | gfx::Size(768 / 2, 10000), |
| 8655 | true, |
| 8656 | false); |
| 8657 | content->SetIsDrawable(true); |
| 8658 | content->SetForceRenderSurface(true); |
| 8659 | |
| 8660 | root->AddChild(clip); |
| 8661 | clip->AddChild(content); |
| 8662 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 8663 | FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 8664 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8665 | host->SetRootLayer(root); |
| 8666 | |
| 8667 | gfx::Size device_viewport_size(768, 582); |
| 8668 | RenderSurfaceLayerList render_surface_layer_list; |
| 8669 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8670 | host->root_layer(), device_viewport_size, &render_surface_layer_list); |
| 8671 | inputs.device_scale_factor = 2.f; |
| 8672 | inputs.page_scale_factor = 1.f; |
| 8673 | inputs.page_scale_application_layer = NULL; |
| 8674 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8675 | |
| 8676 | // Layers in the root render surface have their visible content rect clipped |
| 8677 | // by the viewport. |
| 8678 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); |
| 8679 | |
| 8680 | // Layers drawing to a child render surface should still have their visible |
| 8681 | // content rect clipped by the viewport. |
| 8682 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); |
| 8683 | } |
| 8684 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8685 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
| 8686 | FakeImplProxy proxy; |
| 8687 | TestSharedBitmapManager shared_bitmap_manager; |
| 8688 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 8689 | |
| 8690 | // Set two layers: the root layer clips it's child, |
| 8691 | // the child draws its content. |
| 8692 | |
| 8693 | gfx::Size root_size = gfx::Size(300, 500); |
| 8694 | |
| 8695 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8696 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8697 | |
| 8698 | // Device viewport accomidated the root and the top controls. |
| 8699 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
| 8700 | gfx::Transform identity_matrix; |
| 8701 | |
| 8702 | host_impl.active_tree()->SetRootLayer( |
| 8703 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8704 | |
| 8705 | LayerImpl* root = host_impl.active_tree()->root_layer(); |
| 8706 | SetLayerPropertiesForTesting(root, |
| 8707 | identity_matrix, |
| 8708 | gfx::Point3F(), |
| 8709 | gfx::PointF(), |
| 8710 | root_size, |
| 8711 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8712 | false, |
| 8713 | true); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8714 | |
| 8715 | root->SetContentBounds(root_size); |
| 8716 | root->SetMasksToBounds(true); |
| 8717 | |
| 8718 | root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2)); |
| 8719 | |
| 8720 | LayerImpl* sublayer = root->child_at(0); |
| 8721 | SetLayerPropertiesForTesting(sublayer, |
| 8722 | identity_matrix, |
| 8723 | gfx::Point3F(), |
| 8724 | gfx::PointF(), |
| 8725 | sublayer_size, |
| 8726 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8727 | false, |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8728 | false); |
| 8729 | |
| 8730 | sublayer->SetContentBounds(sublayer_size); |
| 8731 | sublayer->SetDrawsContent(true); |
| 8732 | |
| 8733 | LayerImplList layer_impl_list; |
| 8734 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8735 | root, device_viewport_size, &layer_impl_list); |
| 8736 | |
| 8737 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8738 | |
| 8739 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_content_rect()); |
| 8740 | |
| 8741 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
| 8742 | |
| 8743 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8744 | |
| 8745 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8746 | root_size.height() + 50); |
| 8747 | EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect()); |
| 8748 | } |
| 8749 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8750 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
| 8751 | const gfx::Transform identity_matrix; |
| 8752 | scoped_refptr<Layer> root = Layer::Create(); |
| 8753 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 8754 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 8755 | |
| 8756 | root->AddChild(animated); |
| 8757 | |
| 8758 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8759 | host->SetRootLayer(root); |
| 8760 | |
| 8761 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8762 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8763 | SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 8764 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 8765 | |
| 8766 | root->SetMasksToBounds(true); |
| 8767 | root->SetForceRenderSurface(true); |
| 8768 | animated->SetOpacity(0.f); |
| 8769 | |
| 8770 | AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0, |
| 8771 | 0.f, 1.f, false); |
| 8772 | |
| 8773 | ExecuteCalculateDrawProperties(root.get()); |
| 8774 | |
| 8775 | EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty()); |
| 8776 | } |
| 8777 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 8778 | // Verify that having an animated filter (but no current filter, as these |
| 8779 | // are mutually exclusive) correctly creates a render surface. |
| 8780 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
| 8781 | scoped_refptr<Layer> root = Layer::Create(); |
| 8782 | scoped_refptr<Layer> child = Layer::Create(); |
| 8783 | scoped_refptr<Layer> grandchild = Layer::Create(); |
| 8784 | root->AddChild(child); |
| 8785 | child->AddChild(grandchild); |
| 8786 | |
| 8787 | gfx::Transform identity_transform; |
| 8788 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8789 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8790 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8791 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8792 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8793 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 8794 | true, false); |
| 8795 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8796 | host->SetRootLayer(root); |
| 8797 | |
| 8798 | AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f); |
| 8799 | |
| 8800 | ExecuteCalculateDrawProperties(root.get()); |
| 8801 | |
| 8802 | EXPECT_TRUE(root->render_surface()); |
| 8803 | EXPECT_TRUE(child->render_surface()); |
| 8804 | EXPECT_FALSE(grandchild->render_surface()); |
| 8805 | |
| 8806 | EXPECT_TRUE(root->filters().IsEmpty()); |
| 8807 | EXPECT_TRUE(child->filters().IsEmpty()); |
| 8808 | EXPECT_TRUE(grandchild->filters().IsEmpty()); |
| 8809 | |
| 8810 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 8811 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 8812 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 8813 | } |
| 8814 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 8815 | // Ensures that the property tree code accounts for offsets between fixed |
| 8816 | // position layers and their respective containers. |
| 8817 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
| 8818 | scoped_refptr<Layer> root = Layer::Create(); |
| 8819 | scoped_refptr<Layer> child = Layer::Create(); |
| 8820 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
| 8821 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 8822 | |
| 8823 | root->AddChild(child); |
| 8824 | child->AddChild(grandchild); |
| 8825 | |
| 8826 | gfx::Transform identity_transform; |
| 8827 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8828 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 8829 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 8830 | gfx::PointF(1000, 1000), gfx::Size(50, 50), true, |
| 8831 | false); |
| 8832 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 8833 | gfx::Point3F(), gfx::PointF(-1000, -1000), |
| 8834 | gfx::Size(50, 50), true, false); |
| 8835 | |
| 8836 | root->SetMasksToBounds(true); |
| 8837 | root->SetIsContainerForFixedPositionLayers(true); |
| 8838 | LayerPositionConstraint constraint; |
| 8839 | constraint.set_is_fixed_position(true); |
| 8840 | grandchild->SetPositionConstraint(constraint); |
| 8841 | |
| 8842 | root->SetIsContainerForFixedPositionLayers(true); |
| 8843 | |
| 8844 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8845 | host->SetRootLayer(root); |
| 8846 | |
| 8847 | ExecuteCalculateDrawProperties(root.get()); |
| 8848 | |
| 8849 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), |
| 8850 | grandchild->visible_rect_from_property_trees()); |
| 8851 | } |
| 8852 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 8853 | } // namespace |
| 8854 | } // namespace cc |