[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 {} |
| 59 | void PaintContents( |
[email protected] | 276172b | 2014-05-02 21:03:03 | [diff] [blame] | 60 | SkCanvas* canvas, |
| 61 | const gfx::Rect& clip, |
mostynb | f68776d8 | 2014-10-06 18:07:37 | [diff] [blame] | 62 | ContentLayerClient::GraphicsContextStatus gc_status) override {} |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 63 | scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
| 64 | const gfx::Rect& clip, |
| 65 | GraphicsContextStatus gc_status) override { |
| 66 | NOTIMPLEMENTED(); |
| 67 | return DisplayItemList::Create(); |
| 68 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 69 | bool FillsBoundsCompletely() const override { return false; } |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 70 | }; |
| 71 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 72 | scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer( |
| 73 | ContentLayerClient* delegate) { |
| 74 | scoped_refptr<FakePictureLayer> to_return = |
| 75 | FakePictureLayer::Create(delegate); |
| 76 | to_return->SetIsDrawable(true); |
| 77 | return to_return; |
| 78 | } |
| 79 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 80 | scoped_refptr<ContentLayer> CreateDrawableContentLayer( |
| 81 | ContentLayerClient* delegate) { |
| 82 | scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate); |
| 83 | to_return->SetIsDrawable(true); |
| 84 | return to_return; |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 85 | } |
| 86 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 87 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 88 | do { \ |
| 89 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 90 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 91 | } while (false) |
| 92 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 93 | #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \ |
| 94 | do { \ |
| 95 | EXPECT_FLOAT_EQ(expected, layer->draw_properties().ideal_contents_scale); \ |
| 96 | } while (false) |
| 97 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 98 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 99 | // Sanity check: For layers positioned at zero, with zero size, |
| 100 | // and with identity transforms, then the draw transform, |
| 101 | // screen space transform, and the hierarchy passed on to children |
| 102 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 103 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 104 | scoped_refptr<Layer> parent = Layer::Create(); |
| 105 | scoped_refptr<Layer> child = Layer::Create(); |
| 106 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 107 | parent->AddChild(child); |
| 108 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 109 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 110 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 111 | host->SetRootLayer(parent); |
| 112 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 113 | gfx::Transform identity_matrix; |
| 114 | SetLayerPropertiesForTesting(parent.get(), |
| 115 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 116 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 117 | gfx::PointF(), |
| 118 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 119 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 120 | false); |
| 121 | SetLayerPropertiesForTesting(child.get(), |
| 122 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 123 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 124 | gfx::PointF(), |
| 125 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 126 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 127 | false); |
| 128 | SetLayerPropertiesForTesting(grand_child.get(), |
| 129 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 130 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 131 | gfx::PointF(), |
| 132 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 133 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 134 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 135 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 136 | ExecuteCalculateDrawProperties(parent.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 137 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 138 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 139 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 140 | child->screen_space_transform()); |
| 141 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 142 | grand_child->draw_transform()); |
| 143 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 144 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 145 | } |
| 146 | |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 147 | TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) { |
| 148 | scoped_refptr<Layer> parent = Layer::Create(); |
| 149 | scoped_refptr<Layer> child = Layer::Create(); |
| 150 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 151 | parent->AddChild(child); |
| 152 | child->AddChild(grand_child); |
| 153 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 154 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 155 | host->SetRootLayer(parent); |
| 156 | |
| 157 | gfx::Transform identity_matrix; |
| 158 | SetLayerPropertiesForTesting(parent.get(), |
| 159 | identity_matrix, |
| 160 | gfx::Point3F(), |
| 161 | gfx::PointF(), |
| 162 | gfx::Size(100, 100), |
| 163 | true, |
| 164 | false); |
| 165 | SetLayerPropertiesForTesting(child.get(), |
| 166 | identity_matrix, |
| 167 | gfx::Point3F(), |
| 168 | gfx::PointF(10, 10), |
| 169 | gfx::Size(100, 100), |
| 170 | true, |
| 171 | false); |
| 172 | // This would have previously caused us to skip our subtree, but this would be |
| 173 | // wrong; we need up-to-date draw properties to do hit testing on the layers |
| 174 | // with handlers. |
| 175 | child->SetOpacity(0.f); |
| 176 | SetLayerPropertiesForTesting(grand_child.get(), |
| 177 | identity_matrix, |
| 178 | gfx::Point3F(), |
| 179 | gfx::PointF(10, 10), |
| 180 | gfx::Size(100, 100), |
| 181 | true, |
| 182 | false); |
| 183 | grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
| 184 | |
| 185 | ExecuteCalculateDrawProperties(parent.get()); |
| 186 | |
| 187 | // Check that we've computed draw properties for the subtree rooted at |
| 188 | // |child|. |
| 189 | EXPECT_FALSE(child->draw_transform().IsIdentity()); |
| 190 | EXPECT_FALSE(grand_child->draw_transform().IsIdentity()); |
| 191 | } |
| 192 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 193 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 194 | gfx::Transform identity_matrix; |
| 195 | scoped_refptr<Layer> layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 196 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 197 | scoped_refptr<Layer> root = Layer::Create(); |
| 198 | SetLayerPropertiesForTesting(root.get(), |
| 199 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 200 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 201 | gfx::PointF(), |
| 202 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 203 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 204 | false); |
| 205 | root->AddChild(layer); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 206 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 207 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 208 | host->SetRootLayer(root); |
| 209 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 210 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 211 | // transform or the screenspace transform. |
| 212 | gfx::Transform translation_to_center; |
| 213 | translation_to_center.Translate(5.0, 6.0); |
| 214 | SetLayerPropertiesForTesting(layer.get(), |
| 215 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 216 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 217 | gfx::PointF(), |
| 218 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 219 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 220 | false); |
| 221 | ExecuteCalculateDrawProperties(root.get()); |
| 222 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 223 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 224 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 225 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 226 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 227 | // no effect on the transforms. |
| 228 | SetLayerPropertiesForTesting(layer.get(), |
| 229 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 230 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 231 | gfx::PointF(), |
| 232 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 233 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 234 | false); |
| 235 | ExecuteCalculateDrawProperties(root.get()); |
| 236 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 237 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 238 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 239 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 240 | // Case 4: A change in actual position affects both the draw transform and |
| 241 | // screen space transform. |
| 242 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 243 | position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 244 | SetLayerPropertiesForTesting(layer.get(), |
| 245 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 246 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 247 | gfx::PointF(0.f, 1.2f), |
| 248 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 249 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 250 | false); |
| 251 | ExecuteCalculateDrawProperties(root.get()); |
| 252 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform()); |
| 253 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, |
| 254 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 255 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 256 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 257 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 258 | // scale transform, because scale and translation are not commutative. |
| 259 | gfx::Transform layer_transform; |
| 260 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 261 | SetLayerPropertiesForTesting(layer.get(), |
| 262 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 263 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 264 | gfx::PointF(), |
| 265 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 266 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 267 | false); |
| 268 | ExecuteCalculateDrawProperties(root.get()); |
| 269 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform()); |
| 270 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, |
| 271 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 272 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 273 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 274 | gfx::Transform translation_to_anchor; |
| 275 | translation_to_anchor.Translate(5.0, 0.0); |
| 276 | gfx::Transform expected_result = |
| 277 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
| 278 | SetLayerPropertiesForTesting(layer.get(), |
| 279 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 280 | gfx::Point3F(5.0f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 281 | gfx::PointF(), |
| 282 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 283 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 284 | false); |
| 285 | ExecuteCalculateDrawProperties(root.get()); |
| 286 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 287 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 288 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 289 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 290 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 291 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 292 | // it is still worth testing to detect accidental regressions. |
| 293 | expected_result = position_transform * translation_to_anchor * |
| 294 | layer_transform * Inverse(translation_to_anchor); |
| 295 | SetLayerPropertiesForTesting(layer.get(), |
| 296 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 297 | gfx::Point3F(5.0f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 298 | gfx::PointF(0.f, 1.2f), |
| 299 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 300 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 301 | false); |
| 302 | ExecuteCalculateDrawProperties(root.get()); |
| 303 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 304 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 305 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 306 | } |
| 307 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 308 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 309 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 310 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 311 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 312 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 313 | -kScrollOffset.y()); |
| 314 | const float kPageScale = 0.888f; |
| 315 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 316 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 317 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 318 | TestSharedBitmapManager shared_bitmap_manager; |
| 319 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 320 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 321 | gfx::Transform identity_matrix; |
| 322 | scoped_ptr<LayerImpl> sublayer_scoped_ptr( |
| 323 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 324 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
| 325 | sublayer->SetContentsScale(kPageScale * kDeviceScale, |
| 326 | kPageScale * kDeviceScale); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 327 | SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(), |
| 328 | gfx::PointF(), gfx::Size(500, 500), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 329 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 330 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 331 | scoped_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 332 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 333 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 334 | SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(), |
| 335 | gfx::PointF(), gfx::Size(10, 20), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 336 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 337 | scoped_ptr<LayerImpl> clip_layer_scoped_ptr( |
| 338 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 339 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 340 | |
| 341 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 342 | clip_layer->SetBounds( |
| 343 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 344 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 345 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 346 | scroll_layer->SetScrollDelta(kScrollDelta); |
| 347 | gfx::Transform impl_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 348 | scroll_layer->AddChild(sublayer_scoped_ptr.Pass()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 349 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
| 350 | clip_layer->AddChild(scroll_layer_scoped_ptr.Pass()); |
| 351 | scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 352 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 353 | scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 354 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 355 | gfx::PointF(), gfx::Size(3, 4), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 356 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 357 | root->AddChild(clip_layer_scoped_ptr.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 358 | root->SetHasRenderSurface(true); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 359 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 360 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 361 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 362 | gfx::Transform expected_transform = identity_matrix; |
| 363 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
| 364 | sub_layer_screen_position.Scale(kPageScale * kDeviceScale); |
| 365 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()), |
| 366 | MathUtil::Round(sub_layer_screen_position.y())); |
| 367 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 368 | sublayer->draw_transform()); |
| 369 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 370 | sublayer->screen_space_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 371 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 372 | gfx::Transform arbitrary_translate; |
| 373 | const float kTranslateX = 10.6f; |
| 374 | const float kTranslateY = 20.6f; |
| 375 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 376 | SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate, |
| 377 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20), |
| 378 | true, false, false); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 379 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 380 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 381 | expected_transform.MakeIdentity(); |
| 382 | expected_transform.Translate( |
| 383 | MathUtil::Round(kTranslateX * kPageScale * kDeviceScale + |
| 384 | sub_layer_screen_position.x()), |
| 385 | MathUtil::Round(kTranslateY * kPageScale * kDeviceScale + |
| 386 | sub_layer_screen_position.y())); |
| 387 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 388 | sublayer->draw_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 389 | } |
| 390 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 391 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 392 | gfx::Transform identity_matrix; |
| 393 | scoped_refptr<Layer> root = Layer::Create(); |
| 394 | scoped_refptr<Layer> parent = Layer::Create(); |
| 395 | scoped_refptr<Layer> child = Layer::Create(); |
| 396 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 397 | root->AddChild(parent); |
| 398 | parent->AddChild(child); |
| 399 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 400 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 401 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 402 | host->SetRootLayer(root); |
| 403 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 404 | // One-time setup of root layer |
| 405 | SetLayerPropertiesForTesting(root.get(), |
| 406 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 407 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 408 | gfx::PointF(), |
| 409 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 410 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 411 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 412 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 413 | // Case 1: parent's anchor point should not affect child or grand_child. |
| 414 | SetLayerPropertiesForTesting(parent.get(), |
| 415 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 416 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 417 | gfx::PointF(), |
| 418 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 419 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 420 | false); |
| 421 | SetLayerPropertiesForTesting(child.get(), |
| 422 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 423 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 424 | gfx::PointF(), |
| 425 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 426 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 427 | false); |
| 428 | SetLayerPropertiesForTesting(grand_child.get(), |
| 429 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 430 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 431 | gfx::PointF(), |
| 432 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 433 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 434 | false); |
| 435 | ExecuteCalculateDrawProperties(root.get()); |
| 436 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 437 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 438 | child->screen_space_transform()); |
| 439 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 440 | grand_child->draw_transform()); |
| 441 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 442 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 443 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 444 | // Case 2: parent's position affects child and grand_child. |
| 445 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 446 | parent_position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 447 | SetLayerPropertiesForTesting(parent.get(), |
| 448 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 449 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 450 | gfx::PointF(0.f, 1.2f), |
| 451 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 452 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 453 | false); |
| 454 | SetLayerPropertiesForTesting(child.get(), |
| 455 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 456 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 457 | gfx::PointF(), |
| 458 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 459 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 460 | false); |
| 461 | SetLayerPropertiesForTesting(grand_child.get(), |
| 462 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 463 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 464 | gfx::PointF(), |
| 465 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 466 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 467 | false); |
| 468 | ExecuteCalculateDrawProperties(root.get()); |
| 469 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 470 | child->draw_transform()); |
| 471 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 472 | child->screen_space_transform()); |
| 473 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 474 | grand_child->draw_transform()); |
| 475 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 476 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 477 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 478 | // Case 3: parent's local transform affects child and grandchild |
| 479 | gfx::Transform parent_layer_transform; |
| 480 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 481 | gfx::Transform parent_translation_to_anchor; |
| 482 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 483 | gfx::Transform parent_composite_transform = |
| 484 | parent_translation_to_anchor * parent_layer_transform * |
| 485 | Inverse(parent_translation_to_anchor); |
| 486 | SetLayerPropertiesForTesting(parent.get(), |
| 487 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 488 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 489 | gfx::PointF(), |
| 490 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 491 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 492 | false); |
| 493 | SetLayerPropertiesForTesting(child.get(), |
| 494 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 495 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 496 | gfx::PointF(), |
| 497 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 498 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 499 | false); |
| 500 | SetLayerPropertiesForTesting(grand_child.get(), |
| 501 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 502 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 503 | gfx::PointF(), |
| 504 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 505 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 506 | false); |
| 507 | ExecuteCalculateDrawProperties(root.get()); |
| 508 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 509 | child->draw_transform()); |
| 510 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 511 | child->screen_space_transform()); |
| 512 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 513 | grand_child->draw_transform()); |
| 514 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 515 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 516 | } |
| 517 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 518 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 519 | scoped_refptr<Layer> root = Layer::Create(); |
| 520 | scoped_refptr<Layer> parent = Layer::Create(); |
| 521 | scoped_refptr<Layer> child = Layer::Create(); |
| 522 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 523 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 524 | root->AddChild(parent); |
| 525 | parent->AddChild(child); |
| 526 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 527 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 528 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 529 | host->SetRootLayer(root); |
| 530 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 531 | // One-time setup of root layer |
| 532 | gfx::Transform identity_matrix; |
| 533 | SetLayerPropertiesForTesting(root.get(), |
| 534 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 535 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 536 | gfx::PointF(), |
| 537 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 538 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 539 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 540 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 541 | // Child is set up so that a new render surface should be created. |
| 542 | child->SetOpacity(0.5f); |
| 543 | child->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 544 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 545 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 546 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 547 | gfx::Transform parent_translation_to_anchor; |
| 548 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 549 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 550 | gfx::Transform parent_composite_transform = |
| 551 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 552 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 553 | gfx::Vector2dF parent_composite_scale = |
| 554 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 555 | 1.f); |
| 556 | gfx::Transform surface_sublayer_transform; |
| 557 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 558 | parent_composite_scale.y()); |
| 559 | gfx::Transform surface_sublayer_composite_transform = |
| 560 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 561 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 562 | // Child's render surface should not exist yet. |
| 563 | ASSERT_FALSE(child->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 564 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 565 | SetLayerPropertiesForTesting(parent.get(), |
| 566 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 567 | gfx::Point3F(25.0f, 30.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 568 | gfx::PointF(), |
| 569 | gfx::Size(100, 120), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 570 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 571 | false); |
| 572 | SetLayerPropertiesForTesting(child.get(), |
| 573 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 574 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 575 | gfx::PointF(), |
| 576 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 577 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 578 | false); |
| 579 | SetLayerPropertiesForTesting(grand_child.get(), |
| 580 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 581 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 582 | gfx::PointF(), |
| 583 | gfx::Size(8, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 584 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 585 | false); |
| 586 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 587 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 588 | // Render surface should have been created now. |
| 589 | ASSERT_TRUE(child->render_surface()); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 590 | ASSERT_EQ(child.get(), child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 591 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 592 | // The child layer's draw transform should refer to its new render surface. |
| 593 | // The screen-space transform, however, should still refer to the root. |
| 594 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
| 595 | child->draw_transform()); |
| 596 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 597 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 598 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 599 | // Because the grand_child is the only drawable content, the child's render |
| 600 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 601 | // surface's subtree is drawn must be removed from the composite transform. |
| 602 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 603 | surface_sublayer_composite_transform, |
| 604 | child->render_target()->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 605 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 606 | // The screen space is the same as the target since the child surface draws |
| 607 | // into the root. |
| 608 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 609 | surface_sublayer_composite_transform, |
| 610 | child->render_target()->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 611 | } |
| 612 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 613 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 614 | scoped_refptr<Layer> root = Layer::Create(); |
| 615 | scoped_refptr<Layer> parent = Layer::Create(); |
| 616 | scoped_refptr<Layer> child = Layer::Create(); |
| 617 | scoped_refptr<Layer> child_replica = Layer::Create(); |
| 618 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 619 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 620 | root->AddChild(parent); |
| 621 | parent->AddChild(child); |
| 622 | child->AddChild(grand_child); |
| 623 | child->SetReplicaLayer(child_replica.get()); |
| 624 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 625 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 626 | host->SetRootLayer(root); |
| 627 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 628 | // One-time setup of root layer |
| 629 | gfx::Transform identity_matrix; |
| 630 | SetLayerPropertiesForTesting(root.get(), |
| 631 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 632 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 633 | gfx::PointF(), |
| 634 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 635 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 636 | false); |
| 637 | |
| 638 | // Child is set up so that a new render surface should be created. |
| 639 | child->SetOpacity(0.5f); |
| 640 | |
| 641 | gfx::Transform parent_layer_transform; |
| 642 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 643 | gfx::Transform parent_translation_to_anchor; |
| 644 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 645 | gfx::Transform parent_composite_transform = |
| 646 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 647 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 648 | gfx::Transform replica_layer_transform; |
| 649 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 650 | gfx::Vector2dF parent_composite_scale = |
| 651 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 652 | 1.f); |
| 653 | gfx::Transform surface_sublayer_transform; |
| 654 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 655 | parent_composite_scale.y()); |
| 656 | gfx::Transform replica_composite_transform = |
| 657 | parent_composite_transform * replica_layer_transform * |
| 658 | Inverse(surface_sublayer_transform); |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 659 | child_replica->SetIsDrawable(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 660 | // Child's render surface should not exist yet. |
| 661 | ASSERT_FALSE(child->render_surface()); |
| 662 | |
| 663 | SetLayerPropertiesForTesting(parent.get(), |
| 664 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 665 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 666 | gfx::PointF(), |
| 667 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 668 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 669 | false); |
| 670 | SetLayerPropertiesForTesting(child.get(), |
| 671 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 672 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 673 | gfx::PointF(), |
| 674 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 675 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 676 | false); |
| 677 | SetLayerPropertiesForTesting(grand_child.get(), |
| 678 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 679 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 680 | gfx::PointF(-0.5f, -0.5f), |
| 681 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 682 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 683 | false); |
| 684 | SetLayerPropertiesForTesting(child_replica.get(), |
| 685 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 686 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 687 | gfx::PointF(), |
| 688 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 689 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 690 | false); |
| 691 | ExecuteCalculateDrawProperties(root.get()); |
| 692 | |
| 693 | // Render surface should have been created now. |
| 694 | ASSERT_TRUE(child->render_surface()); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 695 | ASSERT_EQ(child.get(), child->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 696 | |
| 697 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 698 | replica_composite_transform, |
| 699 | child->render_target()->render_surface()->replica_draw_transform()); |
| 700 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 701 | child->render_target() |
| 702 | ->render_surface() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 703 | ->replica_screen_space_transform()); |
| 704 | } |
| 705 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 706 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 707 | // This test creates a more complex tree and verifies it all at once. This |
| 708 | // covers the following cases: |
| 709 | // - layers that are described w.r.t. a render surface: should have draw |
| 710 | // transforms described w.r.t. that surface |
| 711 | // - A render surface described w.r.t. an ancestor render surface: should |
| 712 | // have a draw transform described w.r.t. that ancestor surface |
| 713 | // - Replicas of a render surface are described w.r.t. the replica's |
| 714 | // transform around its anchor, along with the surface itself. |
| 715 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 716 | // a render surface that is described w.r.t. an ancestor render surface. |
| 717 | // - verifying that each layer has a reference to the correct render surface |
| 718 | // and render target values. |
| 719 | |
| 720 | scoped_refptr<Layer> root = Layer::Create(); |
| 721 | scoped_refptr<Layer> parent = Layer::Create(); |
| 722 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 723 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 724 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 725 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 726 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 727 | scoped_refptr<Layer> replica_of_rs1 = Layer::Create(); |
| 728 | scoped_refptr<Layer> replica_of_rs2 = Layer::Create(); |
| 729 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 730 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 731 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 732 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 733 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 734 | root->AddChild(parent); |
| 735 | parent->AddChild(render_surface1); |
| 736 | parent->AddChild(child_of_root); |
| 737 | render_surface1->AddChild(child_of_rs1); |
| 738 | render_surface1->AddChild(render_surface2); |
| 739 | render_surface2->AddChild(child_of_rs2); |
| 740 | child_of_root->AddChild(grand_child_of_root); |
| 741 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 742 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 743 | render_surface1->SetReplicaLayer(replica_of_rs1.get()); |
| 744 | render_surface2->SetReplicaLayer(replica_of_rs2.get()); |
| 745 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 746 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 747 | host->SetRootLayer(root); |
| 748 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 749 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 750 | // to have a new render surface. |
| 751 | render_surface1->SetOpacity(0.5f); |
| 752 | render_surface2->SetOpacity(0.33f); |
| 753 | |
| 754 | // One-time setup of root layer |
| 755 | gfx::Transform identity_matrix; |
| 756 | SetLayerPropertiesForTesting(root.get(), |
| 757 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 758 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 759 | gfx::PointF(), |
| 760 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 761 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 762 | false); |
| 763 | |
| 764 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 765 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 766 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 767 | gfx::Transform translation_to_anchor; |
| 768 | translation_to_anchor.Translate(2.5, 0.0); |
| 769 | gfx::Transform layer_transform; |
| 770 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 771 | gfx::Transform replica_layer_transform; |
| 772 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 773 | |
| 774 | gfx::Transform A = |
| 775 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 776 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 777 | Inverse(translation_to_anchor); |
| 778 | |
| 779 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 780 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 781 | gfx::Transform surface1_sublayer_transform; |
| 782 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 783 | surface1_parent_transform_scale.y()); |
| 784 | |
| 785 | // SS1 = transform given to the subtree of render_surface1 |
| 786 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 787 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 788 | // the owning layer |
| 789 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 790 | |
| 791 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 792 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 793 | gfx::Transform surface2_sublayer_transform; |
| 794 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 795 | surface2_parent_transform_scale.y()); |
| 796 | |
| 797 | // SS2 = transform given to the subtree of render_surface2 |
| 798 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 799 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 800 | // the owning layer |
| 801 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 802 | |
| 803 | SetLayerPropertiesForTesting(parent.get(), |
| 804 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 805 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 806 | gfx::PointF(), |
| 807 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 808 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 809 | false); |
| 810 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 811 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 812 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 813 | gfx::PointF(), |
| 814 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 815 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 816 | false); |
| 817 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 818 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 819 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 820 | gfx::PointF(), |
| 821 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 822 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 823 | false); |
| 824 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 825 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 826 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 827 | gfx::PointF(), |
| 828 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 829 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 830 | false); |
| 831 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 832 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 833 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 834 | gfx::PointF(), |
| 835 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 836 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 837 | false); |
| 838 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 839 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 840 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 841 | gfx::PointF(), |
| 842 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 843 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 844 | false); |
| 845 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 846 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 847 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 848 | gfx::PointF(), |
| 849 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 850 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 851 | false); |
| 852 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 853 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 854 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 855 | gfx::PointF(), |
| 856 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 857 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 858 | false); |
| 859 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 860 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 861 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 862 | gfx::PointF(), |
| 863 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 864 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 865 | false); |
| 866 | SetLayerPropertiesForTesting(replica_of_rs1.get(), |
| 867 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 868 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 869 | gfx::PointF(), |
| 870 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 871 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 872 | false); |
| 873 | SetLayerPropertiesForTesting(replica_of_rs2.get(), |
| 874 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 875 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 876 | gfx::PointF(), |
| 877 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 878 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 879 | false); |
| 880 | |
| 881 | ExecuteCalculateDrawProperties(root.get()); |
| 882 | |
| 883 | // Only layers that are associated with render surfaces should have an actual |
| 884 | // RenderSurface() value. |
| 885 | ASSERT_TRUE(root->render_surface()); |
| 886 | ASSERT_FALSE(child_of_root->render_surface()); |
| 887 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 888 | |
| 889 | ASSERT_TRUE(render_surface1->render_surface()); |
| 890 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 891 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 892 | |
| 893 | ASSERT_TRUE(render_surface2->render_surface()); |
| 894 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 895 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 896 | |
| 897 | // Verify all render target accessors |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 898 | EXPECT_EQ(root.get(), parent->render_target()); |
| 899 | EXPECT_EQ(root.get(), child_of_root->render_target()); |
| 900 | EXPECT_EQ(root.get(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 901 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 902 | EXPECT_EQ(render_surface1.get(), render_surface1->render_target()); |
| 903 | EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target()); |
| 904 | EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 905 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 906 | EXPECT_EQ(render_surface2.get(), render_surface2->render_target()); |
| 907 | EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target()); |
| 908 | EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 909 | |
| 910 | // Verify layer draw transforms note that draw transforms are described with |
| 911 | // respect to the nearest ancestor render surface but screen space transforms |
| 912 | // are described with respect to the root. |
| 913 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 914 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform()); |
| 915 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 916 | grand_child_of_root->draw_transform()); |
| 917 | |
| 918 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 919 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform()); |
| 920 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 921 | grand_child_of_rs1->draw_transform()); |
| 922 | |
| 923 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 924 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform()); |
| 925 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 926 | grand_child_of_rs2->draw_transform()); |
| 927 | |
| 928 | // Verify layer screen-space transforms |
| 929 | // |
| 930 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 931 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 932 | child_of_root->screen_space_transform()); |
| 933 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 934 | A * A * A, grand_child_of_root->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 935 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 936 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 937 | render_surface1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 938 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 939 | child_of_rs1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 940 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 941 | grand_child_of_rs1->screen_space_transform()); |
| 942 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 943 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 944 | render_surface2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 945 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 946 | child_of_rs2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 947 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 948 | grand_child_of_rs2->screen_space_transform()); |
| 949 | |
| 950 | // Verify render surface transforms. |
| 951 | // |
| 952 | // Draw transform of render surface 1 is described with respect to root. |
| 953 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 954 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 955 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 956 | A * R * S1, render_surface1->render_surface()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 957 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 958 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 959 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 960 | A * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 961 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 962 | // Draw transform of render surface 2 is described with respect to render |
| 963 | // surface 1. |
| 964 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 965 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 966 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 967 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 968 | render_surface2->render_surface()->replica_draw_transform()); |
| 969 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 970 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 971 | render_surface2->render_surface()->screen_space_transform()); |
| 972 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 973 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 974 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 975 | |
| 976 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 977 | // is expected that we correctly set up transforms so that the y-component of |
| 978 | // the screen-space transform encodes the "depth" of the layer in the tree. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 979 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 980 | EXPECT_FLOAT_EQ(2.0, |
| 981 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 982 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 983 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 984 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 985 | EXPECT_FLOAT_EQ(2.0, |
| 986 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 987 | EXPECT_FLOAT_EQ(3.0, |
| 988 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 989 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 990 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 991 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 992 | EXPECT_FLOAT_EQ(3.0, |
| 993 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 994 | EXPECT_FLOAT_EQ(4.0, |
| 995 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 996 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 997 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 998 | } |
| 999 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1000 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1001 | // For layers that flatten their subtree, there should be an orthographic |
| 1002 | // projection (for x and y values) in the middle of the transform sequence. |
| 1003 | // Note that the way the code is currently implemented, it is not expected to |
| 1004 | // use a canonical orthographic projection. |
| 1005 | |
| 1006 | scoped_refptr<Layer> root = Layer::Create(); |
| 1007 | scoped_refptr<Layer> child = Layer::Create(); |
| 1008 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1009 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1010 | |
| 1011 | gfx::Transform rotation_about_y_axis; |
| 1012 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1013 | |
| 1014 | const gfx::Transform identity_matrix; |
| 1015 | SetLayerPropertiesForTesting(root.get(), |
| 1016 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1017 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1018 | gfx::PointF(), |
| 1019 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1020 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1021 | false); |
| 1022 | SetLayerPropertiesForTesting(child.get(), |
| 1023 | rotation_about_y_axis, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1024 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1025 | gfx::PointF(), |
| 1026 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1027 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1028 | false); |
| 1029 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1030 | rotation_about_y_axis, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1031 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1032 | gfx::PointF(), |
| 1033 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1034 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1035 | false); |
| 1036 | |
| 1037 | root->AddChild(child); |
| 1038 | child->AddChild(grand_child); |
| 1039 | child->SetForceRenderSurface(true); |
| 1040 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1041 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1042 | host->SetRootLayer(root); |
| 1043 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1044 | // No layers in this test should preserve 3d. |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1045 | ASSERT_TRUE(root->should_flatten_transform()); |
| 1046 | ASSERT_TRUE(child->should_flatten_transform()); |
| 1047 | ASSERT_TRUE(grand_child->should_flatten_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1048 | |
| 1049 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1050 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1051 | gfx::Transform expected_grand_child_draw_transform = |
| 1052 | rotation_about_y_axis; // draws onto child's render surface |
| 1053 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1054 | flattened_rotation_about_y.FlattenTo2d(); |
| 1055 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1056 | flattened_rotation_about_y * rotation_about_y_axis; |
| 1057 | |
| 1058 | ExecuteCalculateDrawProperties(root.get()); |
| 1059 | |
| 1060 | // The child's draw transform should have been taken by its surface. |
| 1061 | ASSERT_TRUE(child->render_surface()); |
| 1062 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1063 | child->render_surface()->draw_transform()); |
| 1064 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1065 | expected_child_screen_space_transform, |
| 1066 | child->render_surface()->screen_space_transform()); |
| 1067 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1068 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
| 1069 | child->screen_space_transform()); |
| 1070 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
| 1071 | grand_child->draw_transform()); |
| 1072 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
| 1073 | grand_child->screen_space_transform()); |
| 1074 | } |
| 1075 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1076 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1077 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1078 | // skipping a necessary translation. Without that translation, the coordinate |
| 1079 | // space of the layer's draw transform is incorrect. |
| 1080 | // |
| 1081 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1082 | // but if that layer becomes a render surface, then its draw transform is |
| 1083 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1084 | // incorrectly as a result. |
| 1085 | |
| 1086 | scoped_refptr<Layer> root = Layer::Create(); |
| 1087 | scoped_refptr<Layer> child = Layer::Create(); |
| 1088 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1089 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1090 | |
| 1091 | // The child height is zero, but has non-zero width that should be accounted |
| 1092 | // for while computing draw transforms. |
| 1093 | const gfx::Transform identity_matrix; |
| 1094 | SetLayerPropertiesForTesting(root.get(), |
| 1095 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1096 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1097 | gfx::PointF(), |
| 1098 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1099 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1100 | false); |
| 1101 | SetLayerPropertiesForTesting(child.get(), |
| 1102 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1103 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1104 | gfx::PointF(), |
| 1105 | gfx::Size(10, 0), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1106 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1107 | false); |
| 1108 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1109 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1110 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1111 | gfx::PointF(), |
| 1112 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1113 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1114 | false); |
| 1115 | |
| 1116 | root->AddChild(child); |
| 1117 | child->AddChild(grand_child); |
| 1118 | child->SetForceRenderSurface(true); |
| 1119 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1120 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1121 | host->SetRootLayer(root); |
| 1122 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1123 | ExecuteCalculateDrawProperties(root.get()); |
| 1124 | |
| 1125 | ASSERT_TRUE(child->render_surface()); |
| 1126 | // This is the real test, the rest are sanity checks. |
| 1127 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1128 | child->render_surface()->draw_transform()); |
| 1129 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1130 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1131 | grand_child->draw_transform()); |
| 1132 | } |
| 1133 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1134 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1135 | // Transformations applied at the root of the tree should be forwarded |
| 1136 | // to child layers instead of applied to the root RenderSurface. |
| 1137 | const gfx::Transform identity_matrix; |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1138 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 1139 | new LayerWithForcedDrawsContent; |
| 1140 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1141 | new LayerWithForcedDrawsContent; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1142 | child->SetScrollClipLayerId(root->id()); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1143 | root->AddChild(child); |
| 1144 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1145 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1146 | host->SetRootLayer(root); |
| 1147 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1148 | SetLayerPropertiesForTesting(root.get(), |
| 1149 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1150 | gfx::Point3F(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1151 | gfx::PointF(), |
| 1152 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1153 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1154 | false); |
| 1155 | SetLayerPropertiesForTesting(child.get(), |
| 1156 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1157 | gfx::Point3F(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1158 | gfx::PointF(), |
| 1159 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1160 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1161 | false); |
| 1162 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1163 | gfx::Transform translate; |
| 1164 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1165 | { |
| 1166 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1167 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1168 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1169 | inputs.can_adjust_raster_scales = true; |
| 1170 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1171 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1172 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1173 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1174 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1175 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1176 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1177 | |
| 1178 | gfx::Transform scale; |
| 1179 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1180 | { |
| 1181 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1182 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1183 | root.get(), root->bounds(), scale, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1184 | inputs.can_adjust_raster_scales = true; |
| 1185 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1186 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1187 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1188 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1189 | EXPECT_EQ(2.f, root->draw_properties().device_scale_factor); |
| 1190 | EXPECT_EQ(2.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1191 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1192 | |
| 1193 | gfx::Transform rotate; |
| 1194 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1195 | { |
| 1196 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1197 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1198 | root.get(), root->bounds(), rotate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1199 | inputs.can_adjust_raster_scales = true; |
| 1200 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1201 | EXPECT_EQ(rotate, root->draw_properties().target_space_transform); |
| 1202 | EXPECT_EQ(rotate, child->draw_properties().target_space_transform); |
| 1203 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1204 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1205 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1206 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1207 | |
| 1208 | gfx::Transform composite; |
| 1209 | composite.ConcatTransform(translate); |
| 1210 | composite.ConcatTransform(scale); |
| 1211 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1212 | { |
| 1213 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1214 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1215 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1216 | inputs.can_adjust_raster_scales = true; |
| 1217 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1218 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1219 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1220 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1221 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1222 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1223 | // Verify it composes correctly with device scale. |
| 1224 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1225 | |
| 1226 | { |
| 1227 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1228 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1229 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1230 | inputs.device_scale_factor = device_scale_factor; |
| 1231 | inputs.can_adjust_raster_scales = true; |
| 1232 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1233 | gfx::Transform device_scaled_translate = translate; |
| 1234 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1235 | EXPECT_EQ(device_scaled_translate, |
| 1236 | root->draw_properties().target_space_transform); |
| 1237 | EXPECT_EQ(device_scaled_translate, |
| 1238 | child->draw_properties().target_space_transform); |
| 1239 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1240 | EXPECT_EQ(device_scale_factor, root->draw_properties().device_scale_factor); |
| 1241 | EXPECT_EQ(device_scale_factor, |
| 1242 | child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1243 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1244 | |
| 1245 | // Verify it composes correctly with page scale. |
| 1246 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1247 | |
| 1248 | { |
| 1249 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1250 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1251 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1252 | inputs.page_scale_factor = page_scale_factor; |
| 1253 | inputs.page_scale_application_layer = root.get(); |
| 1254 | inputs.can_adjust_raster_scales = true; |
| 1255 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1256 | gfx::Transform page_scaled_translate = translate; |
| 1257 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
| 1258 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1259 | EXPECT_EQ(page_scaled_translate, |
| 1260 | child->draw_properties().target_space_transform); |
| 1261 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1262 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1263 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1264 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1265 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1266 | // Verify that it composes correctly with transforms directly on root layer. |
| 1267 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1268 | |
| 1269 | { |
| 1270 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1271 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1272 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1273 | inputs.can_adjust_raster_scales = true; |
| 1274 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1275 | gfx::Transform compositeSquared = composite; |
| 1276 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1277 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1278 | compositeSquared, root->draw_properties().target_space_transform); |
| 1279 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1280 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1281 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1282 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1283 | } |
| 1284 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1285 | TEST_F(LayerTreeHostCommonTest, |
| 1286 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1287 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1288 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1289 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1290 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1291 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1292 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1293 | host->SetRootLayer(parent); |
| 1294 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1295 | const gfx::Transform identity_matrix; |
| 1296 | SetLayerPropertiesForTesting(parent.get(), |
| 1297 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1298 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1299 | gfx::PointF(), |
| 1300 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1301 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1302 | false); |
| 1303 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1304 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1305 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1306 | gfx::PointF(), |
| 1307 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1308 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1309 | false); |
| 1310 | SetLayerPropertiesForTesting(child.get(), |
| 1311 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1312 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1313 | gfx::PointF(30.f, 30.f), |
| 1314 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1315 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1316 | false); |
| 1317 | |
| 1318 | parent->AddChild(render_surface1); |
| 1319 | parent->SetMasksToBounds(true); |
| 1320 | render_surface1->AddChild(child); |
| 1321 | render_surface1->SetForceRenderSurface(true); |
| 1322 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1323 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1324 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1325 | parent.get(), |
| 1326 | parent->bounds(), |
| 1327 | gfx::Transform(), |
| 1328 | &render_surface_layer_list); |
| 1329 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1330 | |
| 1331 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1332 | // the intermediate render surface should not be listed here, even if it was |
| 1333 | // forced to be created. Render surfaces without children or visible content |
| 1334 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1335 | // of size 0). |
| 1336 | ASSERT_TRUE(parent->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1337 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1338 | } |
| 1339 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1340 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1341 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1342 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1343 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1344 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1345 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1346 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1347 | host->SetRootLayer(parent); |
| 1348 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1349 | const gfx::Transform identity_matrix; |
| 1350 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1351 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1352 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1353 | gfx::PointF(), |
| 1354 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1355 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1356 | false); |
| 1357 | SetLayerPropertiesForTesting(child.get(), |
| 1358 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1359 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1360 | gfx::PointF(), |
| 1361 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1362 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1363 | false); |
| 1364 | |
| 1365 | parent->AddChild(render_surface1); |
| 1366 | render_surface1->AddChild(child); |
| 1367 | render_surface1->SetForceRenderSurface(true); |
| 1368 | render_surface1->SetOpacity(0.f); |
| 1369 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1370 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1371 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1372 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1373 | inputs.can_adjust_raster_scales = true; |
| 1374 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1375 | |
| 1376 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1377 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1378 | // have been extended by the children. |
| 1379 | ASSERT_TRUE(parent->render_surface()); |
| 1380 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1381 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1382 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1383 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1384 | } |
| 1385 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1386 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
| 1387 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1388 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1389 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1390 | |
| 1391 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 1392 | host->SetRootLayer(parent); |
| 1393 | |
| 1394 | const gfx::Transform identity_matrix; |
| 1395 | const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode; |
| 1396 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 1397 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1398 | |
| 1399 | parent->AddChild(child); |
| 1400 | child->SetBlendMode(blend_mode); |
| 1401 | |
| 1402 | RenderSurfaceLayerList render_surface_layer_list; |
| 1403 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1404 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1405 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 1406 | |
| 1407 | // Since the child layer has a blend mode other than normal, it should get |
| 1408 | // its own render surface. Also, layer's draw_properties should contain the |
| 1409 | // default blend mode, since the render surface becomes responsible for |
| 1410 | // applying the blend mode. |
| 1411 | ASSERT_TRUE(child->render_surface()); |
| 1412 | EXPECT_EQ(1U, child->render_surface()->layer_list().size()); |
| 1413 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_properties().blend_mode); |
| 1414 | } |
| 1415 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1416 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1417 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1418 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1419 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1420 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1421 | render_surface1->SetForceRenderSurface(true); |
| 1422 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1423 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1424 | host->SetRootLayer(parent); |
| 1425 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1426 | const gfx::Transform identity_matrix; |
| 1427 | SetLayerPropertiesForTesting(parent.get(), |
| 1428 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1429 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1430 | gfx::PointF(), |
| 1431 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1432 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1433 | false); |
| 1434 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1435 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1436 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1437 | gfx::PointF(), |
| 1438 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1439 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1440 | false); |
| 1441 | SetLayerPropertiesForTesting(child.get(), |
| 1442 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1443 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1444 | gfx::PointF(), |
| 1445 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1446 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1447 | false); |
| 1448 | |
| 1449 | parent->AddChild(render_surface1); |
| 1450 | render_surface1->AddChild(child); |
| 1451 | |
| 1452 | // Sanity check before the actual test |
| 1453 | EXPECT_FALSE(parent->render_surface()); |
| 1454 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1455 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1456 | { |
| 1457 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1458 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1459 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1460 | inputs.can_adjust_raster_scales = true; |
| 1461 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1462 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1463 | // The root layer always creates a render surface |
| 1464 | EXPECT_TRUE(parent->render_surface()); |
| 1465 | EXPECT_TRUE(render_surface1->render_surface()); |
| 1466 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1467 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1468 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1469 | { |
| 1470 | RenderSurfaceLayerList render_surface_layer_list; |
| 1471 | render_surface1->SetForceRenderSurface(false); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1472 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1473 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1474 | inputs.can_adjust_raster_scales = true; |
| 1475 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1476 | EXPECT_TRUE(parent->render_surface()); |
| 1477 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1478 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1479 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1480 | } |
| 1481 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1482 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1483 | // The entire subtree of layers that are outside the clip rect should be |
| 1484 | // culled away, and should not affect the render_surface_layer_list. |
| 1485 | // |
| 1486 | // The test tree is set up as follows: |
| 1487 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1488 | // that have something to draw. |
| 1489 | // - parent is a large container layer. |
| 1490 | // - child has masksToBounds=true to cause clipping. |
| 1491 | // - grand_child is positioned outside of the child's bounds |
| 1492 | // - great_grand_child is also kept outside child's bounds. |
| 1493 | // |
| 1494 | // In this configuration, grand_child and great_grand_child are completely |
| 1495 | // outside the clip rect, and they should never get scheduled on the list of |
| 1496 | // render surfaces. |
| 1497 | // |
| 1498 | |
| 1499 | const gfx::Transform identity_matrix; |
| 1500 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1501 | scoped_refptr<Layer> child = Layer::Create(); |
| 1502 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1503 | scoped_refptr<Layer> great_grand_child = Layer::Create(); |
| 1504 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1505 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1506 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1507 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1508 | parent->AddChild(child); |
| 1509 | child->AddChild(grand_child); |
| 1510 | grand_child->AddChild(great_grand_child); |
| 1511 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1512 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1513 | host->SetRootLayer(parent); |
| 1514 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1515 | // leaf_node1 ensures that parent and child are kept on the |
| 1516 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1517 | // should be clipped. |
| 1518 | child->AddChild(leaf_node1); |
| 1519 | great_grand_child->AddChild(leaf_node2); |
| 1520 | |
| 1521 | SetLayerPropertiesForTesting(parent.get(), |
| 1522 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1523 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1524 | gfx::PointF(), |
| 1525 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1526 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1527 | false); |
| 1528 | SetLayerPropertiesForTesting(child.get(), |
| 1529 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1530 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1531 | gfx::PointF(), |
| 1532 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1533 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1534 | false); |
| 1535 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1536 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1537 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1538 | gfx::PointF(45.f, 45.f), |
| 1539 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1540 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1541 | false); |
| 1542 | SetLayerPropertiesForTesting(great_grand_child.get(), |
| 1543 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1544 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1545 | gfx::PointF(), |
| 1546 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1547 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1548 | false); |
| 1549 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1550 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1551 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1552 | gfx::PointF(), |
| 1553 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1554 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1555 | false); |
| 1556 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1557 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1558 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1559 | gfx::PointF(), |
| 1560 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1561 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1562 | false); |
| 1563 | |
| 1564 | child->SetMasksToBounds(true); |
| 1565 | child->SetOpacity(0.4f); |
| 1566 | child->SetForceRenderSurface(true); |
| 1567 | grand_child->SetOpacity(0.5f); |
| 1568 | great_grand_child->SetOpacity(0.4f); |
| 1569 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1570 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1571 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1572 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1573 | inputs.can_adjust_raster_scales = true; |
| 1574 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1575 | |
| 1576 | ASSERT_EQ(2U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1577 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1578 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1579 | } |
| 1580 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1581 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1582 | // When a render surface has a clip rect, it is used to clip the content rect |
| 1583 | // of the surface. When the render surface is animating its transforms, then |
| 1584 | // the content rect's position in the clip rect is not defined on the main |
| 1585 | // thread, and its content rect should not be clipped. |
| 1586 | |
| 1587 | // The test tree is set up as follows: |
| 1588 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1589 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1590 | // the parent. |
| 1591 | // - grand_child is a render surface, and the only visible content in child. |
| 1592 | // It is positioned outside of the clip rect from parent. |
| 1593 | |
| 1594 | // In this configuration, grand_child should be outside the clipped |
| 1595 | // content rect of the child, making grand_child not appear in the |
| 1596 | // render_surface_layer_list. However, when we place an animation on the |
| 1597 | // child, this clipping should be avoided and we should keep the grand_child |
| 1598 | // in the render_surface_layer_list. |
| 1599 | |
| 1600 | const gfx::Transform identity_matrix; |
| 1601 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1602 | scoped_refptr<Layer> child = Layer::Create(); |
| 1603 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1604 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node = |
| 1605 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1606 | parent->AddChild(child); |
| 1607 | child->AddChild(grand_child); |
| 1608 | grand_child->AddChild(leaf_node); |
| 1609 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1610 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1611 | host->SetRootLayer(parent); |
| 1612 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1613 | SetLayerPropertiesForTesting(parent.get(), |
| 1614 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1615 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1616 | gfx::PointF(), |
| 1617 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1618 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1619 | false); |
| 1620 | SetLayerPropertiesForTesting(child.get(), |
| 1621 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1622 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1623 | gfx::PointF(), |
| 1624 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1625 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1626 | false); |
| 1627 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1628 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1629 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1630 | gfx::PointF(200.f, 200.f), |
| 1631 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1632 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1633 | false); |
| 1634 | SetLayerPropertiesForTesting(leaf_node.get(), |
| 1635 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1636 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1637 | gfx::PointF(), |
| 1638 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1639 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1640 | false); |
| 1641 | |
| 1642 | parent->SetMasksToBounds(true); |
| 1643 | child->SetOpacity(0.4f); |
| 1644 | child->SetForceRenderSurface(true); |
| 1645 | grand_child->SetOpacity(0.4f); |
| 1646 | grand_child->SetForceRenderSurface(true); |
| 1647 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1648 | { |
| 1649 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1650 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1651 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1652 | inputs.can_adjust_raster_scales = true; |
| 1653 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1654 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1655 | // Without an animation, we should cull child and grand_child from the |
| 1656 | // render_surface_layer_list. |
| 1657 | ASSERT_EQ(1U, render_surface_layer_list.size()); |
| 1658 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1659 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1660 | |
| 1661 | // Now put an animating transform on child. |
| 1662 | AddAnimatedTransformToController( |
| 1663 | child->layer_animation_controller(), 10.0, 30, 0); |
| 1664 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1665 | { |
| 1666 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1667 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1668 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1669 | inputs.can_adjust_raster_scales = true; |
| 1670 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1671 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1672 | // With an animating transform, we should keep child and grand_child in the |
| 1673 | // render_surface_layer_list. |
| 1674 | ASSERT_EQ(3U, render_surface_layer_list.size()); |
| 1675 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1676 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
| 1677 | EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id()); |
| 1678 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1679 | } |
| 1680 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1681 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1682 | // Layer's IsClipped() property is set to true when: |
| 1683 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1684 | // - the layer is clipped by an ancestor that contributes to the same |
| 1685 | // render target, |
| 1686 | // - a surface is clipped by an ancestor that contributes to the same |
| 1687 | // render target. |
| 1688 | // |
| 1689 | // In particular, for a layer that owns a render surface: |
| 1690 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1691 | // pass that clipped status to the layer itself. |
| 1692 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1693 | // and propagates the clip to the subtree. |
| 1694 | |
| 1695 | const gfx::Transform identity_matrix; |
| 1696 | scoped_refptr<Layer> root = Layer::Create(); |
| 1697 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1698 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 1699 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 1700 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1701 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1702 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1703 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1704 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1705 | root->AddChild(parent); |
| 1706 | parent->AddChild(child1); |
| 1707 | parent->AddChild(child2); |
| 1708 | child1->AddChild(grand_child); |
| 1709 | child2->AddChild(leaf_node2); |
| 1710 | grand_child->AddChild(leaf_node1); |
| 1711 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1712 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1713 | host->SetRootLayer(root); |
| 1714 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1715 | child2->SetForceRenderSurface(true); |
| 1716 | |
| 1717 | SetLayerPropertiesForTesting(root.get(), |
| 1718 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1719 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1720 | gfx::PointF(), |
| 1721 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1722 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1723 | false); |
| 1724 | SetLayerPropertiesForTesting(parent.get(), |
| 1725 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1726 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1727 | gfx::PointF(), |
| 1728 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1729 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1730 | false); |
| 1731 | SetLayerPropertiesForTesting(child1.get(), |
| 1732 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1733 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1734 | gfx::PointF(), |
| 1735 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1736 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1737 | false); |
| 1738 | SetLayerPropertiesForTesting(child2.get(), |
| 1739 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1740 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1741 | gfx::PointF(), |
| 1742 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1743 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1744 | false); |
| 1745 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1746 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1747 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1748 | gfx::PointF(), |
| 1749 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1750 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1751 | false); |
| 1752 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1753 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1754 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1755 | gfx::PointF(), |
| 1756 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1757 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1758 | false); |
| 1759 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1760 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1761 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1762 | gfx::PointF(), |
| 1763 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1764 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1765 | false); |
| 1766 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1767 | // Case 1: nothing is clipped except the root render surface. |
| 1768 | { |
| 1769 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1770 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1771 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1772 | inputs.can_adjust_raster_scales = true; |
| 1773 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1774 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1775 | ASSERT_TRUE(root->render_surface()); |
| 1776 | ASSERT_TRUE(child2->render_surface()); |
| 1777 | |
| 1778 | EXPECT_FALSE(root->is_clipped()); |
| 1779 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1780 | EXPECT_FALSE(parent->is_clipped()); |
| 1781 | EXPECT_FALSE(child1->is_clipped()); |
| 1782 | EXPECT_FALSE(child2->is_clipped()); |
| 1783 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1784 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1785 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1786 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1787 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1788 | |
| 1789 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1790 | // surface are clipped. But layers that contribute to child2's surface are |
| 1791 | // not clipped explicitly because child2's surface already accounts for |
| 1792 | // that clip. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1793 | { |
| 1794 | RenderSurfaceLayerList render_surface_layer_list; |
| 1795 | parent->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1796 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1797 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1798 | inputs.can_adjust_raster_scales = true; |
| 1799 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1800 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1801 | ASSERT_TRUE(root->render_surface()); |
| 1802 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1803 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1804 | EXPECT_FALSE(root->is_clipped()); |
| 1805 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1806 | EXPECT_TRUE(parent->is_clipped()); |
| 1807 | EXPECT_TRUE(child1->is_clipped()); |
| 1808 | EXPECT_FALSE(child2->is_clipped()); |
| 1809 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1810 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1811 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1812 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1813 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1814 | |
| 1815 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1816 | // child2's render surface is not clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1817 | { |
| 1818 | RenderSurfaceLayerList render_surface_layer_list; |
| 1819 | parent->SetMasksToBounds(false); |
| 1820 | child2->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1821 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1822 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1823 | inputs.can_adjust_raster_scales = true; |
| 1824 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1825 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1826 | ASSERT_TRUE(root->render_surface()); |
| 1827 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1828 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1829 | EXPECT_FALSE(root->is_clipped()); |
| 1830 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1831 | EXPECT_FALSE(parent->is_clipped()); |
| 1832 | EXPECT_FALSE(child1->is_clipped()); |
| 1833 | EXPECT_TRUE(child2->is_clipped()); |
| 1834 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1835 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1836 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1837 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1838 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1839 | } |
| 1840 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 1841 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1842 | // Verify that layers get the appropriate DrawableContentRect when their |
| 1843 | // parent masksToBounds is true. |
| 1844 | // |
| 1845 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 1846 | // be the layer rect expressed in target space. |
| 1847 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 1848 | // will be the intersection of layer bounds and the mask region. |
| 1849 | // grand_child3 - partially clipped and masksToBounds; the |
| 1850 | // DrawableContentRect will still be the intersection of layer bounds and |
| 1851 | // the mask region. |
| 1852 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 1853 | // be empty. |
| 1854 | // |
| 1855 | |
| 1856 | const gfx::Transform identity_matrix; |
| 1857 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1858 | scoped_refptr<Layer> child = Layer::Create(); |
| 1859 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 1860 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 1861 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 1862 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 1863 | |
| 1864 | parent->AddChild(child); |
| 1865 | child->AddChild(grand_child1); |
| 1866 | child->AddChild(grand_child2); |
| 1867 | child->AddChild(grand_child3); |
| 1868 | child->AddChild(grand_child4); |
| 1869 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1870 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1871 | host->SetRootLayer(parent); |
| 1872 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1873 | SetLayerPropertiesForTesting(parent.get(), |
| 1874 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1875 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1876 | gfx::PointF(), |
| 1877 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1878 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1879 | false); |
| 1880 | SetLayerPropertiesForTesting(child.get(), |
| 1881 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1882 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1883 | gfx::PointF(), |
| 1884 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1885 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1886 | false); |
| 1887 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 1888 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1889 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1890 | gfx::PointF(5.f, 5.f), |
| 1891 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1892 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1893 | false); |
| 1894 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 1895 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1896 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1897 | gfx::PointF(15.f, 15.f), |
| 1898 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1899 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1900 | false); |
| 1901 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 1902 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1903 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1904 | gfx::PointF(15.f, 15.f), |
| 1905 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1906 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1907 | false); |
| 1908 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 1909 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1910 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1911 | gfx::PointF(45.f, 45.f), |
| 1912 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1913 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1914 | false); |
| 1915 | |
| 1916 | child->SetMasksToBounds(true); |
| 1917 | grand_child3->SetMasksToBounds(true); |
| 1918 | |
| 1919 | // Force everyone to be a render surface. |
| 1920 | child->SetOpacity(0.4f); |
| 1921 | grand_child1->SetOpacity(0.5f); |
| 1922 | grand_child2->SetOpacity(0.5f); |
| 1923 | grand_child3->SetOpacity(0.5f); |
| 1924 | grand_child4->SetOpacity(0.5f); |
| 1925 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1926 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1927 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1928 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1929 | inputs.can_adjust_raster_scales = true; |
| 1930 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1931 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 1932 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 1933 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 1934 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1935 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 1936 | } |
| 1937 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1938 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1939 | // Verify that render surfaces (and their layers) get the appropriate |
| 1940 | // clip rects when their parent masksToBounds is true. |
| 1941 | // |
| 1942 | // Layers that own render surfaces (at least for now) do not inherit any |
| 1943 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 1944 | // They may still have a clip rect of their own layer bounds, however, if |
| 1945 | // masksToBounds was true. |
| 1946 | const gfx::Transform identity_matrix; |
| 1947 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1948 | scoped_refptr<Layer> child = Layer::Create(); |
| 1949 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 1950 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 1951 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 1952 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 1953 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1954 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1955 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1956 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1957 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 = |
| 1958 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1959 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 = |
| 1960 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1961 | |
| 1962 | parent->AddChild(child); |
| 1963 | child->AddChild(grand_child1); |
| 1964 | child->AddChild(grand_child2); |
| 1965 | child->AddChild(grand_child3); |
| 1966 | child->AddChild(grand_child4); |
| 1967 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1968 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1969 | host->SetRootLayer(parent); |
| 1970 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1971 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 1972 | // this test. |
| 1973 | grand_child1->AddChild(leaf_node1); |
| 1974 | grand_child2->AddChild(leaf_node2); |
| 1975 | grand_child3->AddChild(leaf_node3); |
| 1976 | grand_child4->AddChild(leaf_node4); |
| 1977 | |
| 1978 | SetLayerPropertiesForTesting(parent.get(), |
| 1979 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1980 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1981 | gfx::PointF(), |
| 1982 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1983 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1984 | false); |
| 1985 | SetLayerPropertiesForTesting(child.get(), |
| 1986 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1987 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1988 | gfx::PointF(), |
| 1989 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1990 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1991 | false); |
| 1992 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 1993 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1994 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1995 | gfx::PointF(5.f, 5.f), |
| 1996 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1997 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1998 | false); |
| 1999 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2000 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2001 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2002 | gfx::PointF(15.f, 15.f), |
| 2003 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2004 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2005 | false); |
| 2006 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2007 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2008 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2009 | gfx::PointF(15.f, 15.f), |
| 2010 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2011 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2012 | false); |
| 2013 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2014 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2015 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2016 | gfx::PointF(45.f, 45.f), |
| 2017 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2018 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2019 | false); |
| 2020 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 2021 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2022 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2023 | gfx::PointF(), |
| 2024 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2025 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2026 | false); |
| 2027 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 2028 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2029 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2030 | gfx::PointF(), |
| 2031 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2032 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2033 | false); |
| 2034 | SetLayerPropertiesForTesting(leaf_node3.get(), |
| 2035 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2036 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2037 | gfx::PointF(), |
| 2038 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2039 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2040 | false); |
| 2041 | SetLayerPropertiesForTesting(leaf_node4.get(), |
| 2042 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2043 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2044 | gfx::PointF(), |
| 2045 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2046 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2047 | false); |
| 2048 | |
| 2049 | child->SetMasksToBounds(true); |
| 2050 | grand_child3->SetMasksToBounds(true); |
| 2051 | grand_child4->SetMasksToBounds(true); |
| 2052 | |
| 2053 | // Force everyone to be a render surface. |
| 2054 | child->SetOpacity(0.4f); |
| 2055 | child->SetForceRenderSurface(true); |
| 2056 | grand_child1->SetOpacity(0.5f); |
| 2057 | grand_child1->SetForceRenderSurface(true); |
| 2058 | grand_child2->SetOpacity(0.5f); |
| 2059 | grand_child2->SetForceRenderSurface(true); |
| 2060 | grand_child3->SetOpacity(0.5f); |
| 2061 | grand_child3->SetForceRenderSurface(true); |
| 2062 | grand_child4->SetOpacity(0.5f); |
| 2063 | grand_child4->SetForceRenderSurface(true); |
| 2064 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2065 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2066 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2067 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2068 | inputs.can_adjust_raster_scales = true; |
| 2069 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2070 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2071 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2072 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2073 | |
| 2074 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2075 | // masksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2076 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2077 | grand_child1->render_surface()->clip_rect()); |
| 2078 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2079 | grand_child2->render_surface()->clip_rect()); |
| 2080 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2081 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2082 | } |
| 2083 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2084 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2085 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2086 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2087 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 2088 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 2089 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 2090 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 2091 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 2092 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 2093 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2094 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 2095 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2096 | parent->AddChild(render_surface1); |
| 2097 | parent->AddChild(child_of_root); |
| 2098 | render_surface1->AddChild(child_of_rs1); |
| 2099 | render_surface1->AddChild(render_surface2); |
| 2100 | render_surface2->AddChild(child_of_rs2); |
| 2101 | child_of_root->AddChild(grand_child_of_root); |
| 2102 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 2103 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 2104 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2105 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2106 | host->SetRootLayer(parent); |
| 2107 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2108 | // Make our render surfaces. |
| 2109 | render_surface1->SetForceRenderSurface(true); |
| 2110 | render_surface2->SetForceRenderSurface(true); |
| 2111 | |
| 2112 | gfx::Transform layer_transform; |
| 2113 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2114 | |
| 2115 | SetLayerPropertiesForTesting(parent.get(), |
| 2116 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2117 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2118 | gfx::PointF(2.5f, 0.f), |
| 2119 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2120 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2121 | false); |
| 2122 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2123 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2124 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2125 | gfx::PointF(2.5f, 0.f), |
| 2126 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2127 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2128 | false); |
| 2129 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 2130 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2131 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2132 | gfx::PointF(2.5f, 0.f), |
| 2133 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2134 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2135 | false); |
| 2136 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 2137 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2138 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2139 | gfx::PointF(2.5f, 0.f), |
| 2140 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2141 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2142 | false); |
| 2143 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 2144 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2145 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2146 | gfx::PointF(2.5f, 0.f), |
| 2147 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2148 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2149 | false); |
| 2150 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 2151 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2152 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2153 | gfx::PointF(2.5f, 0.f), |
| 2154 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2155 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2156 | false); |
| 2157 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 2158 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2159 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2160 | gfx::PointF(2.5f, 0.f), |
| 2161 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2162 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2163 | false); |
| 2164 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 2165 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2166 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2167 | gfx::PointF(2.5f, 0.f), |
| 2168 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2169 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2170 | false); |
| 2171 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 2172 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2173 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2174 | gfx::PointF(2.5f, 0.f), |
| 2175 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2176 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2177 | false); |
| 2178 | |
| 2179 | // Put an animated opacity on the render surface. |
| 2180 | AddOpacityTransitionToController( |
| 2181 | render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2182 | |
| 2183 | // Also put an animated opacity on a layer without descendants. |
| 2184 | AddOpacityTransitionToController( |
| 2185 | grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2186 | |
| 2187 | // Put a transform animation on the render surface. |
| 2188 | AddAnimatedTransformToController( |
| 2189 | render_surface2->layer_animation_controller(), 10.0, 30, 0); |
| 2190 | |
| 2191 | // Also put transform animations on grand_child_of_root, and |
| 2192 | // grand_child_of_rs2 |
| 2193 | AddAnimatedTransformToController( |
| 2194 | grand_child_of_root->layer_animation_controller(), 10.0, 30, 0); |
| 2195 | AddAnimatedTransformToController( |
| 2196 | grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0); |
| 2197 | |
| 2198 | ExecuteCalculateDrawProperties(parent.get()); |
| 2199 | |
| 2200 | // Only layers that are associated with render surfaces should have an actual |
| 2201 | // RenderSurface() value. |
| 2202 | ASSERT_TRUE(parent->render_surface()); |
| 2203 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2204 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2205 | |
| 2206 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2207 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2208 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2209 | |
| 2210 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2211 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2212 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2213 | |
| 2214 | // Verify all render target accessors |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2215 | EXPECT_EQ(parent.get(), parent->render_target()); |
| 2216 | EXPECT_EQ(parent.get(), child_of_root->render_target()); |
| 2217 | EXPECT_EQ(parent.get(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2218 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2219 | EXPECT_EQ(render_surface1.get(), render_surface1->render_target()); |
| 2220 | EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target()); |
| 2221 | EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2222 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2223 | EXPECT_EQ(render_surface2.get(), render_surface2->render_target()); |
| 2224 | EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target()); |
| 2225 | EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2226 | |
| 2227 | // Verify draw_opacity_is_animating values |
| 2228 | EXPECT_FALSE(parent->draw_opacity_is_animating()); |
| 2229 | EXPECT_FALSE(child_of_root->draw_opacity_is_animating()); |
| 2230 | EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating()); |
| 2231 | EXPECT_FALSE(render_surface1->draw_opacity_is_animating()); |
| 2232 | EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating()); |
| 2233 | EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating()); |
| 2234 | EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating()); |
| 2235 | EXPECT_FALSE(render_surface2->draw_opacity_is_animating()); |
| 2236 | EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating()); |
| 2237 | EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating()); |
| 2238 | EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating()); |
| 2239 | |
| 2240 | // Verify draw_transform_is_animating values |
| 2241 | EXPECT_FALSE(parent->draw_transform_is_animating()); |
| 2242 | EXPECT_FALSE(child_of_root->draw_transform_is_animating()); |
| 2243 | EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating()); |
| 2244 | EXPECT_FALSE(render_surface1->draw_transform_is_animating()); |
| 2245 | EXPECT_FALSE(render_surface1->render_surface() |
| 2246 | ->target_surface_transforms_are_animating()); |
| 2247 | EXPECT_FALSE(child_of_rs1->draw_transform_is_animating()); |
| 2248 | EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating()); |
| 2249 | EXPECT_FALSE(render_surface2->draw_transform_is_animating()); |
| 2250 | EXPECT_TRUE(render_surface2->render_surface() |
| 2251 | ->target_surface_transforms_are_animating()); |
| 2252 | EXPECT_FALSE(child_of_rs2->draw_transform_is_animating()); |
| 2253 | EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating()); |
| 2254 | |
| 2255 | // Verify screen_space_transform_is_animating values |
| 2256 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2257 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2258 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2259 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
| 2260 | EXPECT_FALSE(render_surface1->render_surface() |
| 2261 | ->screen_space_transforms_are_animating()); |
| 2262 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2263 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2264 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
| 2265 | EXPECT_TRUE(render_surface2->render_surface() |
| 2266 | ->screen_space_transforms_are_animating()); |
| 2267 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2268 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2269 | |
| 2270 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2271 | // It is expected that we correctly set up transforms so that the y-component |
| 2272 | // 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] | 2273 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 2274 | EXPECT_FLOAT_EQ(2.0, |
| 2275 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2276 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2277 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2278 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2279 | EXPECT_FLOAT_EQ(2.0, |
| 2280 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 2281 | EXPECT_FLOAT_EQ(3.0, |
| 2282 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2283 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2284 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2285 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2286 | EXPECT_FLOAT_EQ(3.0, |
| 2287 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 2288 | EXPECT_FLOAT_EQ(4.0, |
| 2289 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2290 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2291 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2292 | } |
| 2293 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2294 | TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2295 | // Test the calculateVisibleRect() function works correctly for identity |
| 2296 | // transforms. |
| 2297 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2298 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2299 | gfx::Transform layer_to_surface_transform; |
| 2300 | |
| 2301 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2302 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2303 | gfx::Rect expected = gfx::Rect(10, 10, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2304 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2305 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2306 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2307 | |
| 2308 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2309 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2310 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2311 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2312 | EXPECT_TRUE(actual.IsEmpty()); |
| 2313 | |
| 2314 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2315 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
| 2316 | expected = gfx::Rect(80, 80, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2317 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2318 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2319 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2320 | } |
| 2321 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2322 | TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2323 | // Test the calculateVisibleRect() function works correctly for scaling |
| 2324 | // transforms. |
| 2325 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2326 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2327 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2328 | gfx::Transform layer_to_surface_transform; |
| 2329 | |
| 2330 | // Case 1: Layer is contained within the surface. |
| 2331 | layer_to_surface_transform.MakeIdentity(); |
| 2332 | layer_to_surface_transform.Translate(10.0, 10.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2333 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2334 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2335 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2336 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2337 | |
| 2338 | // Case 2: Layer is outside the surface rect. |
| 2339 | layer_to_surface_transform.MakeIdentity(); |
| 2340 | layer_to_surface_transform.Translate(120.0, 120.0); |
| 2341 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2342 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2343 | EXPECT_TRUE(actual.IsEmpty()); |
| 2344 | |
| 2345 | // Case 3: Layer is partially overlapping the surface rect. |
| 2346 | layer_to_surface_transform.MakeIdentity(); |
| 2347 | layer_to_surface_transform.Translate(80.0, 80.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2348 | expected = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2349 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2350 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2351 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2352 | } |
| 2353 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2354 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2355 | // Test the calculateVisibleRect() function works correctly for rotations |
| 2356 | // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() |
| 2357 | // should return the g in the layer's space. |
| 2358 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2359 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2360 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2361 | gfx::Transform layer_to_surface_transform; |
| 2362 | |
| 2363 | // Case 1: Layer is contained within the surface. |
| 2364 | layer_to_surface_transform.MakeIdentity(); |
| 2365 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2366 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2367 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2368 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2369 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2370 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2371 | |
| 2372 | // Case 2: Layer is outside the surface rect. |
| 2373 | layer_to_surface_transform.MakeIdentity(); |
| 2374 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2375 | layer_to_surface_transform.Rotate(45.0); |
| 2376 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2377 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2378 | EXPECT_TRUE(actual.IsEmpty()); |
| 2379 | |
| 2380 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2381 | // the layer is oriented diagonally, with the left half outside of the render |
| 2382 | // surface. In this case, the g should still be the entire layer |
| 2383 | // (remember the g is computed in layer space); both the top-left |
| 2384 | // and bottom-right corners of the layer are still visible. |
| 2385 | layer_to_surface_transform.MakeIdentity(); |
| 2386 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2387 | expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2388 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2389 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2390 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2391 | |
| 2392 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2393 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2394 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2395 | // surface overlaps the right side of the layer. The g should be |
| 2396 | // the layer's right half. |
| 2397 | layer_to_surface_transform.MakeIdentity(); |
| 2398 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2399 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2400 | expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2401 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2402 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2403 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2404 | } |
| 2405 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2406 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2407 | // Test that the calculateVisibleRect() function works correctly for 3d |
| 2408 | // transforms. |
| 2409 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2410 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2411 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2412 | gfx::Transform layer_to_surface_transform; |
| 2413 | |
| 2414 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2415 | // degrees, should be fully contained in the render surface. |
| 2416 | layer_to_surface_transform.MakeIdentity(); |
| 2417 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2418 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2419 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2420 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2421 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2422 | |
| 2423 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2424 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2425 | // visible on the surface. |
| 2426 | // 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] | 2427 | SkMScalar half_width_of_rotated_layer = |
| 2428 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2429 | layer_to_surface_transform.MakeIdentity(); |
| 2430 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2431 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2432 | // edge of the layer. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2433 | expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2434 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2435 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2436 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2437 | } |
| 2438 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2439 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2440 | // Test the calculateVisibleRect() function works correctly when the layer has |
| 2441 | // a perspective projection onto the target surface. |
| 2442 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2443 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2444 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2445 | gfx::Transform layer_to_surface_transform; |
| 2446 | |
| 2447 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2448 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2449 | // its translated more than the perspective amount. |
| 2450 | layer_to_surface_transform.MakeIdentity(); |
| 2451 | |
| 2452 | // The following sequence of transforms applies the perspective about the |
| 2453 | // center of the surface. |
| 2454 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2455 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2456 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2457 | |
| 2458 | // This translate places the layer in front of the surface's projection plane. |
| 2459 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2460 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2461 | gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2462 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2463 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2464 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2465 | |
| 2466 | // Case 2: same projection as before, except that the layer is also translated |
| 2467 | // to the side, so that only the right half of the layer should be visible. |
| 2468 | // |
| 2469 | // Explanation of expected result: The perspective ratio is (z distance |
| 2470 | // between layer and camera origin) / (z distance between projection plane and |
| 2471 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
| 2472 | // move a layer by translating -50 units in projected surface units (so that |
| 2473 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
| 2474 | // -50 == -200 in the layer's units. |
| 2475 | layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2476 | expected = gfx::Rect(gfx::Point(50, -50), |
| 2477 | gfx::Size(100, 200)); // The right half of the layer's |
| 2478 | // bounding rect. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2479 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2480 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2481 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2482 | } |
| 2483 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2484 | TEST_F(LayerTreeHostCommonTest, |
| 2485 | VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2486 | // There is currently no explicit concept of an orthographic projection plane |
| 2487 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2488 | // are technically behind the surface in an orthographic world should not be |
| 2489 | // clipped when they are flattened to the surface. |
| 2490 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2491 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2492 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2493 | gfx::Transform layer_to_surface_transform; |
| 2494 | |
| 2495 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2496 | // at the center of the layer. |
| 2497 | layer_to_surface_transform.MakeIdentity(); |
| 2498 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2499 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2500 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2501 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2502 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2503 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2504 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2505 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2506 | } |
| 2507 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2508 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2509 | // Test the calculateVisibleRect() function works correctly when projecting a |
| 2510 | // surface onto a layer, but the layer is partially behind the camera (not |
| 2511 | // just behind the projection plane). In this case, the cartesian coordinates |
| 2512 | // may seem to be valid, but actually they are not. The visible rect needs to |
| 2513 | // be properly clipped by the w = 0 plane in homogeneous coordinates before |
| 2514 | // converting to cartesian coordinates. |
| 2515 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2516 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2517 | gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2518 | gfx::Transform layer_to_surface_transform; |
| 2519 | |
| 2520 | // The layer is positioned so that the right half of the layer should be in |
| 2521 | // front of the camera, while the other half is behind the surface's |
| 2522 | // projection plane. The following sequence of transforms applies the |
| 2523 | // perspective and rotation about the center of the layer. |
| 2524 | layer_to_surface_transform.MakeIdentity(); |
| 2525 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2526 | layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); |
| 2527 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2528 | |
| 2529 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2530 | // transform, otherwise this code is not testing the intended scenario. |
| 2531 | bool clipped; |
| 2532 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2533 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2534 | &clipped); |
| 2535 | ASSERT_TRUE(clipped); |
| 2536 | |
| 2537 | int expected_x_position = 0; |
| 2538 | int expected_width = 10; |
| 2539 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2540 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2541 | EXPECT_EQ(expected_x_position, actual.x()); |
| 2542 | EXPECT_EQ(expected_width, actual.width()); |
| 2543 | } |
| 2544 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2545 | TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2546 | // To determine visible rect in layer space, there needs to be an |
| 2547 | // un-projection from surface space to layer space. When the original |
| 2548 | // transform was a perspective projection that was clipped, it returns a rect |
| 2549 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2550 | // clipping again. |
| 2551 | |
| 2552 | // This sequence of transforms causes one corner of the layer to protrude |
| 2553 | // across the w = 0 plane, and should be clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2554 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
| 2555 | gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2556 | gfx::Transform layer_to_surface_transform; |
| 2557 | layer_to_surface_transform.MakeIdentity(); |
| 2558 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2559 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2560 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2561 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2562 | |
| 2563 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2564 | // code is not testing the intended scenario. |
| 2565 | bool clipped; |
| 2566 | gfx::RectF clipped_rect = |
| 2567 | MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); |
| 2568 | MathUtil::ProjectQuad( |
| 2569 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2570 | ASSERT_TRUE(clipped); |
| 2571 | |
| 2572 | // Only the corner of the layer is not visible on the surface because of being |
| 2573 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2574 | // rect is that the entire layer should still be considered visible. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2575 | gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2576 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2577 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2578 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2579 | } |
| 2580 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2581 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2582 | scoped_refptr<Layer> root = Layer::Create(); |
| 2583 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2584 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2585 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2586 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2587 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2588 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2589 | root->AddChild(child1); |
| 2590 | root->AddChild(child2); |
| 2591 | root->AddChild(child3); |
| 2592 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2593 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2594 | host->SetRootLayer(root); |
| 2595 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2596 | gfx::Transform identity_matrix; |
| 2597 | SetLayerPropertiesForTesting(root.get(), |
| 2598 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2599 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2600 | gfx::PointF(), |
| 2601 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2602 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2603 | false); |
| 2604 | SetLayerPropertiesForTesting(child1.get(), |
| 2605 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2606 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2607 | gfx::PointF(), |
| 2608 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2609 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2610 | false); |
| 2611 | SetLayerPropertiesForTesting(child2.get(), |
| 2612 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2613 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2614 | gfx::PointF(75.f, 75.f), |
| 2615 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2616 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2617 | false); |
| 2618 | SetLayerPropertiesForTesting(child3.get(), |
| 2619 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2620 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2621 | gfx::PointF(125.f, 125.f), |
| 2622 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2623 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2624 | false); |
| 2625 | |
| 2626 | ExecuteCalculateDrawProperties(root.get()); |
| 2627 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2628 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2629 | root->render_surface()->DrawableContentRect()); |
| 2630 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2631 | |
| 2632 | // Layers that do not draw content should have empty visible_content_rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2633 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2634 | |
| 2635 | // layer visible_content_rects are clipped by their target surface. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2636 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2637 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2638 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 2639 | |
| 2640 | // layer drawable_content_rects are not clipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2641 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect()); |
| 2642 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2643 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2644 | } |
| 2645 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2646 | TEST_F(LayerTreeHostCommonTest, |
| 2647 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2648 | scoped_refptr<Layer> root = Layer::Create(); |
| 2649 | scoped_refptr<Layer> child = Layer::Create(); |
| 2650 | scoped_refptr<LayerWithForcedDrawsContent> grand_child1 = |
| 2651 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2652 | scoped_refptr<LayerWithForcedDrawsContent> grand_child2 = |
| 2653 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2654 | scoped_refptr<LayerWithForcedDrawsContent> grand_child3 = |
| 2655 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2656 | root->AddChild(child); |
| 2657 | child->AddChild(grand_child1); |
| 2658 | child->AddChild(grand_child2); |
| 2659 | child->AddChild(grand_child3); |
| 2660 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2661 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2662 | host->SetRootLayer(root); |
| 2663 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2664 | gfx::Transform identity_matrix; |
| 2665 | SetLayerPropertiesForTesting(root.get(), |
| 2666 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2667 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2668 | gfx::PointF(), |
| 2669 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2670 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2671 | false); |
| 2672 | SetLayerPropertiesForTesting(child.get(), |
| 2673 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2674 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2675 | gfx::PointF(), |
| 2676 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2677 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2678 | false); |
| 2679 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2680 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2681 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2682 | gfx::PointF(5.f, 5.f), |
| 2683 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2684 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2685 | false); |
| 2686 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2687 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2688 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2689 | gfx::PointF(75.f, 75.f), |
| 2690 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2691 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2692 | false); |
| 2693 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2694 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2695 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2696 | gfx::PointF(125.f, 125.f), |
| 2697 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2698 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2699 | false); |
| 2700 | |
| 2701 | child->SetMasksToBounds(true); |
| 2702 | ExecuteCalculateDrawProperties(root.get()); |
| 2703 | |
| 2704 | ASSERT_FALSE(child->render_surface()); |
| 2705 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2706 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2707 | root->render_surface()->DrawableContentRect()); |
| 2708 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2709 | |
| 2710 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2711 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2712 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2713 | |
| 2714 | // All grandchild visible content rects should be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2715 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect()); |
| 2716 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2717 | EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty()); |
| 2718 | |
| 2719 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2720 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 2721 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2722 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 2723 | } |
| 2724 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2725 | TEST_F(LayerTreeHostCommonTest, |
| 2726 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2727 | scoped_refptr<Layer> root = Layer::Create(); |
| 2728 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2729 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2730 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2731 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2732 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2733 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2734 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2735 | root->AddChild(render_surface1); |
| 2736 | render_surface1->AddChild(child1); |
| 2737 | render_surface1->AddChild(child2); |
| 2738 | render_surface1->AddChild(child3); |
| 2739 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2740 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2741 | host->SetRootLayer(root); |
| 2742 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2743 | gfx::Transform identity_matrix; |
| 2744 | SetLayerPropertiesForTesting(root.get(), |
| 2745 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2746 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2747 | gfx::PointF(), |
| 2748 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2749 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2750 | false); |
| 2751 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2752 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2753 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2754 | gfx::PointF(), |
| 2755 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2756 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2757 | false); |
| 2758 | SetLayerPropertiesForTesting(child1.get(), |
| 2759 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2760 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2761 | gfx::PointF(5.f, 5.f), |
| 2762 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2763 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2764 | false); |
| 2765 | SetLayerPropertiesForTesting(child2.get(), |
| 2766 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2767 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2768 | gfx::PointF(75.f, 75.f), |
| 2769 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2770 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2771 | false); |
| 2772 | SetLayerPropertiesForTesting(child3.get(), |
| 2773 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2774 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2775 | gfx::PointF(125.f, 125.f), |
| 2776 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2777 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2778 | false); |
| 2779 | |
| 2780 | render_surface1->SetForceRenderSurface(true); |
| 2781 | ExecuteCalculateDrawProperties(root.get()); |
| 2782 | |
| 2783 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2784 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2785 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2786 | root->render_surface()->DrawableContentRect()); |
| 2787 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2788 | |
| 2789 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2790 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2791 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2792 | |
| 2793 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 2794 | // regions of the subtree. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2795 | EXPECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 2796 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2797 | |
| 2798 | // All layers that draw content into the unclipped surface are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2799 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2800 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 2801 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2802 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2803 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 2804 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2805 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2806 | } |
| 2807 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2808 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2809 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
| 2810 | scoped_refptr<Layer> root = Layer::Create(); |
| 2811 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2812 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2813 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2814 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2815 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2816 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2817 | root->AddChild(child1); |
| 2818 | root->AddChild(child2); |
| 2819 | root->AddChild(child3); |
| 2820 | |
| 2821 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 2822 | host->SetRootLayer(root); |
| 2823 | |
| 2824 | gfx::Transform identity_matrix; |
| 2825 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 2826 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 2827 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(), |
| 2828 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 2829 | false); |
| 2830 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(), |
| 2831 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 2832 | false); |
| 2833 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, gfx::Point3F(), |
| 2834 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 2835 | true, false); |
| 2836 | |
| 2837 | RenderSurfaceLayerList render_surface_layer_list; |
| 2838 | // Now set the root render surface an empty clip. |
| 2839 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2840 | root.get(), gfx::Size(), &render_surface_layer_list); |
| 2841 | |
| 2842 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 2843 | ASSERT_TRUE(root->render_surface()); |
| 2844 | EXPECT_FALSE(root->is_clipped()); |
| 2845 | |
| 2846 | gfx::Rect empty; |
| 2847 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 2848 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 2849 | |
| 2850 | // Visible content rect calculation will check if the target surface is |
| 2851 | // clipped or not. An empty clip rect does not indicate the render surface |
| 2852 | // is unclipped. |
| 2853 | EXPECT_EQ(empty, child1->visible_content_rect()); |
| 2854 | EXPECT_EQ(empty, child2->visible_content_rect()); |
| 2855 | EXPECT_EQ(empty, child3->visible_content_rect()); |
| 2856 | } |
| 2857 | |
| 2858 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2859 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2860 | scoped_refptr<Layer> root = Layer::Create(); |
| 2861 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2862 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2863 | root->AddChild(child); |
| 2864 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2865 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2866 | host->SetRootLayer(root); |
| 2867 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2868 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2869 | gfx::Transform identity_matrix; |
| 2870 | 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] | 2871 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2872 | |
| 2873 | SetLayerPropertiesForTesting(root.get(), |
| 2874 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2875 | gfx::Point3F(), |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2876 | gfx::PointF(), |
| 2877 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2878 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2879 | false); |
| 2880 | SetLayerPropertiesForTesting(child.get(), |
| 2881 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2882 | gfx::Point3F(), |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2883 | gfx::PointF(5.f, 5.f), |
| 2884 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2885 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2886 | false); |
| 2887 | |
| 2888 | ExecuteCalculateDrawProperties(root.get()); |
| 2889 | |
| 2890 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2891 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2892 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2893 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 2894 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2895 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2896 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2897 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2898 | |
| 2899 | SetLayerPropertiesForTesting(child.get(), |
| 2900 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2901 | gfx::Point3F(), |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2902 | gfx::PointF(5.f, 5.f), |
| 2903 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2904 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2905 | false); |
| 2906 | |
| 2907 | ExecuteCalculateDrawProperties(root.get()); |
| 2908 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2909 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2910 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2911 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2912 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2913 | uninvertible_matrix.MakeIdentity(); |
| 2914 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2915 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2916 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2917 | |
| 2918 | SetLayerPropertiesForTesting(child.get(), |
| 2919 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2920 | gfx::Point3F(), |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2921 | gfx::PointF(5.f, 5.f), |
| 2922 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2923 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2924 | false); |
| 2925 | |
| 2926 | ExecuteCalculateDrawProperties(root.get()); |
| 2927 | |
| 2928 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2929 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2930 | } |
| 2931 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2932 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2933 | SingularTransformDoesNotPreventClearingDrawProperties) { |
| 2934 | scoped_refptr<Layer> root = Layer::Create(); |
| 2935 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2936 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2937 | root->AddChild(child); |
| 2938 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2939 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2940 | host->SetRootLayer(root); |
| 2941 | |
| 2942 | gfx::Transform identity_matrix; |
| 2943 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 2944 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2945 | |
| 2946 | SetLayerPropertiesForTesting(root.get(), |
| 2947 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2948 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2949 | gfx::PointF(), |
| 2950 | gfx::Size(100, 100), |
| 2951 | true, |
| 2952 | false); |
| 2953 | SetLayerPropertiesForTesting(child.get(), |
| 2954 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2955 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2956 | gfx::PointF(5.f, 5.f), |
| 2957 | gfx::Size(50, 50), |
| 2958 | true, |
| 2959 | false); |
| 2960 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 2961 | child->draw_properties().sorted_for_recursion = true; |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2962 | |
| 2963 | TransformOperations start_transform_operations; |
| 2964 | start_transform_operations.AppendScale(1.f, 0.f, 0.f); |
| 2965 | |
| 2966 | TransformOperations end_transform_operations; |
| 2967 | end_transform_operations.AppendScale(1.f, 1.f, 0.f); |
| 2968 | |
| 2969 | AddAnimatedTransformToLayer( |
| 2970 | root.get(), 10.0, start_transform_operations, end_transform_operations); |
| 2971 | |
| 2972 | EXPECT_TRUE(root->TransformIsAnimating()); |
| 2973 | |
| 2974 | ExecuteCalculateDrawProperties(root.get()); |
| 2975 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 2976 | EXPECT_FALSE(child->draw_properties().sorted_for_recursion); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 2980 | SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) { |
| 2981 | scoped_refptr<Layer> root = Layer::Create(); |
| 2982 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2983 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 2984 | host->SetRootLayer(root); |
| 2985 | |
| 2986 | gfx::Transform identity_matrix; |
| 2987 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 2988 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2989 | |
| 2990 | SetLayerPropertiesForTesting(root.get(), |
| 2991 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2992 | gfx::Point3F(), |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 2993 | gfx::PointF(), |
| 2994 | gfx::Size(100, 100), |
| 2995 | true, |
| 2996 | false); |
| 2997 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 2998 | root->draw_properties().sorted_for_recursion = true; |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 2999 | |
| 3000 | EXPECT_FALSE(root->TransformIsAnimating()); |
| 3001 | |
| 3002 | ExecuteCalculateDrawProperties(root.get()); |
| 3003 | |
vollick | eb19494 | 2014-09-12 17:45:27 | [diff] [blame] | 3004 | EXPECT_FALSE(root->draw_properties().sorted_for_recursion); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3008 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3009 | scoped_refptr<Layer> root = Layer::Create(); |
| 3010 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3011 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3012 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3013 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3014 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3015 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3016 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3017 | root->AddChild(render_surface1); |
| 3018 | render_surface1->AddChild(child1); |
| 3019 | render_surface1->AddChild(child2); |
| 3020 | render_surface1->AddChild(child3); |
| 3021 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3022 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3023 | host->SetRootLayer(root); |
| 3024 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3025 | gfx::Transform identity_matrix; |
| 3026 | SetLayerPropertiesForTesting(root.get(), |
| 3027 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3028 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3029 | gfx::PointF(), |
| 3030 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3031 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3032 | false); |
| 3033 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3034 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3035 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3036 | gfx::PointF(), |
| 3037 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3038 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3039 | false); |
| 3040 | SetLayerPropertiesForTesting(child1.get(), |
| 3041 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3042 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3043 | gfx::PointF(5.f, 5.f), |
| 3044 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3045 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3046 | false); |
| 3047 | SetLayerPropertiesForTesting(child2.get(), |
| 3048 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3049 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3050 | gfx::PointF(75.f, 75.f), |
| 3051 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3052 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3053 | false); |
| 3054 | SetLayerPropertiesForTesting(child3.get(), |
| 3055 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3056 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3057 | gfx::PointF(125.f, 125.f), |
| 3058 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3059 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3060 | false); |
| 3061 | |
| 3062 | root->SetMasksToBounds(true); |
| 3063 | render_surface1->SetForceRenderSurface(true); |
| 3064 | ExecuteCalculateDrawProperties(root.get()); |
| 3065 | |
| 3066 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3067 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3068 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3069 | root->render_surface()->DrawableContentRect()); |
| 3070 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3071 | |
| 3072 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3073 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3074 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3075 | |
| 3076 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3077 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3078 | EXPECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3079 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3080 | |
| 3081 | // All layers that draw content into the surface have their visible content |
| 3082 | // rect clipped by the surface clip rect. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3083 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3084 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3085 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 3086 | |
| 3087 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3088 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3089 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3090 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3091 | } |
| 3092 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3093 | TEST_F(LayerTreeHostCommonTest, |
| 3094 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3095 | // Check that clipping does not propagate down surfaces. |
| 3096 | scoped_refptr<Layer> root = Layer::Create(); |
| 3097 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3098 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 3099 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3100 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3101 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3102 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3103 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3104 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3105 | root->AddChild(render_surface1); |
| 3106 | render_surface1->AddChild(render_surface2); |
| 3107 | render_surface2->AddChild(child1); |
| 3108 | render_surface2->AddChild(child2); |
| 3109 | render_surface2->AddChild(child3); |
| 3110 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3111 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3112 | host->SetRootLayer(root); |
| 3113 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3114 | gfx::Transform identity_matrix; |
| 3115 | SetLayerPropertiesForTesting(root.get(), |
| 3116 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3117 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3118 | gfx::PointF(), |
| 3119 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3120 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3121 | false); |
| 3122 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3123 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3124 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3125 | gfx::PointF(), |
| 3126 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3127 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3128 | false); |
| 3129 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3130 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3131 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3132 | gfx::PointF(), |
| 3133 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3134 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3135 | false); |
| 3136 | SetLayerPropertiesForTesting(child1.get(), |
| 3137 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3138 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3139 | gfx::PointF(5.f, 5.f), |
| 3140 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3141 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3142 | false); |
| 3143 | SetLayerPropertiesForTesting(child2.get(), |
| 3144 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3145 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3146 | gfx::PointF(75.f, 75.f), |
| 3147 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3148 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3149 | false); |
| 3150 | SetLayerPropertiesForTesting(child3.get(), |
| 3151 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3152 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3153 | gfx::PointF(125.f, 125.f), |
| 3154 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3155 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3156 | false); |
| 3157 | |
| 3158 | root->SetMasksToBounds(true); |
| 3159 | render_surface1->SetForceRenderSurface(true); |
| 3160 | render_surface2->SetForceRenderSurface(true); |
| 3161 | ExecuteCalculateDrawProperties(root.get()); |
| 3162 | |
| 3163 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3164 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3165 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3166 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3167 | root->render_surface()->DrawableContentRect()); |
| 3168 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3169 | |
| 3170 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3171 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3172 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
| 3173 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3174 | |
| 3175 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3176 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3177 | EXPECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3178 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3179 | |
| 3180 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3181 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3182 | // render_surface2 grows to enclose all drawable content of its subtree. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3183 | EXPECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 3184 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3185 | |
| 3186 | // All layers that draw content into render_surface2 think they are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3187 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3188 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3189 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3190 | |
| 3191 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3192 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3193 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3194 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3195 | } |
| 3196 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3197 | TEST_F(LayerTreeHostCommonTest, |
| 3198 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3199 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3200 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3201 | |
| 3202 | scoped_refptr<Layer> root = Layer::Create(); |
| 3203 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3204 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3205 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3206 | root->AddChild(render_surface1); |
| 3207 | render_surface1->AddChild(child1); |
| 3208 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3209 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3210 | host->SetRootLayer(root); |
| 3211 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3212 | gfx::Transform identity_matrix; |
| 3213 | gfx::Transform child_rotation; |
| 3214 | child_rotation.Rotate(45.0); |
| 3215 | SetLayerPropertiesForTesting(root.get(), |
| 3216 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3217 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3218 | gfx::PointF(), |
| 3219 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3220 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3221 | false); |
| 3222 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3223 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3224 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3225 | gfx::PointF(), |
| 3226 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3227 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3228 | false); |
| 3229 | SetLayerPropertiesForTesting(child1.get(), |
| 3230 | child_rotation, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3231 | gfx::Point3F(25, 25, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3232 | gfx::PointF(25.f, 25.f), |
| 3233 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3234 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3235 | false); |
| 3236 | |
| 3237 | render_surface1->SetForceRenderSurface(true); |
| 3238 | ExecuteCalculateDrawProperties(root.get()); |
| 3239 | |
| 3240 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3241 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3242 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3243 | root->render_surface()->DrawableContentRect()); |
| 3244 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3245 | |
| 3246 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3247 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3248 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3249 | |
| 3250 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3251 | // regions of the subtree. |
| 3252 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3253 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3254 | gfx::Rect(50 - diagonal_radius, |
| 3255 | 50 - diagonal_radius, |
| 3256 | diagonal_radius * 2, |
| 3257 | diagonal_radius * 2); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3258 | EXPECT_EQ(expected_surface_drawable_content, |
| 3259 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3260 | |
| 3261 | // All layers that draw content into the unclipped surface are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3262 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3263 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3264 | } |
| 3265 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3266 | TEST_F(LayerTreeHostCommonTest, |
| 3267 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3268 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3269 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3270 | |
| 3271 | scoped_refptr<Layer> root = Layer::Create(); |
| 3272 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3273 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3274 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3275 | root->AddChild(render_surface1); |
| 3276 | render_surface1->AddChild(child1); |
| 3277 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3278 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3279 | host->SetRootLayer(root); |
| 3280 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3281 | gfx::Transform identity_matrix; |
| 3282 | gfx::Transform child_rotation; |
| 3283 | child_rotation.Rotate(45.0); |
| 3284 | SetLayerPropertiesForTesting(root.get(), |
| 3285 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3286 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3287 | gfx::PointF(), |
| 3288 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3289 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3290 | false); |
| 3291 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3292 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3293 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3294 | gfx::PointF(), |
| 3295 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3296 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3297 | false); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3298 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3299 | SetLayerPropertiesForTesting(child1.get(), |
| 3300 | child_rotation, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3301 | gfx::Point3F(25, 25, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3302 | gfx::PointF(25.f, 25.f), |
| 3303 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3304 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3305 | false); |
| 3306 | |
| 3307 | root->SetMasksToBounds(true); |
| 3308 | render_surface1->SetForceRenderSurface(true); |
| 3309 | ExecuteCalculateDrawProperties(root.get()); |
| 3310 | |
| 3311 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3312 | |
| 3313 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 3314 | // rotated layer. |
| 3315 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3316 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 3317 | 50 - diagonal_radius, |
| 3318 | diagonal_radius * 2, |
| 3319 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3320 | gfx::Rect expected_surface_drawable_content = |
| 3321 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3322 | EXPECT_EQ(expected_surface_drawable_content, |
| 3323 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3324 | |
| 3325 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3326 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 3327 | // up covering the full left half of child1. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3328 | // |
| 3329 | // Given the floating point math, this number is a little bit fuzzy. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3330 | EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3331 | |
| 3332 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3333 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3334 | } |
| 3335 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3336 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3337 | MockContentLayerClient client; |
| 3338 | |
| 3339 | scoped_refptr<Layer> root = Layer::Create(); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 3340 | scoped_refptr<FakePictureLayer> render_surface1 = |
| 3341 | CreateDrawablePictureLayer(&client); |
| 3342 | scoped_refptr<FakePictureLayer> render_surface2 = |
| 3343 | CreateDrawablePictureLayer(&client); |
| 3344 | scoped_refptr<FakePictureLayer> child1 = CreateDrawablePictureLayer(&client); |
| 3345 | scoped_refptr<FakePictureLayer> child2 = CreateDrawablePictureLayer(&client); |
| 3346 | scoped_refptr<FakePictureLayer> child3 = CreateDrawablePictureLayer(&client); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3347 | root->AddChild(render_surface1); |
| 3348 | render_surface1->AddChild(render_surface2); |
| 3349 | render_surface2->AddChild(child1); |
| 3350 | render_surface2->AddChild(child2); |
| 3351 | render_surface2->AddChild(child3); |
| 3352 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3353 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3354 | host->SetRootLayer(root); |
| 3355 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3356 | gfx::Transform identity_matrix; |
| 3357 | SetLayerPropertiesForTesting(root.get(), |
| 3358 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3359 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3360 | gfx::PointF(), |
| 3361 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3362 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3363 | false); |
| 3364 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3365 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3366 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3367 | gfx::PointF(5.f, 5.f), |
| 3368 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3369 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3370 | false); |
| 3371 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3372 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3373 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3374 | gfx::PointF(5.f, 5.f), |
| 3375 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3376 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3377 | false); |
| 3378 | SetLayerPropertiesForTesting(child1.get(), |
| 3379 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3380 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3381 | gfx::PointF(5.f, 5.f), |
| 3382 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3383 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3384 | false); |
| 3385 | SetLayerPropertiesForTesting(child2.get(), |
| 3386 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3387 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3388 | gfx::PointF(75.f, 75.f), |
| 3389 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3390 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3391 | false); |
| 3392 | SetLayerPropertiesForTesting(child3.get(), |
| 3393 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3394 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3395 | gfx::PointF(125.f, 125.f), |
| 3396 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3397 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3398 | false); |
| 3399 | |
| 3400 | float device_scale_factor = 2.f; |
| 3401 | |
| 3402 | root->SetMasksToBounds(true); |
| 3403 | render_surface1->SetForceRenderSurface(true); |
| 3404 | render_surface2->SetForceRenderSurface(true); |
| 3405 | ExecuteCalculateDrawProperties(root.get(), device_scale_factor); |
| 3406 | |
| 3407 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3408 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3409 | |
| 3410 | // drawable_content_rects for all layers and surfaces are scaled by |
| 3411 | // device_scale_factor. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3412 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 3413 | root->render_surface()->DrawableContentRect()); |
| 3414 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); |
| 3415 | EXPECT_EQ(gfx::Rect(10, 10, 190, 190), |
| 3416 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3417 | |
| 3418 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 3419 | // is only implicitly clipped by render_surface1. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3420 | EXPECT_EQ(gfx::Rect(10, 10, 350, 350), |
| 3421 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3422 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3423 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3424 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 3425 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3426 | |
| 3427 | // The root layer does not actually draw content of its own. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3428 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3429 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 3430 | // All layer visible content rects are not expressed in content space of each |
| 3431 | // layer, so they are not scaled by the device_scale_factor. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3432 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_content_rect()); |
| 3433 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_content_rect()); |
| 3434 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3435 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3436 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3437 | } |
| 3438 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3439 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3440 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 3441 | // layers. Note that 3d transforms still apply in this case, but they are |
| 3442 | // "flattened" to each parent layer according to current W3C spec. |
| 3443 | |
| 3444 | const gfx::Transform identity_matrix; |
| 3445 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3446 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3447 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3448 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3449 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3450 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3451 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3452 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3453 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3454 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3455 | front_facing_child_of_front_facing_surface = |
| 3456 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3457 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3458 | back_facing_child_of_front_facing_surface = |
| 3459 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3460 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3461 | front_facing_child_of_back_facing_surface = |
| 3462 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3463 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3464 | back_facing_child_of_back_facing_surface = |
| 3465 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3466 | |
| 3467 | parent->AddChild(front_facing_child); |
| 3468 | parent->AddChild(back_facing_child); |
| 3469 | parent->AddChild(front_facing_surface); |
| 3470 | parent->AddChild(back_facing_surface); |
| 3471 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3472 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3473 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3474 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3475 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3476 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3477 | host->SetRootLayer(parent); |
| 3478 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3479 | // Nothing is double-sided |
| 3480 | front_facing_child->SetDoubleSided(false); |
| 3481 | back_facing_child->SetDoubleSided(false); |
| 3482 | front_facing_surface->SetDoubleSided(false); |
| 3483 | back_facing_surface->SetDoubleSided(false); |
| 3484 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3485 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3486 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3487 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3488 | |
| 3489 | gfx::Transform backface_matrix; |
| 3490 | backface_matrix.Translate(50.0, 50.0); |
| 3491 | backface_matrix.RotateAboutYAxis(180.0); |
| 3492 | backface_matrix.Translate(-50.0, -50.0); |
| 3493 | |
| 3494 | // Having a descendant and opacity will force these to have render surfaces. |
| 3495 | front_facing_surface->SetOpacity(0.5f); |
| 3496 | back_facing_surface->SetOpacity(0.5f); |
| 3497 | |
| 3498 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 3499 | // these layers should blindly use their own local transforms to determine |
| 3500 | // back-face culling. |
| 3501 | SetLayerPropertiesForTesting(parent.get(), |
| 3502 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3503 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3504 | gfx::PointF(), |
| 3505 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3506 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3507 | false); |
| 3508 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3509 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3510 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3511 | gfx::PointF(), |
| 3512 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3513 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3514 | false); |
| 3515 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3516 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3517 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3518 | gfx::PointF(), |
| 3519 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3520 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3521 | false); |
| 3522 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3523 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3524 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3525 | gfx::PointF(), |
| 3526 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3527 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3528 | false); |
| 3529 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3530 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3531 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3532 | gfx::PointF(), |
| 3533 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3534 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3535 | false); |
| 3536 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3537 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3538 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3539 | gfx::PointF(), |
| 3540 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3541 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3542 | false); |
| 3543 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3544 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3545 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3546 | gfx::PointF(), |
| 3547 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3548 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3549 | false); |
| 3550 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3551 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3552 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3553 | gfx::PointF(), |
| 3554 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3555 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3556 | false); |
| 3557 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3558 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3559 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3560 | gfx::PointF(), |
| 3561 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3562 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3563 | false); |
| 3564 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3565 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3566 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3567 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3568 | inputs.can_adjust_raster_scales = true; |
| 3569 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3570 | |
| 3571 | // Verify which render surfaces were created. |
| 3572 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3573 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3574 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3575 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 3576 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3577 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3578 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3579 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3580 | |
| 3581 | // Verify the render_surface_layer_list. |
| 3582 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3583 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3584 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3585 | // Even though the back facing surface LAYER gets culled, the other |
| 3586 | // descendants should still be added, so the SURFACE should not be culled. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3587 | EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3588 | |
| 3589 | // Verify root surface's layer list. |
| 3590 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3591 | 3u, |
| 3592 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3593 | EXPECT_EQ(front_facing_child->id(), |
| 3594 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3595 | ->render_surface() |
| 3596 | ->layer_list() |
| 3597 | .at(0) |
| 3598 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3599 | EXPECT_EQ(front_facing_surface->id(), |
| 3600 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3601 | ->render_surface() |
| 3602 | ->layer_list() |
| 3603 | .at(1) |
| 3604 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3605 | EXPECT_EQ(back_facing_surface->id(), |
| 3606 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3607 | ->render_surface() |
| 3608 | ->layer_list() |
| 3609 | .at(2) |
| 3610 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3611 | |
| 3612 | // Verify front_facing_surface's layer list. |
| 3613 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3614 | 2u, |
| 3615 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3616 | EXPECT_EQ(front_facing_surface->id(), |
| 3617 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3618 | ->render_surface() |
| 3619 | ->layer_list() |
| 3620 | .at(0) |
| 3621 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3622 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3623 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3624 | ->render_surface() |
| 3625 | ->layer_list() |
| 3626 | .at(1) |
| 3627 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3628 | |
| 3629 | // Verify back_facing_surface's layer list; its own layer should be culled |
| 3630 | // from the surface list. |
| 3631 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3632 | 1u, |
| 3633 | render_surface_layer_list.at(2)->render_surface()->layer_list().size()); |
| 3634 | EXPECT_EQ(front_facing_child_of_back_facing_surface->id(), |
| 3635 | render_surface_layer_list.at(2) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3636 | ->render_surface() |
| 3637 | ->layer_list() |
| 3638 | .at(0) |
| 3639 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3640 | } |
| 3641 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3642 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3643 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 3644 | // is used. |
| 3645 | |
| 3646 | const gfx::Transform identity_matrix; |
| 3647 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3648 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3649 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3650 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3651 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3652 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3653 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3654 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3655 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3656 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3657 | front_facing_child_of_front_facing_surface = |
| 3658 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3659 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3660 | back_facing_child_of_front_facing_surface = |
| 3661 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3662 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3663 | front_facing_child_of_back_facing_surface = |
| 3664 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3665 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3666 | back_facing_child_of_back_facing_surface = |
| 3667 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3668 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 = |
| 3669 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3670 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 = |
| 3671 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3672 | |
| 3673 | parent->AddChild(front_facing_child); |
| 3674 | parent->AddChild(back_facing_child); |
| 3675 | parent->AddChild(front_facing_surface); |
| 3676 | parent->AddChild(back_facing_surface); |
| 3677 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3678 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3679 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3680 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3681 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3682 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3683 | host->SetRootLayer(parent); |
| 3684 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3685 | // Nothing is double-sided |
| 3686 | front_facing_child->SetDoubleSided(false); |
| 3687 | back_facing_child->SetDoubleSided(false); |
| 3688 | front_facing_surface->SetDoubleSided(false); |
| 3689 | back_facing_surface->SetDoubleSided(false); |
| 3690 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3691 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3692 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3693 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3694 | |
| 3695 | gfx::Transform backface_matrix; |
| 3696 | backface_matrix.Translate(50.0, 50.0); |
| 3697 | backface_matrix.RotateAboutYAxis(180.0); |
| 3698 | backface_matrix.Translate(-50.0, -50.0); |
| 3699 | |
| 3700 | // Opacity will not force creation of render surfaces in this case because of |
| 3701 | // the preserve-3d transform style. Instead, an example of when a surface |
| 3702 | // would be created with preserve-3d is when there is a replica layer. |
| 3703 | front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get()); |
| 3704 | back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get()); |
| 3705 | |
| 3706 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 3707 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 3708 | // rendering context should use the transform with respect to that context. |
| 3709 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 3710 | // and (b) the layer's transform style is preserve-3d. |
| 3711 | SetLayerPropertiesForTesting(parent.get(), |
| 3712 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3713 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3714 | gfx::PointF(), |
| 3715 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3716 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3717 | false); // parent transform style is flat. |
| 3718 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3719 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3720 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3721 | gfx::PointF(), |
| 3722 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3723 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3724 | false); |
| 3725 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3726 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3727 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3728 | gfx::PointF(), |
| 3729 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3730 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3731 | false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3732 | // surface transform style is preserve-3d. |
| 3733 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3734 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3735 | gfx::Point3F(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3736 | gfx::PointF(), |
| 3737 | gfx::Size(100, 100), |
| 3738 | false, |
| 3739 | true); |
| 3740 | // surface transform style is preserve-3d. |
| 3741 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3742 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3743 | gfx::Point3F(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3744 | gfx::PointF(), |
| 3745 | gfx::Size(100, 100), |
| 3746 | false, |
| 3747 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3748 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3749 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3750 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3751 | gfx::PointF(), |
| 3752 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3753 | true, |
| 3754 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3755 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3756 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3757 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3758 | gfx::PointF(), |
| 3759 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3760 | true, |
| 3761 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3762 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3763 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3764 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3765 | gfx::PointF(), |
| 3766 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3767 | true, |
| 3768 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3769 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3770 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3771 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3772 | gfx::PointF(), |
| 3773 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3774 | true, |
| 3775 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3776 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3777 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3778 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3779 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3780 | inputs.can_adjust_raster_scales = true; |
| 3781 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3782 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3783 | // Verify which render surfaces were created and used. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3784 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3785 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3786 | EXPECT_TRUE(front_facing_surface->render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3787 | EXPECT_NE(back_facing_surface->render_target(), back_facing_surface); |
| 3788 | // We expect that a render_surface was created but not used. |
| 3789 | EXPECT_TRUE(back_facing_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3790 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3791 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3792 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3793 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3794 | |
| 3795 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 3796 | // culled. |
| 3797 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3798 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3799 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3800 | |
| 3801 | // Verify root surface's layer list. |
| 3802 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3803 | 2u, |
| 3804 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3805 | EXPECT_EQ(front_facing_child->id(), |
| 3806 | render_surface_layer_list.at(0) |
| 3807 | ->render_surface()->layer_list().at(0)->id()); |
| 3808 | EXPECT_EQ(front_facing_surface->id(), |
| 3809 | render_surface_layer_list.at(0) |
| 3810 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3811 | |
| 3812 | // Verify front_facing_surface's layer list. |
| 3813 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3814 | 2u, |
| 3815 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3816 | EXPECT_EQ(front_facing_surface->id(), |
| 3817 | render_surface_layer_list.at(1) |
| 3818 | ->render_surface()->layer_list().at(0)->id()); |
| 3819 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3820 | render_surface_layer_list.at(1) |
| 3821 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3822 | } |
| 3823 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3824 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3825 | // Verify that layers are appropriately culled when their back face is showing |
| 3826 | // and they are not double sided, while animations are going on. |
| 3827 | // |
| 3828 | // Layers that are animating do not get culled on the main thread, as their |
| 3829 | // transforms should be treated as "unknown" so we can not be sure that their |
| 3830 | // back face is really showing. |
| 3831 | const gfx::Transform identity_matrix; |
| 3832 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3833 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 3834 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3835 | scoped_refptr<LayerWithForcedDrawsContent> animating_surface = |
| 3836 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3837 | scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = |
| 3838 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3839 | scoped_refptr<LayerWithForcedDrawsContent> animating_child = |
| 3840 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3841 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3842 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3843 | |
| 3844 | parent->AddChild(child); |
| 3845 | parent->AddChild(animating_surface); |
| 3846 | animating_surface->AddChild(child_of_animating_surface); |
| 3847 | parent->AddChild(animating_child); |
| 3848 | parent->AddChild(child2); |
| 3849 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3850 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3851 | host->SetRootLayer(parent); |
| 3852 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3853 | // Nothing is double-sided |
| 3854 | child->SetDoubleSided(false); |
| 3855 | child2->SetDoubleSided(false); |
| 3856 | animating_surface->SetDoubleSided(false); |
| 3857 | child_of_animating_surface->SetDoubleSided(false); |
| 3858 | animating_child->SetDoubleSided(false); |
| 3859 | |
| 3860 | gfx::Transform backface_matrix; |
| 3861 | backface_matrix.Translate(50.0, 50.0); |
| 3862 | backface_matrix.RotateAboutYAxis(180.0); |
| 3863 | backface_matrix.Translate(-50.0, -50.0); |
| 3864 | |
| 3865 | // Make our render surface. |
| 3866 | animating_surface->SetForceRenderSurface(true); |
| 3867 | |
| 3868 | // Animate the transform on the render surface. |
| 3869 | AddAnimatedTransformToController( |
| 3870 | animating_surface->layer_animation_controller(), 10.0, 30, 0); |
| 3871 | // This is just an animating layer, not a surface. |
| 3872 | AddAnimatedTransformToController( |
| 3873 | animating_child->layer_animation_controller(), 10.0, 30, 0); |
| 3874 | |
| 3875 | SetLayerPropertiesForTesting(parent.get(), |
| 3876 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3877 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3878 | gfx::PointF(), |
| 3879 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3880 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3881 | false); |
| 3882 | SetLayerPropertiesForTesting(child.get(), |
| 3883 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3884 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3885 | gfx::PointF(), |
| 3886 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3887 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3888 | false); |
| 3889 | SetLayerPropertiesForTesting(animating_surface.get(), |
| 3890 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3891 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3892 | gfx::PointF(), |
| 3893 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3894 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3895 | false); |
| 3896 | SetLayerPropertiesForTesting(child_of_animating_surface.get(), |
| 3897 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3898 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3899 | gfx::PointF(), |
| 3900 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3901 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3902 | false); |
| 3903 | SetLayerPropertiesForTesting(animating_child.get(), |
| 3904 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3905 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3906 | gfx::PointF(), |
| 3907 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3908 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3909 | false); |
| 3910 | SetLayerPropertiesForTesting(child2.get(), |
| 3911 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3912 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3913 | gfx::PointF(), |
| 3914 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3915 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3916 | false); |
| 3917 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3918 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3919 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3920 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3921 | inputs.can_adjust_raster_scales = true; |
| 3922 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3923 | |
| 3924 | EXPECT_FALSE(child->render_surface()); |
| 3925 | EXPECT_TRUE(animating_surface->render_surface()); |
| 3926 | EXPECT_FALSE(child_of_animating_surface->render_surface()); |
| 3927 | EXPECT_FALSE(animating_child->render_surface()); |
| 3928 | EXPECT_FALSE(child2->render_surface()); |
| 3929 | |
| 3930 | // Verify that the animating_child and child_of_animating_surface were not |
| 3931 | // culled, but that child was. |
| 3932 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3933 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3934 | EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3935 | |
| 3936 | // The non-animating child be culled from the layer list for the parent render |
| 3937 | // surface. |
| 3938 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3939 | 3u, |
| 3940 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3941 | EXPECT_EQ(animating_surface->id(), |
| 3942 | render_surface_layer_list.at(0) |
| 3943 | ->render_surface()->layer_list().at(0)->id()); |
| 3944 | EXPECT_EQ(animating_child->id(), |
| 3945 | render_surface_layer_list.at(0) |
| 3946 | ->render_surface()->layer_list().at(1)->id()); |
| 3947 | EXPECT_EQ(child2->id(), |
| 3948 | render_surface_layer_list.at(0) |
| 3949 | ->render_surface()->layer_list().at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3950 | |
| 3951 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3952 | 2u, |
| 3953 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3954 | EXPECT_EQ(animating_surface->id(), |
| 3955 | render_surface_layer_list.at(1) |
| 3956 | ->render_surface()->layer_list().at(0)->id()); |
| 3957 | EXPECT_EQ(child_of_animating_surface->id(), |
| 3958 | render_surface_layer_list.at(1) |
| 3959 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3960 | |
| 3961 | EXPECT_FALSE(child2->visible_content_rect().IsEmpty()); |
| 3962 | |
| 3963 | // The animating layers should have a visible content rect that represents the |
| 3964 | // area of the front face that is within the viewport. |
| 3965 | EXPECT_EQ(animating_child->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3966 | gfx::Rect(animating_child->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3967 | EXPECT_EQ(animating_surface->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3968 | gfx::Rect(animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3969 | // And layers in the subtree of the animating layer should have valid visible |
| 3970 | // content rects also. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3971 | EXPECT_EQ(child_of_animating_surface->visible_content_rect(), |
| 3972 | gfx::Rect(child_of_animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3973 | } |
| 3974 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3975 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3976 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 3977 | // Verify the behavior of back-face culling for a render surface that is |
| 3978 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 3979 | |
| 3980 | const gfx::Transform identity_matrix; |
| 3981 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3982 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3983 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3984 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3985 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3986 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3987 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3988 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3989 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3990 | |
| 3991 | parent->AddChild(front_facing_surface); |
| 3992 | parent->AddChild(back_facing_surface); |
| 3993 | front_facing_surface->AddChild(child1); |
| 3994 | back_facing_surface->AddChild(child2); |
| 3995 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3996 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3997 | host->SetRootLayer(parent); |
| 3998 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3999 | // RenderSurfaces are not double-sided |
| 4000 | front_facing_surface->SetDoubleSided(false); |
| 4001 | back_facing_surface->SetDoubleSided(false); |
| 4002 | |
| 4003 | gfx::Transform backface_matrix; |
| 4004 | backface_matrix.Translate(50.0, 50.0); |
| 4005 | backface_matrix.RotateAboutYAxis(180.0); |
| 4006 | backface_matrix.Translate(-50.0, -50.0); |
| 4007 | |
| 4008 | SetLayerPropertiesForTesting(parent.get(), |
| 4009 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4010 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4011 | gfx::PointF(), |
| 4012 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4013 | false, |
| 4014 | true); // parent transform style is preserve3d. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4015 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 4016 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4017 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4018 | gfx::PointF(), |
| 4019 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4020 | true, |
| 4021 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4022 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4023 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4024 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4025 | gfx::PointF(), |
| 4026 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4027 | true, |
| 4028 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4029 | SetLayerPropertiesForTesting(child1.get(), |
| 4030 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4031 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4032 | gfx::PointF(), |
| 4033 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4034 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4035 | false); |
| 4036 | SetLayerPropertiesForTesting(child2.get(), |
| 4037 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4038 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4039 | gfx::PointF(), |
| 4040 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4041 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4042 | false); |
| 4043 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4044 | front_facing_surface->Set3dSortingContextId(1); |
| 4045 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4046 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4047 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4048 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4049 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4050 | inputs.can_adjust_raster_scales = true; |
| 4051 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4052 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4053 | // Verify which render surfaces were created and used. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4054 | EXPECT_TRUE(front_facing_surface->render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4055 | |
| 4056 | // We expect the render surface to have been created, but remain unused. |
| 4057 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 4058 | EXPECT_NE(back_facing_surface->render_target(), |
| 4059 | back_facing_surface); // because it should be culled |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4060 | EXPECT_FALSE(child1->render_surface()); |
| 4061 | EXPECT_FALSE(child2->render_surface()); |
| 4062 | |
| 4063 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 4064 | // culled. |
| 4065 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4066 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4067 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4068 | |
| 4069 | // Verify root surface's layer list. |
| 4070 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4071 | 1u, |
| 4072 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4073 | EXPECT_EQ(front_facing_surface->id(), |
| 4074 | render_surface_layer_list.at(0) |
| 4075 | ->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4076 | |
| 4077 | // Verify front_facing_surface's layer list. |
| 4078 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4079 | 2u, |
| 4080 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4081 | EXPECT_EQ(front_facing_surface->id(), |
| 4082 | render_surface_layer_list.at(1) |
| 4083 | ->render_surface()->layer_list().at(0)->id()); |
| 4084 | EXPECT_EQ(child1->id(), |
| 4085 | render_surface_layer_list.at(1) |
| 4086 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4087 | } |
| 4088 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4089 | class NoScaleContentLayer : public ContentLayer { |
| 4090 | public: |
| 4091 | static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
| 4092 | return make_scoped_refptr(new NoScaleContentLayer(client)); |
| 4093 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4094 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 4095 | void CalculateContentsScale(float ideal_contents_scale, |
| 4096 | float* contents_scale_x, |
| 4097 | float* contents_scale_y, |
| 4098 | gfx::Size* content_bounds) override { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4099 | // Skip over the ContentLayer to the base Layer class. |
| 4100 | Layer::CalculateContentsScale(ideal_contents_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4101 | contents_scale_x, |
| 4102 | contents_scale_y, |
| 4103 | content_bounds); |
| 4104 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4105 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4106 | protected: |
| 4107 | explicit NoScaleContentLayer(ContentLayerClient* client) |
| 4108 | : ContentLayer(client) {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 4109 | ~NoScaleContentLayer() override {} |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4110 | }; |
| 4111 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4112 | scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer( |
| 4113 | ContentLayerClient* delegate) { |
| 4114 | scoped_refptr<NoScaleContentLayer> to_return = |
| 4115 | NoScaleContentLayer::Create(delegate); |
| 4116 | to_return->SetIsDrawable(true); |
| 4117 | return to_return; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4118 | } |
| 4119 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4120 | TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4121 | // Verify draw and screen space transforms of layers not in a surface. |
| 4122 | MockContentLayerClient delegate; |
| 4123 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4124 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4125 | scoped_refptr<FakePictureLayer> parent = |
| 4126 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4127 | SetLayerPropertiesForTesting(parent.get(), |
| 4128 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4129 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4130 | gfx::PointF(), |
| 4131 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4132 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4133 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4134 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4135 | scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4136 | SetLayerPropertiesForTesting(child.get(), |
| 4137 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4138 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4139 | gfx::PointF(2.f, 2.f), |
| 4140 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4141 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4142 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4143 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4144 | scoped_refptr<FakePictureLayer> child_empty = |
| 4145 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4146 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4147 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4148 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4149 | gfx::PointF(2.f, 2.f), |
| 4150 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4151 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4152 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4153 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4154 | parent->AddChild(child); |
| 4155 | parent->AddChild(child_empty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4156 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4157 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4158 | host->SetRootLayer(parent); |
| 4159 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4160 | float device_scale_factor = 2.5f; |
| 4161 | float page_scale_factor = 1.f; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4162 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4163 | RenderSurfaceLayerList render_surface_layer_list; |
| 4164 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4165 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4166 | inputs.device_scale_factor = device_scale_factor; |
| 4167 | inputs.page_scale_factor = page_scale_factor; |
| 4168 | inputs.can_adjust_raster_scales = true; |
| 4169 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4170 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4171 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4172 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4173 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child_empty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4174 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4175 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4176 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4177 | // Verify parent transforms |
| 4178 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4179 | expected_parent_transform.Scale(device_scale_factor * page_scale_factor, |
| 4180 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4181 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4182 | parent->screen_space_transform()); |
| 4183 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4184 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4185 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4186 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4187 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4188 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4189 | gfx::RectF parent_draw_rect = |
| 4190 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4191 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4192 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4193 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4194 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4195 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4196 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4197 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4198 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4199 | // Verify child and child_empty transforms. They should match. |
| 4200 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4201 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4202 | expected_child_transform.Translate(child->position().x(), |
| 4203 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4204 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4205 | child->draw_transform()); |
| 4206 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4207 | child->screen_space_transform()); |
| 4208 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4209 | child_empty->draw_transform()); |
| 4210 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4211 | child_empty->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4212 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4213 | // Verify results of transformed child and child_empty rects. They should |
| 4214 | // match. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4215 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4216 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4217 | gfx::RectF child_draw_rect = |
| 4218 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4219 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4220 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4221 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4222 | gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( |
| 4223 | child_empty->draw_transform(), child_content_bounds); |
| 4224 | gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( |
| 4225 | child_empty->screen_space_transform(), child_content_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4226 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4227 | gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); |
| 4228 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4229 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4230 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
| 4231 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); |
| 4232 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4233 | } |
| 4234 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4235 | TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4236 | // Verify draw and screen space transforms of layers in a surface. |
| 4237 | MockContentLayerClient delegate; |
| 4238 | gfx::Transform identity_matrix; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4239 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4240 | gfx::Transform perspective_matrix; |
| 4241 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4242 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4243 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4244 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4245 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4246 | scoped_refptr<Layer> root = Layer::Create(); |
| 4247 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4248 | scoped_refptr<FakePictureLayer> parent = |
| 4249 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4250 | SetLayerPropertiesForTesting(parent.get(), |
| 4251 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4252 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4253 | gfx::PointF(), |
| 4254 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4255 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4256 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4257 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4258 | scoped_refptr<FakePictureLayer> perspective_surface = |
| 4259 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4260 | SetLayerPropertiesForTesting(perspective_surface.get(), |
| 4261 | perspective_matrix * scale_small_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4262 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4263 | gfx::PointF(2.f, 2.f), |
| 4264 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4265 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4266 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4267 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4268 | scoped_refptr<FakePictureLayer> scale_surface = |
| 4269 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4270 | SetLayerPropertiesForTesting(scale_surface.get(), |
| 4271 | scale_small_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4272 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4273 | gfx::PointF(2.f, 2.f), |
| 4274 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4275 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4276 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4277 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4278 | perspective_surface->SetForceRenderSurface(true); |
| 4279 | scale_surface->SetForceRenderSurface(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4280 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4281 | parent->AddChild(perspective_surface); |
| 4282 | parent->AddChild(scale_surface); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4283 | root->AddChild(parent); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4284 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4285 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4286 | host->SetRootLayer(root); |
| 4287 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4288 | float device_scale_factor = 2.5f; |
| 4289 | float page_scale_factor = 3.f; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4290 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4291 | RenderSurfaceLayerList render_surface_layer_list; |
| 4292 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4293 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 4294 | inputs.device_scale_factor = device_scale_factor; |
| 4295 | inputs.page_scale_factor = page_scale_factor; |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 4296 | inputs.page_scale_application_layer = root.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4297 | inputs.can_adjust_raster_scales = true; |
| 4298 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4299 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4300 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4301 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4302 | perspective_surface); |
| 4303 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4304 | // the nearest render target. Here this includes the layer transform as well |
| 4305 | // as the device and page scale factors. |
| 4306 | gfx::Transform transform = scale_small_matrix; |
| 4307 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4308 | device_scale_factor * page_scale_factor); |
| 4309 | gfx::Vector2dF scales = |
| 4310 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4311 | float max_2d_scale = std::max(scales.x(), scales.y()); |
| 4312 | EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface); |
| 4313 | |
| 4314 | // The ideal scale will draw 1:1 with its render target space along |
| 4315 | // the larger-scale axis. |
| 4316 | gfx::Vector2dF target_space_transform_scales = |
| 4317 | MathUtil::ComputeTransform2dScaleComponents( |
| 4318 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4319 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4320 | std::max(target_space_transform_scales.x(), |
| 4321 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4322 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4323 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4324 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4325 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4326 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4327 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4328 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
| 4329 | parent->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4330 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4331 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4332 | // with the screen, and then scaled during drawing. |
| 4333 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4334 | expected_perspective_surface_draw_transform.Translate( |
| 4335 | device_scale_factor * page_scale_factor * |
| 4336 | perspective_surface->position().x(), |
| 4337 | device_scale_factor * page_scale_factor * |
| 4338 | perspective_surface->position().y()); |
| 4339 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4340 | perspective_matrix); |
| 4341 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4342 | scale_small_matrix); |
| 4343 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4344 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4345 | device_scale_factor * page_scale_factor, |
| 4346 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4347 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4348 | expected_perspective_surface_draw_transform, |
| 4349 | perspective_surface->render_surface()->draw_transform()); |
| 4350 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4351 | expected_perspective_surface_layer_draw_transform, |
| 4352 | perspective_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4353 | } |
| 4354 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4355 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4356 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4357 | LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { |
| 4358 | // Verify draw and screen space transforms of layers not in a surface. |
| 4359 | MockContentLayerClient delegate; |
| 4360 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4361 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4362 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4363 | SetLayerPropertiesForTesting(parent.get(), |
| 4364 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4365 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4366 | gfx::PointF(), |
| 4367 | gfx::Size(133, 133), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4368 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4369 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4370 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4371 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 4372 | SetLayerPropertiesForTesting(child.get(), |
| 4373 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4374 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4375 | gfx::PointF(), |
| 4376 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4377 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4378 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4379 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4380 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4381 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4382 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4383 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4384 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4385 | gfx::PointF(), |
| 4386 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4387 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4388 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4389 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4390 | parent->AddChild(child); |
| 4391 | parent->AddChild(child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4392 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4393 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4394 | host->SetRootLayer(parent); |
| 4395 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4396 | float device_scale_factor = 1.7f; |
| 4397 | float page_scale_factor = 1.f; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4398 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4399 | RenderSurfaceLayerList render_surface_layer_list; |
| 4400 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4401 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4402 | inputs.device_scale_factor = device_scale_factor; |
| 4403 | inputs.page_scale_factor = page_scale_factor; |
| 4404 | inputs.page_scale_application_layer = parent.get(); |
| 4405 | inputs.can_adjust_raster_scales = true; |
| 4406 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4407 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4408 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4409 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4410 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4411 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4412 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4413 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4414 | // Verify parent transforms |
| 4415 | gfx::Transform expected_parent_transform; |
| 4416 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4417 | parent->screen_space_transform()); |
| 4418 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4419 | parent->draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4420 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4421 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4422 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4423 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4424 | gfx::RectF parent_draw_rect = |
| 4425 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4426 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4427 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4428 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4429 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4430 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4431 | expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width())); |
| 4432 | expected_parent_draw_rect.set_height( |
| 4433 | ceil(expected_parent_draw_rect.height())); |
| 4434 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4435 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4436 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4437 | // Verify child transforms |
| 4438 | gfx::Transform expected_child_transform; |
| 4439 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4440 | child->draw_transform()); |
| 4441 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4442 | child->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4443 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4444 | // Verify results of transformed child rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4445 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4446 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4447 | gfx::RectF child_draw_rect = |
| 4448 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4449 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4450 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4451 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4452 | gfx::RectF expected_child_draw_rect(child->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4453 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4454 | expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width())); |
| 4455 | expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height())); |
| 4456 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4457 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4458 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4459 | // Verify child_no_scale transforms |
| 4460 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 4461 | // All transforms operate on content rects. The child's content rect |
| 4462 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 4463 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 4464 | device_scale_factor); |
| 4465 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4466 | child_no_scale->draw_transform()); |
| 4467 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4468 | child_no_scale->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4469 | } |
| 4470 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4471 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4472 | TEST_F(LayerTreeHostCommonTest, ContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4473 | MockContentLayerClient delegate; |
| 4474 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4475 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4476 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4477 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4478 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4479 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4480 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4481 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4482 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4483 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4484 | scoped_refptr<Layer> root = Layer::Create(); |
| 4485 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4486 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4487 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4488 | SetLayerPropertiesForTesting(parent.get(), |
| 4489 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4490 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4491 | gfx::PointF(), |
| 4492 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4493 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4494 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4495 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4496 | scoped_refptr<ContentLayer> child_scale = |
| 4497 | CreateDrawableContentLayer(&delegate); |
| 4498 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4499 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4500 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4501 | gfx::PointF(2.f, 2.f), |
| 4502 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4503 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4504 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4505 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4506 | scoped_refptr<ContentLayer> child_empty = |
| 4507 | CreateDrawableContentLayer(&delegate); |
| 4508 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4509 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4510 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4511 | gfx::PointF(2.f, 2.f), |
| 4512 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4513 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4514 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4515 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4516 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4517 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4518 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4519 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4520 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4521 | gfx::PointF(12.f, 12.f), |
| 4522 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4523 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4524 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4525 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4526 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4527 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4528 | parent->AddChild(child_scale); |
| 4529 | parent->AddChild(child_empty); |
| 4530 | parent->AddChild(child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4531 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4532 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4533 | host->SetRootLayer(root); |
| 4534 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4535 | float device_scale_factor = 2.5f; |
| 4536 | float page_scale_factor = 1.f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4537 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4538 | { |
| 4539 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4540 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4541 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4542 | inputs.device_scale_factor = device_scale_factor; |
| 4543 | inputs.page_scale_factor = page_scale_factor; |
| 4544 | inputs.page_scale_application_layer = root.get(); |
| 4545 | inputs.can_adjust_raster_scales = true; |
| 4546 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4547 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4548 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4549 | initial_parent_scale, parent); |
| 4550 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4551 | initial_parent_scale * initial_child_scale, |
| 4552 | child_scale); |
| 4553 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4554 | initial_parent_scale * initial_child_scale, |
| 4555 | child_empty); |
| 4556 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4557 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4558 | // The parent is scaled up and shouldn't need to scale during draw. The |
| 4559 | // child that can scale its contents should also not need to scale during |
| 4560 | // draw. This shouldn't change if the child has empty bounds. The other |
| 4561 | // children should. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4562 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 4563 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
| 4564 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0)); |
| 4565 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1)); |
| 4566 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0)); |
| 4567 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4568 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 4569 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4570 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4571 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4572 | initial_parent_scale * initial_child_scale, |
| 4573 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4574 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4575 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4576 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 4577 | // updated using the initial transform as the raster scale. |
| 4578 | device_scale_factor = 2.25f; |
| 4579 | page_scale_factor = 1.25f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4580 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4581 | { |
| 4582 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4583 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4584 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4585 | inputs.device_scale_factor = device_scale_factor; |
| 4586 | inputs.page_scale_factor = page_scale_factor; |
| 4587 | inputs.page_scale_application_layer = root.get(); |
| 4588 | inputs.can_adjust_raster_scales = true; |
| 4589 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 4590 | |
| 4591 | EXPECT_CONTENTS_SCALE_EQ( |
| 4592 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4593 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4594 | initial_parent_scale * initial_child_scale, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4595 | child_scale); |
| 4596 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4597 | initial_parent_scale * initial_child_scale, |
| 4598 | child_empty); |
| 4599 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4600 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4601 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4602 | // 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] | 4603 | SkMScalar second_child_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4604 | child_scale_matrix.Scale(second_child_scale / initial_child_scale, |
| 4605 | second_child_scale / initial_child_scale); |
| 4606 | child_scale->SetTransform(child_scale_matrix); |
| 4607 | child_empty->SetTransform(child_scale_matrix); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [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] | d051820 | 2013-02-08 02:06:49 | [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, |
| 4621 | parent); |
| 4622 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4623 | child_scale); |
| 4624 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4625 | child_empty); |
| 4626 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4627 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4628 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4629 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 4630 | // updated, but still using 1.0 as the raster scale. |
| 4631 | device_scale_factor = 2.75f; |
| 4632 | page_scale_factor = 1.75f; |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4633 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4634 | { |
| 4635 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4636 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4637 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4638 | inputs.device_scale_factor = device_scale_factor; |
| 4639 | inputs.page_scale_factor = page_scale_factor; |
| 4640 | inputs.page_scale_application_layer = root.get(); |
| 4641 | inputs.can_adjust_raster_scales = true; |
| 4642 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4643 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4644 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4645 | initial_parent_scale, |
| 4646 | parent); |
| 4647 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4648 | child_scale); |
| 4649 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4650 | child_empty); |
| 4651 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4652 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4653 | } |
| 4654 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4655 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4656 | TEST_F(LayerTreeHostCommonTest, |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4657 | ContentsScale_LayerTransformsDontAffectContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4658 | MockContentLayerClient delegate; |
| 4659 | gfx::Transform identity_matrix; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4660 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4661 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4662 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4663 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4664 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4665 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4666 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4667 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4668 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4669 | scoped_refptr<Layer> root = Layer::Create(); |
| 4670 | root->SetBounds(gfx::Size(100, 100)); |
| 4671 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4672 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4673 | SetLayerPropertiesForTesting(parent.get(), |
| 4674 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4675 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4676 | gfx::PointF(), |
| 4677 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4678 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4679 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4680 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4681 | scoped_refptr<ContentLayer> child_scale = |
| 4682 | CreateDrawableContentLayer(&delegate); |
| 4683 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4684 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4685 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4686 | gfx::PointF(2.f, 2.f), |
| 4687 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4688 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4689 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4690 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4691 | scoped_refptr<ContentLayer> child_empty = |
| 4692 | CreateDrawableContentLayer(&delegate); |
| 4693 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4694 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4695 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4696 | gfx::PointF(2.f, 2.f), |
| 4697 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4698 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4699 | true); |
| 4700 | |
| 4701 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4702 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4703 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4704 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4705 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4706 | gfx::PointF(12.f, 12.f), |
| 4707 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4708 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4709 | true); |
| 4710 | |
| 4711 | root->AddChild(parent); |
| 4712 | |
| 4713 | parent->AddChild(child_scale); |
| 4714 | parent->AddChild(child_empty); |
| 4715 | parent->AddChild(child_no_scale); |
| 4716 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4717 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4718 | host->SetRootLayer(root); |
| 4719 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4720 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4721 | |
| 4722 | float device_scale_factor = 2.5f; |
| 4723 | float page_scale_factor = 1.f; |
| 4724 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4725 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4726 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4727 | inputs.device_scale_factor = device_scale_factor; |
| 4728 | inputs.page_scale_factor = page_scale_factor; |
| 4729 | inputs.page_scale_application_layer = root.get(), |
| 4730 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4731 | |
| 4732 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4733 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4734 | child_scale); |
| 4735 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4736 | child_empty); |
| 4737 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4738 | |
| 4739 | // Since the transform scale does not affect contents scale, it should affect |
| 4740 | // the draw transform instead. |
| 4741 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4742 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4743 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4744 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4745 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4746 | child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4747 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4748 | child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4749 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4750 | child_empty->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4751 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4752 | child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4753 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4754 | initial_parent_scale * initial_child_scale, |
| 4755 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4756 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4757 | initial_parent_scale * initial_child_scale, |
| 4758 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4759 | } |
| 4760 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4761 | TEST_F(LayerTreeHostCommonTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4762 | MockContentLayerClient delegate; |
| 4763 | gfx::Transform identity_matrix; |
| 4764 | |
| 4765 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4766 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4767 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4768 | |
| 4769 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4770 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4771 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4772 | |
| 4773 | scoped_refptr<Layer> root = Layer::Create(); |
| 4774 | root->SetBounds(gfx::Size(100, 100)); |
| 4775 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4776 | scoped_refptr<FakePictureLayer> parent = |
| 4777 | CreateDrawablePictureLayer(&delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4778 | SetLayerPropertiesForTesting(parent.get(), |
| 4779 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4780 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4781 | gfx::PointF(), |
| 4782 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4783 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4784 | true); |
| 4785 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4786 | scoped_refptr<FakePictureLayer> child_scale = |
| 4787 | CreateDrawablePictureLayer(&delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4788 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4789 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4790 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4791 | gfx::PointF(2.f, 2.f), |
| 4792 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4793 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4794 | true); |
| 4795 | |
| 4796 | root->AddChild(parent); |
| 4797 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4798 | parent->AddChild(child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4799 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4800 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4801 | host->SetRootLayer(root); |
| 4802 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4803 | float device_scale_factor = 2.5f; |
| 4804 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4805 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4806 | { |
| 4807 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4808 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4809 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4810 | inputs.device_scale_factor = device_scale_factor; |
| 4811 | inputs.page_scale_factor = page_scale_factor; |
| 4812 | inputs.page_scale_application_layer = root.get(); |
| 4813 | inputs.can_adjust_raster_scales = true; |
| 4814 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4815 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4816 | // The ideal scale is able to go below 1. |
| 4817 | float expected_ideal_scale = |
| 4818 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4819 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4820 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4821 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4822 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4823 | initial_parent_scale * initial_child_scale; |
| 4824 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4825 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4826 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4827 | } |
| 4828 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4829 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4830 | MockContentLayerClient delegate; |
| 4831 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4832 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4833 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4834 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4835 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4836 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4837 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4838 | SkMScalar initial_child_scale = 3.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4839 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4840 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4841 | scoped_refptr<Layer> root = Layer::Create(); |
| 4842 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4843 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4844 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4845 | SetLayerPropertiesForTesting(parent.get(), |
| 4846 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4847 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4848 | gfx::PointF(), |
| 4849 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4850 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4851 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4852 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4853 | scoped_refptr<ContentLayer> surface_scale = |
| 4854 | CreateDrawableContentLayer(&delegate); |
| 4855 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 4856 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4857 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4858 | gfx::PointF(2.f, 2.f), |
| 4859 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4860 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4861 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4862 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4863 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 4864 | CreateDrawableContentLayer(&delegate); |
| 4865 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 4866 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4867 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4868 | gfx::PointF(), |
| 4869 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4870 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4871 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4872 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4873 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 4874 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4875 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 4876 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4877 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4878 | gfx::PointF(), |
| 4879 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4880 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4881 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4882 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4883 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 4884 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4885 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 4886 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4887 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4888 | gfx::PointF(12.f, 12.f), |
| 4889 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4890 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4891 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4892 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4893 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 4894 | CreateDrawableContentLayer(&delegate); |
| 4895 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 4896 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4897 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4898 | gfx::PointF(), |
| 4899 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4900 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4901 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4902 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4903 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 4904 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4905 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 4906 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4907 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4908 | gfx::PointF(), |
| 4909 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4910 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4911 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4912 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4913 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4914 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4915 | parent->AddChild(surface_scale); |
| 4916 | parent->AddChild(surface_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4917 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4918 | surface_scale->SetForceRenderSurface(true); |
| 4919 | surface_scale->AddChild(surface_scale_child_scale); |
| 4920 | surface_scale->AddChild(surface_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4921 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4922 | surface_no_scale->SetForceRenderSurface(true); |
| 4923 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 4924 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4925 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4926 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4927 | host->SetRootLayer(root); |
| 4928 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4929 | SkMScalar device_scale_factor = 5; |
| 4930 | SkMScalar page_scale_factor = 7; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4931 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4932 | RenderSurfaceLayerList render_surface_layer_list; |
| 4933 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4934 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4935 | inputs.device_scale_factor = device_scale_factor; |
| 4936 | inputs.page_scale_factor = page_scale_factor; |
| 4937 | inputs.page_scale_application_layer = root.get(); |
| 4938 | inputs.can_adjust_raster_scales = true; |
| 4939 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 4940 | |
| 4941 | EXPECT_CONTENTS_SCALE_EQ( |
| 4942 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4943 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4944 | initial_parent_scale * initial_child_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4945 | surface_scale); |
| 4946 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale); |
| 4947 | EXPECT_CONTENTS_SCALE_EQ( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4948 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 4949 | initial_child_scale * initial_child_scale, |
| 4950 | surface_scale_child_scale); |
| 4951 | EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale); |
| 4952 | EXPECT_CONTENTS_SCALE_EQ( |
| 4953 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 4954 | initial_child_scale * initial_child_scale, |
| 4955 | surface_no_scale_child_scale); |
| 4956 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4957 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4958 | // The parent is scaled up and shouldn't need to scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4959 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 4960 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4961 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4962 | // RenderSurfaces should always be 1:1 with their target. |
| 4963 | EXPECT_FLOAT_EQ( |
| 4964 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4965 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4966 | EXPECT_FLOAT_EQ( |
| 4967 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4968 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4969 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4970 | // The surface_scale can apply contents scale so the layer shouldn't need to |
| 4971 | // scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4972 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 4973 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4974 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4975 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 4976 | // to scale during draw. |
| 4977 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4978 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4979 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4980 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4981 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4982 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 4983 | // to be scaled during draw. |
| 4984 | EXPECT_FLOAT_EQ( |
| 4985 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4986 | initial_child_scale * initial_child_scale, |
| 4987 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4988 | EXPECT_FLOAT_EQ( |
| 4989 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4990 | initial_child_scale * initial_child_scale, |
| 4991 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4992 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4993 | // RenderSurfaces should always be 1:1 with their target. |
| 4994 | EXPECT_FLOAT_EQ( |
| 4995 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4996 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4997 | EXPECT_FLOAT_EQ( |
| 4998 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4999 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5000 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5001 | // The surface_no_scale layer can not apply contents scale, so it needs to be |
| 5002 | // scaled during draw. |
| 5003 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5004 | initial_parent_scale * initial_child_scale, |
| 5005 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5006 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5007 | initial_parent_scale * initial_child_scale, |
| 5008 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5009 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5010 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 5011 | // to scale during draw. |
| 5012 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5013 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5014 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5015 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5016 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5017 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 5018 | // to be scaled during draw. |
| 5019 | EXPECT_FLOAT_EQ( |
| 5020 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5021 | initial_child_scale * initial_child_scale, |
| 5022 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5023 | EXPECT_FLOAT_EQ( |
| 5024 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5025 | initial_child_scale * initial_child_scale, |
| 5026 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5027 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5028 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5029 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5030 | TEST_F(LayerTreeHostCommonTest, |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5031 | ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5032 | MockContentLayerClient delegate; |
| 5033 | gfx::Transform identity_matrix; |
| 5034 | |
| 5035 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5036 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5037 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 5038 | |
| 5039 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5040 | SkMScalar initial_child_scale = 3.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5041 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 5042 | |
| 5043 | scoped_refptr<Layer> root = Layer::Create(); |
| 5044 | root->SetBounds(gfx::Size(100, 100)); |
| 5045 | |
| 5046 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 5047 | SetLayerPropertiesForTesting(parent.get(), |
| 5048 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5049 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5050 | gfx::PointF(), |
| 5051 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5052 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5053 | true); |
| 5054 | |
| 5055 | scoped_refptr<ContentLayer> surface_scale = |
| 5056 | CreateDrawableContentLayer(&delegate); |
| 5057 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 5058 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5059 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5060 | gfx::PointF(2.f, 2.f), |
| 5061 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5062 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5063 | true); |
| 5064 | |
| 5065 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 5066 | CreateDrawableContentLayer(&delegate); |
| 5067 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 5068 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5069 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5070 | gfx::PointF(), |
| 5071 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5072 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5073 | true); |
| 5074 | |
| 5075 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 5076 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5077 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 5078 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5079 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5080 | gfx::PointF(), |
| 5081 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5082 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5083 | true); |
| 5084 | |
| 5085 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 5086 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5087 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 5088 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5089 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5090 | gfx::PointF(12.f, 12.f), |
| 5091 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5092 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5093 | true); |
| 5094 | |
| 5095 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 5096 | CreateDrawableContentLayer(&delegate); |
| 5097 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 5098 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5099 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5100 | gfx::PointF(), |
| 5101 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5102 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5103 | true); |
| 5104 | |
| 5105 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 5106 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5107 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 5108 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5109 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5110 | gfx::PointF(), |
| 5111 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5112 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5113 | true); |
| 5114 | |
| 5115 | root->AddChild(parent); |
| 5116 | |
| 5117 | parent->AddChild(surface_scale); |
| 5118 | parent->AddChild(surface_no_scale); |
| 5119 | |
| 5120 | surface_scale->SetForceRenderSurface(true); |
| 5121 | surface_scale->AddChild(surface_scale_child_scale); |
| 5122 | surface_scale->AddChild(surface_scale_child_no_scale); |
| 5123 | |
| 5124 | surface_no_scale->SetForceRenderSurface(true); |
| 5125 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 5126 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
| 5127 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5128 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5129 | host->SetRootLayer(root); |
| 5130 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5131 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5132 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5133 | SkMScalar device_scale_factor = 5.0; |
| 5134 | SkMScalar page_scale_factor = 7.0; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5135 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5136 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5137 | inputs.device_scale_factor = device_scale_factor; |
| 5138 | inputs.page_scale_factor = page_scale_factor; |
| 5139 | inputs.page_scale_application_layer = root.get(); |
| 5140 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5141 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5142 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5143 | parent); |
| 5144 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5145 | surface_scale); |
| 5146 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale); |
| 5147 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5148 | surface_scale_child_scale); |
| 5149 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale); |
| 5150 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5151 | surface_no_scale_child_scale); |
| 5152 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale); |
| 5153 | |
| 5154 | // The parent is scaled up during draw, since its contents are not scaled by |
| 5155 | // the transform hierarchy. |
| 5156 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5157 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5158 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5159 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5160 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5161 | // 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] | 5162 | // by the transform hierarchy. |
| 5163 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5164 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5165 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5166 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5167 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5168 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5169 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5170 | // The surface_scale's RenderSurface is not scaled during draw, so the layer |
| 5171 | // needs to be scaled when drawing into its surface. |
| 5172 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 5173 | surface_scale->draw_transform().matrix().get(0, 0)); |
| 5174 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 5175 | surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5176 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5177 | // The surface_scale_child_scale is not scaled when drawing into its surface, |
| 5178 | // since its content bounds are scaled by the transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5179 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5180 | initial_child_scale * initial_child_scale * initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5181 | surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5182 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5183 | initial_child_scale * initial_child_scale * initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5184 | surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5185 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5186 | // The surface_scale_child_no_scale is scaled by the device scale, page scale |
| 5187 | // and transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5188 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5189 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5190 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5191 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5192 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5193 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5194 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5195 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5196 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5197 | // 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] | 5198 | // by the transform hierarchy. |
| 5199 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5200 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5201 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5202 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5203 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5204 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5205 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5206 | // The surface_no_scale layer has a fixed contents scale of 1, so it needs to |
| 5207 | // be scaled by the device and page scale factors. Its surface is already |
| 5208 | // scaled by the transform hierarchy so those don't need to scale the layer's |
| 5209 | // drawing. |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5210 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale * |
| 5211 | device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5212 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5213 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale * |
| 5214 | device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5215 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5216 | |
| 5217 | // The surface_no_scale_child_scale has its contents scaled by the page and |
| 5218 | // device scale factors, but needs to be scaled by the transform hierarchy |
| 5219 | // when drawing. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5220 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5221 | initial_parent_scale * initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5222 | surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5223 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5224 | initial_parent_scale * initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5225 | surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5226 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5227 | // The surface_no_scale_child_no_scale needs to be scaled by the device and |
| 5228 | // page scale factors and by any transform heirarchy below its target surface. |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5229 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5230 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5231 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5232 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5233 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5234 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5235 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5236 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5237 | } |
| 5238 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5239 | TEST_F(LayerTreeHostCommonTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5240 | MockContentLayerClient delegate; |
| 5241 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5242 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5243 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5244 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5245 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5246 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5247 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5248 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5249 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5250 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5251 | scoped_refptr<Layer> root = Layer::Create(); |
| 5252 | root->SetBounds(gfx::Size(100, 100)); |
| 5253 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5254 | scoped_refptr<FakePictureLayer> parent = |
| 5255 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5256 | SetLayerPropertiesForTesting(parent.get(), |
| 5257 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5258 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5259 | gfx::PointF(), |
| 5260 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5261 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5262 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5263 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5264 | scoped_refptr<FakePictureLayer> child_scale = |
| 5265 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5266 | SetLayerPropertiesForTesting(child_scale.get(), |
| 5267 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5268 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5269 | gfx::PointF(2.f, 2.f), |
| 5270 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5271 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5272 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5273 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5274 | root->AddChild(parent); |
| 5275 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5276 | parent->AddChild(child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5277 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5278 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5279 | host->SetRootLayer(root); |
| 5280 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5281 | { |
| 5282 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5283 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5284 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5285 | inputs.can_adjust_raster_scales = true; |
| 5286 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5287 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5288 | EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); |
| 5289 | // Animating layers compute ideal scale in the same way as when |
| 5290 | // they are static. |
| 5291 | EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, |
| 5292 | child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5293 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5294 | } |
| 5295 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5296 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5297 | TEST_F(LayerTreeHostCommonTest, |
| 5298 | ChangeInContentBoundsOrScaleTriggersPushProperties) { |
| 5299 | MockContentLayerClient delegate; |
| 5300 | scoped_refptr<Layer> root = Layer::Create(); |
| 5301 | scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate); |
| 5302 | root->AddChild(child); |
| 5303 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5304 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5305 | host->SetRootLayer(root); |
| 5306 | |
| 5307 | gfx::Transform identity_matrix; |
| 5308 | SetLayerPropertiesForTesting(root.get(), |
| 5309 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5310 | gfx::Point3F(), |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5311 | gfx::PointF(), |
| 5312 | gfx::Size(100, 100), |
| 5313 | true, |
| 5314 | false); |
| 5315 | SetLayerPropertiesForTesting(child.get(), |
| 5316 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5317 | gfx::Point3F(), |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5318 | gfx::PointF(), |
| 5319 | gfx::Size(100, 100), |
| 5320 | true, |
| 5321 | false); |
| 5322 | |
| 5323 | root->reset_needs_push_properties_for_testing(); |
| 5324 | child->reset_needs_push_properties_for_testing(); |
| 5325 | |
| 5326 | // This will change both layers' content bounds. |
| 5327 | ExecuteCalculateDrawProperties(root.get()); |
| 5328 | EXPECT_TRUE(root->needs_push_properties()); |
| 5329 | EXPECT_TRUE(child->needs_push_properties()); |
| 5330 | |
| 5331 | root->reset_needs_push_properties_for_testing(); |
| 5332 | child->reset_needs_push_properties_for_testing(); |
| 5333 | |
| 5334 | // This will change only the child layer's contents scale and content bounds, |
| 5335 | // since the root layer is not a ContentsScalingLayer. |
| 5336 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 5337 | EXPECT_FALSE(root->needs_push_properties()); |
| 5338 | EXPECT_TRUE(child->needs_push_properties()); |
| 5339 | |
| 5340 | root->reset_needs_push_properties_for_testing(); |
| 5341 | child->reset_needs_push_properties_for_testing(); |
| 5342 | |
| 5343 | // This will not change either layer's contents scale or content bounds. |
| 5344 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 5345 | EXPECT_FALSE(root->needs_push_properties()); |
| 5346 | EXPECT_FALSE(child->needs_push_properties()); |
| 5347 | } |
| 5348 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5349 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5350 | MockContentLayerClient delegate; |
| 5351 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5352 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5353 | scoped_refptr<FakePictureLayer> parent = |
| 5354 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5355 | SetLayerPropertiesForTesting(parent.get(), |
| 5356 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5357 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5358 | gfx::PointF(), |
| 5359 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5360 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5361 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5362 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5363 | scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5364 | SetLayerPropertiesForTesting(child.get(), |
| 5365 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5366 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5367 | gfx::PointF(2.f, 2.f), |
| 5368 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5369 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5370 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5371 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5372 | gfx::Transform replica_transform; |
| 5373 | replica_transform.Scale(1.0, -1.0); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5374 | scoped_refptr<FakePictureLayer> replica = |
| 5375 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5376 | SetLayerPropertiesForTesting(replica.get(), |
| 5377 | replica_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5378 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5379 | gfx::PointF(2.f, 2.f), |
| 5380 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5381 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5382 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5383 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5384 | // This layer should end up in the same surface as child, with the same draw |
| 5385 | // and screen space transforms. |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5386 | scoped_refptr<FakePictureLayer> duplicate_child_non_owner = |
| 5387 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5388 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 5389 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5390 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5391 | gfx::PointF(), |
| 5392 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5393 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5394 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5395 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5396 | parent->AddChild(child); |
| 5397 | child->AddChild(duplicate_child_non_owner); |
| 5398 | child->SetReplicaLayer(replica.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5399 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5400 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5401 | host->SetRootLayer(parent); |
| 5402 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5403 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5404 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5405 | float device_scale_factor = 1.5f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5406 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5407 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5408 | inputs.device_scale_factor = device_scale_factor; |
| 5409 | inputs.can_adjust_raster_scales = true; |
| 5410 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5411 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5412 | // We should have two render surfaces. The root's render surface and child's |
| 5413 | // render surface (it needs one because it has a replica layer). |
| 5414 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5415 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5416 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5417 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5418 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5419 | parent->screen_space_transform()); |
| 5420 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5421 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5422 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5423 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5424 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5425 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
| 5426 | child->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5427 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5428 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5429 | expected_screen_space_transform.Scale(device_scale_factor, |
| 5430 | device_scale_factor); |
| 5431 | expected_screen_space_transform.Translate(child->position().x(), |
| 5432 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5433 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 5434 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5435 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5436 | gfx::Transform expected_duplicate_child_draw_transform = |
| 5437 | child->draw_transform(); |
| 5438 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), |
| 5439 | duplicate_child_non_owner->draw_transform()); |
| 5440 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5441 | child->screen_space_transform(), |
| 5442 | duplicate_child_non_owner->screen_space_transform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 5443 | EXPECT_EQ(child->drawable_content_rect(), |
| 5444 | duplicate_child_non_owner->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5445 | EXPECT_EQ(child->content_bounds(), |
| 5446 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5447 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5448 | gfx::Transform expected_render_surface_draw_transform; |
| 5449 | expected_render_surface_draw_transform.Translate( |
| 5450 | device_scale_factor * child->position().x(), |
| 5451 | device_scale_factor * child->position().y()); |
| 5452 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 5453 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5454 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5455 | gfx::Transform expected_surface_draw_transform; |
| 5456 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 5457 | device_scale_factor * 2.f); |
| 5458 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 5459 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5460 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5461 | gfx::Transform expected_surface_screen_space_transform; |
| 5462 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 5463 | device_scale_factor * 2.f); |
| 5464 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5465 | expected_surface_screen_space_transform, |
| 5466 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5467 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5468 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5469 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 5470 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 5471 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5472 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5473 | expected_replica_draw_transform, |
| 5474 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5475 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5476 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5477 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 5478 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 5479 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5480 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5481 | expected_replica_screen_space_transform, |
| 5482 | child->render_surface()->replica_screen_space_transform()); |
| 5483 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5484 | expected_replica_screen_space_transform, |
| 5485 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5486 | } |
| 5487 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5488 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5489 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
| 5490 | MockContentLayerClient delegate; |
| 5491 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5492 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5493 | scoped_refptr<FakePictureLayer> parent = |
| 5494 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5495 | SetLayerPropertiesForTesting(parent.get(), |
| 5496 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5497 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5498 | gfx::PointF(), |
| 5499 | gfx::Size(33, 31), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5500 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5501 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5502 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5503 | scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5504 | SetLayerPropertiesForTesting(child.get(), |
| 5505 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5506 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5507 | gfx::PointF(), |
| 5508 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5509 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5510 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5511 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5512 | gfx::Transform replica_transform; |
| 5513 | replica_transform.Scale(1.0, -1.0); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5514 | scoped_refptr<FakePictureLayer> replica = |
| 5515 | CreateDrawablePictureLayer(&delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5516 | SetLayerPropertiesForTesting(replica.get(), |
| 5517 | replica_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5518 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5519 | gfx::PointF(), |
| 5520 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5521 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5522 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5523 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5524 | parent->AddChild(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5525 | child->SetReplicaLayer(replica.get()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5526 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5527 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5528 | host->SetRootLayer(parent); |
| 5529 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 5530 | float device_scale_factor = 1.7f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5531 | |
| 5532 | RenderSurfaceLayerList render_surface_layer_list; |
| 5533 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5534 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5535 | inputs.device_scale_factor = device_scale_factor; |
| 5536 | inputs.can_adjust_raster_scales = true; |
| 5537 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5538 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5539 | // We should have two render surfaces. The root's render surface and child's |
| 5540 | // render surface (it needs one because it has a replica layer). |
| 5541 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5542 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5543 | gfx::Transform identity_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5544 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5545 | child->render_surface()->draw_transform()); |
| 5546 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5547 | child->render_surface()->draw_transform()); |
| 5548 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5549 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5550 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5551 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5552 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5553 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5554 | expected_replica_draw_transform, |
| 5555 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5556 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5557 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5558 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5559 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5560 | expected_replica_screen_space_transform, |
| 5561 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5562 | } |
| 5563 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5564 | TEST_F(LayerTreeHostCommonTest, SubtreeSearch) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5565 | scoped_refptr<Layer> root = Layer::Create(); |
| 5566 | scoped_refptr<Layer> child = Layer::Create(); |
| 5567 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5568 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 5569 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5570 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5571 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 5572 | child->AddChild(grand_child.get()); |
| 5573 | child->SetMaskLayer(mask_layer.get()); |
| 5574 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5575 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5576 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5577 | host->SetRootLayer(root); |
| 5578 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5579 | int nonexistent_id = -1; |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5580 | EXPECT_EQ(root.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5581 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id())); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5582 | EXPECT_EQ(child.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5583 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id())); |
| 5584 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5585 | grand_child.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5586 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id())); |
| 5587 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5588 | mask_layer.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5589 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id())); |
| 5590 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5591 | replica_layer.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5592 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id())); |
| 5593 | EXPECT_EQ( |
| 5594 | 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5595 | } |
| 5596 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5597 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5598 | scoped_refptr<Layer> root = Layer::Create(); |
| 5599 | scoped_refptr<Layer> child = Layer::Create(); |
| 5600 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 5601 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5602 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5603 | const gfx::Transform identity_matrix; |
| 5604 | SetLayerPropertiesForTesting(root.get(), |
| 5605 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5606 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5607 | gfx::PointF(), |
| 5608 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5609 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5610 | false); |
| 5611 | SetLayerPropertiesForTesting(child.get(), |
| 5612 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5613 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5614 | gfx::PointF(), |
| 5615 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5616 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5617 | false); |
| 5618 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5619 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5620 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5621 | gfx::PointF(), |
| 5622 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5623 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5624 | false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5625 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5626 | root->AddChild(child); |
| 5627 | child->AddChild(grand_child); |
| 5628 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5629 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5630 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5631 | host->SetRootLayer(root); |
| 5632 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5633 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5634 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5635 | EXPECT_FALSE(child->render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5636 | } |
| 5637 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5638 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5639 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5640 | TestSharedBitmapManager shared_bitmap_manager; |
| 5641 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5642 | host_impl.CreatePendingTree(); |
| 5643 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5644 | |
| 5645 | const gfx::Transform identity_matrix; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5646 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5647 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5648 | false); |
| 5649 | root->SetDrawsContent(true); |
| 5650 | |
| 5651 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5652 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5653 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5654 | false); |
| 5655 | child->SetDrawsContent(true); |
| 5656 | child->SetOpacity(0.0f); |
| 5657 | |
| 5658 | // Add opacity animation. |
| 5659 | AddOpacityTransitionToController( |
| 5660 | child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false); |
| 5661 | |
| 5662 | root->AddChild(child.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5663 | root->SetHasRenderSurface(true); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5664 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5665 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5666 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5667 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5668 | inputs.can_adjust_raster_scales = true; |
| 5669 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5670 | |
| 5671 | // We should have one render surface and two layers. The child |
| 5672 | // layer should be included even though it is transparent. |
| 5673 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5674 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 5675 | } |
| 5676 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5677 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5678 | class LCDTextTest |
| 5679 | : public LayerTreeHostCommonTestBase, |
| 5680 | public testing::TestWithParam<LCDTextTestParam> { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5681 | protected: |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 5682 | void SetUp() override { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5683 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5684 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5685 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5686 | root_ = Layer::Create(); |
| 5687 | child_ = Layer::Create(); |
| 5688 | grand_child_ = Layer::Create(); |
| 5689 | child_->AddChild(grand_child_.get()); |
| 5690 | root_->AddChild(child_.get()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5691 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5692 | root_->SetContentsOpaque(true); |
| 5693 | child_->SetContentsOpaque(true); |
| 5694 | grand_child_->SetContentsOpaque(true); |
| 5695 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5696 | gfx::Transform identity_matrix; |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5697 | SetLayerPropertiesForTesting(root_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5698 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5699 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5700 | gfx::PointF(), |
| 5701 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5702 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5703 | false); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5704 | SetLayerPropertiesForTesting(child_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5705 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5706 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5707 | gfx::PointF(), |
| 5708 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5709 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5710 | false); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5711 | SetLayerPropertiesForTesting(grand_child_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5712 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5713 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5714 | gfx::PointF(), |
| 5715 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5716 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5717 | false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5718 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5719 | child_->SetForceRenderSurface(std::tr1::get<2>(GetParam())); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5720 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5721 | host_ = CreateFakeLayerTreeHost(); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5722 | host_->SetRootLayer(root_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5723 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5724 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5725 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5726 | bool layers_always_allowed_lcd_text_; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5727 | scoped_ptr<FakeLayerTreeHost> host_; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5728 | scoped_refptr<Layer> root_; |
| 5729 | scoped_refptr<Layer> child_; |
| 5730 | scoped_refptr<Layer> grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5731 | }; |
| 5732 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5733 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5734 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5735 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5736 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5737 | // Case 1: Identity transform. |
| 5738 | gfx::Transform identity_matrix; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5739 | ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5740 | layers_always_allowed_lcd_text_); |
| 5741 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5742 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5743 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5744 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5745 | // Case 2: Integral translation. |
| 5746 | gfx::Transform integral_translation; |
| 5747 | integral_translation.Translate(1.0, 2.0); |
| 5748 | child_->SetTransform(integral_translation); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5749 | ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5750 | layers_always_allowed_lcd_text_); |
| 5751 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5752 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5753 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5754 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5755 | // Case 3: Non-integral translation. |
| 5756 | gfx::Transform non_integral_translation; |
| 5757 | non_integral_translation.Translate(1.5, 2.5); |
| 5758 | child_->SetTransform(non_integral_translation); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5759 | ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5760 | layers_always_allowed_lcd_text_); |
| 5761 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5762 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5763 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5764 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5765 | // Case 4: Rotation. |
| 5766 | gfx::Transform rotation; |
| 5767 | rotation.Rotate(10.0); |
| 5768 | child_->SetTransform(rotation); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5769 | ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5770 | layers_always_allowed_lcd_text_); |
| 5771 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5772 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5773 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5774 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5775 | // Case 5: Scale. |
| 5776 | gfx::Transform scale; |
| 5777 | scale.Scale(2.0, 2.0); |
| 5778 | child_->SetTransform(scale); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5779 | ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5780 | layers_always_allowed_lcd_text_); |
| 5781 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5782 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5783 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5784 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5785 | // Case 6: Skew. |
| 5786 | gfx::Transform skew; |
| 5787 | skew.SkewX(10.0); |
| 5788 | child_->SetTransform(skew); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5789 | ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5790 | layers_always_allowed_lcd_text_); |
| 5791 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5792 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5793 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5794 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5795 | // Case 7: Translucent. |
| 5796 | child_->SetTransform(identity_matrix); |
| 5797 | child_->SetOpacity(0.5f); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5798 | ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5799 | layers_always_allowed_lcd_text_); |
| 5800 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5801 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5802 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5803 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5804 | // Case 8: Sanity check: restore transform and opacity. |
| 5805 | child_->SetTransform(identity_matrix); |
| 5806 | child_->SetOpacity(1.f); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5807 | ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5808 | layers_always_allowed_lcd_text_); |
| 5809 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5810 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5811 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5812 | |
| 5813 | // Case 9: Non-opaque content. |
| 5814 | child_->SetContentsOpaque(false); |
| 5815 | ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5816 | layers_always_allowed_lcd_text_); |
| 5817 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5818 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5819 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
| 5820 | |
| 5821 | // Case 10: Sanity check: restore content opaqueness. |
| 5822 | child_->SetContentsOpaque(true); |
| 5823 | ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5824 | layers_always_allowed_lcd_text_); |
| 5825 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5826 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5827 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5828 | } |
| 5829 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5830 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5831 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5832 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5833 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5834 | ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5835 | layers_always_allowed_lcd_text_); |
| 5836 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5837 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5838 | EXPECT_EQ(expect_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 | // Add opacity animation. |
| 5841 | child_->SetOpacity(0.9f); |
| 5842 | AddOpacityTransitionToController( |
| 5843 | child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5844 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5845 | ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, |
| 5846 | layers_always_allowed_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5847 | // Text AA should not be adjusted while animation is active. |
| 5848 | // Make sure LCD text AA setting remains unchanged. |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5849 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5850 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5851 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5852 | } |
| 5853 | |
| 5854 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5855 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5856 | testing::Combine(testing::Bool(), |
| 5857 | testing::Bool(), |
| 5858 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5859 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5860 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5861 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5862 | TestSharedBitmapManager shared_bitmap_manager; |
| 5863 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5864 | host_impl.CreatePendingTree(); |
| 5865 | const gfx::Transform identity_matrix; |
| 5866 | |
| 5867 | scoped_refptr<Layer> root = Layer::Create(); |
| 5868 | SetLayerPropertiesForTesting(root.get(), |
| 5869 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5870 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5871 | gfx::PointF(), |
| 5872 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5873 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5874 | false); |
| 5875 | root->SetIsDrawable(true); |
| 5876 | |
| 5877 | scoped_refptr<Layer> child = Layer::Create(); |
| 5878 | SetLayerPropertiesForTesting(child.get(), |
| 5879 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5880 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5881 | gfx::PointF(), |
| 5882 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5883 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5884 | false); |
| 5885 | child->SetIsDrawable(true); |
| 5886 | |
| 5887 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5888 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5889 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5890 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5891 | gfx::PointF(), |
| 5892 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5893 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5894 | false); |
| 5895 | grand_child->SetIsDrawable(true); |
| 5896 | grand_child->SetHideLayerAndSubtree(true); |
| 5897 | |
| 5898 | child->AddChild(grand_child); |
| 5899 | root->AddChild(child); |
| 5900 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5901 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5902 | host->SetRootLayer(root); |
| 5903 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5904 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5905 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5906 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5907 | inputs.can_adjust_raster_scales = true; |
| 5908 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5909 | |
| 5910 | // We should have one render surface and two layers. The grand child has |
| 5911 | // hidden itself. |
| 5912 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5913 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5914 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 5915 | EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5916 | } |
| 5917 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5918 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5919 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5920 | TestSharedBitmapManager shared_bitmap_manager; |
| 5921 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5922 | host_impl.CreatePendingTree(); |
| 5923 | const gfx::Transform identity_matrix; |
| 5924 | |
| 5925 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5926 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5927 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5928 | false); |
| 5929 | root->SetDrawsContent(true); |
| 5930 | |
| 5931 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5932 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5933 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5934 | false); |
| 5935 | child->SetDrawsContent(true); |
| 5936 | |
| 5937 | scoped_ptr<LayerImpl> grand_child = |
| 5938 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5939 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 5940 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 5941 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5942 | grand_child->SetDrawsContent(true); |
| 5943 | grand_child->SetHideLayerAndSubtree(true); |
| 5944 | |
| 5945 | child->AddChild(grand_child.Pass()); |
| 5946 | root->AddChild(child.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5947 | root->SetHasRenderSurface(true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5948 | |
| 5949 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5950 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5951 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5952 | inputs.can_adjust_raster_scales = true; |
| 5953 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5954 | |
| 5955 | // We should have one render surface and two layers. The grand child has |
| 5956 | // hidden itself. |
| 5957 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5958 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5959 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
| 5960 | EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5961 | } |
| 5962 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5963 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5964 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5965 | TestSharedBitmapManager shared_bitmap_manager; |
| 5966 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5967 | host_impl.CreatePendingTree(); |
| 5968 | const gfx::Transform identity_matrix; |
| 5969 | |
| 5970 | scoped_refptr<Layer> root = Layer::Create(); |
| 5971 | SetLayerPropertiesForTesting(root.get(), |
| 5972 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5973 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5974 | gfx::PointF(), |
| 5975 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5976 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5977 | false); |
| 5978 | root->SetIsDrawable(true); |
| 5979 | |
| 5980 | scoped_refptr<Layer> child = Layer::Create(); |
| 5981 | SetLayerPropertiesForTesting(child.get(), |
| 5982 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5983 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5984 | gfx::PointF(), |
| 5985 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5986 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5987 | false); |
| 5988 | child->SetIsDrawable(true); |
| 5989 | child->SetHideLayerAndSubtree(true); |
| 5990 | |
| 5991 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5992 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5993 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5994 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5995 | gfx::PointF(), |
| 5996 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5997 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5998 | false); |
| 5999 | grand_child->SetIsDrawable(true); |
| 6000 | |
| 6001 | child->AddChild(grand_child); |
| 6002 | root->AddChild(child); |
| 6003 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6004 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6005 | host->SetRootLayer(root); |
| 6006 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6007 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6008 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6009 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6010 | inputs.can_adjust_raster_scales = true; |
| 6011 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6012 | |
| 6013 | // We should have one render surface and one layers. The child has |
| 6014 | // hidden itself and the grand child. |
| 6015 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6016 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6017 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6018 | } |
| 6019 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6020 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6021 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6022 | TestSharedBitmapManager shared_bitmap_manager; |
| 6023 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6024 | host_impl.CreatePendingTree(); |
| 6025 | const gfx::Transform identity_matrix; |
| 6026 | |
| 6027 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6028 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 6029 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6030 | true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6031 | root->SetDrawsContent(true); |
| 6032 | |
| 6033 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6034 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 6035 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6036 | false); |
| 6037 | child->SetDrawsContent(true); |
| 6038 | child->SetHideLayerAndSubtree(true); |
| 6039 | |
| 6040 | scoped_ptr<LayerImpl> grand_child = |
| 6041 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6042 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 6043 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6044 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6045 | grand_child->SetDrawsContent(true); |
| 6046 | |
| 6047 | child->AddChild(grand_child.Pass()); |
| 6048 | root->AddChild(child.Pass()); |
| 6049 | |
| 6050 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6051 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6052 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6053 | inputs.can_adjust_raster_scales = true; |
| 6054 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6055 | |
| 6056 | // We should have one render surface and one layers. The child has |
| 6057 | // hidden itself and the grand child. |
| 6058 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6059 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6060 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6061 | } |
| 6062 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6063 | void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 6064 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6065 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6066 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6067 | TestSharedBitmapManager shared_bitmap_manager; |
| 6068 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6069 | host_impl.CreatePendingTree(); |
| 6070 | const gfx::Transform identity_matrix; |
| 6071 | |
| 6072 | scoped_refptr<Layer> root = Layer::Create(); |
| 6073 | SetLayerPropertiesForTesting(root.get(), |
| 6074 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6075 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6076 | gfx::PointF(), |
| 6077 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6078 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6079 | false); |
| 6080 | root->SetIsDrawable(true); |
| 6081 | |
| 6082 | scoped_refptr<Layer> copy_grand_parent = Layer::Create(); |
| 6083 | SetLayerPropertiesForTesting(copy_grand_parent.get(), |
| 6084 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6085 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6086 | gfx::PointF(), |
| 6087 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6088 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6089 | false); |
| 6090 | copy_grand_parent->SetIsDrawable(true); |
| 6091 | |
| 6092 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 6093 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 6094 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6095 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6096 | gfx::PointF(), |
| 6097 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6098 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6099 | false); |
| 6100 | copy_parent->SetIsDrawable(true); |
| 6101 | copy_parent->SetForceRenderSurface(true); |
| 6102 | |
| 6103 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 6104 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 6105 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6106 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6107 | gfx::PointF(), |
| 6108 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6109 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6110 | false); |
| 6111 | copy_layer->SetIsDrawable(true); |
| 6112 | |
| 6113 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 6114 | SetLayerPropertiesForTesting(copy_child.get(), |
| 6115 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6116 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6117 | gfx::PointF(), |
| 6118 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6119 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6120 | false); |
| 6121 | copy_child->SetIsDrawable(true); |
| 6122 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6123 | scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create(); |
| 6124 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
| 6125 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6126 | gfx::Point3F(), |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6127 | gfx::PointF(), |
| 6128 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6129 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6130 | false); |
| 6131 | copy_grand_parent_sibling_before->SetIsDrawable(true); |
| 6132 | |
| 6133 | scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create(); |
| 6134 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
| 6135 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6136 | gfx::Point3F(), |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6137 | gfx::PointF(), |
| 6138 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6139 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6140 | false); |
| 6141 | copy_grand_parent_sibling_after->SetIsDrawable(true); |
| 6142 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6143 | copy_layer->AddChild(copy_child); |
| 6144 | copy_parent->AddChild(copy_layer); |
| 6145 | copy_grand_parent->AddChild(copy_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6146 | root->AddChild(copy_grand_parent_sibling_before); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6147 | root->AddChild(copy_grand_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6148 | root->AddChild(copy_grand_parent_sibling_after); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6149 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6150 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6151 | host->SetRootLayer(root); |
| 6152 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6153 | // Hide the copy_grand_parent and its subtree. But make a copy request in that |
| 6154 | // hidden subtree on copy_layer. |
| 6155 | copy_grand_parent->SetHideLayerAndSubtree(true); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6156 | copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true); |
| 6157 | copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6158 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 6159 | base::Bind(&EmptyCopyOutputCallback))); |
| 6160 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 6161 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6162 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6163 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6164 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6165 | inputs.can_adjust_raster_scales = true; |
| 6166 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6167 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6168 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request); |
| 6169 | EXPECT_TRUE(copy_grand_parent->draw_properties(). |
| 6170 | layer_or_descendant_has_copy_request); |
| 6171 | EXPECT_TRUE(copy_parent->draw_properties(). |
| 6172 | layer_or_descendant_has_copy_request); |
| 6173 | EXPECT_TRUE(copy_layer->draw_properties(). |
| 6174 | layer_or_descendant_has_copy_request); |
| 6175 | EXPECT_FALSE(copy_child->draw_properties(). |
| 6176 | layer_or_descendant_has_copy_request); |
| 6177 | EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties(). |
| 6178 | layer_or_descendant_has_copy_request); |
| 6179 | EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties(). |
| 6180 | layer_or_descendant_has_copy_request); |
| 6181 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6182 | // We should have three render surfaces, one for the root, one for the parent |
| 6183 | // since it owns a surface, and one for the copy_layer. |
| 6184 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6185 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 6186 | EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id()); |
| 6187 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6188 | |
| 6189 | // The root render surface should have 2 contributing layers. The |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6190 | // copy_grand_parent is hidden along with its siblings, but the copy_parent |
| 6191 | // will appear since something in its subtree needs to be drawn for a copy |
| 6192 | // request. |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6193 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6194 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 6195 | EXPECT_EQ(copy_parent->id(), |
| 6196 | root->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6197 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 6198 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6199 | // appear in its list, since it needs to be drawn for the copy request. |
| 6200 | ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size()); |
| 6201 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6202 | copy_parent->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6203 | |
| 6204 | // The copy_layer's render surface should have two contributing layers. |
| 6205 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 6206 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6207 | copy_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6208 | EXPECT_EQ(copy_child->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6209 | copy_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6210 | } |
| 6211 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6212 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6213 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6214 | TestSharedBitmapManager shared_bitmap_manager; |
| 6215 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6216 | host_impl.CreatePendingTree(); |
| 6217 | const gfx::Transform identity_matrix; |
| 6218 | |
| 6219 | scoped_refptr<Layer> root = Layer::Create(); |
| 6220 | SetLayerPropertiesForTesting(root.get(), |
| 6221 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6222 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6223 | gfx::PointF(), |
| 6224 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6225 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6226 | false); |
| 6227 | root->SetIsDrawable(true); |
| 6228 | |
| 6229 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 6230 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 6231 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6232 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6233 | gfx::PointF(), |
| 6234 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6235 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6236 | false); |
| 6237 | copy_parent->SetIsDrawable(true); |
| 6238 | copy_parent->SetMasksToBounds(true); |
| 6239 | |
| 6240 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 6241 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 6242 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6243 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6244 | gfx::PointF(), |
| 6245 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6246 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6247 | false); |
| 6248 | copy_layer->SetIsDrawable(true); |
| 6249 | |
| 6250 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 6251 | SetLayerPropertiesForTesting(copy_child.get(), |
| 6252 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6253 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6254 | gfx::PointF(), |
| 6255 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6256 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6257 | false); |
| 6258 | copy_child->SetIsDrawable(true); |
| 6259 | |
| 6260 | copy_layer->AddChild(copy_child); |
| 6261 | copy_parent->AddChild(copy_layer); |
| 6262 | root->AddChild(copy_parent); |
| 6263 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6264 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6265 | host->SetRootLayer(root); |
| 6266 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6267 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 6268 | base::Bind(&EmptyCopyOutputCallback))); |
| 6269 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 6270 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6271 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6272 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6273 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6274 | inputs.can_adjust_raster_scales = true; |
| 6275 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6276 | |
| 6277 | // We should have one render surface, as the others are clipped out. |
| 6278 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6279 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6280 | |
| 6281 | // The root render surface should only have 1 contributing layer, since the |
| 6282 | // other layers are empty/clipped away. |
| 6283 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6284 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6285 | } |
| 6286 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6287 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
| 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] | 11a07b10 | 2013-07-24 17:33:19 | [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] | 11a07b10 | 2013-07-24 17:33:19 | [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] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6301 | false); |
| 6302 | root->SetIsDrawable(true); |
| 6303 | |
| 6304 | // The surface is moved slightly outside of the viewport. |
| 6305 | scoped_refptr<Layer> surface = Layer::Create(); |
| 6306 | SetLayerPropertiesForTesting(surface.get(), |
| 6307 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6308 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6309 | gfx::PointF(-10, -20), |
| 6310 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6311 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6312 | false); |
| 6313 | surface->SetForceRenderSurface(true); |
| 6314 | |
| 6315 | scoped_refptr<Layer> surface_child = Layer::Create(); |
| 6316 | SetLayerPropertiesForTesting(surface_child.get(), |
| 6317 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6318 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6319 | gfx::PointF(), |
| 6320 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6321 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6322 | false); |
| 6323 | surface_child->SetIsDrawable(true); |
| 6324 | |
| 6325 | surface->AddChild(surface_child); |
| 6326 | root->AddChild(surface); |
| 6327 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6328 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6329 | host->SetRootLayer(root); |
| 6330 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6331 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6332 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6333 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6334 | inputs.can_adjust_raster_scales = true; |
| 6335 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6336 | |
| 6337 | // The visible_content_rect for the |surface_child| should not be clipped by |
| 6338 | // the viewport. |
| 6339 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 6340 | surface_child->visible_content_rect().ToString()); |
| 6341 | } |
| 6342 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6343 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 6344 | // Ensure that a transform between the layer and its render surface is not a |
| 6345 | // problem. Constructs the following layer tree. |
| 6346 | // |
| 6347 | // root (a render surface) |
| 6348 | // + render_surface |
| 6349 | // + clip_parent (scaled) |
| 6350 | // + intervening_clipping_layer |
| 6351 | // + clip_child |
| 6352 | // |
| 6353 | // The render surface should be resized correctly and the clip child should |
| 6354 | // inherit the right clip rect. |
| 6355 | scoped_refptr<Layer> root = Layer::Create(); |
| 6356 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 6357 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6358 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6359 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6360 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6361 | |
| 6362 | root->AddChild(render_surface); |
| 6363 | render_surface->AddChild(clip_parent); |
| 6364 | clip_parent->AddChild(intervening); |
| 6365 | intervening->AddChild(clip_child); |
| 6366 | |
| 6367 | clip_child->SetClipParent(clip_parent.get()); |
| 6368 | |
| 6369 | intervening->SetMasksToBounds(true); |
| 6370 | clip_parent->SetMasksToBounds(true); |
| 6371 | |
| 6372 | render_surface->SetForceRenderSurface(true); |
| 6373 | |
| 6374 | gfx::Transform scale_transform; |
| 6375 | scale_transform.Scale(2, 2); |
| 6376 | |
| 6377 | gfx::Transform identity_transform; |
| 6378 | |
| 6379 | SetLayerPropertiesForTesting(root.get(), |
| 6380 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6381 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6382 | gfx::PointF(), |
| 6383 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6384 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6385 | false); |
| 6386 | SetLayerPropertiesForTesting(render_surface.get(), |
| 6387 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6388 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6389 | gfx::PointF(), |
| 6390 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6391 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6392 | false); |
| 6393 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6394 | scale_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6395 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6396 | gfx::PointF(1.f, 1.f), |
| 6397 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6398 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6399 | false); |
| 6400 | SetLayerPropertiesForTesting(intervening.get(), |
| 6401 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6402 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6403 | gfx::PointF(1.f, 1.f), |
| 6404 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6405 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6406 | false); |
| 6407 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6408 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6409 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6410 | gfx::PointF(1.f, 1.f), |
| 6411 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6412 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6413 | false); |
| 6414 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6415 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6416 | host->SetRootLayer(root); |
| 6417 | |
| 6418 | ExecuteCalculateDrawProperties(root.get()); |
| 6419 | |
| 6420 | ASSERT_TRUE(root->render_surface()); |
| 6421 | ASSERT_TRUE(render_surface->render_surface()); |
| 6422 | |
| 6423 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 6424 | // by the intervening clip layer. |
| 6425 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
| 6426 | clip_parent->clip_rect().ToString()); |
| 6427 | ASSERT_EQ(clip_parent->clip_rect().ToString(), |
| 6428 | clip_child->clip_rect().ToString()); |
| 6429 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(), |
| 6430 | intervening->clip_rect().ToString()); |
| 6431 | |
| 6432 | // Ensure that the render surface reports a content rect that has been grown |
| 6433 | // to accomodate for the clip child. |
| 6434 | ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(), |
| 6435 | render_surface->render_surface()->content_rect().ToString()); |
| 6436 | |
| 6437 | // The above check implies the two below, but they nicely demonstrate that |
| 6438 | // we've grown, despite the intervening layer's clip. |
| 6439 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 6440 | render_surface->render_surface()->content_rect())); |
| 6441 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 6442 | render_surface->render_surface()->content_rect())); |
| 6443 | } |
| 6444 | |
| 6445 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 6446 | // Ensure that intervening render surfaces are not a problem in the basic |
| 6447 | // case. In the following tree, both render surfaces should be resized to |
| 6448 | // accomodate for the clip child, despite an intervening clip. |
| 6449 | // |
| 6450 | // root (a render surface) |
| 6451 | // + clip_parent (masks to bounds) |
| 6452 | // + render_surface1 (sets opacity) |
| 6453 | // + intervening (masks to bounds) |
| 6454 | // + render_surface2 (also sets opacity) |
| 6455 | // + clip_child |
| 6456 | // |
| 6457 | scoped_refptr<Layer> root = Layer::Create(); |
| 6458 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6459 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6460 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6461 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6462 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6463 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6464 | |
| 6465 | root->AddChild(clip_parent); |
| 6466 | clip_parent->AddChild(render_surface1); |
| 6467 | render_surface1->AddChild(intervening); |
| 6468 | intervening->AddChild(render_surface2); |
| 6469 | render_surface2->AddChild(clip_child); |
| 6470 | |
| 6471 | clip_child->SetClipParent(clip_parent.get()); |
| 6472 | |
| 6473 | intervening->SetMasksToBounds(true); |
| 6474 | clip_parent->SetMasksToBounds(true); |
| 6475 | |
| 6476 | render_surface1->SetForceRenderSurface(true); |
| 6477 | render_surface2->SetForceRenderSurface(true); |
| 6478 | |
| 6479 | gfx::Transform translation_transform; |
| 6480 | translation_transform.Translate(2, 2); |
| 6481 | |
| 6482 | gfx::Transform identity_transform; |
| 6483 | SetLayerPropertiesForTesting(root.get(), |
| 6484 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6485 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6486 | gfx::PointF(), |
| 6487 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6488 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6489 | false); |
| 6490 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6491 | translation_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6492 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6493 | gfx::PointF(1.f, 1.f), |
| 6494 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6495 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6496 | false); |
| 6497 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6498 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6499 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6500 | gfx::PointF(), |
| 6501 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6502 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6503 | false); |
| 6504 | SetLayerPropertiesForTesting(intervening.get(), |
| 6505 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6506 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6507 | gfx::PointF(1.f, 1.f), |
| 6508 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6509 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6510 | false); |
| 6511 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6512 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6513 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6514 | gfx::PointF(), |
| 6515 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6516 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6517 | false); |
| 6518 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6519 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6520 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6521 | gfx::PointF(-10.f, -10.f), |
| 6522 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6523 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6524 | false); |
| 6525 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6526 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6527 | host->SetRootLayer(root); |
| 6528 | |
| 6529 | ExecuteCalculateDrawProperties(root.get()); |
| 6530 | |
| 6531 | EXPECT_TRUE(root->render_surface()); |
| 6532 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6533 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6534 | |
| 6535 | // Since the render surfaces could have expanded, they should not clip (their |
| 6536 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6537 | // in this case. |
| 6538 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6539 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6540 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6541 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6542 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6543 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6544 | |
| 6545 | // NB: clip rects are in target space. |
| 6546 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6547 | render_surface1->clip_rect().ToString()); |
| 6548 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6549 | |
| 6550 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6551 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6552 | render_surface2->clip_rect().ToString()); |
| 6553 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6554 | |
| 6555 | // The content rects of both render surfaces should both have expanded to |
| 6556 | // contain the clip child. |
| 6557 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6558 | render_surface1->render_surface()->content_rect().ToString()); |
| 6559 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6560 | render_surface2->render_surface()->content_rect().ToString()); |
| 6561 | |
| 6562 | // The clip child should have inherited the clip parent's clip (projected to |
| 6563 | // the right space, of course), and should have the correctly sized visible |
| 6564 | // content rect. |
| 6565 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6566 | clip_child->clip_rect().ToString()); |
| 6567 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(), |
| 6568 | clip_child->visible_content_rect().ToString()); |
| 6569 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6570 | } |
| 6571 | |
| 6572 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 6573 | // Ensure that intervening render surfaces are not a problem, even if there |
| 6574 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 6575 | // of transform. |
| 6576 | // |
| 6577 | // root (a render surface) |
| 6578 | // + clip_parent (masks to bounds) |
| 6579 | // + render_surface1 (sets opacity) |
| 6580 | // + intervening (masks to bounds AND scrolls) |
| 6581 | // + render_surface2 (also sets opacity) |
| 6582 | // + clip_child |
| 6583 | // |
| 6584 | scoped_refptr<Layer> root = Layer::Create(); |
| 6585 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6586 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6587 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6588 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6589 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6590 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6591 | |
| 6592 | root->AddChild(clip_parent); |
| 6593 | clip_parent->AddChild(render_surface1); |
| 6594 | render_surface1->AddChild(intervening); |
| 6595 | intervening->AddChild(render_surface2); |
| 6596 | render_surface2->AddChild(clip_child); |
| 6597 | |
| 6598 | clip_child->SetClipParent(clip_parent.get()); |
| 6599 | |
| 6600 | intervening->SetMasksToBounds(true); |
| 6601 | clip_parent->SetMasksToBounds(true); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6602 | intervening->SetScrollClipLayerId(clip_parent->id()); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 6603 | intervening->SetScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6604 | |
| 6605 | render_surface1->SetForceRenderSurface(true); |
| 6606 | render_surface2->SetForceRenderSurface(true); |
| 6607 | |
| 6608 | gfx::Transform translation_transform; |
| 6609 | translation_transform.Translate(2, 2); |
| 6610 | |
| 6611 | gfx::Transform identity_transform; |
| 6612 | SetLayerPropertiesForTesting(root.get(), |
| 6613 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6614 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6615 | gfx::PointF(), |
| 6616 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6617 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6618 | false); |
| 6619 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6620 | translation_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6621 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6622 | gfx::PointF(1.f, 1.f), |
| 6623 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6624 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6625 | false); |
| 6626 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6627 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6628 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6629 | gfx::PointF(), |
| 6630 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6631 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6632 | false); |
| 6633 | SetLayerPropertiesForTesting(intervening.get(), |
| 6634 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6635 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6636 | gfx::PointF(1.f, 1.f), |
| 6637 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6638 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6639 | false); |
| 6640 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6641 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6642 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6643 | gfx::PointF(), |
| 6644 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6645 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6646 | false); |
| 6647 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6648 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6649 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6650 | gfx::PointF(-10.f, -10.f), |
| 6651 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6652 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6653 | false); |
| 6654 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6655 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6656 | host->SetRootLayer(root); |
| 6657 | |
| 6658 | ExecuteCalculateDrawProperties(root.get()); |
| 6659 | |
| 6660 | EXPECT_TRUE(root->render_surface()); |
| 6661 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6662 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6663 | |
| 6664 | // Since the render surfaces could have expanded, they should not clip (their |
| 6665 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6666 | // in this case. |
| 6667 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6668 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6669 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6670 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6671 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6672 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6673 | |
| 6674 | // NB: clip rects are in target space. |
| 6675 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6676 | render_surface1->clip_rect().ToString()); |
| 6677 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6678 | |
| 6679 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6680 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(), |
| 6681 | render_surface2->clip_rect().ToString()); |
| 6682 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6683 | |
| 6684 | // The content rects of both render surfaces should both have expanded to |
| 6685 | // contain the clip child. |
| 6686 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6687 | render_surface1->render_surface()->content_rect().ToString()); |
| 6688 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6689 | render_surface2->render_surface()->content_rect().ToString()); |
| 6690 | |
| 6691 | // The clip child should have inherited the clip parent's clip (projected to |
| 6692 | // the right space, of course), and should have the correctly sized visible |
| 6693 | // content rect. |
| 6694 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6695 | clip_child->clip_rect().ToString()); |
| 6696 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), |
| 6697 | clip_child->visible_content_rect().ToString()); |
| 6698 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6699 | } |
| 6700 | |
| 6701 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 6702 | // Ensures that descendants of the clip child inherit the correct clip. |
| 6703 | // |
| 6704 | // root (a render surface) |
| 6705 | // + clip_parent (masks to bounds) |
| 6706 | // + intervening (masks to bounds) |
| 6707 | // + clip_child |
| 6708 | // + child |
| 6709 | // |
| 6710 | scoped_refptr<Layer> root = Layer::Create(); |
| 6711 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6712 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6713 | scoped_refptr<Layer> clip_child = Layer::Create(); |
| 6714 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 6715 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6716 | |
| 6717 | root->AddChild(clip_parent); |
| 6718 | clip_parent->AddChild(intervening); |
| 6719 | intervening->AddChild(clip_child); |
| 6720 | clip_child->AddChild(child); |
| 6721 | |
| 6722 | clip_child->SetClipParent(clip_parent.get()); |
| 6723 | |
| 6724 | intervening->SetMasksToBounds(true); |
| 6725 | clip_parent->SetMasksToBounds(true); |
| 6726 | |
| 6727 | gfx::Transform identity_transform; |
| 6728 | SetLayerPropertiesForTesting(root.get(), |
| 6729 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6730 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6731 | gfx::PointF(), |
| 6732 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6733 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6734 | false); |
| 6735 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6736 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6737 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6738 | gfx::PointF(), |
| 6739 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6740 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6741 | false); |
| 6742 | SetLayerPropertiesForTesting(intervening.get(), |
| 6743 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6744 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6745 | gfx::PointF(), |
| 6746 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6747 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6748 | false); |
| 6749 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6750 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6751 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6752 | gfx::PointF(), |
| 6753 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6754 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6755 | false); |
| 6756 | SetLayerPropertiesForTesting(child.get(), |
| 6757 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6758 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6759 | gfx::PointF(), |
| 6760 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6761 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6762 | false); |
| 6763 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6764 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6765 | host->SetRootLayer(root); |
| 6766 | |
| 6767 | ExecuteCalculateDrawProperties(root.get()); |
| 6768 | |
| 6769 | EXPECT_TRUE(root->render_surface()); |
| 6770 | |
| 6771 | // Neither the clip child nor its descendant should have inherited the clip |
| 6772 | // from |intervening|. |
| 6773 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6774 | clip_child->clip_rect().ToString()); |
| 6775 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6776 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6777 | child->visible_content_rect().ToString()); |
| 6778 | EXPECT_TRUE(child->is_clipped()); |
| 6779 | } |
| 6780 | |
| 6781 | TEST_F(LayerTreeHostCommonTest, |
| 6782 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 6783 | // Ensures that non-descendant clip children in the tree do not affect |
| 6784 | // render surfaces. |
| 6785 | // |
| 6786 | // root (a render surface) |
| 6787 | // + clip_parent (masks to bounds) |
| 6788 | // + render_surface1 |
| 6789 | // + clip_child |
| 6790 | // + render_surface2 |
| 6791 | // + non_clip_child |
| 6792 | // |
| 6793 | // In this example render_surface2 should be unaffected by clip_child. |
| 6794 | scoped_refptr<Layer> root = Layer::Create(); |
| 6795 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6796 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6797 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6798 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6799 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6800 | scoped_refptr<LayerWithForcedDrawsContent> non_clip_child = |
| 6801 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6802 | |
| 6803 | root->AddChild(clip_parent); |
| 6804 | clip_parent->AddChild(render_surface1); |
| 6805 | render_surface1->AddChild(clip_child); |
| 6806 | clip_parent->AddChild(render_surface2); |
| 6807 | render_surface2->AddChild(non_clip_child); |
| 6808 | |
| 6809 | clip_child->SetClipParent(clip_parent.get()); |
| 6810 | |
| 6811 | clip_parent->SetMasksToBounds(true); |
| 6812 | render_surface1->SetMasksToBounds(true); |
| 6813 | |
| 6814 | gfx::Transform identity_transform; |
| 6815 | SetLayerPropertiesForTesting(root.get(), |
| 6816 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6817 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6818 | gfx::PointF(), |
| 6819 | gfx::Size(15, 15), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6820 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6821 | false); |
| 6822 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6823 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6824 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6825 | gfx::PointF(), |
| 6826 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6827 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6828 | false); |
| 6829 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6830 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6831 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6832 | gfx::PointF(5, 5), |
| 6833 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6834 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6835 | false); |
| 6836 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6837 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6838 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6839 | gfx::PointF(), |
| 6840 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6841 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6842 | false); |
| 6843 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6844 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6845 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6846 | gfx::PointF(-1, 1), |
| 6847 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6848 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6849 | false); |
| 6850 | SetLayerPropertiesForTesting(non_clip_child.get(), |
| 6851 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6852 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6853 | gfx::PointF(), |
| 6854 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6855 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6856 | false); |
| 6857 | |
| 6858 | render_surface1->SetForceRenderSurface(true); |
| 6859 | render_surface2->SetForceRenderSurface(true); |
| 6860 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6861 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6862 | host->SetRootLayer(root); |
| 6863 | |
| 6864 | ExecuteCalculateDrawProperties(root.get()); |
| 6865 | |
| 6866 | EXPECT_TRUE(root->render_surface()); |
| 6867 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6868 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6869 | |
| 6870 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6871 | render_surface1->clip_rect().ToString()); |
| 6872 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6873 | |
| 6874 | // The render surface should not clip (it has unclipped descendants), instead |
| 6875 | // it should rely on layer clipping. |
| 6876 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6877 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6878 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6879 | |
| 6880 | // That said, it should have grown to accomodate the unclipped descendant. |
| 6881 | EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(), |
| 6882 | render_surface1->render_surface()->content_rect().ToString()); |
| 6883 | |
| 6884 | // This render surface should clip. It has no unclipped descendants. |
| 6885 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6886 | render_surface2->clip_rect().ToString()); |
| 6887 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
| 6888 | |
| 6889 | // It also shouldn't have grown to accomodate the clip child. |
| 6890 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6891 | render_surface2->render_surface()->content_rect().ToString()); |
| 6892 | |
| 6893 | // Sanity check our num_unclipped_descendants values. |
| 6894 | EXPECT_EQ(1, render_surface1->num_unclipped_descendants()); |
| 6895 | EXPECT_EQ(0, render_surface2->num_unclipped_descendants()); |
| 6896 | } |
| 6897 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6898 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
| 6899 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6900 | TestSharedBitmapManager shared_bitmap_manager; |
| 6901 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6902 | scoped_ptr<LayerImpl> root = |
| 6903 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 6904 | scoped_ptr<LayerImpl> child1 = |
| 6905 | LayerImpl::Create(host_impl.active_tree(), 123456); |
| 6906 | scoped_ptr<LayerImpl> child2 = |
| 6907 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
| 6908 | scoped_ptr<LayerImpl> child3 = |
| 6909 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 6910 | |
| 6911 | gfx::Transform identity_matrix; |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6912 | gfx::Point3F transform_origin; |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6913 | gfx::PointF position; |
| 6914 | gfx::Size bounds(100, 100); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6915 | SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 6916 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6917 | root->SetDrawsContent(true); |
| 6918 | |
| 6919 | // This layer structure normally forces render surface due to preserves3d |
| 6920 | // behavior. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6921 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin, |
| 6922 | position, bounds, false, true, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6923 | child1->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6924 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin, |
| 6925 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6926 | child2->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6927 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin, |
| 6928 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6929 | child3->SetDrawsContent(true); |
| 6930 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6931 | child2->Set3dSortingContextId(1); |
| 6932 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6933 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6934 | child2->AddChild(child3.Pass()); |
| 6935 | child1->AddChild(child2.Pass()); |
| 6936 | root->AddChild(child1.Pass()); |
| 6937 | |
| 6938 | { |
| 6939 | LayerImplList render_surface_layer_list; |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 6940 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get()); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6941 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6942 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6943 | inputs.can_render_to_separate_surface = true; |
| 6944 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6945 | |
| 6946 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
| 6947 | } |
| 6948 | |
| 6949 | { |
| 6950 | LayerImplList render_surface_layer_list; |
| 6951 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6952 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6953 | inputs.can_render_to_separate_surface = false; |
| 6954 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6955 | |
| 6956 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
| 6957 | } |
| 6958 | } |
| 6959 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6960 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
| 6961 | scoped_refptr<Layer> root = Layer::Create(); |
| 6962 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 6963 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 6964 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6965 | |
| 6966 | root->AddChild(render_surface); |
| 6967 | render_surface->AddChild(child); |
| 6968 | |
| 6969 | gfx::Transform identity_transform; |
| 6970 | SetLayerPropertiesForTesting(root.get(), |
| 6971 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6972 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6973 | gfx::PointF(), |
| 6974 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6975 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6976 | false); |
| 6977 | SetLayerPropertiesForTesting(render_surface.get(), |
| 6978 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6979 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6980 | gfx::PointF(), |
| 6981 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6982 | false, |
| 6983 | true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6984 | SetLayerPropertiesForTesting(child.get(), |
| 6985 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6986 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6987 | gfx::PointF(), |
| 6988 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6989 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6990 | false); |
| 6991 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6992 | root->SetShouldFlattenTransform(false); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 6993 | root->Set3dSortingContextId(1); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6994 | render_surface->SetDoubleSided(false); |
| 6995 | render_surface->SetForceRenderSurface(true); |
| 6996 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6997 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 6998 | host->SetRootLayer(root); |
| 6999 | |
| 7000 | ExecuteCalculateDrawProperties(root.get()); |
| 7001 | |
| 7002 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 7003 | EXPECT_EQ(1u, |
| 7004 | render_surface_layer_list()->at(0) |
| 7005 | ->render_surface()->layer_list().size()); |
| 7006 | EXPECT_EQ(1u, |
| 7007 | render_surface_layer_list()->at(1) |
| 7008 | ->render_surface()->layer_list().size()); |
| 7009 | |
| 7010 | gfx::Transform rotation_transform = identity_transform; |
| 7011 | rotation_transform.RotateAboutXAxis(180.0); |
| 7012 | |
| 7013 | render_surface->SetTransform(rotation_transform); |
| 7014 | |
| 7015 | ExecuteCalculateDrawProperties(root.get()); |
| 7016 | |
| 7017 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 7018 | EXPECT_EQ(0u, |
| 7019 | render_surface_layer_list()->at(0) |
| 7020 | ->render_surface()->layer_list().size()); |
| 7021 | } |
| 7022 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7023 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 7024 | // Checks that the simple case (being clipped by a scroll parent that would |
| 7025 | // have been processed before you anyhow) results in the right clips. |
| 7026 | // |
| 7027 | // + root |
| 7028 | // + scroll_parent_border |
| 7029 | // | + scroll_parent_clip |
| 7030 | // | + scroll_parent |
| 7031 | // + scroll_child |
| 7032 | // |
| 7033 | scoped_refptr<Layer> root = Layer::Create(); |
| 7034 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7035 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7036 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7037 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7038 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7039 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7040 | |
| 7041 | root->AddChild(scroll_child); |
| 7042 | |
| 7043 | root->AddChild(scroll_parent_border); |
| 7044 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7045 | scroll_parent_clip->AddChild(scroll_parent); |
| 7046 | |
| 7047 | scroll_parent_clip->SetMasksToBounds(true); |
| 7048 | |
| 7049 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7050 | |
| 7051 | gfx::Transform identity_transform; |
| 7052 | SetLayerPropertiesForTesting(root.get(), |
| 7053 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7054 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7055 | gfx::PointF(), |
| 7056 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7057 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7058 | false); |
| 7059 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7060 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7061 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7062 | gfx::PointF(), |
| 7063 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7064 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7065 | false); |
| 7066 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7067 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7068 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7069 | gfx::PointF(), |
| 7070 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7071 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7072 | false); |
| 7073 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7074 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7075 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7076 | gfx::PointF(), |
| 7077 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7078 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7079 | false); |
| 7080 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7081 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7082 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7083 | gfx::PointF(), |
| 7084 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7085 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7086 | false); |
| 7087 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7088 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7089 | host->SetRootLayer(root); |
| 7090 | |
| 7091 | ExecuteCalculateDrawProperties(root.get()); |
| 7092 | |
| 7093 | EXPECT_TRUE(root->render_surface()); |
| 7094 | |
| 7095 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 7096 | scroll_child->clip_rect().ToString()); |
| 7097 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7098 | } |
| 7099 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7100 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
| 7101 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 7102 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7103 | scoped_refptr<LayerWithForcedDrawsContent> parent = |
| 7104 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7105 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 7106 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7107 | |
| 7108 | root->AddChild(parent); |
| 7109 | parent->AddChild(child); |
| 7110 | |
| 7111 | gfx::Transform identity_transform; |
| 7112 | SetLayerPropertiesForTesting(root.get(), |
| 7113 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7114 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7115 | gfx::PointF(), |
| 7116 | gfx::Size(50, 50), |
| 7117 | true, |
| 7118 | true); |
| 7119 | root->SetForceRenderSurface(true); |
| 7120 | SetLayerPropertiesForTesting(parent.get(), |
| 7121 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7122 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7123 | gfx::PointF(), |
| 7124 | gfx::Size(30, 30), |
| 7125 | true, |
| 7126 | true); |
| 7127 | parent->SetForceRenderSurface(true); |
| 7128 | SetLayerPropertiesForTesting(child.get(), |
| 7129 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7130 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7131 | gfx::PointF(), |
| 7132 | gfx::Size(20, 20), |
| 7133 | true, |
| 7134 | true); |
| 7135 | child->SetForceRenderSurface(true); |
| 7136 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7137 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7138 | host->SetRootLayer(root); |
| 7139 | |
| 7140 | ExecuteCalculateDrawProperties(root.get()); |
| 7141 | |
| 7142 | EXPECT_EQ(3u, render_surface_layer_list()->size()); |
| 7143 | |
| 7144 | gfx::Transform singular_transform; |
| 7145 | singular_transform.Scale3d( |
| 7146 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 7147 | |
| 7148 | child->SetTransform(singular_transform); |
| 7149 | |
| 7150 | ExecuteCalculateDrawProperties(root.get()); |
| 7151 | |
| 7152 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 7153 | |
| 7154 | // Ensure that the entire subtree under a layer with singular transform does |
| 7155 | // not get rendered. |
| 7156 | parent->SetTransform(singular_transform); |
| 7157 | child->SetTransform(identity_transform); |
| 7158 | |
| 7159 | ExecuteCalculateDrawProperties(root.get()); |
| 7160 | |
| 7161 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 7162 | } |
| 7163 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7164 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 7165 | // Checks that clipping by a scroll parent that follows you in paint order |
| 7166 | // still results in correct clipping. |
| 7167 | // |
| 7168 | // + root |
| 7169 | // + scroll_child |
| 7170 | // + scroll_parent_border |
| 7171 | // + scroll_parent_clip |
| 7172 | // + scroll_parent |
| 7173 | // |
| 7174 | scoped_refptr<Layer> root = Layer::Create(); |
| 7175 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7176 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7177 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7178 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7179 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7180 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7181 | |
| 7182 | root->AddChild(scroll_parent_border); |
| 7183 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7184 | scroll_parent_clip->AddChild(scroll_parent); |
| 7185 | |
| 7186 | root->AddChild(scroll_child); |
| 7187 | |
| 7188 | scroll_parent_clip->SetMasksToBounds(true); |
| 7189 | |
| 7190 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7191 | |
| 7192 | gfx::Transform identity_transform; |
| 7193 | SetLayerPropertiesForTesting(root.get(), |
| 7194 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7195 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7196 | gfx::PointF(), |
| 7197 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7198 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7199 | false); |
| 7200 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7201 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7202 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7203 | gfx::PointF(), |
| 7204 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7205 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7206 | false); |
| 7207 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7208 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7209 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7210 | gfx::PointF(), |
| 7211 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7212 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7213 | false); |
| 7214 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7215 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7216 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7217 | gfx::PointF(), |
| 7218 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7219 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7220 | false); |
| 7221 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7222 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7223 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7224 | gfx::PointF(), |
| 7225 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7226 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7227 | false); |
| 7228 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7229 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7230 | host->SetRootLayer(root); |
| 7231 | |
| 7232 | ExecuteCalculateDrawProperties(root.get()); |
| 7233 | |
| 7234 | EXPECT_TRUE(root->render_surface()); |
| 7235 | |
| 7236 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 7237 | scroll_child->clip_rect().ToString()); |
| 7238 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7239 | } |
| 7240 | |
| 7241 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 7242 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 7243 | // you in paint order still results in correct clipping. |
| 7244 | // |
| 7245 | // + root |
| 7246 | // + scroll_child |
| 7247 | // + scroll_parent_border |
| 7248 | // | + scroll_parent_clip |
| 7249 | // | + scroll_parent |
| 7250 | // + scroll_grandparent_border |
| 7251 | // + scroll_grandparent_clip |
| 7252 | // + scroll_grandparent |
| 7253 | // |
| 7254 | scoped_refptr<Layer> root = Layer::Create(); |
| 7255 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7256 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7257 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7258 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7259 | |
| 7260 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 7261 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 7262 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 7263 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7264 | |
| 7265 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7266 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7267 | |
| 7268 | root->AddChild(scroll_child); |
| 7269 | |
| 7270 | root->AddChild(scroll_parent_border); |
| 7271 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7272 | scroll_parent_clip->AddChild(scroll_parent); |
| 7273 | |
| 7274 | root->AddChild(scroll_grandparent_border); |
| 7275 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 7276 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 7277 | |
| 7278 | scroll_parent_clip->SetMasksToBounds(true); |
| 7279 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 7280 | |
| 7281 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7282 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 7283 | |
| 7284 | gfx::Transform identity_transform; |
| 7285 | SetLayerPropertiesForTesting(root.get(), |
| 7286 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7287 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7288 | gfx::PointF(), |
| 7289 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7290 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7291 | false); |
| 7292 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 7293 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7294 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7295 | gfx::PointF(), |
| 7296 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7297 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7298 | false); |
| 7299 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 7300 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7301 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7302 | gfx::PointF(), |
| 7303 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7304 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7305 | false); |
| 7306 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 7307 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7308 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7309 | gfx::PointF(), |
| 7310 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7311 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7312 | false); |
| 7313 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7314 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7315 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7316 | gfx::PointF(), |
| 7317 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7318 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7319 | false); |
| 7320 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7321 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7322 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7323 | gfx::PointF(), |
| 7324 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7325 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7326 | false); |
| 7327 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7328 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7329 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7330 | gfx::PointF(), |
| 7331 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7332 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7333 | false); |
| 7334 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7335 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7336 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7337 | gfx::PointF(), |
| 7338 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7339 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7340 | false); |
| 7341 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7342 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7343 | host->SetRootLayer(root); |
| 7344 | |
| 7345 | ExecuteCalculateDrawProperties(root.get()); |
| 7346 | |
| 7347 | EXPECT_TRUE(root->render_surface()); |
| 7348 | |
| 7349 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 7350 | scroll_child->clip_rect().ToString()); |
| 7351 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7352 | |
| 7353 | // Despite the fact that we visited the above layers out of order to get the |
| 7354 | // correct clip, the layer lists should be unaffected. |
| 7355 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 7356 | EXPECT_EQ(scroll_child.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7357 | root->render_surface()->layer_list().at(0).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7358 | EXPECT_EQ(scroll_parent.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7359 | root->render_surface()->layer_list().at(1).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7360 | EXPECT_EQ(scroll_grandparent.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7361 | root->render_surface()->layer_list().at(2).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7362 | } |
| 7363 | |
| 7364 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 7365 | // 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] | 7366 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7367 | // + root |
| 7368 | // + scroll_child |
| 7369 | // + scroll_parent_border |
| 7370 | // + scroll_parent_clip |
| 7371 | // + scroll_parent |
| 7372 | // + render_surface1 |
| 7373 | // + scroll_grandparent_border |
| 7374 | // + scroll_grandparent_clip |
| 7375 | // + scroll_grandparent |
| 7376 | // + render_surface2 |
| 7377 | // |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 7378 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 7379 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7380 | |
| 7381 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7382 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7383 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7384 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7385 | scoped_refptr<LayerWithForcedDrawsContent> render_surface1 = |
| 7386 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7387 | |
| 7388 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 7389 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 7390 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 7391 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7392 | scoped_refptr<LayerWithForcedDrawsContent> render_surface2 = |
| 7393 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7394 | |
| 7395 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7396 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7397 | |
| 7398 | root->AddChild(scroll_child); |
| 7399 | |
| 7400 | root->AddChild(scroll_parent_border); |
| 7401 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7402 | scroll_parent_clip->AddChild(scroll_parent); |
| 7403 | scroll_parent->AddChild(render_surface2); |
| 7404 | |
| 7405 | root->AddChild(scroll_grandparent_border); |
| 7406 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 7407 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 7408 | scroll_grandparent->AddChild(render_surface1); |
| 7409 | |
| 7410 | scroll_parent_clip->SetMasksToBounds(true); |
| 7411 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 7412 | |
| 7413 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7414 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 7415 | |
| 7416 | render_surface1->SetForceRenderSurface(true); |
| 7417 | render_surface2->SetForceRenderSurface(true); |
| 7418 | |
| 7419 | gfx::Transform identity_transform; |
| 7420 | SetLayerPropertiesForTesting(root.get(), |
| 7421 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7422 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7423 | gfx::PointF(), |
| 7424 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7425 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7426 | false); |
| 7427 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 7428 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7429 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7430 | gfx::PointF(), |
| 7431 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7432 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7433 | false); |
| 7434 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 7435 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7436 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7437 | gfx::PointF(), |
| 7438 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7439 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7440 | false); |
| 7441 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 7442 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7443 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7444 | gfx::PointF(), |
| 7445 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7446 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7447 | false); |
| 7448 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 7449 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7450 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7451 | gfx::PointF(), |
| 7452 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7453 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7454 | false); |
| 7455 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7456 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7457 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7458 | gfx::PointF(), |
| 7459 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7460 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7461 | false); |
| 7462 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7463 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7464 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7465 | gfx::PointF(), |
| 7466 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7467 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7468 | false); |
| 7469 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7470 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7471 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7472 | gfx::PointF(), |
| 7473 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7474 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7475 | false); |
| 7476 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 7477 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7478 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7479 | gfx::PointF(), |
| 7480 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7481 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7482 | false); |
| 7483 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7484 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7485 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7486 | gfx::PointF(), |
| 7487 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7488 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7489 | false); |
| 7490 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7491 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7492 | host->SetRootLayer(root); |
| 7493 | |
| 7494 | RenderSurfaceLayerList render_surface_layer_list; |
| 7495 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7496 | root.get(), |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7497 | root->bounds(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7498 | identity_transform, |
| 7499 | &render_surface_layer_list); |
| 7500 | |
| 7501 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7502 | |
| 7503 | EXPECT_TRUE(root->render_surface()); |
| 7504 | |
| 7505 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 7506 | scroll_child->clip_rect().ToString()); |
| 7507 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7508 | |
| 7509 | // Despite the fact that we had to process the layers out of order to get the |
| 7510 | // right clip, our render_surface_layer_list's order should be unaffected. |
| 7511 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
| 7512 | EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); |
| 7513 | EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); |
| 7514 | EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 7515 | EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); |
| 7516 | EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); |
| 7517 | EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7518 | } |
| 7519 | |
| 7520 | TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) { |
| 7521 | // We rearrange layer list contributions if we have to visit children out of |
| 7522 | // order, but it should be a 'stable' rearrangement. That is, the layer list |
| 7523 | // additions for a single layer should not be reordered, though their position |
| 7524 | // wrt to the contributions due to a sibling may vary. |
| 7525 | // |
| 7526 | // + root |
| 7527 | // + scroll_child |
| 7528 | // + top_content |
| 7529 | // + bottom_content |
| 7530 | // + scroll_parent_border |
| 7531 | // + scroll_parent_clip |
| 7532 | // + scroll_parent |
| 7533 | // |
| 7534 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7535 | TestSharedBitmapManager shared_bitmap_manager; |
| 7536 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7537 | host_impl.CreatePendingTree(); |
| 7538 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7539 | scoped_ptr<LayerImpl> scroll_parent_border = |
| 7540 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7541 | scoped_ptr<LayerImpl> scroll_parent_clip = |
| 7542 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7543 | scoped_ptr<LayerImpl> scroll_parent = |
| 7544 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 7545 | scoped_ptr<LayerImpl> scroll_child = |
| 7546 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 7547 | scoped_ptr<LayerImpl> bottom_content = |
| 7548 | LayerImpl::Create(host_impl.active_tree(), 6); |
| 7549 | scoped_ptr<LayerImpl> top_content = |
| 7550 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 7551 | |
| 7552 | scroll_parent_clip->SetMasksToBounds(true); |
| 7553 | |
| 7554 | scroll_child->SetScrollParent(scroll_parent.get()); |
danakj | 6496cba | 2014-10-16 01:31:08 | [diff] [blame] | 7555 | scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7556 | scroll_children->insert(scroll_child.get()); |
| 7557 | scroll_parent->SetScrollChildren(scroll_children.release()); |
| 7558 | |
| 7559 | scroll_child->SetDrawsContent(true); |
| 7560 | scroll_parent->SetDrawsContent(true); |
| 7561 | top_content->SetDrawsContent(true); |
| 7562 | bottom_content->SetDrawsContent(true); |
| 7563 | |
| 7564 | gfx::Transform identity_transform; |
| 7565 | gfx::Transform top_transform; |
| 7566 | top_transform.Translate3d(0.0, 0.0, 5.0); |
| 7567 | gfx::Transform bottom_transform; |
| 7568 | bottom_transform.Translate3d(0.0, 0.0, 3.0); |
| 7569 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7570 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7571 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7572 | true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7573 | SetLayerPropertiesForTesting(scroll_parent_border.get(), identity_transform, |
| 7574 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7575 | true, false, false); |
| 7576 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), identity_transform, |
| 7577 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 7578 | true, false, false); |
| 7579 | SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform, |
| 7580 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 7581 | true, false, false); |
| 7582 | SetLayerPropertiesForTesting(scroll_child.get(), identity_transform, |
| 7583 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 7584 | true, false, false); |
| 7585 | SetLayerPropertiesForTesting(top_content.get(), top_transform, gfx::Point3F(), |
| 7586 | gfx::PointF(), gfx::Size(50, 50), false, true, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7587 | true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7588 | SetLayerPropertiesForTesting(bottom_content.get(), bottom_transform, |
| 7589 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 7590 | false, true, true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7591 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7592 | scroll_child->SetShouldFlattenTransform(false); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 7593 | scroll_child->Set3dSortingContextId(1); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7594 | |
| 7595 | scroll_child->AddChild(top_content.Pass()); |
| 7596 | scroll_child->AddChild(bottom_content.Pass()); |
| 7597 | root->AddChild(scroll_child.Pass()); |
| 7598 | |
| 7599 | scroll_parent_clip->AddChild(scroll_parent.Pass()); |
| 7600 | scroll_parent_border->AddChild(scroll_parent_clip.Pass()); |
| 7601 | root->AddChild(scroll_parent_border.Pass()); |
| 7602 | |
| 7603 | LayerImplList render_surface_layer_list; |
| 7604 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7605 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7606 | |
| 7607 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7608 | |
| 7609 | EXPECT_TRUE(root->render_surface()); |
| 7610 | |
| 7611 | // If we don't sort by depth and let the layers get added in the order they |
| 7612 | // would normally be visited in, then layers 6 and 7 will be out of order. In |
| 7613 | // other words, although we've had to shift 5, 6, and 7 to appear before 4 |
| 7614 | // in the list (because of the scroll parent relationship), this should not |
| 7615 | // have an effect on the the order of 5, 6, and 7 (which had been reordered |
| 7616 | // due to layer sorting). |
| 7617 | EXPECT_EQ(4u, root->render_surface()->layer_list().size()); |
| 7618 | EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id()); |
| 7619 | EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id()); |
| 7620 | EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id()); |
| 7621 | EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id()); |
| 7622 | } |
| 7623 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7624 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 7625 | // This test verifies that a scrolling layer that gets snapped to |
| 7626 | // integer coordinates doesn't move a fixed position child. |
| 7627 | // |
| 7628 | // + root |
| 7629 | // + container |
| 7630 | // + scroller |
| 7631 | // + fixed |
| 7632 | // |
| 7633 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7634 | TestSharedBitmapManager shared_bitmap_manager; |
| 7635 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7636 | host_impl.CreatePendingTree(); |
| 7637 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7638 | scoped_ptr<LayerImpl> container = |
| 7639 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7640 | LayerImpl* container_layer = container.get(); |
| 7641 | scoped_ptr<LayerImpl> scroller = |
| 7642 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7643 | LayerImpl* scroll_layer = scroller.get(); |
| 7644 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7645 | LayerImpl* fixed_layer = fixed.get(); |
| 7646 | |
| 7647 | container->SetIsContainerForFixedPositionLayers(true); |
| 7648 | |
| 7649 | LayerPositionConstraint constraint; |
| 7650 | constraint.set_is_fixed_position(true); |
| 7651 | fixed->SetPositionConstraint(constraint); |
| 7652 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 7653 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7654 | |
| 7655 | gfx::Transform identity_transform; |
| 7656 | gfx::Transform container_transform; |
| 7657 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7658 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7659 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7660 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7661 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7662 | true); |
| 7663 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7664 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7665 | true, false, false); |
| 7666 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7667 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 7668 | true, false, false); |
| 7669 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7670 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7671 | false); |
| 7672 | |
| 7673 | scroller->AddChild(fixed.Pass()); |
| 7674 | container->AddChild(scroller.Pass()); |
| 7675 | root->AddChild(container.Pass()); |
| 7676 | |
| 7677 | // Rounded to integers already. |
| 7678 | { |
| 7679 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
| 7680 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7681 | |
| 7682 | LayerImplList render_surface_layer_list; |
| 7683 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7684 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7685 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7686 | |
| 7687 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7688 | container_layer->draw_properties().screen_space_transform, |
| 7689 | fixed_layer->draw_properties().screen_space_transform); |
| 7690 | EXPECT_VECTOR_EQ( |
| 7691 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7692 | container_offset); |
| 7693 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7694 | .screen_space_transform.To2dTranslation(), |
| 7695 | container_offset - scroll_delta); |
| 7696 | } |
| 7697 | |
| 7698 | // Scroll delta requiring rounding. |
| 7699 | { |
| 7700 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
| 7701 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7702 | |
| 7703 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 7704 | |
| 7705 | LayerImplList render_surface_layer_list; |
| 7706 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7707 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7708 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7709 | |
| 7710 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7711 | container_layer->draw_properties().screen_space_transform, |
| 7712 | fixed_layer->draw_properties().screen_space_transform); |
| 7713 | EXPECT_VECTOR_EQ( |
| 7714 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7715 | container_offset); |
| 7716 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7717 | .screen_space_transform.To2dTranslation(), |
| 7718 | container_offset - rounded_scroll_delta); |
| 7719 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7720 | |
| 7721 | // Scale is applied earlier in the tree. |
| 7722 | { |
| 7723 | gfx::Transform scaled_container_transform = container_transform; |
| 7724 | scaled_container_transform.Scale3d(3.0, 3.0, 1.0); |
| 7725 | container_layer->SetTransform(scaled_container_transform); |
| 7726 | |
| 7727 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7728 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7729 | |
| 7730 | LayerImplList render_surface_layer_list; |
| 7731 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7732 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7733 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7734 | |
| 7735 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7736 | container_layer->draw_properties().screen_space_transform, |
| 7737 | fixed_layer->draw_properties().screen_space_transform); |
| 7738 | EXPECT_VECTOR_EQ( |
| 7739 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7740 | container_offset); |
| 7741 | |
| 7742 | container_layer->SetTransform(container_transform); |
| 7743 | } |
| 7744 | |
| 7745 | // Scale is applied on the scroll layer itself. |
| 7746 | { |
| 7747 | gfx::Transform scale_transform; |
| 7748 | scale_transform.Scale3d(3.0, 3.0, 1.0); |
| 7749 | scroll_layer->SetTransform(scale_transform); |
| 7750 | |
| 7751 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7752 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7753 | |
| 7754 | LayerImplList render_surface_layer_list; |
| 7755 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7756 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7757 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7758 | |
| 7759 | EXPECT_VECTOR_EQ( |
| 7760 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7761 | container_offset); |
| 7762 | |
| 7763 | scroll_layer->SetTransform(identity_transform); |
| 7764 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7765 | } |
| 7766 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7767 | TEST_F(LayerTreeHostCommonTest, |
| 7768 | ScrollCompensationMainScrollOffsetFractionalPart) { |
| 7769 | // This test verifies that a scrolling layer that has fractional scroll offset |
| 7770 | // from main doesn't move a fixed position child. |
| 7771 | // |
| 7772 | // + root |
| 7773 | // + container |
| 7774 | // + scroller |
| 7775 | // + fixed |
| 7776 | // |
| 7777 | FakeImplProxy proxy; |
| 7778 | TestSharedBitmapManager shared_bitmap_manager; |
| 7779 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 7780 | host_impl.CreatePendingTree(); |
| 7781 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7782 | scoped_ptr<LayerImpl> container = |
| 7783 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7784 | LayerImpl* container_layer = container.get(); |
| 7785 | scoped_ptr<LayerImpl> scroller = |
| 7786 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7787 | LayerImpl* scroll_layer = scroller.get(); |
| 7788 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7789 | LayerImpl* fixed_layer = fixed.get(); |
| 7790 | |
| 7791 | container->SetIsContainerForFixedPositionLayers(true); |
| 7792 | |
| 7793 | LayerPositionConstraint constraint; |
| 7794 | constraint.set_is_fixed_position(true); |
| 7795 | fixed->SetPositionConstraint(constraint); |
| 7796 | |
| 7797 | scroller->SetScrollClipLayer(container->id()); |
| 7798 | |
| 7799 | gfx::Transform identity_transform; |
| 7800 | gfx::Transform container_transform; |
| 7801 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7802 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7803 | |
| 7804 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7805 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7806 | true); |
| 7807 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7808 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7809 | true, false, false); |
| 7810 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7811 | gfx::Point3F(), gfx::PointF(0.0, 0.0), |
| 7812 | gfx::Size(30, 30), true, false, false); |
| 7813 | |
| 7814 | gfx::ScrollOffset scroll_offset(3.3, 4.2); |
| 7815 | gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f); |
| 7816 | gfx::Vector2dF scroll_delta(0.1f, 0.4f); |
| 7817 | // Blink only uses the integer part of the scroll_offset for fixed |
| 7818 | // position layer. |
| 7819 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7820 | gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true, |
| 7821 | false, false); |
| 7822 | scroll_layer->SetScrollOffsetAndDelta(scroll_offset, scroll_delta); |
miletus | ff93ab7 | 2015-01-30 04:30:44 | [diff] [blame^] | 7823 | scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7824 | |
| 7825 | scroller->AddChild(fixed.Pass()); |
| 7826 | container->AddChild(scroller.Pass()); |
| 7827 | root->AddChild(container.Pass()); |
| 7828 | |
| 7829 | LayerImplList render_surface_layer_list; |
| 7830 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7831 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7832 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7833 | |
| 7834 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7835 | container_layer->draw_properties().screen_space_transform, |
| 7836 | fixed_layer->draw_properties().screen_space_transform); |
| 7837 | EXPECT_VECTOR_EQ( |
| 7838 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7839 | container_offset); |
| 7840 | |
| 7841 | gfx::ScrollOffset effective_scroll_offset = |
| 7842 | ScrollOffsetWithDelta(scroll_offset, scroll_delta); |
| 7843 | gfx::Vector2d rounded_effective_scroll_offset = |
| 7844 | ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset)); |
| 7845 | EXPECT_VECTOR_EQ( |
| 7846 | scroll_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7847 | container_offset - rounded_effective_scroll_offset); |
| 7848 | } |
| 7849 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7850 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7851 | public: |
| 7852 | static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
| 7853 | LayerTreeImpl* tree_impl, |
| 7854 | int id) { |
| 7855 | return make_scoped_ptr( |
| 7856 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7857 | } |
| 7858 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 7859 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7860 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7861 | private: |
| 7862 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7863 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7864 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7865 | SetDrawsContent(true); |
| 7866 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7867 | }; |
| 7868 | |
| 7869 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
| 7870 | FakeImplProxy proxy; |
| 7871 | TestSharedBitmapManager shared_bitmap_manager; |
| 7872 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 7873 | gfx::Transform identity_matrix; |
| 7874 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
| 7875 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
| 7876 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
| 7877 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
| 7878 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
| 7879 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
| 7880 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
| 7881 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7882 | |
| 7883 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7884 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7885 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
| 7886 | |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 7887 | child->AddChild(grand_child.Pass()); |
| 7888 | parent->AddChild(child.Pass()); |
| 7889 | grand_parent->AddChild(parent.Pass()); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7890 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7891 | SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix, |
| 7892 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 7893 | true, false, true); |
| 7894 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 7895 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7896 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7897 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 7898 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7899 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7900 | |
| 7901 | SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(), |
| 7902 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7903 | false); |
| 7904 | |
| 7905 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7906 | |
| 7907 | // No layers have animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7908 | EXPECT_EQ(0.f, |
| 7909 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7910 | EXPECT_EQ(0.f, |
| 7911 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7912 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7913 | EXPECT_EQ( |
| 7914 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7915 | |
| 7916 | TransformOperations translation; |
| 7917 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7918 | |
| 7919 | AddAnimatedTransformToLayer( |
| 7920 | parent_raw, 1.0, TransformOperations(), translation); |
| 7921 | |
| 7922 | // No layers have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7923 | EXPECT_EQ(0.f, |
| 7924 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7925 | EXPECT_EQ(0.f, |
| 7926 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7927 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7928 | EXPECT_EQ( |
| 7929 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7930 | |
| 7931 | TransformOperations scale; |
| 7932 | scale.AppendScale(5.f, 4.f, 3.f); |
| 7933 | |
| 7934 | AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); |
| 7935 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7936 | |
| 7937 | // Only |child| has a scale-affecting animation. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7938 | EXPECT_EQ(0.f, |
| 7939 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7940 | EXPECT_EQ(0.f, |
| 7941 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7942 | EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7943 | EXPECT_EQ( |
| 7944 | 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7945 | |
| 7946 | AddAnimatedTransformToLayer( |
| 7947 | grand_parent.get(), 1.0, TransformOperations(), scale); |
| 7948 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7949 | |
| 7950 | // |grand_parent| and |child| have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7951 | EXPECT_EQ(5.f, |
| 7952 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7953 | EXPECT_EQ(5.f, |
| 7954 | parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7955 | // We don't support combining animated scales from two nodes; 0.f means |
| 7956 | // that the maximum scale could not be computed. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7957 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7958 | EXPECT_EQ( |
| 7959 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7960 | |
| 7961 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 7962 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7963 | |
| 7964 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7965 | EXPECT_EQ(5.f, |
| 7966 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7967 | EXPECT_EQ(0.f, |
| 7968 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7969 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7970 | EXPECT_EQ( |
| 7971 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7972 | |
| 7973 | grand_parent->layer_animation_controller()->AbortAnimations( |
| 7974 | Animation::Transform); |
| 7975 | parent_raw->layer_animation_controller()->AbortAnimations( |
| 7976 | Animation::Transform); |
| 7977 | child_raw->layer_animation_controller()->AbortAnimations( |
| 7978 | Animation::Transform); |
| 7979 | |
| 7980 | TransformOperations perspective; |
| 7981 | perspective.AppendPerspective(10.f); |
| 7982 | |
| 7983 | AddAnimatedTransformToLayer( |
| 7984 | child_raw, 1.0, TransformOperations(), perspective); |
| 7985 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7986 | |
| 7987 | // |child| has a scale-affecting animation but computing the maximum of this |
| 7988 | // animation is not supported. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 7989 | EXPECT_EQ(0.f, |
| 7990 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7991 | EXPECT_EQ(0.f, |
| 7992 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7993 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7994 | EXPECT_EQ( |
| 7995 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7996 | |
| 7997 | child_raw->layer_animation_controller()->AbortAnimations( |
| 7998 | Animation::Transform); |
| 7999 | |
| 8000 | gfx::Transform scale_matrix; |
| 8001 | scale_matrix.Scale(1.f, 2.f); |
| 8002 | grand_parent->SetTransform(scale_matrix); |
| 8003 | parent_raw->SetTransform(scale_matrix); |
| 8004 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 8005 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8006 | |
| 8007 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 8008 | // animation with maximum scale 5.f. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8009 | EXPECT_EQ(0.f, |
| 8010 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8011 | EXPECT_EQ(10.f, |
| 8012 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8013 | EXPECT_EQ(10.f, |
| 8014 | child_raw->draw_properties().maximum_animation_contents_scale); |
| 8015 | EXPECT_EQ( |
| 8016 | 10.f, |
| 8017 | grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8018 | |
| 8019 | gfx::Transform perspective_matrix; |
| 8020 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 8021 | child_raw->SetTransform(perspective_matrix); |
| 8022 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8023 | |
| 8024 | // |child| has a transform that's neither a translation nor a scale. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8025 | EXPECT_EQ(0.f, |
| 8026 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8027 | EXPECT_EQ(10.f, |
| 8028 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8029 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8030 | EXPECT_EQ( |
| 8031 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8032 | |
| 8033 | parent_raw->SetTransform(perspective_matrix); |
| 8034 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8035 | |
| 8036 | // |parent| and |child| have transforms that are neither translations nor |
| 8037 | // scales. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8038 | EXPECT_EQ(0.f, |
| 8039 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8040 | EXPECT_EQ(0.f, |
| 8041 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8042 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8043 | EXPECT_EQ( |
| 8044 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8045 | |
| 8046 | parent_raw->SetTransform(identity_matrix); |
| 8047 | child_raw->SetTransform(identity_matrix); |
| 8048 | grand_parent->SetTransform(perspective_matrix); |
| 8049 | |
| 8050 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8051 | |
| 8052 | // |grand_parent| has a transform that's neither a translation nor a scale. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8053 | EXPECT_EQ(0.f, |
| 8054 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8055 | EXPECT_EQ(0.f, |
| 8056 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8057 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8058 | EXPECT_EQ( |
| 8059 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8060 | } |
| 8061 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8062 | static int membership_id(LayerImpl* layer) { |
| 8063 | return layer->draw_properties().last_drawn_render_surface_layer_list_id; |
| 8064 | } |
| 8065 | |
| 8066 | static void GatherDrawnLayers(LayerImplList* rsll, |
| 8067 | std::set<LayerImpl*>* drawn_layers) { |
| 8068 | for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll), |
| 8069 | end = LayerIterator<LayerImpl>::End(rsll); |
| 8070 | it != end; |
| 8071 | ++it) { |
| 8072 | LayerImpl* layer = *it; |
| 8073 | if (it.represents_itself()) |
| 8074 | drawn_layers->insert(layer); |
| 8075 | |
| 8076 | if (!it.represents_contributing_render_surface()) |
| 8077 | continue; |
| 8078 | |
| 8079 | if (layer->mask_layer()) |
| 8080 | drawn_layers->insert(layer->mask_layer()); |
| 8081 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 8082 | drawn_layers->insert(layer->replica_layer()->mask_layer()); |
| 8083 | } |
| 8084 | } |
| 8085 | |
| 8086 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
| 8087 | FakeImplProxy proxy; |
| 8088 | TestSharedBitmapManager shared_bitmap_manager; |
| 8089 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 8090 | gfx::Transform identity_matrix; |
| 8091 | |
| 8092 | scoped_ptr<LayerImpl> grand_parent = |
| 8093 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8094 | scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3); |
| 8095 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5); |
| 8096 | scoped_ptr<LayerImpl> grand_child1 = |
| 8097 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 8098 | scoped_ptr<LayerImpl> grand_child2 = |
| 8099 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 8100 | |
| 8101 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 8102 | LayerImpl* parent_raw = parent.get(); |
| 8103 | LayerImpl* child_raw = child.get(); |
| 8104 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 8105 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 8106 | |
| 8107 | child->AddChild(grand_child1.Pass()); |
| 8108 | child->AddChild(grand_child2.Pass()); |
| 8109 | parent->AddChild(child.Pass()); |
| 8110 | grand_parent->AddChild(parent.Pass()); |
| 8111 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8112 | SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, |
| 8113 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8114 | true, false, true); |
| 8115 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 8116 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8117 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8118 | |
| 8119 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 8120 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8121 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8122 | |
| 8123 | SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix, |
| 8124 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8125 | true, false, false); |
| 8126 | |
| 8127 | SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix, |
| 8128 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8129 | true, false, false); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8130 | |
| 8131 | // Start with nothing being drawn. |
| 8132 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8133 | int member_id = render_surface_layer_list_count(); |
| 8134 | |
| 8135 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8136 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8137 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8138 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8139 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8140 | |
| 8141 | std::set<LayerImpl*> expected; |
| 8142 | std::set<LayerImpl*> actual; |
| 8143 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8144 | EXPECT_EQ(expected, actual); |
| 8145 | |
| 8146 | // If we force render surface, but none of the layers are in the layer list, |
| 8147 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8148 | grand_child1_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8149 | |
| 8150 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8151 | member_id = render_surface_layer_list_count(); |
| 8152 | |
| 8153 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8154 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8155 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8156 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8157 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8158 | |
| 8159 | expected.clear(); |
| 8160 | actual.clear(); |
| 8161 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8162 | EXPECT_EQ(expected, actual); |
| 8163 | |
| 8164 | // However, if we say that this layer also draws content, it will appear in |
| 8165 | // RSLL. |
| 8166 | grand_child1_raw->SetDrawsContent(true); |
| 8167 | |
| 8168 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8169 | member_id = render_surface_layer_list_count(); |
| 8170 | |
| 8171 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8172 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8173 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8174 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 8175 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8176 | |
| 8177 | expected.clear(); |
| 8178 | expected.insert(grand_child1_raw); |
| 8179 | |
| 8180 | actual.clear(); |
| 8181 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8182 | EXPECT_EQ(expected, actual); |
| 8183 | |
| 8184 | // Now child is forced to have a render surface, and one if its children draws |
| 8185 | // content. |
| 8186 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8187 | grand_child1_raw->SetHasRenderSurface(false); |
| 8188 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8189 | grand_child2_raw->SetDrawsContent(true); |
| 8190 | |
| 8191 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8192 | member_id = render_surface_layer_list_count(); |
| 8193 | |
| 8194 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8195 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8196 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8197 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8198 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8199 | |
| 8200 | expected.clear(); |
| 8201 | expected.insert(grand_child2_raw); |
| 8202 | |
| 8203 | actual.clear(); |
| 8204 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8205 | EXPECT_EQ(expected, actual); |
| 8206 | |
| 8207 | // Add a mask layer to child. |
| 8208 | child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass()); |
| 8209 | |
| 8210 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8211 | member_id = render_surface_layer_list_count(); |
| 8212 | |
| 8213 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8214 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8215 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8216 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8217 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8218 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8219 | |
| 8220 | expected.clear(); |
| 8221 | expected.insert(grand_child2_raw); |
| 8222 | expected.insert(child_raw->mask_layer()); |
| 8223 | |
| 8224 | expected.clear(); |
| 8225 | expected.insert(grand_child2_raw); |
| 8226 | expected.insert(child_raw->mask_layer()); |
| 8227 | |
| 8228 | actual.clear(); |
| 8229 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8230 | EXPECT_EQ(expected, actual); |
| 8231 | |
| 8232 | // Add replica mask layer. |
| 8233 | scoped_ptr<LayerImpl> replica_layer = |
| 8234 | LayerImpl::Create(host_impl.active_tree(), 20); |
| 8235 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21)); |
| 8236 | child_raw->SetReplicaLayer(replica_layer.Pass()); |
| 8237 | |
| 8238 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8239 | member_id = render_surface_layer_list_count(); |
| 8240 | |
| 8241 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8242 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8243 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8244 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8245 | EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer())); |
| 8246 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8247 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8248 | |
| 8249 | expected.clear(); |
| 8250 | expected.insert(grand_child2_raw); |
| 8251 | expected.insert(child_raw->mask_layer()); |
| 8252 | expected.insert(child_raw->replica_layer()->mask_layer()); |
| 8253 | |
| 8254 | actual.clear(); |
| 8255 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8256 | EXPECT_EQ(expected, actual); |
| 8257 | |
| 8258 | child_raw->TakeReplicaLayer(); |
| 8259 | |
| 8260 | // With nothing drawing, we should have no layers. |
| 8261 | grand_child2_raw->SetDrawsContent(false); |
| 8262 | |
| 8263 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8264 | member_id = render_surface_layer_list_count(); |
| 8265 | |
| 8266 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8267 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8268 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8269 | EXPECT_NE(member_id, membership_id(child_raw->mask_layer())); |
| 8270 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8271 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8272 | |
| 8273 | expected.clear(); |
| 8274 | actual.clear(); |
| 8275 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8276 | EXPECT_EQ(expected, actual); |
| 8277 | |
| 8278 | // Child itself draws means that we should have the child and the mask in the |
| 8279 | // list. |
| 8280 | child_raw->SetDrawsContent(true); |
| 8281 | |
| 8282 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8283 | member_id = render_surface_layer_list_count(); |
| 8284 | |
| 8285 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8286 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8287 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 8288 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8289 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8290 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8291 | |
| 8292 | expected.clear(); |
| 8293 | expected.insert(child_raw); |
| 8294 | expected.insert(child_raw->mask_layer()); |
| 8295 | actual.clear(); |
| 8296 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8297 | EXPECT_EQ(expected, actual); |
| 8298 | |
| 8299 | child_raw->TakeMaskLayer(); |
| 8300 | |
| 8301 | // Now everyone's a member! |
| 8302 | grand_parent_raw->SetDrawsContent(true); |
| 8303 | parent_raw->SetDrawsContent(true); |
| 8304 | child_raw->SetDrawsContent(true); |
| 8305 | grand_child1_raw->SetDrawsContent(true); |
| 8306 | grand_child2_raw->SetDrawsContent(true); |
| 8307 | |
| 8308 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8309 | member_id = render_surface_layer_list_count(); |
| 8310 | |
| 8311 | EXPECT_EQ(member_id, membership_id(grand_parent_raw)); |
| 8312 | EXPECT_EQ(member_id, membership_id(parent_raw)); |
| 8313 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 8314 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 8315 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8316 | |
| 8317 | expected.clear(); |
| 8318 | expected.insert(grand_parent_raw); |
| 8319 | expected.insert(parent_raw); |
| 8320 | expected.insert(child_raw); |
| 8321 | expected.insert(grand_child1_raw); |
| 8322 | expected.insert(grand_child2_raw); |
| 8323 | |
| 8324 | actual.clear(); |
| 8325 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8326 | EXPECT_EQ(expected, actual); |
| 8327 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8328 | |
| 8329 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
| 8330 | FakeImplProxy proxy; |
| 8331 | TestSharedBitmapManager shared_bitmap_manager; |
| 8332 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 8333 | |
| 8334 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 8335 | LayerImpl* root_layer = root.get(); |
| 8336 | scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2); |
| 8337 | LayerImpl* child1_layer = child1.get(); |
| 8338 | scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3); |
| 8339 | LayerImpl* child2_layer = child2.get(); |
| 8340 | |
| 8341 | root->AddChild(child1.Pass()); |
| 8342 | root->AddChild(child2.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8343 | root->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8344 | |
| 8345 | gfx::Transform identity_matrix, scale_transform_child1, |
| 8346 | scale_transform_child2; |
| 8347 | scale_transform_child1.Scale(2, 3); |
| 8348 | scale_transform_child2.Scale(4, 5); |
| 8349 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8350 | SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(), |
| 8351 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 8352 | true); |
| 8353 | SetLayerPropertiesForTesting(child1_layer, scale_transform_child1, |
| 8354 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 8355 | false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8356 | |
| 8357 | child1_layer->SetMaskLayer( |
| 8358 | LayerImpl::Create(host_impl.active_tree(), 4).Pass()); |
| 8359 | |
| 8360 | scoped_ptr<LayerImpl> replica_layer = |
| 8361 | LayerImpl::Create(host_impl.active_tree(), 5); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8362 | replica_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8363 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
| 8364 | child1_layer->SetReplicaLayer(replica_layer.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8365 | child1_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8366 | |
| 8367 | ExecuteCalculateDrawProperties(root_layer); |
| 8368 | |
| 8369 | TransformOperations scale; |
| 8370 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8371 | |
| 8372 | AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8373 | SetLayerPropertiesForTesting(child2_layer, scale_transform_child2, |
| 8374 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 8375 | false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8376 | |
| 8377 | ExecuteCalculateDrawProperties(root_layer); |
| 8378 | |
| 8379 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); |
| 8380 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8381 | EXPECT_FLOAT_EQ( |
| 8382 | 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8383 | EXPECT_FLOAT_EQ(3.f, |
| 8384 | child1_layer->replica_layer() |
| 8385 | ->mask_layer() |
| 8386 | ->draw_properties() |
| 8387 | .ideal_contents_scale); |
| 8388 | EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8389 | |
| 8390 | EXPECT_FLOAT_EQ( |
| 8391 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8392 | EXPECT_FLOAT_EQ( |
| 8393 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8394 | EXPECT_FLOAT_EQ(0.f, |
| 8395 | child1_layer->mask_layer() |
| 8396 | ->draw_properties() |
| 8397 | .maximum_animation_contents_scale); |
| 8398 | EXPECT_FLOAT_EQ(0.f, |
| 8399 | child1_layer->replica_layer() |
| 8400 | ->mask_layer() |
| 8401 | ->draw_properties() |
| 8402 | .maximum_animation_contents_scale); |
| 8403 | EXPECT_FLOAT_EQ( |
| 8404 | 8.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8405 | |
| 8406 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8407 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor); |
| 8408 | EXPECT_FLOAT_EQ( |
| 8409 | 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8410 | EXPECT_FLOAT_EQ(1.f, |
| 8411 | child1_layer->replica_layer() |
| 8412 | ->mask_layer() |
| 8413 | ->draw_properties() |
| 8414 | .page_scale_factor); |
| 8415 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor); |
| 8416 | |
| 8417 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); |
| 8418 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); |
| 8419 | EXPECT_FLOAT_EQ( |
| 8420 | 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8421 | EXPECT_FLOAT_EQ(1.f, |
| 8422 | child1_layer->replica_layer() |
| 8423 | ->mask_layer() |
| 8424 | ->draw_properties() |
| 8425 | .device_scale_factor); |
| 8426 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); |
| 8427 | |
| 8428 | // Changing page-scale would affect ideal_contents_scale and |
| 8429 | // maximum_animation_contents_scale. |
| 8430 | |
| 8431 | float page_scale_factor = 3.f; |
| 8432 | float device_scale_factor = 1.0f; |
| 8433 | std::vector<LayerImpl*> render_surface_layer_list; |
| 8434 | gfx::Size device_viewport_size = |
| 8435 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 8436 | root_layer->bounds().height() * device_scale_factor); |
| 8437 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8438 | root_layer, device_viewport_size, &render_surface_layer_list); |
| 8439 | |
| 8440 | inputs.page_scale_factor = page_scale_factor; |
| 8441 | inputs.can_adjust_raster_scales = true; |
| 8442 | inputs.page_scale_application_layer = root_layer; |
| 8443 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8444 | |
| 8445 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); |
| 8446 | EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8447 | EXPECT_FLOAT_EQ( |
| 8448 | 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8449 | EXPECT_FLOAT_EQ(9.f, |
| 8450 | child1_layer->replica_layer() |
| 8451 | ->mask_layer() |
| 8452 | ->draw_properties() |
| 8453 | .ideal_contents_scale); |
| 8454 | EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8455 | |
| 8456 | EXPECT_FLOAT_EQ( |
| 8457 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8458 | EXPECT_FLOAT_EQ( |
| 8459 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8460 | EXPECT_FLOAT_EQ(0.f, |
| 8461 | child1_layer->mask_layer() |
| 8462 | ->draw_properties() |
| 8463 | .maximum_animation_contents_scale); |
| 8464 | EXPECT_FLOAT_EQ(0.f, |
| 8465 | child1_layer->replica_layer() |
| 8466 | ->mask_layer() |
| 8467 | ->draw_properties() |
| 8468 | .maximum_animation_contents_scale); |
| 8469 | EXPECT_FLOAT_EQ( |
| 8470 | 24.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8471 | |
| 8472 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8473 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); |
| 8474 | EXPECT_FLOAT_EQ( |
| 8475 | 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8476 | EXPECT_FLOAT_EQ(3.f, |
| 8477 | child1_layer->replica_layer() |
| 8478 | ->mask_layer() |
| 8479 | ->draw_properties() |
| 8480 | .page_scale_factor); |
| 8481 | EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); |
| 8482 | |
| 8483 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); |
| 8484 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); |
| 8485 | EXPECT_FLOAT_EQ( |
| 8486 | 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8487 | EXPECT_FLOAT_EQ(1.f, |
| 8488 | child1_layer->replica_layer() |
| 8489 | ->mask_layer() |
| 8490 | ->draw_properties() |
| 8491 | .device_scale_factor); |
| 8492 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); |
| 8493 | |
| 8494 | // Changing device-scale would affect ideal_contents_scale and |
| 8495 | // maximum_animation_contents_scale. |
| 8496 | |
| 8497 | device_scale_factor = 4.0f; |
| 8498 | inputs.device_scale_factor = device_scale_factor; |
| 8499 | inputs.can_adjust_raster_scales = true; |
| 8500 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8501 | |
| 8502 | EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale); |
| 8503 | EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8504 | EXPECT_FLOAT_EQ( |
| 8505 | 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8506 | EXPECT_FLOAT_EQ(36.f, |
| 8507 | child1_layer->replica_layer() |
| 8508 | ->mask_layer() |
| 8509 | ->draw_properties() |
| 8510 | .ideal_contents_scale); |
| 8511 | EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8512 | |
| 8513 | EXPECT_FLOAT_EQ( |
| 8514 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8515 | EXPECT_FLOAT_EQ( |
| 8516 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8517 | EXPECT_FLOAT_EQ(0.f, |
| 8518 | child1_layer->mask_layer() |
| 8519 | ->draw_properties() |
| 8520 | .maximum_animation_contents_scale); |
| 8521 | EXPECT_FLOAT_EQ(0.f, |
| 8522 | child1_layer->replica_layer() |
| 8523 | ->mask_layer() |
| 8524 | ->draw_properties() |
| 8525 | .maximum_animation_contents_scale); |
| 8526 | EXPECT_FLOAT_EQ( |
| 8527 | 96.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8528 | |
| 8529 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8530 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); |
| 8531 | EXPECT_FLOAT_EQ( |
| 8532 | 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8533 | EXPECT_FLOAT_EQ(3.f, |
| 8534 | child1_layer->replica_layer() |
| 8535 | ->mask_layer() |
| 8536 | ->draw_properties() |
| 8537 | .page_scale_factor); |
| 8538 | EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); |
| 8539 | |
| 8540 | EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor); |
| 8541 | EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor); |
| 8542 | EXPECT_FLOAT_EQ( |
| 8543 | 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8544 | EXPECT_FLOAT_EQ(4.f, |
| 8545 | child1_layer->replica_layer() |
| 8546 | ->mask_layer() |
| 8547 | ->draw_properties() |
| 8548 | .device_scale_factor); |
| 8549 | EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor); |
| 8550 | } |
| 8551 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8552 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
| 8553 | scoped_refptr<Layer> root = Layer::Create(); |
| 8554 | SetLayerPropertiesForTesting(root.get(), |
| 8555 | gfx::Transform(), |
| 8556 | gfx::Point3F(), |
| 8557 | gfx::PointF(), |
| 8558 | gfx::Size(768 / 2, 3000), |
| 8559 | true, |
| 8560 | false); |
| 8561 | root->SetIsDrawable(true); |
| 8562 | |
| 8563 | scoped_refptr<Layer> clip = Layer::Create(); |
| 8564 | SetLayerPropertiesForTesting(clip.get(), |
| 8565 | gfx::Transform(), |
| 8566 | gfx::Point3F(), |
| 8567 | gfx::PointF(), |
| 8568 | gfx::Size(768 / 2, 10000), |
| 8569 | true, |
| 8570 | false); |
| 8571 | clip->SetMasksToBounds(true); |
| 8572 | |
| 8573 | scoped_refptr<Layer> content = Layer::Create(); |
| 8574 | SetLayerPropertiesForTesting(content.get(), |
| 8575 | gfx::Transform(), |
| 8576 | gfx::Point3F(), |
| 8577 | gfx::PointF(), |
| 8578 | gfx::Size(768 / 2, 10000), |
| 8579 | true, |
| 8580 | false); |
| 8581 | content->SetIsDrawable(true); |
| 8582 | content->SetForceRenderSurface(true); |
| 8583 | |
| 8584 | root->AddChild(clip); |
| 8585 | clip->AddChild(content); |
| 8586 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 8587 | FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 8588 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8589 | host->SetRootLayer(root); |
| 8590 | |
| 8591 | gfx::Size device_viewport_size(768, 582); |
| 8592 | RenderSurfaceLayerList render_surface_layer_list; |
| 8593 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8594 | host->root_layer(), device_viewport_size, &render_surface_layer_list); |
| 8595 | inputs.device_scale_factor = 2.f; |
| 8596 | inputs.page_scale_factor = 1.f; |
| 8597 | inputs.page_scale_application_layer = NULL; |
| 8598 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8599 | |
| 8600 | // Layers in the root render surface have their visible content rect clipped |
| 8601 | // by the viewport. |
| 8602 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); |
| 8603 | |
| 8604 | // Layers drawing to a child render surface should still have their visible |
| 8605 | // content rect clipped by the viewport. |
| 8606 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); |
| 8607 | } |
| 8608 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8609 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
| 8610 | FakeImplProxy proxy; |
| 8611 | TestSharedBitmapManager shared_bitmap_manager; |
| 8612 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 8613 | |
| 8614 | // Set two layers: the root layer clips it's child, |
| 8615 | // the child draws its content. |
| 8616 | |
| 8617 | gfx::Size root_size = gfx::Size(300, 500); |
| 8618 | |
| 8619 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8620 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8621 | |
| 8622 | // Device viewport accomidated the root and the top controls. |
| 8623 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
| 8624 | gfx::Transform identity_matrix; |
| 8625 | |
| 8626 | host_impl.active_tree()->SetRootLayer( |
| 8627 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8628 | |
| 8629 | LayerImpl* root = host_impl.active_tree()->root_layer(); |
| 8630 | SetLayerPropertiesForTesting(root, |
| 8631 | identity_matrix, |
| 8632 | gfx::Point3F(), |
| 8633 | gfx::PointF(), |
| 8634 | root_size, |
| 8635 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8636 | false, |
| 8637 | true); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8638 | |
| 8639 | root->SetContentBounds(root_size); |
| 8640 | root->SetMasksToBounds(true); |
| 8641 | |
| 8642 | root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2)); |
| 8643 | |
| 8644 | LayerImpl* sublayer = root->child_at(0); |
| 8645 | SetLayerPropertiesForTesting(sublayer, |
| 8646 | identity_matrix, |
| 8647 | gfx::Point3F(), |
| 8648 | gfx::PointF(), |
| 8649 | sublayer_size, |
| 8650 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8651 | false, |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8652 | false); |
| 8653 | |
| 8654 | sublayer->SetContentBounds(sublayer_size); |
| 8655 | sublayer->SetDrawsContent(true); |
| 8656 | |
| 8657 | LayerImplList layer_impl_list; |
| 8658 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8659 | root, device_viewport_size, &layer_impl_list); |
| 8660 | |
| 8661 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8662 | |
| 8663 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_content_rect()); |
| 8664 | |
| 8665 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
| 8666 | |
| 8667 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8668 | |
| 8669 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8670 | root_size.height() + 50); |
| 8671 | EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect()); |
| 8672 | } |
| 8673 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 8674 | } // namespace |
| 8675 | } // namespace cc |