[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" |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 24 | #include "cc/test/fake_content_layer.h" |
| 25 | #include "cc/test/fake_content_layer_client.h" |
| 26 | #include "cc/test/fake_content_layer_impl.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 27 | #include "cc/test/fake_impl_proxy.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 28 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 29 | #include "cc/test/fake_layer_tree_host_impl.h" |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 30 | #include "cc/test/fake_picture_layer.h" |
| 31 | #include "cc/test/fake_picture_layer_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 32 | #include "cc/test/geometry_test_utils.h" |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 33 | #include "cc/test/layer_tree_host_common_test.h" |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 34 | #include "cc/test/test_task_graph_runner.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 35 | #include "cc/trees/layer_tree_impl.h" |
| 36 | #include "cc/trees/proxy.h" |
| 37 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 38 | #include "testing/gmock/include/gmock/gmock.h" |
| 39 | #include "testing/gtest/include/gtest/gtest.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 40 | #include "ui/gfx/geometry/quad_f.h" |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 41 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 42 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 43 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 44 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 45 | namespace { |
| 46 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 47 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 48 | public: |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 49 | explicit LayerWithForcedDrawsContent(const LayerSettings& settings) |
| 50 | : Layer(settings) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 51 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 52 | bool DrawsContent() const override; |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 53 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 54 | private: |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 55 | ~LayerWithForcedDrawsContent() override {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 56 | }; |
| 57 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 58 | bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 59 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 60 | class MockContentLayerClient : public ContentLayerClient { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 61 | public: |
| 62 | MockContentLayerClient() {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 63 | ~MockContentLayerClient() override {} |
schenney | 0154bfa | 2015-02-05 19:46:49 | [diff] [blame] | 64 | void PaintContents(SkCanvas* canvas, |
| 65 | const gfx::Rect& clip, |
| 66 | PaintingControlSetting picture_control) override {} |
jbroman | 16d628c | 2015-05-29 20:11:59 | [diff] [blame] | 67 | scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 68 | const gfx::Rect& clip, |
schenney | 0154bfa | 2015-02-05 19:46:49 | [diff] [blame] | 69 | PaintingControlSetting picture_control) override { |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 70 | NOTIMPLEMENTED(); |
jbroman | 16d628c | 2015-05-29 20:11:59 | [diff] [blame] | 71 | return nullptr; |
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 72 | } |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 73 | bool FillsBoundsCompletely() const override { return false; } |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 74 | }; |
| 75 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 76 | scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer( |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 77 | const LayerSettings& settings, |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 78 | ContentLayerClient* delegate) { |
| 79 | scoped_refptr<FakePictureLayer> to_return = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 80 | FakePictureLayer::Create(settings, delegate); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 81 | to_return->SetIsDrawable(true); |
| 82 | return to_return; |
| 83 | } |
| 84 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 85 | scoped_refptr<ContentLayer> CreateDrawableContentLayer( |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 86 | const LayerSettings& settings, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 87 | ContentLayerClient* delegate) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 88 | scoped_refptr<ContentLayer> to_return = |
| 89 | ContentLayer::Create(settings, delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 90 | to_return->SetIsDrawable(true); |
| 91 | return to_return; |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 92 | } |
| 93 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 94 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 95 | do { \ |
| 96 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 97 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 98 | } while (false) |
| 99 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 100 | #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \ |
| 101 | do { \ |
| 102 | EXPECT_FLOAT_EQ(expected, layer->draw_properties().ideal_contents_scale); \ |
| 103 | } while (false) |
| 104 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 105 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 106 | // Sanity check: For layers positioned at zero, with zero size, |
| 107 | // and with identity transforms, then the draw transform, |
| 108 | // screen space transform, and the hierarchy passed on to children |
| 109 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 110 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 111 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 112 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 113 | scoped_refptr<Layer> grand_child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 114 | parent->AddChild(child); |
| 115 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 116 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 117 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 118 | host->SetRootLayer(parent); |
| 119 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 120 | gfx::Transform identity_matrix; |
| 121 | SetLayerPropertiesForTesting(parent.get(), |
| 122 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 123 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 124 | gfx::PointF(), |
| 125 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 126 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 127 | false); |
| 128 | SetLayerPropertiesForTesting(child.get(), |
| 129 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 130 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 131 | gfx::PointF(), |
| 132 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 133 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 134 | false); |
| 135 | SetLayerPropertiesForTesting(grand_child.get(), |
| 136 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 137 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 138 | gfx::PointF(), |
| 139 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 140 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 141 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 142 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 143 | ExecuteCalculateDrawProperties(parent.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 144 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 145 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 146 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 147 | child->screen_space_transform()); |
| 148 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 149 | grand_child->draw_transform()); |
| 150 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 151 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 152 | } |
| 153 | |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 154 | TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 155 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 156 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 157 | scoped_refptr<Layer> grand_child = Layer::Create(layer_settings()); |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 158 | parent->AddChild(child); |
| 159 | child->AddChild(grand_child); |
| 160 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 161 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 162 | host->SetRootLayer(parent); |
| 163 | |
| 164 | gfx::Transform identity_matrix; |
| 165 | SetLayerPropertiesForTesting(parent.get(), |
| 166 | identity_matrix, |
| 167 | gfx::Point3F(), |
| 168 | gfx::PointF(), |
| 169 | gfx::Size(100, 100), |
| 170 | true, |
| 171 | false); |
| 172 | SetLayerPropertiesForTesting(child.get(), |
| 173 | identity_matrix, |
| 174 | gfx::Point3F(), |
| 175 | gfx::PointF(10, 10), |
| 176 | gfx::Size(100, 100), |
| 177 | true, |
| 178 | false); |
| 179 | // This would have previously caused us to skip our subtree, but this would be |
| 180 | // wrong; we need up-to-date draw properties to do hit testing on the layers |
| 181 | // with handlers. |
| 182 | child->SetOpacity(0.f); |
| 183 | SetLayerPropertiesForTesting(grand_child.get(), |
| 184 | identity_matrix, |
| 185 | gfx::Point3F(), |
| 186 | gfx::PointF(10, 10), |
| 187 | gfx::Size(100, 100), |
| 188 | true, |
| 189 | false); |
| 190 | grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
| 191 | |
| 192 | ExecuteCalculateDrawProperties(parent.get()); |
| 193 | |
| 194 | // Check that we've computed draw properties for the subtree rooted at |
| 195 | // |child|. |
| 196 | EXPECT_FALSE(child->draw_transform().IsIdentity()); |
| 197 | EXPECT_FALSE(grand_child->draw_transform().IsIdentity()); |
| 198 | } |
| 199 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 200 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 201 | gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 202 | scoped_refptr<Layer> layer = Layer::Create(layer_settings()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 203 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 204 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 205 | SetLayerPropertiesForTesting(root.get(), |
| 206 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 207 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 208 | gfx::PointF(), |
| 209 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 210 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 211 | false); |
| 212 | root->AddChild(layer); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 213 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 214 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 215 | host->SetRootLayer(root); |
| 216 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 217 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 218 | // transform or the screenspace transform. |
| 219 | gfx::Transform translation_to_center; |
| 220 | translation_to_center.Translate(5.0, 6.0); |
| 221 | SetLayerPropertiesForTesting(layer.get(), |
| 222 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 223 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 224 | gfx::PointF(), |
| 225 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 226 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 227 | false); |
| 228 | ExecuteCalculateDrawProperties(root.get()); |
| 229 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 230 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 231 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 232 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 233 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 234 | // no effect on the transforms. |
| 235 | SetLayerPropertiesForTesting(layer.get(), |
| 236 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 237 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 238 | gfx::PointF(), |
| 239 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 240 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 241 | false); |
| 242 | ExecuteCalculateDrawProperties(root.get()); |
| 243 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 244 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 245 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 246 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 247 | // Case 4: A change in actual position affects both the draw transform and |
| 248 | // screen space transform. |
| 249 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 250 | position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 251 | SetLayerPropertiesForTesting(layer.get(), |
| 252 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 253 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 254 | gfx::PointF(0.f, 1.2f), |
| 255 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 256 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 257 | false); |
| 258 | ExecuteCalculateDrawProperties(root.get()); |
| 259 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform()); |
| 260 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, |
| 261 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 262 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 263 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 264 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 265 | // scale transform, because scale and translation are not commutative. |
| 266 | gfx::Transform layer_transform; |
| 267 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 268 | SetLayerPropertiesForTesting(layer.get(), |
| 269 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 270 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 271 | gfx::PointF(), |
| 272 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 273 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 274 | false); |
| 275 | ExecuteCalculateDrawProperties(root.get()); |
| 276 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform()); |
| 277 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, |
| 278 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 279 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 280 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 281 | gfx::Transform translation_to_anchor; |
| 282 | translation_to_anchor.Translate(5.0, 0.0); |
| 283 | gfx::Transform expected_result = |
| 284 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
| 285 | SetLayerPropertiesForTesting(layer.get(), |
| 286 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 287 | gfx::Point3F(5.0f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 288 | gfx::PointF(), |
| 289 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 290 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 291 | false); |
| 292 | ExecuteCalculateDrawProperties(root.get()); |
| 293 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 294 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 295 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 296 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 297 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 298 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 299 | // it is still worth testing to detect accidental regressions. |
| 300 | expected_result = position_transform * translation_to_anchor * |
| 301 | layer_transform * Inverse(translation_to_anchor); |
| 302 | SetLayerPropertiesForTesting(layer.get(), |
| 303 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 304 | gfx::Point3F(5.0f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 305 | gfx::PointF(0.f, 1.2f), |
| 306 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 307 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 308 | false); |
| 309 | ExecuteCalculateDrawProperties(root.get()); |
| 310 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 311 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 312 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 313 | } |
| 314 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 315 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 316 | const gfx::ScrollOffset kScrollOffset(50, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 317 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 318 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 319 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 320 | -kScrollOffset.y()); |
| 321 | const float kPageScale = 0.888f; |
| 322 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 323 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 324 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 325 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 326 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 327 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 328 | gfx::Transform identity_matrix; |
| 329 | scoped_ptr<LayerImpl> sublayer_scoped_ptr( |
| 330 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 331 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
| 332 | sublayer->SetContentsScale(kPageScale * kDeviceScale, |
| 333 | kPageScale * kDeviceScale); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 334 | SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(), |
| 335 | gfx::PointF(), gfx::Size(500, 500), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 336 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 337 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 338 | scoped_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 339 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 340 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 341 | SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(), |
| 342 | gfx::PointF(), gfx::Size(10, 20), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 343 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 344 | scoped_ptr<LayerImpl> clip_layer_scoped_ptr( |
| 345 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 346 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 347 | |
| 348 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 349 | clip_layer->SetBounds( |
| 350 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 351 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 352 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 353 | scroll_layer->SetScrollDelta(kScrollDelta); |
| 354 | gfx::Transform impl_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 355 | scroll_layer->AddChild(sublayer_scoped_ptr.Pass()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 356 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
| 357 | clip_layer->AddChild(scroll_layer_scoped_ptr.Pass()); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 358 | scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 359 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 360 | scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 361 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 362 | gfx::PointF(), gfx::Size(3, 4), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 363 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 364 | root->AddChild(clip_layer_scoped_ptr.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 365 | root->SetHasRenderSurface(true); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 366 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 367 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 368 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 369 | gfx::Transform expected_transform = identity_matrix; |
| 370 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
| 371 | sub_layer_screen_position.Scale(kPageScale * kDeviceScale); |
| 372 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()), |
| 373 | MathUtil::Round(sub_layer_screen_position.y())); |
| 374 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 375 | sublayer->draw_transform()); |
| 376 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 377 | sublayer->screen_space_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 378 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 379 | gfx::Transform arbitrary_translate; |
| 380 | const float kTranslateX = 10.6f; |
| 381 | const float kTranslateY = 20.6f; |
| 382 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 383 | SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate, |
| 384 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20), |
| 385 | true, false, false); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 386 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 387 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 388 | expected_transform.MakeIdentity(); |
| 389 | expected_transform.Translate( |
| 390 | MathUtil::Round(kTranslateX * kPageScale * kDeviceScale + |
| 391 | sub_layer_screen_position.x()), |
| 392 | MathUtil::Round(kTranslateY * kPageScale * kDeviceScale + |
| 393 | sub_layer_screen_position.y())); |
| 394 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 395 | sublayer->draw_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 396 | } |
| 397 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 398 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 399 | gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 400 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 401 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 402 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 403 | scoped_refptr<Layer> grand_child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 404 | root->AddChild(parent); |
| 405 | parent->AddChild(child); |
| 406 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 407 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 408 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 409 | host->SetRootLayer(root); |
| 410 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 411 | // One-time setup of root layer |
| 412 | SetLayerPropertiesForTesting(root.get(), |
| 413 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 414 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 415 | gfx::PointF(), |
| 416 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 417 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 418 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 419 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 420 | // Case 1: parent's anchor point should not affect child or grand_child. |
| 421 | SetLayerPropertiesForTesting(parent.get(), |
| 422 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 423 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 424 | gfx::PointF(), |
| 425 | gfx::Size(10, 12), |
[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(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(16, 18), |
[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 | SetLayerPropertiesForTesting(grand_child.get(), |
| 436 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 437 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 438 | gfx::PointF(), |
| 439 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 440 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 441 | false); |
| 442 | ExecuteCalculateDrawProperties(root.get()); |
| 443 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 444 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 445 | child->screen_space_transform()); |
| 446 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 447 | grand_child->draw_transform()); |
| 448 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 449 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 450 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 451 | // Case 2: parent's position affects child and grand_child. |
| 452 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 453 | parent_position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 454 | SetLayerPropertiesForTesting(parent.get(), |
| 455 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 456 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 457 | gfx::PointF(0.f, 1.2f), |
| 458 | gfx::Size(10, 12), |
[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(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(16, 18), |
[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 | SetLayerPropertiesForTesting(grand_child.get(), |
| 469 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 470 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 471 | gfx::PointF(), |
| 472 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 473 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 474 | false); |
| 475 | ExecuteCalculateDrawProperties(root.get()); |
| 476 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 477 | child->draw_transform()); |
| 478 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 479 | child->screen_space_transform()); |
| 480 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 481 | grand_child->draw_transform()); |
| 482 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 483 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 484 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 485 | // Case 3: parent's local transform affects child and grandchild |
| 486 | gfx::Transform parent_layer_transform; |
| 487 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 488 | gfx::Transform parent_translation_to_anchor; |
| 489 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 490 | gfx::Transform parent_composite_transform = |
| 491 | parent_translation_to_anchor * parent_layer_transform * |
| 492 | Inverse(parent_translation_to_anchor); |
| 493 | SetLayerPropertiesForTesting(parent.get(), |
| 494 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 495 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 496 | gfx::PointF(), |
| 497 | gfx::Size(10, 12), |
[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(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(16, 18), |
[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 | SetLayerPropertiesForTesting(grand_child.get(), |
| 508 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 509 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 510 | gfx::PointF(), |
| 511 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 512 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 513 | false); |
| 514 | ExecuteCalculateDrawProperties(root.get()); |
| 515 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 516 | child->draw_transform()); |
| 517 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 518 | child->screen_space_transform()); |
| 519 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 520 | grand_child->draw_transform()); |
| 521 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 522 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 523 | } |
| 524 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 525 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 526 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 527 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 528 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 529 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 530 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 531 | root->AddChild(parent); |
| 532 | parent->AddChild(child); |
| 533 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 534 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 535 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 536 | host->SetRootLayer(root); |
| 537 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 538 | // One-time setup of root layer |
| 539 | gfx::Transform identity_matrix; |
| 540 | SetLayerPropertiesForTesting(root.get(), |
| 541 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 542 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 543 | gfx::PointF(), |
| 544 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 545 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 546 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 547 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 548 | // Child is set up so that a new render surface should be created. |
| 549 | child->SetOpacity(0.5f); |
| 550 | child->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 551 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 552 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 553 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 554 | gfx::Transform parent_translation_to_anchor; |
| 555 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 556 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 557 | gfx::Transform parent_composite_transform = |
| 558 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 559 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 560 | gfx::Vector2dF parent_composite_scale = |
| 561 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 562 | 1.f); |
| 563 | gfx::Transform surface_sublayer_transform; |
| 564 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 565 | parent_composite_scale.y()); |
| 566 | gfx::Transform surface_sublayer_composite_transform = |
| 567 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 568 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 569 | // Child's render surface should not exist yet. |
| 570 | ASSERT_FALSE(child->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 571 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 572 | SetLayerPropertiesForTesting(parent.get(), |
| 573 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 574 | gfx::Point3F(25.0f, 30.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 575 | gfx::PointF(), |
| 576 | gfx::Size(100, 120), |
[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(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(16, 18), |
[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 | SetLayerPropertiesForTesting(grand_child.get(), |
| 587 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 588 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 589 | gfx::PointF(), |
| 590 | gfx::Size(8, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 591 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 592 | false); |
| 593 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 594 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 595 | // Render surface should have been created now. |
| 596 | ASSERT_TRUE(child->render_surface()); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 597 | ASSERT_EQ(child.get(), child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 598 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 599 | // The child layer's draw transform should refer to its new render surface. |
| 600 | // The screen-space transform, however, should still refer to the root. |
| 601 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
| 602 | child->draw_transform()); |
| 603 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 604 | child->screen_space_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 | // Because the grand_child is the only drawable content, the child's render |
| 607 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 608 | // surface's subtree is drawn must be removed from the composite transform. |
| 609 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 610 | surface_sublayer_composite_transform, |
| 611 | child->render_target()->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 612 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 613 | // The screen space is the same as the target since the child surface draws |
| 614 | // into the root. |
| 615 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 616 | surface_sublayer_composite_transform, |
| 617 | child->render_target()->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 618 | } |
| 619 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 620 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 621 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 622 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 623 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 624 | scoped_refptr<Layer> child_replica = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 625 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 626 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 627 | root->AddChild(parent); |
| 628 | parent->AddChild(child); |
| 629 | child->AddChild(grand_child); |
| 630 | child->SetReplicaLayer(child_replica.get()); |
| 631 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 632 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 633 | host->SetRootLayer(root); |
| 634 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 635 | // One-time setup of root layer |
| 636 | gfx::Transform identity_matrix; |
| 637 | SetLayerPropertiesForTesting(root.get(), |
| 638 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 639 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 640 | gfx::PointF(), |
| 641 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 642 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 643 | false); |
| 644 | |
| 645 | // Child is set up so that a new render surface should be created. |
| 646 | child->SetOpacity(0.5f); |
| 647 | |
| 648 | gfx::Transform parent_layer_transform; |
| 649 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 650 | gfx::Transform parent_translation_to_anchor; |
| 651 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 652 | gfx::Transform parent_composite_transform = |
| 653 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 654 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 655 | gfx::Transform replica_layer_transform; |
| 656 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 657 | gfx::Vector2dF parent_composite_scale = |
| 658 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 659 | 1.f); |
| 660 | gfx::Transform surface_sublayer_transform; |
| 661 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 662 | parent_composite_scale.y()); |
| 663 | gfx::Transform replica_composite_transform = |
| 664 | parent_composite_transform * replica_layer_transform * |
| 665 | Inverse(surface_sublayer_transform); |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 666 | child_replica->SetIsDrawable(true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 667 | // Child's render surface should not exist yet. |
| 668 | ASSERT_FALSE(child->render_surface()); |
| 669 | |
| 670 | SetLayerPropertiesForTesting(parent.get(), |
| 671 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 672 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 673 | gfx::PointF(), |
| 674 | gfx::Size(10, 12), |
[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(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(), |
| 681 | gfx::Size(16, 18), |
[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(grand_child.get(), |
| 685 | identity_matrix, |
[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(-0.5f, -0.5f), |
| 688 | gfx::Size(1, 1), |
[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 | SetLayerPropertiesForTesting(child_replica.get(), |
| 692 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 693 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 694 | gfx::PointF(), |
| 695 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 696 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 697 | false); |
| 698 | ExecuteCalculateDrawProperties(root.get()); |
| 699 | |
| 700 | // Render surface should have been created now. |
| 701 | ASSERT_TRUE(child->render_surface()); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 702 | ASSERT_EQ(child.get(), child->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 703 | |
| 704 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 705 | replica_composite_transform, |
| 706 | child->render_target()->render_surface()->replica_draw_transform()); |
| 707 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 708 | child->render_target() |
| 709 | ->render_surface() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 710 | ->replica_screen_space_transform()); |
| 711 | } |
| 712 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 713 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 714 | // This test creates a more complex tree and verifies it all at once. This |
| 715 | // covers the following cases: |
| 716 | // - layers that are described w.r.t. a render surface: should have draw |
| 717 | // transforms described w.r.t. that surface |
| 718 | // - A render surface described w.r.t. an ancestor render surface: should |
| 719 | // have a draw transform described w.r.t. that ancestor surface |
| 720 | // - Replicas of a render surface are described w.r.t. the replica's |
| 721 | // transform around its anchor, along with the surface itself. |
| 722 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 723 | // a render surface that is described w.r.t. an ancestor render surface. |
| 724 | // - verifying that each layer has a reference to the correct render surface |
| 725 | // and render target values. |
| 726 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 727 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 728 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 729 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
| 730 | scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings()); |
| 731 | scoped_refptr<Layer> child_of_root = Layer::Create(layer_settings()); |
| 732 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(layer_settings()); |
| 733 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(layer_settings()); |
| 734 | scoped_refptr<Layer> replica_of_rs1 = Layer::Create(layer_settings()); |
| 735 | scoped_refptr<Layer> replica_of_rs2 = Layer::Create(layer_settings()); |
| 736 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 737 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 738 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 739 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 740 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 741 | root->AddChild(parent); |
| 742 | parent->AddChild(render_surface1); |
| 743 | parent->AddChild(child_of_root); |
| 744 | render_surface1->AddChild(child_of_rs1); |
| 745 | render_surface1->AddChild(render_surface2); |
| 746 | render_surface2->AddChild(child_of_rs2); |
| 747 | child_of_root->AddChild(grand_child_of_root); |
| 748 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 749 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 750 | render_surface1->SetReplicaLayer(replica_of_rs1.get()); |
| 751 | render_surface2->SetReplicaLayer(replica_of_rs2.get()); |
| 752 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 753 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 754 | host->SetRootLayer(root); |
| 755 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 756 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 757 | // to have a new render surface. |
| 758 | render_surface1->SetOpacity(0.5f); |
| 759 | render_surface2->SetOpacity(0.33f); |
| 760 | |
| 761 | // One-time setup of root layer |
| 762 | gfx::Transform identity_matrix; |
| 763 | SetLayerPropertiesForTesting(root.get(), |
| 764 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 765 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 766 | gfx::PointF(), |
| 767 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 768 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 769 | false); |
| 770 | |
| 771 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 772 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 773 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 774 | gfx::Transform translation_to_anchor; |
| 775 | translation_to_anchor.Translate(2.5, 0.0); |
| 776 | gfx::Transform layer_transform; |
| 777 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 778 | gfx::Transform replica_layer_transform; |
| 779 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 780 | |
| 781 | gfx::Transform A = |
| 782 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 783 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 784 | Inverse(translation_to_anchor); |
| 785 | |
| 786 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 787 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 788 | gfx::Transform surface1_sublayer_transform; |
| 789 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 790 | surface1_parent_transform_scale.y()); |
| 791 | |
| 792 | // SS1 = transform given to the subtree of render_surface1 |
| 793 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 794 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 795 | // the owning layer |
| 796 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 797 | |
| 798 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 799 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 800 | gfx::Transform surface2_sublayer_transform; |
| 801 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 802 | surface2_parent_transform_scale.y()); |
| 803 | |
| 804 | // SS2 = transform given to the subtree of render_surface2 |
| 805 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 806 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 807 | // the owning layer |
| 808 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 809 | |
| 810 | SetLayerPropertiesForTesting(parent.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_surface1.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(render_surface2.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_root.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_rs1.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(child_of_rs2.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_root.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_rs1.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(grand_child_of_rs2.get(), |
| 867 | 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(10, 10), |
[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_rs1.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 | SetLayerPropertiesForTesting(replica_of_rs2.get(), |
| 881 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 882 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 883 | gfx::PointF(), |
| 884 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 885 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 886 | false); |
| 887 | |
| 888 | ExecuteCalculateDrawProperties(root.get()); |
| 889 | |
| 890 | // Only layers that are associated with render surfaces should have an actual |
| 891 | // RenderSurface() value. |
| 892 | ASSERT_TRUE(root->render_surface()); |
| 893 | ASSERT_FALSE(child_of_root->render_surface()); |
| 894 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 895 | |
| 896 | ASSERT_TRUE(render_surface1->render_surface()); |
| 897 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 898 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 899 | |
| 900 | ASSERT_TRUE(render_surface2->render_surface()); |
| 901 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 902 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 903 | |
| 904 | // Verify all render target accessors |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 905 | EXPECT_EQ(root.get(), parent->render_target()); |
| 906 | EXPECT_EQ(root.get(), child_of_root->render_target()); |
| 907 | EXPECT_EQ(root.get(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 908 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 909 | EXPECT_EQ(render_surface1.get(), render_surface1->render_target()); |
| 910 | EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target()); |
| 911 | EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 912 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 913 | EXPECT_EQ(render_surface2.get(), render_surface2->render_target()); |
| 914 | EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target()); |
| 915 | EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 916 | |
| 917 | // Verify layer draw transforms note that draw transforms are described with |
| 918 | // respect to the nearest ancestor render surface but screen space transforms |
| 919 | // are described with respect to the root. |
| 920 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 921 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform()); |
| 922 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 923 | grand_child_of_root->draw_transform()); |
| 924 | |
| 925 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 926 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform()); |
| 927 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 928 | grand_child_of_rs1->draw_transform()); |
| 929 | |
| 930 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 931 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform()); |
| 932 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 933 | grand_child_of_rs2->draw_transform()); |
| 934 | |
| 935 | // Verify layer screen-space transforms |
| 936 | // |
| 937 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 938 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 939 | child_of_root->screen_space_transform()); |
| 940 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 941 | A * A * A, grand_child_of_root->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 942 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 943 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 944 | render_surface1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 945 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 946 | child_of_rs1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 947 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 948 | grand_child_of_rs1->screen_space_transform()); |
| 949 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 950 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 951 | render_surface2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 952 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 953 | child_of_rs2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 954 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 955 | grand_child_of_rs2->screen_space_transform()); |
| 956 | |
| 957 | // Verify render surface transforms. |
| 958 | // |
| 959 | // Draw transform of render surface 1 is described with respect to root. |
| 960 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 961 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 962 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 963 | A * R * S1, render_surface1->render_surface()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 964 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 965 | A * A * S1, render_surface1->render_surface()->screen_space_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 | A * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 968 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 969 | // Draw transform of render surface 2 is described with respect to render |
| 970 | // surface 1. |
| 971 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 972 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 973 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 974 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 975 | render_surface2->render_surface()->replica_draw_transform()); |
| 976 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 977 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 978 | render_surface2->render_surface()->screen_space_transform()); |
| 979 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 980 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 981 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 982 | |
| 983 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 984 | // is expected that we correctly set up transforms so that the y-component of |
| 985 | // the screen-space transform encodes the "depth" of the layer in the tree. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 986 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 987 | EXPECT_FLOAT_EQ(2.0, |
| 988 | child_of_root->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 | 3.0, grand_child_of_root->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(2.0, |
| 993 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 994 | EXPECT_FLOAT_EQ(3.0, |
| 995 | child_of_rs1->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 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 998 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 999 | EXPECT_FLOAT_EQ(3.0, |
| 1000 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 1001 | EXPECT_FLOAT_EQ(4.0, |
| 1002 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1003 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1004 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1005 | } |
| 1006 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1007 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1008 | // For layers that flatten their subtree, there should be an orthographic |
| 1009 | // projection (for x and y values) in the middle of the transform sequence. |
| 1010 | // Note that the way the code is currently implemented, it is not expected to |
| 1011 | // use a canonical orthographic projection. |
| 1012 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1013 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 1014 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1015 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1016 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1017 | scoped_refptr<LayerWithForcedDrawsContent> great_grand_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1018 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1019 | |
| 1020 | gfx::Transform rotation_about_y_axis; |
| 1021 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1022 | |
| 1023 | const gfx::Transform identity_matrix; |
| 1024 | SetLayerPropertiesForTesting(root.get(), |
| 1025 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1026 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1027 | gfx::PointF(), |
| 1028 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1029 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1030 | false); |
| 1031 | SetLayerPropertiesForTesting(child.get(), |
| 1032 | rotation_about_y_axis, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1033 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1034 | gfx::PointF(), |
| 1035 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1036 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1037 | false); |
| 1038 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1039 | rotation_about_y_axis, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1040 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1041 | gfx::PointF(), |
| 1042 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1043 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1044 | false); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1045 | SetLayerPropertiesForTesting(great_grand_child.get(), identity_matrix, |
| 1046 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1047 | true, false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1048 | |
| 1049 | root->AddChild(child); |
| 1050 | child->AddChild(grand_child); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1051 | grand_child->AddChild(great_grand_child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1052 | child->SetForceRenderSurface(true); |
| 1053 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1054 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1055 | host->SetRootLayer(root); |
| 1056 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1057 | // No layers in this test should preserve 3d. |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1058 | ASSERT_TRUE(root->should_flatten_transform()); |
| 1059 | ASSERT_TRUE(child->should_flatten_transform()); |
| 1060 | ASSERT_TRUE(grand_child->should_flatten_transform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1061 | ASSERT_TRUE(great_grand_child->should_flatten_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1062 | |
| 1063 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1064 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1065 | gfx::Transform expected_grand_child_draw_transform = |
| 1066 | rotation_about_y_axis; // draws onto child's render surface |
| 1067 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1068 | flattened_rotation_about_y.FlattenTo2d(); |
| 1069 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1070 | flattened_rotation_about_y * rotation_about_y_axis; |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1071 | gfx::Transform expected_great_grand_child_draw_transform = |
| 1072 | flattened_rotation_about_y; |
| 1073 | gfx::Transform expected_great_grand_child_screen_space_transform = |
| 1074 | flattened_rotation_about_y * flattened_rotation_about_y; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1075 | |
| 1076 | ExecuteCalculateDrawProperties(root.get()); |
| 1077 | |
| 1078 | // The child's draw transform should have been taken by its surface. |
| 1079 | ASSERT_TRUE(child->render_surface()); |
| 1080 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1081 | child->render_surface()->draw_transform()); |
| 1082 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1083 | expected_child_screen_space_transform, |
| 1084 | child->render_surface()->screen_space_transform()); |
| 1085 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1086 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
| 1087 | child->screen_space_transform()); |
| 1088 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
| 1089 | grand_child->draw_transform()); |
| 1090 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
| 1091 | grand_child->screen_space_transform()); |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 1092 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform, |
| 1093 | great_grand_child->draw_transform()); |
| 1094 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1095 | expected_great_grand_child_screen_space_transform, |
| 1096 | great_grand_child->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1097 | } |
| 1098 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1099 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1100 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1101 | // skipping a necessary translation. Without that translation, the coordinate |
| 1102 | // space of the layer's draw transform is incorrect. |
| 1103 | // |
| 1104 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1105 | // but if that layer becomes a render surface, then its draw transform is |
| 1106 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1107 | // incorrectly as a result. |
| 1108 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1109 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 1110 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1111 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1112 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1113 | |
| 1114 | // The child height is zero, but has non-zero width that should be accounted |
| 1115 | // for while computing draw transforms. |
| 1116 | const gfx::Transform identity_matrix; |
| 1117 | SetLayerPropertiesForTesting(root.get(), |
| 1118 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1119 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1120 | gfx::PointF(), |
| 1121 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1122 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1123 | false); |
| 1124 | SetLayerPropertiesForTesting(child.get(), |
| 1125 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1126 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1127 | gfx::PointF(), |
| 1128 | gfx::Size(10, 0), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1129 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1130 | false); |
| 1131 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1132 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1133 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1134 | gfx::PointF(), |
| 1135 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1136 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1137 | false); |
| 1138 | |
| 1139 | root->AddChild(child); |
| 1140 | child->AddChild(grand_child); |
| 1141 | child->SetForceRenderSurface(true); |
| 1142 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1143 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1144 | host->SetRootLayer(root); |
| 1145 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1146 | ExecuteCalculateDrawProperties(root.get()); |
| 1147 | |
| 1148 | ASSERT_TRUE(child->render_surface()); |
| 1149 | // This is the real test, the rest are sanity checks. |
| 1150 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1151 | child->render_surface()->draw_transform()); |
| 1152 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1153 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1154 | grand_child->draw_transform()); |
| 1155 | } |
| 1156 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1157 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1158 | // Transformations applied at the root of the tree should be forwarded |
| 1159 | // to child layers instead of applied to the root RenderSurface. |
| 1160 | const gfx::Transform identity_matrix; |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1161 | scoped_refptr<LayerWithForcedDrawsContent> root = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1162 | new LayerWithForcedDrawsContent(layer_settings()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1163 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1164 | new LayerWithForcedDrawsContent(layer_settings()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1165 | child->SetScrollClipLayerId(root->id()); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1166 | root->AddChild(child); |
| 1167 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1168 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1169 | host->SetRootLayer(root); |
| 1170 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1171 | SetLayerPropertiesForTesting(root.get(), |
| 1172 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1173 | gfx::Point3F(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1174 | gfx::PointF(), |
| 1175 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1176 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1177 | false); |
| 1178 | SetLayerPropertiesForTesting(child.get(), |
| 1179 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1180 | gfx::Point3F(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1181 | gfx::PointF(), |
| 1182 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1183 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1184 | false); |
| 1185 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1186 | gfx::Transform translate; |
| 1187 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1188 | { |
| 1189 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1190 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1191 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1192 | inputs.can_adjust_raster_scales = true; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1193 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1194 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1195 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1196 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1197 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1198 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1199 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1200 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1201 | |
| 1202 | gfx::Transform scale; |
| 1203 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1204 | { |
| 1205 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1206 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1207 | root.get(), root->bounds(), scale, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1208 | inputs.can_adjust_raster_scales = true; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1209 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1210 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1211 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1212 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1213 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1214 | EXPECT_EQ(2.f, root->draw_properties().device_scale_factor); |
| 1215 | EXPECT_EQ(2.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1216 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1217 | |
| 1218 | gfx::Transform rotate; |
| 1219 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1220 | { |
| 1221 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1222 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1223 | root.get(), root->bounds(), rotate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1224 | inputs.can_adjust_raster_scales = true; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1225 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1226 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1227 | EXPECT_EQ(rotate, root->draw_properties().target_space_transform); |
| 1228 | EXPECT_EQ(rotate, child->draw_properties().target_space_transform); |
| 1229 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1230 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1231 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1232 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1233 | |
| 1234 | gfx::Transform composite; |
| 1235 | composite.ConcatTransform(translate); |
| 1236 | composite.ConcatTransform(scale); |
| 1237 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1238 | { |
| 1239 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1240 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1241 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1242 | inputs.can_adjust_raster_scales = true; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1243 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1244 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1245 | EXPECT_EQ(composite, root->draw_properties().target_space_transform); |
| 1246 | EXPECT_EQ(composite, child->draw_properties().target_space_transform); |
| 1247 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1248 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1249 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1250 | // Verify it composes correctly with device scale. |
| 1251 | float device_scale_factor = 1.5f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1252 | |
| 1253 | { |
| 1254 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1255 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1256 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1257 | inputs.device_scale_factor = device_scale_factor; |
| 1258 | inputs.can_adjust_raster_scales = true; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1259 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1260 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1261 | gfx::Transform device_scaled_translate = translate; |
| 1262 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1263 | EXPECT_EQ(device_scaled_translate, |
| 1264 | root->draw_properties().target_space_transform); |
| 1265 | EXPECT_EQ(device_scaled_translate, |
| 1266 | child->draw_properties().target_space_transform); |
| 1267 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1268 | EXPECT_EQ(device_scale_factor, root->draw_properties().device_scale_factor); |
| 1269 | EXPECT_EQ(device_scale_factor, |
| 1270 | child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1271 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1272 | |
| 1273 | // Verify it composes correctly with page scale. |
| 1274 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1275 | |
| 1276 | { |
| 1277 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1278 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1279 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1280 | inputs.page_scale_factor = page_scale_factor; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 1281 | inputs.page_scale_layer = root.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1282 | inputs.can_adjust_raster_scales = true; |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 1283 | inputs.property_trees->needs_rebuild = true; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1284 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1285 | gfx::Transform page_scaled_translate = translate; |
| 1286 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 1287 | EXPECT_EQ(page_scaled_translate, |
| 1288 | root->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1289 | EXPECT_EQ(page_scaled_translate, |
| 1290 | child->draw_properties().target_space_transform); |
| 1291 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | 3532235 | 2014-08-08 01:36:20 | [diff] [blame] | 1292 | EXPECT_EQ(1.f, root->draw_properties().device_scale_factor); |
| 1293 | EXPECT_EQ(1.f, child->draw_properties().device_scale_factor); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1294 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1295 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1296 | // Verify that it composes correctly with transforms directly on root layer. |
| 1297 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1298 | |
| 1299 | { |
| 1300 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1301 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 1302 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1303 | inputs.can_adjust_raster_scales = true; |
| 1304 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1305 | gfx::Transform compositeSquared = composite; |
| 1306 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1307 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1308 | compositeSquared, root->draw_properties().target_space_transform); |
| 1309 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1310 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1311 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1312 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1313 | } |
| 1314 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1315 | TEST_F(LayerTreeHostCommonTest, |
| 1316 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1317 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 1318 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1319 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1320 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1321 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1322 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1323 | host->SetRootLayer(parent); |
| 1324 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1325 | const gfx::Transform identity_matrix; |
| 1326 | SetLayerPropertiesForTesting(parent.get(), |
| 1327 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1328 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1329 | gfx::PointF(), |
| 1330 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1331 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1332 | false); |
| 1333 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1334 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1335 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1336 | gfx::PointF(), |
| 1337 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1338 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1339 | false); |
| 1340 | SetLayerPropertiesForTesting(child.get(), |
| 1341 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1342 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1343 | gfx::PointF(30.f, 30.f), |
| 1344 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1345 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1346 | false); |
| 1347 | |
| 1348 | parent->AddChild(render_surface1); |
| 1349 | parent->SetMasksToBounds(true); |
| 1350 | render_surface1->AddChild(child); |
| 1351 | render_surface1->SetForceRenderSurface(true); |
| 1352 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1353 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1354 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1355 | parent.get(), |
| 1356 | parent->bounds(), |
| 1357 | gfx::Transform(), |
| 1358 | &render_surface_layer_list); |
| 1359 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1360 | |
| 1361 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1362 | // the intermediate render surface should not be listed here, even if it was |
| 1363 | // forced to be created. Render surfaces without children or visible content |
| 1364 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1365 | // of size 0). |
| 1366 | ASSERT_TRUE(parent->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1367 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1368 | } |
| 1369 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1370 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1371 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 1372 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1373 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1374 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1375 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1376 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1377 | host->SetRootLayer(parent); |
| 1378 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1379 | const gfx::Transform identity_matrix; |
| 1380 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1381 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1382 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1383 | gfx::PointF(), |
| 1384 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1385 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1386 | false); |
| 1387 | SetLayerPropertiesForTesting(child.get(), |
| 1388 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1389 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1390 | gfx::PointF(), |
| 1391 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1392 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1393 | false); |
| 1394 | |
| 1395 | parent->AddChild(render_surface1); |
| 1396 | render_surface1->AddChild(child); |
| 1397 | render_surface1->SetForceRenderSurface(true); |
| 1398 | render_surface1->SetOpacity(0.f); |
| 1399 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1400 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1401 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1402 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1403 | inputs.can_adjust_raster_scales = true; |
| 1404 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1405 | |
| 1406 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1407 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1408 | // have been extended by the children. |
| 1409 | ASSERT_TRUE(parent->render_surface()); |
| 1410 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1411 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1412 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1413 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1414 | } |
| 1415 | |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1416 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1417 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1418 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1419 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
rosca | 948d29d | 2014-11-09 10:25:13 | [diff] [blame] | 1420 | |
| 1421 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 1422 | host->SetRootLayer(parent); |
| 1423 | |
| 1424 | const gfx::Transform identity_matrix; |
| 1425 | const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode; |
| 1426 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 1427 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1428 | |
| 1429 | parent->AddChild(child); |
| 1430 | child->SetBlendMode(blend_mode); |
| 1431 | |
| 1432 | RenderSurfaceLayerList render_surface_layer_list; |
| 1433 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1434 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1435 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 1436 | |
| 1437 | // Since the child layer has a blend mode other than normal, it should get |
| 1438 | // its own render surface. Also, layer's draw_properties should contain the |
| 1439 | // default blend mode, since the render surface becomes responsible for |
| 1440 | // applying the blend mode. |
| 1441 | ASSERT_TRUE(child->render_surface()); |
| 1442 | EXPECT_EQ(1U, child->render_surface()->layer_list().size()); |
| 1443 | EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_properties().blend_mode); |
| 1444 | } |
| 1445 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1446 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1447 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 1448 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1449 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1450 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1451 | render_surface1->SetForceRenderSurface(true); |
| 1452 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1453 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1454 | host->SetRootLayer(parent); |
| 1455 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1456 | const gfx::Transform identity_matrix; |
| 1457 | SetLayerPropertiesForTesting(parent.get(), |
| 1458 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1459 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1460 | gfx::PointF(), |
| 1461 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1462 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1463 | false); |
| 1464 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1465 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1466 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1467 | gfx::PointF(), |
| 1468 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1469 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1470 | false); |
| 1471 | SetLayerPropertiesForTesting(child.get(), |
| 1472 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1473 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1474 | gfx::PointF(), |
| 1475 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1476 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1477 | false); |
| 1478 | |
| 1479 | parent->AddChild(render_surface1); |
| 1480 | render_surface1->AddChild(child); |
| 1481 | |
| 1482 | // Sanity check before the actual test |
| 1483 | EXPECT_FALSE(parent->render_surface()); |
| 1484 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1485 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1486 | { |
| 1487 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1488 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1489 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1490 | inputs.can_adjust_raster_scales = true; |
| 1491 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1492 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1493 | // The root layer always creates a render surface |
| 1494 | EXPECT_TRUE(parent->render_surface()); |
| 1495 | EXPECT_TRUE(render_surface1->render_surface()); |
| 1496 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1497 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1498 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1499 | { |
| 1500 | RenderSurfaceLayerList render_surface_layer_list; |
| 1501 | render_surface1->SetForceRenderSurface(false); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1502 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1503 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1504 | inputs.can_adjust_raster_scales = true; |
| 1505 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1506 | EXPECT_TRUE(parent->render_surface()); |
| 1507 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1508 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1509 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1510 | } |
| 1511 | |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1512 | TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) { |
| 1513 | // Render surfaces act as a flattening point for their subtree, so should |
| 1514 | // always flatten the target-to-screen space transform seen by descendants. |
| 1515 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1516 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 1517 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1518 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1519 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1520 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1521 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | 246190a | 2015-03-11 20:56:03 | [diff] [blame] | 1522 | |
| 1523 | gfx::Transform rotation_about_y_axis; |
| 1524 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1525 | // Make |parent| have a render surface. |
| 1526 | parent->SetOpacity(0.9f); |
| 1527 | |
| 1528 | const gfx::Transform identity_matrix; |
| 1529 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 1530 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 1531 | SetLayerPropertiesForTesting(parent.get(), rotation_about_y_axis, |
| 1532 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1533 | true, false); |
| 1534 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 1535 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 1536 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 1537 | gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10), |
| 1538 | true, false); |
| 1539 | |
| 1540 | root->AddChild(parent); |
| 1541 | parent->AddChild(child); |
| 1542 | child->AddChild(grand_child); |
| 1543 | |
| 1544 | grand_child->SetShouldFlattenTransform(false); |
| 1545 | |
| 1546 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 1547 | host->SetRootLayer(root); |
| 1548 | |
| 1549 | // Only grand_child should preserve 3d. |
| 1550 | EXPECT_TRUE(root->should_flatten_transform()); |
| 1551 | EXPECT_TRUE(parent->should_flatten_transform()); |
| 1552 | EXPECT_TRUE(child->should_flatten_transform()); |
| 1553 | EXPECT_FALSE(grand_child->should_flatten_transform()); |
| 1554 | |
| 1555 | gfx::Transform expected_child_draw_transform = identity_matrix; |
| 1556 | gfx::Transform expected_grand_child_draw_transform = identity_matrix; |
| 1557 | |
| 1558 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1559 | flattened_rotation_about_y.FlattenTo2d(); |
| 1560 | |
| 1561 | ExecuteCalculateDrawProperties(root.get()); |
| 1562 | |
| 1563 | EXPECT_TRUE(parent->render_surface()); |
| 1564 | EXPECT_FALSE(child->render_surface()); |
| 1565 | EXPECT_FALSE(grand_child->render_surface()); |
| 1566 | |
| 1567 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1568 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1569 | grand_child->draw_transform()); |
| 1570 | |
| 1571 | // The screen-space transform inherited by |child| and |grand_child| should |
| 1572 | // have been flattened at their render target. In particular, the fact that |
| 1573 | // |grand_child| happens to preserve 3d shouldn't affect this flattening. |
| 1574 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
| 1575 | child->screen_space_transform()); |
| 1576 | EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y, |
| 1577 | grand_child->screen_space_transform()); |
| 1578 | } |
| 1579 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1580 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1581 | // The entire subtree of layers that are outside the clip rect should be |
| 1582 | // culled away, and should not affect the render_surface_layer_list. |
| 1583 | // |
| 1584 | // The test tree is set up as follows: |
| 1585 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1586 | // that have something to draw. |
| 1587 | // - parent is a large container layer. |
| 1588 | // - child has masksToBounds=true to cause clipping. |
| 1589 | // - grand_child is positioned outside of the child's bounds |
| 1590 | // - great_grand_child is also kept outside child's bounds. |
| 1591 | // |
| 1592 | // In this configuration, grand_child and great_grand_child are completely |
| 1593 | // outside the clip rect, and they should never get scheduled on the list of |
| 1594 | // render surfaces. |
| 1595 | // |
| 1596 | |
| 1597 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1598 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 1599 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 1600 | scoped_refptr<Layer> grand_child = Layer::Create(layer_settings()); |
| 1601 | scoped_refptr<Layer> great_grand_child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1602 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1603 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1604 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1605 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1606 | parent->AddChild(child); |
| 1607 | child->AddChild(grand_child); |
| 1608 | grand_child->AddChild(great_grand_child); |
| 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 | // leaf_node1 ensures that parent and child are kept on the |
| 1614 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1615 | // should be clipped. |
| 1616 | child->AddChild(leaf_node1); |
| 1617 | great_grand_child->AddChild(leaf_node2); |
| 1618 | |
| 1619 | SetLayerPropertiesForTesting(parent.get(), |
| 1620 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1621 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1622 | gfx::PointF(), |
| 1623 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1624 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1625 | false); |
| 1626 | SetLayerPropertiesForTesting(child.get(), |
| 1627 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1628 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1629 | gfx::PointF(), |
| 1630 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1631 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1632 | false); |
| 1633 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1634 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1635 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1636 | gfx::PointF(45.f, 45.f), |
| 1637 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1638 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1639 | false); |
| 1640 | SetLayerPropertiesForTesting(great_grand_child.get(), |
| 1641 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1642 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1643 | gfx::PointF(), |
| 1644 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1645 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1646 | false); |
| 1647 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1648 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1649 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1650 | gfx::PointF(), |
| 1651 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1652 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1653 | false); |
| 1654 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1655 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1656 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1657 | gfx::PointF(), |
| 1658 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1659 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1660 | false); |
| 1661 | |
| 1662 | child->SetMasksToBounds(true); |
| 1663 | child->SetOpacity(0.4f); |
| 1664 | child->SetForceRenderSurface(true); |
| 1665 | grand_child->SetOpacity(0.5f); |
| 1666 | great_grand_child->SetOpacity(0.4f); |
| 1667 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1668 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1669 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1670 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1671 | inputs.can_adjust_raster_scales = true; |
| 1672 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1673 | |
| 1674 | ASSERT_EQ(2U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1675 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1676 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1677 | } |
| 1678 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1679 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1680 | // When a render surface has a clip rect, it is used to clip the content rect |
| 1681 | // of the surface. When the render surface is animating its transforms, then |
| 1682 | // the content rect's position in the clip rect is not defined on the main |
| 1683 | // thread, and its content rect should not be clipped. |
| 1684 | |
| 1685 | // The test tree is set up as follows: |
| 1686 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1687 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1688 | // the parent. |
| 1689 | // - grand_child is a render surface, and the only visible content in child. |
| 1690 | // It is positioned outside of the clip rect from parent. |
| 1691 | |
| 1692 | // In this configuration, grand_child should be outside the clipped |
| 1693 | // content rect of the child, making grand_child not appear in the |
| 1694 | // render_surface_layer_list. However, when we place an animation on the |
| 1695 | // child, this clipping should be avoided and we should keep the grand_child |
| 1696 | // in the render_surface_layer_list. |
| 1697 | |
| 1698 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1699 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 1700 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 1701 | scoped_refptr<Layer> grand_child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1702 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1703 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1704 | parent->AddChild(child); |
| 1705 | child->AddChild(grand_child); |
| 1706 | grand_child->AddChild(leaf_node); |
| 1707 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1708 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1709 | host->SetRootLayer(parent); |
| 1710 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1711 | SetLayerPropertiesForTesting(parent.get(), |
| 1712 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1713 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1714 | gfx::PointF(), |
| 1715 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1716 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1717 | false); |
| 1718 | SetLayerPropertiesForTesting(child.get(), |
| 1719 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1720 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1721 | gfx::PointF(), |
| 1722 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1723 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1724 | false); |
| 1725 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1726 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1727 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1728 | gfx::PointF(200.f, 200.f), |
| 1729 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1730 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1731 | false); |
| 1732 | SetLayerPropertiesForTesting(leaf_node.get(), |
| 1733 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1734 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1735 | gfx::PointF(), |
| 1736 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1737 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1738 | false); |
| 1739 | |
| 1740 | parent->SetMasksToBounds(true); |
| 1741 | child->SetOpacity(0.4f); |
| 1742 | child->SetForceRenderSurface(true); |
| 1743 | grand_child->SetOpacity(0.4f); |
| 1744 | grand_child->SetForceRenderSurface(true); |
| 1745 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1746 | { |
| 1747 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1748 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1749 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1750 | inputs.can_adjust_raster_scales = true; |
| 1751 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1752 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1753 | // Without an animation, we should cull child and grand_child from the |
| 1754 | // render_surface_layer_list. |
| 1755 | ASSERT_EQ(1U, render_surface_layer_list.size()); |
| 1756 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1757 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1758 | |
| 1759 | // Now put an animating transform on child. |
| 1760 | AddAnimatedTransformToController( |
| 1761 | child->layer_animation_controller(), 10.0, 30, 0); |
| 1762 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1763 | { |
| 1764 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1765 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1766 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1767 | inputs.can_adjust_raster_scales = true; |
| 1768 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1769 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1770 | // With an animating transform, we should keep child and grand_child in the |
| 1771 | // render_surface_layer_list. |
| 1772 | ASSERT_EQ(3U, render_surface_layer_list.size()); |
| 1773 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1774 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
| 1775 | EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id()); |
| 1776 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1777 | } |
| 1778 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1779 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1780 | // Layer's IsClipped() property is set to true when: |
| 1781 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1782 | // - the layer is clipped by an ancestor that contributes to the same |
| 1783 | // render target, |
| 1784 | // - a surface is clipped by an ancestor that contributes to the same |
| 1785 | // render target. |
| 1786 | // |
| 1787 | // In particular, for a layer that owns a render surface: |
| 1788 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1789 | // pass that clipped status to the layer itself. |
| 1790 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1791 | // and propagates the clip to the subtree. |
| 1792 | |
| 1793 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1794 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 1795 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 1796 | scoped_refptr<Layer> child1 = Layer::Create(layer_settings()); |
| 1797 | scoped_refptr<Layer> child2 = Layer::Create(layer_settings()); |
| 1798 | scoped_refptr<Layer> grand_child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1799 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1800 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1801 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1802 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1803 | root->AddChild(parent); |
| 1804 | parent->AddChild(child1); |
| 1805 | parent->AddChild(child2); |
| 1806 | child1->AddChild(grand_child); |
| 1807 | child2->AddChild(leaf_node2); |
| 1808 | grand_child->AddChild(leaf_node1); |
| 1809 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 1810 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1811 | host->SetRootLayer(root); |
| 1812 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1813 | child2->SetForceRenderSurface(true); |
| 1814 | |
| 1815 | SetLayerPropertiesForTesting(root.get(), |
| 1816 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1817 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1818 | gfx::PointF(), |
| 1819 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1820 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1821 | false); |
| 1822 | SetLayerPropertiesForTesting(parent.get(), |
| 1823 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1824 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1825 | gfx::PointF(), |
| 1826 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1827 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1828 | false); |
| 1829 | SetLayerPropertiesForTesting(child1.get(), |
| 1830 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1831 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1832 | gfx::PointF(), |
| 1833 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1834 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1835 | false); |
| 1836 | SetLayerPropertiesForTesting(child2.get(), |
| 1837 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1838 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1839 | gfx::PointF(), |
| 1840 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1841 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1842 | false); |
| 1843 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1844 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1845 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1846 | gfx::PointF(), |
| 1847 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1848 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1849 | false); |
| 1850 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1851 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1852 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1853 | gfx::PointF(), |
| 1854 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1855 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1856 | false); |
| 1857 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1858 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1859 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1860 | gfx::PointF(), |
| 1861 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1862 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1863 | false); |
| 1864 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1865 | // Case 1: nothing is clipped except the root render surface. |
| 1866 | { |
| 1867 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1868 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1869 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1870 | inputs.can_adjust_raster_scales = true; |
| 1871 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1872 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1873 | ASSERT_TRUE(root->render_surface()); |
| 1874 | ASSERT_TRUE(child2->render_surface()); |
| 1875 | |
| 1876 | EXPECT_FALSE(root->is_clipped()); |
| 1877 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1878 | EXPECT_FALSE(parent->is_clipped()); |
| 1879 | EXPECT_FALSE(child1->is_clipped()); |
| 1880 | EXPECT_FALSE(child2->is_clipped()); |
| 1881 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1882 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1883 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1884 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1885 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1886 | |
| 1887 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1888 | // surface are clipped. But layers that contribute to child2's surface are |
| 1889 | // not clipped explicitly because child2's surface already accounts for |
| 1890 | // that clip. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1891 | { |
| 1892 | RenderSurfaceLayerList render_surface_layer_list; |
| 1893 | parent->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1894 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1895 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1896 | inputs.can_adjust_raster_scales = true; |
| 1897 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1898 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1899 | ASSERT_TRUE(root->render_surface()); |
| 1900 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1901 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1902 | EXPECT_FALSE(root->is_clipped()); |
| 1903 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1904 | EXPECT_TRUE(parent->is_clipped()); |
| 1905 | EXPECT_TRUE(child1->is_clipped()); |
| 1906 | EXPECT_FALSE(child2->is_clipped()); |
| 1907 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1908 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1909 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1910 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1911 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1912 | |
| 1913 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1914 | // child2's render surface is not clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1915 | { |
| 1916 | RenderSurfaceLayerList render_surface_layer_list; |
| 1917 | parent->SetMasksToBounds(false); |
| 1918 | child2->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1919 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1920 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1921 | inputs.can_adjust_raster_scales = true; |
| 1922 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1923 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1924 | ASSERT_TRUE(root->render_surface()); |
| 1925 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1926 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1927 | EXPECT_FALSE(root->is_clipped()); |
| 1928 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1929 | EXPECT_FALSE(parent->is_clipped()); |
| 1930 | EXPECT_FALSE(child1->is_clipped()); |
| 1931 | EXPECT_TRUE(child2->is_clipped()); |
| 1932 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1933 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1934 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1935 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1936 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1937 | } |
| 1938 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 1939 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1940 | // Verify that layers get the appropriate DrawableContentRect when their |
| 1941 | // parent masksToBounds is true. |
| 1942 | // |
| 1943 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 1944 | // be the layer rect expressed in target space. |
| 1945 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 1946 | // will be the intersection of layer bounds and the mask region. |
| 1947 | // grand_child3 - partially clipped and masksToBounds; the |
| 1948 | // DrawableContentRect will still be the intersection of layer bounds and |
| 1949 | // the mask region. |
| 1950 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 1951 | // be empty. |
| 1952 | // |
| 1953 | |
| 1954 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 1955 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 1956 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 1957 | scoped_refptr<Layer> grand_child1 = Layer::Create(layer_settings()); |
| 1958 | scoped_refptr<Layer> grand_child2 = Layer::Create(layer_settings()); |
| 1959 | scoped_refptr<Layer> grand_child3 = Layer::Create(layer_settings()); |
| 1960 | scoped_refptr<Layer> grand_child4 = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 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 | SetLayerPropertiesForTesting(parent.get(), |
| 1972 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1973 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1974 | gfx::PointF(), |
| 1975 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1976 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1977 | false); |
| 1978 | SetLayerPropertiesForTesting(child.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(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1983 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1984 | false); |
| 1985 | SetLayerPropertiesForTesting(grand_child1.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(5.f, 5.f), |
| 1989 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1990 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1991 | false); |
| 1992 | SetLayerPropertiesForTesting(grand_child2.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(15.f, 15.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_child3.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_child4.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(45.f, 45.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 | |
| 2014 | child->SetMasksToBounds(true); |
| 2015 | grand_child3->SetMasksToBounds(true); |
| 2016 | |
| 2017 | // Force everyone to be a render surface. |
| 2018 | child->SetOpacity(0.4f); |
| 2019 | grand_child1->SetOpacity(0.5f); |
| 2020 | grand_child2->SetOpacity(0.5f); |
| 2021 | grand_child3->SetOpacity(0.5f); |
| 2022 | grand_child4->SetOpacity(0.5f); |
| 2023 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2024 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2025 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2026 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2027 | inputs.can_adjust_raster_scales = true; |
| 2028 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2029 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2030 | EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect()); |
| 2031 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
| 2032 | EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2033 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 2034 | } |
| 2035 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2036 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2037 | // Verify that render surfaces (and their layers) get the appropriate |
| 2038 | // clip rects when their parent masksToBounds is true. |
| 2039 | // |
| 2040 | // Layers that own render surfaces (at least for now) do not inherit any |
| 2041 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 2042 | // They may still have a clip rect of their own layer bounds, however, if |
| 2043 | // masksToBounds was true. |
| 2044 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2045 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 2046 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 2047 | scoped_refptr<Layer> grand_child1 = Layer::Create(layer_settings()); |
| 2048 | scoped_refptr<Layer> grand_child2 = Layer::Create(layer_settings()); |
| 2049 | scoped_refptr<Layer> grand_child3 = Layer::Create(layer_settings()); |
| 2050 | scoped_refptr<Layer> grand_child4 = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2051 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2052 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2053 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2054 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2055 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2056 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2057 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2058 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2059 | |
| 2060 | parent->AddChild(child); |
| 2061 | child->AddChild(grand_child1); |
| 2062 | child->AddChild(grand_child2); |
| 2063 | child->AddChild(grand_child3); |
| 2064 | child->AddChild(grand_child4); |
| 2065 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2066 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2067 | host->SetRootLayer(parent); |
| 2068 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2069 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 2070 | // this test. |
| 2071 | grand_child1->AddChild(leaf_node1); |
| 2072 | grand_child2->AddChild(leaf_node2); |
| 2073 | grand_child3->AddChild(leaf_node3); |
| 2074 | grand_child4->AddChild(leaf_node4); |
| 2075 | |
| 2076 | SetLayerPropertiesForTesting(parent.get(), |
| 2077 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2078 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2079 | gfx::PointF(), |
| 2080 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2081 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2082 | false); |
| 2083 | SetLayerPropertiesForTesting(child.get(), |
| 2084 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2085 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2086 | gfx::PointF(), |
| 2087 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2088 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2089 | false); |
| 2090 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2091 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2092 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2093 | gfx::PointF(5.f, 5.f), |
| 2094 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2095 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2096 | false); |
| 2097 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2098 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2099 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2100 | gfx::PointF(15.f, 15.f), |
| 2101 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2102 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2103 | false); |
| 2104 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2105 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2106 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2107 | gfx::PointF(15.f, 15.f), |
| 2108 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2109 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2110 | false); |
| 2111 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2112 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2113 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2114 | gfx::PointF(45.f, 45.f), |
| 2115 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2116 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2117 | false); |
| 2118 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 2119 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2120 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2121 | gfx::PointF(), |
| 2122 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2123 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2124 | false); |
| 2125 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 2126 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2127 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2128 | gfx::PointF(), |
| 2129 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2130 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2131 | false); |
| 2132 | SetLayerPropertiesForTesting(leaf_node3.get(), |
| 2133 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2134 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2135 | gfx::PointF(), |
| 2136 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2137 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2138 | false); |
| 2139 | SetLayerPropertiesForTesting(leaf_node4.get(), |
| 2140 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2141 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2142 | gfx::PointF(), |
| 2143 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2144 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2145 | false); |
| 2146 | |
| 2147 | child->SetMasksToBounds(true); |
| 2148 | grand_child3->SetMasksToBounds(true); |
| 2149 | grand_child4->SetMasksToBounds(true); |
| 2150 | |
| 2151 | // Force everyone to be a render surface. |
| 2152 | child->SetOpacity(0.4f); |
| 2153 | child->SetForceRenderSurface(true); |
| 2154 | grand_child1->SetOpacity(0.5f); |
| 2155 | grand_child1->SetForceRenderSurface(true); |
| 2156 | grand_child2->SetOpacity(0.5f); |
| 2157 | grand_child2->SetForceRenderSurface(true); |
| 2158 | grand_child3->SetOpacity(0.5f); |
| 2159 | grand_child3->SetForceRenderSurface(true); |
| 2160 | grand_child4->SetOpacity(0.5f); |
| 2161 | grand_child4->SetForceRenderSurface(true); |
| 2162 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2163 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2164 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2165 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2166 | inputs.can_adjust_raster_scales = true; |
| 2167 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2168 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2169 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2170 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2171 | |
| 2172 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2173 | // masksToBounds. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2174 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2175 | grand_child1->render_surface()->clip_rect()); |
| 2176 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2177 | grand_child2->render_surface()->clip_rect()); |
| 2178 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20), |
| 2179 | grand_child3->render_surface()->clip_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2180 | } |
| 2181 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2182 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2183 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 2184 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
| 2185 | scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings()); |
| 2186 | scoped_refptr<Layer> child_of_root = Layer::Create(layer_settings()); |
| 2187 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(layer_settings()); |
| 2188 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(layer_settings()); |
| 2189 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2190 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2191 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2192 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2193 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2194 | parent->AddChild(render_surface1); |
| 2195 | parent->AddChild(child_of_root); |
| 2196 | render_surface1->AddChild(child_of_rs1); |
| 2197 | render_surface1->AddChild(render_surface2); |
| 2198 | render_surface2->AddChild(child_of_rs2); |
| 2199 | child_of_root->AddChild(grand_child_of_root); |
| 2200 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 2201 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 2202 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2203 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2204 | host->SetRootLayer(parent); |
| 2205 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2206 | // Make our render surfaces. |
| 2207 | render_surface1->SetForceRenderSurface(true); |
| 2208 | render_surface2->SetForceRenderSurface(true); |
| 2209 | |
| 2210 | gfx::Transform layer_transform; |
| 2211 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2212 | |
| 2213 | SetLayerPropertiesForTesting(parent.get(), |
| 2214 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2215 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2216 | gfx::PointF(2.5f, 0.f), |
| 2217 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2218 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2219 | false); |
| 2220 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2221 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2222 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2223 | gfx::PointF(2.5f, 0.f), |
| 2224 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2225 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2226 | false); |
| 2227 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 2228 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2229 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2230 | gfx::PointF(2.5f, 0.f), |
| 2231 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2232 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2233 | false); |
| 2234 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 2235 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2236 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2237 | gfx::PointF(2.5f, 0.f), |
| 2238 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2239 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2240 | false); |
| 2241 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 2242 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2243 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2244 | gfx::PointF(2.5f, 0.f), |
| 2245 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2246 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2247 | false); |
| 2248 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 2249 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2250 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2251 | gfx::PointF(2.5f, 0.f), |
| 2252 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2253 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2254 | false); |
| 2255 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 2256 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2257 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2258 | gfx::PointF(2.5f, 0.f), |
| 2259 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2260 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2261 | false); |
| 2262 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 2263 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2264 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2265 | gfx::PointF(2.5f, 0.f), |
| 2266 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2267 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2268 | false); |
| 2269 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 2270 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2271 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2272 | gfx::PointF(2.5f, 0.f), |
| 2273 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2274 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2275 | false); |
| 2276 | |
| 2277 | // Put an animated opacity on the render surface. |
| 2278 | AddOpacityTransitionToController( |
| 2279 | render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2280 | |
| 2281 | // Also put an animated opacity on a layer without descendants. |
| 2282 | AddOpacityTransitionToController( |
| 2283 | grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2284 | |
| 2285 | // Put a transform animation on the render surface. |
| 2286 | AddAnimatedTransformToController( |
| 2287 | render_surface2->layer_animation_controller(), 10.0, 30, 0); |
| 2288 | |
| 2289 | // Also put transform animations on grand_child_of_root, and |
| 2290 | // grand_child_of_rs2 |
| 2291 | AddAnimatedTransformToController( |
| 2292 | grand_child_of_root->layer_animation_controller(), 10.0, 30, 0); |
| 2293 | AddAnimatedTransformToController( |
| 2294 | grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0); |
| 2295 | |
| 2296 | ExecuteCalculateDrawProperties(parent.get()); |
| 2297 | |
| 2298 | // Only layers that are associated with render surfaces should have an actual |
| 2299 | // RenderSurface() value. |
| 2300 | ASSERT_TRUE(parent->render_surface()); |
| 2301 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2302 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2303 | |
| 2304 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2305 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2306 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2307 | |
| 2308 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2309 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2310 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2311 | |
| 2312 | // Verify all render target accessors |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2313 | EXPECT_EQ(parent.get(), parent->render_target()); |
| 2314 | EXPECT_EQ(parent.get(), child_of_root->render_target()); |
| 2315 | EXPECT_EQ(parent.get(), grand_child_of_root->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2316 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2317 | EXPECT_EQ(render_surface1.get(), render_surface1->render_target()); |
| 2318 | EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target()); |
| 2319 | EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2320 | |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 2321 | EXPECT_EQ(render_surface2.get(), render_surface2->render_target()); |
| 2322 | EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target()); |
| 2323 | EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2324 | |
| 2325 | // Verify draw_opacity_is_animating values |
| 2326 | EXPECT_FALSE(parent->draw_opacity_is_animating()); |
| 2327 | EXPECT_FALSE(child_of_root->draw_opacity_is_animating()); |
| 2328 | EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating()); |
| 2329 | EXPECT_FALSE(render_surface1->draw_opacity_is_animating()); |
| 2330 | EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating()); |
| 2331 | EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating()); |
| 2332 | EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating()); |
| 2333 | EXPECT_FALSE(render_surface2->draw_opacity_is_animating()); |
| 2334 | EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating()); |
| 2335 | EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating()); |
| 2336 | EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating()); |
| 2337 | |
| 2338 | // Verify draw_transform_is_animating values |
| 2339 | EXPECT_FALSE(parent->draw_transform_is_animating()); |
| 2340 | EXPECT_FALSE(child_of_root->draw_transform_is_animating()); |
| 2341 | EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating()); |
| 2342 | EXPECT_FALSE(render_surface1->draw_transform_is_animating()); |
| 2343 | EXPECT_FALSE(render_surface1->render_surface() |
| 2344 | ->target_surface_transforms_are_animating()); |
| 2345 | EXPECT_FALSE(child_of_rs1->draw_transform_is_animating()); |
| 2346 | EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating()); |
| 2347 | EXPECT_FALSE(render_surface2->draw_transform_is_animating()); |
| 2348 | EXPECT_TRUE(render_surface2->render_surface() |
| 2349 | ->target_surface_transforms_are_animating()); |
| 2350 | EXPECT_FALSE(child_of_rs2->draw_transform_is_animating()); |
| 2351 | EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating()); |
| 2352 | |
| 2353 | // Verify screen_space_transform_is_animating values |
| 2354 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2355 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2356 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2357 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
| 2358 | EXPECT_FALSE(render_surface1->render_surface() |
| 2359 | ->screen_space_transforms_are_animating()); |
| 2360 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2361 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2362 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
| 2363 | EXPECT_TRUE(render_surface2->render_surface() |
| 2364 | ->screen_space_transforms_are_animating()); |
| 2365 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2366 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2367 | |
| 2368 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2369 | // It is expected that we correctly set up transforms so that the y-component |
| 2370 | // 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] | 2371 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 2372 | EXPECT_FLOAT_EQ(2.0, |
| 2373 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2374 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2375 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2376 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2377 | EXPECT_FLOAT_EQ(2.0, |
| 2378 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 2379 | EXPECT_FLOAT_EQ(3.0, |
| 2380 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2381 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2382 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2383 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2384 | EXPECT_FLOAT_EQ(3.0, |
| 2385 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 2386 | EXPECT_FLOAT_EQ(4.0, |
| 2387 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2388 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2389 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2390 | } |
| 2391 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2392 | TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2393 | // Test the calculateVisibleRect() function works correctly for identity |
| 2394 | // transforms. |
| 2395 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2396 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2397 | gfx::Transform layer_to_surface_transform; |
| 2398 | |
| 2399 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2400 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2401 | gfx::Rect expected = gfx::Rect(10, 10, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2402 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2403 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2404 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2405 | |
| 2406 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2407 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2408 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2409 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2410 | EXPECT_TRUE(actual.IsEmpty()); |
| 2411 | |
| 2412 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2413 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
| 2414 | expected = gfx::Rect(80, 80, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2415 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2416 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2417 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2418 | } |
| 2419 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2420 | TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2421 | // Test the calculateVisibleRect() function works correctly for scaling |
| 2422 | // transforms. |
| 2423 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2424 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2425 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2426 | gfx::Transform layer_to_surface_transform; |
| 2427 | |
| 2428 | // Case 1: Layer is contained within the surface. |
| 2429 | layer_to_surface_transform.MakeIdentity(); |
| 2430 | layer_to_surface_transform.Translate(10.0, 10.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2431 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2432 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2433 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2434 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2435 | |
| 2436 | // Case 2: Layer is outside the surface rect. |
| 2437 | layer_to_surface_transform.MakeIdentity(); |
| 2438 | layer_to_surface_transform.Translate(120.0, 120.0); |
| 2439 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2440 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2441 | EXPECT_TRUE(actual.IsEmpty()); |
| 2442 | |
| 2443 | // Case 3: Layer is partially overlapping the surface rect. |
| 2444 | layer_to_surface_transform.MakeIdentity(); |
| 2445 | layer_to_surface_transform.Translate(80.0, 80.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2446 | expected = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2447 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2448 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2449 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2450 | } |
| 2451 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2452 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2453 | // Test the calculateVisibleRect() function works correctly for rotations |
| 2454 | // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() |
| 2455 | // should return the g in the layer's space. |
| 2456 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2457 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2458 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2459 | gfx::Transform layer_to_surface_transform; |
| 2460 | |
| 2461 | // Case 1: Layer is contained within the surface. |
| 2462 | layer_to_surface_transform.MakeIdentity(); |
| 2463 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2464 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2465 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2466 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2467 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2468 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2469 | |
| 2470 | // Case 2: Layer is outside the surface rect. |
| 2471 | layer_to_surface_transform.MakeIdentity(); |
| 2472 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2473 | layer_to_surface_transform.Rotate(45.0); |
| 2474 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2475 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2476 | EXPECT_TRUE(actual.IsEmpty()); |
| 2477 | |
| 2478 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2479 | // the layer is oriented diagonally, with the left half outside of the render |
| 2480 | // surface. In this case, the g should still be the entire layer |
| 2481 | // (remember the g is computed in layer space); both the top-left |
| 2482 | // and bottom-right corners of the layer are still visible. |
| 2483 | layer_to_surface_transform.MakeIdentity(); |
| 2484 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2485 | expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2486 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2487 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2488 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2489 | |
| 2490 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2491 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2492 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2493 | // surface overlaps the right side of the layer. The g should be |
| 2494 | // the layer's right half. |
| 2495 | layer_to_surface_transform.MakeIdentity(); |
| 2496 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2497 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2498 | expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2499 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2500 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2501 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2502 | } |
| 2503 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2504 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2505 | // Test that the calculateVisibleRect() function works correctly for 3d |
| 2506 | // transforms. |
| 2507 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2508 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2509 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2510 | gfx::Transform layer_to_surface_transform; |
| 2511 | |
| 2512 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2513 | // degrees, should be fully contained in the render surface. |
| 2514 | layer_to_surface_transform.MakeIdentity(); |
| 2515 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2516 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2517 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2518 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2519 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2520 | |
| 2521 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2522 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2523 | // visible on the surface. |
| 2524 | // 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] | 2525 | SkMScalar half_width_of_rotated_layer = |
| 2526 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2527 | layer_to_surface_transform.MakeIdentity(); |
| 2528 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2529 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2530 | // edge of the layer. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2531 | expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2532 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2533 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2534 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2535 | } |
| 2536 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2537 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2538 | // Test the calculateVisibleRect() function works correctly when the layer has |
| 2539 | // a perspective projection onto the target surface. |
| 2540 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2541 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2542 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2543 | gfx::Transform layer_to_surface_transform; |
| 2544 | |
| 2545 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2546 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2547 | // its translated more than the perspective amount. |
| 2548 | layer_to_surface_transform.MakeIdentity(); |
| 2549 | |
| 2550 | // The following sequence of transforms applies the perspective about the |
| 2551 | // center of the surface. |
| 2552 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2553 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2554 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2555 | |
| 2556 | // This translate places the layer in front of the surface's projection plane. |
| 2557 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2558 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2559 | gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2560 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2561 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2562 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2563 | |
| 2564 | // Case 2: same projection as before, except that the layer is also translated |
| 2565 | // to the side, so that only the right half of the layer should be visible. |
| 2566 | // |
| 2567 | // Explanation of expected result: The perspective ratio is (z distance |
| 2568 | // between layer and camera origin) / (z distance between projection plane and |
| 2569 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
| 2570 | // move a layer by translating -50 units in projected surface units (so that |
| 2571 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
| 2572 | // -50 == -200 in the layer's units. |
| 2573 | layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2574 | expected = gfx::Rect(gfx::Point(50, -50), |
| 2575 | gfx::Size(100, 200)); // The right half of the layer's |
| 2576 | // bounding rect. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2577 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2578 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2579 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2580 | } |
| 2581 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2582 | TEST_F(LayerTreeHostCommonTest, |
| 2583 | VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2584 | // There is currently no explicit concept of an orthographic projection plane |
| 2585 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2586 | // are technically behind the surface in an orthographic world should not be |
| 2587 | // clipped when they are flattened to the surface. |
| 2588 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2589 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2590 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2591 | gfx::Transform layer_to_surface_transform; |
| 2592 | |
| 2593 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2594 | // at the center of the layer. |
| 2595 | layer_to_surface_transform.MakeIdentity(); |
| 2596 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2597 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2598 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2599 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2600 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2601 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2602 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2603 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2604 | } |
| 2605 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2606 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2607 | // Test the calculateVisibleRect() function works correctly when projecting a |
| 2608 | // surface onto a layer, but the layer is partially behind the camera (not |
| 2609 | // just behind the projection plane). In this case, the cartesian coordinates |
| 2610 | // may seem to be valid, but actually they are not. The visible rect needs to |
| 2611 | // be properly clipped by the w = 0 plane in homogeneous coordinates before |
| 2612 | // converting to cartesian coordinates. |
| 2613 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2614 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2615 | gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2616 | gfx::Transform layer_to_surface_transform; |
| 2617 | |
| 2618 | // The layer is positioned so that the right half of the layer should be in |
| 2619 | // front of the camera, while the other half is behind the surface's |
| 2620 | // projection plane. The following sequence of transforms applies the |
| 2621 | // perspective and rotation about the center of the layer. |
| 2622 | layer_to_surface_transform.MakeIdentity(); |
| 2623 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2624 | layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); |
| 2625 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2626 | |
| 2627 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2628 | // transform, otherwise this code is not testing the intended scenario. |
| 2629 | bool clipped; |
| 2630 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2631 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2632 | &clipped); |
| 2633 | ASSERT_TRUE(clipped); |
| 2634 | |
| 2635 | int expected_x_position = 0; |
| 2636 | int expected_width = 10; |
| 2637 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2638 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2639 | EXPECT_EQ(expected_x_position, actual.x()); |
| 2640 | EXPECT_EQ(expected_width, actual.width()); |
| 2641 | } |
| 2642 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2643 | TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2644 | // To determine visible rect in layer space, there needs to be an |
| 2645 | // un-projection from surface space to layer space. When the original |
| 2646 | // transform was a perspective projection that was clipped, it returns a rect |
| 2647 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2648 | // clipping again. |
| 2649 | |
| 2650 | // This sequence of transforms causes one corner of the layer to protrude |
| 2651 | // across the w = 0 plane, and should be clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2652 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
| 2653 | gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2654 | gfx::Transform layer_to_surface_transform; |
| 2655 | layer_to_surface_transform.MakeIdentity(); |
| 2656 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2657 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2658 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2659 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2660 | |
| 2661 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2662 | // code is not testing the intended scenario. |
| 2663 | bool clipped; |
| 2664 | gfx::RectF clipped_rect = |
| 2665 | MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); |
| 2666 | MathUtil::ProjectQuad( |
| 2667 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2668 | ASSERT_TRUE(clipped); |
| 2669 | |
| 2670 | // Only the corner of the layer is not visible on the surface because of being |
| 2671 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2672 | // rect is that the entire layer should still be considered visible. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2673 | gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2674 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2675 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2676 | EXPECT_EQ(expected, actual); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2677 | } |
| 2678 | |
miletus | 9d3da52 | 2015-06-05 19:45:07 | [diff] [blame^] | 2679 | TEST_F(LayerTreeHostCommonTest, |
| 2680 | VisibleRectsForPositionedRootLayerClippedByViewport) { |
| 2681 | scoped_refptr<Layer> root = |
| 2682 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
| 2683 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 2684 | host->SetRootLayer(root); |
| 2685 | |
| 2686 | gfx::Transform identity_matrix; |
| 2687 | // Root layer is positioned at (60, 70). The default device viewport size |
| 2688 | // is (0, 0, 100x100) in target space. So the root layer's visible rect |
| 2689 | // will be clipped by the viewport to be (0, 0, 40x30) in layer's space. |
| 2690 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 2691 | gfx::PointF(60, 70), gfx::Size(100, 100), true, |
| 2692 | false); |
| 2693 | ExecuteCalculateDrawProperties(root.get()); |
| 2694 | |
| 2695 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2696 | root->render_surface()->DrawableContentRect()); |
| 2697 | // In target space, not clipped. |
| 2698 | EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect()); |
| 2699 | // In layer space, clipped. |
| 2700 | EXPECT_EQ(gfx::Rect(0, 0, 40, 30), root->visible_content_rect()); |
| 2701 | } |
| 2702 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2703 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2704 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2705 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2706 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2707 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2708 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2709 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2710 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2711 | root->AddChild(child1); |
| 2712 | root->AddChild(child2); |
| 2713 | root->AddChild(child3); |
| 2714 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2715 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2716 | host->SetRootLayer(root); |
| 2717 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2718 | gfx::Transform identity_matrix; |
| 2719 | SetLayerPropertiesForTesting(root.get(), |
| 2720 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2721 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2722 | gfx::PointF(), |
| 2723 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2724 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2725 | false); |
| 2726 | SetLayerPropertiesForTesting(child1.get(), |
| 2727 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2728 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2729 | gfx::PointF(), |
| 2730 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2731 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2732 | false); |
| 2733 | SetLayerPropertiesForTesting(child2.get(), |
| 2734 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2735 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2736 | gfx::PointF(75.f, 75.f), |
| 2737 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2738 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2739 | false); |
| 2740 | SetLayerPropertiesForTesting(child3.get(), |
| 2741 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2742 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2743 | gfx::PointF(125.f, 125.f), |
| 2744 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2745 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2746 | false); |
| 2747 | |
| 2748 | ExecuteCalculateDrawProperties(root.get()); |
| 2749 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2750 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2751 | root->render_surface()->DrawableContentRect()); |
| 2752 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2753 | |
| 2754 | // Layers that do not draw content should have empty visible_content_rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2755 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2756 | |
| 2757 | // layer visible_content_rects are clipped by their target surface. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2758 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2759 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2760 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 2761 | |
| 2762 | // layer drawable_content_rects are not clipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2763 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect()); |
| 2764 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2765 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2766 | } |
| 2767 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2768 | TEST_F(LayerTreeHostCommonTest, |
| 2769 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2770 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 2771 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2772 | scoped_refptr<LayerWithForcedDrawsContent> grand_child1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2773 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2774 | scoped_refptr<LayerWithForcedDrawsContent> grand_child2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2775 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2776 | scoped_refptr<LayerWithForcedDrawsContent> grand_child3 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2777 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2778 | root->AddChild(child); |
| 2779 | child->AddChild(grand_child1); |
| 2780 | child->AddChild(grand_child2); |
| 2781 | child->AddChild(grand_child3); |
| 2782 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2783 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2784 | host->SetRootLayer(root); |
| 2785 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2786 | gfx::Transform identity_matrix; |
| 2787 | SetLayerPropertiesForTesting(root.get(), |
| 2788 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2789 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2790 | gfx::PointF(), |
| 2791 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2792 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2793 | false); |
| 2794 | SetLayerPropertiesForTesting(child.get(), |
| 2795 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2796 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2797 | gfx::PointF(), |
| 2798 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2799 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2800 | false); |
| 2801 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2802 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2803 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2804 | gfx::PointF(5.f, 5.f), |
| 2805 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2806 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2807 | false); |
| 2808 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2809 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2810 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2811 | gfx::PointF(75.f, 75.f), |
| 2812 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2813 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2814 | false); |
| 2815 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2816 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2817 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2818 | gfx::PointF(125.f, 125.f), |
| 2819 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2820 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2821 | false); |
| 2822 | |
| 2823 | child->SetMasksToBounds(true); |
| 2824 | ExecuteCalculateDrawProperties(root.get()); |
| 2825 | |
| 2826 | ASSERT_FALSE(child->render_surface()); |
| 2827 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2828 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2829 | root->render_surface()->DrawableContentRect()); |
| 2830 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2831 | |
| 2832 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2833 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2834 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2835 | |
| 2836 | // All grandchild visible content rects should be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2837 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect()); |
| 2838 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2839 | EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty()); |
| 2840 | |
| 2841 | // All grandchild DrawableContentRects should also be clipped by child. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2842 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect()); |
| 2843 | EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2844 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 2845 | } |
| 2846 | |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 2847 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2848 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 2849 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 2850 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2851 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 2852 | root->AddChild(child); |
| 2853 | child->AddChild(grand_child); |
| 2854 | |
| 2855 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 2856 | host->SetRootLayer(root); |
| 2857 | |
| 2858 | gfx::Transform identity_matrix; |
| 2859 | gfx::Transform child_scale_matrix; |
| 2860 | child_scale_matrix.Scale(0.25f, 0.25f); |
| 2861 | gfx::Transform grand_child_scale_matrix; |
| 2862 | grand_child_scale_matrix.Scale(0.246f, 0.246f); |
| 2863 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 2864 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 2865 | SetLayerPropertiesForTesting(child.get(), child_scale_matrix, gfx::Point3F(), |
| 2866 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 2867 | SetLayerPropertiesForTesting(grand_child.get(), grand_child_scale_matrix, |
| 2868 | gfx::Point3F(), gfx::PointF(), |
| 2869 | gfx::Size(100, 100), true, false); |
| 2870 | |
| 2871 | child->SetMasksToBounds(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 2872 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | 27442dd | 2015-03-30 19:19:48 | [diff] [blame] | 2873 | |
| 2874 | // The visible rect is expanded to integer coordinates in target space before |
| 2875 | // being projected back to layer space, where it is once again expanded to |
| 2876 | // integer coordinates. |
| 2877 | EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_rect_from_property_trees()); |
| 2878 | } |
| 2879 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2880 | TEST_F(LayerTreeHostCommonTest, |
| 2881 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2882 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 2883 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2884 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2885 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2886 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2887 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2888 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2889 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2890 | root->AddChild(render_surface1); |
| 2891 | render_surface1->AddChild(child1); |
| 2892 | render_surface1->AddChild(child2); |
| 2893 | render_surface1->AddChild(child3); |
| 2894 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 2895 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2896 | host->SetRootLayer(root); |
| 2897 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2898 | gfx::Transform identity_matrix; |
| 2899 | SetLayerPropertiesForTesting(root.get(), |
| 2900 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2901 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2902 | gfx::PointF(), |
| 2903 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2904 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2905 | false); |
| 2906 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2907 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2908 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2909 | gfx::PointF(), |
| 2910 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2911 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2912 | false); |
| 2913 | SetLayerPropertiesForTesting(child1.get(), |
| 2914 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2915 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2916 | gfx::PointF(5.f, 5.f), |
| 2917 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2918 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2919 | false); |
| 2920 | SetLayerPropertiesForTesting(child2.get(), |
| 2921 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2922 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2923 | gfx::PointF(75.f, 75.f), |
| 2924 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2925 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2926 | false); |
| 2927 | SetLayerPropertiesForTesting(child3.get(), |
| 2928 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2929 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2930 | gfx::PointF(125.f, 125.f), |
| 2931 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2932 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2933 | false); |
| 2934 | |
| 2935 | render_surface1->SetForceRenderSurface(true); |
| 2936 | ExecuteCalculateDrawProperties(root.get()); |
| 2937 | |
| 2938 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2939 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2940 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2941 | root->render_surface()->DrawableContentRect()); |
| 2942 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2943 | |
| 2944 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2945 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2946 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2947 | |
| 2948 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 2949 | // regions of the subtree. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2950 | EXPECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 2951 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2952 | |
| 2953 | // All layers that draw content into the unclipped surface are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2954 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2955 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 2956 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2957 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 2958 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 2959 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2960 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2961 | } |
| 2962 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2963 | TEST_F(LayerTreeHostCommonTest, |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2964 | VisibleContentRectsForClippedSurfaceWithEmptyClip) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2965 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2966 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2967 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2968 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2969 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2970 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 2971 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
hush | 887bb54 | 2014-12-02 22:49:02 | [diff] [blame] | 2972 | root->AddChild(child1); |
| 2973 | root->AddChild(child2); |
| 2974 | root->AddChild(child3); |
| 2975 | |
| 2976 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 2977 | host->SetRootLayer(root); |
| 2978 | |
| 2979 | gfx::Transform identity_matrix; |
| 2980 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 2981 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 2982 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(), |
| 2983 | gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true, |
| 2984 | false); |
| 2985 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(), |
| 2986 | gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true, |
| 2987 | false); |
| 2988 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, gfx::Point3F(), |
| 2989 | gfx::PointF(125.f, 125.f), gfx::Size(50, 50), |
| 2990 | true, false); |
| 2991 | |
| 2992 | RenderSurfaceLayerList render_surface_layer_list; |
| 2993 | // Now set the root render surface an empty clip. |
| 2994 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2995 | root.get(), gfx::Size(), &render_surface_layer_list); |
| 2996 | |
| 2997 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 2998 | ASSERT_TRUE(root->render_surface()); |
| 2999 | EXPECT_FALSE(root->is_clipped()); |
| 3000 | |
| 3001 | gfx::Rect empty; |
| 3002 | EXPECT_EQ(empty, root->render_surface()->clip_rect()); |
| 3003 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 3004 | |
| 3005 | // Visible content rect calculation will check if the target surface is |
| 3006 | // clipped or not. An empty clip rect does not indicate the render surface |
| 3007 | // is unclipped. |
| 3008 | EXPECT_EQ(empty, child1->visible_content_rect()); |
| 3009 | EXPECT_EQ(empty, child2->visible_content_rect()); |
| 3010 | EXPECT_EQ(empty, child3->visible_content_rect()); |
| 3011 | } |
| 3012 | |
| 3013 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3014 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3015 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3016 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3017 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3018 | root->AddChild(child); |
| 3019 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3020 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3021 | host->SetRootLayer(root); |
| 3022 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3023 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3024 | gfx::Transform identity_matrix; |
| 3025 | 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] | 3026 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3027 | |
| 3028 | SetLayerPropertiesForTesting(root.get(), |
| 3029 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3030 | gfx::Point3F(), |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3031 | gfx::PointF(), |
| 3032 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3033 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3034 | false); |
| 3035 | SetLayerPropertiesForTesting(child.get(), |
| 3036 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3037 | gfx::Point3F(), |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3038 | gfx::PointF(5.f, 5.f), |
| 3039 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3040 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3041 | false); |
| 3042 | |
| 3043 | ExecuteCalculateDrawProperties(root.get()); |
| 3044 | |
| 3045 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 3046 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3047 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3048 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 3049 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3050 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3051 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3052 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3053 | |
| 3054 | SetLayerPropertiesForTesting(child.get(), |
| 3055 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3056 | gfx::Point3F(), |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3057 | gfx::PointF(5.f, 5.f), |
| 3058 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3059 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3060 | false); |
| 3061 | |
| 3062 | ExecuteCalculateDrawProperties(root.get()); |
| 3063 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3064 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 3065 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3066 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3067 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3068 | uninvertible_matrix.MakeIdentity(); |
| 3069 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3070 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3071 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3072 | |
| 3073 | SetLayerPropertiesForTesting(child.get(), |
| 3074 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3075 | gfx::Point3F(), |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3076 | gfx::PointF(5.f, 5.f), |
| 3077 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3078 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 3079 | false); |
| 3080 | |
| 3081 | ExecuteCalculateDrawProperties(root.get()); |
| 3082 | |
| 3083 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 3084 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 3085 | } |
| 3086 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3087 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3088 | SingularTransformDoesNotPreventClearingDrawProperties) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3089 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3090 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3091 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3092 | root->AddChild(child); |
| 3093 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3094 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3095 | host->SetRootLayer(root); |
| 3096 | |
| 3097 | gfx::Transform identity_matrix; |
| 3098 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 3099 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3100 | |
| 3101 | SetLayerPropertiesForTesting(root.get(), |
| 3102 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3103 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3104 | gfx::PointF(), |
| 3105 | gfx::Size(100, 100), |
| 3106 | true, |
| 3107 | false); |
| 3108 | SetLayerPropertiesForTesting(child.get(), |
| 3109 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3110 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3111 | gfx::PointF(5.f, 5.f), |
| 3112 | gfx::Size(50, 50), |
| 3113 | true, |
| 3114 | false); |
| 3115 | |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 3116 | child->set_sorted_for_recursion(true); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3117 | |
| 3118 | TransformOperations start_transform_operations; |
| 3119 | start_transform_operations.AppendScale(1.f, 0.f, 0.f); |
| 3120 | |
| 3121 | TransformOperations end_transform_operations; |
| 3122 | end_transform_operations.AppendScale(1.f, 1.f, 0.f); |
| 3123 | |
| 3124 | AddAnimatedTransformToLayer( |
| 3125 | root.get(), 10.0, start_transform_operations, end_transform_operations); |
| 3126 | |
| 3127 | EXPECT_TRUE(root->TransformIsAnimating()); |
| 3128 | |
| 3129 | ExecuteCalculateDrawProperties(root.get()); |
| 3130 | |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 3131 | EXPECT_FALSE(child->sorted_for_recursion()); |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 3132 | } |
| 3133 | |
| 3134 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3135 | SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3136 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3137 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3138 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3139 | host->SetRootLayer(root); |
| 3140 | |
| 3141 | gfx::Transform identity_matrix; |
| 3142 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 3143 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 3144 | |
| 3145 | SetLayerPropertiesForTesting(root.get(), |
| 3146 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3147 | gfx::Point3F(), |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3148 | gfx::PointF(), |
| 3149 | gfx::Size(100, 100), |
| 3150 | true, |
| 3151 | false); |
| 3152 | |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 3153 | root->set_sorted_for_recursion(true); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3154 | |
| 3155 | EXPECT_FALSE(root->TransformIsAnimating()); |
| 3156 | |
| 3157 | ExecuteCalculateDrawProperties(root.get()); |
| 3158 | |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 3159 | EXPECT_FALSE(root->sorted_for_recursion()); |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3163 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3164 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 3165 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3166 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3167 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3168 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3169 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3170 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3171 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3172 | root->AddChild(render_surface1); |
| 3173 | render_surface1->AddChild(child1); |
| 3174 | render_surface1->AddChild(child2); |
| 3175 | render_surface1->AddChild(child3); |
| 3176 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3177 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3178 | host->SetRootLayer(root); |
| 3179 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3180 | gfx::Transform identity_matrix; |
| 3181 | SetLayerPropertiesForTesting(root.get(), |
| 3182 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3183 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3184 | gfx::PointF(), |
| 3185 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3186 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3187 | false); |
| 3188 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3189 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3190 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3191 | gfx::PointF(), |
| 3192 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3193 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3194 | false); |
| 3195 | SetLayerPropertiesForTesting(child1.get(), |
| 3196 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3197 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3198 | gfx::PointF(5.f, 5.f), |
| 3199 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3200 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3201 | false); |
| 3202 | SetLayerPropertiesForTesting(child2.get(), |
| 3203 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3204 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3205 | gfx::PointF(75.f, 75.f), |
| 3206 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3207 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3208 | false); |
| 3209 | SetLayerPropertiesForTesting(child3.get(), |
| 3210 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3211 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3212 | gfx::PointF(125.f, 125.f), |
| 3213 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3214 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3215 | false); |
| 3216 | |
| 3217 | root->SetMasksToBounds(true); |
| 3218 | render_surface1->SetForceRenderSurface(true); |
| 3219 | ExecuteCalculateDrawProperties(root.get()); |
| 3220 | |
| 3221 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3222 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3223 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3224 | root->render_surface()->DrawableContentRect()); |
| 3225 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3226 | |
| 3227 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3228 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3229 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3230 | |
| 3231 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3232 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3233 | EXPECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3234 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3235 | |
| 3236 | // All layers that draw content into the surface have their visible content |
| 3237 | // rect clipped by the surface clip rect. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3238 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3239 | EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3240 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 3241 | |
| 3242 | // But the DrawableContentRects are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3243 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3244 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3245 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3246 | } |
| 3247 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3248 | TEST_F(LayerTreeHostCommonTest, |
| 3249 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3250 | // Check that clipping does not propagate down surfaces. |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3251 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 3252 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
| 3253 | scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3254 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3255 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3256 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3257 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3258 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3259 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3260 | root->AddChild(render_surface1); |
| 3261 | render_surface1->AddChild(render_surface2); |
| 3262 | render_surface2->AddChild(child1); |
| 3263 | render_surface2->AddChild(child2); |
| 3264 | render_surface2->AddChild(child3); |
| 3265 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3266 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3267 | host->SetRootLayer(root); |
| 3268 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3269 | gfx::Transform identity_matrix; |
| 3270 | SetLayerPropertiesForTesting(root.get(), |
| 3271 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3272 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3273 | gfx::PointF(), |
| 3274 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3275 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3276 | false); |
| 3277 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3278 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3279 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3280 | gfx::PointF(), |
| 3281 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3282 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3283 | false); |
| 3284 | SetLayerPropertiesForTesting(render_surface2.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(7, 13), |
[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(child1.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(5.f, 5.f), |
| 3295 | gfx::Size(50, 50), |
[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); |
| 3298 | SetLayerPropertiesForTesting(child2.get(), |
| 3299 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3300 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3301 | gfx::PointF(75.f, 75.f), |
| 3302 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3303 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3304 | false); |
| 3305 | SetLayerPropertiesForTesting(child3.get(), |
| 3306 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3307 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3308 | gfx::PointF(125.f, 125.f), |
| 3309 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3310 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3311 | false); |
| 3312 | |
| 3313 | root->SetMasksToBounds(true); |
| 3314 | render_surface1->SetForceRenderSurface(true); |
| 3315 | render_surface2->SetForceRenderSurface(true); |
| 3316 | ExecuteCalculateDrawProperties(root.get()); |
| 3317 | |
| 3318 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3319 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3320 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3321 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3322 | root->render_surface()->DrawableContentRect()); |
| 3323 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3324 | |
| 3325 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3326 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3327 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
| 3328 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3329 | |
| 3330 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3331 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3332 | EXPECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3333 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3334 | |
| 3335 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3336 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3337 | // render_surface2 grows to enclose all drawable content of its subtree. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3338 | EXPECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 3339 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3340 | |
| 3341 | // All layers that draw content into render_surface2 think they are unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3342 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3343 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3344 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3345 | |
| 3346 | // DrawableContentRects are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3347 | EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3348 | EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3349 | EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3350 | } |
| 3351 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3352 | TEST_F(LayerTreeHostCommonTest, |
| 3353 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3354 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3355 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3356 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3357 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 3358 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3359 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3360 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3361 | root->AddChild(render_surface1); |
| 3362 | render_surface1->AddChild(child1); |
| 3363 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3364 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3365 | host->SetRootLayer(root); |
| 3366 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3367 | gfx::Transform identity_matrix; |
| 3368 | gfx::Transform child_rotation; |
| 3369 | child_rotation.Rotate(45.0); |
| 3370 | SetLayerPropertiesForTesting(root.get(), |
| 3371 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3372 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3373 | gfx::PointF(), |
| 3374 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3375 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3376 | false); |
| 3377 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3378 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3379 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3380 | gfx::PointF(), |
| 3381 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3382 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3383 | false); |
| 3384 | SetLayerPropertiesForTesting(child1.get(), |
| 3385 | child_rotation, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3386 | gfx::Point3F(25, 25, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3387 | gfx::PointF(25.f, 25.f), |
| 3388 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3389 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3390 | false); |
| 3391 | |
| 3392 | render_surface1->SetForceRenderSurface(true); |
| 3393 | ExecuteCalculateDrawProperties(root.get()); |
| 3394 | |
| 3395 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3396 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3397 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3398 | root->render_surface()->DrawableContentRect()); |
| 3399 | EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3400 | |
| 3401 | // Layers that do not draw content should have empty visible content rects. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3402 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3403 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3404 | |
| 3405 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3406 | // regions of the subtree. |
| 3407 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3408 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3409 | gfx::Rect(50 - diagonal_radius, |
| 3410 | 50 - diagonal_radius, |
| 3411 | diagonal_radius * 2, |
| 3412 | diagonal_radius * 2); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3413 | EXPECT_EQ(expected_surface_drawable_content, |
| 3414 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3415 | |
| 3416 | // All layers that draw content into the unclipped surface are also unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3417 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3418 | EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3419 | } |
| 3420 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3421 | TEST_F(LayerTreeHostCommonTest, |
| 3422 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3423 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3424 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3425 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3426 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 3427 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3428 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3429 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3430 | root->AddChild(render_surface1); |
| 3431 | render_surface1->AddChild(child1); |
| 3432 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3433 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3434 | host->SetRootLayer(root); |
| 3435 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3436 | gfx::Transform identity_matrix; |
| 3437 | gfx::Transform child_rotation; |
| 3438 | child_rotation.Rotate(45.0); |
| 3439 | SetLayerPropertiesForTesting(root.get(), |
| 3440 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3441 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3442 | gfx::PointF(), |
| 3443 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3444 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3445 | false); |
| 3446 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3447 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3448 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3449 | gfx::PointF(), |
| 3450 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3451 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3452 | false); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3453 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3454 | SetLayerPropertiesForTesting(child1.get(), |
| 3455 | child_rotation, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3456 | gfx::Point3F(25, 25, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3457 | gfx::PointF(25.f, 25.f), |
| 3458 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3459 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3460 | false); |
| 3461 | |
| 3462 | root->SetMasksToBounds(true); |
| 3463 | render_surface1->SetForceRenderSurface(true); |
| 3464 | ExecuteCalculateDrawProperties(root.get()); |
| 3465 | |
| 3466 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3467 | |
| 3468 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 3469 | // rotated layer. |
| 3470 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3471 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 3472 | 50 - diagonal_radius, |
| 3473 | diagonal_radius * 2, |
| 3474 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3475 | gfx::Rect expected_surface_drawable_content = |
| 3476 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3477 | EXPECT_EQ(expected_surface_drawable_content, |
| 3478 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3479 | |
| 3480 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3481 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 3482 | // up covering the full left half of child1. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3483 | // |
| 3484 | // Given the floating point math, this number is a little bit fuzzy. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3485 | EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3486 | |
| 3487 | // The child's DrawableContentRect is unclipped. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3488 | EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3489 | } |
| 3490 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3491 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3492 | MockContentLayerClient client; |
| 3493 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3494 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 3495 | scoped_refptr<FakePictureLayer> render_surface1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3496 | CreateDrawablePictureLayer(layer_settings(), &client); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 3497 | scoped_refptr<FakePictureLayer> render_surface2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3498 | CreateDrawablePictureLayer(layer_settings(), &client); |
| 3499 | scoped_refptr<FakePictureLayer> child1 = |
| 3500 | CreateDrawablePictureLayer(layer_settings(), &client); |
| 3501 | scoped_refptr<FakePictureLayer> child2 = |
| 3502 | CreateDrawablePictureLayer(layer_settings(), &client); |
| 3503 | scoped_refptr<FakePictureLayer> child3 = |
| 3504 | CreateDrawablePictureLayer(layer_settings(), &client); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3505 | root->AddChild(render_surface1); |
| 3506 | render_surface1->AddChild(render_surface2); |
| 3507 | render_surface2->AddChild(child1); |
| 3508 | render_surface2->AddChild(child2); |
| 3509 | render_surface2->AddChild(child3); |
| 3510 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3511 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3512 | host->SetRootLayer(root); |
| 3513 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3514 | gfx::Transform identity_matrix; |
| 3515 | SetLayerPropertiesForTesting(root.get(), |
| 3516 | identity_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(render_surface1.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(5.f, 5.f), |
| 3526 | gfx::Size(3, 4), |
[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(render_surface2.get(), |
| 3530 | identity_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(5.f, 5.f), |
| 3533 | gfx::Size(7, 13), |
[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(child1.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(5.f, 5.f), |
| 3540 | gfx::Size(50, 50), |
[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(child2.get(), |
| 3544 | identity_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(75.f, 75.f), |
| 3547 | gfx::Size(50, 50), |
[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(child3.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(125.f, 125.f), |
| 3554 | gfx::Size(50, 50), |
[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 | |
| 3558 | float device_scale_factor = 2.f; |
| 3559 | |
| 3560 | root->SetMasksToBounds(true); |
| 3561 | render_surface1->SetForceRenderSurface(true); |
| 3562 | render_surface2->SetForceRenderSurface(true); |
| 3563 | ExecuteCalculateDrawProperties(root.get(), device_scale_factor); |
| 3564 | |
| 3565 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3566 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3567 | |
| 3568 | // drawable_content_rects for all layers and surfaces are scaled by |
| 3569 | // device_scale_factor. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3570 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 3571 | root->render_surface()->DrawableContentRect()); |
| 3572 | EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); |
| 3573 | EXPECT_EQ(gfx::Rect(10, 10, 190, 190), |
| 3574 | render_surface1->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3575 | |
| 3576 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 3577 | // is only implicitly clipped by render_surface1. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3578 | EXPECT_EQ(gfx::Rect(10, 10, 350, 350), |
| 3579 | render_surface2->render_surface()->DrawableContentRect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3580 | |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3581 | EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3582 | EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect()); |
| 3583 | EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3584 | |
| 3585 | // The root layer does not actually draw content of its own. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3586 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3587 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 3588 | // All layer visible content rects are not expressed in content space of each |
| 3589 | // layer, so they are not scaled by the device_scale_factor. |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 3590 | EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_content_rect()); |
| 3591 | EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_content_rect()); |
| 3592 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3593 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3594 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3595 | } |
| 3596 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3597 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3598 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 3599 | // layers. Note that 3d transforms still apply in this case, but they are |
| 3600 | // "flattened" to each parent layer according to current W3C spec. |
| 3601 | |
| 3602 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3603 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3604 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3605 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3606 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3607 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3608 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3609 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3610 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3611 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3612 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3613 | front_facing_child_of_front_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3614 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3615 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3616 | back_facing_child_of_front_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3617 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3618 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3619 | front_facing_child_of_back_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3620 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3621 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3622 | back_facing_child_of_back_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3623 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3624 | |
| 3625 | parent->AddChild(front_facing_child); |
| 3626 | parent->AddChild(back_facing_child); |
| 3627 | parent->AddChild(front_facing_surface); |
| 3628 | parent->AddChild(back_facing_surface); |
| 3629 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3630 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3631 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3632 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3633 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3634 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3635 | host->SetRootLayer(parent); |
| 3636 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3637 | // Nothing is double-sided |
| 3638 | front_facing_child->SetDoubleSided(false); |
| 3639 | back_facing_child->SetDoubleSided(false); |
| 3640 | front_facing_surface->SetDoubleSided(false); |
| 3641 | back_facing_surface->SetDoubleSided(false); |
| 3642 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3643 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3644 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3645 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3646 | |
| 3647 | gfx::Transform backface_matrix; |
| 3648 | backface_matrix.Translate(50.0, 50.0); |
| 3649 | backface_matrix.RotateAboutYAxis(180.0); |
| 3650 | backface_matrix.Translate(-50.0, -50.0); |
| 3651 | |
| 3652 | // Having a descendant and opacity will force these to have render surfaces. |
| 3653 | front_facing_surface->SetOpacity(0.5f); |
| 3654 | back_facing_surface->SetOpacity(0.5f); |
| 3655 | |
| 3656 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 3657 | // these layers should blindly use their own local transforms to determine |
| 3658 | // back-face culling. |
| 3659 | SetLayerPropertiesForTesting(parent.get(), |
| 3660 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3661 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3662 | gfx::PointF(), |
| 3663 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3664 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3665 | false); |
| 3666 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3667 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3668 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3669 | gfx::PointF(), |
| 3670 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3671 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3672 | false); |
| 3673 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3674 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3675 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3676 | gfx::PointF(), |
| 3677 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3678 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3679 | false); |
| 3680 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3681 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3682 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3683 | gfx::PointF(), |
| 3684 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3685 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3686 | false); |
| 3687 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3688 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3689 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3690 | gfx::PointF(), |
| 3691 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3692 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3693 | false); |
| 3694 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3695 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3696 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3697 | gfx::PointF(), |
| 3698 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3699 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3700 | false); |
| 3701 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3702 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3703 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3704 | gfx::PointF(), |
| 3705 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3706 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3707 | false); |
| 3708 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3709 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3710 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3711 | gfx::PointF(), |
| 3712 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3713 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3714 | false); |
| 3715 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3716 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3717 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3718 | gfx::PointF(), |
| 3719 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3720 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3721 | false); |
| 3722 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3723 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3724 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3725 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3726 | inputs.can_adjust_raster_scales = true; |
| 3727 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3728 | |
| 3729 | // Verify which render surfaces were created. |
| 3730 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3731 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3732 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3733 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 3734 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3735 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3736 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3737 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3738 | |
| 3739 | // Verify the render_surface_layer_list. |
| 3740 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3741 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3742 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3743 | // Even though the back facing surface LAYER gets culled, the other |
| 3744 | // descendants should still be added, so the SURFACE should not be culled. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3745 | EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3746 | |
| 3747 | // Verify root surface's layer list. |
| 3748 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3749 | 3u, |
| 3750 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3751 | EXPECT_EQ(front_facing_child->id(), |
| 3752 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3753 | ->render_surface() |
| 3754 | ->layer_list() |
| 3755 | .at(0) |
| 3756 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3757 | EXPECT_EQ(front_facing_surface->id(), |
| 3758 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3759 | ->render_surface() |
| 3760 | ->layer_list() |
| 3761 | .at(1) |
| 3762 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3763 | EXPECT_EQ(back_facing_surface->id(), |
| 3764 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3765 | ->render_surface() |
| 3766 | ->layer_list() |
| 3767 | .at(2) |
| 3768 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3769 | |
| 3770 | // Verify front_facing_surface's layer list. |
| 3771 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3772 | 2u, |
| 3773 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3774 | EXPECT_EQ(front_facing_surface->id(), |
| 3775 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3776 | ->render_surface() |
| 3777 | ->layer_list() |
| 3778 | .at(0) |
| 3779 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3780 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3781 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3782 | ->render_surface() |
| 3783 | ->layer_list() |
| 3784 | .at(1) |
| 3785 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3786 | |
| 3787 | // Verify back_facing_surface's layer list; its own layer should be culled |
| 3788 | // from the surface list. |
| 3789 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3790 | 1u, |
| 3791 | render_surface_layer_list.at(2)->render_surface()->layer_list().size()); |
| 3792 | EXPECT_EQ(front_facing_child_of_back_facing_surface->id(), |
| 3793 | render_surface_layer_list.at(2) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3794 | ->render_surface() |
| 3795 | ->layer_list() |
| 3796 | .at(0) |
| 3797 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3798 | } |
| 3799 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3800 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3801 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 3802 | // is used. |
| 3803 | |
| 3804 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3805 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3806 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3807 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3808 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3809 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3810 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3811 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3812 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3813 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3814 | scoped_refptr<LayerWithForcedDrawsContent> |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3815 | front_facing_child_of_front_facing_surface = |
| 3816 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3817 | scoped_refptr<LayerWithForcedDrawsContent> |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3818 | back_facing_child_of_front_facing_surface = |
| 3819 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3820 | scoped_refptr<LayerWithForcedDrawsContent> |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3821 | front_facing_child_of_back_facing_surface = |
| 3822 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3823 | scoped_refptr<LayerWithForcedDrawsContent> |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3824 | back_facing_child_of_back_facing_surface = |
| 3825 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3826 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3827 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3828 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3829 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3830 | |
| 3831 | parent->AddChild(front_facing_child); |
| 3832 | parent->AddChild(back_facing_child); |
| 3833 | parent->AddChild(front_facing_surface); |
| 3834 | parent->AddChild(back_facing_surface); |
| 3835 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3836 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3837 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3838 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3839 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 3840 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3841 | host->SetRootLayer(parent); |
| 3842 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3843 | // Nothing is double-sided |
| 3844 | front_facing_child->SetDoubleSided(false); |
| 3845 | back_facing_child->SetDoubleSided(false); |
| 3846 | front_facing_surface->SetDoubleSided(false); |
| 3847 | back_facing_surface->SetDoubleSided(false); |
| 3848 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3849 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3850 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3851 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3852 | |
| 3853 | gfx::Transform backface_matrix; |
| 3854 | backface_matrix.Translate(50.0, 50.0); |
| 3855 | backface_matrix.RotateAboutYAxis(180.0); |
| 3856 | backface_matrix.Translate(-50.0, -50.0); |
| 3857 | |
| 3858 | // Opacity will not force creation of render surfaces in this case because of |
| 3859 | // the preserve-3d transform style. Instead, an example of when a surface |
| 3860 | // would be created with preserve-3d is when there is a replica layer. |
| 3861 | front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get()); |
| 3862 | back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get()); |
| 3863 | |
| 3864 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 3865 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 3866 | // rendering context should use the transform with respect to that context. |
| 3867 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 3868 | // and (b) the layer's transform style is preserve-3d. |
| 3869 | SetLayerPropertiesForTesting(parent.get(), |
| 3870 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3871 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3872 | gfx::PointF(), |
| 3873 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3874 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3875 | false); // parent transform style is flat. |
| 3876 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3877 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3878 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3879 | gfx::PointF(), |
| 3880 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3881 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3882 | false); |
| 3883 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3884 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3885 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3886 | gfx::PointF(), |
| 3887 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3888 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3889 | false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3890 | // surface transform style is preserve-3d. |
| 3891 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3892 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3893 | gfx::Point3F(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3894 | gfx::PointF(), |
| 3895 | gfx::Size(100, 100), |
| 3896 | false, |
| 3897 | true); |
| 3898 | // surface transform style is preserve-3d. |
| 3899 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3900 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3901 | gfx::Point3F(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3902 | gfx::PointF(), |
| 3903 | gfx::Size(100, 100), |
| 3904 | false, |
| 3905 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3906 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3907 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3908 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3909 | gfx::PointF(), |
| 3910 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3911 | true, |
| 3912 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3913 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3914 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3915 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3916 | gfx::PointF(), |
| 3917 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3918 | true, |
| 3919 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3920 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3921 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3922 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3923 | gfx::PointF(), |
| 3924 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3925 | true, |
| 3926 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3927 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3928 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3929 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3930 | gfx::PointF(), |
| 3931 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3932 | true, |
| 3933 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3934 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3935 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3936 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3937 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3938 | inputs.can_adjust_raster_scales = true; |
| 3939 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3940 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3941 | // Verify which render surfaces were created and used. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3942 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3943 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3944 | EXPECT_TRUE(front_facing_surface->render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 3945 | EXPECT_NE(back_facing_surface->render_target(), back_facing_surface); |
| 3946 | // We expect that a render_surface was created but not used. |
| 3947 | EXPECT_TRUE(back_facing_surface->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3948 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3949 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3950 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3951 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3952 | |
| 3953 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 3954 | // culled. |
| 3955 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3956 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3957 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3958 | |
| 3959 | // Verify root surface's layer list. |
| 3960 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3961 | 2u, |
| 3962 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3963 | EXPECT_EQ(front_facing_child->id(), |
| 3964 | render_surface_layer_list.at(0) |
| 3965 | ->render_surface()->layer_list().at(0)->id()); |
| 3966 | EXPECT_EQ(front_facing_surface->id(), |
| 3967 | render_surface_layer_list.at(0) |
| 3968 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3969 | |
| 3970 | // Verify front_facing_surface's layer list. |
| 3971 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3972 | 2u, |
| 3973 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3974 | EXPECT_EQ(front_facing_surface->id(), |
| 3975 | render_surface_layer_list.at(1) |
| 3976 | ->render_surface()->layer_list().at(0)->id()); |
| 3977 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3978 | render_surface_layer_list.at(1) |
| 3979 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3980 | } |
| 3981 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3982 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3983 | // Verify that layers are appropriately culled when their back face is showing |
| 3984 | // and they are not double sided, while animations are going on. |
| 3985 | // |
| 3986 | // Layers that are animating do not get culled on the main thread, as their |
| 3987 | // transforms should be treated as "unknown" so we can not be sure that their |
| 3988 | // back face is really showing. |
| 3989 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3990 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3991 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3992 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3993 | scoped_refptr<LayerWithForcedDrawsContent> animating_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3994 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3995 | scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3996 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3997 | scoped_refptr<LayerWithForcedDrawsContent> animating_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 3998 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3999 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4000 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4001 | |
| 4002 | parent->AddChild(child); |
| 4003 | parent->AddChild(animating_surface); |
| 4004 | animating_surface->AddChild(child_of_animating_surface); |
| 4005 | parent->AddChild(animating_child); |
| 4006 | parent->AddChild(child2); |
| 4007 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4008 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4009 | host->SetRootLayer(parent); |
| 4010 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4011 | // Nothing is double-sided |
| 4012 | child->SetDoubleSided(false); |
| 4013 | child2->SetDoubleSided(false); |
| 4014 | animating_surface->SetDoubleSided(false); |
| 4015 | child_of_animating_surface->SetDoubleSided(false); |
| 4016 | animating_child->SetDoubleSided(false); |
| 4017 | |
| 4018 | gfx::Transform backface_matrix; |
| 4019 | backface_matrix.Translate(50.0, 50.0); |
| 4020 | backface_matrix.RotateAboutYAxis(180.0); |
| 4021 | backface_matrix.Translate(-50.0, -50.0); |
| 4022 | |
| 4023 | // Make our render surface. |
| 4024 | animating_surface->SetForceRenderSurface(true); |
| 4025 | |
| 4026 | // Animate the transform on the render surface. |
| 4027 | AddAnimatedTransformToController( |
| 4028 | animating_surface->layer_animation_controller(), 10.0, 30, 0); |
| 4029 | // This is just an animating layer, not a surface. |
| 4030 | AddAnimatedTransformToController( |
| 4031 | animating_child->layer_animation_controller(), 10.0, 30, 0); |
| 4032 | |
| 4033 | SetLayerPropertiesForTesting(parent.get(), |
| 4034 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4035 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4036 | gfx::PointF(), |
| 4037 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4038 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4039 | false); |
| 4040 | SetLayerPropertiesForTesting(child.get(), |
| 4041 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4042 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4043 | gfx::PointF(), |
| 4044 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4045 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4046 | false); |
| 4047 | SetLayerPropertiesForTesting(animating_surface.get(), |
| 4048 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4049 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4050 | gfx::PointF(), |
| 4051 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4052 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4053 | false); |
| 4054 | SetLayerPropertiesForTesting(child_of_animating_surface.get(), |
| 4055 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4056 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4057 | gfx::PointF(), |
| 4058 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4059 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4060 | false); |
| 4061 | SetLayerPropertiesForTesting(animating_child.get(), |
| 4062 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4063 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4064 | gfx::PointF(), |
| 4065 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4066 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4067 | false); |
| 4068 | SetLayerPropertiesForTesting(child2.get(), |
| 4069 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4070 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4071 | gfx::PointF(), |
| 4072 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4073 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4074 | false); |
| 4075 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4076 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4077 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4078 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4079 | inputs.can_adjust_raster_scales = true; |
| 4080 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4081 | |
| 4082 | EXPECT_FALSE(child->render_surface()); |
| 4083 | EXPECT_TRUE(animating_surface->render_surface()); |
| 4084 | EXPECT_FALSE(child_of_animating_surface->render_surface()); |
| 4085 | EXPECT_FALSE(animating_child->render_surface()); |
| 4086 | EXPECT_FALSE(child2->render_surface()); |
| 4087 | |
| 4088 | // Verify that the animating_child and child_of_animating_surface were not |
| 4089 | // culled, but that child was. |
| 4090 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4091 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4092 | EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4093 | |
| 4094 | // The non-animating child be culled from the layer list for the parent render |
| 4095 | // surface. |
| 4096 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4097 | 3u, |
| 4098 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4099 | EXPECT_EQ(animating_surface->id(), |
| 4100 | render_surface_layer_list.at(0) |
| 4101 | ->render_surface()->layer_list().at(0)->id()); |
| 4102 | EXPECT_EQ(animating_child->id(), |
| 4103 | render_surface_layer_list.at(0) |
| 4104 | ->render_surface()->layer_list().at(1)->id()); |
| 4105 | EXPECT_EQ(child2->id(), |
| 4106 | render_surface_layer_list.at(0) |
| 4107 | ->render_surface()->layer_list().at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4108 | |
| 4109 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4110 | 2u, |
| 4111 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4112 | EXPECT_EQ(animating_surface->id(), |
| 4113 | render_surface_layer_list.at(1) |
| 4114 | ->render_surface()->layer_list().at(0)->id()); |
| 4115 | EXPECT_EQ(child_of_animating_surface->id(), |
| 4116 | render_surface_layer_list.at(1) |
| 4117 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4118 | |
| 4119 | EXPECT_FALSE(child2->visible_content_rect().IsEmpty()); |
| 4120 | |
| 4121 | // The animating layers should have a visible content rect that represents the |
| 4122 | // area of the front face that is within the viewport. |
| 4123 | EXPECT_EQ(animating_child->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4124 | gfx::Rect(animating_child->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4125 | EXPECT_EQ(animating_surface->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4126 | gfx::Rect(animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4127 | // And layers in the subtree of the animating layer should have valid visible |
| 4128 | // content rects also. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4129 | EXPECT_EQ(child_of_animating_surface->visible_content_rect(), |
| 4130 | gfx::Rect(child_of_animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4131 | } |
| 4132 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4133 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4134 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 4135 | // Verify the behavior of back-face culling for a render surface that is |
| 4136 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 4137 | |
| 4138 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4139 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4140 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4141 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4142 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4143 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4144 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4145 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4146 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4147 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4148 | |
| 4149 | parent->AddChild(front_facing_surface); |
| 4150 | parent->AddChild(back_facing_surface); |
| 4151 | front_facing_surface->AddChild(child1); |
| 4152 | back_facing_surface->AddChild(child2); |
| 4153 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4154 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4155 | host->SetRootLayer(parent); |
| 4156 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4157 | // RenderSurfaces are not double-sided |
| 4158 | front_facing_surface->SetDoubleSided(false); |
| 4159 | back_facing_surface->SetDoubleSided(false); |
| 4160 | |
| 4161 | gfx::Transform backface_matrix; |
| 4162 | backface_matrix.Translate(50.0, 50.0); |
| 4163 | backface_matrix.RotateAboutYAxis(180.0); |
| 4164 | backface_matrix.Translate(-50.0, -50.0); |
| 4165 | |
| 4166 | SetLayerPropertiesForTesting(parent.get(), |
| 4167 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4168 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4169 | gfx::PointF(), |
| 4170 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4171 | false, |
| 4172 | true); // parent transform style is preserve3d. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4173 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 4174 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4175 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4176 | gfx::PointF(), |
| 4177 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4178 | true, |
| 4179 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4180 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 4181 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4182 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4183 | gfx::PointF(), |
| 4184 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4185 | true, |
| 4186 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4187 | SetLayerPropertiesForTesting(child1.get(), |
| 4188 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4189 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4190 | gfx::PointF(), |
| 4191 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4192 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4193 | false); |
| 4194 | SetLayerPropertiesForTesting(child2.get(), |
| 4195 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4196 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4197 | gfx::PointF(), |
| 4198 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4199 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4200 | false); |
| 4201 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 4202 | front_facing_surface->Set3dSortingContextId(1); |
| 4203 | back_facing_surface->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4204 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4205 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4206 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4207 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4208 | inputs.can_adjust_raster_scales = true; |
| 4209 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4210 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4211 | // Verify which render surfaces were created and used. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4212 | EXPECT_TRUE(front_facing_surface->render_surface()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 4213 | |
| 4214 | // We expect the render surface to have been created, but remain unused. |
| 4215 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 4216 | EXPECT_NE(back_facing_surface->render_target(), |
| 4217 | back_facing_surface); // because it should be culled |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4218 | EXPECT_FALSE(child1->render_surface()); |
| 4219 | EXPECT_FALSE(child2->render_surface()); |
| 4220 | |
| 4221 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 4222 | // culled. |
| 4223 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4224 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4225 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4226 | |
| 4227 | // Verify root surface's layer list. |
| 4228 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4229 | 1u, |
| 4230 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4231 | EXPECT_EQ(front_facing_surface->id(), |
| 4232 | render_surface_layer_list.at(0) |
| 4233 | ->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4234 | |
| 4235 | // Verify front_facing_surface's layer list. |
| 4236 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4237 | 2u, |
| 4238 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4239 | EXPECT_EQ(front_facing_surface->id(), |
| 4240 | render_surface_layer_list.at(1) |
| 4241 | ->render_surface()->layer_list().at(0)->id()); |
| 4242 | EXPECT_EQ(child1->id(), |
| 4243 | render_surface_layer_list.at(1) |
| 4244 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4245 | } |
| 4246 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4247 | class NoScaleContentLayer : public ContentLayer { |
| 4248 | public: |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4249 | static scoped_refptr<NoScaleContentLayer> Create( |
| 4250 | const LayerSettings& settings, |
| 4251 | ContentLayerClient* client) { |
| 4252 | return make_scoped_refptr(new NoScaleContentLayer(settings, client)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4253 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4254 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 4255 | void CalculateContentsScale(float ideal_contents_scale, |
| 4256 | float* contents_scale_x, |
| 4257 | float* contents_scale_y, |
| 4258 | gfx::Size* content_bounds) override { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4259 | // Skip over the ContentLayer to the base Layer class. |
| 4260 | Layer::CalculateContentsScale(ideal_contents_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4261 | contents_scale_x, |
| 4262 | contents_scale_y, |
| 4263 | content_bounds); |
| 4264 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4265 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4266 | protected: |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4267 | NoScaleContentLayer(const LayerSettings& settings, ContentLayerClient* client) |
| 4268 | : ContentLayer(settings, client) {} |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 4269 | ~NoScaleContentLayer() override {} |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4270 | }; |
| 4271 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4272 | scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer( |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4273 | const LayerSettings& settings, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4274 | ContentLayerClient* delegate) { |
| 4275 | scoped_refptr<NoScaleContentLayer> to_return = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4276 | NoScaleContentLayer::Create(settings, delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4277 | to_return->SetIsDrawable(true); |
| 4278 | return to_return; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4279 | } |
| 4280 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4281 | TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4282 | // Verify draw and screen space transforms of layers not in a surface. |
| 4283 | MockContentLayerClient delegate; |
| 4284 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4285 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4286 | scoped_refptr<FakePictureLayer> parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4287 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4288 | SetLayerPropertiesForTesting(parent.get(), |
| 4289 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4290 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4291 | gfx::PointF(), |
| 4292 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4293 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4294 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4295 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4296 | scoped_refptr<FakePictureLayer> child = |
| 4297 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4298 | SetLayerPropertiesForTesting(child.get(), |
| 4299 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4300 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4301 | gfx::PointF(2.f, 2.f), |
| 4302 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4303 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4304 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4305 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4306 | scoped_refptr<FakePictureLayer> child_empty = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4307 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4308 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4309 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4310 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4311 | gfx::PointF(2.f, 2.f), |
| 4312 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4313 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4314 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4315 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4316 | parent->AddChild(child); |
| 4317 | parent->AddChild(child_empty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4318 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4319 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4320 | host->SetRootLayer(parent); |
| 4321 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4322 | float device_scale_factor = 2.5f; |
| 4323 | float page_scale_factor = 1.f; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4324 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4325 | RenderSurfaceLayerList render_surface_layer_list; |
| 4326 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4327 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4328 | inputs.device_scale_factor = device_scale_factor; |
| 4329 | inputs.page_scale_factor = page_scale_factor; |
| 4330 | inputs.can_adjust_raster_scales = true; |
| 4331 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4332 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4333 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4334 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4335 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child_empty); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4336 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4337 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4338 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4339 | // Verify parent transforms |
| 4340 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4341 | expected_parent_transform.Scale(device_scale_factor * page_scale_factor, |
| 4342 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4343 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4344 | parent->screen_space_transform()); |
| 4345 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4346 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4347 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4348 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4349 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4350 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4351 | gfx::RectF parent_draw_rect = |
| 4352 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4353 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4354 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4355 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4356 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4357 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4358 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4359 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4360 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4361 | // Verify child and child_empty transforms. They should match. |
| 4362 | gfx::Transform expected_child_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4363 | expected_child_transform.Scale(device_scale_factor, device_scale_factor); |
| 4364 | expected_child_transform.Translate(child->position().x(), |
| 4365 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4366 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4367 | child->draw_transform()); |
| 4368 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4369 | child->screen_space_transform()); |
| 4370 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4371 | child_empty->draw_transform()); |
| 4372 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4373 | child_empty->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4374 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4375 | // Verify results of transformed child and child_empty rects. They should |
| 4376 | // match. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4377 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4378 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4379 | gfx::RectF child_draw_rect = |
| 4380 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4381 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4382 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4383 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4384 | gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( |
| 4385 | child_empty->draw_transform(), child_content_bounds); |
| 4386 | gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( |
| 4387 | child_empty->screen_space_transform(), child_content_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4388 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4389 | gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); |
| 4390 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4391 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4392 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
| 4393 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); |
| 4394 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4395 | } |
| 4396 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4397 | TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4398 | // Verify draw and screen space transforms of layers in a surface. |
| 4399 | MockContentLayerClient delegate; |
| 4400 | gfx::Transform identity_matrix; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4401 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4402 | gfx::Transform perspective_matrix; |
| 4403 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4404 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4405 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4406 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4407 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4408 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4409 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4410 | scoped_refptr<FakePictureLayer> parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4411 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4412 | SetLayerPropertiesForTesting(parent.get(), |
| 4413 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4414 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4415 | gfx::PointF(), |
| 4416 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4417 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4418 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4419 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4420 | scoped_refptr<FakePictureLayer> perspective_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4421 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4422 | SetLayerPropertiesForTesting(perspective_surface.get(), |
| 4423 | perspective_matrix * scale_small_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4424 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4425 | gfx::PointF(2.f, 2.f), |
| 4426 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4427 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4428 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4429 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4430 | scoped_refptr<FakePictureLayer> scale_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4431 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4432 | SetLayerPropertiesForTesting(scale_surface.get(), |
| 4433 | scale_small_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4434 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4435 | gfx::PointF(2.f, 2.f), |
| 4436 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4437 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4438 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4439 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4440 | perspective_surface->SetForceRenderSurface(true); |
| 4441 | scale_surface->SetForceRenderSurface(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4442 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4443 | parent->AddChild(perspective_surface); |
| 4444 | parent->AddChild(scale_surface); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4445 | root->AddChild(parent); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4446 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4447 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4448 | host->SetRootLayer(root); |
| 4449 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4450 | float device_scale_factor = 2.5f; |
| 4451 | float page_scale_factor = 3.f; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4452 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4453 | RenderSurfaceLayerList render_surface_layer_list; |
| 4454 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4455 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 4456 | inputs.device_scale_factor = device_scale_factor; |
| 4457 | inputs.page_scale_factor = page_scale_factor; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 4458 | inputs.page_scale_layer = root.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4459 | inputs.can_adjust_raster_scales = true; |
| 4460 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4461 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4462 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4463 | EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4464 | perspective_surface); |
| 4465 | // Ideal scale is the max 2d scale component of the combined transform up to |
| 4466 | // the nearest render target. Here this includes the layer transform as well |
| 4467 | // as the device and page scale factors. |
| 4468 | gfx::Transform transform = scale_small_matrix; |
| 4469 | transform.Scale(device_scale_factor * page_scale_factor, |
| 4470 | device_scale_factor * page_scale_factor); |
| 4471 | gfx::Vector2dF scales = |
| 4472 | MathUtil::ComputeTransform2dScaleComponents(transform, 0.f); |
| 4473 | float max_2d_scale = std::max(scales.x(), scales.y()); |
| 4474 | EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface); |
| 4475 | |
| 4476 | // The ideal scale will draw 1:1 with its render target space along |
| 4477 | // the larger-scale axis. |
| 4478 | gfx::Vector2dF target_space_transform_scales = |
| 4479 | MathUtil::ComputeTransform2dScaleComponents( |
| 4480 | scale_surface->draw_properties().target_space_transform, 0.f); |
| 4481 | EXPECT_FLOAT_EQ(max_2d_scale, |
| 4482 | std::max(target_space_transform_scales.x(), |
| 4483 | target_space_transform_scales.y())); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4484 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4485 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4486 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4487 | gfx::Transform expected_parent_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4488 | expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor, |
| 4489 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4490 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
| 4491 | parent->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4492 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4493 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4494 | // with the screen, and then scaled during drawing. |
| 4495 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4496 | expected_perspective_surface_draw_transform.Translate( |
| 4497 | device_scale_factor * page_scale_factor * |
| 4498 | perspective_surface->position().x(), |
| 4499 | device_scale_factor * page_scale_factor * |
| 4500 | perspective_surface->position().y()); |
| 4501 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4502 | perspective_matrix); |
| 4503 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4504 | scale_small_matrix); |
| 4505 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4506 | expected_perspective_surface_layer_draw_transform.Scale( |
| 4507 | device_scale_factor * page_scale_factor, |
| 4508 | device_scale_factor * page_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4509 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4510 | expected_perspective_surface_draw_transform, |
| 4511 | perspective_surface->render_surface()->draw_transform()); |
| 4512 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4513 | expected_perspective_surface_layer_draw_transform, |
| 4514 | perspective_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4515 | } |
| 4516 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4517 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4518 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4519 | LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { |
| 4520 | // Verify draw and screen space transforms of layers not in a surface. |
| 4521 | MockContentLayerClient delegate; |
| 4522 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4523 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4524 | scoped_refptr<ContentLayer> parent = |
| 4525 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4526 | SetLayerPropertiesForTesting(parent.get(), |
| 4527 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4528 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4529 | gfx::PointF(), |
| 4530 | gfx::Size(133, 133), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4531 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4532 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4533 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4534 | scoped_refptr<ContentLayer> child = |
| 4535 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4536 | SetLayerPropertiesForTesting(child.get(), |
| 4537 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4538 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4539 | gfx::PointF(), |
| 4540 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4541 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4542 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4543 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4544 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4545 | CreateNoScaleDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4546 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4547 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4548 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4549 | gfx::PointF(), |
| 4550 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4551 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4552 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4553 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4554 | parent->AddChild(child); |
| 4555 | parent->AddChild(child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4556 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4557 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4558 | host->SetRootLayer(parent); |
| 4559 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4560 | float device_scale_factor = 1.7f; |
| 4561 | float page_scale_factor = 1.f; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4562 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4563 | RenderSurfaceLayerList render_surface_layer_list; |
| 4564 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4565 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4566 | inputs.device_scale_factor = device_scale_factor; |
| 4567 | inputs.page_scale_factor = page_scale_factor; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 4568 | inputs.page_scale_layer = parent.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4569 | inputs.can_adjust_raster_scales = true; |
enne | 432edd0 | 2015-05-11 18:38:33 | [diff] [blame] | 4570 | inputs.verify_property_trees = false; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4571 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4572 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4573 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4574 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4575 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4576 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4577 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4578 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4579 | // Verify parent transforms |
| 4580 | gfx::Transform expected_parent_transform; |
| 4581 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4582 | parent->screen_space_transform()); |
| 4583 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4584 | parent->draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4585 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4586 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4587 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4588 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4589 | gfx::RectF parent_draw_rect = |
| 4590 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4591 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4592 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4593 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4594 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4595 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4596 | expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width())); |
| 4597 | expected_parent_draw_rect.set_height( |
| 4598 | ceil(expected_parent_draw_rect.height())); |
| 4599 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4600 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4601 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4602 | // Verify child transforms |
| 4603 | gfx::Transform expected_child_transform; |
| 4604 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4605 | child->draw_transform()); |
| 4606 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4607 | child->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4608 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4609 | // Verify results of transformed child rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4610 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4611 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4612 | gfx::RectF child_draw_rect = |
| 4613 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4614 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4615 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4616 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4617 | gfx::RectF expected_child_draw_rect(child->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4618 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4619 | expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width())); |
| 4620 | expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height())); |
| 4621 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4622 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4623 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4624 | // Verify child_no_scale transforms |
| 4625 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 4626 | // All transforms operate on content rects. The child's content rect |
| 4627 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 4628 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 4629 | device_scale_factor); |
| 4630 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4631 | child_no_scale->draw_transform()); |
| 4632 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4633 | child_no_scale->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4634 | } |
| 4635 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4636 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4637 | TEST_F(LayerTreeHostCommonTest, ContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4638 | MockContentLayerClient delegate; |
| 4639 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4640 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4641 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4642 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4643 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4644 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4645 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4646 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4647 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4648 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4649 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4650 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4651 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4652 | scoped_refptr<ContentLayer> parent = |
| 4653 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4654 | SetLayerPropertiesForTesting(parent.get(), |
| 4655 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4656 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4657 | gfx::PointF(), |
| 4658 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4659 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4660 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4661 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4662 | scoped_refptr<ContentLayer> child_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4663 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4664 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4665 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4666 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4667 | gfx::PointF(2.f, 2.f), |
| 4668 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4669 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4670 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4671 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4672 | scoped_refptr<ContentLayer> child_empty = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4673 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4674 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4675 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4676 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4677 | gfx::PointF(2.f, 2.f), |
| 4678 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4679 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4680 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4681 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4682 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4683 | CreateNoScaleDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4684 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4685 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4686 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4687 | gfx::PointF(12.f, 12.f), |
| 4688 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4689 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4690 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4691 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4692 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4693 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4694 | parent->AddChild(child_scale); |
| 4695 | parent->AddChild(child_empty); |
| 4696 | parent->AddChild(child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4697 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4698 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4699 | host->SetRootLayer(root); |
| 4700 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4701 | float device_scale_factor = 2.5f; |
| 4702 | float page_scale_factor = 1.f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4703 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4704 | { |
| 4705 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4706 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4707 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4708 | inputs.device_scale_factor = device_scale_factor; |
| 4709 | inputs.page_scale_factor = page_scale_factor; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 4710 | inputs.page_scale_layer = root.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4711 | inputs.can_adjust_raster_scales = true; |
enne | 432edd0 | 2015-05-11 18:38:33 | [diff] [blame] | 4712 | inputs.verify_property_trees = false; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4713 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4714 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4715 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4716 | initial_parent_scale, parent); |
| 4717 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4718 | initial_parent_scale * initial_child_scale, |
| 4719 | child_scale); |
| 4720 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4721 | initial_parent_scale * initial_child_scale, |
| 4722 | child_empty); |
| 4723 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4724 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4725 | // The parent is scaled up and shouldn't need to scale during draw. The |
| 4726 | // child that can scale its contents should also not need to scale during |
| 4727 | // draw. This shouldn't change if the child has empty bounds. The other |
| 4728 | // children should. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4729 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 4730 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
| 4731 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0)); |
| 4732 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1)); |
| 4733 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0)); |
| 4734 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4735 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 4736 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4737 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4738 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4739 | initial_parent_scale * initial_child_scale, |
| 4740 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4741 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4742 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4743 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 4744 | // updated using the initial transform as the raster scale. |
| 4745 | device_scale_factor = 2.25f; |
| 4746 | page_scale_factor = 1.25f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4747 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4748 | { |
| 4749 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4750 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4751 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4752 | inputs.device_scale_factor = device_scale_factor; |
| 4753 | inputs.page_scale_factor = page_scale_factor; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 4754 | inputs.page_scale_layer = root.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4755 | inputs.can_adjust_raster_scales = true; |
enne | 432edd0 | 2015-05-11 18:38:33 | [diff] [blame] | 4756 | inputs.verify_property_trees = false; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4757 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 4758 | |
| 4759 | EXPECT_CONTENTS_SCALE_EQ( |
| 4760 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4761 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4762 | initial_parent_scale * initial_child_scale, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4763 | child_scale); |
| 4764 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4765 | initial_parent_scale * initial_child_scale, |
| 4766 | child_empty); |
| 4767 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4768 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4769 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4770 | // 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] | 4771 | SkMScalar second_child_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4772 | child_scale_matrix.Scale(second_child_scale / initial_child_scale, |
| 4773 | second_child_scale / initial_child_scale); |
| 4774 | child_scale->SetTransform(child_scale_matrix); |
| 4775 | child_empty->SetTransform(child_scale_matrix); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4776 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4777 | { |
| 4778 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4779 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4780 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4781 | inputs.device_scale_factor = device_scale_factor; |
| 4782 | inputs.page_scale_factor = page_scale_factor; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 4783 | inputs.page_scale_layer = root.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4784 | inputs.can_adjust_raster_scales = true; |
enne | 432edd0 | 2015-05-11 18:38:33 | [diff] [blame] | 4785 | inputs.verify_property_trees = false; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4786 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4787 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4788 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4789 | initial_parent_scale, |
| 4790 | parent); |
| 4791 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4792 | child_scale); |
| 4793 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4794 | child_empty); |
| 4795 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4796 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4797 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4798 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 4799 | // updated, but still using 1.0 as the raster scale. |
| 4800 | device_scale_factor = 2.75f; |
| 4801 | page_scale_factor = 1.75f; |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4802 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4803 | { |
| 4804 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4805 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4806 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4807 | inputs.device_scale_factor = device_scale_factor; |
| 4808 | inputs.page_scale_factor = page_scale_factor; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 4809 | inputs.page_scale_layer = root.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4810 | inputs.can_adjust_raster_scales = true; |
enne | 432edd0 | 2015-05-11 18:38:33 | [diff] [blame] | 4811 | inputs.verify_property_trees = false; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4812 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4813 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4814 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4815 | initial_parent_scale, |
| 4816 | parent); |
| 4817 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4818 | child_scale); |
| 4819 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4820 | child_empty); |
| 4821 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4822 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4823 | } |
| 4824 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4825 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4826 | TEST_F(LayerTreeHostCommonTest, |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4827 | ContentsScale_LayerTransformsDontAffectContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4828 | MockContentLayerClient delegate; |
| 4829 | gfx::Transform identity_matrix; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4830 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4831 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4832 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4833 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4834 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4835 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4836 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4837 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4838 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4839 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4840 | root->SetBounds(gfx::Size(100, 100)); |
| 4841 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4842 | scoped_refptr<ContentLayer> parent = |
| 4843 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4844 | SetLayerPropertiesForTesting(parent.get(), |
| 4845 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4846 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4847 | gfx::PointF(), |
| 4848 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4849 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4850 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4851 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4852 | scoped_refptr<ContentLayer> child_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4853 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4854 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4855 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4856 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4857 | gfx::PointF(2.f, 2.f), |
| 4858 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4859 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4860 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4861 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4862 | scoped_refptr<ContentLayer> child_empty = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4863 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4864 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4865 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4866 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4867 | gfx::PointF(2.f, 2.f), |
| 4868 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4869 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4870 | true); |
| 4871 | |
| 4872 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4873 | CreateNoScaleDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4874 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4875 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4876 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4877 | gfx::PointF(12.f, 12.f), |
| 4878 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4879 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4880 | true); |
| 4881 | |
| 4882 | root->AddChild(parent); |
| 4883 | |
| 4884 | parent->AddChild(child_scale); |
| 4885 | parent->AddChild(child_empty); |
| 4886 | parent->AddChild(child_no_scale); |
| 4887 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4888 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4889 | host->SetRootLayer(root); |
| 4890 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4891 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4892 | |
| 4893 | float device_scale_factor = 2.5f; |
| 4894 | float page_scale_factor = 1.f; |
| 4895 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4896 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4897 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4898 | inputs.device_scale_factor = device_scale_factor; |
| 4899 | inputs.page_scale_factor = page_scale_factor; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 4900 | inputs.page_scale_layer = root.get(); |
enne | 432edd0 | 2015-05-11 18:38:33 | [diff] [blame] | 4901 | inputs.verify_property_trees = false; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4902 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4903 | |
| 4904 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4905 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4906 | child_scale); |
| 4907 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4908 | child_empty); |
| 4909 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4910 | |
| 4911 | // Since the transform scale does not affect contents scale, it should affect |
| 4912 | // the draw transform instead. |
| 4913 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4914 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4915 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4916 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4917 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4918 | child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4919 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4920 | child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4921 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4922 | child_empty->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4923 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4924 | child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4925 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4926 | initial_parent_scale * initial_child_scale, |
| 4927 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4928 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4929 | initial_parent_scale * initial_child_scale, |
| 4930 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4931 | } |
| 4932 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4933 | TEST_F(LayerTreeHostCommonTest, SmallIdealScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4934 | MockContentLayerClient delegate; |
| 4935 | gfx::Transform identity_matrix; |
| 4936 | |
| 4937 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4938 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4939 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4940 | |
| 4941 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4942 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4943 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4944 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4945 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4946 | root->SetBounds(gfx::Size(100, 100)); |
| 4947 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4948 | scoped_refptr<FakePictureLayer> parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4949 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4950 | SetLayerPropertiesForTesting(parent.get(), |
| 4951 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4952 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4953 | gfx::PointF(), |
| 4954 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4955 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4956 | true); |
| 4957 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4958 | scoped_refptr<FakePictureLayer> child_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 4959 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4960 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4961 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4962 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4963 | gfx::PointF(2.f, 2.f), |
| 4964 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4965 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4966 | true); |
| 4967 | |
| 4968 | root->AddChild(parent); |
| 4969 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4970 | parent->AddChild(child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4971 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 4972 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4973 | host->SetRootLayer(root); |
| 4974 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4975 | float device_scale_factor = 2.5f; |
| 4976 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4977 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4978 | { |
| 4979 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4980 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 4981 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4982 | inputs.device_scale_factor = device_scale_factor; |
| 4983 | inputs.page_scale_factor = page_scale_factor; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 4984 | inputs.page_scale_layer = root.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4985 | inputs.can_adjust_raster_scales = true; |
| 4986 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4987 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4988 | // The ideal scale is able to go below 1. |
| 4989 | float expected_ideal_scale = |
| 4990 | device_scale_factor * page_scale_factor * initial_parent_scale; |
| 4991 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4992 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4993 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 4994 | expected_ideal_scale = device_scale_factor * page_scale_factor * |
| 4995 | initial_parent_scale * initial_child_scale; |
| 4996 | EXPECT_LT(expected_ideal_scale, 1.f); |
| 4997 | EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4998 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4999 | } |
| 5000 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5001 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5002 | MockContentLayerClient delegate; |
| 5003 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5004 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5005 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5006 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5007 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5008 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5009 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5010 | SkMScalar initial_child_scale = 3.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5011 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5012 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5013 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5014 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5015 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5016 | scoped_refptr<ContentLayer> parent = |
| 5017 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5018 | SetLayerPropertiesForTesting(parent.get(), |
| 5019 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5020 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5021 | gfx::PointF(), |
| 5022 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5023 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5024 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5025 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5026 | scoped_refptr<ContentLayer> surface_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5027 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5028 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 5029 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5030 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5031 | gfx::PointF(2.f, 2.f), |
| 5032 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5033 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5034 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5035 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5036 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5037 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5038 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 5039 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5040 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5041 | gfx::PointF(), |
| 5042 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5043 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5044 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5045 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5046 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5047 | CreateNoScaleDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5048 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 5049 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5050 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5051 | gfx::PointF(), |
| 5052 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5053 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5054 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5055 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5056 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5057 | CreateNoScaleDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5058 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 5059 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5060 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5061 | gfx::PointF(12.f, 12.f), |
| 5062 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5063 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5064 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5065 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5066 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5067 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5068 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 5069 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5070 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5071 | gfx::PointF(), |
| 5072 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5073 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5074 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5075 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5076 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5077 | CreateNoScaleDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5078 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 5079 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5080 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5081 | gfx::PointF(), |
| 5082 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5083 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5084 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5085 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5086 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5087 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5088 | parent->AddChild(surface_scale); |
| 5089 | parent->AddChild(surface_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5090 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5091 | surface_scale->SetForceRenderSurface(true); |
| 5092 | surface_scale->AddChild(surface_scale_child_scale); |
| 5093 | surface_scale->AddChild(surface_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5094 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5095 | surface_no_scale->SetForceRenderSurface(true); |
| 5096 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 5097 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5098 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5099 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5100 | host->SetRootLayer(root); |
| 5101 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5102 | SkMScalar device_scale_factor = 5; |
| 5103 | SkMScalar page_scale_factor = 7; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5104 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5105 | RenderSurfaceLayerList render_surface_layer_list; |
| 5106 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5107 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5108 | inputs.device_scale_factor = device_scale_factor; |
| 5109 | inputs.page_scale_factor = page_scale_factor; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 5110 | inputs.page_scale_layer = root.get(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5111 | inputs.can_adjust_raster_scales = true; |
enne | 432edd0 | 2015-05-11 18:38:33 | [diff] [blame] | 5112 | inputs.verify_property_trees = false; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5113 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5114 | |
| 5115 | EXPECT_CONTENTS_SCALE_EQ( |
| 5116 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 5117 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5118 | initial_parent_scale * initial_child_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5119 | surface_scale); |
| 5120 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale); |
| 5121 | EXPECT_CONTENTS_SCALE_EQ( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5122 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5123 | initial_child_scale * initial_child_scale, |
| 5124 | surface_scale_child_scale); |
| 5125 | EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale); |
| 5126 | EXPECT_CONTENTS_SCALE_EQ( |
| 5127 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5128 | initial_child_scale * initial_child_scale, |
| 5129 | surface_no_scale_child_scale); |
| 5130 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5131 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5132 | // The parent is scaled up and shouldn't need to scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5133 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 5134 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5135 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5136 | // RenderSurfaces should always be 1:1 with their target. |
| 5137 | EXPECT_FLOAT_EQ( |
| 5138 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5139 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5140 | EXPECT_FLOAT_EQ( |
| 5141 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5142 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5143 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5144 | // The surface_scale can apply contents scale so the layer shouldn't need to |
| 5145 | // scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5146 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 5147 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5148 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5149 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 5150 | // to scale during draw. |
| 5151 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5152 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5153 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5154 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5155 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5156 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 5157 | // to be scaled during draw. |
| 5158 | EXPECT_FLOAT_EQ( |
| 5159 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5160 | initial_child_scale * initial_child_scale, |
| 5161 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5162 | EXPECT_FLOAT_EQ( |
| 5163 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5164 | initial_child_scale * initial_child_scale, |
| 5165 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5166 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5167 | // RenderSurfaces should always be 1:1 with their target. |
| 5168 | EXPECT_FLOAT_EQ( |
| 5169 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5170 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5171 | EXPECT_FLOAT_EQ( |
| 5172 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5173 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5174 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5175 | // The surface_no_scale layer can not apply contents scale, so it needs to be |
| 5176 | // scaled during draw. |
| 5177 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5178 | initial_parent_scale * initial_child_scale, |
| 5179 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5180 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5181 | initial_parent_scale * initial_child_scale, |
| 5182 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5183 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5184 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 5185 | // to scale during draw. |
| 5186 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5187 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5188 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5189 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5190 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5191 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 5192 | // to be scaled during draw. |
| 5193 | EXPECT_FLOAT_EQ( |
| 5194 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5195 | initial_child_scale * initial_child_scale, |
| 5196 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5197 | EXPECT_FLOAT_EQ( |
| 5198 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5199 | initial_child_scale * initial_child_scale, |
| 5200 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5201 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5202 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5203 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5204 | TEST_F(LayerTreeHostCommonTest, |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5205 | ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5206 | MockContentLayerClient delegate; |
| 5207 | gfx::Transform identity_matrix; |
| 5208 | |
| 5209 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5210 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5211 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 5212 | |
| 5213 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5214 | SkMScalar initial_child_scale = 3.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5215 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 5216 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5217 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5218 | root->SetBounds(gfx::Size(100, 100)); |
| 5219 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5220 | scoped_refptr<ContentLayer> parent = |
| 5221 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5222 | SetLayerPropertiesForTesting(parent.get(), |
| 5223 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5224 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5225 | gfx::PointF(), |
| 5226 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5227 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5228 | true); |
| 5229 | |
| 5230 | scoped_refptr<ContentLayer> surface_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5231 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5232 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 5233 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5234 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5235 | gfx::PointF(2.f, 2.f), |
| 5236 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5237 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5238 | true); |
| 5239 | |
| 5240 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5241 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5242 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 5243 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5244 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5245 | gfx::PointF(), |
| 5246 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5247 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5248 | true); |
| 5249 | |
| 5250 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5251 | CreateNoScaleDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5252 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 5253 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5254 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5255 | gfx::PointF(), |
| 5256 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5257 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5258 | true); |
| 5259 | |
| 5260 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5261 | CreateNoScaleDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5262 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 5263 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5264 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5265 | gfx::PointF(12.f, 12.f), |
| 5266 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5267 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5268 | true); |
| 5269 | |
| 5270 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5271 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5272 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 5273 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5274 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5275 | gfx::PointF(), |
| 5276 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5277 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5278 | true); |
| 5279 | |
| 5280 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5281 | CreateNoScaleDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5282 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 5283 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5284 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5285 | gfx::PointF(), |
| 5286 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5287 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5288 | true); |
| 5289 | |
| 5290 | root->AddChild(parent); |
| 5291 | |
| 5292 | parent->AddChild(surface_scale); |
| 5293 | parent->AddChild(surface_no_scale); |
| 5294 | |
| 5295 | surface_scale->SetForceRenderSurface(true); |
| 5296 | surface_scale->AddChild(surface_scale_child_scale); |
| 5297 | surface_scale->AddChild(surface_scale_child_no_scale); |
| 5298 | |
| 5299 | surface_no_scale->SetForceRenderSurface(true); |
| 5300 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 5301 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
| 5302 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5303 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5304 | host->SetRootLayer(root); |
| 5305 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5306 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5307 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5308 | SkMScalar device_scale_factor = 5.0; |
| 5309 | SkMScalar page_scale_factor = 7.0; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5310 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5311 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5312 | inputs.device_scale_factor = device_scale_factor; |
| 5313 | inputs.page_scale_factor = page_scale_factor; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 5314 | inputs.page_scale_layer = root.get(); |
enne | 432edd0 | 2015-05-11 18:38:33 | [diff] [blame] | 5315 | inputs.verify_property_trees = false; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5316 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5317 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5318 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5319 | parent); |
| 5320 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5321 | surface_scale); |
| 5322 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale); |
| 5323 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5324 | surface_scale_child_scale); |
| 5325 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale); |
| 5326 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5327 | surface_no_scale_child_scale); |
| 5328 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale); |
| 5329 | |
| 5330 | // The parent is scaled up during draw, since its contents are not scaled by |
| 5331 | // the transform hierarchy. |
| 5332 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5333 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5334 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5335 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5336 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5337 | // 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] | 5338 | // by the transform hierarchy. |
| 5339 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5340 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5341 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5342 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5343 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5344 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5345 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5346 | // The surface_scale's RenderSurface is not scaled during draw, so the layer |
| 5347 | // needs to be scaled when drawing into its surface. |
| 5348 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 5349 | surface_scale->draw_transform().matrix().get(0, 0)); |
| 5350 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
| 5351 | surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5352 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5353 | // The surface_scale_child_scale is not scaled when drawing into its surface, |
| 5354 | // since its content bounds are scaled by the transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5355 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5356 | initial_child_scale * initial_child_scale * initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5357 | surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5358 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5359 | initial_child_scale * initial_child_scale * initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5360 | surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5361 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5362 | // The surface_scale_child_no_scale is scaled by the device scale, page scale |
| 5363 | // and transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5364 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5365 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5366 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5367 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5368 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5369 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5370 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5371 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5372 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5373 | // 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] | 5374 | // by the transform hierarchy. |
| 5375 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5376 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5377 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5378 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5379 | 1.f, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5380 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5381 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5382 | // The surface_no_scale layer has a fixed contents scale of 1, so it needs to |
| 5383 | // be scaled by the device and page scale factors. Its surface is already |
| 5384 | // scaled by the transform hierarchy so those don't need to scale the layer's |
| 5385 | // drawing. |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5386 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale * |
| 5387 | device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5388 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5389 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale * |
| 5390 | device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5391 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5392 | |
| 5393 | // The surface_no_scale_child_scale has its contents scaled by the page and |
| 5394 | // device scale factors, but needs to be scaled by the transform hierarchy |
| 5395 | // when drawing. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5396 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5397 | initial_parent_scale * initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5398 | surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5399 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5400 | initial_parent_scale * initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5401 | surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5402 | |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5403 | // The surface_no_scale_child_no_scale needs to be scaled by the device and |
| 5404 | // page scale factors and by any transform heirarchy below its target surface. |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5405 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5406 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5407 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5408 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5409 | EXPECT_FLOAT_EQ( |
hendrikw | c493d268 | 2015-01-26 23:35:11 | [diff] [blame] | 5410 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 5411 | initial_child_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5412 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5413 | } |
| 5414 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5415 | TEST_F(LayerTreeHostCommonTest, IdealScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5416 | MockContentLayerClient delegate; |
| 5417 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5418 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5419 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5420 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5421 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5422 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5423 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5424 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5425 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5426 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5427 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5428 | root->SetBounds(gfx::Size(100, 100)); |
| 5429 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5430 | scoped_refptr<FakePictureLayer> parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5431 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5432 | SetLayerPropertiesForTesting(parent.get(), |
| 5433 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5434 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5435 | gfx::PointF(), |
| 5436 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5437 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5438 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5439 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5440 | scoped_refptr<FakePictureLayer> child_scale = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5441 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5442 | SetLayerPropertiesForTesting(child_scale.get(), |
| 5443 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5444 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5445 | gfx::PointF(2.f, 2.f), |
| 5446 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5447 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5448 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5449 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5450 | root->AddChild(parent); |
| 5451 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5452 | parent->AddChild(child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5453 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5454 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5455 | host->SetRootLayer(root); |
| 5456 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5457 | { |
| 5458 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5459 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5460 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5461 | inputs.can_adjust_raster_scales = true; |
| 5462 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5463 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5464 | EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent); |
| 5465 | // Animating layers compute ideal scale in the same way as when |
| 5466 | // they are static. |
| 5467 | EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale, |
| 5468 | child_scale); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5469 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5470 | } |
| 5471 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5472 | // TODO(sohanjg): Remove this test when ContentLayer is removed. |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5473 | TEST_F(LayerTreeHostCommonTest, |
| 5474 | ChangeInContentBoundsOrScaleTriggersPushProperties) { |
| 5475 | MockContentLayerClient delegate; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5476 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 5477 | scoped_refptr<Layer> child = |
| 5478 | CreateDrawableContentLayer(layer_settings(), &delegate); |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5479 | root->AddChild(child); |
| 5480 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5481 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5482 | host->SetRootLayer(root); |
| 5483 | |
| 5484 | gfx::Transform identity_matrix; |
| 5485 | SetLayerPropertiesForTesting(root.get(), |
| 5486 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5487 | gfx::Point3F(), |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5488 | gfx::PointF(), |
| 5489 | gfx::Size(100, 100), |
| 5490 | true, |
| 5491 | false); |
| 5492 | SetLayerPropertiesForTesting(child.get(), |
| 5493 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5494 | gfx::Point3F(), |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5495 | gfx::PointF(), |
| 5496 | gfx::Size(100, 100), |
| 5497 | true, |
| 5498 | false); |
| 5499 | |
| 5500 | root->reset_needs_push_properties_for_testing(); |
| 5501 | child->reset_needs_push_properties_for_testing(); |
| 5502 | |
enne | 432edd0 | 2015-05-11 18:38:33 | [diff] [blame] | 5503 | gfx::Size device_viewport_size = gfx::Size(100, 100); |
| 5504 | RenderSurfaceLayerList render_surface_layer_list; |
| 5505 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5506 | root.get(), device_viewport_size, &render_surface_layer_list); |
| 5507 | inputs.device_scale_factor = 1.f; |
| 5508 | inputs.can_adjust_raster_scales = true; |
| 5509 | inputs.verify_property_trees = false; |
| 5510 | |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5511 | // This will change both layers' content bounds. |
enne | 432edd0 | 2015-05-11 18:38:33 | [diff] [blame] | 5512 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5513 | EXPECT_TRUE(root->needs_push_properties()); |
| 5514 | EXPECT_TRUE(child->needs_push_properties()); |
| 5515 | |
| 5516 | root->reset_needs_push_properties_for_testing(); |
| 5517 | child->reset_needs_push_properties_for_testing(); |
| 5518 | |
| 5519 | // This will change only the child layer's contents scale and content bounds, |
| 5520 | // since the root layer is not a ContentsScalingLayer. |
enne | 432edd0 | 2015-05-11 18:38:33 | [diff] [blame] | 5521 | inputs.device_scale_factor = 2.f; |
| 5522 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5523 | EXPECT_FALSE(root->needs_push_properties()); |
| 5524 | EXPECT_TRUE(child->needs_push_properties()); |
| 5525 | |
| 5526 | root->reset_needs_push_properties_for_testing(); |
| 5527 | child->reset_needs_push_properties_for_testing(); |
| 5528 | |
| 5529 | // This will not change either layer's contents scale or content bounds. |
enne | 432edd0 | 2015-05-11 18:38:33 | [diff] [blame] | 5530 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5531 | EXPECT_FALSE(root->needs_push_properties()); |
| 5532 | EXPECT_FALSE(child->needs_push_properties()); |
| 5533 | } |
| 5534 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5535 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5536 | MockContentLayerClient delegate; |
| 5537 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5538 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5539 | scoped_refptr<FakePictureLayer> parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5540 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5541 | SetLayerPropertiesForTesting(parent.get(), |
| 5542 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5543 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5544 | gfx::PointF(), |
| 5545 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5546 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5547 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5548 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5549 | scoped_refptr<FakePictureLayer> child = |
| 5550 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5551 | SetLayerPropertiesForTesting(child.get(), |
| 5552 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5553 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5554 | gfx::PointF(2.f, 2.f), |
| 5555 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5556 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5557 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5558 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5559 | gfx::Transform replica_transform; |
| 5560 | replica_transform.Scale(1.0, -1.0); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5561 | scoped_refptr<FakePictureLayer> replica = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5562 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5563 | SetLayerPropertiesForTesting(replica.get(), |
| 5564 | replica_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5565 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5566 | gfx::PointF(2.f, 2.f), |
| 5567 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5568 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5569 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5570 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5571 | // This layer should end up in the same surface as child, with the same draw |
| 5572 | // and screen space transforms. |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5573 | scoped_refptr<FakePictureLayer> duplicate_child_non_owner = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5574 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5575 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 5576 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5577 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5578 | gfx::PointF(), |
| 5579 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5580 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5581 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5582 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5583 | parent->AddChild(child); |
| 5584 | child->AddChild(duplicate_child_non_owner); |
| 5585 | child->SetReplicaLayer(replica.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5586 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5587 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5588 | host->SetRootLayer(parent); |
| 5589 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5590 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5591 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5592 | float device_scale_factor = 1.5f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5593 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5594 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5595 | inputs.device_scale_factor = device_scale_factor; |
| 5596 | inputs.can_adjust_raster_scales = true; |
| 5597 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5598 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5599 | // We should have two render surfaces. The root's render surface and child's |
| 5600 | // render surface (it needs one because it has a replica layer). |
| 5601 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5602 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5603 | gfx::Transform expected_parent_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5604 | expected_parent_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5605 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5606 | parent->screen_space_transform()); |
| 5607 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5608 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5609 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5610 | gfx::Transform expected_draw_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5611 | expected_draw_transform.Scale(device_scale_factor, device_scale_factor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5612 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
| 5613 | child->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5614 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5615 | gfx::Transform expected_screen_space_transform; |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5616 | expected_screen_space_transform.Scale(device_scale_factor, |
| 5617 | device_scale_factor); |
| 5618 | expected_screen_space_transform.Translate(child->position().x(), |
| 5619 | child->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5620 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 5621 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5622 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5623 | gfx::Transform expected_duplicate_child_draw_transform = |
| 5624 | child->draw_transform(); |
| 5625 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), |
| 5626 | duplicate_child_non_owner->draw_transform()); |
| 5627 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5628 | child->screen_space_transform(), |
| 5629 | duplicate_child_non_owner->screen_space_transform()); |
hush | 6b61421 | 2014-12-04 22:37:32 | [diff] [blame] | 5630 | EXPECT_EQ(child->drawable_content_rect(), |
| 5631 | duplicate_child_non_owner->drawable_content_rect()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5632 | EXPECT_EQ(child->content_bounds(), |
| 5633 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5634 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5635 | gfx::Transform expected_render_surface_draw_transform; |
| 5636 | expected_render_surface_draw_transform.Translate( |
| 5637 | device_scale_factor * child->position().x(), |
| 5638 | device_scale_factor * child->position().y()); |
| 5639 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 5640 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5641 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5642 | gfx::Transform expected_surface_draw_transform; |
| 5643 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 5644 | device_scale_factor * 2.f); |
| 5645 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 5646 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5647 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5648 | gfx::Transform expected_surface_screen_space_transform; |
| 5649 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 5650 | device_scale_factor * 2.f); |
| 5651 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5652 | expected_surface_screen_space_transform, |
| 5653 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5654 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5655 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5656 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 5657 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 5658 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5659 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5660 | expected_replica_draw_transform, |
| 5661 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5662 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5663 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5664 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 5665 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 5666 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5667 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5668 | expected_replica_screen_space_transform, |
| 5669 | child->render_surface()->replica_screen_space_transform()); |
| 5670 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5671 | expected_replica_screen_space_transform, |
| 5672 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5673 | } |
| 5674 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5675 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5676 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
| 5677 | MockContentLayerClient delegate; |
| 5678 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5679 | |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5680 | scoped_refptr<FakePictureLayer> parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5681 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5682 | SetLayerPropertiesForTesting(parent.get(), |
| 5683 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5684 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5685 | gfx::PointF(), |
| 5686 | gfx::Size(33, 31), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5687 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5688 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5689 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5690 | scoped_refptr<FakePictureLayer> child = |
| 5691 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5692 | SetLayerPropertiesForTesting(child.get(), |
| 5693 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5694 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5695 | gfx::PointF(), |
| 5696 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5697 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5698 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5699 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5700 | gfx::Transform replica_transform; |
| 5701 | replica_transform.Scale(1.0, -1.0); |
sohan.jyoti | e3bd619 | 2014-10-13 07:13:59 | [diff] [blame] | 5702 | scoped_refptr<FakePictureLayer> replica = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5703 | CreateDrawablePictureLayer(layer_settings(), &delegate); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5704 | SetLayerPropertiesForTesting(replica.get(), |
| 5705 | replica_transform, |
[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(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5709 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5710 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5711 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5712 | parent->AddChild(child); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5713 | child->SetReplicaLayer(replica.get()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5714 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5715 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5716 | host->SetRootLayer(parent); |
| 5717 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 5718 | float device_scale_factor = 1.7f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5719 | |
| 5720 | RenderSurfaceLayerList render_surface_layer_list; |
| 5721 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5722 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5723 | inputs.device_scale_factor = device_scale_factor; |
| 5724 | inputs.can_adjust_raster_scales = true; |
| 5725 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5726 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5727 | // We should have two render surfaces. The root's render surface and child's |
| 5728 | // render surface (it needs one because it has a replica layer). |
| 5729 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5730 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5731 | gfx::Transform identity_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5732 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5733 | child->render_surface()->draw_transform()); |
| 5734 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5735 | child->render_surface()->draw_transform()); |
| 5736 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5737 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5738 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5739 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5740 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5741 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5742 | expected_replica_draw_transform, |
| 5743 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5744 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5745 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5746 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5747 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5748 | expected_replica_screen_space_transform, |
| 5749 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5750 | } |
| 5751 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5752 | TEST_F(LayerTreeHostCommonTest, SubtreeSearch) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5753 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 5754 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 5755 | scoped_refptr<Layer> grand_child = Layer::Create(layer_settings()); |
| 5756 | scoped_refptr<Layer> mask_layer = Layer::Create(layer_settings()); |
| 5757 | scoped_refptr<Layer> replica_layer = Layer::Create(layer_settings()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5758 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5759 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 5760 | child->AddChild(grand_child.get()); |
| 5761 | child->SetMaskLayer(mask_layer.get()); |
| 5762 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5763 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5764 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5765 | host->SetRootLayer(root); |
| 5766 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5767 | int nonexistent_id = -1; |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5768 | EXPECT_EQ(root.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5769 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id())); |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5770 | EXPECT_EQ(child.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5771 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id())); |
| 5772 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5773 | grand_child.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5774 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id())); |
| 5775 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5776 | mask_layer.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5777 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id())); |
| 5778 | EXPECT_EQ( |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 5779 | replica_layer.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5780 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id())); |
| 5781 | EXPECT_EQ( |
| 5782 | 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5783 | } |
| 5784 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5785 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5786 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 5787 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5788 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 5789 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5790 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5791 | const gfx::Transform identity_matrix; |
| 5792 | SetLayerPropertiesForTesting(root.get(), |
| 5793 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5794 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5795 | gfx::PointF(), |
| 5796 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5797 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5798 | false); |
| 5799 | SetLayerPropertiesForTesting(child.get(), |
| 5800 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5801 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5802 | gfx::PointF(), |
| 5803 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5804 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5805 | false); |
| 5806 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5807 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5808 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5809 | gfx::PointF(), |
| 5810 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5811 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5812 | false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5813 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5814 | root->AddChild(child); |
| 5815 | child->AddChild(grand_child); |
| 5816 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5817 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 5818 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5819 | host->SetRootLayer(root); |
| 5820 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5821 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5822 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5823 | EXPECT_FALSE(child->render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5824 | } |
| 5825 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5826 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5827 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5828 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5829 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5830 | host_impl.CreatePendingTree(); |
| 5831 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5832 | |
| 5833 | const gfx::Transform identity_matrix; |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5834 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 5835 | gfx::PointF(), gfx::Size(100, 100), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5836 | false); |
| 5837 | root->SetDrawsContent(true); |
| 5838 | |
| 5839 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5840 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 5841 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5842 | false); |
| 5843 | child->SetDrawsContent(true); |
| 5844 | child->SetOpacity(0.0f); |
| 5845 | |
| 5846 | // Add opacity animation. |
| 5847 | AddOpacityTransitionToController( |
| 5848 | child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false); |
| 5849 | |
| 5850 | root->AddChild(child.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 5851 | root->SetHasRenderSurface(true); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5852 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5853 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5854 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 5855 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5856 | inputs.can_adjust_raster_scales = true; |
| 5857 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5858 | |
| 5859 | // We should have one render surface and two layers. The child |
| 5860 | // layer should be included even though it is transparent. |
| 5861 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5862 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 5863 | } |
| 5864 | |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5865 | using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5866 | class LCDTextTest |
| 5867 | : public LayerTreeHostCommonTestBase, |
| 5868 | public testing::TestWithParam<LCDTextTestParam> { |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5869 | public: |
| 5870 | LCDTextTest() |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5871 | : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_), |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5872 | root_(nullptr), |
| 5873 | child_(nullptr), |
| 5874 | grand_child_(nullptr) {} |
| 5875 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5876 | protected: |
dcheng | 93a52eb | 2014-12-23 02:14:23 | [diff] [blame] | 5877 | void SetUp() override { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5878 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5879 | layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5880 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5881 | scoped_ptr<LayerImpl> root_ptr = |
| 5882 | LayerImpl::Create(host_impl_.active_tree(), 1); |
| 5883 | scoped_ptr<LayerImpl> child_ptr = |
| 5884 | LayerImpl::Create(host_impl_.active_tree(), 2); |
| 5885 | scoped_ptr<LayerImpl> grand_child_ptr = |
| 5886 | LayerImpl::Create(host_impl_.active_tree(), 3); |
| 5887 | |
| 5888 | // Stash raw pointers to look at later. |
| 5889 | root_ = root_ptr.get(); |
| 5890 | child_ = child_ptr.get(); |
| 5891 | grand_child_ = grand_child_ptr.get(); |
| 5892 | |
| 5893 | child_->AddChild(grand_child_ptr.Pass()); |
| 5894 | root_->AddChild(child_ptr.Pass()); |
| 5895 | host_impl_.active_tree()->SetRootLayer(root_ptr.Pass()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5896 | |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 5897 | root_->SetContentsOpaque(true); |
| 5898 | child_->SetContentsOpaque(true); |
| 5899 | grand_child_->SetContentsOpaque(true); |
| 5900 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5901 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5902 | SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(), |
| 5903 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5904 | true); |
| 5905 | SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(), |
| 5906 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 5907 | std::tr1::get<2>(GetParam())); |
| 5908 | SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(), |
| 5909 | gfx::PointF(), gfx::Size(1, 1), true, false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5910 | false); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5911 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5912 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5913 | bool can_use_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5914 | bool layers_always_allowed_lcd_text_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5915 | |
| 5916 | FakeImplProxy proxy_; |
| 5917 | TestSharedBitmapManager shared_bitmap_manager_; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 5918 | TestTaskGraphRunner task_graph_runner_; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5919 | FakeLayerTreeHostImpl host_impl_; |
| 5920 | |
| 5921 | LayerImpl* root_; |
| 5922 | LayerImpl* child_; |
| 5923 | LayerImpl* grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5924 | }; |
| 5925 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5926 | TEST_P(LCDTextTest, CanUseLCDText) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5927 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 5928 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 5929 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5930 | // Case 1: Identity transform. |
| 5931 | gfx::Transform identity_matrix; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5932 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5933 | layers_always_allowed_lcd_text_); |
| 5934 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5935 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5936 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5937 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5938 | // Case 2: Integral translation. |
| 5939 | gfx::Transform integral_translation; |
| 5940 | integral_translation.Translate(1.0, 2.0); |
| 5941 | child_->SetTransform(integral_translation); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5942 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5943 | layers_always_allowed_lcd_text_); |
| 5944 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5945 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 5946 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5947 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5948 | // Case 3: Non-integral translation. |
| 5949 | gfx::Transform non_integral_translation; |
| 5950 | non_integral_translation.Translate(1.5, 2.5); |
| 5951 | child_->SetTransform(non_integral_translation); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5952 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5953 | layers_always_allowed_lcd_text_); |
| 5954 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5955 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5956 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5957 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5958 | // Case 4: Rotation. |
| 5959 | gfx::Transform rotation; |
| 5960 | rotation.Rotate(10.0); |
| 5961 | child_->SetTransform(rotation); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5962 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5963 | layers_always_allowed_lcd_text_); |
| 5964 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5965 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5966 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5967 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5968 | // Case 5: Scale. |
| 5969 | gfx::Transform scale; |
| 5970 | scale.Scale(2.0, 2.0); |
| 5971 | child_->SetTransform(scale); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5972 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5973 | layers_always_allowed_lcd_text_); |
| 5974 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5975 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5976 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5977 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5978 | // Case 6: Skew. |
| 5979 | gfx::Transform skew; |
| 5980 | skew.SkewX(10.0); |
| 5981 | child_->SetTransform(skew); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5982 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5983 | layers_always_allowed_lcd_text_); |
| 5984 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5985 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5986 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5987 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5988 | // Case 7: Translucent. |
| 5989 | child_->SetTransform(identity_matrix); |
| 5990 | child_->SetOpacity(0.5f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 5991 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 5992 | layers_always_allowed_lcd_text_); |
| 5993 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 5994 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 5995 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5996 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5997 | // Case 8: Sanity check: restore transform and opacity. |
| 5998 | child_->SetTransform(identity_matrix); |
| 5999 | child_->SetOpacity(1.f); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 6000 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 6001 | layers_always_allowed_lcd_text_); |
| 6002 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 6003 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 6004 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 6005 | |
| 6006 | // Case 9: Non-opaque content. |
| 6007 | child_->SetContentsOpaque(false); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 6008 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 6009 | layers_always_allowed_lcd_text_); |
| 6010 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 6011 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 6012 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
| 6013 | |
| 6014 | // Case 10: Sanity check: restore content opaqueness. |
| 6015 | child_->SetContentsOpaque(true); |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 6016 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
fmalita | 51b5e20 | 2014-11-18 20:11:50 | [diff] [blame] | 6017 | layers_always_allowed_lcd_text_); |
| 6018 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 6019 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 6020 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 6021 | } |
| 6022 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 6023 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 6024 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 6025 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 6026 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6027 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 6028 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 6029 | layers_always_allowed_lcd_text_); |
| 6030 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 6031 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 6032 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 6033 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 6034 | // Add opacity animation. |
| 6035 | child_->SetOpacity(0.9f); |
| 6036 | AddOpacityTransitionToController( |
| 6037 | child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 6038 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 6039 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 6040 | layers_always_allowed_lcd_text_); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 6041 | // Text LCD should be adjusted while animation is active. |
| 6042 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 6043 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 6044 | EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); |
| 6045 | } |
| 6046 | |
| 6047 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { |
| 6048 | bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; |
| 6049 | bool expect_not_lcd_text = layers_always_allowed_lcd_text_; |
| 6050 | |
| 6051 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
| 6052 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
| 6053 | layers_always_allowed_lcd_text_); |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 6054 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 6055 | EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); |
| 6056 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
fmalita | fcd926a | 2015-05-13 20:19:33 | [diff] [blame] | 6057 | |
| 6058 | // Mark contents non-opaque within the first animation frame. |
| 6059 | child_->SetContentsOpaque(false); |
| 6060 | AddOpacityTransitionToController(child_->layer_animation_controller(), 10.0, |
| 6061 | 0.9f, 0.1f, false); |
| 6062 | |
| 6063 | ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_, |
| 6064 | layers_always_allowed_lcd_text_); |
| 6065 | // LCD text should be disabled for non-opaque layers even during animations. |
| 6066 | EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); |
| 6067 | EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); |
| 6068 | EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 6069 | } |
| 6070 | |
| 6071 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 6072 | LCDTextTest, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 6073 | testing::Combine(testing::Bool(), |
| 6074 | testing::Bool(), |
| 6075 | testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 6076 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6077 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6078 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6079 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6080 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6081 | host_impl.CreatePendingTree(); |
| 6082 | const gfx::Transform identity_matrix; |
| 6083 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6084 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6085 | SetLayerPropertiesForTesting(root.get(), |
| 6086 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6087 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6088 | gfx::PointF(), |
| 6089 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6090 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6091 | false); |
| 6092 | root->SetIsDrawable(true); |
| 6093 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6094 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6095 | SetLayerPropertiesForTesting(child.get(), |
| 6096 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6097 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6098 | gfx::PointF(), |
| 6099 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6100 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6101 | false); |
| 6102 | child->SetIsDrawable(true); |
| 6103 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6104 | scoped_refptr<Layer> grand_child = Layer::Create(layer_settings()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6105 | SetLayerPropertiesForTesting(grand_child.get(), |
| 6106 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6107 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6108 | gfx::PointF(), |
| 6109 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6110 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6111 | false); |
| 6112 | grand_child->SetIsDrawable(true); |
| 6113 | grand_child->SetHideLayerAndSubtree(true); |
| 6114 | |
| 6115 | child->AddChild(grand_child); |
| 6116 | root->AddChild(child); |
| 6117 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6118 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6119 | host->SetRootLayer(root); |
| 6120 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6121 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6122 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6123 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6124 | inputs.can_adjust_raster_scales = true; |
| 6125 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6126 | |
| 6127 | // We should have one render surface and two layers. The grand child has |
| 6128 | // hidden itself. |
| 6129 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6130 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6131 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 6132 | EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6133 | } |
| 6134 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6135 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6136 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6137 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6138 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6139 | host_impl.CreatePendingTree(); |
| 6140 | const gfx::Transform identity_matrix; |
| 6141 | |
| 6142 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6143 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 6144 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6145 | false); |
| 6146 | root->SetDrawsContent(true); |
| 6147 | |
| 6148 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6149 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 6150 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6151 | false); |
| 6152 | child->SetDrawsContent(true); |
| 6153 | |
| 6154 | scoped_ptr<LayerImpl> grand_child = |
| 6155 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6156 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 6157 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6158 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6159 | grand_child->SetDrawsContent(true); |
| 6160 | grand_child->SetHideLayerAndSubtree(true); |
| 6161 | |
| 6162 | child->AddChild(grand_child.Pass()); |
| 6163 | root->AddChild(child.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6164 | root->SetHasRenderSurface(true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6165 | |
| 6166 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6167 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6168 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6169 | inputs.can_adjust_raster_scales = true; |
| 6170 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6171 | |
| 6172 | // We should have one render surface and two layers. The grand child has |
| 6173 | // hidden itself. |
| 6174 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6175 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6176 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
| 6177 | EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6178 | } |
| 6179 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6180 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6181 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6182 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6183 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6184 | host_impl.CreatePendingTree(); |
| 6185 | const gfx::Transform identity_matrix; |
| 6186 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6187 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6188 | SetLayerPropertiesForTesting(root.get(), |
| 6189 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6190 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6191 | gfx::PointF(), |
| 6192 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6193 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6194 | false); |
| 6195 | root->SetIsDrawable(true); |
| 6196 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6197 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6198 | SetLayerPropertiesForTesting(child.get(), |
| 6199 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6200 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6201 | gfx::PointF(), |
| 6202 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6203 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6204 | false); |
| 6205 | child->SetIsDrawable(true); |
| 6206 | child->SetHideLayerAndSubtree(true); |
| 6207 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6208 | scoped_refptr<Layer> grand_child = Layer::Create(layer_settings()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6209 | SetLayerPropertiesForTesting(grand_child.get(), |
| 6210 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6211 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6212 | gfx::PointF(), |
| 6213 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6214 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6215 | false); |
| 6216 | grand_child->SetIsDrawable(true); |
| 6217 | |
| 6218 | child->AddChild(grand_child); |
| 6219 | root->AddChild(child); |
| 6220 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6221 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6222 | host->SetRootLayer(root); |
| 6223 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6224 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6225 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6226 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6227 | inputs.can_adjust_raster_scales = true; |
| 6228 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6229 | |
| 6230 | // We should have one render surface and one layers. The child has |
| 6231 | // hidden itself and the grand child. |
| 6232 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6233 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6234 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6235 | } |
| 6236 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6237 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6238 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6239 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6240 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6241 | host_impl.CreatePendingTree(); |
| 6242 | const gfx::Transform identity_matrix; |
| 6243 | |
| 6244 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6245 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 6246 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 6247 | true); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6248 | root->SetDrawsContent(true); |
| 6249 | |
| 6250 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6251 | SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
| 6252 | gfx::PointF(), gfx::Size(40, 40), true, false, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6253 | false); |
| 6254 | child->SetDrawsContent(true); |
| 6255 | child->SetHideLayerAndSubtree(true); |
| 6256 | |
| 6257 | scoped_ptr<LayerImpl> grand_child = |
| 6258 | LayerImpl::Create(host_impl.pending_tree(), 3); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 6259 | SetLayerPropertiesForTesting(grand_child.get(), identity_matrix, |
| 6260 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 6261 | true, false, false); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6262 | grand_child->SetDrawsContent(true); |
| 6263 | |
| 6264 | child->AddChild(grand_child.Pass()); |
| 6265 | root->AddChild(child.Pass()); |
| 6266 | |
| 6267 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6268 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6269 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6270 | inputs.can_adjust_raster_scales = true; |
| 6271 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6272 | |
| 6273 | // We should have one render surface and one layers. The child has |
| 6274 | // hidden itself and the grand child. |
| 6275 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6276 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6277 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6278 | } |
| 6279 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6280 | void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 6281 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6282 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6283 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6284 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6285 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6286 | host_impl.CreatePendingTree(); |
| 6287 | const gfx::Transform identity_matrix; |
| 6288 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6289 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6290 | SetLayerPropertiesForTesting(root.get(), |
| 6291 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6292 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6293 | gfx::PointF(), |
| 6294 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6295 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6296 | false); |
| 6297 | root->SetIsDrawable(true); |
| 6298 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6299 | scoped_refptr<Layer> copy_grand_parent = Layer::Create(layer_settings()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6300 | SetLayerPropertiesForTesting(copy_grand_parent.get(), |
| 6301 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6302 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6303 | gfx::PointF(), |
| 6304 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6305 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6306 | false); |
| 6307 | copy_grand_parent->SetIsDrawable(true); |
| 6308 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6309 | scoped_refptr<Layer> copy_parent = Layer::Create(layer_settings()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6310 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 6311 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6312 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6313 | gfx::PointF(), |
| 6314 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6315 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6316 | false); |
| 6317 | copy_parent->SetIsDrawable(true); |
| 6318 | copy_parent->SetForceRenderSurface(true); |
| 6319 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6320 | scoped_refptr<Layer> copy_layer = Layer::Create(layer_settings()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6321 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 6322 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6323 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6324 | gfx::PointF(), |
| 6325 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6326 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6327 | false); |
| 6328 | copy_layer->SetIsDrawable(true); |
| 6329 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6330 | scoped_refptr<Layer> copy_child = Layer::Create(layer_settings()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6331 | SetLayerPropertiesForTesting(copy_child.get(), |
| 6332 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6333 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6334 | gfx::PointF(), |
| 6335 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6336 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6337 | false); |
| 6338 | copy_child->SetIsDrawable(true); |
| 6339 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6340 | scoped_refptr<Layer> copy_grand_parent_sibling_before = |
| 6341 | Layer::Create(layer_settings()); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6342 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
| 6343 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6344 | gfx::Point3F(), |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6345 | gfx::PointF(), |
| 6346 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6347 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6348 | false); |
| 6349 | copy_grand_parent_sibling_before->SetIsDrawable(true); |
| 6350 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6351 | scoped_refptr<Layer> copy_grand_parent_sibling_after = |
| 6352 | Layer::Create(layer_settings()); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6353 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
| 6354 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6355 | gfx::Point3F(), |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6356 | gfx::PointF(), |
| 6357 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6358 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6359 | false); |
| 6360 | copy_grand_parent_sibling_after->SetIsDrawable(true); |
| 6361 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6362 | copy_layer->AddChild(copy_child); |
| 6363 | copy_parent->AddChild(copy_layer); |
| 6364 | copy_grand_parent->AddChild(copy_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6365 | root->AddChild(copy_grand_parent_sibling_before); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6366 | root->AddChild(copy_grand_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6367 | root->AddChild(copy_grand_parent_sibling_after); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6368 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6369 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6370 | host->SetRootLayer(root); |
| 6371 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6372 | // Hide the copy_grand_parent and its subtree. But make a copy request in that |
| 6373 | // hidden subtree on copy_layer. |
| 6374 | copy_grand_parent->SetHideLayerAndSubtree(true); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6375 | copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true); |
| 6376 | copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6377 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 6378 | base::Bind(&EmptyCopyOutputCallback))); |
| 6379 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 6380 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6381 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6382 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6383 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6384 | inputs.can_adjust_raster_scales = true; |
| 6385 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6386 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6387 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request); |
| 6388 | EXPECT_TRUE(copy_grand_parent->draw_properties(). |
| 6389 | layer_or_descendant_has_copy_request); |
| 6390 | EXPECT_TRUE(copy_parent->draw_properties(). |
| 6391 | layer_or_descendant_has_copy_request); |
| 6392 | EXPECT_TRUE(copy_layer->draw_properties(). |
| 6393 | layer_or_descendant_has_copy_request); |
| 6394 | EXPECT_FALSE(copy_child->draw_properties(). |
| 6395 | layer_or_descendant_has_copy_request); |
| 6396 | EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties(). |
| 6397 | layer_or_descendant_has_copy_request); |
| 6398 | EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties(). |
| 6399 | layer_or_descendant_has_copy_request); |
| 6400 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6401 | // We should have three render surfaces, one for the root, one for the parent |
| 6402 | // since it owns a surface, and one for the copy_layer. |
| 6403 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6404 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 6405 | EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id()); |
| 6406 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6407 | |
| 6408 | // The root render surface should have 2 contributing layers. The |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6409 | // copy_grand_parent is hidden along with its siblings, but the copy_parent |
| 6410 | // will appear since something in its subtree needs to be drawn for a copy |
| 6411 | // request. |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6412 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6413 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 6414 | EXPECT_EQ(copy_parent->id(), |
| 6415 | root->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6416 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 6417 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6418 | // appear in its list, since it needs to be drawn for the copy request. |
| 6419 | ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size()); |
| 6420 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6421 | copy_parent->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6422 | |
| 6423 | // The copy_layer's render surface should have two contributing layers. |
| 6424 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 6425 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6426 | copy_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6427 | EXPECT_EQ(copy_child->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6428 | copy_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6429 | } |
| 6430 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6431 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6432 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6433 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6434 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6435 | host_impl.CreatePendingTree(); |
| 6436 | const gfx::Transform identity_matrix; |
| 6437 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6438 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6439 | SetLayerPropertiesForTesting(root.get(), |
| 6440 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6441 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6442 | gfx::PointF(), |
| 6443 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6444 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6445 | false); |
| 6446 | root->SetIsDrawable(true); |
| 6447 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6448 | scoped_refptr<Layer> copy_parent = Layer::Create(layer_settings()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6449 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 6450 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6451 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6452 | gfx::PointF(), |
| 6453 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6454 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6455 | false); |
| 6456 | copy_parent->SetIsDrawable(true); |
| 6457 | copy_parent->SetMasksToBounds(true); |
| 6458 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6459 | scoped_refptr<Layer> copy_layer = Layer::Create(layer_settings()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6460 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 6461 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6462 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6463 | gfx::PointF(), |
| 6464 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6465 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6466 | false); |
| 6467 | copy_layer->SetIsDrawable(true); |
| 6468 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6469 | scoped_refptr<Layer> copy_child = Layer::Create(layer_settings()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6470 | SetLayerPropertiesForTesting(copy_child.get(), |
| 6471 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6472 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6473 | gfx::PointF(), |
| 6474 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6475 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6476 | false); |
| 6477 | copy_child->SetIsDrawable(true); |
| 6478 | |
| 6479 | copy_layer->AddChild(copy_child); |
| 6480 | copy_parent->AddChild(copy_layer); |
| 6481 | root->AddChild(copy_parent); |
| 6482 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6483 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6484 | host->SetRootLayer(root); |
| 6485 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6486 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 6487 | base::Bind(&EmptyCopyOutputCallback))); |
| 6488 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 6489 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6490 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6491 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6492 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6493 | inputs.can_adjust_raster_scales = true; |
| 6494 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6495 | |
| 6496 | // We should have one render surface, as the others are clipped out. |
| 6497 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6498 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6499 | |
| 6500 | // The root render surface should only have 1 contributing layer, since the |
| 6501 | // other layers are empty/clipped away. |
| 6502 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6503 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6504 | } |
| 6505 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6506 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
| 6507 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6508 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 6509 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6510 | host_impl.CreatePendingTree(); |
| 6511 | const gfx::Transform identity_matrix; |
| 6512 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6513 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6514 | SetLayerPropertiesForTesting(root.get(), |
| 6515 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6516 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6517 | gfx::PointF(), |
| 6518 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6519 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6520 | false); |
| 6521 | root->SetIsDrawable(true); |
| 6522 | |
| 6523 | // The surface is moved slightly outside of the viewport. |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6524 | scoped_refptr<Layer> surface = Layer::Create(layer_settings()); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6525 | SetLayerPropertiesForTesting(surface.get(), |
| 6526 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6527 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6528 | gfx::PointF(-10, -20), |
| 6529 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6530 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6531 | false); |
| 6532 | surface->SetForceRenderSurface(true); |
| 6533 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6534 | scoped_refptr<Layer> surface_child = Layer::Create(layer_settings()); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6535 | SetLayerPropertiesForTesting(surface_child.get(), |
| 6536 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6537 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6538 | gfx::PointF(), |
| 6539 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6540 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6541 | false); |
| 6542 | surface_child->SetIsDrawable(true); |
| 6543 | |
| 6544 | surface->AddChild(surface_child); |
| 6545 | root->AddChild(surface); |
| 6546 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6547 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6548 | host->SetRootLayer(root); |
| 6549 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6550 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6551 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 6552 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6553 | inputs.can_adjust_raster_scales = true; |
| 6554 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6555 | |
| 6556 | // The visible_content_rect for the |surface_child| should not be clipped by |
| 6557 | // the viewport. |
| 6558 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 6559 | surface_child->visible_content_rect().ToString()); |
| 6560 | } |
| 6561 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6562 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 6563 | // Ensure that a transform between the layer and its render surface is not a |
| 6564 | // problem. Constructs the following layer tree. |
| 6565 | // |
| 6566 | // root (a render surface) |
| 6567 | // + render_surface |
| 6568 | // + clip_parent (scaled) |
| 6569 | // + intervening_clipping_layer |
| 6570 | // + clip_child |
| 6571 | // |
| 6572 | // The render surface should be resized correctly and the clip child should |
| 6573 | // inherit the right clip rect. |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6574 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 6575 | scoped_refptr<Layer> render_surface = Layer::Create(layer_settings()); |
| 6576 | scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings()); |
| 6577 | scoped_refptr<Layer> intervening = Layer::Create(layer_settings()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6578 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6579 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6580 | |
| 6581 | root->AddChild(render_surface); |
| 6582 | render_surface->AddChild(clip_parent); |
| 6583 | clip_parent->AddChild(intervening); |
| 6584 | intervening->AddChild(clip_child); |
| 6585 | |
| 6586 | clip_child->SetClipParent(clip_parent.get()); |
| 6587 | |
| 6588 | intervening->SetMasksToBounds(true); |
| 6589 | clip_parent->SetMasksToBounds(true); |
| 6590 | |
| 6591 | render_surface->SetForceRenderSurface(true); |
| 6592 | |
| 6593 | gfx::Transform scale_transform; |
| 6594 | scale_transform.Scale(2, 2); |
| 6595 | |
| 6596 | gfx::Transform identity_transform; |
| 6597 | |
| 6598 | SetLayerPropertiesForTesting(root.get(), |
| 6599 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6600 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6601 | gfx::PointF(), |
| 6602 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6603 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6604 | false); |
| 6605 | SetLayerPropertiesForTesting(render_surface.get(), |
| 6606 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6607 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6608 | gfx::PointF(), |
| 6609 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6610 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6611 | false); |
| 6612 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6613 | scale_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6614 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6615 | gfx::PointF(1.f, 1.f), |
| 6616 | gfx::Size(10, 10), |
[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(intervening.get(), |
| 6620 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6621 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6622 | gfx::PointF(1.f, 1.f), |
| 6623 | gfx::Size(5, 5), |
[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(clip_child.get(), |
| 6627 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6628 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6629 | gfx::PointF(1.f, 1.f), |
| 6630 | gfx::Size(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 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6634 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6635 | host->SetRootLayer(root); |
| 6636 | |
| 6637 | ExecuteCalculateDrawProperties(root.get()); |
| 6638 | |
| 6639 | ASSERT_TRUE(root->render_surface()); |
| 6640 | ASSERT_TRUE(render_surface->render_surface()); |
| 6641 | |
| 6642 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 6643 | // by the intervening clip layer. |
| 6644 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
| 6645 | clip_parent->clip_rect().ToString()); |
| 6646 | ASSERT_EQ(clip_parent->clip_rect().ToString(), |
| 6647 | clip_child->clip_rect().ToString()); |
| 6648 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(), |
| 6649 | intervening->clip_rect().ToString()); |
| 6650 | |
| 6651 | // Ensure that the render surface reports a content rect that has been grown |
| 6652 | // to accomodate for the clip child. |
| 6653 | ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(), |
| 6654 | render_surface->render_surface()->content_rect().ToString()); |
| 6655 | |
| 6656 | // The above check implies the two below, but they nicely demonstrate that |
| 6657 | // we've grown, despite the intervening layer's clip. |
| 6658 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 6659 | render_surface->render_surface()->content_rect())); |
| 6660 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 6661 | render_surface->render_surface()->content_rect())); |
| 6662 | } |
| 6663 | |
| 6664 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 6665 | // Ensure that intervening render surfaces are not a problem in the basic |
| 6666 | // case. In the following tree, both render surfaces should be resized to |
| 6667 | // accomodate for the clip child, despite an intervening clip. |
| 6668 | // |
| 6669 | // root (a render surface) |
| 6670 | // + clip_parent (masks to bounds) |
| 6671 | // + render_surface1 (sets opacity) |
| 6672 | // + intervening (masks to bounds) |
| 6673 | // + render_surface2 (also sets opacity) |
| 6674 | // + clip_child |
| 6675 | // |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6676 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 6677 | scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings()); |
| 6678 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
| 6679 | scoped_refptr<Layer> intervening = Layer::Create(layer_settings()); |
| 6680 | scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6681 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6682 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6683 | |
| 6684 | root->AddChild(clip_parent); |
| 6685 | clip_parent->AddChild(render_surface1); |
| 6686 | render_surface1->AddChild(intervening); |
| 6687 | intervening->AddChild(render_surface2); |
| 6688 | render_surface2->AddChild(clip_child); |
| 6689 | |
| 6690 | clip_child->SetClipParent(clip_parent.get()); |
| 6691 | |
| 6692 | intervening->SetMasksToBounds(true); |
| 6693 | clip_parent->SetMasksToBounds(true); |
| 6694 | |
| 6695 | render_surface1->SetForceRenderSurface(true); |
| 6696 | render_surface2->SetForceRenderSurface(true); |
| 6697 | |
| 6698 | gfx::Transform translation_transform; |
| 6699 | translation_transform.Translate(2, 2); |
| 6700 | |
| 6701 | gfx::Transform identity_transform; |
| 6702 | SetLayerPropertiesForTesting(root.get(), |
| 6703 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6704 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6705 | gfx::PointF(), |
| 6706 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6707 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6708 | false); |
| 6709 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6710 | translation_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6711 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6712 | gfx::PointF(1.f, 1.f), |
| 6713 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6714 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6715 | false); |
| 6716 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6717 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6718 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6719 | gfx::PointF(), |
| 6720 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6721 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6722 | false); |
| 6723 | SetLayerPropertiesForTesting(intervening.get(), |
| 6724 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6725 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6726 | gfx::PointF(1.f, 1.f), |
| 6727 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6728 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6729 | false); |
| 6730 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6731 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6732 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6733 | gfx::PointF(), |
| 6734 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6735 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6736 | false); |
| 6737 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6738 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6739 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6740 | gfx::PointF(-10.f, -10.f), |
| 6741 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6742 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6743 | false); |
| 6744 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6745 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6746 | host->SetRootLayer(root); |
| 6747 | |
| 6748 | ExecuteCalculateDrawProperties(root.get()); |
| 6749 | |
| 6750 | EXPECT_TRUE(root->render_surface()); |
| 6751 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6752 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6753 | |
| 6754 | // Since the render surfaces could have expanded, they should not clip (their |
| 6755 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6756 | // in this case. |
| 6757 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6758 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6759 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6760 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6761 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6762 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6763 | |
| 6764 | // NB: clip rects are in target space. |
| 6765 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6766 | render_surface1->clip_rect().ToString()); |
| 6767 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6768 | |
| 6769 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6770 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6771 | render_surface2->clip_rect().ToString()); |
| 6772 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6773 | |
| 6774 | // The content rects of both render surfaces should both have expanded to |
| 6775 | // contain the clip child. |
| 6776 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6777 | render_surface1->render_surface()->content_rect().ToString()); |
| 6778 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6779 | render_surface2->render_surface()->content_rect().ToString()); |
| 6780 | |
| 6781 | // The clip child should have inherited the clip parent's clip (projected to |
| 6782 | // the right space, of course), and should have the correctly sized visible |
| 6783 | // content rect. |
| 6784 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6785 | clip_child->clip_rect().ToString()); |
| 6786 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(), |
| 6787 | clip_child->visible_content_rect().ToString()); |
| 6788 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6789 | } |
| 6790 | |
| 6791 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 6792 | // Ensure that intervening render surfaces are not a problem, even if there |
| 6793 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 6794 | // of transform. |
| 6795 | // |
| 6796 | // root (a render surface) |
| 6797 | // + clip_parent (masks to bounds) |
| 6798 | // + render_surface1 (sets opacity) |
| 6799 | // + intervening (masks to bounds AND scrolls) |
| 6800 | // + render_surface2 (also sets opacity) |
| 6801 | // + clip_child |
| 6802 | // |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6803 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 6804 | scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings()); |
| 6805 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
| 6806 | scoped_refptr<Layer> intervening = Layer::Create(layer_settings()); |
| 6807 | scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6808 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6809 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6810 | |
| 6811 | root->AddChild(clip_parent); |
| 6812 | clip_parent->AddChild(render_surface1); |
| 6813 | render_surface1->AddChild(intervening); |
| 6814 | intervening->AddChild(render_surface2); |
| 6815 | render_surface2->AddChild(clip_child); |
| 6816 | |
| 6817 | clip_child->SetClipParent(clip_parent.get()); |
| 6818 | |
| 6819 | intervening->SetMasksToBounds(true); |
| 6820 | clip_parent->SetMasksToBounds(true); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6821 | intervening->SetScrollClipLayerId(clip_parent->id()); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 6822 | intervening->SetScrollOffset(gfx::ScrollOffset(3, 3)); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6823 | |
| 6824 | render_surface1->SetForceRenderSurface(true); |
| 6825 | render_surface2->SetForceRenderSurface(true); |
| 6826 | |
| 6827 | gfx::Transform translation_transform; |
| 6828 | translation_transform.Translate(2, 2); |
| 6829 | |
| 6830 | gfx::Transform identity_transform; |
| 6831 | SetLayerPropertiesForTesting(root.get(), |
| 6832 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6833 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6834 | gfx::PointF(), |
| 6835 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6836 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6837 | false); |
| 6838 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6839 | translation_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6840 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6841 | gfx::PointF(1.f, 1.f), |
| 6842 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6843 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6844 | false); |
| 6845 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6846 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6847 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6848 | gfx::PointF(), |
| 6849 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6850 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6851 | false); |
| 6852 | SetLayerPropertiesForTesting(intervening.get(), |
| 6853 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6854 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6855 | gfx::PointF(1.f, 1.f), |
| 6856 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6857 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6858 | false); |
| 6859 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6860 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6861 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6862 | gfx::PointF(), |
| 6863 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6864 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6865 | false); |
| 6866 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6867 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6868 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6869 | gfx::PointF(-10.f, -10.f), |
| 6870 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6871 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6872 | false); |
| 6873 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6874 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6875 | host->SetRootLayer(root); |
| 6876 | |
| 6877 | ExecuteCalculateDrawProperties(root.get()); |
| 6878 | |
| 6879 | EXPECT_TRUE(root->render_surface()); |
| 6880 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6881 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6882 | |
| 6883 | // Since the render surfaces could have expanded, they should not clip (their |
| 6884 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6885 | // in this case. |
| 6886 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6887 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6888 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6889 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6890 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6891 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6892 | |
| 6893 | // NB: clip rects are in target space. |
| 6894 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6895 | render_surface1->clip_rect().ToString()); |
| 6896 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6897 | |
| 6898 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6899 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(), |
| 6900 | render_surface2->clip_rect().ToString()); |
| 6901 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6902 | |
| 6903 | // The content rects of both render surfaces should both have expanded to |
| 6904 | // contain the clip child. |
| 6905 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6906 | render_surface1->render_surface()->content_rect().ToString()); |
| 6907 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6908 | render_surface2->render_surface()->content_rect().ToString()); |
| 6909 | |
| 6910 | // The clip child should have inherited the clip parent's clip (projected to |
| 6911 | // the right space, of course), and should have the correctly sized visible |
| 6912 | // content rect. |
| 6913 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6914 | clip_child->clip_rect().ToString()); |
| 6915 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), |
| 6916 | clip_child->visible_content_rect().ToString()); |
| 6917 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6918 | } |
| 6919 | |
| 6920 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 6921 | // Ensures that descendants of the clip child inherit the correct clip. |
| 6922 | // |
| 6923 | // root (a render surface) |
| 6924 | // + clip_parent (masks to bounds) |
| 6925 | // + intervening (masks to bounds) |
| 6926 | // + clip_child |
| 6927 | // + child |
| 6928 | // |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6929 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 6930 | scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings()); |
| 6931 | scoped_refptr<Layer> intervening = Layer::Create(layer_settings()); |
| 6932 | scoped_refptr<Layer> clip_child = Layer::Create(layer_settings()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6933 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 6934 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6935 | |
| 6936 | root->AddChild(clip_parent); |
| 6937 | clip_parent->AddChild(intervening); |
| 6938 | intervening->AddChild(clip_child); |
| 6939 | clip_child->AddChild(child); |
| 6940 | |
| 6941 | clip_child->SetClipParent(clip_parent.get()); |
| 6942 | |
| 6943 | intervening->SetMasksToBounds(true); |
| 6944 | clip_parent->SetMasksToBounds(true); |
| 6945 | |
| 6946 | gfx::Transform identity_transform; |
| 6947 | SetLayerPropertiesForTesting(root.get(), |
| 6948 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6949 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6950 | gfx::PointF(), |
| 6951 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6952 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6953 | false); |
| 6954 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6955 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6956 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6957 | gfx::PointF(), |
| 6958 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6959 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6960 | false); |
| 6961 | SetLayerPropertiesForTesting(intervening.get(), |
| 6962 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6963 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6964 | gfx::PointF(), |
| 6965 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6966 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6967 | false); |
| 6968 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6969 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6970 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6971 | gfx::PointF(), |
| 6972 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6973 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6974 | false); |
| 6975 | SetLayerPropertiesForTesting(child.get(), |
| 6976 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6977 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6978 | gfx::PointF(), |
| 6979 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6980 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6981 | false); |
| 6982 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 6983 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6984 | host->SetRootLayer(root); |
| 6985 | |
| 6986 | ExecuteCalculateDrawProperties(root.get()); |
| 6987 | |
| 6988 | EXPECT_TRUE(root->render_surface()); |
| 6989 | |
| 6990 | // Neither the clip child nor its descendant should have inherited the clip |
| 6991 | // from |intervening|. |
| 6992 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6993 | clip_child->clip_rect().ToString()); |
| 6994 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6995 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6996 | child->visible_content_rect().ToString()); |
| 6997 | EXPECT_TRUE(child->is_clipped()); |
| 6998 | } |
| 6999 | |
| 7000 | TEST_F(LayerTreeHostCommonTest, |
| 7001 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 7002 | // Ensures that non-descendant clip children in the tree do not affect |
| 7003 | // render surfaces. |
| 7004 | // |
| 7005 | // root (a render surface) |
| 7006 | // + clip_parent (masks to bounds) |
| 7007 | // + render_surface1 |
| 7008 | // + clip_child |
| 7009 | // + render_surface2 |
| 7010 | // + non_clip_child |
| 7011 | // |
| 7012 | // In this example render_surface2 should be unaffected by clip_child. |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7013 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 7014 | scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings()); |
| 7015 | scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7016 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7017 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
| 7018 | scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7019 | scoped_refptr<LayerWithForcedDrawsContent> non_clip_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7020 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7021 | |
| 7022 | root->AddChild(clip_parent); |
| 7023 | clip_parent->AddChild(render_surface1); |
| 7024 | render_surface1->AddChild(clip_child); |
| 7025 | clip_parent->AddChild(render_surface2); |
| 7026 | render_surface2->AddChild(non_clip_child); |
| 7027 | |
| 7028 | clip_child->SetClipParent(clip_parent.get()); |
| 7029 | |
| 7030 | clip_parent->SetMasksToBounds(true); |
| 7031 | render_surface1->SetMasksToBounds(true); |
| 7032 | |
| 7033 | gfx::Transform identity_transform; |
| 7034 | SetLayerPropertiesForTesting(root.get(), |
| 7035 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7036 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7037 | gfx::PointF(), |
| 7038 | gfx::Size(15, 15), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7039 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7040 | false); |
| 7041 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 7042 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7043 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7044 | gfx::PointF(), |
| 7045 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7046 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7047 | false); |
| 7048 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 7049 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7050 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7051 | gfx::PointF(5, 5), |
| 7052 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7053 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7054 | false); |
| 7055 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 7056 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7057 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7058 | gfx::PointF(), |
| 7059 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7060 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7061 | false); |
| 7062 | SetLayerPropertiesForTesting(clip_child.get(), |
| 7063 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7064 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7065 | gfx::PointF(-1, 1), |
| 7066 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7067 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7068 | false); |
| 7069 | SetLayerPropertiesForTesting(non_clip_child.get(), |
| 7070 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7071 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7072 | gfx::PointF(), |
| 7073 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7074 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7075 | false); |
| 7076 | |
| 7077 | render_surface1->SetForceRenderSurface(true); |
| 7078 | render_surface2->SetForceRenderSurface(true); |
| 7079 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7080 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 7081 | host->SetRootLayer(root); |
| 7082 | |
| 7083 | ExecuteCalculateDrawProperties(root.get()); |
| 7084 | |
| 7085 | EXPECT_TRUE(root->render_surface()); |
| 7086 | EXPECT_TRUE(render_surface1->render_surface()); |
| 7087 | EXPECT_TRUE(render_surface2->render_surface()); |
| 7088 | |
| 7089 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 7090 | render_surface1->clip_rect().ToString()); |
| 7091 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 7092 | |
| 7093 | // The render surface should not clip (it has unclipped descendants), instead |
| 7094 | // it should rely on layer clipping. |
| 7095 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 7096 | render_surface1->render_surface()->clip_rect().ToString()); |
| 7097 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 7098 | |
| 7099 | // That said, it should have grown to accomodate the unclipped descendant. |
| 7100 | EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(), |
| 7101 | render_surface1->render_surface()->content_rect().ToString()); |
| 7102 | |
| 7103 | // This render surface should clip. It has no unclipped descendants. |
| 7104 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 7105 | render_surface2->clip_rect().ToString()); |
| 7106 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
| 7107 | |
| 7108 | // It also shouldn't have grown to accomodate the clip child. |
| 7109 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 7110 | render_surface2->render_surface()->content_rect().ToString()); |
| 7111 | |
| 7112 | // Sanity check our num_unclipped_descendants values. |
| 7113 | EXPECT_EQ(1, render_surface1->num_unclipped_descendants()); |
| 7114 | EXPECT_EQ(0, render_surface2->num_unclipped_descendants()); |
| 7115 | } |
| 7116 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7117 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
| 7118 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7119 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 7120 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7121 | scoped_ptr<LayerImpl> root = |
| 7122 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 7123 | scoped_ptr<LayerImpl> child1 = |
| 7124 | LayerImpl::Create(host_impl.active_tree(), 123456); |
| 7125 | scoped_ptr<LayerImpl> child2 = |
| 7126 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
| 7127 | scoped_ptr<LayerImpl> child3 = |
| 7128 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 7129 | |
| 7130 | gfx::Transform identity_matrix; |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7131 | gfx::Point3F transform_origin; |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7132 | gfx::PointF position; |
| 7133 | gfx::Size bounds(100, 100); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7134 | SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, |
| 7135 | position, bounds, true, false, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7136 | root->SetDrawsContent(true); |
| 7137 | |
| 7138 | // This layer structure normally forces render surface due to preserves3d |
| 7139 | // behavior. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7140 | SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin, |
| 7141 | position, bounds, false, true, true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7142 | child1->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7143 | SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin, |
| 7144 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7145 | child2->SetDrawsContent(true); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7146 | SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin, |
| 7147 | position, bounds, true, false, false); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7148 | child3->SetDrawsContent(true); |
| 7149 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 7150 | child2->Set3dSortingContextId(1); |
| 7151 | child3->Set3dSortingContextId(1); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7152 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7153 | child2->AddChild(child3.Pass()); |
| 7154 | child1->AddChild(child2.Pass()); |
| 7155 | root->AddChild(child1.Pass()); |
| 7156 | |
| 7157 | { |
| 7158 | LayerImplList render_surface_layer_list; |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 7159 | FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get()); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7160 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7161 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7162 | inputs.can_render_to_separate_surface = true; |
| 7163 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7164 | |
| 7165 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 7166 | |
| 7167 | int count_represents_target_render_surface = 0; |
| 7168 | int count_represents_contributing_render_surface = 0; |
| 7169 | int count_represents_itself = 0; |
| 7170 | auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list); |
| 7171 | for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list); |
| 7172 | it != end; ++it) { |
| 7173 | if (it.represents_target_render_surface()) |
| 7174 | count_represents_target_render_surface++; |
| 7175 | if (it.represents_contributing_render_surface()) |
| 7176 | count_represents_contributing_render_surface++; |
| 7177 | if (it.represents_itself()) |
| 7178 | count_represents_itself++; |
| 7179 | } |
| 7180 | |
| 7181 | // Two render surfaces. |
| 7182 | EXPECT_EQ(2, count_represents_target_render_surface); |
| 7183 | // Second render surface contributes to root render surface. |
| 7184 | EXPECT_EQ(1, count_represents_contributing_render_surface); |
| 7185 | // All 4 layers represent itself. |
| 7186 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7187 | } |
| 7188 | |
| 7189 | { |
| 7190 | LayerImplList render_surface_layer_list; |
| 7191 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7192 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7193 | inputs.can_render_to_separate_surface = false; |
| 7194 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7195 | |
| 7196 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
boliu | 13185ca | 2015-03-16 23:20:02 | [diff] [blame] | 7197 | |
| 7198 | int count_represents_target_render_surface = 0; |
| 7199 | int count_represents_contributing_render_surface = 0; |
| 7200 | int count_represents_itself = 0; |
| 7201 | auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list); |
| 7202 | for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list); |
| 7203 | it != end; ++it) { |
| 7204 | if (it.represents_target_render_surface()) |
| 7205 | count_represents_target_render_surface++; |
| 7206 | if (it.represents_contributing_render_surface()) |
| 7207 | count_represents_contributing_render_surface++; |
| 7208 | if (it.represents_itself()) |
| 7209 | count_represents_itself++; |
| 7210 | } |
| 7211 | |
| 7212 | // Only root layer has a render surface. |
| 7213 | EXPECT_EQ(1, count_represents_target_render_surface); |
| 7214 | // No layer contributes a render surface to root render surface. |
| 7215 | EXPECT_EQ(0, count_represents_contributing_render_surface); |
| 7216 | // All 4 layers represent itself. |
| 7217 | EXPECT_EQ(4, count_represents_itself); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 7218 | } |
| 7219 | } |
| 7220 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7221 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7222 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 7223 | scoped_refptr<Layer> render_surface = Layer::Create(layer_settings()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7224 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7225 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7226 | |
| 7227 | root->AddChild(render_surface); |
| 7228 | render_surface->AddChild(child); |
| 7229 | |
| 7230 | gfx::Transform identity_transform; |
| 7231 | SetLayerPropertiesForTesting(root.get(), |
| 7232 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7233 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7234 | gfx::PointF(), |
| 7235 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7236 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7237 | false); |
| 7238 | SetLayerPropertiesForTesting(render_surface.get(), |
| 7239 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7240 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7241 | gfx::PointF(), |
| 7242 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7243 | false, |
| 7244 | true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7245 | SetLayerPropertiesForTesting(child.get(), |
| 7246 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7247 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7248 | gfx::PointF(), |
| 7249 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7250 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7251 | false); |
| 7252 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7253 | root->SetShouldFlattenTransform(false); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 7254 | root->Set3dSortingContextId(1); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7255 | render_surface->SetDoubleSided(false); |
| 7256 | render_surface->SetForceRenderSurface(true); |
| 7257 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7258 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7259 | host->SetRootLayer(root); |
| 7260 | |
| 7261 | ExecuteCalculateDrawProperties(root.get()); |
| 7262 | |
| 7263 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 7264 | EXPECT_EQ(1u, |
| 7265 | render_surface_layer_list()->at(0) |
| 7266 | ->render_surface()->layer_list().size()); |
| 7267 | EXPECT_EQ(1u, |
| 7268 | render_surface_layer_list()->at(1) |
| 7269 | ->render_surface()->layer_list().size()); |
| 7270 | |
| 7271 | gfx::Transform rotation_transform = identity_transform; |
| 7272 | rotation_transform.RotateAboutXAxis(180.0); |
| 7273 | |
| 7274 | render_surface->SetTransform(rotation_transform); |
| 7275 | |
| 7276 | ExecuteCalculateDrawProperties(root.get()); |
| 7277 | |
| 7278 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 7279 | EXPECT_EQ(0u, |
| 7280 | render_surface_layer_list()->at(0) |
| 7281 | ->render_surface()->layer_list().size()); |
| 7282 | } |
| 7283 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7284 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 7285 | // Checks that the simple case (being clipped by a scroll parent that would |
| 7286 | // have been processed before you anyhow) results in the right clips. |
| 7287 | // |
| 7288 | // + root |
| 7289 | // + scroll_parent_border |
| 7290 | // | + scroll_parent_clip |
| 7291 | // | + scroll_parent |
| 7292 | // + scroll_child |
| 7293 | // |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7294 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 7295 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(layer_settings()); |
| 7296 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(layer_settings()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7297 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7298 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7299 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7300 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7301 | |
| 7302 | root->AddChild(scroll_child); |
| 7303 | |
| 7304 | root->AddChild(scroll_parent_border); |
| 7305 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7306 | scroll_parent_clip->AddChild(scroll_parent); |
| 7307 | |
| 7308 | scroll_parent_clip->SetMasksToBounds(true); |
| 7309 | |
| 7310 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7311 | |
| 7312 | gfx::Transform identity_transform; |
| 7313 | SetLayerPropertiesForTesting(root.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(50, 50), |
[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_border.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(40, 40), |
[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_clip.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(30, 30), |
[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_parent.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 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7342 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7343 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7344 | gfx::PointF(), |
| 7345 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7346 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7347 | false); |
| 7348 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7349 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7350 | host->SetRootLayer(root); |
| 7351 | |
| 7352 | ExecuteCalculateDrawProperties(root.get()); |
| 7353 | |
| 7354 | EXPECT_TRUE(root->render_surface()); |
| 7355 | |
| 7356 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 7357 | scroll_child->clip_rect().ToString()); |
| 7358 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7359 | } |
| 7360 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7361 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
| 7362 | scoped_refptr<LayerWithForcedDrawsContent> root = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7363 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7364 | scoped_refptr<LayerWithForcedDrawsContent> parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7365 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7366 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7367 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7368 | |
| 7369 | root->AddChild(parent); |
| 7370 | parent->AddChild(child); |
| 7371 | |
| 7372 | gfx::Transform identity_transform; |
| 7373 | SetLayerPropertiesForTesting(root.get(), |
| 7374 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7375 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7376 | gfx::PointF(), |
| 7377 | gfx::Size(50, 50), |
| 7378 | true, |
| 7379 | true); |
| 7380 | root->SetForceRenderSurface(true); |
| 7381 | SetLayerPropertiesForTesting(parent.get(), |
| 7382 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7383 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7384 | gfx::PointF(), |
| 7385 | gfx::Size(30, 30), |
| 7386 | true, |
| 7387 | true); |
| 7388 | parent->SetForceRenderSurface(true); |
| 7389 | SetLayerPropertiesForTesting(child.get(), |
| 7390 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7391 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7392 | gfx::PointF(), |
| 7393 | gfx::Size(20, 20), |
| 7394 | true, |
| 7395 | true); |
| 7396 | child->SetForceRenderSurface(true); |
| 7397 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7398 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7399 | host->SetRootLayer(root); |
| 7400 | |
| 7401 | ExecuteCalculateDrawProperties(root.get()); |
| 7402 | |
| 7403 | EXPECT_EQ(3u, render_surface_layer_list()->size()); |
| 7404 | |
| 7405 | gfx::Transform singular_transform; |
| 7406 | singular_transform.Scale3d( |
| 7407 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 7408 | |
| 7409 | child->SetTransform(singular_transform); |
| 7410 | |
| 7411 | ExecuteCalculateDrawProperties(root.get()); |
| 7412 | |
| 7413 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 7414 | |
| 7415 | // Ensure that the entire subtree under a layer with singular transform does |
| 7416 | // not get rendered. |
| 7417 | parent->SetTransform(singular_transform); |
| 7418 | child->SetTransform(identity_transform); |
| 7419 | |
| 7420 | ExecuteCalculateDrawProperties(root.get()); |
| 7421 | |
| 7422 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 7423 | } |
| 7424 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7425 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 7426 | // Checks that clipping by a scroll parent that follows you in paint order |
| 7427 | // still results in correct clipping. |
| 7428 | // |
| 7429 | // + root |
| 7430 | // + scroll_child |
| 7431 | // + scroll_parent_border |
| 7432 | // + scroll_parent_clip |
| 7433 | // + scroll_parent |
| 7434 | // |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7435 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 7436 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(layer_settings()); |
| 7437 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(layer_settings()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7438 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7439 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7440 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7441 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7442 | |
| 7443 | root->AddChild(scroll_parent_border); |
| 7444 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7445 | scroll_parent_clip->AddChild(scroll_parent); |
| 7446 | |
| 7447 | root->AddChild(scroll_child); |
| 7448 | |
| 7449 | scroll_parent_clip->SetMasksToBounds(true); |
| 7450 | |
| 7451 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7452 | |
| 7453 | gfx::Transform identity_transform; |
| 7454 | SetLayerPropertiesForTesting(root.get(), |
| 7455 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7456 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7457 | gfx::PointF(), |
| 7458 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7459 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7460 | false); |
| 7461 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7462 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7463 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7464 | gfx::PointF(), |
| 7465 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7466 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7467 | false); |
| 7468 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7469 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7470 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7471 | gfx::PointF(), |
| 7472 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7473 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7474 | false); |
| 7475 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7476 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7477 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7478 | gfx::PointF(), |
| 7479 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7480 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7481 | false); |
| 7482 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7483 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7484 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7485 | gfx::PointF(), |
| 7486 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7487 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7488 | false); |
| 7489 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7490 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7491 | host->SetRootLayer(root); |
| 7492 | |
| 7493 | ExecuteCalculateDrawProperties(root.get()); |
| 7494 | |
| 7495 | EXPECT_TRUE(root->render_surface()); |
| 7496 | |
| 7497 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 7498 | scroll_child->clip_rect().ToString()); |
| 7499 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7500 | } |
| 7501 | |
| 7502 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 7503 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 7504 | // you in paint order still results in correct clipping. |
| 7505 | // |
| 7506 | // + root |
| 7507 | // + scroll_child |
| 7508 | // + scroll_parent_border |
| 7509 | // | + scroll_parent_clip |
| 7510 | // | + scroll_parent |
| 7511 | // + scroll_grandparent_border |
| 7512 | // + scroll_grandparent_clip |
| 7513 | // + scroll_grandparent |
| 7514 | // |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7515 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 7516 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(layer_settings()); |
| 7517 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(layer_settings()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7518 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7519 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7520 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7521 | scoped_refptr<Layer> scroll_grandparent_border = |
| 7522 | Layer::Create(layer_settings()); |
| 7523 | scoped_refptr<Layer> scroll_grandparent_clip = |
| 7524 | Layer::Create(layer_settings()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7525 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7526 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7527 | |
| 7528 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7529 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7530 | |
| 7531 | root->AddChild(scroll_child); |
| 7532 | |
| 7533 | root->AddChild(scroll_parent_border); |
| 7534 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7535 | scroll_parent_clip->AddChild(scroll_parent); |
| 7536 | |
| 7537 | root->AddChild(scroll_grandparent_border); |
| 7538 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 7539 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 7540 | |
| 7541 | scroll_parent_clip->SetMasksToBounds(true); |
| 7542 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 7543 | |
| 7544 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7545 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 7546 | |
| 7547 | gfx::Transform identity_transform; |
| 7548 | SetLayerPropertiesForTesting(root.get(), |
| 7549 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7550 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7551 | gfx::PointF(), |
| 7552 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7553 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7554 | false); |
| 7555 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 7556 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7557 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7558 | gfx::PointF(), |
| 7559 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7560 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7561 | false); |
| 7562 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 7563 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7564 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7565 | gfx::PointF(), |
| 7566 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7567 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7568 | false); |
| 7569 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 7570 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7571 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7572 | gfx::PointF(), |
| 7573 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7574 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7575 | false); |
| 7576 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7577 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7578 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7579 | gfx::PointF(), |
| 7580 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7581 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7582 | false); |
| 7583 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7584 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7585 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7586 | gfx::PointF(), |
| 7587 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7588 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7589 | false); |
| 7590 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7591 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7592 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7593 | gfx::PointF(), |
| 7594 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7595 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7596 | false); |
| 7597 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7598 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7599 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7600 | gfx::PointF(), |
| 7601 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7602 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7603 | false); |
| 7604 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7605 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7606 | host->SetRootLayer(root); |
| 7607 | |
| 7608 | ExecuteCalculateDrawProperties(root.get()); |
| 7609 | |
| 7610 | EXPECT_TRUE(root->render_surface()); |
| 7611 | |
| 7612 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 7613 | scroll_child->clip_rect().ToString()); |
| 7614 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7615 | |
| 7616 | // Despite the fact that we visited the above layers out of order to get the |
| 7617 | // correct clip, the layer lists should be unaffected. |
| 7618 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 7619 | EXPECT_EQ(scroll_child.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7620 | root->render_surface()->layer_list().at(0).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7621 | EXPECT_EQ(scroll_parent.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7622 | root->render_surface()->layer_list().at(1).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7623 | EXPECT_EQ(scroll_grandparent.get(), |
Daniel Cheng | eea9804 | 2014-08-26 00:28:10 | [diff] [blame] | 7624 | root->render_surface()->layer_list().at(2).get()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7625 | } |
| 7626 | |
| 7627 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 7628 | // 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] | 7629 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7630 | // + root |
| 7631 | // + scroll_child |
| 7632 | // + scroll_parent_border |
| 7633 | // + scroll_parent_clip |
| 7634 | // + scroll_parent |
| 7635 | // + render_surface1 |
| 7636 | // + scroll_grandparent_border |
| 7637 | // + scroll_grandparent_clip |
| 7638 | // + scroll_grandparent |
| 7639 | // + render_surface2 |
| 7640 | // |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 7641 | scoped_refptr<LayerWithForcedDrawsContent> root = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7642 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7643 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7644 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(layer_settings()); |
| 7645 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(layer_settings()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7646 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7647 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7648 | scoped_refptr<LayerWithForcedDrawsContent> render_surface1 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7649 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7650 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7651 | scoped_refptr<Layer> scroll_grandparent_border = |
| 7652 | Layer::Create(layer_settings()); |
| 7653 | scoped_refptr<Layer> scroll_grandparent_clip = |
| 7654 | Layer::Create(layer_settings()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7655 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7656 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7657 | scoped_refptr<LayerWithForcedDrawsContent> render_surface2 = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7658 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7659 | |
| 7660 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7661 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7662 | |
| 7663 | root->AddChild(scroll_child); |
| 7664 | |
| 7665 | root->AddChild(scroll_parent_border); |
| 7666 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7667 | scroll_parent_clip->AddChild(scroll_parent); |
| 7668 | scroll_parent->AddChild(render_surface2); |
| 7669 | |
| 7670 | root->AddChild(scroll_grandparent_border); |
| 7671 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 7672 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 7673 | scroll_grandparent->AddChild(render_surface1); |
| 7674 | |
| 7675 | scroll_parent_clip->SetMasksToBounds(true); |
| 7676 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 7677 | |
| 7678 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7679 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 7680 | |
| 7681 | render_surface1->SetForceRenderSurface(true); |
| 7682 | render_surface2->SetForceRenderSurface(true); |
| 7683 | |
| 7684 | gfx::Transform identity_transform; |
| 7685 | SetLayerPropertiesForTesting(root.get(), |
| 7686 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7687 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7688 | gfx::PointF(), |
| 7689 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7690 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7691 | false); |
| 7692 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 7693 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7694 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7695 | gfx::PointF(), |
| 7696 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7697 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7698 | false); |
| 7699 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 7700 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7701 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7702 | gfx::PointF(), |
| 7703 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7704 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7705 | false); |
| 7706 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 7707 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7708 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7709 | gfx::PointF(), |
| 7710 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7711 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7712 | false); |
| 7713 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 7714 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7715 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7716 | gfx::PointF(), |
| 7717 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7718 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7719 | false); |
| 7720 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7721 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7722 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7723 | gfx::PointF(), |
| 7724 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7725 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7726 | false); |
| 7727 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7728 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7729 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7730 | gfx::PointF(), |
| 7731 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7732 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7733 | false); |
| 7734 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7735 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7736 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7737 | gfx::PointF(), |
| 7738 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7739 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7740 | false); |
| 7741 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 7742 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7743 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7744 | gfx::PointF(), |
| 7745 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7746 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7747 | false); |
| 7748 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7749 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7750 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7751 | gfx::PointF(), |
| 7752 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7753 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7754 | false); |
| 7755 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 7756 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7757 | host->SetRootLayer(root); |
| 7758 | |
| 7759 | RenderSurfaceLayerList render_surface_layer_list; |
| 7760 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7761 | root.get(), |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7762 | root->bounds(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7763 | identity_transform, |
| 7764 | &render_surface_layer_list); |
| 7765 | |
| 7766 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7767 | |
| 7768 | EXPECT_TRUE(root->render_surface()); |
| 7769 | |
| 7770 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 7771 | scroll_child->clip_rect().ToString()); |
| 7772 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7773 | |
| 7774 | // Despite the fact that we had to process the layers out of order to get the |
| 7775 | // right clip, our render_surface_layer_list's order should be unaffected. |
| 7776 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
| 7777 | EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); |
| 7778 | EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); |
| 7779 | EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 7780 | EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); |
| 7781 | EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); |
| 7782 | EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7783 | } |
| 7784 | |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7785 | TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) { |
| 7786 | // Ensures that when we have a render surface between a fixed position layer |
| 7787 | // and its container, we compute the fixed position layer's draw transform |
| 7788 | // with respect to that intervening render surface, not with respect to its |
| 7789 | // container's render target. |
| 7790 | // |
| 7791 | // + root |
| 7792 | // + render_surface |
| 7793 | // + fixed |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7794 | // + child |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7795 | // |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7796 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7797 | scoped_refptr<LayerWithForcedDrawsContent> render_surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7798 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7799 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7800 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7801 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 7802 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7803 | |
| 7804 | root->AddChild(render_surface); |
| 7805 | render_surface->AddChild(fixed); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7806 | fixed->AddChild(child); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7807 | |
| 7808 | root->SetIsContainerForFixedPositionLayers(true); |
| 7809 | render_surface->SetForceRenderSurface(true); |
| 7810 | |
| 7811 | LayerPositionConstraint constraint; |
| 7812 | constraint.set_is_fixed_position(true); |
| 7813 | fixed->SetPositionConstraint(constraint); |
| 7814 | |
| 7815 | SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(), |
| 7816 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 7817 | SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(), |
| 7818 | gfx::Point3F(), gfx::PointF(7.f, 9.f), |
| 7819 | gfx::Size(50, 50), true, false); |
| 7820 | SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(), |
| 7821 | gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true, |
| 7822 | false); |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7823 | SetLayerPropertiesForTesting(child.get(), gfx::Transform(), gfx::Point3F(), |
| 7824 | gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true, |
| 7825 | false); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7826 | |
| 7827 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 7828 | host->SetRootLayer(root); |
| 7829 | |
| 7830 | ExecuteCalculateDrawProperties(root.get()); |
| 7831 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7832 | gfx::Transform expected_fixed_draw_transform; |
| 7833 | expected_fixed_draw_transform.Translate(10.f, 15.f); |
| 7834 | EXPECT_EQ(expected_fixed_draw_transform, fixed->draw_transform()); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7835 | |
ajuma | 737b270 | 2015-05-06 01:18:37 | [diff] [blame] | 7836 | gfx::Transform expected_fixed_screen_space_transform; |
| 7837 | expected_fixed_screen_space_transform.Translate(17.f, 24.f); |
| 7838 | EXPECT_EQ(expected_fixed_screen_space_transform, |
| 7839 | fixed->screen_space_transform()); |
| 7840 | |
| 7841 | gfx::Transform expected_child_draw_transform; |
| 7842 | expected_child_draw_transform.Translate(11.f, 17.f); |
| 7843 | EXPECT_EQ(expected_child_draw_transform, child->draw_transform()); |
| 7844 | |
| 7845 | gfx::Transform expected_child_screen_space_transform; |
| 7846 | expected_child_screen_space_transform.Translate(18.f, 26.f); |
| 7847 | EXPECT_EQ(expected_child_screen_space_transform, |
| 7848 | child->screen_space_transform()); |
ajuma | 0b10f94 | 2015-03-21 07:45:53 | [diff] [blame] | 7849 | } |
| 7850 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7851 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 7852 | // This test verifies that a scrolling layer that gets snapped to |
| 7853 | // integer coordinates doesn't move a fixed position child. |
| 7854 | // |
| 7855 | // + root |
| 7856 | // + container |
| 7857 | // + scroller |
| 7858 | // + fixed |
| 7859 | // |
| 7860 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7861 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 7862 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7863 | host_impl.CreatePendingTree(); |
| 7864 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7865 | scoped_ptr<LayerImpl> container = |
| 7866 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7867 | LayerImpl* container_layer = container.get(); |
| 7868 | scoped_ptr<LayerImpl> scroller = |
| 7869 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7870 | LayerImpl* scroll_layer = scroller.get(); |
| 7871 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7872 | LayerImpl* fixed_layer = fixed.get(); |
| 7873 | |
| 7874 | container->SetIsContainerForFixedPositionLayers(true); |
| 7875 | |
| 7876 | LayerPositionConstraint constraint; |
| 7877 | constraint.set_is_fixed_position(true); |
| 7878 | fixed->SetPositionConstraint(constraint); |
| 7879 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 7880 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7881 | |
| 7882 | gfx::Transform identity_transform; |
| 7883 | gfx::Transform container_transform; |
| 7884 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7885 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7886 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 7887 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 7888 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 7889 | true); |
| 7890 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 7891 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 7892 | true, false, false); |
| 7893 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 7894 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 7895 | true, false, false); |
| 7896 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 7897 | gfx::PointF(), gfx::Size(50, 50), true, false, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7898 | false); |
| 7899 | |
| 7900 | scroller->AddChild(fixed.Pass()); |
| 7901 | container->AddChild(scroller.Pass()); |
| 7902 | root->AddChild(container.Pass()); |
| 7903 | |
| 7904 | // Rounded to integers already. |
| 7905 | { |
| 7906 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
| 7907 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7908 | |
| 7909 | LayerImplList render_surface_layer_list; |
| 7910 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7911 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7912 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7913 | |
| 7914 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7915 | container_layer->draw_properties().screen_space_transform, |
| 7916 | fixed_layer->draw_properties().screen_space_transform); |
| 7917 | EXPECT_VECTOR_EQ( |
| 7918 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7919 | container_offset); |
| 7920 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7921 | .screen_space_transform.To2dTranslation(), |
| 7922 | container_offset - scroll_delta); |
| 7923 | } |
| 7924 | |
| 7925 | // Scroll delta requiring rounding. |
| 7926 | { |
| 7927 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
| 7928 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7929 | |
| 7930 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 7931 | |
| 7932 | LayerImplList render_surface_layer_list; |
| 7933 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7934 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7935 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7936 | |
| 7937 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7938 | container_layer->draw_properties().screen_space_transform, |
| 7939 | fixed_layer->draw_properties().screen_space_transform); |
| 7940 | EXPECT_VECTOR_EQ( |
| 7941 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7942 | container_offset); |
| 7943 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7944 | .screen_space_transform.To2dTranslation(), |
| 7945 | container_offset - rounded_scroll_delta); |
| 7946 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7947 | |
| 7948 | // Scale is applied earlier in the tree. |
| 7949 | { |
| 7950 | gfx::Transform scaled_container_transform = container_transform; |
| 7951 | scaled_container_transform.Scale3d(3.0, 3.0, 1.0); |
| 7952 | container_layer->SetTransform(scaled_container_transform); |
| 7953 | |
| 7954 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7955 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7956 | |
| 7957 | LayerImplList render_surface_layer_list; |
| 7958 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7959 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7960 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7961 | |
| 7962 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7963 | container_layer->draw_properties().screen_space_transform, |
| 7964 | fixed_layer->draw_properties().screen_space_transform); |
| 7965 | EXPECT_VECTOR_EQ( |
| 7966 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7967 | container_offset); |
| 7968 | |
| 7969 | container_layer->SetTransform(container_transform); |
| 7970 | } |
| 7971 | |
| 7972 | // Scale is applied on the scroll layer itself. |
| 7973 | { |
| 7974 | gfx::Transform scale_transform; |
| 7975 | scale_transform.Scale3d(3.0, 3.0, 1.0); |
| 7976 | scroll_layer->SetTransform(scale_transform); |
| 7977 | |
| 7978 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7979 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7980 | |
| 7981 | LayerImplList render_surface_layer_list; |
| 7982 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 7983 | root.get(), root->bounds(), &render_surface_layer_list); |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7984 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7985 | |
| 7986 | EXPECT_VECTOR_EQ( |
| 7987 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7988 | container_offset); |
| 7989 | |
| 7990 | scroll_layer->SetTransform(identity_transform); |
| 7991 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7992 | } |
| 7993 | |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 7994 | TEST_F(LayerTreeHostCommonTest, |
| 7995 | ScrollCompensationMainScrollOffsetFractionalPart) { |
| 7996 | // This test verifies that a scrolling layer that has fractional scroll offset |
| 7997 | // from main doesn't move a fixed position child. |
| 7998 | // |
| 7999 | // + root |
| 8000 | // + container |
| 8001 | // + scroller |
| 8002 | // + fixed |
| 8003 | // |
| 8004 | FakeImplProxy proxy; |
| 8005 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 8006 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 8007 | host_impl.CreatePendingTree(); |
| 8008 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 8009 | scoped_ptr<LayerImpl> container = |
| 8010 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 8011 | LayerImpl* container_layer = container.get(); |
| 8012 | scoped_ptr<LayerImpl> scroller = |
| 8013 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 8014 | LayerImpl* scroll_layer = scroller.get(); |
| 8015 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 8016 | LayerImpl* fixed_layer = fixed.get(); |
| 8017 | |
| 8018 | container->SetIsContainerForFixedPositionLayers(true); |
| 8019 | |
| 8020 | LayerPositionConstraint constraint; |
| 8021 | constraint.set_is_fixed_position(true); |
| 8022 | fixed->SetPositionConstraint(constraint); |
| 8023 | |
| 8024 | scroller->SetScrollClipLayer(container->id()); |
| 8025 | |
| 8026 | gfx::Transform identity_transform; |
| 8027 | gfx::Transform container_transform; |
| 8028 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 8029 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 8030 | |
| 8031 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 8032 | gfx::PointF(), gfx::Size(50, 50), true, false, |
| 8033 | true); |
| 8034 | SetLayerPropertiesForTesting(container.get(), container_transform, |
| 8035 | gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), |
| 8036 | true, false, false); |
| 8037 | SetLayerPropertiesForTesting(scroller.get(), identity_transform, |
| 8038 | gfx::Point3F(), gfx::PointF(0.0, 0.0), |
| 8039 | gfx::Size(30, 30), true, false, false); |
| 8040 | |
| 8041 | gfx::ScrollOffset scroll_offset(3.3, 4.2); |
| 8042 | gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f); |
| 8043 | gfx::Vector2dF scroll_delta(0.1f, 0.4f); |
| 8044 | // Blink only uses the integer part of the scroll_offset for fixed |
| 8045 | // position layer. |
| 8046 | SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), |
| 8047 | gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true, |
| 8048 | false, false); |
aelias | f998da8 | 2015-02-03 01:40:51 | [diff] [blame] | 8049 | scroll_layer->PushScrollOffsetFromMainThread(scroll_offset); |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 8050 | scroll_layer->SetScrollDelta(scroll_delta); |
miletus | ff93ab7 | 2015-01-30 04:30:44 | [diff] [blame] | 8051 | scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part); |
miletus | 2c78036b | 2015-01-29 20:52:37 | [diff] [blame] | 8052 | |
| 8053 | scroller->AddChild(fixed.Pass()); |
| 8054 | container->AddChild(scroller.Pass()); |
| 8055 | root->AddChild(container.Pass()); |
| 8056 | |
| 8057 | LayerImplList render_surface_layer_list; |
| 8058 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8059 | root.get(), root->bounds(), &render_surface_layer_list); |
| 8060 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8061 | |
| 8062 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 8063 | container_layer->draw_properties().screen_space_transform, |
| 8064 | fixed_layer->draw_properties().screen_space_transform); |
| 8065 | EXPECT_VECTOR_EQ( |
| 8066 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 8067 | container_offset); |
| 8068 | |
| 8069 | gfx::ScrollOffset effective_scroll_offset = |
| 8070 | ScrollOffsetWithDelta(scroll_offset, scroll_delta); |
| 8071 | gfx::Vector2d rounded_effective_scroll_offset = |
| 8072 | ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset)); |
| 8073 | EXPECT_VECTOR_EQ( |
| 8074 | scroll_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 8075 | container_offset - rounded_effective_scroll_offset); |
| 8076 | } |
| 8077 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8078 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 8079 | public: |
| 8080 | static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
| 8081 | LayerTreeImpl* tree_impl, |
| 8082 | int id) { |
| 8083 | return make_scoped_ptr( |
| 8084 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 8085 | } |
| 8086 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 8087 | ~AnimationScaleFactorTrackingLayerImpl() override {} |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8088 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8089 | private: |
| 8090 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 8091 | int id) |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8092 | : LayerImpl(tree_impl, id) { |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8093 | SetDrawsContent(true); |
| 8094 | } |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8095 | }; |
| 8096 | |
| 8097 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
| 8098 | FakeImplProxy proxy; |
| 8099 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 8100 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8101 | gfx::Transform identity_matrix; |
| 8102 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
| 8103 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
| 8104 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
| 8105 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
| 8106 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
| 8107 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
| 8108 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
| 8109 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 8110 | |
| 8111 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 8112 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 8113 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
| 8114 | |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 8115 | child->AddChild(grand_child.Pass()); |
| 8116 | parent->AddChild(child.Pass()); |
| 8117 | grand_parent->AddChild(parent.Pass()); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8118 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8119 | SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix, |
| 8120 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8121 | true, false, true); |
| 8122 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 8123 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8124 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8125 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 8126 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8127 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8128 | |
| 8129 | SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(), |
| 8130 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8131 | false); |
| 8132 | |
| 8133 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8134 | |
| 8135 | // No layers have animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8136 | EXPECT_EQ(0.f, |
| 8137 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8138 | EXPECT_EQ(0.f, |
| 8139 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8140 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8141 | EXPECT_EQ( |
| 8142 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8143 | |
| 8144 | TransformOperations translation; |
| 8145 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 8146 | |
| 8147 | AddAnimatedTransformToLayer( |
| 8148 | parent_raw, 1.0, TransformOperations(), translation); |
| 8149 | |
| 8150 | // No layers have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8151 | EXPECT_EQ(0.f, |
| 8152 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8153 | EXPECT_EQ(0.f, |
| 8154 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8155 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8156 | EXPECT_EQ( |
| 8157 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8158 | |
| 8159 | TransformOperations scale; |
| 8160 | scale.AppendScale(5.f, 4.f, 3.f); |
| 8161 | |
| 8162 | AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); |
| 8163 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8164 | |
| 8165 | // Only |child| has a scale-affecting animation. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8166 | EXPECT_EQ(0.f, |
| 8167 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8168 | EXPECT_EQ(0.f, |
| 8169 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8170 | EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8171 | EXPECT_EQ( |
| 8172 | 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8173 | |
| 8174 | AddAnimatedTransformToLayer( |
| 8175 | grand_parent.get(), 1.0, TransformOperations(), scale); |
| 8176 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8177 | |
| 8178 | // |grand_parent| and |child| have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8179 | EXPECT_EQ(5.f, |
| 8180 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8181 | EXPECT_EQ(5.f, |
| 8182 | parent_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8183 | // We don't support combining animated scales from two nodes; 0.f means |
| 8184 | // that the maximum scale could not be computed. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8185 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8186 | EXPECT_EQ( |
| 8187 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8188 | |
| 8189 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 8190 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8191 | |
| 8192 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8193 | EXPECT_EQ(5.f, |
| 8194 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8195 | EXPECT_EQ(0.f, |
| 8196 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8197 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8198 | EXPECT_EQ( |
| 8199 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8200 | |
| 8201 | grand_parent->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8202 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8203 | parent_raw->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8204 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8205 | child_raw->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8206 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8207 | |
| 8208 | TransformOperations perspective; |
| 8209 | perspective.AppendPerspective(10.f); |
| 8210 | |
| 8211 | AddAnimatedTransformToLayer( |
| 8212 | child_raw, 1.0, TransformOperations(), perspective); |
| 8213 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8214 | |
| 8215 | // |child| has a scale-affecting animation but computing the maximum of this |
| 8216 | // animation is not supported. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8217 | EXPECT_EQ(0.f, |
| 8218 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8219 | EXPECT_EQ(0.f, |
| 8220 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8221 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8222 | EXPECT_EQ( |
| 8223 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8224 | |
| 8225 | child_raw->layer_animation_controller()->AbortAnimations( |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 8226 | Animation::TRANSFORM); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8227 | |
| 8228 | gfx::Transform scale_matrix; |
| 8229 | scale_matrix.Scale(1.f, 2.f); |
| 8230 | grand_parent->SetTransform(scale_matrix); |
| 8231 | parent_raw->SetTransform(scale_matrix); |
| 8232 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 8233 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8234 | |
| 8235 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 8236 | // animation with maximum scale 5.f. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8237 | EXPECT_EQ(0.f, |
| 8238 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8239 | EXPECT_EQ(10.f, |
| 8240 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8241 | EXPECT_EQ(10.f, |
| 8242 | child_raw->draw_properties().maximum_animation_contents_scale); |
| 8243 | EXPECT_EQ( |
| 8244 | 10.f, |
| 8245 | grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8246 | |
| 8247 | gfx::Transform perspective_matrix; |
| 8248 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 8249 | child_raw->SetTransform(perspective_matrix); |
| 8250 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8251 | |
| 8252 | // |child| has a transform that's neither a translation nor a scale. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8253 | EXPECT_EQ(0.f, |
| 8254 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8255 | EXPECT_EQ(10.f, |
| 8256 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8257 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8258 | EXPECT_EQ( |
| 8259 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8260 | |
| 8261 | parent_raw->SetTransform(perspective_matrix); |
| 8262 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8263 | |
| 8264 | // |parent| and |child| have transforms that are neither translations nor |
| 8265 | // scales. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8266 | EXPECT_EQ(0.f, |
| 8267 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8268 | EXPECT_EQ(0.f, |
| 8269 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8270 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8271 | EXPECT_EQ( |
| 8272 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8273 | |
| 8274 | parent_raw->SetTransform(identity_matrix); |
| 8275 | child_raw->SetTransform(identity_matrix); |
| 8276 | grand_parent->SetTransform(perspective_matrix); |
| 8277 | |
| 8278 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8279 | |
| 8280 | // |grand_parent| has a transform that's neither a translation nor a scale. |
[email protected] | a57cb8b1 | 2014-06-13 18:15:37 | [diff] [blame] | 8281 | EXPECT_EQ(0.f, |
| 8282 | grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8283 | EXPECT_EQ(0.f, |
| 8284 | parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8285 | EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8286 | EXPECT_EQ( |
| 8287 | 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 8288 | } |
| 8289 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8290 | static int membership_id(LayerImpl* layer) { |
| 8291 | return layer->draw_properties().last_drawn_render_surface_layer_list_id; |
| 8292 | } |
| 8293 | |
| 8294 | static void GatherDrawnLayers(LayerImplList* rsll, |
| 8295 | std::set<LayerImpl*>* drawn_layers) { |
| 8296 | for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll), |
| 8297 | end = LayerIterator<LayerImpl>::End(rsll); |
| 8298 | it != end; |
| 8299 | ++it) { |
| 8300 | LayerImpl* layer = *it; |
| 8301 | if (it.represents_itself()) |
| 8302 | drawn_layers->insert(layer); |
| 8303 | |
| 8304 | if (!it.represents_contributing_render_surface()) |
| 8305 | continue; |
| 8306 | |
| 8307 | if (layer->mask_layer()) |
| 8308 | drawn_layers->insert(layer->mask_layer()); |
| 8309 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 8310 | drawn_layers->insert(layer->replica_layer()->mask_layer()); |
| 8311 | } |
| 8312 | } |
| 8313 | |
| 8314 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
| 8315 | FakeImplProxy proxy; |
| 8316 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 8317 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8318 | gfx::Transform identity_matrix; |
| 8319 | |
| 8320 | scoped_ptr<LayerImpl> grand_parent = |
| 8321 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8322 | scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3); |
| 8323 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5); |
| 8324 | scoped_ptr<LayerImpl> grand_child1 = |
| 8325 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 8326 | scoped_ptr<LayerImpl> grand_child2 = |
| 8327 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 8328 | |
| 8329 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 8330 | LayerImpl* parent_raw = parent.get(); |
| 8331 | LayerImpl* child_raw = child.get(); |
| 8332 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 8333 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 8334 | |
| 8335 | child->AddChild(grand_child1.Pass()); |
| 8336 | child->AddChild(grand_child2.Pass()); |
| 8337 | parent->AddChild(child.Pass()); |
| 8338 | grand_parent->AddChild(parent.Pass()); |
| 8339 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8340 | SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix, |
| 8341 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8342 | true, false, true); |
| 8343 | SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(), |
| 8344 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8345 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8346 | |
| 8347 | SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(), |
| 8348 | gfx::PointF(), gfx::Size(1, 2), true, false, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8349 | false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8350 | |
| 8351 | SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix, |
| 8352 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8353 | true, false, false); |
| 8354 | |
| 8355 | SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix, |
| 8356 | gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2), |
| 8357 | true, false, false); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8358 | |
| 8359 | // Start with nothing being drawn. |
| 8360 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8361 | int member_id = render_surface_layer_list_count(); |
| 8362 | |
| 8363 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8364 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8365 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8366 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8367 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8368 | |
| 8369 | std::set<LayerImpl*> expected; |
| 8370 | std::set<LayerImpl*> actual; |
| 8371 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8372 | EXPECT_EQ(expected, actual); |
| 8373 | |
| 8374 | // If we force render surface, but none of the layers are in the layer list, |
| 8375 | // then this layer should not appear in RSLL. |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8376 | grand_child1_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8377 | |
| 8378 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8379 | member_id = render_surface_layer_list_count(); |
| 8380 | |
| 8381 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8382 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8383 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8384 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8385 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8386 | |
| 8387 | expected.clear(); |
| 8388 | actual.clear(); |
| 8389 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8390 | EXPECT_EQ(expected, actual); |
| 8391 | |
| 8392 | // However, if we say that this layer also draws content, it will appear in |
| 8393 | // RSLL. |
| 8394 | grand_child1_raw->SetDrawsContent(true); |
| 8395 | |
| 8396 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8397 | member_id = render_surface_layer_list_count(); |
| 8398 | |
| 8399 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8400 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8401 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8402 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 8403 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8404 | |
| 8405 | expected.clear(); |
| 8406 | expected.insert(grand_child1_raw); |
| 8407 | |
| 8408 | actual.clear(); |
| 8409 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8410 | EXPECT_EQ(expected, actual); |
| 8411 | |
| 8412 | // Now child is forced to have a render surface, and one if its children draws |
| 8413 | // content. |
| 8414 | grand_child1_raw->SetDrawsContent(false); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8415 | grand_child1_raw->SetHasRenderSurface(false); |
| 8416 | child_raw->SetHasRenderSurface(true); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8417 | grand_child2_raw->SetDrawsContent(true); |
| 8418 | |
| 8419 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8420 | member_id = render_surface_layer_list_count(); |
| 8421 | |
| 8422 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8423 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8424 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8425 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8426 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8427 | |
| 8428 | expected.clear(); |
| 8429 | expected.insert(grand_child2_raw); |
| 8430 | |
| 8431 | actual.clear(); |
| 8432 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8433 | EXPECT_EQ(expected, actual); |
| 8434 | |
| 8435 | // Add a mask layer to child. |
| 8436 | child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass()); |
| 8437 | |
| 8438 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8439 | member_id = render_surface_layer_list_count(); |
| 8440 | |
| 8441 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8442 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8443 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8444 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8445 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8446 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8447 | |
| 8448 | expected.clear(); |
| 8449 | expected.insert(grand_child2_raw); |
| 8450 | expected.insert(child_raw->mask_layer()); |
| 8451 | |
| 8452 | expected.clear(); |
| 8453 | expected.insert(grand_child2_raw); |
| 8454 | expected.insert(child_raw->mask_layer()); |
| 8455 | |
| 8456 | actual.clear(); |
| 8457 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8458 | EXPECT_EQ(expected, actual); |
| 8459 | |
| 8460 | // Add replica mask layer. |
| 8461 | scoped_ptr<LayerImpl> replica_layer = |
| 8462 | LayerImpl::Create(host_impl.active_tree(), 20); |
| 8463 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21)); |
| 8464 | child_raw->SetReplicaLayer(replica_layer.Pass()); |
| 8465 | |
| 8466 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8467 | member_id = render_surface_layer_list_count(); |
| 8468 | |
| 8469 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8470 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8471 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8472 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8473 | EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer())); |
| 8474 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8475 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8476 | |
| 8477 | expected.clear(); |
| 8478 | expected.insert(grand_child2_raw); |
| 8479 | expected.insert(child_raw->mask_layer()); |
| 8480 | expected.insert(child_raw->replica_layer()->mask_layer()); |
| 8481 | |
| 8482 | actual.clear(); |
| 8483 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8484 | EXPECT_EQ(expected, actual); |
| 8485 | |
| 8486 | child_raw->TakeReplicaLayer(); |
| 8487 | |
| 8488 | // With nothing drawing, we should have no layers. |
| 8489 | grand_child2_raw->SetDrawsContent(false); |
| 8490 | |
| 8491 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8492 | member_id = render_surface_layer_list_count(); |
| 8493 | |
| 8494 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8495 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8496 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8497 | EXPECT_NE(member_id, membership_id(child_raw->mask_layer())); |
| 8498 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8499 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8500 | |
| 8501 | expected.clear(); |
| 8502 | actual.clear(); |
| 8503 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8504 | EXPECT_EQ(expected, actual); |
| 8505 | |
| 8506 | // Child itself draws means that we should have the child and the mask in the |
| 8507 | // list. |
| 8508 | child_raw->SetDrawsContent(true); |
| 8509 | |
| 8510 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8511 | member_id = render_surface_layer_list_count(); |
| 8512 | |
| 8513 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8514 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8515 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 8516 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8517 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8518 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8519 | |
| 8520 | expected.clear(); |
| 8521 | expected.insert(child_raw); |
| 8522 | expected.insert(child_raw->mask_layer()); |
| 8523 | actual.clear(); |
| 8524 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8525 | EXPECT_EQ(expected, actual); |
| 8526 | |
| 8527 | child_raw->TakeMaskLayer(); |
| 8528 | |
| 8529 | // Now everyone's a member! |
| 8530 | grand_parent_raw->SetDrawsContent(true); |
| 8531 | parent_raw->SetDrawsContent(true); |
| 8532 | child_raw->SetDrawsContent(true); |
| 8533 | grand_child1_raw->SetDrawsContent(true); |
| 8534 | grand_child2_raw->SetDrawsContent(true); |
| 8535 | |
| 8536 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8537 | member_id = render_surface_layer_list_count(); |
| 8538 | |
| 8539 | EXPECT_EQ(member_id, membership_id(grand_parent_raw)); |
| 8540 | EXPECT_EQ(member_id, membership_id(parent_raw)); |
| 8541 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 8542 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 8543 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8544 | |
| 8545 | expected.clear(); |
| 8546 | expected.insert(grand_parent_raw); |
| 8547 | expected.insert(parent_raw); |
| 8548 | expected.insert(child_raw); |
| 8549 | expected.insert(grand_child1_raw); |
| 8550 | expected.insert(grand_child2_raw); |
| 8551 | |
| 8552 | actual.clear(); |
| 8553 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8554 | EXPECT_EQ(expected, actual); |
| 8555 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8556 | |
| 8557 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
| 8558 | FakeImplProxy proxy; |
| 8559 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 8560 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8561 | |
| 8562 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 8563 | LayerImpl* root_layer = root.get(); |
| 8564 | scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2); |
| 8565 | LayerImpl* child1_layer = child1.get(); |
| 8566 | scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3); |
| 8567 | LayerImpl* child2_layer = child2.get(); |
| 8568 | |
| 8569 | root->AddChild(child1.Pass()); |
| 8570 | root->AddChild(child2.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8571 | root->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8572 | |
| 8573 | gfx::Transform identity_matrix, scale_transform_child1, |
| 8574 | scale_transform_child2; |
| 8575 | scale_transform_child1.Scale(2, 3); |
| 8576 | scale_transform_child2.Scale(4, 5); |
| 8577 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8578 | SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(), |
| 8579 | gfx::PointF(), gfx::Size(1, 1), true, false, |
| 8580 | true); |
| 8581 | SetLayerPropertiesForTesting(child1_layer, scale_transform_child1, |
| 8582 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 8583 | false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8584 | |
| 8585 | child1_layer->SetMaskLayer( |
| 8586 | LayerImpl::Create(host_impl.active_tree(), 4).Pass()); |
| 8587 | |
| 8588 | scoped_ptr<LayerImpl> replica_layer = |
| 8589 | LayerImpl::Create(host_impl.active_tree(), 5); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8590 | replica_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8591 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
| 8592 | child1_layer->SetReplicaLayer(replica_layer.Pass()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8593 | child1_layer->SetHasRenderSurface(true); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8594 | |
| 8595 | ExecuteCalculateDrawProperties(root_layer); |
| 8596 | |
| 8597 | TransformOperations scale; |
| 8598 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8599 | |
| 8600 | AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8601 | SetLayerPropertiesForTesting(child2_layer, scale_transform_child2, |
| 8602 | gfx::Point3F(), gfx::PointF(), gfx::Size(), true, |
| 8603 | false, false); |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8604 | |
| 8605 | ExecuteCalculateDrawProperties(root_layer); |
| 8606 | |
| 8607 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); |
| 8608 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8609 | EXPECT_FLOAT_EQ( |
| 8610 | 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8611 | EXPECT_FLOAT_EQ(3.f, |
| 8612 | child1_layer->replica_layer() |
| 8613 | ->mask_layer() |
| 8614 | ->draw_properties() |
| 8615 | .ideal_contents_scale); |
| 8616 | EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8617 | |
| 8618 | EXPECT_FLOAT_EQ( |
| 8619 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8620 | EXPECT_FLOAT_EQ( |
| 8621 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8622 | EXPECT_FLOAT_EQ(0.f, |
| 8623 | child1_layer->mask_layer() |
| 8624 | ->draw_properties() |
| 8625 | .maximum_animation_contents_scale); |
| 8626 | EXPECT_FLOAT_EQ(0.f, |
| 8627 | child1_layer->replica_layer() |
| 8628 | ->mask_layer() |
| 8629 | ->draw_properties() |
| 8630 | .maximum_animation_contents_scale); |
| 8631 | EXPECT_FLOAT_EQ( |
| 8632 | 8.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8633 | |
| 8634 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8635 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor); |
| 8636 | EXPECT_FLOAT_EQ( |
| 8637 | 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8638 | EXPECT_FLOAT_EQ(1.f, |
| 8639 | child1_layer->replica_layer() |
| 8640 | ->mask_layer() |
| 8641 | ->draw_properties() |
| 8642 | .page_scale_factor); |
| 8643 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor); |
| 8644 | |
| 8645 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); |
| 8646 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); |
| 8647 | EXPECT_FLOAT_EQ( |
| 8648 | 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8649 | EXPECT_FLOAT_EQ(1.f, |
| 8650 | child1_layer->replica_layer() |
| 8651 | ->mask_layer() |
| 8652 | ->draw_properties() |
| 8653 | .device_scale_factor); |
| 8654 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); |
| 8655 | |
| 8656 | // Changing page-scale would affect ideal_contents_scale and |
| 8657 | // maximum_animation_contents_scale. |
| 8658 | |
| 8659 | float page_scale_factor = 3.f; |
| 8660 | float device_scale_factor = 1.0f; |
| 8661 | std::vector<LayerImpl*> render_surface_layer_list; |
| 8662 | gfx::Size device_viewport_size = |
| 8663 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 8664 | root_layer->bounds().height() * device_scale_factor); |
| 8665 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8666 | root_layer, device_viewport_size, &render_surface_layer_list); |
| 8667 | |
| 8668 | inputs.page_scale_factor = page_scale_factor; |
| 8669 | inputs.can_adjust_raster_scales = true; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 8670 | inputs.page_scale_layer = root_layer; |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame] | 8671 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8672 | |
| 8673 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); |
| 8674 | EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8675 | EXPECT_FLOAT_EQ( |
| 8676 | 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8677 | EXPECT_FLOAT_EQ(9.f, |
| 8678 | child1_layer->replica_layer() |
| 8679 | ->mask_layer() |
| 8680 | ->draw_properties() |
| 8681 | .ideal_contents_scale); |
| 8682 | EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8683 | |
| 8684 | EXPECT_FLOAT_EQ( |
| 8685 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8686 | EXPECT_FLOAT_EQ( |
| 8687 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8688 | EXPECT_FLOAT_EQ(0.f, |
| 8689 | child1_layer->mask_layer() |
| 8690 | ->draw_properties() |
| 8691 | .maximum_animation_contents_scale); |
| 8692 | EXPECT_FLOAT_EQ(0.f, |
| 8693 | child1_layer->replica_layer() |
| 8694 | ->mask_layer() |
| 8695 | ->draw_properties() |
| 8696 | .maximum_animation_contents_scale); |
| 8697 | EXPECT_FLOAT_EQ( |
| 8698 | 24.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8699 | |
| 8700 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8701 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); |
| 8702 | EXPECT_FLOAT_EQ( |
| 8703 | 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8704 | EXPECT_FLOAT_EQ(3.f, |
| 8705 | child1_layer->replica_layer() |
| 8706 | ->mask_layer() |
| 8707 | ->draw_properties() |
| 8708 | .page_scale_factor); |
| 8709 | EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); |
| 8710 | |
| 8711 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); |
| 8712 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); |
| 8713 | EXPECT_FLOAT_EQ( |
| 8714 | 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8715 | EXPECT_FLOAT_EQ(1.f, |
| 8716 | child1_layer->replica_layer() |
| 8717 | ->mask_layer() |
| 8718 | ->draw_properties() |
| 8719 | .device_scale_factor); |
| 8720 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); |
| 8721 | |
| 8722 | // Changing device-scale would affect ideal_contents_scale and |
| 8723 | // maximum_animation_contents_scale. |
| 8724 | |
| 8725 | device_scale_factor = 4.0f; |
| 8726 | inputs.device_scale_factor = device_scale_factor; |
| 8727 | inputs.can_adjust_raster_scales = true; |
| 8728 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8729 | |
| 8730 | EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale); |
| 8731 | EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8732 | EXPECT_FLOAT_EQ( |
| 8733 | 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8734 | EXPECT_FLOAT_EQ(36.f, |
| 8735 | child1_layer->replica_layer() |
| 8736 | ->mask_layer() |
| 8737 | ->draw_properties() |
| 8738 | .ideal_contents_scale); |
| 8739 | EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8740 | |
| 8741 | EXPECT_FLOAT_EQ( |
| 8742 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8743 | EXPECT_FLOAT_EQ( |
| 8744 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8745 | EXPECT_FLOAT_EQ(0.f, |
| 8746 | child1_layer->mask_layer() |
| 8747 | ->draw_properties() |
| 8748 | .maximum_animation_contents_scale); |
| 8749 | EXPECT_FLOAT_EQ(0.f, |
| 8750 | child1_layer->replica_layer() |
| 8751 | ->mask_layer() |
| 8752 | ->draw_properties() |
| 8753 | .maximum_animation_contents_scale); |
| 8754 | EXPECT_FLOAT_EQ( |
| 8755 | 96.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8756 | |
| 8757 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8758 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); |
| 8759 | EXPECT_FLOAT_EQ( |
| 8760 | 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8761 | EXPECT_FLOAT_EQ(3.f, |
| 8762 | child1_layer->replica_layer() |
| 8763 | ->mask_layer() |
| 8764 | ->draw_properties() |
| 8765 | .page_scale_factor); |
| 8766 | EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); |
| 8767 | |
| 8768 | EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor); |
| 8769 | EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor); |
| 8770 | EXPECT_FLOAT_EQ( |
| 8771 | 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8772 | EXPECT_FLOAT_EQ(4.f, |
| 8773 | child1_layer->replica_layer() |
| 8774 | ->mask_layer() |
| 8775 | ->draw_properties() |
| 8776 | .device_scale_factor); |
| 8777 | EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor); |
| 8778 | } |
| 8779 | |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8780 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8781 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8782 | SetLayerPropertiesForTesting(root.get(), |
| 8783 | gfx::Transform(), |
| 8784 | gfx::Point3F(), |
| 8785 | gfx::PointF(), |
| 8786 | gfx::Size(768 / 2, 3000), |
| 8787 | true, |
| 8788 | false); |
| 8789 | root->SetIsDrawable(true); |
| 8790 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8791 | scoped_refptr<Layer> clip = Layer::Create(layer_settings()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8792 | SetLayerPropertiesForTesting(clip.get(), |
| 8793 | gfx::Transform(), |
| 8794 | gfx::Point3F(), |
| 8795 | gfx::PointF(), |
| 8796 | gfx::Size(768 / 2, 10000), |
| 8797 | true, |
| 8798 | false); |
| 8799 | clip->SetMasksToBounds(true); |
| 8800 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8801 | scoped_refptr<Layer> content = Layer::Create(layer_settings()); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8802 | SetLayerPropertiesForTesting(content.get(), |
| 8803 | gfx::Transform(), |
| 8804 | gfx::Point3F(), |
| 8805 | gfx::PointF(), |
| 8806 | gfx::Size(768 / 2, 10000), |
| 8807 | true, |
| 8808 | false); |
| 8809 | content->SetIsDrawable(true); |
| 8810 | content->SetForceRenderSurface(true); |
| 8811 | |
| 8812 | root->AddChild(clip); |
| 8813 | clip->AddChild(content); |
| 8814 | |
enne | 2097cab | 2014-09-25 20:16:31 | [diff] [blame] | 8815 | FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); |
| 8816 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8817 | host->SetRootLayer(root); |
| 8818 | |
| 8819 | gfx::Size device_viewport_size(768, 582); |
| 8820 | RenderSurfaceLayerList render_surface_layer_list; |
| 8821 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 8822 | host->root_layer(), device_viewport_size, &render_surface_layer_list); |
| 8823 | inputs.device_scale_factor = 2.f; |
| 8824 | inputs.page_scale_factor = 1.f; |
enne | 6394d5b4 | 2015-05-26 22:23:11 | [diff] [blame] | 8825 | inputs.page_scale_layer = NULL; |
danakj | f6069db | 2014-09-13 00:46:47 | [diff] [blame] | 8826 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8827 | |
| 8828 | // Layers in the root render surface have their visible content rect clipped |
| 8829 | // by the viewport. |
| 8830 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); |
| 8831 | |
| 8832 | // Layers drawing to a child render surface should still have their visible |
| 8833 | // content rect clipped by the viewport. |
| 8834 | EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); |
| 8835 | } |
| 8836 | |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8837 | TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { |
| 8838 | FakeImplProxy proxy; |
| 8839 | TestSharedBitmapManager shared_bitmap_manager; |
reveman | 34b7a152 | 2015-03-23 20:27:47 | [diff] [blame] | 8840 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8841 | |
| 8842 | // Set two layers: the root layer clips it's child, |
| 8843 | // the child draws its content. |
| 8844 | |
| 8845 | gfx::Size root_size = gfx::Size(300, 500); |
| 8846 | |
| 8847 | // Sublayer should be bigger than the root enlarged by bounds_delta. |
| 8848 | gfx::Size sublayer_size = gfx::Size(300, 1000); |
| 8849 | |
| 8850 | // Device viewport accomidated the root and the top controls. |
| 8851 | gfx::Size device_viewport_size = gfx::Size(300, 600); |
| 8852 | gfx::Transform identity_matrix; |
| 8853 | |
| 8854 | host_impl.active_tree()->SetRootLayer( |
| 8855 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8856 | |
| 8857 | LayerImpl* root = host_impl.active_tree()->root_layer(); |
| 8858 | SetLayerPropertiesForTesting(root, |
| 8859 | identity_matrix, |
| 8860 | gfx::Point3F(), |
| 8861 | gfx::PointF(), |
| 8862 | root_size, |
| 8863 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8864 | false, |
| 8865 | true); |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8866 | |
| 8867 | root->SetContentBounds(root_size); |
| 8868 | root->SetMasksToBounds(true); |
| 8869 | |
| 8870 | root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2)); |
| 8871 | |
| 8872 | LayerImpl* sublayer = root->child_at(0); |
| 8873 | SetLayerPropertiesForTesting(sublayer, |
| 8874 | identity_matrix, |
| 8875 | gfx::Point3F(), |
| 8876 | gfx::PointF(), |
| 8877 | sublayer_size, |
| 8878 | false, |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 8879 | false, |
timav | 599f4359d | 2014-12-05 00:12:22 | [diff] [blame] | 8880 | false); |
| 8881 | |
| 8882 | sublayer->SetContentBounds(sublayer_size); |
| 8883 | sublayer->SetDrawsContent(true); |
| 8884 | |
| 8885 | LayerImplList layer_impl_list; |
| 8886 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8887 | root, device_viewport_size, &layer_impl_list); |
| 8888 | |
| 8889 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8890 | |
| 8891 | EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_content_rect()); |
| 8892 | |
| 8893 | root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
| 8894 | |
| 8895 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8896 | |
| 8897 | gfx::Rect affected_by_delta(0, 0, root_size.width(), |
| 8898 | root_size.height() + 50); |
| 8899 | EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect()); |
| 8900 | } |
| 8901 | |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8902 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) { |
| 8903 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8904 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8905 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8906 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8907 | |
| 8908 | root->AddChild(animated); |
| 8909 | |
| 8910 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8911 | host->SetRootLayer(root); |
| 8912 | |
| 8913 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8914 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8915 | SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 8916 | gfx::PointF(), gfx::Size(20, 20), true, false); |
| 8917 | |
| 8918 | root->SetMasksToBounds(true); |
| 8919 | root->SetForceRenderSurface(true); |
| 8920 | animated->SetOpacity(0.f); |
| 8921 | |
| 8922 | AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0, |
| 8923 | 0.f, 1.f, false); |
| 8924 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8925 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 7d83b45 | 2015-02-24 20:18:06 | [diff] [blame] | 8926 | |
| 8927 | EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty()); |
| 8928 | } |
| 8929 | |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8930 | TEST_F(LayerTreeHostCommonTest, |
| 8931 | VisibleContentRectForAnimatedLayerWithSingularTransform) { |
| 8932 | const gfx::Transform identity_matrix; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8933 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 8934 | scoped_refptr<Layer> clip = Layer::Create(layer_settings()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8935 | scoped_refptr<LayerWithForcedDrawsContent> animated = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8936 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8937 | scoped_refptr<LayerWithForcedDrawsContent> surface = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8938 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8939 | scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 8940 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8941 | |
| 8942 | root->AddChild(clip); |
| 8943 | clip->AddChild(animated); |
| 8944 | animated->AddChild(surface); |
| 8945 | surface->AddChild(descendant_of_animation); |
| 8946 | |
| 8947 | clip->SetMasksToBounds(true); |
| 8948 | surface->SetForceRenderSurface(true); |
| 8949 | |
| 8950 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8951 | host->SetRootLayer(root); |
| 8952 | |
| 8953 | gfx::Transform uninvertible_matrix; |
| 8954 | uninvertible_matrix.Scale3d(6.f, 6.f, 0.f); |
| 8955 | |
| 8956 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 8957 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8958 | SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(), |
| 8959 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 8960 | SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix, |
| 8961 | gfx::Point3F(), gfx::PointF(), |
| 8962 | gfx::Size(120, 120), true, false); |
| 8963 | SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(), |
| 8964 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 8965 | SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix, |
| 8966 | gfx::Point3F(), gfx::PointF(), |
| 8967 | gfx::Size(200, 200), true, false); |
| 8968 | |
| 8969 | TransformOperations start_transform_operations; |
| 8970 | start_transform_operations.AppendMatrix(uninvertible_matrix); |
| 8971 | TransformOperations end_transform_operations; |
| 8972 | |
| 8973 | AddAnimatedTransformToLayer(animated.get(), 10.0, start_transform_operations, |
| 8974 | end_transform_operations); |
| 8975 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8976 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8977 | |
| 8978 | // The animated layer has a singular transform and maps to a non-empty rect in |
| 8979 | // clipped target space, so is treated as fully visible. |
| 8980 | EXPECT_EQ(gfx::Rect(120, 120), animated->visible_rect_from_property_trees()); |
| 8981 | |
| 8982 | // The singular transform on |animated| is flattened when inherited by |
| 8983 | // |surface|, and this happens to make it invertible. |
| 8984 | EXPECT_EQ(gfx::Rect(2, 2), surface->visible_rect_from_property_trees()); |
| 8985 | EXPECT_EQ(gfx::Rect(2, 2), |
| 8986 | descendant_of_animation->visible_rect_from_property_trees()); |
| 8987 | |
| 8988 | gfx::Transform zero_matrix; |
| 8989 | zero_matrix.Scale3d(0.f, 0.f, 0.f); |
| 8990 | SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(), |
| 8991 | gfx::PointF(), gfx::Size(120, 120), true, false); |
| 8992 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 8993 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | a92fdc1 | 2015-03-31 22:47:41 | [diff] [blame] | 8994 | |
| 8995 | // The animated layer maps to the empty rect in clipped target space, so is |
| 8996 | // treated as having an empty visible rect. |
| 8997 | EXPECT_EQ(gfx::Rect(), animated->visible_rect_from_property_trees()); |
| 8998 | |
| 8999 | // This time, flattening does not make |animated|'s transform invertible. This |
| 9000 | // means the clip cannot be projected into |surface|'s space, so we treat |
| 9001 | // |surface| and layers that draw into it as fully visible. |
| 9002 | EXPECT_EQ(gfx::Rect(100, 100), surface->visible_rect_from_property_trees()); |
| 9003 | EXPECT_EQ(gfx::Rect(200, 200), |
| 9004 | descendant_of_animation->visible_rect_from_property_trees()); |
| 9005 | } |
| 9006 | |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 9007 | // Verify that having an animated filter (but no current filter, as these |
| 9008 | // are mutually exclusive) correctly creates a render surface. |
| 9009 | TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9010 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 9011 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 9012 | scoped_refptr<Layer> grandchild = Layer::Create(layer_settings()); |
enne | 92f2f6d9 | 2015-02-25 23:13:31 | [diff] [blame] | 9013 | root->AddChild(child); |
| 9014 | child->AddChild(grandchild); |
| 9015 | |
| 9016 | gfx::Transform identity_transform; |
| 9017 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 9018 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 9019 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 9020 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 9021 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 9022 | gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), |
| 9023 | true, false); |
| 9024 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9025 | host->SetRootLayer(root); |
| 9026 | |
| 9027 | AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f); |
| 9028 | |
| 9029 | ExecuteCalculateDrawProperties(root.get()); |
| 9030 | |
| 9031 | EXPECT_TRUE(root->render_surface()); |
| 9032 | EXPECT_TRUE(child->render_surface()); |
| 9033 | EXPECT_FALSE(grandchild->render_surface()); |
| 9034 | |
| 9035 | EXPECT_TRUE(root->filters().IsEmpty()); |
| 9036 | EXPECT_TRUE(child->filters().IsEmpty()); |
| 9037 | EXPECT_TRUE(grandchild->filters().IsEmpty()); |
| 9038 | |
| 9039 | EXPECT_FALSE(root->FilterIsAnimating()); |
| 9040 | EXPECT_TRUE(child->FilterIsAnimating()); |
| 9041 | EXPECT_FALSE(grandchild->FilterIsAnimating()); |
| 9042 | } |
| 9043 | |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 9044 | // Ensures that the property tree code accounts for offsets between fixed |
| 9045 | // position layers and their respective containers. |
| 9046 | TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9047 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 9048 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 9049 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9050 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 9051 | |
| 9052 | root->AddChild(child); |
| 9053 | child->AddChild(grandchild); |
| 9054 | |
| 9055 | gfx::Transform identity_transform; |
| 9056 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 9057 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 9058 | SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(), |
| 9059 | gfx::PointF(1000, 1000), gfx::Size(50, 50), true, |
| 9060 | false); |
| 9061 | SetLayerPropertiesForTesting(grandchild.get(), identity_transform, |
| 9062 | gfx::Point3F(), gfx::PointF(-1000, -1000), |
| 9063 | gfx::Size(50, 50), true, false); |
| 9064 | |
| 9065 | root->SetMasksToBounds(true); |
| 9066 | root->SetIsContainerForFixedPositionLayers(true); |
| 9067 | LayerPositionConstraint constraint; |
| 9068 | constraint.set_is_fixed_position(true); |
| 9069 | grandchild->SetPositionConstraint(constraint); |
| 9070 | |
| 9071 | root->SetIsContainerForFixedPositionLayers(true); |
| 9072 | |
| 9073 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9074 | host->SetRootLayer(root); |
| 9075 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9076 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 0120eb2 | 2015-03-02 03:07:34 | [diff] [blame] | 9077 | |
| 9078 | EXPECT_EQ(gfx::Rect(0, 0, 50, 50), |
| 9079 | grandchild->visible_rect_from_property_trees()); |
| 9080 | } |
| 9081 | |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 9082 | TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) { |
| 9083 | // In the following layer tree, the layer |box|'s render target is |surface|. |
| 9084 | // |surface| also creates a transform node. We want to combine clips for |box| |
| 9085 | // in the space of its target (i.e., |surface|), not its target's target. This |
| 9086 | // test ensures that happens. |
| 9087 | |
| 9088 | gfx::Transform rotate; |
| 9089 | rotate.Rotate(5); |
| 9090 | gfx::Transform identity; |
| 9091 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9092 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 9093 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9094 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 9095 | false); |
| 9096 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9097 | scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 9098 | SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), |
| 9099 | gfx::PointF(), gfx::Size(2500, 1500), true, |
| 9100 | false); |
| 9101 | frame_clip->SetMasksToBounds(true); |
| 9102 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9103 | scoped_refptr<Layer> rotated = Layer::Create(layer_settings()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 9104 | SetLayerPropertiesForTesting(rotated.get(), rotate, |
| 9105 | gfx::Point3F(1250, 250, 0), gfx::PointF(), |
| 9106 | gfx::Size(2500, 500), true, false); |
| 9107 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9108 | scoped_refptr<Layer> surface = Layer::Create(layer_settings()); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 9109 | SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(), |
| 9110 | gfx::PointF(), gfx::Size(2500, 500), true, |
| 9111 | false); |
| 9112 | surface->SetOpacity(0.5); |
| 9113 | |
| 9114 | scoped_refptr<LayerWithForcedDrawsContent> container = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9115 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 9116 | SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(), |
| 9117 | gfx::PointF(), gfx::Size(300, 300), true, false); |
| 9118 | |
| 9119 | scoped_refptr<LayerWithForcedDrawsContent> box = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9120 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 67394b4 | 2015-03-10 00:22:30 | [diff] [blame] | 9121 | SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(), |
| 9122 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9123 | |
| 9124 | root->AddChild(frame_clip); |
| 9125 | frame_clip->AddChild(rotated); |
| 9126 | rotated->AddChild(surface); |
| 9127 | surface->AddChild(container); |
| 9128 | surface->AddChild(box); |
| 9129 | |
| 9130 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9131 | host->SetRootLayer(root); |
| 9132 | |
| 9133 | ExecuteCalculateDrawProperties(root.get()); |
| 9134 | } |
| 9135 | |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9136 | TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) { |
| 9137 | gfx::Transform identity; |
| 9138 | gfx::Transform translate_z; |
| 9139 | translate_z.Translate3d(0, 0, 10); |
| 9140 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9141 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9142 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9143 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 9144 | root->SetIsContainerForFixedPositionLayers(true); |
| 9145 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9146 | scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9147 | SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(), |
| 9148 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
| 9149 | false); |
| 9150 | frame_clip->SetMasksToBounds(true); |
| 9151 | |
| 9152 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9153 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9154 | SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(), |
| 9155 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 9156 | false); |
| 9157 | |
| 9158 | LayerPositionConstraint constraint; |
| 9159 | constraint.set_is_fixed_position(true); |
| 9160 | fixed->SetPositionConstraint(constraint); |
| 9161 | |
| 9162 | root->AddChild(frame_clip); |
| 9163 | frame_clip->AddChild(fixed); |
| 9164 | |
| 9165 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9166 | host->SetRootLayer(root); |
| 9167 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9168 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 8c82474 | 2015-03-20 22:21:08 | [diff] [blame] | 9169 | |
| 9170 | gfx::Rect expected(0, 0, 100, 100); |
| 9171 | EXPECT_EQ(expected, fixed->visible_rect_from_property_trees()); |
| 9172 | } |
| 9173 | |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 9174 | TEST_F(LayerTreeHostCommonTest, |
| 9175 | PropertyTreesAccountForScrollCompensationAdjustment) { |
| 9176 | gfx::Transform identity; |
| 9177 | gfx::Transform translate_z; |
| 9178 | translate_z.Translate3d(0, 0, 10); |
| 9179 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9180 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 9181 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9182 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 9183 | root->SetIsContainerForFixedPositionLayers(true); |
| 9184 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9185 | scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings()); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 9186 | SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(), |
| 9187 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
| 9188 | false); |
| 9189 | frame_clip->SetMasksToBounds(true); |
| 9190 | |
| 9191 | scoped_refptr<LayerWithForcedDrawsContent> scroller = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9192 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 9193 | SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(), |
| 9194 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 9195 | false); |
| 9196 | |
| 9197 | scroller->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f, 0.7f)); |
| 9198 | scroller->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7)); |
| 9199 | scroller->SetScrollClipLayerId(frame_clip->id()); |
| 9200 | |
| 9201 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9202 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 9203 | SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(), |
| 9204 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 9205 | |
| 9206 | LayerPositionConstraint constraint; |
| 9207 | constraint.set_is_fixed_position(true); |
| 9208 | fixed->SetPositionConstraint(constraint); |
| 9209 | |
| 9210 | scoped_refptr<LayerWithForcedDrawsContent> fixed_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9211 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 9212 | SetLayerPropertiesForTesting(fixed_child.get(), identity, gfx::Point3F(), |
| 9213 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 9214 | |
| 9215 | fixed_child->SetPositionConstraint(constraint); |
| 9216 | |
| 9217 | root->AddChild(frame_clip); |
| 9218 | frame_clip->AddChild(scroller); |
| 9219 | scroller->AddChild(fixed); |
| 9220 | fixed->AddChild(fixed_child); |
| 9221 | |
| 9222 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9223 | host->SetRootLayer(root); |
| 9224 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9225 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | f6281c4 | 2015-03-30 21:44:41 | [diff] [blame] | 9226 | |
| 9227 | gfx::Rect expected(0, 0, 50, 50); |
| 9228 | EXPECT_EQ(expected, fixed->visible_rect_from_property_trees()); |
| 9229 | |
| 9230 | expected = gfx::Rect(0, 0, 10, 10); |
| 9231 | EXPECT_EQ(expected, fixed_child->visible_rect_from_property_trees()); |
| 9232 | } |
| 9233 | |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 9234 | TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { |
| 9235 | gfx::Transform identity; |
| 9236 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9237 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 9238 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9239 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 9240 | root->SetIsContainerForFixedPositionLayers(true); |
| 9241 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9242 | scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 9243 | SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), |
| 9244 | gfx::PointF(500, 100), gfx::Size(100, 100), true, |
| 9245 | false); |
| 9246 | frame_clip->SetMasksToBounds(true); |
| 9247 | |
| 9248 | scoped_refptr<LayerWithForcedDrawsContent> scroller = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9249 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 9250 | SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(), |
| 9251 | gfx::PointF(), gfx::Size(1000, 1000), true, |
| 9252 | false); |
| 9253 | |
| 9254 | scroller->SetScrollOffset(gfx::ScrollOffset(100, 100)); |
| 9255 | scroller->SetScrollClipLayerId(frame_clip->id()); |
| 9256 | |
| 9257 | scoped_refptr<LayerWithForcedDrawsContent> fixed = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9258 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 9259 | SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(), |
| 9260 | gfx::PointF(100, 100), gfx::Size(50, 50), true, |
| 9261 | false); |
| 9262 | |
| 9263 | LayerPositionConstraint constraint; |
| 9264 | constraint.set_is_fixed_position(true); |
| 9265 | fixed->SetPositionConstraint(constraint); |
| 9266 | fixed->SetForceRenderSurface(true); |
| 9267 | fixed->SetMasksToBounds(true); |
| 9268 | |
| 9269 | root->AddChild(frame_clip); |
| 9270 | frame_clip->AddChild(scroller); |
| 9271 | scroller->AddChild(fixed); |
| 9272 | |
| 9273 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9274 | host->SetRootLayer(root); |
| 9275 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9276 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 06ca3e83 | 2015-03-31 19:37:12 | [diff] [blame] | 9277 | |
| 9278 | gfx::Rect expected(0, 0, 50, 50); |
| 9279 | EXPECT_EQ(expected, fixed->visible_rect_from_property_trees()); |
| 9280 | } |
| 9281 | |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 9282 | TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) { |
| 9283 | gfx::Transform identity; |
| 9284 | gfx::Transform translate; |
| 9285 | gfx::Transform rotate; |
| 9286 | |
| 9287 | translate.Translate(10, 10); |
| 9288 | rotate.Rotate(45); |
| 9289 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9290 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 9291 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9292 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 9293 | root->SetIsContainerForFixedPositionLayers(true); |
| 9294 | |
| 9295 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9296 | host->SetRootLayer(root); |
| 9297 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9298 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9299 | EXPECT_FALSE(host->property_trees()->needs_rebuild); |
vollick | 5057e1e | 2015-04-17 19:12:32 | [diff] [blame] | 9300 | |
| 9301 | root->SetTransform(translate); |
| 9302 | EXPECT_FALSE(host->property_trees()->needs_rebuild); |
| 9303 | |
| 9304 | root->SetTransform(rotate); |
| 9305 | EXPECT_TRUE(host->property_trees()->needs_rebuild); |
| 9306 | } |
| 9307 | |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 9308 | TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9309 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 9310 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9311 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 9312 | root->AddChild(child); |
| 9313 | |
| 9314 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9315 | host->SetRootLayer(root); |
| 9316 | |
| 9317 | gfx::Transform identity_matrix; |
| 9318 | gfx::Transform scale_matrix; |
| 9319 | scale_matrix.Scale(2.f, 2.f); |
| 9320 | SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 9321 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9322 | SetLayerPropertiesForTesting(child.get(), scale_matrix, gfx::Point3F(), |
| 9323 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 9324 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9325 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 9326 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees()); |
| 9327 | |
| 9328 | child->SetTransformOrigin(gfx::Point3F(10.f, 10.f, 10.f)); |
| 9329 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9330 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | b0e0c1c | 2015-04-23 00:29:23 | [diff] [blame] | 9331 | EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_rect_from_property_trees()); |
| 9332 | } |
| 9333 | |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 9334 | TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) { |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9335 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 9336 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9337 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 9338 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9339 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 9340 | |
| 9341 | root->AddChild(scroll_child); |
| 9342 | root->AddChild(scroll_parent); |
| 9343 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 9344 | scroll_parent->SetScrollClipLayerId(root->id()); |
| 9345 | |
| 9346 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9347 | host->SetRootLayer(root); |
| 9348 | |
| 9349 | gfx::Transform identity_transform; |
| 9350 | gfx::Transform scale; |
| 9351 | scale.Scale(2.f, 2.f); |
| 9352 | SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), |
| 9353 | gfx::PointF(), gfx::Size(50, 50), true, false); |
| 9354 | SetLayerPropertiesForTesting(scroll_child.get(), scale, gfx::Point3F(), |
| 9355 | gfx::PointF(), gfx::Size(40, 40), true, false); |
| 9356 | SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform, |
| 9357 | gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), |
| 9358 | true, false); |
| 9359 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9360 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 9361 | EXPECT_EQ(gfx::Rect(25, 25), |
| 9362 | scroll_child->visible_rect_from_property_trees()); |
| 9363 | |
| 9364 | scroll_child->SetPosition(gfx::PointF(0, -10.f)); |
| 9365 | scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f)); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9366 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
ajuma | f09db896 | 2015-04-24 21:55:34 | [diff] [blame] | 9367 | EXPECT_EQ(gfx::Rect(0, 5, 25, 25), |
| 9368 | scroll_child->visible_rect_from_property_trees()); |
| 9369 | } |
| 9370 | |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9371 | static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
| 9372 | } |
| 9373 | |
| 9374 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { |
| 9375 | gfx::Transform identity; |
| 9376 | FakeContentLayerClient client; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9377 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9378 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9379 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9380 | scoped_refptr<LayerWithForcedDrawsContent> grandchild = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9381 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9382 | scoped_refptr<FakeContentLayer> greatgrandchild( |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9383 | FakeContentLayer::Create(layer_settings(), &client)); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9384 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9385 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9386 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9387 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 9388 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 9389 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 9390 | SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(), |
| 9391 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 9392 | |
| 9393 | root->AddChild(child); |
| 9394 | child->AddChild(grandchild); |
| 9395 | grandchild->AddChild(greatgrandchild); |
| 9396 | |
| 9397 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9398 | host->SetRootLayer(root); |
| 9399 | |
| 9400 | // Check the non-skipped case. |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9401 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9402 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees()); |
| 9403 | |
| 9404 | // Now we will reset the visible rect from property trees for the grandchild, |
| 9405 | // and we will configure |child| in several ways that should force the subtree |
| 9406 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 9407 | // remain empty. |
| 9408 | grandchild->set_visible_rect_from_property_trees(gfx::Rect()); |
| 9409 | gfx::Transform singular; |
| 9410 | singular.matrix().set(0, 0, 0); |
| 9411 | |
| 9412 | child->SetTransform(singular); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9413 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9414 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees()); |
| 9415 | child->SetTransform(identity); |
| 9416 | |
| 9417 | child->SetHideLayerAndSubtree(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9418 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9419 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees()); |
| 9420 | child->SetHideLayerAndSubtree(false); |
| 9421 | |
| 9422 | child->SetOpacity(0.f); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9423 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9424 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees()); |
| 9425 | |
| 9426 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 9427 | // |greatgrandchild| in several ways that should force the subtree to be |
| 9428 | // processed anyhow. |
| 9429 | grandchild->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10))); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9430 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9431 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees()); |
| 9432 | grandchild->set_visible_rect_from_property_trees(gfx::Rect()); |
| 9433 | grandchild->SetTouchEventHandlerRegion(Region()); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9434 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9435 | EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees()); |
| 9436 | grandchild->set_visible_rect_from_property_trees(gfx::Rect()); |
| 9437 | |
| 9438 | greatgrandchild->RequestCopyOfOutput( |
| 9439 | CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback))); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9440 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9441 | EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees()); |
| 9442 | } |
| 9443 | |
| 9444 | TEST_F(LayerTreeHostCommonTest, SkippingSubtreeImpl) { |
| 9445 | FakeImplProxy proxy; |
| 9446 | TestSharedBitmapManager shared_bitmap_manager; |
| 9447 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr); |
| 9448 | |
| 9449 | gfx::Transform identity; |
| 9450 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 9451 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2); |
| 9452 | scoped_ptr<LayerImpl> grandchild = |
| 9453 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 9454 | |
| 9455 | scoped_ptr<FakeContentLayerImpl> greatgrandchild( |
| 9456 | FakeContentLayerImpl::Create(host_impl.active_tree(), 4)); |
| 9457 | |
| 9458 | child->SetDrawsContent(true); |
| 9459 | grandchild->SetDrawsContent(true); |
| 9460 | greatgrandchild->SetDrawsContent(true); |
| 9461 | |
| 9462 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9463 | gfx::PointF(), gfx::Size(100, 100), true, false, |
| 9464 | true); |
| 9465 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9466 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 9467 | false); |
| 9468 | SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(), |
| 9469 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 9470 | false); |
| 9471 | SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(), |
| 9472 | gfx::PointF(), gfx::Size(10, 10), true, false, |
| 9473 | true); |
| 9474 | |
| 9475 | LayerImpl* child_ptr = child.get(); |
| 9476 | LayerImpl* grandchild_ptr = grandchild.get(); |
| 9477 | LayerImpl* greatgrandchild_ptr = greatgrandchild.get(); |
| 9478 | |
| 9479 | grandchild->AddChild(greatgrandchild.Pass()); |
| 9480 | child->AddChild(grandchild.Pass()); |
| 9481 | root->AddChild(child.Pass()); |
| 9482 | |
| 9483 | // Check the non-skipped case. |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9484 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9485 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9486 | grandchild_ptr->visible_rect_from_property_trees()); |
| 9487 | |
| 9488 | // Now we will reset the visible rect from property trees for the grandchild, |
| 9489 | // and we will configure |child| in several ways that should force the subtree |
| 9490 | // to be skipped. The visible content rect for |grandchild| should, therefore, |
| 9491 | // remain empty. |
| 9492 | grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect()); |
| 9493 | gfx::Transform singular; |
| 9494 | singular.matrix().set(0, 0, 0); |
| 9495 | |
| 9496 | child_ptr->SetTransform(singular); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9497 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9498 | EXPECT_EQ(gfx::Rect(0, 0), |
| 9499 | grandchild_ptr->visible_rect_from_property_trees()); |
| 9500 | child_ptr->SetTransform(identity); |
| 9501 | |
| 9502 | child_ptr->SetHideLayerAndSubtree(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9503 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9504 | EXPECT_EQ(gfx::Rect(0, 0), |
| 9505 | grandchild_ptr->visible_rect_from_property_trees()); |
| 9506 | child_ptr->SetHideLayerAndSubtree(false); |
| 9507 | |
| 9508 | child_ptr->SetOpacity(0.f); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9509 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9510 | EXPECT_EQ(gfx::Rect(0, 0), |
| 9511 | grandchild_ptr->visible_rect_from_property_trees()); |
| 9512 | |
| 9513 | // Now, even though child has zero opacity, we will configure |grandchild| and |
| 9514 | // |greatgrandchild| in several ways that should force the subtree to be |
| 9515 | // processed anyhow. |
| 9516 | grandchild_ptr->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10))); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9517 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9518 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9519 | grandchild_ptr->visible_rect_from_property_trees()); |
| 9520 | grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect()); |
| 9521 | grandchild_ptr->SetTouchEventHandlerRegion(Region()); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9522 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9523 | EXPECT_EQ(gfx::Rect(0, 0), |
| 9524 | grandchild_ptr->visible_rect_from_property_trees()); |
| 9525 | grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect()); |
| 9526 | |
| 9527 | ScopedPtrVector<CopyOutputRequest> requests; |
| 9528 | requests.push_back(CopyOutputRequest::CreateEmptyRequest()); |
| 9529 | |
| 9530 | greatgrandchild_ptr->PassCopyRequests(&requests); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9531 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9532 | EXPECT_EQ(gfx::Rect(10, 10), |
| 9533 | grandchild_ptr->visible_rect_from_property_trees()); |
| 9534 | } |
| 9535 | |
| 9536 | TEST_F(LayerTreeHostCommonTest, SkippingLayer) { |
| 9537 | gfx::Transform identity; |
| 9538 | FakeContentLayerClient client; |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9539 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9540 | scoped_refptr<LayerWithForcedDrawsContent> child = |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9541 | make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9542 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9543 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9544 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9545 | gfx::PointF(), gfx::Size(10, 10), true, false); |
| 9546 | root->AddChild(child); |
| 9547 | |
| 9548 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9549 | host->SetRootLayer(root); |
| 9550 | |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9551 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9552 | EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees()); |
| 9553 | child->set_visible_rect_from_property_trees(gfx::Rect()); |
| 9554 | |
| 9555 | child->SetHideLayerAndSubtree(true); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9556 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9557 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees()); |
| 9558 | child->SetHideLayerAndSubtree(false); |
| 9559 | |
| 9560 | child->SetBounds(gfx::Size()); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9561 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9562 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees()); |
| 9563 | child->SetBounds(gfx::Size(10, 10)); |
| 9564 | |
| 9565 | gfx::Transform rotate; |
| 9566 | child->SetDoubleSided(false); |
| 9567 | rotate.RotateAboutXAxis(180.f); |
| 9568 | child->SetTransform(rotate); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9569 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9570 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees()); |
| 9571 | child->SetDoubleSided(true); |
| 9572 | child->SetTransform(identity); |
| 9573 | |
| 9574 | child->SetOpacity(0.f); |
enne | 601f2ef1 | 2015-05-19 18:20:17 | [diff] [blame] | 9575 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
vollick | 2175fae8 | 2015-04-27 21:18:12 | [diff] [blame] | 9576 | EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees()); |
| 9577 | } |
| 9578 | |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9579 | TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) { |
| 9580 | // Ensure that the treewalk in LayerTreeHostCommom:: |
| 9581 | // PreCalculateMetaInformation happens when its required. |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9582 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 9583 | scoped_refptr<Layer> parent = Layer::Create(layer_settings()); |
| 9584 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9585 | |
| 9586 | root->AddChild(parent); |
| 9587 | parent->AddChild(child); |
| 9588 | |
| 9589 | child->SetClipParent(root.get()); |
| 9590 | |
| 9591 | gfx::Transform identity; |
| 9592 | |
| 9593 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9594 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9595 | SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(), |
| 9596 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9597 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9598 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9599 | |
| 9600 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9601 | host->SetRootLayer(root); |
| 9602 | |
| 9603 | ExecuteCalculateDrawProperties(root.get()); |
| 9604 | EXPECT_EQ(parent->draw_properties().num_unclipped_descendants, 1); |
| 9605 | |
| 9606 | // Ensure the dynamic update to input handlers happens. |
| 9607 | child->SetHaveWheelEventHandlers(true); |
| 9608 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_input_handler); |
| 9609 | ExecuteCalculateDrawProperties(root.get()); |
| 9610 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_input_handler); |
| 9611 | |
| 9612 | child->SetHaveWheelEventHandlers(false); |
| 9613 | EXPECT_FALSE(root->draw_properties().layer_or_descendant_has_input_handler); |
| 9614 | ExecuteCalculateDrawProperties(root.get()); |
| 9615 | EXPECT_FALSE(root->draw_properties().layer_or_descendant_has_input_handler); |
| 9616 | |
| 9617 | child->RequestCopyOfOutput( |
| 9618 | CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback))); |
| 9619 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request); |
| 9620 | ExecuteCalculateDrawProperties(root.get()); |
| 9621 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request); |
| 9622 | } |
| 9623 | |
| 9624 | TEST_F(LayerTreeHostCommonTest, InputHandlersRecursiveUpdateTest) { |
| 9625 | // Ensure that the treewalk in LayertreeHostCommon:: |
| 9626 | // PreCalculateMetaInformation updates input handlers correctly. |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9627 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 9628 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
jaydasika | 3d10aa6 | 2015-05-06 17:50:44 | [diff] [blame] | 9629 | |
| 9630 | root->AddChild(child); |
| 9631 | |
| 9632 | child->SetHaveWheelEventHandlers(true); |
| 9633 | |
| 9634 | gfx::Transform identity; |
| 9635 | |
| 9636 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9637 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9638 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9639 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9640 | |
| 9641 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9642 | host->SetRootLayer(root); |
| 9643 | |
| 9644 | EXPECT_EQ(root->num_layer_or_descendants_with_input_handler(), 0); |
| 9645 | ExecuteCalculateDrawProperties(root.get()); |
| 9646 | EXPECT_EQ(root->num_layer_or_descendants_with_input_handler(), 1); |
| 9647 | child->SetHaveWheelEventHandlers(false); |
| 9648 | EXPECT_EQ(root->num_layer_or_descendants_with_input_handler(), 0); |
| 9649 | } |
| 9650 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9651 | TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) { |
| 9652 | gfx::Transform identity; |
| 9653 | gfx::Transform translate_z; |
| 9654 | translate_z.Translate3d(0, 0, 10); |
| 9655 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9656 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9657 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9658 | gfx::PointF(), gfx::Size(800, 800), true, false); |
| 9659 | |
loyso | a6edaaff | 2015-05-25 03:26:44 | [diff] [blame] | 9660 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 9661 | SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(), |
| 9662 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9663 | |
| 9664 | root->AddChild(child); |
| 9665 | |
| 9666 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9667 | host->SetRootLayer(root); |
| 9668 | |
| 9669 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9670 | EXPECT_NE(-1, child->transform_tree_index()); |
| 9671 | |
| 9672 | child->RemoveFromParent(); |
| 9673 | |
| 9674 | ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9675 | EXPECT_EQ(-1, child->transform_tree_index()); |
| 9676 | } |
| 9677 | |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 9678 | TEST_F(LayerTreeHostCommonTest, ResetLayerDrawPropertiestest) { |
| 9679 | scoped_refptr<Layer> root = Layer::Create(layer_settings()); |
| 9680 | scoped_refptr<Layer> child = Layer::Create(layer_settings()); |
| 9681 | |
| 9682 | root->AddChild(child); |
| 9683 | gfx::Transform identity; |
| 9684 | |
| 9685 | SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 9686 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9687 | SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(), |
| 9688 | gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9689 | |
| 9690 | scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 9691 | host->SetRootLayer(root); |
| 9692 | |
| 9693 | EXPECT_FALSE(root->layer_or_descendant_is_drawn()); |
| 9694 | EXPECT_FALSE(root->visited()); |
| 9695 | EXPECT_FALSE(root->sorted_for_recursion()); |
| 9696 | EXPECT_FALSE(child->layer_or_descendant_is_drawn()); |
| 9697 | EXPECT_FALSE(child->visited()); |
| 9698 | EXPECT_FALSE(child->sorted_for_recursion()); |
| 9699 | |
| 9700 | root->set_layer_or_descendant_is_drawn(true); |
| 9701 | root->set_visited(true); |
| 9702 | root->set_sorted_for_recursion(true); |
| 9703 | child->set_layer_or_descendant_is_drawn(true); |
| 9704 | child->set_visited(true); |
| 9705 | child->set_sorted_for_recursion(true); |
| 9706 | |
| 9707 | LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root.get()); |
| 9708 | |
| 9709 | EXPECT_FALSE(root->layer_or_descendant_is_drawn()); |
| 9710 | EXPECT_FALSE(root->visited()); |
| 9711 | EXPECT_FALSE(root->sorted_for_recursion()); |
| 9712 | EXPECT_FALSE(child->layer_or_descendant_is_drawn()); |
| 9713 | EXPECT_FALSE(child->visited()); |
| 9714 | EXPECT_FALSE(child->sorted_for_recursion()); |
| 9715 | } |
| 9716 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 9717 | } // namespace |
| 9718 | } // namespace cc |