[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 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7 | #include <set> |
| 8 | |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 9 | #include "cc/animation/layer_animation_controller.h" |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 10 | #include "cc/animation/transform_operations.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 11 | #include "cc/base/math_util.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 12 | #include "cc/layers/content_layer.h" |
| 13 | #include "cc/layers/content_layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 14 | #include "cc/layers/layer.h" |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 15 | #include "cc/layers/layer_client.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 16 | #include "cc/layers/layer_impl.h" |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 17 | #include "cc/layers/layer_iterator.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 18 | #include "cc/layers/render_surface.h" |
| 19 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 20 | #include "cc/output/copy_output_request.h" |
| 21 | #include "cc/output/copy_output_result.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 22 | #include "cc/test/animation_test_common.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 23 | #include "cc/test/fake_impl_proxy.h" |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 24 | #include "cc/test/fake_layer_tree_host.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame] | 25 | #include "cc/test/fake_layer_tree_host_impl.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 26 | #include "cc/test/geometry_test_utils.h" |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 27 | #include "cc/test/layer_tree_host_common_test.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 28 | #include "cc/trees/layer_tree_impl.h" |
| 29 | #include "cc/trees/proxy.h" |
| 30 | #include "cc/trees/single_thread_proxy.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 31 | #include "testing/gmock/include/gmock/gmock.h" |
| 32 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 93698c1 | 2012-12-07 00:43:56 | [diff] [blame] | 33 | #include "ui/gfx/quad_f.h" |
[email protected] | c8686a0 | 2012-11-27 08:29:00 | [diff] [blame] | 34 | #include "ui/gfx/transform.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 35 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 36 | namespace cc { |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 37 | namespace { |
| 38 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 39 | class LayerWithForcedDrawsContent : public Layer { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 40 | public: |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 41 | LayerWithForcedDrawsContent() : Layer(), last_device_scale_factor_(0.f) {} |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 42 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 43 | virtual bool DrawsContent() const OVERRIDE; |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 44 | virtual void CalculateContentsScale(float ideal_contents_scale, |
| 45 | float device_scale_factor, |
| 46 | float page_scale_factor, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 47 | float maximum_animation_contents_scale, |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 48 | bool animating_transform_to_screen, |
| 49 | float* contents_scale_x, |
| 50 | float* contents_scale_y, |
| 51 | gfx::Size* content_bounds) OVERRIDE; |
| 52 | |
| 53 | float last_device_scale_factor() const { return last_device_scale_factor_; } |
[email protected] | d58499a | 2012-10-09 22:27:47 | [diff] [blame] | 54 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 55 | private: |
| 56 | virtual ~LayerWithForcedDrawsContent() {} |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 57 | |
| 58 | // Parameters from last CalculateContentsScale. |
| 59 | float last_device_scale_factor_; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 60 | }; |
| 61 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 62 | bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 63 | |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 64 | void LayerWithForcedDrawsContent::CalculateContentsScale( |
| 65 | float ideal_contents_scale, |
| 66 | float device_scale_factor, |
| 67 | float page_scale_factor, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 68 | float maximum_animation_contents_scale, |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 69 | bool animating_transform_to_screen, |
| 70 | float* contents_scale_x, |
| 71 | float* contents_scale_y, |
| 72 | gfx::Size* content_bounds) { |
| 73 | last_device_scale_factor_ = device_scale_factor; |
| 74 | Layer::CalculateContentsScale(ideal_contents_scale, |
| 75 | device_scale_factor, |
| 76 | page_scale_factor, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 77 | maximum_animation_contents_scale, |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 78 | animating_transform_to_screen, |
| 79 | contents_scale_x, |
| 80 | contents_scale_y, |
| 81 | content_bounds); |
| 82 | } |
| 83 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 84 | class MockContentLayerClient : public ContentLayerClient { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 85 | public: |
| 86 | MockContentLayerClient() {} |
| 87 | virtual ~MockContentLayerClient() {} |
[email protected] | 276172b | 2014-05-02 21:03:03 | [diff] [blame] | 88 | virtual void PaintContents( |
| 89 | SkCanvas* canvas, |
| 90 | const gfx::Rect& clip, |
| 91 | gfx::RectF* opaque, |
| 92 | ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {} |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 93 | virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} |
[email protected] | 1d96e03 | 2014-03-25 05:59:08 | [diff] [blame] | 94 | virtual bool FillsBoundsCompletely() const OVERRIDE { return false; } |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 95 | }; |
| 96 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 97 | scoped_refptr<ContentLayer> CreateDrawableContentLayer( |
| 98 | ContentLayerClient* delegate) { |
| 99 | scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate); |
| 100 | to_return->SetIsDrawable(true); |
| 101 | return to_return; |
[email protected] | f34a2423 | 2012-09-20 22:59:55 | [diff] [blame] | 102 | } |
| 103 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 104 | #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \ |
| 105 | do { \ |
| 106 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \ |
| 107 | EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \ |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 108 | } while (false) |
| 109 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 110 | TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 111 | // Sanity check: For layers positioned at zero, with zero size, |
| 112 | // and with identity transforms, then the draw transform, |
| 113 | // screen space transform, and the hierarchy passed on to children |
| 114 | // layers should also be identity transforms. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 115 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 116 | scoped_refptr<Layer> parent = Layer::Create(); |
| 117 | scoped_refptr<Layer> child = Layer::Create(); |
| 118 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 119 | parent->AddChild(child); |
| 120 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 121 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 122 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 123 | host->SetRootLayer(parent); |
| 124 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 125 | gfx::Transform identity_matrix; |
| 126 | SetLayerPropertiesForTesting(parent.get(), |
| 127 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 128 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 129 | gfx::PointF(), |
| 130 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 131 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 132 | false); |
| 133 | SetLayerPropertiesForTesting(child.get(), |
| 134 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 135 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 136 | gfx::PointF(), |
| 137 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 138 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 139 | false); |
| 140 | SetLayerPropertiesForTesting(grand_child.get(), |
| 141 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 142 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 143 | gfx::PointF(), |
| 144 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 145 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 146 | false); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 147 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 148 | ExecuteCalculateDrawProperties(parent.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 149 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 150 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 151 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 152 | child->screen_space_transform()); |
| 153 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 154 | grand_child->draw_transform()); |
| 155 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 156 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 157 | } |
| 158 | |
[email protected] | f9e5670 | 2014-06-13 01:19:59 | [diff] [blame] | 159 | TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) { |
| 160 | scoped_refptr<Layer> parent = Layer::Create(); |
| 161 | scoped_refptr<Layer> child = Layer::Create(); |
| 162 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 163 | parent->AddChild(child); |
| 164 | child->AddChild(grand_child); |
| 165 | |
| 166 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 167 | host->SetRootLayer(parent); |
| 168 | |
| 169 | gfx::Transform identity_matrix; |
| 170 | SetLayerPropertiesForTesting(parent.get(), |
| 171 | identity_matrix, |
| 172 | gfx::Point3F(), |
| 173 | gfx::PointF(), |
| 174 | gfx::Size(100, 100), |
| 175 | true, |
| 176 | false); |
| 177 | SetLayerPropertiesForTesting(child.get(), |
| 178 | identity_matrix, |
| 179 | gfx::Point3F(), |
| 180 | gfx::PointF(10, 10), |
| 181 | gfx::Size(100, 100), |
| 182 | true, |
| 183 | false); |
| 184 | // This would have previously caused us to skip our subtree, but this would be |
| 185 | // wrong; we need up-to-date draw properties to do hit testing on the layers |
| 186 | // with handlers. |
| 187 | child->SetOpacity(0.f); |
| 188 | SetLayerPropertiesForTesting(grand_child.get(), |
| 189 | identity_matrix, |
| 190 | gfx::Point3F(), |
| 191 | gfx::PointF(10, 10), |
| 192 | gfx::Size(100, 100), |
| 193 | true, |
| 194 | false); |
| 195 | grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100)); |
| 196 | |
| 197 | ExecuteCalculateDrawProperties(parent.get()); |
| 198 | |
| 199 | // Check that we've computed draw properties for the subtree rooted at |
| 200 | // |child|. |
| 201 | EXPECT_FALSE(child->draw_transform().IsIdentity()); |
| 202 | EXPECT_FALSE(grand_child->draw_transform().IsIdentity()); |
| 203 | } |
| 204 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 205 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 206 | gfx::Transform identity_matrix; |
| 207 | scoped_refptr<Layer> layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 208 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 209 | scoped_refptr<Layer> root = Layer::Create(); |
| 210 | SetLayerPropertiesForTesting(root.get(), |
| 211 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 212 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 213 | gfx::PointF(), |
| 214 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 215 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 216 | false); |
| 217 | root->AddChild(layer); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 218 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 219 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 220 | host->SetRootLayer(root); |
| 221 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 222 | // Case 2: Setting the bounds of the layer should not affect either the draw |
| 223 | // transform or the screenspace transform. |
| 224 | gfx::Transform translation_to_center; |
| 225 | translation_to_center.Translate(5.0, 6.0); |
| 226 | SetLayerPropertiesForTesting(layer.get(), |
| 227 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 228 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 229 | gfx::PointF(), |
| 230 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 231 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 232 | false); |
| 233 | ExecuteCalculateDrawProperties(root.get()); |
| 234 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 235 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 236 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 237 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 238 | // Case 3: The anchor point by itself (without a layer transform) should have |
| 239 | // no effect on the transforms. |
| 240 | SetLayerPropertiesForTesting(layer.get(), |
| 241 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 242 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 243 | gfx::PointF(), |
| 244 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 245 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 246 | false); |
| 247 | ExecuteCalculateDrawProperties(root.get()); |
| 248 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform()); |
| 249 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 250 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 251 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 252 | // Case 4: A change in actual position affects both the draw transform and |
| 253 | // screen space transform. |
| 254 | gfx::Transform position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 255 | position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 256 | SetLayerPropertiesForTesting(layer.get(), |
| 257 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 258 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 259 | gfx::PointF(0.f, 1.2f), |
| 260 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 261 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 262 | false); |
| 263 | ExecuteCalculateDrawProperties(root.get()); |
| 264 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform()); |
| 265 | EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, |
| 266 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 267 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 268 | // Case 5: In the correct sequence of transforms, the layer transform should |
| 269 | // pre-multiply the translation_to_center. This is easily tested by using a |
| 270 | // scale transform, because scale and translation are not commutative. |
| 271 | gfx::Transform layer_transform; |
| 272 | layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 273 | SetLayerPropertiesForTesting(layer.get(), |
| 274 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 275 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 276 | gfx::PointF(), |
| 277 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 278 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 279 | false); |
| 280 | ExecuteCalculateDrawProperties(root.get()); |
| 281 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform()); |
| 282 | EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, |
| 283 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 284 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 285 | // Case 6: The layer transform should occur with respect to the anchor point. |
| 286 | gfx::Transform translation_to_anchor; |
| 287 | translation_to_anchor.Translate(5.0, 0.0); |
| 288 | gfx::Transform expected_result = |
| 289 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
| 290 | SetLayerPropertiesForTesting(layer.get(), |
| 291 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 292 | gfx::Point3F(5.0f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 293 | gfx::PointF(), |
| 294 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 295 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 296 | false); |
| 297 | ExecuteCalculateDrawProperties(root.get()); |
| 298 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 299 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 300 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 301 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 302 | // Case 7: Verify that position pre-multiplies the layer transform. The |
| 303 | // current implementation of CalculateDrawProperties does this implicitly, but |
| 304 | // it is still worth testing to detect accidental regressions. |
| 305 | expected_result = position_transform * translation_to_anchor * |
| 306 | layer_transform * Inverse(translation_to_anchor); |
| 307 | SetLayerPropertiesForTesting(layer.get(), |
| 308 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 309 | gfx::Point3F(5.0f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 310 | gfx::PointF(0.f, 1.2f), |
| 311 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 312 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 313 | false); |
| 314 | ExecuteCalculateDrawProperties(root.get()); |
| 315 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform()); |
| 316 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, |
| 317 | layer->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 318 | } |
| 319 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 320 | TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 321 | const gfx::Vector2d kScrollOffset(50, 100); |
| 322 | const gfx::Vector2dF kScrollDelta(2.34f, 5.67f); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 323 | const gfx::Vector2d kMaxScrollOffset(200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 324 | const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(), |
| 325 | -kScrollOffset.y()); |
| 326 | const float kPageScale = 0.888f; |
| 327 | const float kDeviceScale = 1.666f; |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 328 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 329 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 330 | TestSharedBitmapManager shared_bitmap_manager; |
| 331 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 332 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 333 | gfx::Transform identity_matrix; |
| 334 | scoped_ptr<LayerImpl> sublayer_scoped_ptr( |
| 335 | LayerImpl::Create(host_impl.active_tree(), 1)); |
| 336 | LayerImpl* sublayer = sublayer_scoped_ptr.get(); |
| 337 | sublayer->SetContentsScale(kPageScale * kDeviceScale, |
| 338 | kPageScale * kDeviceScale); |
| 339 | SetLayerPropertiesForTesting(sublayer, |
| 340 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 341 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 342 | gfx::PointF(), |
| 343 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 344 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 345 | false); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 346 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 347 | scoped_ptr<LayerImpl> scroll_layer_scoped_ptr( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 348 | LayerImpl::Create(host_impl.active_tree(), 2)); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 349 | LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get(); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 350 | SetLayerPropertiesForTesting(scroll_layer, |
| 351 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 352 | gfx::Point3F(), |
[email protected] | 4ec78f8 | 2013-07-11 18:45:47 | [diff] [blame] | 353 | gfx::PointF(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 354 | gfx::Size(10, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 355 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 356 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 357 | scoped_ptr<LayerImpl> clip_layer_scoped_ptr( |
| 358 | LayerImpl::Create(host_impl.active_tree(), 4)); |
| 359 | LayerImpl* clip_layer = clip_layer_scoped_ptr.get(); |
| 360 | |
| 361 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
| 362 | clip_layer->SetBounds( |
| 363 | gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(), |
| 364 | scroll_layer->bounds().height() + kMaxScrollOffset.y())); |
| 365 | scroll_layer->SetScrollClipLayer(clip_layer->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 366 | scroll_layer->SetScrollDelta(kScrollDelta); |
| 367 | gfx::Transform impl_transform; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 368 | scroll_layer->AddChild(sublayer_scoped_ptr.Pass()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 369 | LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get(); |
| 370 | clip_layer->AddChild(scroll_layer_scoped_ptr.Pass()); |
| 371 | scroll_layer_raw_ptr->SetScrollOffset(kScrollOffset); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 372 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 373 | scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3)); |
| 374 | SetLayerPropertiesForTesting(root.get(), |
| 375 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 376 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 377 | gfx::PointF(), |
| 378 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 379 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 380 | false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 381 | root->AddChild(clip_layer_scoped_ptr.Pass()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 382 | |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 383 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 384 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 385 | gfx::Transform expected_transform = identity_matrix; |
| 386 | gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; |
| 387 | sub_layer_screen_position.Scale(kPageScale * kDeviceScale); |
| 388 | expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()), |
| 389 | MathUtil::Round(sub_layer_screen_position.y())); |
| 390 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 391 | sublayer->draw_transform()); |
| 392 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 393 | sublayer->screen_space_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 394 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 395 | gfx::Transform arbitrary_translate; |
| 396 | const float kTranslateX = 10.6f; |
| 397 | const float kTranslateY = 20.6f; |
| 398 | arbitrary_translate.Translate(kTranslateX, kTranslateY); |
| 399 | SetLayerPropertiesForTesting(scroll_layer, |
| 400 | arbitrary_translate, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 401 | gfx::Point3F(), |
[email protected] | 4ec78f8 | 2013-07-11 18:45:47 | [diff] [blame] | 402 | gfx::PointF(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 403 | gfx::Size(10, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 404 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 405 | false); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 406 | ExecuteCalculateDrawProperties( |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 407 | root.get(), kDeviceScale, kPageScale, scroll_layer->parent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 408 | expected_transform.MakeIdentity(); |
| 409 | expected_transform.Translate( |
| 410 | MathUtil::Round(kTranslateX * kPageScale * kDeviceScale + |
| 411 | sub_layer_screen_position.x()), |
| 412 | MathUtil::Round(kTranslateY * kPageScale * kDeviceScale + |
| 413 | sub_layer_screen_position.y())); |
| 414 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 415 | sublayer->draw_transform()); |
[email protected] | 657b24c | 2013-03-06 09:01:20 | [diff] [blame] | 416 | } |
| 417 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 418 | TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 419 | gfx::Transform identity_matrix; |
| 420 | scoped_refptr<Layer> root = Layer::Create(); |
| 421 | scoped_refptr<Layer> parent = Layer::Create(); |
| 422 | scoped_refptr<Layer> child = Layer::Create(); |
| 423 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 424 | root->AddChild(parent); |
| 425 | parent->AddChild(child); |
| 426 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 427 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 428 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 429 | host->SetRootLayer(root); |
| 430 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 431 | // One-time setup of root layer |
| 432 | SetLayerPropertiesForTesting(root.get(), |
| 433 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 434 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 435 | gfx::PointF(), |
| 436 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 437 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 438 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 439 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 440 | // Case 1: parent's anchor point should not affect child or grand_child. |
| 441 | SetLayerPropertiesForTesting(parent.get(), |
| 442 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 443 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 444 | gfx::PointF(), |
| 445 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 446 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 447 | false); |
| 448 | SetLayerPropertiesForTesting(child.get(), |
| 449 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 450 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 451 | gfx::PointF(), |
| 452 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 453 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 454 | false); |
| 455 | SetLayerPropertiesForTesting(grand_child.get(), |
| 456 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 457 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 458 | gfx::PointF(), |
| 459 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 460 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 461 | false); |
| 462 | ExecuteCalculateDrawProperties(root.get()); |
| 463 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 464 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 465 | child->screen_space_transform()); |
| 466 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 467 | grand_child->draw_transform()); |
| 468 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 469 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 470 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 471 | // Case 2: parent's position affects child and grand_child. |
| 472 | gfx::Transform parent_position_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 473 | parent_position_transform.Translate(0.f, 1.2f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 474 | SetLayerPropertiesForTesting(parent.get(), |
| 475 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 476 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 477 | gfx::PointF(0.f, 1.2f), |
| 478 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 479 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 480 | false); |
| 481 | SetLayerPropertiesForTesting(child.get(), |
| 482 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 483 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 484 | gfx::PointF(), |
| 485 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 486 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 487 | false); |
| 488 | SetLayerPropertiesForTesting(grand_child.get(), |
| 489 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 490 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 491 | gfx::PointF(), |
| 492 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 493 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 494 | false); |
| 495 | ExecuteCalculateDrawProperties(root.get()); |
| 496 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 497 | child->draw_transform()); |
| 498 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 499 | child->screen_space_transform()); |
| 500 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 501 | grand_child->draw_transform()); |
| 502 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform, |
| 503 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 504 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 505 | // Case 3: parent's local transform affects child and grandchild |
| 506 | gfx::Transform parent_layer_transform; |
| 507 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 508 | gfx::Transform parent_translation_to_anchor; |
| 509 | parent_translation_to_anchor.Translate(2.5, 3.0); |
| 510 | gfx::Transform parent_composite_transform = |
| 511 | parent_translation_to_anchor * parent_layer_transform * |
| 512 | Inverse(parent_translation_to_anchor); |
| 513 | SetLayerPropertiesForTesting(parent.get(), |
| 514 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 515 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 516 | gfx::PointF(), |
| 517 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 518 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 519 | false); |
| 520 | SetLayerPropertiesForTesting(child.get(), |
| 521 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 522 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 523 | gfx::PointF(), |
| 524 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 525 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 526 | false); |
| 527 | SetLayerPropertiesForTesting(grand_child.get(), |
| 528 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 529 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 530 | gfx::PointF(), |
| 531 | gfx::Size(76, 78), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 532 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 533 | false); |
| 534 | ExecuteCalculateDrawProperties(root.get()); |
| 535 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 536 | child->draw_transform()); |
| 537 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 538 | child->screen_space_transform()); |
| 539 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 540 | grand_child->draw_transform()); |
| 541 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 542 | grand_child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 543 | } |
| 544 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 545 | TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 546 | scoped_refptr<Layer> root = Layer::Create(); |
| 547 | scoped_refptr<Layer> parent = Layer::Create(); |
| 548 | scoped_refptr<Layer> child = Layer::Create(); |
| 549 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 550 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 551 | root->AddChild(parent); |
| 552 | parent->AddChild(child); |
| 553 | child->AddChild(grand_child); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 554 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 555 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 556 | host->SetRootLayer(root); |
| 557 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 558 | // One-time setup of root layer |
| 559 | gfx::Transform identity_matrix; |
| 560 | SetLayerPropertiesForTesting(root.get(), |
| 561 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 562 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 563 | gfx::PointF(), |
| 564 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 565 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 566 | false); |
[email protected] | ecc1262 | 2012-10-30 20:45:42 | [diff] [blame] | 567 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 568 | // Child is set up so that a new render surface should be created. |
| 569 | child->SetOpacity(0.5f); |
| 570 | child->SetForceRenderSurface(true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 571 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 572 | gfx::Transform parent_layer_transform; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 573 | parent_layer_transform.Scale3d(1.f, 0.9f, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 574 | gfx::Transform parent_translation_to_anchor; |
| 575 | parent_translation_to_anchor.Translate(25.0, 30.0); |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 576 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 577 | gfx::Transform parent_composite_transform = |
| 578 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 579 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 580 | gfx::Vector2dF parent_composite_scale = |
| 581 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 582 | 1.f); |
| 583 | gfx::Transform surface_sublayer_transform; |
| 584 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 585 | parent_composite_scale.y()); |
| 586 | gfx::Transform surface_sublayer_composite_transform = |
| 587 | parent_composite_transform * Inverse(surface_sublayer_transform); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 588 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 589 | // Child's render surface should not exist yet. |
| 590 | ASSERT_FALSE(child->render_surface()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 591 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 592 | SetLayerPropertiesForTesting(parent.get(), |
| 593 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 594 | gfx::Point3F(25.0f, 30.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 595 | gfx::PointF(), |
| 596 | gfx::Size(100, 120), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 597 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 598 | false); |
| 599 | SetLayerPropertiesForTesting(child.get(), |
| 600 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 601 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 602 | gfx::PointF(), |
| 603 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 604 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 605 | false); |
| 606 | SetLayerPropertiesForTesting(grand_child.get(), |
| 607 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 608 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 609 | gfx::PointF(), |
| 610 | gfx::Size(8, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 611 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 612 | false); |
| 613 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 614 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 615 | // Render surface should have been created now. |
| 616 | ASSERT_TRUE(child->render_surface()); |
| 617 | ASSERT_EQ(child, child->render_target()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 618 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 619 | // The child layer's draw transform should refer to its new render surface. |
| 620 | // The screen-space transform, however, should still refer to the root. |
| 621 | EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform, |
| 622 | child->draw_transform()); |
| 623 | EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform, |
| 624 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 625 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 626 | // Because the grand_child is the only drawable content, the child's render |
| 627 | // surface will tighten its bounds to the grand_child. The scale at which the |
| 628 | // surface's subtree is drawn must be removed from the composite transform. |
| 629 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 630 | surface_sublayer_composite_transform, |
| 631 | child->render_target()->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 632 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 633 | // The screen space is the same as the target since the child surface draws |
| 634 | // into the root. |
| 635 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 636 | surface_sublayer_composite_transform, |
| 637 | child->render_target()->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 638 | } |
| 639 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 640 | TEST_F(LayerTreeHostCommonTest, TransformsForReplica) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 641 | scoped_refptr<Layer> root = Layer::Create(); |
| 642 | scoped_refptr<Layer> parent = Layer::Create(); |
| 643 | scoped_refptr<Layer> child = Layer::Create(); |
| 644 | scoped_refptr<Layer> child_replica = Layer::Create(); |
| 645 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 646 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 647 | root->AddChild(parent); |
| 648 | parent->AddChild(child); |
| 649 | child->AddChild(grand_child); |
| 650 | child->SetReplicaLayer(child_replica.get()); |
| 651 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 652 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 653 | host->SetRootLayer(root); |
| 654 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 655 | // One-time setup of root layer |
| 656 | gfx::Transform identity_matrix; |
| 657 | SetLayerPropertiesForTesting(root.get(), |
| 658 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 659 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 660 | gfx::PointF(), |
| 661 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 662 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 663 | false); |
| 664 | |
| 665 | // Child is set up so that a new render surface should be created. |
| 666 | child->SetOpacity(0.5f); |
| 667 | |
| 668 | gfx::Transform parent_layer_transform; |
| 669 | parent_layer_transform.Scale3d(2.0, 2.0, 1.0); |
| 670 | gfx::Transform parent_translation_to_anchor; |
| 671 | parent_translation_to_anchor.Translate(2.5, 3.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 672 | gfx::Transform parent_composite_transform = |
| 673 | parent_translation_to_anchor * parent_layer_transform * |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 674 | Inverse(parent_translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 675 | gfx::Transform replica_layer_transform; |
| 676 | replica_layer_transform.Scale3d(3.0, 3.0, 1.0); |
| 677 | gfx::Vector2dF parent_composite_scale = |
| 678 | MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform, |
| 679 | 1.f); |
| 680 | gfx::Transform surface_sublayer_transform; |
| 681 | surface_sublayer_transform.Scale(parent_composite_scale.x(), |
| 682 | parent_composite_scale.y()); |
| 683 | gfx::Transform replica_composite_transform = |
| 684 | parent_composite_transform * replica_layer_transform * |
| 685 | Inverse(surface_sublayer_transform); |
| 686 | |
| 687 | // Child's render surface should not exist yet. |
| 688 | ASSERT_FALSE(child->render_surface()); |
| 689 | |
| 690 | SetLayerPropertiesForTesting(parent.get(), |
| 691 | parent_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 692 | gfx::Point3F(2.5f, 3.0f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 693 | gfx::PointF(), |
| 694 | gfx::Size(10, 12), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 695 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 696 | false); |
| 697 | SetLayerPropertiesForTesting(child.get(), |
| 698 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 699 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 700 | gfx::PointF(), |
| 701 | gfx::Size(16, 18), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 702 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 703 | false); |
| 704 | SetLayerPropertiesForTesting(grand_child.get(), |
| 705 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 706 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 707 | gfx::PointF(-0.5f, -0.5f), |
| 708 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 709 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 710 | false); |
| 711 | SetLayerPropertiesForTesting(child_replica.get(), |
| 712 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 713 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 714 | gfx::PointF(), |
| 715 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 716 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 717 | false); |
| 718 | ExecuteCalculateDrawProperties(root.get()); |
| 719 | |
| 720 | // Render surface should have been created now. |
| 721 | ASSERT_TRUE(child->render_surface()); |
| 722 | ASSERT_EQ(child, child->render_target()); |
| 723 | |
| 724 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 725 | replica_composite_transform, |
| 726 | child->render_target()->render_surface()->replica_draw_transform()); |
| 727 | EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 728 | child->render_target() |
| 729 | ->render_surface() |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 730 | ->replica_screen_space_transform()); |
| 731 | } |
| 732 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 733 | TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 734 | // This test creates a more complex tree and verifies it all at once. This |
| 735 | // covers the following cases: |
| 736 | // - layers that are described w.r.t. a render surface: should have draw |
| 737 | // transforms described w.r.t. that surface |
| 738 | // - A render surface described w.r.t. an ancestor render surface: should |
| 739 | // have a draw transform described w.r.t. that ancestor surface |
| 740 | // - Replicas of a render surface are described w.r.t. the replica's |
| 741 | // transform around its anchor, along with the surface itself. |
| 742 | // - Sanity check on recursion: verify transforms of layers described w.r.t. |
| 743 | // a render surface that is described w.r.t. an ancestor render surface. |
| 744 | // - verifying that each layer has a reference to the correct render surface |
| 745 | // and render target values. |
| 746 | |
| 747 | scoped_refptr<Layer> root = Layer::Create(); |
| 748 | scoped_refptr<Layer> parent = Layer::Create(); |
| 749 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 750 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 751 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 752 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 753 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 754 | scoped_refptr<Layer> replica_of_rs1 = Layer::Create(); |
| 755 | scoped_refptr<Layer> replica_of_rs2 = Layer::Create(); |
| 756 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 757 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 758 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 759 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 760 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 761 | root->AddChild(parent); |
| 762 | parent->AddChild(render_surface1); |
| 763 | parent->AddChild(child_of_root); |
| 764 | render_surface1->AddChild(child_of_rs1); |
| 765 | render_surface1->AddChild(render_surface2); |
| 766 | render_surface2->AddChild(child_of_rs2); |
| 767 | child_of_root->AddChild(grand_child_of_root); |
| 768 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 769 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 770 | render_surface1->SetReplicaLayer(replica_of_rs1.get()); |
| 771 | render_surface2->SetReplicaLayer(replica_of_rs2.get()); |
| 772 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 773 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 774 | host->SetRootLayer(root); |
| 775 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 776 | // In combination with descendant draws content, opacity != 1 forces the layer |
| 777 | // to have a new render surface. |
| 778 | render_surface1->SetOpacity(0.5f); |
| 779 | render_surface2->SetOpacity(0.33f); |
| 780 | |
| 781 | // One-time setup of root layer |
| 782 | gfx::Transform identity_matrix; |
| 783 | SetLayerPropertiesForTesting(root.get(), |
| 784 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 785 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 786 | gfx::PointF(), |
| 787 | gfx::Size(1, 2), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 788 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 789 | false); |
| 790 | |
| 791 | // All layers in the tree are initialized with an anchor at .25 and a size of |
| 792 | // (10,10). matrix "A" is the composite layer transform used in all layers, |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 793 | // Matrix "R" is the composite replica transform used in all replica layers. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 794 | gfx::Transform translation_to_anchor; |
| 795 | translation_to_anchor.Translate(2.5, 0.0); |
| 796 | gfx::Transform layer_transform; |
| 797 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 798 | gfx::Transform replica_layer_transform; |
| 799 | replica_layer_transform.Scale3d(-2.0, 5.0, 1.0); |
| 800 | |
| 801 | gfx::Transform A = |
| 802 | translation_to_anchor * layer_transform * Inverse(translation_to_anchor); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 803 | gfx::Transform R = A * translation_to_anchor * replica_layer_transform * |
| 804 | Inverse(translation_to_anchor); |
| 805 | |
| 806 | gfx::Vector2dF surface1_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 807 | MathUtil::ComputeTransform2dScaleComponents(A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 808 | gfx::Transform surface1_sublayer_transform; |
| 809 | surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(), |
| 810 | surface1_parent_transform_scale.y()); |
| 811 | |
| 812 | // SS1 = transform given to the subtree of render_surface1 |
| 813 | gfx::Transform SS1 = surface1_sublayer_transform; |
| 814 | // S1 = transform to move from render_surface1 pixels to the layer space of |
| 815 | // the owning layer |
| 816 | gfx::Transform S1 = Inverse(surface1_sublayer_transform); |
| 817 | |
| 818 | gfx::Vector2dF surface2_parent_transform_scale = |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 819 | MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 820 | gfx::Transform surface2_sublayer_transform; |
| 821 | surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(), |
| 822 | surface2_parent_transform_scale.y()); |
| 823 | |
| 824 | // SS2 = transform given to the subtree of render_surface2 |
| 825 | gfx::Transform SS2 = surface2_sublayer_transform; |
| 826 | // S2 = transform to move from render_surface2 pixels to the layer space of |
| 827 | // the owning layer |
| 828 | gfx::Transform S2 = Inverse(surface2_sublayer_transform); |
| 829 | |
| 830 | SetLayerPropertiesForTesting(parent.get(), |
| 831 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 832 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 833 | gfx::PointF(), |
| 834 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 835 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 836 | false); |
| 837 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 838 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 839 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 840 | gfx::PointF(), |
| 841 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 842 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 843 | false); |
| 844 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 845 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 846 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 847 | gfx::PointF(), |
| 848 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 849 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 850 | false); |
| 851 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 852 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 853 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 854 | gfx::PointF(), |
| 855 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 856 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 857 | false); |
| 858 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 859 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 860 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 861 | gfx::PointF(), |
| 862 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 863 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 864 | false); |
| 865 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 866 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 867 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 868 | gfx::PointF(), |
| 869 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 870 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 871 | false); |
| 872 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 873 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 874 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 875 | gfx::PointF(), |
| 876 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 877 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 878 | false); |
| 879 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 880 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 881 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 882 | gfx::PointF(), |
| 883 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 884 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 885 | false); |
| 886 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 887 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 888 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 889 | gfx::PointF(), |
| 890 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 891 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 892 | false); |
| 893 | SetLayerPropertiesForTesting(replica_of_rs1.get(), |
| 894 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 895 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 896 | gfx::PointF(), |
| 897 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 898 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 899 | false); |
| 900 | SetLayerPropertiesForTesting(replica_of_rs2.get(), |
| 901 | replica_layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 902 | gfx::Point3F(2.5f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 903 | gfx::PointF(), |
| 904 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 905 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 906 | false); |
| 907 | |
| 908 | ExecuteCalculateDrawProperties(root.get()); |
| 909 | |
| 910 | // Only layers that are associated with render surfaces should have an actual |
| 911 | // RenderSurface() value. |
| 912 | ASSERT_TRUE(root->render_surface()); |
| 913 | ASSERT_FALSE(child_of_root->render_surface()); |
| 914 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 915 | |
| 916 | ASSERT_TRUE(render_surface1->render_surface()); |
| 917 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 918 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 919 | |
| 920 | ASSERT_TRUE(render_surface2->render_surface()); |
| 921 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 922 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 923 | |
| 924 | // Verify all render target accessors |
| 925 | EXPECT_EQ(root, parent->render_target()); |
| 926 | EXPECT_EQ(root, child_of_root->render_target()); |
| 927 | EXPECT_EQ(root, grand_child_of_root->render_target()); |
| 928 | |
| 929 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 930 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 931 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
| 932 | |
| 933 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 934 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 935 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
| 936 | |
| 937 | // Verify layer draw transforms note that draw transforms are described with |
| 938 | // respect to the nearest ancestor render surface but screen space transforms |
| 939 | // are described with respect to the root. |
| 940 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 941 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform()); |
| 942 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 943 | grand_child_of_root->draw_transform()); |
| 944 | |
| 945 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 946 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform()); |
| 947 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 948 | grand_child_of_rs1->draw_transform()); |
| 949 | |
| 950 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 951 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform()); |
| 952 | EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 953 | grand_child_of_rs2->draw_transform()); |
| 954 | |
| 955 | // Verify layer screen-space transforms |
| 956 | // |
| 957 | EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 958 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 959 | child_of_root->screen_space_transform()); |
| 960 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 961 | A * A * A, grand_child_of_root->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 962 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 963 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 964 | render_surface1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 965 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 966 | child_of_rs1->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 967 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 968 | grand_child_of_rs1->screen_space_transform()); |
| 969 | |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 970 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 971 | render_surface2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 972 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 973 | child_of_rs2->screen_space_transform()); |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 974 | EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 975 | grand_child_of_rs2->screen_space_transform()); |
| 976 | |
| 977 | // Verify render surface transforms. |
| 978 | // |
| 979 | // Draw transform of render surface 1 is described with respect to root. |
| 980 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 981 | A * A * S1, render_surface1->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 982 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 983 | A * R * S1, render_surface1->render_surface()->replica_draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 984 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 985 | A * A * S1, render_surface1->render_surface()->screen_space_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 986 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 987 | A * R * S1, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 988 | render_surface1->render_surface()->replica_screen_space_transform()); |
| 989 | // Draw transform of render surface 2 is described with respect to render |
| 990 | // surface 1. |
| 991 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 992 | SS1 * A * S2, render_surface2->render_surface()->draw_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 993 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 994 | SS1 * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 995 | render_surface2->render_surface()->replica_draw_transform()); |
| 996 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 997 | A * A * A * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 998 | render_surface2->render_surface()->screen_space_transform()); |
| 999 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1000 | A * A * R * S2, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1001 | render_surface2->render_surface()->replica_screen_space_transform()); |
| 1002 | |
| 1003 | // Sanity check. If these fail there is probably a bug in the test itself. It |
| 1004 | // is expected that we correctly set up transforms so that the y-component of |
| 1005 | // the screen-space transform encodes the "depth" of the layer in the tree. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1006 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 1007 | EXPECT_FLOAT_EQ(2.0, |
| 1008 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1009 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1010 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1011 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1012 | EXPECT_FLOAT_EQ(2.0, |
| 1013 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 1014 | EXPECT_FLOAT_EQ(3.0, |
| 1015 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1016 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1017 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1018 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1019 | EXPECT_FLOAT_EQ(3.0, |
| 1020 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 1021 | EXPECT_FLOAT_EQ(4.0, |
| 1022 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1023 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1024 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1025 | } |
| 1026 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1027 | TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1028 | // For layers that flatten their subtree, there should be an orthographic |
| 1029 | // projection (for x and y values) in the middle of the transform sequence. |
| 1030 | // Note that the way the code is currently implemented, it is not expected to |
| 1031 | // use a canonical orthographic projection. |
| 1032 | |
| 1033 | scoped_refptr<Layer> root = Layer::Create(); |
| 1034 | scoped_refptr<Layer> child = Layer::Create(); |
| 1035 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1036 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1037 | |
| 1038 | gfx::Transform rotation_about_y_axis; |
| 1039 | rotation_about_y_axis.RotateAboutYAxis(30.0); |
| 1040 | |
| 1041 | const gfx::Transform identity_matrix; |
| 1042 | SetLayerPropertiesForTesting(root.get(), |
| 1043 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1044 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1045 | gfx::PointF(), |
| 1046 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1047 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1048 | false); |
| 1049 | SetLayerPropertiesForTesting(child.get(), |
| 1050 | rotation_about_y_axis, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1051 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1052 | gfx::PointF(), |
| 1053 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1054 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1055 | false); |
| 1056 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1057 | rotation_about_y_axis, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1058 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1059 | gfx::PointF(), |
| 1060 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1061 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1062 | false); |
| 1063 | |
| 1064 | root->AddChild(child); |
| 1065 | child->AddChild(grand_child); |
| 1066 | child->SetForceRenderSurface(true); |
| 1067 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1068 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1069 | host->SetRootLayer(root); |
| 1070 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1071 | // No layers in this test should preserve 3d. |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1072 | ASSERT_TRUE(root->should_flatten_transform()); |
| 1073 | ASSERT_TRUE(child->should_flatten_transform()); |
| 1074 | ASSERT_TRUE(grand_child->should_flatten_transform()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1075 | |
| 1076 | gfx::Transform expected_child_draw_transform = rotation_about_y_axis; |
| 1077 | gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis; |
| 1078 | gfx::Transform expected_grand_child_draw_transform = |
| 1079 | rotation_about_y_axis; // draws onto child's render surface |
| 1080 | gfx::Transform flattened_rotation_about_y = rotation_about_y_axis; |
| 1081 | flattened_rotation_about_y.FlattenTo2d(); |
| 1082 | gfx::Transform expected_grand_child_screen_space_transform = |
| 1083 | flattened_rotation_about_y * rotation_about_y_axis; |
| 1084 | |
| 1085 | ExecuteCalculateDrawProperties(root.get()); |
| 1086 | |
| 1087 | // The child's draw transform should have been taken by its surface. |
| 1088 | ASSERT_TRUE(child->render_surface()); |
| 1089 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform, |
| 1090 | child->render_surface()->draw_transform()); |
| 1091 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1092 | expected_child_screen_space_transform, |
| 1093 | child->render_surface()->screen_space_transform()); |
| 1094 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1095 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform, |
| 1096 | child->screen_space_transform()); |
| 1097 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform, |
| 1098 | grand_child->draw_transform()); |
| 1099 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform, |
| 1100 | grand_child->screen_space_transform()); |
| 1101 | } |
| 1102 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1103 | TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1104 | // A layer that is empty in one axis, but not the other, was accidentally |
| 1105 | // skipping a necessary translation. Without that translation, the coordinate |
| 1106 | // space of the layer's draw transform is incorrect. |
| 1107 | // |
| 1108 | // Normally this isn't a problem, because the layer wouldn't be drawn anyway, |
| 1109 | // but if that layer becomes a render surface, then its draw transform is |
| 1110 | // implicitly inherited by the rest of the subtree, which then is positioned |
| 1111 | // incorrectly as a result. |
| 1112 | |
| 1113 | scoped_refptr<Layer> root = Layer::Create(); |
| 1114 | scoped_refptr<Layer> child = Layer::Create(); |
| 1115 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 1116 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1117 | |
| 1118 | // The child height is zero, but has non-zero width that should be accounted |
| 1119 | // for while computing draw transforms. |
| 1120 | const gfx::Transform identity_matrix; |
| 1121 | SetLayerPropertiesForTesting(root.get(), |
| 1122 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1123 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1124 | gfx::PointF(), |
| 1125 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1126 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1127 | false); |
| 1128 | SetLayerPropertiesForTesting(child.get(), |
| 1129 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1130 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1131 | gfx::PointF(), |
| 1132 | gfx::Size(10, 0), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1133 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1134 | false); |
| 1135 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1136 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1137 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1138 | gfx::PointF(), |
| 1139 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1140 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1141 | false); |
| 1142 | |
| 1143 | root->AddChild(child); |
| 1144 | child->AddChild(grand_child); |
| 1145 | child->SetForceRenderSurface(true); |
| 1146 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1147 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1148 | host->SetRootLayer(root); |
| 1149 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1150 | ExecuteCalculateDrawProperties(root.get()); |
| 1151 | |
| 1152 | ASSERT_TRUE(child->render_surface()); |
| 1153 | // This is the real test, the rest are sanity checks. |
| 1154 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1155 | child->render_surface()->draw_transform()); |
| 1156 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); |
| 1157 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, |
| 1158 | grand_child->draw_transform()); |
| 1159 | } |
| 1160 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1161 | TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1162 | // Transformations applied at the root of the tree should be forwarded |
| 1163 | // to child layers instead of applied to the root RenderSurface. |
| 1164 | const gfx::Transform identity_matrix; |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1165 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 1166 | new LayerWithForcedDrawsContent; |
| 1167 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1168 | new LayerWithForcedDrawsContent; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1169 | child->SetScrollClipLayerId(root->id()); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1170 | root->AddChild(child); |
| 1171 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1172 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1173 | host->SetRootLayer(root); |
| 1174 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1175 | SetLayerPropertiesForTesting(root.get(), |
| 1176 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1177 | gfx::Point3F(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1178 | gfx::PointF(), |
| 1179 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1180 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1181 | false); |
| 1182 | SetLayerPropertiesForTesting(child.get(), |
| 1183 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1184 | gfx::Point3F(), |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1185 | gfx::PointF(), |
| 1186 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1187 | true, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1188 | false); |
| 1189 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1190 | gfx::Transform translate; |
| 1191 | translate.Translate(50, 50); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1192 | { |
| 1193 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1194 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1195 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
| 1196 | inputs.can_adjust_raster_scales = true; |
| 1197 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1198 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1199 | EXPECT_EQ(translate, child->draw_properties().target_space_transform); |
| 1200 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1201 | EXPECT_EQ(1.f, root->last_device_scale_factor()); |
| 1202 | EXPECT_EQ(1.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1203 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1204 | |
| 1205 | gfx::Transform scale; |
| 1206 | scale.Scale(2, 2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1207 | { |
| 1208 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1209 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1210 | root.get(), root->bounds(), scale, &render_surface_layer_list); |
| 1211 | inputs.can_adjust_raster_scales = true; |
| 1212 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1213 | EXPECT_EQ(scale, root->draw_properties().target_space_transform); |
| 1214 | EXPECT_EQ(scale, child->draw_properties().target_space_transform); |
| 1215 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1216 | EXPECT_EQ(2.f, root->last_device_scale_factor()); |
| 1217 | EXPECT_EQ(2.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1218 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1219 | |
| 1220 | gfx::Transform rotate; |
| 1221 | rotate.Rotate(2); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1222 | { |
| 1223 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1224 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1225 | root.get(), root->bounds(), rotate, &render_surface_layer_list); |
| 1226 | inputs.can_adjust_raster_scales = true; |
| 1227 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1228 | EXPECT_EQ(rotate, root->draw_properties().target_space_transform); |
| 1229 | EXPECT_EQ(rotate, child->draw_properties().target_space_transform); |
| 1230 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1231 | EXPECT_EQ(1.f, root->last_device_scale_factor()); |
| 1232 | EXPECT_EQ(1.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1233 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1234 | |
| 1235 | gfx::Transform composite; |
| 1236 | composite.ConcatTransform(translate); |
| 1237 | composite.ConcatTransform(scale); |
| 1238 | composite.ConcatTransform(rotate); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1239 | { |
| 1240 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1241 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1242 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
| 1243 | inputs.can_adjust_raster_scales = true; |
| 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( |
| 1256 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
| 1257 | inputs.device_scale_factor = device_scale_factor; |
| 1258 | inputs.can_adjust_raster_scales = true; |
| 1259 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1260 | gfx::Transform device_scaled_translate = translate; |
| 1261 | device_scaled_translate.Scale(device_scale_factor, device_scale_factor); |
| 1262 | EXPECT_EQ(device_scaled_translate, |
| 1263 | root->draw_properties().target_space_transform); |
| 1264 | EXPECT_EQ(device_scaled_translate, |
| 1265 | child->draw_properties().target_space_transform); |
| 1266 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1267 | EXPECT_EQ(device_scale_factor, root->last_device_scale_factor()); |
| 1268 | EXPECT_EQ(device_scale_factor, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1269 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1270 | |
| 1271 | // Verify it composes correctly with page scale. |
| 1272 | float page_scale_factor = 2.f; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1273 | |
| 1274 | { |
| 1275 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1276 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1277 | root.get(), root->bounds(), translate, &render_surface_layer_list); |
| 1278 | inputs.page_scale_factor = page_scale_factor; |
| 1279 | inputs.page_scale_application_layer = root.get(); |
| 1280 | inputs.can_adjust_raster_scales = true; |
| 1281 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1282 | gfx::Transform page_scaled_translate = translate; |
| 1283 | page_scaled_translate.Scale(page_scale_factor, page_scale_factor); |
| 1284 | EXPECT_EQ(translate, root->draw_properties().target_space_transform); |
| 1285 | EXPECT_EQ(page_scaled_translate, |
| 1286 | child->draw_properties().target_space_transform); |
| 1287 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
[email protected] | d575428 | 2014-04-09 00:43:29 | [diff] [blame] | 1288 | EXPECT_EQ(1.f, root->last_device_scale_factor()); |
| 1289 | EXPECT_EQ(1.f, child->last_device_scale_factor()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1290 | } |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 1291 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1292 | // Verify that it composes correctly with transforms directly on root layer. |
| 1293 | root->SetTransform(composite); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1294 | |
| 1295 | { |
| 1296 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1297 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1298 | root.get(), root->bounds(), composite, &render_surface_layer_list); |
| 1299 | inputs.can_adjust_raster_scales = true; |
| 1300 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1301 | gfx::Transform compositeSquared = composite; |
| 1302 | compositeSquared.ConcatTransform(composite); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 1303 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 1304 | compositeSquared, root->draw_properties().target_space_transform); |
| 1305 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
[email protected] | baf64d06 | 2014-02-16 22:10:39 | [diff] [blame] | 1306 | compositeSquared, child->draw_properties().target_space_transform); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1307 | EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform()); |
| 1308 | } |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 1309 | } |
| 1310 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1311 | TEST_F(LayerTreeHostCommonTest, |
| 1312 | RenderSurfaceListForRenderSurfaceWithClippedLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1313 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1314 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1315 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1316 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1317 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1318 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1319 | host->SetRootLayer(parent); |
| 1320 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1321 | const gfx::Transform identity_matrix; |
| 1322 | SetLayerPropertiesForTesting(parent.get(), |
| 1323 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1324 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1325 | gfx::PointF(), |
| 1326 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1327 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1328 | false); |
| 1329 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1330 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1331 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1332 | gfx::PointF(), |
| 1333 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1334 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1335 | false); |
| 1336 | SetLayerPropertiesForTesting(child.get(), |
| 1337 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1338 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1339 | gfx::PointF(30.f, 30.f), |
| 1340 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1341 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1342 | false); |
| 1343 | |
| 1344 | parent->AddChild(render_surface1); |
| 1345 | parent->SetMasksToBounds(true); |
| 1346 | render_surface1->AddChild(child); |
| 1347 | render_surface1->SetForceRenderSurface(true); |
| 1348 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1349 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1350 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1351 | parent.get(), |
| 1352 | parent->bounds(), |
| 1353 | gfx::Transform(), |
| 1354 | &render_surface_layer_list); |
| 1355 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1356 | |
| 1357 | // The child layer's content is entirely outside the parent's clip rect, so |
| 1358 | // the intermediate render surface should not be listed here, even if it was |
| 1359 | // forced to be created. Render surfaces without children or visible content |
| 1360 | // are unexpected at draw time (e.g. we might try to create a content texture |
| 1361 | // of size 0). |
| 1362 | ASSERT_TRUE(parent->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1363 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1364 | } |
| 1365 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1366 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1367 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1368 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1369 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1370 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1371 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1372 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1373 | host->SetRootLayer(parent); |
| 1374 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1375 | const gfx::Transform identity_matrix; |
| 1376 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1377 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1378 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1379 | gfx::PointF(), |
| 1380 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1381 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1382 | false); |
| 1383 | SetLayerPropertiesForTesting(child.get(), |
| 1384 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1385 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1386 | gfx::PointF(), |
| 1387 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1388 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1389 | false); |
| 1390 | |
| 1391 | parent->AddChild(render_surface1); |
| 1392 | render_surface1->AddChild(child); |
| 1393 | render_surface1->SetForceRenderSurface(true); |
| 1394 | render_surface1->SetOpacity(0.f); |
| 1395 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1396 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1397 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1398 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1399 | inputs.can_adjust_raster_scales = true; |
| 1400 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1401 | |
| 1402 | // Since the layer is transparent, render_surface1->render_surface() should |
| 1403 | // not have gotten added anywhere. Also, the drawable content rect should not |
| 1404 | // have been extended by the children. |
| 1405 | ASSERT_TRUE(parent->render_surface()); |
| 1406 | EXPECT_EQ(0U, parent->render_surface()->layer_list().size()); |
| 1407 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1408 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1409 | EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect()); |
| 1410 | } |
| 1411 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1412 | TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1413 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1414 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 1415 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 1416 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1417 | render_surface1->SetForceRenderSurface(true); |
| 1418 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1419 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1420 | host->SetRootLayer(parent); |
| 1421 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1422 | const gfx::Transform identity_matrix; |
| 1423 | SetLayerPropertiesForTesting(parent.get(), |
| 1424 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1425 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1426 | gfx::PointF(), |
| 1427 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1428 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1429 | false); |
| 1430 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 1431 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1432 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1433 | gfx::PointF(), |
| 1434 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1435 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1436 | false); |
| 1437 | SetLayerPropertiesForTesting(child.get(), |
| 1438 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1439 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1440 | gfx::PointF(), |
| 1441 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1442 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1443 | false); |
| 1444 | |
| 1445 | parent->AddChild(render_surface1); |
| 1446 | render_surface1->AddChild(child); |
| 1447 | |
| 1448 | // Sanity check before the actual test |
| 1449 | EXPECT_FALSE(parent->render_surface()); |
| 1450 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1451 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1452 | { |
| 1453 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1454 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1455 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1456 | inputs.can_adjust_raster_scales = true; |
| 1457 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1458 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1459 | // The root layer always creates a render surface |
| 1460 | EXPECT_TRUE(parent->render_surface()); |
| 1461 | EXPECT_TRUE(render_surface1->render_surface()); |
| 1462 | EXPECT_EQ(2U, render_surface_layer_list.size()); |
| 1463 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1464 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1465 | { |
| 1466 | RenderSurfaceLayerList render_surface_layer_list; |
| 1467 | render_surface1->SetForceRenderSurface(false); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1468 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1469 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1470 | inputs.can_adjust_raster_scales = true; |
| 1471 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1472 | EXPECT_TRUE(parent->render_surface()); |
| 1473 | EXPECT_FALSE(render_surface1->render_surface()); |
| 1474 | EXPECT_EQ(1U, render_surface_layer_list.size()); |
| 1475 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1476 | } |
| 1477 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1478 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1479 | // The entire subtree of layers that are outside the clip rect should be |
| 1480 | // culled away, and should not affect the render_surface_layer_list. |
| 1481 | // |
| 1482 | // The test tree is set up as follows: |
| 1483 | // - all layers except the leaf_nodes are forced to be a new render surface |
| 1484 | // that have something to draw. |
| 1485 | // - parent is a large container layer. |
| 1486 | // - child has masksToBounds=true to cause clipping. |
| 1487 | // - grand_child is positioned outside of the child's bounds |
| 1488 | // - great_grand_child is also kept outside child's bounds. |
| 1489 | // |
| 1490 | // In this configuration, grand_child and great_grand_child are completely |
| 1491 | // outside the clip rect, and they should never get scheduled on the list of |
| 1492 | // render surfaces. |
| 1493 | // |
| 1494 | |
| 1495 | const gfx::Transform identity_matrix; |
| 1496 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1497 | scoped_refptr<Layer> child = Layer::Create(); |
| 1498 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1499 | scoped_refptr<Layer> great_grand_child = Layer::Create(); |
| 1500 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1501 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1502 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1503 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1504 | parent->AddChild(child); |
| 1505 | child->AddChild(grand_child); |
| 1506 | grand_child->AddChild(great_grand_child); |
| 1507 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1508 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1509 | host->SetRootLayer(parent); |
| 1510 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1511 | // leaf_node1 ensures that parent and child are kept on the |
| 1512 | // render_surface_layer_list, even though grand_child and great_grand_child |
| 1513 | // should be clipped. |
| 1514 | child->AddChild(leaf_node1); |
| 1515 | great_grand_child->AddChild(leaf_node2); |
| 1516 | |
| 1517 | SetLayerPropertiesForTesting(parent.get(), |
| 1518 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1519 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1520 | gfx::PointF(), |
| 1521 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1522 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1523 | false); |
| 1524 | SetLayerPropertiesForTesting(child.get(), |
| 1525 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1526 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1527 | gfx::PointF(), |
| 1528 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1529 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1530 | false); |
| 1531 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1532 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1533 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1534 | gfx::PointF(45.f, 45.f), |
| 1535 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1536 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1537 | false); |
| 1538 | SetLayerPropertiesForTesting(great_grand_child.get(), |
| 1539 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1540 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1541 | gfx::PointF(), |
| 1542 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1543 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1544 | false); |
| 1545 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1546 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1547 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1548 | gfx::PointF(), |
| 1549 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1550 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1551 | false); |
| 1552 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1553 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1554 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1555 | gfx::PointF(), |
| 1556 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1557 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1558 | false); |
| 1559 | |
| 1560 | child->SetMasksToBounds(true); |
| 1561 | child->SetOpacity(0.4f); |
| 1562 | child->SetForceRenderSurface(true); |
| 1563 | grand_child->SetOpacity(0.5f); |
| 1564 | great_grand_child->SetOpacity(0.4f); |
| 1565 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1566 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1567 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1568 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1569 | inputs.can_adjust_raster_scales = true; |
| 1570 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1571 | |
| 1572 | ASSERT_EQ(2U, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1573 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1574 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1575 | } |
| 1576 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1577 | TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1578 | // When a render surface has a clip rect, it is used to clip the content rect |
| 1579 | // of the surface. When the render surface is animating its transforms, then |
| 1580 | // the content rect's position in the clip rect is not defined on the main |
| 1581 | // thread, and its content rect should not be clipped. |
| 1582 | |
| 1583 | // The test tree is set up as follows: |
| 1584 | // - parent is a container layer that masksToBounds=true to cause clipping. |
| 1585 | // - child is a render surface, which has a clip rect set to the bounds of |
| 1586 | // the parent. |
| 1587 | // - grand_child is a render surface, and the only visible content in child. |
| 1588 | // It is positioned outside of the clip rect from parent. |
| 1589 | |
| 1590 | // In this configuration, grand_child should be outside the clipped |
| 1591 | // content rect of the child, making grand_child not appear in the |
| 1592 | // render_surface_layer_list. However, when we place an animation on the |
| 1593 | // child, this clipping should be avoided and we should keep the grand_child |
| 1594 | // in the render_surface_layer_list. |
| 1595 | |
| 1596 | const gfx::Transform identity_matrix; |
| 1597 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1598 | scoped_refptr<Layer> child = Layer::Create(); |
| 1599 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1600 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node = |
| 1601 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1602 | parent->AddChild(child); |
| 1603 | child->AddChild(grand_child); |
| 1604 | grand_child->AddChild(leaf_node); |
| 1605 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1606 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1607 | host->SetRootLayer(parent); |
| 1608 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1609 | SetLayerPropertiesForTesting(parent.get(), |
| 1610 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1611 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1612 | gfx::PointF(), |
| 1613 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1614 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1615 | false); |
| 1616 | SetLayerPropertiesForTesting(child.get(), |
| 1617 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1618 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1619 | gfx::PointF(), |
| 1620 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1621 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1622 | false); |
| 1623 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1624 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1625 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1626 | gfx::PointF(200.f, 200.f), |
| 1627 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1628 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1629 | false); |
| 1630 | SetLayerPropertiesForTesting(leaf_node.get(), |
| 1631 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1632 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1633 | gfx::PointF(), |
| 1634 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1635 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1636 | false); |
| 1637 | |
| 1638 | parent->SetMasksToBounds(true); |
| 1639 | child->SetOpacity(0.4f); |
| 1640 | child->SetForceRenderSurface(true); |
| 1641 | grand_child->SetOpacity(0.4f); |
| 1642 | grand_child->SetForceRenderSurface(true); |
| 1643 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1644 | { |
| 1645 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1646 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1647 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1648 | inputs.can_adjust_raster_scales = true; |
| 1649 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1650 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1651 | // Without an animation, we should cull child and grand_child from the |
| 1652 | // render_surface_layer_list. |
| 1653 | ASSERT_EQ(1U, render_surface_layer_list.size()); |
| 1654 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1655 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1656 | |
| 1657 | // Now put an animating transform on child. |
| 1658 | AddAnimatedTransformToController( |
| 1659 | child->layer_animation_controller(), 10.0, 30, 0); |
| 1660 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1661 | { |
| 1662 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1663 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1664 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1665 | inputs.can_adjust_raster_scales = true; |
| 1666 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1667 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1668 | // With an animating transform, we should keep child and grand_child in the |
| 1669 | // render_surface_layer_list. |
| 1670 | ASSERT_EQ(3U, render_surface_layer_list.size()); |
| 1671 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 1672 | EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id()); |
| 1673 | EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id()); |
| 1674 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1675 | } |
| 1676 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1677 | TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1678 | // Layer's IsClipped() property is set to true when: |
| 1679 | // - the layer clips its subtree, e.g. masks to bounds, |
| 1680 | // - the layer is clipped by an ancestor that contributes to the same |
| 1681 | // render target, |
| 1682 | // - a surface is clipped by an ancestor that contributes to the same |
| 1683 | // render target. |
| 1684 | // |
| 1685 | // In particular, for a layer that owns a render surface: |
| 1686 | // - the render surface inherits any clip from ancestors, and does NOT |
| 1687 | // pass that clipped status to the layer itself. |
| 1688 | // - but if the layer itself masks to bounds, it is considered clipped |
| 1689 | // and propagates the clip to the subtree. |
| 1690 | |
| 1691 | const gfx::Transform identity_matrix; |
| 1692 | scoped_refptr<Layer> root = Layer::Create(); |
| 1693 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1694 | scoped_refptr<Layer> child1 = Layer::Create(); |
| 1695 | scoped_refptr<Layer> child2 = Layer::Create(); |
| 1696 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 1697 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1698 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1699 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1700 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1701 | root->AddChild(parent); |
| 1702 | parent->AddChild(child1); |
| 1703 | parent->AddChild(child2); |
| 1704 | child1->AddChild(grand_child); |
| 1705 | child2->AddChild(leaf_node2); |
| 1706 | grand_child->AddChild(leaf_node1); |
| 1707 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1708 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1709 | host->SetRootLayer(root); |
| 1710 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1711 | child2->SetForceRenderSurface(true); |
| 1712 | |
| 1713 | SetLayerPropertiesForTesting(root.get(), |
| 1714 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1715 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1716 | gfx::PointF(), |
| 1717 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1718 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1719 | false); |
| 1720 | SetLayerPropertiesForTesting(parent.get(), |
| 1721 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1722 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1723 | gfx::PointF(), |
| 1724 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1725 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1726 | false); |
| 1727 | SetLayerPropertiesForTesting(child1.get(), |
| 1728 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1729 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1730 | gfx::PointF(), |
| 1731 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1732 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1733 | false); |
| 1734 | SetLayerPropertiesForTesting(child2.get(), |
| 1735 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1736 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1737 | gfx::PointF(), |
| 1738 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1739 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1740 | false); |
| 1741 | SetLayerPropertiesForTesting(grand_child.get(), |
| 1742 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1743 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1744 | gfx::PointF(), |
| 1745 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1746 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1747 | false); |
| 1748 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 1749 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1750 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1751 | gfx::PointF(), |
| 1752 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1753 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1754 | false); |
| 1755 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 1756 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1757 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1758 | gfx::PointF(), |
| 1759 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1760 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1761 | false); |
| 1762 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1763 | // Case 1: nothing is clipped except the root render surface. |
| 1764 | { |
| 1765 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1766 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1767 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1768 | inputs.can_adjust_raster_scales = true; |
| 1769 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1770 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1771 | ASSERT_TRUE(root->render_surface()); |
| 1772 | ASSERT_TRUE(child2->render_surface()); |
| 1773 | |
| 1774 | EXPECT_FALSE(root->is_clipped()); |
| 1775 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1776 | EXPECT_FALSE(parent->is_clipped()); |
| 1777 | EXPECT_FALSE(child1->is_clipped()); |
| 1778 | EXPECT_FALSE(child2->is_clipped()); |
| 1779 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1780 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1781 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1782 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1783 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1784 | |
| 1785 | // Case 2: parent masksToBounds, so the parent, child1, and child2's |
| 1786 | // surface are clipped. But layers that contribute to child2's surface are |
| 1787 | // not clipped explicitly because child2's surface already accounts for |
| 1788 | // that clip. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1789 | { |
| 1790 | RenderSurfaceLayerList render_surface_layer_list; |
| 1791 | parent->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1792 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1793 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1794 | inputs.can_adjust_raster_scales = true; |
| 1795 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1796 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1797 | ASSERT_TRUE(root->render_surface()); |
| 1798 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1799 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1800 | EXPECT_FALSE(root->is_clipped()); |
| 1801 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1802 | EXPECT_TRUE(parent->is_clipped()); |
| 1803 | EXPECT_TRUE(child1->is_clipped()); |
| 1804 | EXPECT_FALSE(child2->is_clipped()); |
| 1805 | EXPECT_TRUE(child2->render_surface()->is_clipped()); |
| 1806 | EXPECT_TRUE(grand_child->is_clipped()); |
| 1807 | EXPECT_TRUE(leaf_node1->is_clipped()); |
| 1808 | EXPECT_FALSE(leaf_node2->is_clipped()); |
| 1809 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1810 | |
| 1811 | // Case 3: child2 masksToBounds. The layer and subtree are clipped, and |
| 1812 | // child2's render surface is not clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1813 | { |
| 1814 | RenderSurfaceLayerList render_surface_layer_list; |
| 1815 | parent->SetMasksToBounds(false); |
| 1816 | child2->SetMasksToBounds(true); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1817 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1818 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 1819 | inputs.can_adjust_raster_scales = true; |
| 1820 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1821 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1822 | ASSERT_TRUE(root->render_surface()); |
| 1823 | ASSERT_TRUE(child2->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1824 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1825 | EXPECT_FALSE(root->is_clipped()); |
| 1826 | EXPECT_TRUE(root->render_surface()->is_clipped()); |
| 1827 | EXPECT_FALSE(parent->is_clipped()); |
| 1828 | EXPECT_FALSE(child1->is_clipped()); |
| 1829 | EXPECT_TRUE(child2->is_clipped()); |
| 1830 | EXPECT_FALSE(child2->render_surface()->is_clipped()); |
| 1831 | EXPECT_FALSE(grand_child->is_clipped()); |
| 1832 | EXPECT_FALSE(leaf_node1->is_clipped()); |
| 1833 | EXPECT_TRUE(leaf_node2->is_clipped()); |
| 1834 | } |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1835 | } |
| 1836 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 1837 | TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1838 | // Verify that layers get the appropriate DrawableContentRect when their |
| 1839 | // parent masksToBounds is true. |
| 1840 | // |
| 1841 | // grand_child1 - completely inside the region; DrawableContentRect should |
| 1842 | // be the layer rect expressed in target space. |
| 1843 | // grand_child2 - partially clipped but NOT masksToBounds; the clip rect |
| 1844 | // will be the intersection of layer bounds and the mask region. |
| 1845 | // grand_child3 - partially clipped and masksToBounds; the |
| 1846 | // DrawableContentRect will still be the intersection of layer bounds and |
| 1847 | // the mask region. |
| 1848 | // grand_child4 - outside parent's clip rect; the DrawableContentRect should |
| 1849 | // be empty. |
| 1850 | // |
| 1851 | |
| 1852 | const gfx::Transform identity_matrix; |
| 1853 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1854 | scoped_refptr<Layer> child = Layer::Create(); |
| 1855 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 1856 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 1857 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 1858 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 1859 | |
| 1860 | parent->AddChild(child); |
| 1861 | child->AddChild(grand_child1); |
| 1862 | child->AddChild(grand_child2); |
| 1863 | child->AddChild(grand_child3); |
| 1864 | child->AddChild(grand_child4); |
| 1865 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1866 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1867 | host->SetRootLayer(parent); |
| 1868 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1869 | SetLayerPropertiesForTesting(parent.get(), |
| 1870 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1871 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1872 | gfx::PointF(), |
| 1873 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1874 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1875 | false); |
| 1876 | SetLayerPropertiesForTesting(child.get(), |
| 1877 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1878 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1879 | gfx::PointF(), |
| 1880 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1881 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1882 | false); |
| 1883 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 1884 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1885 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1886 | gfx::PointF(5.f, 5.f), |
| 1887 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1888 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1889 | false); |
| 1890 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 1891 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1892 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1893 | gfx::PointF(15.f, 15.f), |
| 1894 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1895 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1896 | false); |
| 1897 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 1898 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1899 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1900 | gfx::PointF(15.f, 15.f), |
| 1901 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1902 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1903 | false); |
| 1904 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 1905 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1906 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1907 | gfx::PointF(45.f, 45.f), |
| 1908 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1909 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1910 | false); |
| 1911 | |
| 1912 | child->SetMasksToBounds(true); |
| 1913 | grand_child3->SetMasksToBounds(true); |
| 1914 | |
| 1915 | // Force everyone to be a render surface. |
| 1916 | child->SetOpacity(0.4f); |
| 1917 | grand_child1->SetOpacity(0.5f); |
| 1918 | grand_child2->SetOpacity(0.5f); |
| 1919 | grand_child3->SetOpacity(0.5f); |
| 1920 | grand_child4->SetOpacity(0.5f); |
| 1921 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1922 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 1923 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 1924 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 1925 | inputs.can_adjust_raster_scales = true; |
| 1926 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1927 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 1928 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 10, 10), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1929 | grand_child1->drawable_content_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 1930 | EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1931 | grand_child3->drawable_content_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 1932 | EXPECT_RECT_EQ(gfx::Rect(15, 15, 5, 5), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1933 | grand_child3->drawable_content_rect()); |
| 1934 | EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty()); |
| 1935 | } |
| 1936 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 1937 | TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1938 | // Verify that render surfaces (and their layers) get the appropriate |
| 1939 | // clip rects when their parent masksToBounds is true. |
| 1940 | // |
| 1941 | // Layers that own render surfaces (at least for now) do not inherit any |
| 1942 | // clipping; instead the surface will enforce the clip for the entire subtree. |
| 1943 | // They may still have a clip rect of their own layer bounds, however, if |
| 1944 | // masksToBounds was true. |
| 1945 | const gfx::Transform identity_matrix; |
| 1946 | scoped_refptr<Layer> parent = Layer::Create(); |
| 1947 | scoped_refptr<Layer> child = Layer::Create(); |
| 1948 | scoped_refptr<Layer> grand_child1 = Layer::Create(); |
| 1949 | scoped_refptr<Layer> grand_child2 = Layer::Create(); |
| 1950 | scoped_refptr<Layer> grand_child3 = Layer::Create(); |
| 1951 | scoped_refptr<Layer> grand_child4 = Layer::Create(); |
| 1952 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 = |
| 1953 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1954 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 = |
| 1955 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1956 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 = |
| 1957 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1958 | scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 = |
| 1959 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 1960 | |
| 1961 | parent->AddChild(child); |
| 1962 | child->AddChild(grand_child1); |
| 1963 | child->AddChild(grand_child2); |
| 1964 | child->AddChild(grand_child3); |
| 1965 | child->AddChild(grand_child4); |
| 1966 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 1967 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 1968 | host->SetRootLayer(parent); |
| 1969 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1970 | // the leaf nodes ensure that these grand_children become render surfaces for |
| 1971 | // this test. |
| 1972 | grand_child1->AddChild(leaf_node1); |
| 1973 | grand_child2->AddChild(leaf_node2); |
| 1974 | grand_child3->AddChild(leaf_node3); |
| 1975 | grand_child4->AddChild(leaf_node4); |
| 1976 | |
| 1977 | SetLayerPropertiesForTesting(parent.get(), |
| 1978 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1979 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1980 | gfx::PointF(), |
| 1981 | gfx::Size(500, 500), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1982 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1983 | false); |
| 1984 | SetLayerPropertiesForTesting(child.get(), |
| 1985 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1986 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1987 | gfx::PointF(), |
| 1988 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1989 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1990 | false); |
| 1991 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 1992 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 1993 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1994 | gfx::PointF(5.f, 5.f), |
| 1995 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1996 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 1997 | false); |
| 1998 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 1999 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2000 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2001 | gfx::PointF(15.f, 15.f), |
| 2002 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2003 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2004 | false); |
| 2005 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2006 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2007 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2008 | gfx::PointF(15.f, 15.f), |
| 2009 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2010 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2011 | false); |
| 2012 | SetLayerPropertiesForTesting(grand_child4.get(), |
| 2013 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2014 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2015 | gfx::PointF(45.f, 45.f), |
| 2016 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2017 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2018 | false); |
| 2019 | SetLayerPropertiesForTesting(leaf_node1.get(), |
| 2020 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2021 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2022 | gfx::PointF(), |
| 2023 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2024 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2025 | false); |
| 2026 | SetLayerPropertiesForTesting(leaf_node2.get(), |
| 2027 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2028 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2029 | gfx::PointF(), |
| 2030 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2031 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2032 | false); |
| 2033 | SetLayerPropertiesForTesting(leaf_node3.get(), |
| 2034 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2035 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2036 | gfx::PointF(), |
| 2037 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2038 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2039 | false); |
| 2040 | SetLayerPropertiesForTesting(leaf_node4.get(), |
| 2041 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2042 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2043 | gfx::PointF(), |
| 2044 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2045 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2046 | false); |
| 2047 | |
| 2048 | child->SetMasksToBounds(true); |
| 2049 | grand_child3->SetMasksToBounds(true); |
| 2050 | grand_child4->SetMasksToBounds(true); |
| 2051 | |
| 2052 | // Force everyone to be a render surface. |
| 2053 | child->SetOpacity(0.4f); |
| 2054 | child->SetForceRenderSurface(true); |
| 2055 | grand_child1->SetOpacity(0.5f); |
| 2056 | grand_child1->SetForceRenderSurface(true); |
| 2057 | grand_child2->SetOpacity(0.5f); |
| 2058 | grand_child2->SetForceRenderSurface(true); |
| 2059 | grand_child3->SetOpacity(0.5f); |
| 2060 | grand_child3->SetForceRenderSurface(true); |
| 2061 | grand_child4->SetOpacity(0.5f); |
| 2062 | grand_child4->SetForceRenderSurface(true); |
| 2063 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2064 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 2065 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 2066 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 2067 | inputs.can_adjust_raster_scales = true; |
| 2068 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2069 | ASSERT_TRUE(grand_child1->render_surface()); |
| 2070 | ASSERT_TRUE(grand_child2->render_surface()); |
| 2071 | ASSERT_TRUE(grand_child3->render_surface()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2072 | |
| 2073 | // Surfaces are clipped by their parent, but un-affected by the owning layer's |
| 2074 | // masksToBounds. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2075 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2076 | grand_child1->render_surface()->clip_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2077 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2078 | grand_child2->render_surface()->clip_rect()); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2079 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 20, 20), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2080 | grand_child3->render_surface()->clip_rect()); |
| 2081 | } |
| 2082 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2083 | TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2084 | scoped_refptr<Layer> parent = Layer::Create(); |
| 2085 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2086 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 2087 | scoped_refptr<Layer> child_of_root = Layer::Create(); |
| 2088 | scoped_refptr<Layer> child_of_rs1 = Layer::Create(); |
| 2089 | scoped_refptr<Layer> child_of_rs2 = Layer::Create(); |
| 2090 | scoped_refptr<Layer> grand_child_of_root = Layer::Create(); |
| 2091 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 = |
| 2092 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2093 | scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 = |
| 2094 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2095 | parent->AddChild(render_surface1); |
| 2096 | parent->AddChild(child_of_root); |
| 2097 | render_surface1->AddChild(child_of_rs1); |
| 2098 | render_surface1->AddChild(render_surface2); |
| 2099 | render_surface2->AddChild(child_of_rs2); |
| 2100 | child_of_root->AddChild(grand_child_of_root); |
| 2101 | child_of_rs1->AddChild(grand_child_of_rs1); |
| 2102 | child_of_rs2->AddChild(grand_child_of_rs2); |
| 2103 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2104 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2105 | host->SetRootLayer(parent); |
| 2106 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2107 | // Make our render surfaces. |
| 2108 | render_surface1->SetForceRenderSurface(true); |
| 2109 | render_surface2->SetForceRenderSurface(true); |
| 2110 | |
| 2111 | gfx::Transform layer_transform; |
| 2112 | layer_transform.Translate(1.0, 1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2113 | |
| 2114 | SetLayerPropertiesForTesting(parent.get(), |
| 2115 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2116 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2117 | gfx::PointF(2.5f, 0.f), |
| 2118 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2119 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2120 | false); |
| 2121 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2122 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2123 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2124 | gfx::PointF(2.5f, 0.f), |
| 2125 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2126 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2127 | false); |
| 2128 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 2129 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2130 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2131 | gfx::PointF(2.5f, 0.f), |
| 2132 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2133 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2134 | false); |
| 2135 | SetLayerPropertiesForTesting(child_of_root.get(), |
| 2136 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2137 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2138 | gfx::PointF(2.5f, 0.f), |
| 2139 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2140 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2141 | false); |
| 2142 | SetLayerPropertiesForTesting(child_of_rs1.get(), |
| 2143 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2144 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2145 | gfx::PointF(2.5f, 0.f), |
| 2146 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2147 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2148 | false); |
| 2149 | SetLayerPropertiesForTesting(child_of_rs2.get(), |
| 2150 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2151 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2152 | gfx::PointF(2.5f, 0.f), |
| 2153 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2154 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2155 | false); |
| 2156 | SetLayerPropertiesForTesting(grand_child_of_root.get(), |
| 2157 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2158 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2159 | gfx::PointF(2.5f, 0.f), |
| 2160 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2161 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2162 | false); |
| 2163 | SetLayerPropertiesForTesting(grand_child_of_rs1.get(), |
| 2164 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2165 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2166 | gfx::PointF(2.5f, 0.f), |
| 2167 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2168 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2169 | false); |
| 2170 | SetLayerPropertiesForTesting(grand_child_of_rs2.get(), |
| 2171 | layer_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2172 | gfx::Point3F(0.25f, 0.f, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2173 | gfx::PointF(2.5f, 0.f), |
| 2174 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2175 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2176 | false); |
| 2177 | |
| 2178 | // Put an animated opacity on the render surface. |
| 2179 | AddOpacityTransitionToController( |
| 2180 | render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2181 | |
| 2182 | // Also put an animated opacity on a layer without descendants. |
| 2183 | AddOpacityTransitionToController( |
| 2184 | grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false); |
| 2185 | |
| 2186 | // Put a transform animation on the render surface. |
| 2187 | AddAnimatedTransformToController( |
| 2188 | render_surface2->layer_animation_controller(), 10.0, 30, 0); |
| 2189 | |
| 2190 | // Also put transform animations on grand_child_of_root, and |
| 2191 | // grand_child_of_rs2 |
| 2192 | AddAnimatedTransformToController( |
| 2193 | grand_child_of_root->layer_animation_controller(), 10.0, 30, 0); |
| 2194 | AddAnimatedTransformToController( |
| 2195 | grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0); |
| 2196 | |
| 2197 | ExecuteCalculateDrawProperties(parent.get()); |
| 2198 | |
| 2199 | // Only layers that are associated with render surfaces should have an actual |
| 2200 | // RenderSurface() value. |
| 2201 | ASSERT_TRUE(parent->render_surface()); |
| 2202 | ASSERT_FALSE(child_of_root->render_surface()); |
| 2203 | ASSERT_FALSE(grand_child_of_root->render_surface()); |
| 2204 | |
| 2205 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2206 | ASSERT_FALSE(child_of_rs1->render_surface()); |
| 2207 | ASSERT_FALSE(grand_child_of_rs1->render_surface()); |
| 2208 | |
| 2209 | ASSERT_TRUE(render_surface2->render_surface()); |
| 2210 | ASSERT_FALSE(child_of_rs2->render_surface()); |
| 2211 | ASSERT_FALSE(grand_child_of_rs2->render_surface()); |
| 2212 | |
| 2213 | // Verify all render target accessors |
| 2214 | EXPECT_EQ(parent, parent->render_target()); |
| 2215 | EXPECT_EQ(parent, child_of_root->render_target()); |
| 2216 | EXPECT_EQ(parent, grand_child_of_root->render_target()); |
| 2217 | |
| 2218 | EXPECT_EQ(render_surface1, render_surface1->render_target()); |
| 2219 | EXPECT_EQ(render_surface1, child_of_rs1->render_target()); |
| 2220 | EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target()); |
| 2221 | |
| 2222 | EXPECT_EQ(render_surface2, render_surface2->render_target()); |
| 2223 | EXPECT_EQ(render_surface2, child_of_rs2->render_target()); |
| 2224 | EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target()); |
| 2225 | |
| 2226 | // Verify draw_opacity_is_animating values |
| 2227 | EXPECT_FALSE(parent->draw_opacity_is_animating()); |
| 2228 | EXPECT_FALSE(child_of_root->draw_opacity_is_animating()); |
| 2229 | EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating()); |
| 2230 | EXPECT_FALSE(render_surface1->draw_opacity_is_animating()); |
| 2231 | EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating()); |
| 2232 | EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating()); |
| 2233 | EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating()); |
| 2234 | EXPECT_FALSE(render_surface2->draw_opacity_is_animating()); |
| 2235 | EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating()); |
| 2236 | EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating()); |
| 2237 | EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating()); |
| 2238 | |
| 2239 | // Verify draw_transform_is_animating values |
| 2240 | EXPECT_FALSE(parent->draw_transform_is_animating()); |
| 2241 | EXPECT_FALSE(child_of_root->draw_transform_is_animating()); |
| 2242 | EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating()); |
| 2243 | EXPECT_FALSE(render_surface1->draw_transform_is_animating()); |
| 2244 | EXPECT_FALSE(render_surface1->render_surface() |
| 2245 | ->target_surface_transforms_are_animating()); |
| 2246 | EXPECT_FALSE(child_of_rs1->draw_transform_is_animating()); |
| 2247 | EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating()); |
| 2248 | EXPECT_FALSE(render_surface2->draw_transform_is_animating()); |
| 2249 | EXPECT_TRUE(render_surface2->render_surface() |
| 2250 | ->target_surface_transforms_are_animating()); |
| 2251 | EXPECT_FALSE(child_of_rs2->draw_transform_is_animating()); |
| 2252 | EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating()); |
| 2253 | |
| 2254 | // Verify screen_space_transform_is_animating values |
| 2255 | EXPECT_FALSE(parent->screen_space_transform_is_animating()); |
| 2256 | EXPECT_FALSE(child_of_root->screen_space_transform_is_animating()); |
| 2257 | EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating()); |
| 2258 | EXPECT_FALSE(render_surface1->screen_space_transform_is_animating()); |
| 2259 | EXPECT_FALSE(render_surface1->render_surface() |
| 2260 | ->screen_space_transforms_are_animating()); |
| 2261 | EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating()); |
| 2262 | EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating()); |
| 2263 | EXPECT_TRUE(render_surface2->screen_space_transform_is_animating()); |
| 2264 | EXPECT_TRUE(render_surface2->render_surface() |
| 2265 | ->screen_space_transforms_are_animating()); |
| 2266 | EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating()); |
| 2267 | EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating()); |
| 2268 | |
| 2269 | // Sanity check. If these fail there is probably a bug in the test itself. |
| 2270 | // It is expected that we correctly set up transforms so that the y-component |
| 2271 | // of the screen-space transform encodes the "depth" of the layer in the tree. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2272 | EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3)); |
| 2273 | EXPECT_FLOAT_EQ(2.0, |
| 2274 | child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2275 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2276 | 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2277 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2278 | EXPECT_FLOAT_EQ(2.0, |
| 2279 | render_surface1->screen_space_transform().matrix().get(1, 3)); |
| 2280 | EXPECT_FLOAT_EQ(3.0, |
| 2281 | child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2282 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2283 | 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2284 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2285 | EXPECT_FLOAT_EQ(3.0, |
| 2286 | render_surface2->screen_space_transform().matrix().get(1, 3)); |
| 2287 | EXPECT_FLOAT_EQ(4.0, |
| 2288 | child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2289 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2290 | 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2291 | } |
| 2292 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2293 | TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2294 | // Test the calculateVisibleRect() function works correctly for identity |
| 2295 | // transforms. |
| 2296 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2297 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2298 | gfx::Transform layer_to_surface_transform; |
| 2299 | |
| 2300 | // Case 1: Layer is contained within the surface. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2301 | gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2302 | gfx::Rect expected = gfx::Rect(10, 10, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2303 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2304 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2305 | EXPECT_RECT_EQ(expected, actual); |
| 2306 | |
| 2307 | // Case 2: Layer is outside the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2308 | layer_content_rect = gfx::Rect(120, 120, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2309 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2310 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2311 | EXPECT_TRUE(actual.IsEmpty()); |
| 2312 | |
| 2313 | // Case 3: Layer is partially overlapping the surface rect. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2314 | layer_content_rect = gfx::Rect(80, 80, 30, 30); |
| 2315 | expected = gfx::Rect(80, 80, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2316 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2317 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2318 | EXPECT_RECT_EQ(expected, actual); |
| 2319 | } |
| 2320 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2321 | TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2322 | // Test the calculateVisibleRect() function works correctly for scaling |
| 2323 | // transforms. |
| 2324 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2325 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2326 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2327 | gfx::Transform layer_to_surface_transform; |
| 2328 | |
| 2329 | // Case 1: Layer is contained within the surface. |
| 2330 | layer_to_surface_transform.MakeIdentity(); |
| 2331 | layer_to_surface_transform.Translate(10.0, 10.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2332 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2333 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2334 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2335 | EXPECT_RECT_EQ(expected, actual); |
| 2336 | |
| 2337 | // Case 2: Layer is outside the surface rect. |
| 2338 | layer_to_surface_transform.MakeIdentity(); |
| 2339 | layer_to_surface_transform.Translate(120.0, 120.0); |
| 2340 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2341 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2342 | EXPECT_TRUE(actual.IsEmpty()); |
| 2343 | |
| 2344 | // Case 3: Layer is partially overlapping the surface rect. |
| 2345 | layer_to_surface_transform.MakeIdentity(); |
| 2346 | layer_to_surface_transform.Translate(80.0, 80.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2347 | expected = gfx::Rect(0, 0, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2348 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2349 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2350 | EXPECT_RECT_EQ(expected, actual); |
| 2351 | } |
| 2352 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2353 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2354 | // Test the calculateVisibleRect() function works correctly for rotations |
| 2355 | // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect() |
| 2356 | // should return the g in the layer's space. |
| 2357 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2358 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2359 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2360 | gfx::Transform layer_to_surface_transform; |
| 2361 | |
| 2362 | // Case 1: Layer is contained within the surface. |
| 2363 | layer_to_surface_transform.MakeIdentity(); |
| 2364 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2365 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2366 | gfx::Rect expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2367 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2368 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2369 | EXPECT_RECT_EQ(expected, actual); |
| 2370 | |
| 2371 | // Case 2: Layer is outside the surface rect. |
| 2372 | layer_to_surface_transform.MakeIdentity(); |
| 2373 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2374 | layer_to_surface_transform.Rotate(45.0); |
| 2375 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2376 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2377 | EXPECT_TRUE(actual.IsEmpty()); |
| 2378 | |
| 2379 | // Case 3: The layer is rotated about its top-left corner. In surface space, |
| 2380 | // the layer is oriented diagonally, with the left half outside of the render |
| 2381 | // surface. In this case, the g should still be the entire layer |
| 2382 | // (remember the g is computed in layer space); both the top-left |
| 2383 | // and bottom-right corners of the layer are still visible. |
| 2384 | layer_to_surface_transform.MakeIdentity(); |
| 2385 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2386 | expected = gfx::Rect(0, 0, 30, 30); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2387 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2388 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2389 | EXPECT_RECT_EQ(expected, actual); |
| 2390 | |
| 2391 | // Case 4: The layer is rotated about its top-left corner, and translated |
| 2392 | // upwards. In surface space, the layer is oriented diagonally, with only the |
| 2393 | // top corner of the surface overlapping the layer. In layer space, the render |
| 2394 | // surface overlaps the right side of the layer. The g should be |
| 2395 | // the layer's right half. |
| 2396 | layer_to_surface_transform.MakeIdentity(); |
| 2397 | layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0); |
| 2398 | layer_to_surface_transform.Rotate(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2399 | expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2400 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2401 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2402 | EXPECT_RECT_EQ(expected, actual); |
| 2403 | } |
| 2404 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2405 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2406 | // Test that the calculateVisibleRect() function works correctly for 3d |
| 2407 | // transforms. |
| 2408 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2409 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2410 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2411 | gfx::Transform layer_to_surface_transform; |
| 2412 | |
| 2413 | // Case 1: Orthographic projection of a layer rotated about y-axis by 45 |
| 2414 | // degrees, should be fully contained in the render surface. |
| 2415 | layer_to_surface_transform.MakeIdentity(); |
| 2416 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2417 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2418 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2419 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2420 | EXPECT_RECT_EQ(expected, actual); |
| 2421 | |
| 2422 | // Case 2: Orthographic projection of a layer rotated about y-axis by 45 |
| 2423 | // degrees, but shifted to the side so only the right-half the layer would be |
| 2424 | // visible on the surface. |
| 2425 | // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2426 | SkMScalar half_width_of_rotated_layer = |
| 2427 | SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2428 | layer_to_surface_transform.MakeIdentity(); |
| 2429 | layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2430 | layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left |
| 2431 | // edge of the layer. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2432 | expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2433 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2434 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2435 | EXPECT_RECT_EQ(expected, actual); |
| 2436 | } |
| 2437 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2438 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2439 | // Test the calculateVisibleRect() function works correctly when the layer has |
| 2440 | // a perspective projection onto the target surface. |
| 2441 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2442 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2443 | gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2444 | gfx::Transform layer_to_surface_transform; |
| 2445 | |
| 2446 | // Case 1: Even though the layer is twice as large as the surface, due to |
| 2447 | // perspective foreshortening, the layer will fit fully in the surface when |
| 2448 | // its translated more than the perspective amount. |
| 2449 | layer_to_surface_transform.MakeIdentity(); |
| 2450 | |
| 2451 | // The following sequence of transforms applies the perspective about the |
| 2452 | // center of the surface. |
| 2453 | layer_to_surface_transform.Translate(50.0, 50.0); |
| 2454 | layer_to_surface_transform.ApplyPerspectiveDepth(9.0); |
| 2455 | layer_to_surface_transform.Translate(-50.0, -50.0); |
| 2456 | |
| 2457 | // This translate places the layer in front of the surface's projection plane. |
| 2458 | layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0); |
| 2459 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2460 | gfx::Rect expected = gfx::Rect(-50, -50, 200, 200); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2461 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2462 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2463 | EXPECT_RECT_EQ(expected, actual); |
| 2464 | |
| 2465 | // Case 2: same projection as before, except that the layer is also translated |
| 2466 | // to the side, so that only the right half of the layer should be visible. |
| 2467 | // |
| 2468 | // Explanation of expected result: The perspective ratio is (z distance |
| 2469 | // between layer and camera origin) / (z distance between projection plane and |
| 2470 | // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to |
| 2471 | // move a layer by translating -50 units in projected surface units (so that |
| 2472 | // only half of it is visible), then we would need to translate by (-36 / 9) * |
| 2473 | // -50 == -200 in the layer's units. |
| 2474 | layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2475 | expected = gfx::Rect(gfx::Point(50, -50), |
| 2476 | gfx::Size(100, 200)); // The right half of the layer's |
| 2477 | // bounding rect. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2478 | actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2479 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2480 | EXPECT_RECT_EQ(expected, actual); |
| 2481 | } |
| 2482 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2483 | TEST_F(LayerTreeHostCommonTest, |
| 2484 | VisibleRectFor3dOrthographicIsNotClippedBehindSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2485 | // There is currently no explicit concept of an orthographic projection plane |
| 2486 | // in our code (nor in the CSS spec to my knowledge). Therefore, layers that |
| 2487 | // are technically behind the surface in an orthographic world should not be |
| 2488 | // clipped when they are flattened to the surface. |
| 2489 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2490 | gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100); |
| 2491 | gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2492 | gfx::Transform layer_to_surface_transform; |
| 2493 | |
| 2494 | // This sequence of transforms effectively rotates the layer about the y-axis |
| 2495 | // at the center of the layer. |
| 2496 | layer_to_surface_transform.MakeIdentity(); |
| 2497 | layer_to_surface_transform.Translate(50.0, 0.0); |
| 2498 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2499 | layer_to_surface_transform.Translate(-50.0, 0.0); |
| 2500 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2501 | gfx::Rect expected = gfx::Rect(0, 0, 100, 100); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2502 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2503 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2504 | EXPECT_RECT_EQ(expected, actual); |
| 2505 | } |
| 2506 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2507 | TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2508 | // Test the calculateVisibleRect() function works correctly when projecting a |
| 2509 | // surface onto a layer, but the layer is partially behind the camera (not |
| 2510 | // just behind the projection plane). In this case, the cartesian coordinates |
| 2511 | // may seem to be valid, but actually they are not. The visible rect needs to |
| 2512 | // be properly clipped by the w = 0 plane in homogeneous coordinates before |
| 2513 | // converting to cartesian coordinates. |
| 2514 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2515 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2516 | gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2517 | gfx::Transform layer_to_surface_transform; |
| 2518 | |
| 2519 | // The layer is positioned so that the right half of the layer should be in |
| 2520 | // front of the camera, while the other half is behind the surface's |
| 2521 | // projection plane. The following sequence of transforms applies the |
| 2522 | // perspective and rotation about the center of the layer. |
| 2523 | layer_to_surface_transform.MakeIdentity(); |
| 2524 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2525 | layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0); |
| 2526 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2527 | |
| 2528 | // Sanity check that this transform does indeed cause w < 0 when applying the |
| 2529 | // transform, otherwise this code is not testing the intended scenario. |
| 2530 | bool clipped; |
| 2531 | MathUtil::MapQuad(layer_to_surface_transform, |
| 2532 | gfx::QuadF(gfx::RectF(layer_content_rect)), |
| 2533 | &clipped); |
| 2534 | ASSERT_TRUE(clipped); |
| 2535 | |
| 2536 | int expected_x_position = 0; |
| 2537 | int expected_width = 10; |
| 2538 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2539 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2540 | EXPECT_EQ(expected_x_position, actual.x()); |
| 2541 | EXPECT_EQ(expected_width, actual.width()); |
| 2542 | } |
| 2543 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2544 | TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2545 | // To determine visible rect in layer space, there needs to be an |
| 2546 | // un-projection from surface space to layer space. When the original |
| 2547 | // transform was a perspective projection that was clipped, it returns a rect |
| 2548 | // that encloses the clipped bounds. Un-projecting this new rect may require |
| 2549 | // clipping again. |
| 2550 | |
| 2551 | // This sequence of transforms causes one corner of the layer to protrude |
| 2552 | // across the w = 0 plane, and should be clipped. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2553 | gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100); |
| 2554 | gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2555 | gfx::Transform layer_to_surface_transform; |
| 2556 | layer_to_surface_transform.MakeIdentity(); |
| 2557 | layer_to_surface_transform.ApplyPerspectiveDepth(1.0); |
| 2558 | layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0); |
| 2559 | layer_to_surface_transform.RotateAboutYAxis(45.0); |
| 2560 | layer_to_surface_transform.RotateAboutXAxis(80.0); |
| 2561 | |
| 2562 | // Sanity check that un-projection does indeed cause w < 0, otherwise this |
| 2563 | // code is not testing the intended scenario. |
| 2564 | bool clipped; |
| 2565 | gfx::RectF clipped_rect = |
| 2566 | MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect); |
| 2567 | MathUtil::ProjectQuad( |
| 2568 | Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped); |
| 2569 | ASSERT_TRUE(clipped); |
| 2570 | |
| 2571 | // Only the corner of the layer is not visible on the surface because of being |
| 2572 | // clipped. But, the net result of rounding visible region to an axis-aligned |
| 2573 | // rect is that the entire layer should still be considered visible. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 2574 | gfx::Rect expected = gfx::Rect(-10, -10, 20, 20); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2575 | gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect( |
| 2576 | target_surface_rect, layer_content_rect, layer_to_surface_transform); |
| 2577 | EXPECT_RECT_EQ(expected, actual); |
| 2578 | } |
| 2579 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2580 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2581 | scoped_refptr<Layer> root = Layer::Create(); |
| 2582 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2583 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2584 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2585 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2586 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2587 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2588 | root->AddChild(child1); |
| 2589 | root->AddChild(child2); |
| 2590 | root->AddChild(child3); |
| 2591 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2592 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2593 | host->SetRootLayer(root); |
| 2594 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2595 | gfx::Transform identity_matrix; |
| 2596 | SetLayerPropertiesForTesting(root.get(), |
| 2597 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2598 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2599 | gfx::PointF(), |
| 2600 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2601 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2602 | false); |
| 2603 | SetLayerPropertiesForTesting(child1.get(), |
| 2604 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2605 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2606 | gfx::PointF(), |
| 2607 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2608 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2609 | false); |
| 2610 | SetLayerPropertiesForTesting(child2.get(), |
| 2611 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2612 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2613 | gfx::PointF(75.f, 75.f), |
| 2614 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2615 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2616 | false); |
| 2617 | SetLayerPropertiesForTesting(child3.get(), |
| 2618 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2619 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2620 | gfx::PointF(125.f, 125.f), |
| 2621 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2622 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2623 | false); |
| 2624 | |
| 2625 | ExecuteCalculateDrawProperties(root.get()); |
| 2626 | |
| 2627 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2628 | root->render_surface()->DrawableContentRect()); |
| 2629 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2630 | |
| 2631 | // Layers that do not draw content should have empty visible_content_rects. |
| 2632 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2633 | |
| 2634 | // layer visible_content_rects are clipped by their target surface. |
| 2635 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2636 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
| 2637 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 2638 | |
| 2639 | // layer drawable_content_rects are not clipped. |
| 2640 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect()); |
| 2641 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2642 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 2643 | } |
| 2644 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2645 | TEST_F(LayerTreeHostCommonTest, |
| 2646 | DrawableAndVisibleContentRectsForLayersClippedByLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2647 | scoped_refptr<Layer> root = Layer::Create(); |
| 2648 | scoped_refptr<Layer> child = Layer::Create(); |
| 2649 | scoped_refptr<LayerWithForcedDrawsContent> grand_child1 = |
| 2650 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2651 | scoped_refptr<LayerWithForcedDrawsContent> grand_child2 = |
| 2652 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2653 | scoped_refptr<LayerWithForcedDrawsContent> grand_child3 = |
| 2654 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2655 | root->AddChild(child); |
| 2656 | child->AddChild(grand_child1); |
| 2657 | child->AddChild(grand_child2); |
| 2658 | child->AddChild(grand_child3); |
| 2659 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2660 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2661 | host->SetRootLayer(root); |
| 2662 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2663 | gfx::Transform identity_matrix; |
| 2664 | SetLayerPropertiesForTesting(root.get(), |
| 2665 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2666 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2667 | gfx::PointF(), |
| 2668 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2669 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2670 | false); |
| 2671 | SetLayerPropertiesForTesting(child.get(), |
| 2672 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2673 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2674 | gfx::PointF(), |
| 2675 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2676 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2677 | false); |
| 2678 | SetLayerPropertiesForTesting(grand_child1.get(), |
| 2679 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2680 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2681 | gfx::PointF(5.f, 5.f), |
| 2682 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2683 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2684 | false); |
| 2685 | SetLayerPropertiesForTesting(grand_child2.get(), |
| 2686 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2687 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2688 | gfx::PointF(75.f, 75.f), |
| 2689 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2690 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2691 | false); |
| 2692 | SetLayerPropertiesForTesting(grand_child3.get(), |
| 2693 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2694 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2695 | gfx::PointF(125.f, 125.f), |
| 2696 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2697 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2698 | false); |
| 2699 | |
| 2700 | child->SetMasksToBounds(true); |
| 2701 | ExecuteCalculateDrawProperties(root.get()); |
| 2702 | |
| 2703 | ASSERT_FALSE(child->render_surface()); |
| 2704 | |
| 2705 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2706 | root->render_surface()->DrawableContentRect()); |
| 2707 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2708 | |
| 2709 | // Layers that do not draw content should have empty visible content rects. |
| 2710 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2711 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect()); |
| 2712 | |
| 2713 | // All grandchild visible content rects should be clipped by child. |
| 2714 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect()); |
| 2715 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect()); |
| 2716 | EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty()); |
| 2717 | |
| 2718 | // All grandchild DrawableContentRects should also be clipped by child. |
| 2719 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), |
| 2720 | grand_child1->drawable_content_rect()); |
| 2721 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 25, 25), |
| 2722 | grand_child2->drawable_content_rect()); |
| 2723 | EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty()); |
| 2724 | } |
| 2725 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2726 | TEST_F(LayerTreeHostCommonTest, |
| 2727 | DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2728 | scoped_refptr<Layer> root = Layer::Create(); |
| 2729 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2730 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2731 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2732 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2733 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2734 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2735 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2736 | root->AddChild(render_surface1); |
| 2737 | render_surface1->AddChild(child1); |
| 2738 | render_surface1->AddChild(child2); |
| 2739 | render_surface1->AddChild(child3); |
| 2740 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2741 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2742 | host->SetRootLayer(root); |
| 2743 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2744 | gfx::Transform identity_matrix; |
| 2745 | SetLayerPropertiesForTesting(root.get(), |
| 2746 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2747 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2748 | gfx::PointF(), |
| 2749 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2750 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2751 | false); |
| 2752 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2753 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2754 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2755 | gfx::PointF(), |
| 2756 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2757 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2758 | false); |
| 2759 | SetLayerPropertiesForTesting(child1.get(), |
| 2760 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2761 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2762 | gfx::PointF(5.f, 5.f), |
| 2763 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2764 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2765 | false); |
| 2766 | SetLayerPropertiesForTesting(child2.get(), |
| 2767 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2768 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2769 | gfx::PointF(75.f, 75.f), |
| 2770 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2771 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2772 | false); |
| 2773 | SetLayerPropertiesForTesting(child3.get(), |
| 2774 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2775 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2776 | gfx::PointF(125.f, 125.f), |
| 2777 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2778 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2779 | false); |
| 2780 | |
| 2781 | render_surface1->SetForceRenderSurface(true); |
| 2782 | ExecuteCalculateDrawProperties(root.get()); |
| 2783 | |
| 2784 | ASSERT_TRUE(render_surface1->render_surface()); |
| 2785 | |
| 2786 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 2787 | root->render_surface()->DrawableContentRect()); |
| 2788 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 2789 | |
| 2790 | // Layers that do not draw content should have empty visible content rects. |
| 2791 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 2792 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 2793 | render_surface1->visible_content_rect()); |
| 2794 | |
| 2795 | // An unclipped surface grows its DrawableContentRect to include all drawable |
| 2796 | // regions of the subtree. |
| 2797 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 2798 | render_surface1->render_surface()->DrawableContentRect()); |
| 2799 | |
| 2800 | // All layers that draw content into the unclipped surface are also unclipped. |
| 2801 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 2802 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 2803 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
| 2804 | |
| 2805 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 2806 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 2807 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 2808 | } |
| 2809 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2810 | TEST_F(LayerTreeHostCommonTest, |
| 2811 | DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) { |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2812 | scoped_refptr<Layer> root = Layer::Create(); |
| 2813 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2814 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2815 | root->AddChild(child); |
| 2816 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2817 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2818 | host->SetRootLayer(root); |
| 2819 | |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2820 | // Case 1: a truly degenerate matrix |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2821 | gfx::Transform identity_matrix; |
| 2822 | 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] | 2823 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2824 | |
| 2825 | SetLayerPropertiesForTesting(root.get(), |
| 2826 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2827 | gfx::Point3F(), |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2828 | gfx::PointF(), |
| 2829 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2830 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2831 | false); |
| 2832 | SetLayerPropertiesForTesting(child.get(), |
| 2833 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2834 | gfx::Point3F(), |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2835 | gfx::PointF(5.f, 5.f), |
| 2836 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2837 | true, |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2838 | false); |
| 2839 | |
| 2840 | ExecuteCalculateDrawProperties(root.get()); |
| 2841 | |
| 2842 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2843 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2844 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2845 | // Case 2: a matrix with flattened z, uninvertible and not visible according |
| 2846 | // to the CSS spec. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2847 | uninvertible_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2848 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2849 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2850 | |
| 2851 | SetLayerPropertiesForTesting(child.get(), |
| 2852 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2853 | gfx::Point3F(), |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2854 | gfx::PointF(5.f, 5.f), |
| 2855 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2856 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2857 | false); |
| 2858 | |
| 2859 | ExecuteCalculateDrawProperties(root.get()); |
| 2860 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2861 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
| 2862 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2863 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2864 | // Case 3: a matrix with flattened z, also uninvertible and not visible. |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2865 | uninvertible_matrix.MakeIdentity(); |
| 2866 | uninvertible_matrix.Translate(500.0, 0.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 2867 | uninvertible_matrix.matrix().set(2, 2, 0.0); |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2868 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2869 | |
| 2870 | SetLayerPropertiesForTesting(child.get(), |
| 2871 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2872 | gfx::Point3F(), |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2873 | gfx::PointF(5.f, 5.f), |
| 2874 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2875 | true, |
[email protected] | 630ddad | 2013-08-16 03:01:32 | [diff] [blame] | 2876 | false); |
| 2877 | |
| 2878 | ExecuteCalculateDrawProperties(root.get()); |
| 2879 | |
| 2880 | EXPECT_TRUE(child->visible_content_rect().IsEmpty()); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 2881 | EXPECT_TRUE(child->drawable_content_rect().IsEmpty()); |
[email protected] | 451107a3 | 2013-04-10 05:12:47 | [diff] [blame] | 2882 | } |
| 2883 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2884 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2885 | SingularTransformDoesNotPreventClearingDrawProperties) { |
| 2886 | scoped_refptr<Layer> root = Layer::Create(); |
| 2887 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 2888 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2889 | root->AddChild(child); |
| 2890 | |
| 2891 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2892 | host->SetRootLayer(root); |
| 2893 | |
| 2894 | gfx::Transform identity_matrix; |
| 2895 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 2896 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2897 | |
| 2898 | SetLayerPropertiesForTesting(root.get(), |
| 2899 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2900 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2901 | gfx::PointF(), |
| 2902 | gfx::Size(100, 100), |
| 2903 | true, |
| 2904 | false); |
| 2905 | SetLayerPropertiesForTesting(child.get(), |
| 2906 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2907 | gfx::Point3F(), |
[email protected] | e43c68b | 2014-05-01 05:10:36 | [diff] [blame] | 2908 | gfx::PointF(5.f, 5.f), |
| 2909 | gfx::Size(50, 50), |
| 2910 | true, |
| 2911 | false); |
| 2912 | |
| 2913 | child->draw_properties().sorted_for_recursion = true; |
| 2914 | |
| 2915 | TransformOperations start_transform_operations; |
| 2916 | start_transform_operations.AppendScale(1.f, 0.f, 0.f); |
| 2917 | |
| 2918 | TransformOperations end_transform_operations; |
| 2919 | end_transform_operations.AppendScale(1.f, 1.f, 0.f); |
| 2920 | |
| 2921 | AddAnimatedTransformToLayer( |
| 2922 | root.get(), 10.0, start_transform_operations, end_transform_operations); |
| 2923 | |
| 2924 | EXPECT_TRUE(root->TransformIsAnimating()); |
| 2925 | |
| 2926 | ExecuteCalculateDrawProperties(root.get()); |
| 2927 | |
| 2928 | EXPECT_FALSE(child->draw_properties().sorted_for_recursion); |
| 2929 | } |
| 2930 | |
| 2931 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 2932 | SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) { |
| 2933 | scoped_refptr<Layer> root = Layer::Create(); |
| 2934 | |
| 2935 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2936 | host->SetRootLayer(root); |
| 2937 | |
| 2938 | gfx::Transform identity_matrix; |
| 2939 | gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 2940 | ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| 2941 | |
| 2942 | SetLayerPropertiesForTesting(root.get(), |
| 2943 | uninvertible_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2944 | gfx::Point3F(), |
[email protected] | 8dbc85c | 2014-05-03 03:21:06 | [diff] [blame] | 2945 | gfx::PointF(), |
| 2946 | gfx::Size(100, 100), |
| 2947 | true, |
| 2948 | false); |
| 2949 | |
| 2950 | root->draw_properties().sorted_for_recursion = true; |
| 2951 | |
| 2952 | EXPECT_FALSE(root->TransformIsAnimating()); |
| 2953 | |
| 2954 | ExecuteCalculateDrawProperties(root.get()); |
| 2955 | |
| 2956 | EXPECT_FALSE(root->draw_properties().sorted_for_recursion); |
| 2957 | } |
| 2958 | |
| 2959 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 2960 | DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2961 | scoped_refptr<Layer> root = Layer::Create(); |
| 2962 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 2963 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 2964 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2965 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 2966 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2967 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 2968 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 2969 | root->AddChild(render_surface1); |
| 2970 | render_surface1->AddChild(child1); |
| 2971 | render_surface1->AddChild(child2); |
| 2972 | render_surface1->AddChild(child3); |
| 2973 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 2974 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 2975 | host->SetRootLayer(root); |
| 2976 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2977 | gfx::Transform identity_matrix; |
| 2978 | SetLayerPropertiesForTesting(root.get(), |
| 2979 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2980 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2981 | gfx::PointF(), |
| 2982 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2983 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2984 | false); |
| 2985 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 2986 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2987 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2988 | gfx::PointF(), |
| 2989 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2990 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2991 | false); |
| 2992 | SetLayerPropertiesForTesting(child1.get(), |
| 2993 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 2994 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2995 | gfx::PointF(5.f, 5.f), |
| 2996 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 2997 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 2998 | false); |
| 2999 | SetLayerPropertiesForTesting(child2.get(), |
| 3000 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3001 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3002 | gfx::PointF(75.f, 75.f), |
| 3003 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3004 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3005 | false); |
| 3006 | SetLayerPropertiesForTesting(child3.get(), |
| 3007 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3008 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3009 | gfx::PointF(125.f, 125.f), |
| 3010 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3011 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3012 | false); |
| 3013 | |
| 3014 | root->SetMasksToBounds(true); |
| 3015 | render_surface1->SetForceRenderSurface(true); |
| 3016 | ExecuteCalculateDrawProperties(root.get()); |
| 3017 | |
| 3018 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3019 | |
| 3020 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3021 | root->render_surface()->DrawableContentRect()); |
| 3022 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3023 | |
| 3024 | // Layers that do not draw content should have empty visible content rects. |
| 3025 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3026 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3027 | render_surface1->visible_content_rect()); |
| 3028 | |
| 3029 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3030 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
| 3031 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3032 | render_surface1->render_surface()->DrawableContentRect()); |
| 3033 | |
| 3034 | // All layers that draw content into the surface have their visible content |
| 3035 | // rect clipped by the surface clip rect. |
| 3036 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3037 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect()); |
| 3038 | EXPECT_TRUE(child3->visible_content_rect().IsEmpty()); |
| 3039 | |
| 3040 | // But the DrawableContentRects are unclipped. |
| 3041 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3042 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3043 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 3044 | } |
| 3045 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3046 | TEST_F(LayerTreeHostCommonTest, |
| 3047 | DrawableAndVisibleContentRectsForSurfaceHierarchy) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3048 | // Check that clipping does not propagate down surfaces. |
| 3049 | scoped_refptr<Layer> root = Layer::Create(); |
| 3050 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3051 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 3052 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3053 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3054 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3055 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3056 | scoped_refptr<LayerWithForcedDrawsContent> child3 = |
| 3057 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3058 | root->AddChild(render_surface1); |
| 3059 | render_surface1->AddChild(render_surface2); |
| 3060 | render_surface2->AddChild(child1); |
| 3061 | render_surface2->AddChild(child2); |
| 3062 | render_surface2->AddChild(child3); |
| 3063 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3064 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3065 | host->SetRootLayer(root); |
| 3066 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3067 | gfx::Transform identity_matrix; |
| 3068 | SetLayerPropertiesForTesting(root.get(), |
| 3069 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3070 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3071 | gfx::PointF(), |
| 3072 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3073 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3074 | false); |
| 3075 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3076 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3077 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3078 | gfx::PointF(), |
| 3079 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3080 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3081 | false); |
| 3082 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3083 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3084 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3085 | gfx::PointF(), |
| 3086 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3087 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3088 | false); |
| 3089 | SetLayerPropertiesForTesting(child1.get(), |
| 3090 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3091 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3092 | gfx::PointF(5.f, 5.f), |
| 3093 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3094 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3095 | false); |
| 3096 | SetLayerPropertiesForTesting(child2.get(), |
| 3097 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3098 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3099 | gfx::PointF(75.f, 75.f), |
| 3100 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3101 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3102 | false); |
| 3103 | SetLayerPropertiesForTesting(child3.get(), |
| 3104 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3105 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3106 | gfx::PointF(125.f, 125.f), |
| 3107 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3108 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3109 | false); |
| 3110 | |
| 3111 | root->SetMasksToBounds(true); |
| 3112 | render_surface1->SetForceRenderSurface(true); |
| 3113 | render_surface2->SetForceRenderSurface(true); |
| 3114 | ExecuteCalculateDrawProperties(root.get()); |
| 3115 | |
| 3116 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3117 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3118 | |
| 3119 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3120 | root->render_surface()->DrawableContentRect()); |
| 3121 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3122 | |
| 3123 | // Layers that do not draw content should have empty visible content rects. |
| 3124 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3125 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3126 | render_surface1->visible_content_rect()); |
| 3127 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3128 | render_surface2->visible_content_rect()); |
| 3129 | |
| 3130 | // A clipped surface grows its DrawableContentRect to include all drawable |
| 3131 | // regions of the subtree, but also gets clamped by the ancestor's clip. |
| 3132 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 95, 95), |
| 3133 | render_surface1->render_surface()->DrawableContentRect()); |
| 3134 | |
| 3135 | // render_surface1 lives in the "unclipped universe" of render_surface1, and |
| 3136 | // is only implicitly clipped by render_surface1's content rect. So, |
| 3137 | // render_surface2 grows to enclose all drawable content of its subtree. |
| 3138 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 170, 170), |
| 3139 | render_surface2->render_surface()->DrawableContentRect()); |
| 3140 | |
| 3141 | // All layers that draw content into render_surface2 think they are unclipped. |
| 3142 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3143 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect()); |
| 3144 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect()); |
| 3145 | |
| 3146 | // DrawableContentRects are also unclipped. |
| 3147 | EXPECT_RECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect()); |
| 3148 | EXPECT_RECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect()); |
| 3149 | EXPECT_RECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect()); |
| 3150 | } |
| 3151 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3152 | TEST_F(LayerTreeHostCommonTest, |
| 3153 | DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3154 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3155 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3156 | |
| 3157 | scoped_refptr<Layer> root = Layer::Create(); |
| 3158 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3159 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3160 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3161 | root->AddChild(render_surface1); |
| 3162 | render_surface1->AddChild(child1); |
| 3163 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3164 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3165 | host->SetRootLayer(root); |
| 3166 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3167 | gfx::Transform identity_matrix; |
| 3168 | gfx::Transform child_rotation; |
| 3169 | child_rotation.Rotate(45.0); |
| 3170 | SetLayerPropertiesForTesting(root.get(), |
| 3171 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3172 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3173 | gfx::PointF(), |
| 3174 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3175 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3176 | false); |
| 3177 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3178 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3179 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3180 | gfx::PointF(), |
| 3181 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3182 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3183 | false); |
| 3184 | SetLayerPropertiesForTesting(child1.get(), |
| 3185 | child_rotation, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3186 | gfx::Point3F(25, 25, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3187 | gfx::PointF(25.f, 25.f), |
| 3188 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3189 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3190 | false); |
| 3191 | |
| 3192 | render_surface1->SetForceRenderSurface(true); |
| 3193 | ExecuteCalculateDrawProperties(root.get()); |
| 3194 | |
| 3195 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3196 | |
| 3197 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), |
| 3198 | root->render_surface()->DrawableContentRect()); |
| 3199 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect()); |
| 3200 | |
| 3201 | // Layers that do not draw content should have empty visible content rects. |
| 3202 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3203 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), |
| 3204 | render_surface1->visible_content_rect()); |
| 3205 | |
| 3206 | // The unclipped surface grows its DrawableContentRect to include all drawable |
| 3207 | // regions of the subtree. |
| 3208 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
| 3209 | gfx::Rect expected_surface_drawable_content = |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3210 | gfx::Rect(50 - diagonal_radius, |
| 3211 | 50 - diagonal_radius, |
| 3212 | diagonal_radius * 2, |
| 3213 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3214 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3215 | render_surface1->render_surface()->DrawableContentRect()); |
| 3216 | |
| 3217 | // All layers that draw content into the unclipped surface are also unclipped. |
| 3218 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect()); |
| 3219 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3220 | child1->drawable_content_rect()); |
| 3221 | } |
| 3222 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3223 | TEST_F(LayerTreeHostCommonTest, |
| 3224 | DrawableAndVisibleContentRectsWithTransformOnClippedSurface) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3225 | // Layers that have non-axis aligned bounds (due to transforms) have an |
| 3226 | // expanded, axis-aligned DrawableContentRect and visible content rect. |
| 3227 | |
| 3228 | scoped_refptr<Layer> root = Layer::Create(); |
| 3229 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 3230 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3231 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3232 | root->AddChild(render_surface1); |
| 3233 | render_surface1->AddChild(child1); |
| 3234 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3235 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3236 | host->SetRootLayer(root); |
| 3237 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3238 | gfx::Transform identity_matrix; |
| 3239 | gfx::Transform child_rotation; |
| 3240 | child_rotation.Rotate(45.0); |
| 3241 | SetLayerPropertiesForTesting(root.get(), |
| 3242 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3243 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3244 | gfx::PointF(), |
| 3245 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3246 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3247 | false); |
| 3248 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3249 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3250 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3251 | gfx::PointF(), |
| 3252 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3253 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3254 | false); |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3255 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3256 | SetLayerPropertiesForTesting(child1.get(), |
| 3257 | child_rotation, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3258 | gfx::Point3F(25, 25, 0.f), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3259 | gfx::PointF(25.f, 25.f), |
| 3260 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3261 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3262 | false); |
| 3263 | |
| 3264 | root->SetMasksToBounds(true); |
| 3265 | render_surface1->SetForceRenderSurface(true); |
| 3266 | ExecuteCalculateDrawProperties(root.get()); |
| 3267 | |
| 3268 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3269 | |
| 3270 | // The clipped surface clamps the DrawableContentRect that encloses the |
| 3271 | // rotated layer. |
| 3272 | int diagonal_radius = ceil(sqrt(2.0) * 25.0); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3273 | gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius, |
| 3274 | 50 - diagonal_radius, |
| 3275 | diagonal_radius * 2, |
| 3276 | diagonal_radius * 2); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3277 | gfx::Rect expected_surface_drawable_content = |
| 3278 | gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50)); |
| 3279 | EXPECT_RECT_EQ(expected_surface_drawable_content, |
| 3280 | render_surface1->render_surface()->DrawableContentRect()); |
| 3281 | |
| 3282 | // On the clipped surface, only a quarter of the child1 is visible, but when |
| 3283 | // rotating it back to child1's content space, the actual enclosing rect ends |
| 3284 | // up covering the full left half of child1. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 3285 | // |
| 3286 | // Given the floating point math, this number is a little bit fuzzy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3287 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect()); |
| 3288 | |
| 3289 | // The child's DrawableContentRect is unclipped. |
| 3290 | EXPECT_RECT_EQ(unclipped_surface_content, child1->drawable_content_rect()); |
| 3291 | } |
| 3292 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3293 | TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3294 | MockContentLayerClient client; |
| 3295 | |
| 3296 | scoped_refptr<Layer> root = Layer::Create(); |
| 3297 | scoped_refptr<ContentLayer> render_surface1 = |
| 3298 | CreateDrawableContentLayer(&client); |
| 3299 | scoped_refptr<ContentLayer> render_surface2 = |
| 3300 | CreateDrawableContentLayer(&client); |
| 3301 | scoped_refptr<ContentLayer> child1 = CreateDrawableContentLayer(&client); |
| 3302 | scoped_refptr<ContentLayer> child2 = CreateDrawableContentLayer(&client); |
| 3303 | scoped_refptr<ContentLayer> child3 = CreateDrawableContentLayer(&client); |
| 3304 | root->AddChild(render_surface1); |
| 3305 | render_surface1->AddChild(render_surface2); |
| 3306 | render_surface2->AddChild(child1); |
| 3307 | render_surface2->AddChild(child2); |
| 3308 | render_surface2->AddChild(child3); |
| 3309 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3310 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3311 | host->SetRootLayer(root); |
| 3312 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3313 | gfx::Transform identity_matrix; |
| 3314 | SetLayerPropertiesForTesting(root.get(), |
| 3315 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3316 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3317 | gfx::PointF(), |
| 3318 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3319 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3320 | false); |
| 3321 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 3322 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3323 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3324 | gfx::PointF(5.f, 5.f), |
| 3325 | gfx::Size(3, 4), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3326 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3327 | false); |
| 3328 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 3329 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3330 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3331 | gfx::PointF(5.f, 5.f), |
| 3332 | gfx::Size(7, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3333 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3334 | false); |
| 3335 | SetLayerPropertiesForTesting(child1.get(), |
| 3336 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3337 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3338 | gfx::PointF(5.f, 5.f), |
| 3339 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3340 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3341 | false); |
| 3342 | SetLayerPropertiesForTesting(child2.get(), |
| 3343 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3344 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3345 | gfx::PointF(75.f, 75.f), |
| 3346 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3347 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3348 | false); |
| 3349 | SetLayerPropertiesForTesting(child3.get(), |
| 3350 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3351 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3352 | gfx::PointF(125.f, 125.f), |
| 3353 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3354 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3355 | false); |
| 3356 | |
| 3357 | float device_scale_factor = 2.f; |
| 3358 | |
| 3359 | root->SetMasksToBounds(true); |
| 3360 | render_surface1->SetForceRenderSurface(true); |
| 3361 | render_surface2->SetForceRenderSurface(true); |
| 3362 | ExecuteCalculateDrawProperties(root.get(), device_scale_factor); |
| 3363 | |
| 3364 | ASSERT_TRUE(render_surface1->render_surface()); |
| 3365 | ASSERT_TRUE(render_surface2->render_surface()); |
| 3366 | |
| 3367 | // drawable_content_rects for all layers and surfaces are scaled by |
| 3368 | // device_scale_factor. |
| 3369 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), |
| 3370 | root->render_surface()->DrawableContentRect()); |
| 3371 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect()); |
| 3372 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 190, 190), |
| 3373 | render_surface1->render_surface()->DrawableContentRect()); |
| 3374 | |
| 3375 | // render_surface2 lives in the "unclipped universe" of render_surface1, and |
| 3376 | // is only implicitly clipped by render_surface1. |
| 3377 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 350, 350), |
| 3378 | render_surface2->render_surface()->DrawableContentRect()); |
| 3379 | |
| 3380 | EXPECT_RECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect()); |
| 3381 | EXPECT_RECT_EQ(gfx::Rect(150, 150, 100, 100), |
| 3382 | child2->drawable_content_rect()); |
| 3383 | EXPECT_RECT_EQ(gfx::Rect(250, 250, 100, 100), |
| 3384 | child3->drawable_content_rect()); |
| 3385 | |
| 3386 | // The root layer does not actually draw content of its own. |
| 3387 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect()); |
| 3388 | |
| 3389 | // All layer visible content rects are expressed in content space of each |
| 3390 | // layer, so they are also scaled by the device_scale_factor. |
| 3391 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 6, 8), |
| 3392 | render_surface1->visible_content_rect()); |
| 3393 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 14, 26), |
| 3394 | render_surface2->visible_content_rect()); |
| 3395 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child1->visible_content_rect()); |
| 3396 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child2->visible_content_rect()); |
| 3397 | EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), child3->visible_content_rect()); |
| 3398 | } |
| 3399 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3400 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3401 | // Verify the behavior of back-face culling when there are no preserve-3d |
| 3402 | // layers. Note that 3d transforms still apply in this case, but they are |
| 3403 | // "flattened" to each parent layer according to current W3C spec. |
| 3404 | |
| 3405 | const gfx::Transform identity_matrix; |
| 3406 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3407 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3408 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3409 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3410 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3411 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3412 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3413 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3414 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3415 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3416 | front_facing_child_of_front_facing_surface = |
| 3417 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3418 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3419 | back_facing_child_of_front_facing_surface = |
| 3420 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3421 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3422 | front_facing_child_of_back_facing_surface = |
| 3423 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3424 | scoped_refptr<LayerWithForcedDrawsContent> |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3425 | back_facing_child_of_back_facing_surface = |
| 3426 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3427 | |
| 3428 | parent->AddChild(front_facing_child); |
| 3429 | parent->AddChild(back_facing_child); |
| 3430 | parent->AddChild(front_facing_surface); |
| 3431 | parent->AddChild(back_facing_surface); |
| 3432 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3433 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3434 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3435 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3436 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3437 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3438 | host->SetRootLayer(parent); |
| 3439 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3440 | // Nothing is double-sided |
| 3441 | front_facing_child->SetDoubleSided(false); |
| 3442 | back_facing_child->SetDoubleSided(false); |
| 3443 | front_facing_surface->SetDoubleSided(false); |
| 3444 | back_facing_surface->SetDoubleSided(false); |
| 3445 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3446 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3447 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3448 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3449 | |
| 3450 | gfx::Transform backface_matrix; |
| 3451 | backface_matrix.Translate(50.0, 50.0); |
| 3452 | backface_matrix.RotateAboutYAxis(180.0); |
| 3453 | backface_matrix.Translate(-50.0, -50.0); |
| 3454 | |
| 3455 | // Having a descendant and opacity will force these to have render surfaces. |
| 3456 | front_facing_surface->SetOpacity(0.5f); |
| 3457 | back_facing_surface->SetOpacity(0.5f); |
| 3458 | |
| 3459 | // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec, |
| 3460 | // these layers should blindly use their own local transforms to determine |
| 3461 | // back-face culling. |
| 3462 | SetLayerPropertiesForTesting(parent.get(), |
| 3463 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3464 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3465 | gfx::PointF(), |
| 3466 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3467 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3468 | false); |
| 3469 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3470 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3471 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3472 | gfx::PointF(), |
| 3473 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3474 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3475 | false); |
| 3476 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3477 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3478 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3479 | gfx::PointF(), |
| 3480 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3481 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3482 | false); |
| 3483 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3484 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3485 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3486 | gfx::PointF(), |
| 3487 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3488 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3489 | false); |
| 3490 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3491 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3492 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3493 | gfx::PointF(), |
| 3494 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3495 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3496 | false); |
| 3497 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3498 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3499 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3500 | gfx::PointF(), |
| 3501 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3502 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3503 | false); |
| 3504 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3505 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3506 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3507 | gfx::PointF(), |
| 3508 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3509 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3510 | false); |
| 3511 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3512 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3513 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3514 | gfx::PointF(), |
| 3515 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3516 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3517 | false); |
| 3518 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3519 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3520 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3521 | gfx::PointF(), |
| 3522 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3523 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3524 | false); |
| 3525 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3526 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3527 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3528 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3529 | inputs.can_adjust_raster_scales = true; |
| 3530 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3531 | |
| 3532 | // Verify which render surfaces were created. |
| 3533 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3534 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3535 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3536 | EXPECT_TRUE(back_facing_surface->render_surface()); |
| 3537 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3538 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3539 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3540 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3541 | |
| 3542 | // Verify the render_surface_layer_list. |
| 3543 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3544 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3545 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3546 | // Even though the back facing surface LAYER gets culled, the other |
| 3547 | // descendants should still be added, so the SURFACE should not be culled. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3548 | EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3549 | |
| 3550 | // Verify root surface's layer list. |
| 3551 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3552 | 3u, |
| 3553 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3554 | EXPECT_EQ(front_facing_child->id(), |
| 3555 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3556 | ->render_surface() |
| 3557 | ->layer_list() |
| 3558 | .at(0) |
| 3559 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3560 | EXPECT_EQ(front_facing_surface->id(), |
| 3561 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3562 | ->render_surface() |
| 3563 | ->layer_list() |
| 3564 | .at(1) |
| 3565 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3566 | EXPECT_EQ(back_facing_surface->id(), |
| 3567 | render_surface_layer_list.at(0) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3568 | ->render_surface() |
| 3569 | ->layer_list() |
| 3570 | .at(2) |
| 3571 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3572 | |
| 3573 | // Verify front_facing_surface's layer list. |
| 3574 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3575 | 2u, |
| 3576 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3577 | EXPECT_EQ(front_facing_surface->id(), |
| 3578 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3579 | ->render_surface() |
| 3580 | ->layer_list() |
| 3581 | .at(0) |
| 3582 | ->id()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3583 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3584 | render_surface_layer_list.at(1) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3585 | ->render_surface() |
| 3586 | ->layer_list() |
| 3587 | .at(1) |
| 3588 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3589 | |
| 3590 | // Verify back_facing_surface's layer list; its own layer should be culled |
| 3591 | // from the surface list. |
| 3592 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3593 | 1u, |
| 3594 | render_surface_layer_list.at(2)->render_surface()->layer_list().size()); |
| 3595 | EXPECT_EQ(front_facing_child_of_back_facing_surface->id(), |
| 3596 | render_surface_layer_list.at(2) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3597 | ->render_surface() |
| 3598 | ->layer_list() |
| 3599 | .at(0) |
| 3600 | ->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3601 | } |
| 3602 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3603 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3604 | // Verify the behavior of back-face culling when preserves-3d transform style |
| 3605 | // is used. |
| 3606 | |
| 3607 | const gfx::Transform identity_matrix; |
| 3608 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3609 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = |
| 3610 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3611 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_child = |
| 3612 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3613 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3614 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3615 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3616 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3617 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3618 | front_facing_child_of_front_facing_surface = |
| 3619 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3620 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3621 | back_facing_child_of_front_facing_surface = |
| 3622 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3623 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3624 | front_facing_child_of_back_facing_surface = |
| 3625 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3626 | scoped_refptr<LayerWithForcedDrawsContent> |
| 3627 | back_facing_child_of_back_facing_surface = |
| 3628 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3629 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 = |
| 3630 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3631 | scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 = |
| 3632 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3633 | |
| 3634 | parent->AddChild(front_facing_child); |
| 3635 | parent->AddChild(back_facing_child); |
| 3636 | parent->AddChild(front_facing_surface); |
| 3637 | parent->AddChild(back_facing_surface); |
| 3638 | front_facing_surface->AddChild(front_facing_child_of_front_facing_surface); |
| 3639 | front_facing_surface->AddChild(back_facing_child_of_front_facing_surface); |
| 3640 | back_facing_surface->AddChild(front_facing_child_of_back_facing_surface); |
| 3641 | back_facing_surface->AddChild(back_facing_child_of_back_facing_surface); |
| 3642 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3643 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3644 | host->SetRootLayer(parent); |
| 3645 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3646 | // Nothing is double-sided |
| 3647 | front_facing_child->SetDoubleSided(false); |
| 3648 | back_facing_child->SetDoubleSided(false); |
| 3649 | front_facing_surface->SetDoubleSided(false); |
| 3650 | back_facing_surface->SetDoubleSided(false); |
| 3651 | front_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3652 | back_facing_child_of_front_facing_surface->SetDoubleSided(false); |
| 3653 | front_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3654 | back_facing_child_of_back_facing_surface->SetDoubleSided(false); |
| 3655 | |
| 3656 | gfx::Transform backface_matrix; |
| 3657 | backface_matrix.Translate(50.0, 50.0); |
| 3658 | backface_matrix.RotateAboutYAxis(180.0); |
| 3659 | backface_matrix.Translate(-50.0, -50.0); |
| 3660 | |
| 3661 | // Opacity will not force creation of render surfaces in this case because of |
| 3662 | // the preserve-3d transform style. Instead, an example of when a surface |
| 3663 | // would be created with preserve-3d is when there is a replica layer. |
| 3664 | front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get()); |
| 3665 | back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get()); |
| 3666 | |
| 3667 | // Each surface creates its own new 3d rendering context (as defined by W3C |
| 3668 | // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d |
| 3669 | // rendering context should use the transform with respect to that context. |
| 3670 | // This 3d rendering context occurs when (a) parent's transform style is flat |
| 3671 | // and (b) the layer's transform style is preserve-3d. |
| 3672 | SetLayerPropertiesForTesting(parent.get(), |
| 3673 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3674 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3675 | gfx::PointF(), |
| 3676 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3677 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3678 | false); // parent transform style is flat. |
| 3679 | SetLayerPropertiesForTesting(front_facing_child.get(), |
| 3680 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3681 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3682 | gfx::PointF(), |
| 3683 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3684 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3685 | false); |
| 3686 | SetLayerPropertiesForTesting(back_facing_child.get(), |
| 3687 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3688 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3689 | gfx::PointF(), |
| 3690 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3691 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3692 | false); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3693 | // surface transform style is preserve-3d. |
| 3694 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3695 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3696 | gfx::Point3F(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3697 | gfx::PointF(), |
| 3698 | gfx::Size(100, 100), |
| 3699 | false, |
| 3700 | true); |
| 3701 | // surface transform style is preserve-3d. |
| 3702 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3703 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3704 | gfx::Point3F(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3705 | gfx::PointF(), |
| 3706 | gfx::Size(100, 100), |
| 3707 | false, |
| 3708 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3709 | SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(), |
| 3710 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3711 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3712 | gfx::PointF(), |
| 3713 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3714 | true, |
| 3715 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3716 | SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(), |
| 3717 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3718 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3719 | gfx::PointF(), |
| 3720 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3721 | true, |
| 3722 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3723 | SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(), |
| 3724 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3725 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3726 | gfx::PointF(), |
| 3727 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3728 | true, |
| 3729 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3730 | SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), |
| 3731 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3732 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3733 | gfx::PointF(), |
| 3734 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3735 | true, |
| 3736 | true); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3737 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3738 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3739 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3740 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3741 | inputs.can_adjust_raster_scales = true; |
| 3742 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3743 | |
| 3744 | // Verify which render surfaces were created. |
| 3745 | EXPECT_FALSE(front_facing_child->render_surface()); |
| 3746 | EXPECT_FALSE(back_facing_child->render_surface()); |
| 3747 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 3748 | EXPECT_FALSE(back_facing_surface->render_surface()); |
| 3749 | EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); |
| 3750 | EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); |
| 3751 | EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); |
| 3752 | EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); |
| 3753 | |
| 3754 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 3755 | // culled. |
| 3756 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3757 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3758 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3759 | |
| 3760 | // Verify root surface's layer list. |
| 3761 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3762 | 2u, |
| 3763 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3764 | EXPECT_EQ(front_facing_child->id(), |
| 3765 | render_surface_layer_list.at(0) |
| 3766 | ->render_surface()->layer_list().at(0)->id()); |
| 3767 | EXPECT_EQ(front_facing_surface->id(), |
| 3768 | render_surface_layer_list.at(0) |
| 3769 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3770 | |
| 3771 | // Verify front_facing_surface's layer list. |
| 3772 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3773 | 2u, |
| 3774 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3775 | EXPECT_EQ(front_facing_surface->id(), |
| 3776 | render_surface_layer_list.at(1) |
| 3777 | ->render_surface()->layer_list().at(0)->id()); |
| 3778 | EXPECT_EQ(front_facing_child_of_front_facing_surface->id(), |
| 3779 | render_surface_layer_list.at(1) |
| 3780 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3781 | } |
| 3782 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3783 | TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3784 | // Verify that layers are appropriately culled when their back face is showing |
| 3785 | // and they are not double sided, while animations are going on. |
| 3786 | // |
| 3787 | // Layers that are animating do not get culled on the main thread, as their |
| 3788 | // transforms should be treated as "unknown" so we can not be sure that their |
| 3789 | // back face is really showing. |
| 3790 | const gfx::Transform identity_matrix; |
| 3791 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3792 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 3793 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3794 | scoped_refptr<LayerWithForcedDrawsContent> animating_surface = |
| 3795 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3796 | scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface = |
| 3797 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3798 | scoped_refptr<LayerWithForcedDrawsContent> animating_child = |
| 3799 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3800 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3801 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3802 | |
| 3803 | parent->AddChild(child); |
| 3804 | parent->AddChild(animating_surface); |
| 3805 | animating_surface->AddChild(child_of_animating_surface); |
| 3806 | parent->AddChild(animating_child); |
| 3807 | parent->AddChild(child2); |
| 3808 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3809 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3810 | host->SetRootLayer(parent); |
| 3811 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3812 | // Nothing is double-sided |
| 3813 | child->SetDoubleSided(false); |
| 3814 | child2->SetDoubleSided(false); |
| 3815 | animating_surface->SetDoubleSided(false); |
| 3816 | child_of_animating_surface->SetDoubleSided(false); |
| 3817 | animating_child->SetDoubleSided(false); |
| 3818 | |
| 3819 | gfx::Transform backface_matrix; |
| 3820 | backface_matrix.Translate(50.0, 50.0); |
| 3821 | backface_matrix.RotateAboutYAxis(180.0); |
| 3822 | backface_matrix.Translate(-50.0, -50.0); |
| 3823 | |
| 3824 | // Make our render surface. |
| 3825 | animating_surface->SetForceRenderSurface(true); |
| 3826 | |
| 3827 | // Animate the transform on the render surface. |
| 3828 | AddAnimatedTransformToController( |
| 3829 | animating_surface->layer_animation_controller(), 10.0, 30, 0); |
| 3830 | // This is just an animating layer, not a surface. |
| 3831 | AddAnimatedTransformToController( |
| 3832 | animating_child->layer_animation_controller(), 10.0, 30, 0); |
| 3833 | |
| 3834 | SetLayerPropertiesForTesting(parent.get(), |
| 3835 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3836 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3837 | gfx::PointF(), |
| 3838 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3839 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3840 | false); |
| 3841 | SetLayerPropertiesForTesting(child.get(), |
| 3842 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3843 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3844 | gfx::PointF(), |
| 3845 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3846 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3847 | false); |
| 3848 | SetLayerPropertiesForTesting(animating_surface.get(), |
| 3849 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3850 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3851 | gfx::PointF(), |
| 3852 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3853 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3854 | false); |
| 3855 | SetLayerPropertiesForTesting(child_of_animating_surface.get(), |
| 3856 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3857 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3858 | gfx::PointF(), |
| 3859 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3860 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3861 | false); |
| 3862 | SetLayerPropertiesForTesting(animating_child.get(), |
| 3863 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3864 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3865 | gfx::PointF(), |
| 3866 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3867 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3868 | false); |
| 3869 | SetLayerPropertiesForTesting(child2.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); |
| 3876 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3877 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 3878 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 3879 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 3880 | inputs.can_adjust_raster_scales = true; |
| 3881 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3882 | |
| 3883 | EXPECT_FALSE(child->render_surface()); |
| 3884 | EXPECT_TRUE(animating_surface->render_surface()); |
| 3885 | EXPECT_FALSE(child_of_animating_surface->render_surface()); |
| 3886 | EXPECT_FALSE(animating_child->render_surface()); |
| 3887 | EXPECT_FALSE(child2->render_surface()); |
| 3888 | |
| 3889 | // Verify that the animating_child and child_of_animating_surface were not |
| 3890 | // culled, but that child was. |
| 3891 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3892 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 3893 | EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3894 | |
| 3895 | // The non-animating child be culled from the layer list for the parent render |
| 3896 | // surface. |
| 3897 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3898 | 3u, |
| 3899 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 3900 | EXPECT_EQ(animating_surface->id(), |
| 3901 | render_surface_layer_list.at(0) |
| 3902 | ->render_surface()->layer_list().at(0)->id()); |
| 3903 | EXPECT_EQ(animating_child->id(), |
| 3904 | render_surface_layer_list.at(0) |
| 3905 | ->render_surface()->layer_list().at(1)->id()); |
| 3906 | EXPECT_EQ(child2->id(), |
| 3907 | render_surface_layer_list.at(0) |
| 3908 | ->render_surface()->layer_list().at(2)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3909 | |
| 3910 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3911 | 2u, |
| 3912 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 3913 | EXPECT_EQ(animating_surface->id(), |
| 3914 | render_surface_layer_list.at(1) |
| 3915 | ->render_surface()->layer_list().at(0)->id()); |
| 3916 | EXPECT_EQ(child_of_animating_surface->id(), |
| 3917 | render_surface_layer_list.at(1) |
| 3918 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3919 | |
| 3920 | EXPECT_FALSE(child2->visible_content_rect().IsEmpty()); |
| 3921 | |
| 3922 | // The animating layers should have a visible content rect that represents the |
| 3923 | // area of the front face that is within the viewport. |
| 3924 | EXPECT_EQ(animating_child->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3925 | gfx::Rect(animating_child->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3926 | EXPECT_EQ(animating_surface->visible_content_rect(), |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 3927 | gfx::Rect(animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3928 | // And layers in the subtree of the animating layer should have valid visible |
| 3929 | // content rects also. |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3930 | EXPECT_EQ(child_of_animating_surface->visible_content_rect(), |
| 3931 | gfx::Rect(child_of_animating_surface->content_bounds())); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3932 | } |
| 3933 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 3934 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3935 | BackFaceCullingWithPreserves3dForFlatteningSurface) { |
| 3936 | // Verify the behavior of back-face culling for a render surface that is |
| 3937 | // created when it flattens its subtree, and its parent has preserves-3d. |
| 3938 | |
| 3939 | const gfx::Transform identity_matrix; |
| 3940 | scoped_refptr<Layer> parent = Layer::Create(); |
| 3941 | scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface = |
| 3942 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3943 | scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface = |
| 3944 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3945 | scoped_refptr<LayerWithForcedDrawsContent> child1 = |
| 3946 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3947 | scoped_refptr<LayerWithForcedDrawsContent> child2 = |
| 3948 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 3949 | |
| 3950 | parent->AddChild(front_facing_surface); |
| 3951 | parent->AddChild(back_facing_surface); |
| 3952 | front_facing_surface->AddChild(child1); |
| 3953 | back_facing_surface->AddChild(child2); |
| 3954 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 3955 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 3956 | host->SetRootLayer(parent); |
| 3957 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3958 | // RenderSurfaces are not double-sided |
| 3959 | front_facing_surface->SetDoubleSided(false); |
| 3960 | back_facing_surface->SetDoubleSided(false); |
| 3961 | |
| 3962 | gfx::Transform backface_matrix; |
| 3963 | backface_matrix.Translate(50.0, 50.0); |
| 3964 | backface_matrix.RotateAboutYAxis(180.0); |
| 3965 | backface_matrix.Translate(-50.0, -50.0); |
| 3966 | |
| 3967 | SetLayerPropertiesForTesting(parent.get(), |
| 3968 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3969 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3970 | gfx::PointF(), |
| 3971 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3972 | false, |
| 3973 | true); // parent transform style is preserve3d. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3974 | SetLayerPropertiesForTesting(front_facing_surface.get(), |
| 3975 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3976 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3977 | gfx::PointF(), |
| 3978 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3979 | true, |
| 3980 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3981 | SetLayerPropertiesForTesting(back_facing_surface.get(), |
| 3982 | backface_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3983 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3984 | gfx::PointF(), |
| 3985 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3986 | true, |
| 3987 | true); // surface transform style is flat. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3988 | SetLayerPropertiesForTesting(child1.get(), |
| 3989 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3990 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3991 | gfx::PointF(), |
| 3992 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 3993 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3994 | false); |
| 3995 | SetLayerPropertiesForTesting(child2.get(), |
| 3996 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 3997 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 3998 | gfx::PointF(), |
| 3999 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4000 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4001 | false); |
| 4002 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4003 | front_facing_surface->SetIs3dSorted(true); |
| 4004 | back_facing_surface->SetIs3dSorted(true); |
| 4005 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4006 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4007 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4008 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4009 | inputs.can_adjust_raster_scales = true; |
| 4010 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4011 | |
| 4012 | // Verify which render surfaces were created. |
| 4013 | EXPECT_TRUE(front_facing_surface->render_surface()); |
| 4014 | EXPECT_FALSE( |
| 4015 | back_facing_surface->render_surface()); // because it should be culled |
| 4016 | EXPECT_FALSE(child1->render_surface()); |
| 4017 | EXPECT_FALSE(child2->render_surface()); |
| 4018 | |
| 4019 | // Verify the render_surface_layer_list. The back-facing surface should be |
| 4020 | // culled. |
| 4021 | ASSERT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4022 | EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); |
| 4023 | EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4024 | |
| 4025 | // Verify root surface's layer list. |
| 4026 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4027 | 1u, |
| 4028 | render_surface_layer_list.at(0)->render_surface()->layer_list().size()); |
| 4029 | EXPECT_EQ(front_facing_surface->id(), |
| 4030 | render_surface_layer_list.at(0) |
| 4031 | ->render_surface()->layer_list().at(0)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4032 | |
| 4033 | // Verify front_facing_surface's layer list. |
| 4034 | ASSERT_EQ( |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4035 | 2u, |
| 4036 | render_surface_layer_list.at(1)->render_surface()->layer_list().size()); |
| 4037 | EXPECT_EQ(front_facing_surface->id(), |
| 4038 | render_surface_layer_list.at(1) |
| 4039 | ->render_surface()->layer_list().at(0)->id()); |
| 4040 | EXPECT_EQ(child1->id(), |
| 4041 | render_surface_layer_list.at(1) |
| 4042 | ->render_surface()->layer_list().at(1)->id()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4043 | } |
| 4044 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4045 | class NoScaleContentLayer : public ContentLayer { |
| 4046 | public: |
| 4047 | static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
| 4048 | return make_scoped_refptr(new NoScaleContentLayer(client)); |
| 4049 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4050 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4051 | virtual void CalculateContentsScale(float ideal_contents_scale, |
[email protected] | b673495c | 2013-05-07 17:16:06 | [diff] [blame] | 4052 | float device_scale_factor, |
| 4053 | float page_scale_factor, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 4054 | float maximum_animation_contents_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4055 | bool animating_transform_to_screen, |
| 4056 | float* contents_scale_x, |
| 4057 | float* contents_scale_y, |
| 4058 | gfx::Size* content_bounds) OVERRIDE { |
| 4059 | // Skip over the ContentLayer to the base Layer class. |
| 4060 | Layer::CalculateContentsScale(ideal_contents_scale, |
[email protected] | b673495c | 2013-05-07 17:16:06 | [diff] [blame] | 4061 | device_scale_factor, |
| 4062 | page_scale_factor, |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 4063 | maximum_animation_contents_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4064 | animating_transform_to_screen, |
| 4065 | contents_scale_x, |
| 4066 | contents_scale_y, |
| 4067 | content_bounds); |
| 4068 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4069 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4070 | protected: |
| 4071 | explicit NoScaleContentLayer(ContentLayerClient* client) |
| 4072 | : ContentLayer(client) {} |
| 4073 | virtual ~NoScaleContentLayer() {} |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4074 | }; |
| 4075 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4076 | scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer( |
| 4077 | ContentLayerClient* delegate) { |
| 4078 | scoped_refptr<NoScaleContentLayer> to_return = |
| 4079 | NoScaleContentLayer::Create(delegate); |
| 4080 | to_return->SetIsDrawable(true); |
| 4081 | return to_return; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4082 | } |
| 4083 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4084 | TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4085 | // Verify draw and screen space transforms of layers not in a surface. |
| 4086 | MockContentLayerClient delegate; |
| 4087 | gfx::Transform identity_matrix; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4088 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4089 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4090 | SetLayerPropertiesForTesting(parent.get(), |
| 4091 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4092 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4093 | gfx::PointF(), |
| 4094 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4095 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4096 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4097 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4098 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 4099 | SetLayerPropertiesForTesting(child.get(), |
| 4100 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4101 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4102 | gfx::PointF(2.f, 2.f), |
| 4103 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4104 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4105 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4106 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4107 | scoped_refptr<ContentLayer> child_empty = |
| 4108 | CreateDrawableContentLayer(&delegate); |
| 4109 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4110 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4111 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4112 | gfx::PointF(2.f, 2.f), |
| 4113 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4114 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4115 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4116 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4117 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4118 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4119 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4120 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4121 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4122 | gfx::PointF(2.f, 2.f), |
| 4123 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4124 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4125 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4126 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4127 | parent->AddChild(child); |
| 4128 | parent->AddChild(child_empty); |
| 4129 | parent->AddChild(child_no_scale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4130 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4131 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 4132 | host->SetRootLayer(parent); |
| 4133 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4134 | float device_scale_factor = 2.5f; |
| 4135 | float page_scale_factor = 1.f; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4136 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4137 | RenderSurfaceLayerList render_surface_layer_list; |
| 4138 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4139 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4140 | inputs.device_scale_factor = device_scale_factor; |
| 4141 | inputs.page_scale_factor = page_scale_factor; |
| 4142 | inputs.can_adjust_raster_scales = true; |
| 4143 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4144 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4145 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4146 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4147 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4148 | child_empty); |
| 4149 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4150 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4151 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4152 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4153 | // Verify parent transforms |
| 4154 | gfx::Transform expected_parent_transform; |
| 4155 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4156 | parent->screen_space_transform()); |
| 4157 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4158 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4159 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4160 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4161 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4162 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4163 | gfx::RectF parent_draw_rect = |
| 4164 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4165 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4166 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4167 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4168 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4169 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4170 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4171 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4172 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4173 | // Verify child and child_empty transforms. They should match. |
| 4174 | gfx::Transform expected_child_transform; |
| 4175 | expected_child_transform.Translate( |
| 4176 | device_scale_factor * child->position().x(), |
| 4177 | device_scale_factor * child->position().y()); |
| 4178 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4179 | child->draw_transform()); |
| 4180 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4181 | child->screen_space_transform()); |
| 4182 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4183 | child_empty->draw_transform()); |
| 4184 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4185 | child_empty->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4186 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4187 | // Verify results of transformed child and child_empty rects. They should |
| 4188 | // match. |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4189 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4190 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4191 | gfx::RectF child_draw_rect = |
| 4192 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4193 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4194 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4195 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4196 | gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect( |
| 4197 | child_empty->draw_transform(), child_content_bounds); |
| 4198 | gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect( |
| 4199 | child_empty->screen_space_transform(), child_content_bounds); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4200 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4201 | gfx::RectF expected_child_draw_rect(child->position(), child->bounds()); |
| 4202 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4203 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4204 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
| 4205 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect); |
| 4206 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4207 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4208 | // Verify child_no_scale transforms |
| 4209 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 4210 | // All transforms operate on content rects. The child's content rect |
| 4211 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 4212 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 4213 | device_scale_factor); |
| 4214 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4215 | child_no_scale->draw_transform()); |
| 4216 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4217 | child_no_scale->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 4218 | } |
| 4219 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4220 | TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4221 | // Verify draw and screen space transforms of layers in a surface. |
| 4222 | MockContentLayerClient delegate; |
| 4223 | gfx::Transform identity_matrix; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4224 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4225 | gfx::Transform perspective_matrix; |
| 4226 | perspective_matrix.ApplyPerspectiveDepth(2.0); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4227 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4228 | gfx::Transform scale_small_matrix; |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 4229 | scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4230 | |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4231 | scoped_refptr<Layer> root = Layer::Create(); |
| 4232 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4233 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4234 | SetLayerPropertiesForTesting(parent.get(), |
| 4235 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4236 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4237 | gfx::PointF(), |
| 4238 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4239 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4240 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4241 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4242 | scoped_refptr<ContentLayer> perspective_surface = |
| 4243 | CreateDrawableContentLayer(&delegate); |
| 4244 | SetLayerPropertiesForTesting(perspective_surface.get(), |
| 4245 | perspective_matrix * scale_small_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4246 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4247 | gfx::PointF(2.f, 2.f), |
| 4248 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4249 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4250 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4251 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4252 | scoped_refptr<ContentLayer> scale_surface = |
| 4253 | CreateDrawableContentLayer(&delegate); |
| 4254 | SetLayerPropertiesForTesting(scale_surface.get(), |
| 4255 | scale_small_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4256 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4257 | gfx::PointF(2.f, 2.f), |
| 4258 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4259 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4260 | true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4261 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4262 | perspective_surface->SetForceRenderSurface(true); |
| 4263 | scale_surface->SetForceRenderSurface(true); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4264 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4265 | parent->AddChild(perspective_surface); |
| 4266 | parent->AddChild(scale_surface); |
[email protected] | 9781afa | 2013-07-17 23:15:32 | [diff] [blame] | 4267 | root->AddChild(parent); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4268 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4269 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 4270 | host->SetRootLayer(root); |
| 4271 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4272 | float device_scale_factor = 2.5f; |
| 4273 | float page_scale_factor = 3.f; |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4274 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4275 | RenderSurfaceLayerList render_surface_layer_list; |
| 4276 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4277 | root.get(), parent->bounds(), &render_surface_layer_list); |
| 4278 | inputs.device_scale_factor = device_scale_factor; |
| 4279 | inputs.page_scale_factor = page_scale_factor; |
| 4280 | inputs.page_scale_application_layer = root; |
| 4281 | inputs.can_adjust_raster_scales = true; |
| 4282 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4283 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4284 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4285 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4286 | perspective_surface); |
| 4287 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4288 | scale_surface); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4289 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4290 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4291 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4292 | gfx::Transform expected_parent_draw_transform; |
| 4293 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform, |
| 4294 | parent->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4295 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4296 | // The scaled surface is rendered at its appropriate scale, and drawn 1:1 |
| 4297 | // into its target. |
| 4298 | gfx::Transform expected_scale_surface_draw_transform; |
| 4299 | expected_scale_surface_draw_transform.Translate( |
| 4300 | device_scale_factor * page_scale_factor * scale_surface->position().x(), |
| 4301 | device_scale_factor * page_scale_factor * scale_surface->position().y()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4302 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4303 | expected_scale_surface_draw_transform, |
| 4304 | scale_surface->render_surface()->draw_transform()); |
[email protected] | a52c6ff | 2013-05-04 05:33:15 | [diff] [blame] | 4305 | gfx::Transform expected_scale_surface_layer_draw_transform = |
| 4306 | scale_small_matrix; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4307 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scale_surface_layer_draw_transform, |
| 4308 | scale_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4309 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4310 | // The scale for the perspective surface is not known, so it is rendered 1:1 |
| 4311 | // with the screen, and then scaled during drawing. |
| 4312 | gfx::Transform expected_perspective_surface_draw_transform; |
| 4313 | expected_perspective_surface_draw_transform.Translate( |
| 4314 | device_scale_factor * page_scale_factor * |
| 4315 | perspective_surface->position().x(), |
| 4316 | device_scale_factor * page_scale_factor * |
| 4317 | perspective_surface->position().y()); |
| 4318 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4319 | perspective_matrix); |
| 4320 | expected_perspective_surface_draw_transform.PreconcatTransform( |
| 4321 | scale_small_matrix); |
| 4322 | gfx::Transform expected_perspective_surface_layer_draw_transform; |
| 4323 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4324 | expected_perspective_surface_draw_transform, |
| 4325 | perspective_surface->render_surface()->draw_transform()); |
| 4326 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 4327 | expected_perspective_surface_layer_draw_transform, |
| 4328 | perspective_surface->draw_transform()); |
[email protected] | 1b30e8e | 2012-12-21 02:59:09 | [diff] [blame] | 4329 | } |
| 4330 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4331 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4332 | LayerTransformsInHighDPIAccurateScaleZeroChildPosition) { |
| 4333 | // Verify draw and screen space transforms of layers not in a surface. |
| 4334 | MockContentLayerClient delegate; |
| 4335 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4336 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4337 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4338 | SetLayerPropertiesForTesting(parent.get(), |
| 4339 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4340 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4341 | gfx::PointF(), |
| 4342 | gfx::Size(133, 133), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4343 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4344 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4345 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4346 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 4347 | SetLayerPropertiesForTesting(child.get(), |
| 4348 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4349 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4350 | gfx::PointF(), |
| 4351 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4352 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4353 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4354 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4355 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4356 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4357 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4358 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4359 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4360 | gfx::PointF(), |
| 4361 | gfx::Size(13, 13), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4362 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4363 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4364 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4365 | parent->AddChild(child); |
| 4366 | parent->AddChild(child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4367 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4368 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 4369 | host->SetRootLayer(parent); |
| 4370 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4371 | float device_scale_factor = 1.7f; |
| 4372 | float page_scale_factor = 1.f; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4373 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4374 | RenderSurfaceLayerList render_surface_layer_list; |
| 4375 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4376 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 4377 | inputs.device_scale_factor = device_scale_factor; |
| 4378 | inputs.page_scale_factor = page_scale_factor; |
| 4379 | inputs.page_scale_application_layer = parent.get(); |
| 4380 | inputs.can_adjust_raster_scales = true; |
| 4381 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4382 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4383 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4384 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child); |
| 4385 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4386 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4387 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4388 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4389 | // Verify parent transforms |
| 4390 | gfx::Transform expected_parent_transform; |
| 4391 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4392 | parent->screen_space_transform()); |
| 4393 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 4394 | parent->draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4395 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4396 | // Verify results of transformed parent rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4397 | gfx::RectF parent_content_bounds(parent->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4398 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4399 | gfx::RectF parent_draw_rect = |
| 4400 | MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds); |
| 4401 | gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect( |
| 4402 | parent->screen_space_transform(), parent_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4403 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4404 | gfx::RectF expected_parent_draw_rect(parent->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4405 | expected_parent_draw_rect.Scale(device_scale_factor); |
| 4406 | expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width())); |
| 4407 | expected_parent_draw_rect.set_height( |
| 4408 | ceil(expected_parent_draw_rect.height())); |
| 4409 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect); |
| 4410 | EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4411 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4412 | // Verify child transforms |
| 4413 | gfx::Transform expected_child_transform; |
| 4414 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4415 | child->draw_transform()); |
| 4416 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, |
| 4417 | child->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4418 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4419 | // Verify results of transformed child rects |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4420 | gfx::RectF child_content_bounds(child->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4421 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4422 | gfx::RectF child_draw_rect = |
| 4423 | MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds); |
| 4424 | gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect( |
| 4425 | child->screen_space_transform(), child_content_bounds); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4426 | |
[email protected] | 2c7c670 | 2013-03-26 03:14:05 | [diff] [blame] | 4427 | gfx::RectF expected_child_draw_rect(child->bounds()); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4428 | expected_child_draw_rect.Scale(device_scale_factor); |
| 4429 | expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width())); |
| 4430 | expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height())); |
| 4431 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect); |
| 4432 | EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4433 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4434 | // Verify child_no_scale transforms |
| 4435 | gfx::Transform expected_child_no_scale_transform = child->draw_transform(); |
| 4436 | // All transforms operate on content rects. The child's content rect |
| 4437 | // incorporates device scale, but the child_no_scale does not; add it here. |
| 4438 | expected_child_no_scale_transform.Scale(device_scale_factor, |
| 4439 | device_scale_factor); |
| 4440 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4441 | child_no_scale->draw_transform()); |
| 4442 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform, |
| 4443 | child_no_scale->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 4444 | } |
| 4445 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4446 | TEST_F(LayerTreeHostCommonTest, ContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4447 | MockContentLayerClient delegate; |
| 4448 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4449 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4450 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4451 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4452 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4453 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4454 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4455 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4456 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4457 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4458 | scoped_refptr<Layer> root = Layer::Create(); |
| 4459 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4460 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4461 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4462 | SetLayerPropertiesForTesting(parent.get(), |
| 4463 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4464 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4465 | gfx::PointF(), |
| 4466 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4467 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4468 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4469 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4470 | scoped_refptr<ContentLayer> child_scale = |
| 4471 | CreateDrawableContentLayer(&delegate); |
| 4472 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4473 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4474 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4475 | gfx::PointF(2.f, 2.f), |
| 4476 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4477 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4478 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4479 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4480 | scoped_refptr<ContentLayer> child_empty = |
| 4481 | CreateDrawableContentLayer(&delegate); |
| 4482 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4483 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4484 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4485 | gfx::PointF(2.f, 2.f), |
| 4486 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4487 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4488 | true); |
[email protected] | f89f563 | 2012-11-14 23:34:45 | [diff] [blame] | 4489 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4490 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4491 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4492 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4493 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4494 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4495 | gfx::PointF(12.f, 12.f), |
| 4496 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4497 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4498 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4499 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4500 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4501 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4502 | parent->AddChild(child_scale); |
| 4503 | parent->AddChild(child_empty); |
| 4504 | parent->AddChild(child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4505 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4506 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 4507 | host->SetRootLayer(root); |
| 4508 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4509 | float device_scale_factor = 2.5f; |
| 4510 | float page_scale_factor = 1.f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4511 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4512 | { |
| 4513 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4514 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4515 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4516 | inputs.device_scale_factor = device_scale_factor; |
| 4517 | inputs.page_scale_factor = page_scale_factor; |
| 4518 | inputs.page_scale_application_layer = root.get(); |
| 4519 | inputs.can_adjust_raster_scales = true; |
| 4520 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4521 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4522 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4523 | initial_parent_scale, parent); |
| 4524 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4525 | initial_parent_scale * initial_child_scale, |
| 4526 | child_scale); |
| 4527 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4528 | initial_parent_scale * initial_child_scale, |
| 4529 | child_empty); |
| 4530 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4531 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4532 | // The parent is scaled up and shouldn't need to scale during draw. The |
| 4533 | // child that can scale its contents should also not need to scale during |
| 4534 | // draw. This shouldn't change if the child has empty bounds. The other |
| 4535 | // children should. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4536 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 4537 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
| 4538 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0)); |
| 4539 | EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1)); |
| 4540 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0)); |
| 4541 | EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4542 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
| 4543 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4544 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4545 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4546 | initial_parent_scale * initial_child_scale, |
| 4547 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4548 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4549 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4550 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 4551 | // updated using the initial transform as the raster scale. |
| 4552 | device_scale_factor = 2.25f; |
| 4553 | page_scale_factor = 1.25f; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4554 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4555 | { |
| 4556 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4557 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4558 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4559 | inputs.device_scale_factor = device_scale_factor; |
| 4560 | inputs.page_scale_factor = page_scale_factor; |
| 4561 | inputs.page_scale_application_layer = root.get(); |
| 4562 | inputs.can_adjust_raster_scales = true; |
| 4563 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 4564 | |
| 4565 | EXPECT_CONTENTS_SCALE_EQ( |
| 4566 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4567 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4568 | initial_parent_scale * initial_child_scale, |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4569 | child_scale); |
| 4570 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4571 | initial_parent_scale * initial_child_scale, |
| 4572 | child_empty); |
| 4573 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4574 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4575 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4576 | // 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] | 4577 | SkMScalar second_child_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4578 | child_scale_matrix.Scale(second_child_scale / initial_child_scale, |
| 4579 | second_child_scale / initial_child_scale); |
| 4580 | child_scale->SetTransform(child_scale_matrix); |
| 4581 | child_empty->SetTransform(child_scale_matrix); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4582 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4583 | { |
| 4584 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4585 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4586 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4587 | inputs.device_scale_factor = device_scale_factor; |
| 4588 | inputs.page_scale_factor = page_scale_factor; |
| 4589 | inputs.page_scale_application_layer = root.get(); |
| 4590 | inputs.can_adjust_raster_scales = true; |
| 4591 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4592 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4593 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4594 | initial_parent_scale, |
| 4595 | parent); |
| 4596 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4597 | child_scale); |
| 4598 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4599 | child_empty); |
| 4600 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4601 | } |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4602 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4603 | // If the device_scale_factor or page_scale_factor changes, then it should be |
| 4604 | // updated, but still using 1.0 as the raster scale. |
| 4605 | device_scale_factor = 2.75f; |
| 4606 | page_scale_factor = 1.75f; |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4607 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4608 | { |
| 4609 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4610 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4611 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4612 | inputs.device_scale_factor = device_scale_factor; |
| 4613 | inputs.page_scale_factor = page_scale_factor; |
| 4614 | inputs.page_scale_application_layer = root.get(); |
| 4615 | inputs.can_adjust_raster_scales = true; |
| 4616 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | d051820 | 2013-02-08 02:06:49 | [diff] [blame] | 4617 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4618 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
| 4619 | initial_parent_scale, |
| 4620 | parent); |
| 4621 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4622 | child_scale); |
| 4623 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4624 | child_empty); |
| 4625 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4626 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4627 | } |
| 4628 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4629 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4630 | ContentsScale_LayerTransformsDontAffectContentsScale) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4631 | MockContentLayerClient delegate; |
| 4632 | gfx::Transform identity_matrix; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4633 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4634 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4635 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4636 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4637 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4638 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4639 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4640 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4641 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4642 | scoped_refptr<Layer> root = Layer::Create(); |
| 4643 | root->SetBounds(gfx::Size(100, 100)); |
| 4644 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4645 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4646 | SetLayerPropertiesForTesting(parent.get(), |
| 4647 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4648 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4649 | gfx::PointF(), |
| 4650 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4651 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4652 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4653 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4654 | scoped_refptr<ContentLayer> child_scale = |
| 4655 | CreateDrawableContentLayer(&delegate); |
| 4656 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4657 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4658 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4659 | gfx::PointF(2.f, 2.f), |
| 4660 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4661 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4662 | true); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4663 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4664 | scoped_refptr<ContentLayer> child_empty = |
| 4665 | CreateDrawableContentLayer(&delegate); |
| 4666 | SetLayerPropertiesForTesting(child_empty.get(), |
| 4667 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4668 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4669 | gfx::PointF(2.f, 2.f), |
| 4670 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4671 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4672 | true); |
| 4673 | |
| 4674 | scoped_refptr<NoScaleContentLayer> child_no_scale = |
| 4675 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4676 | SetLayerPropertiesForTesting(child_no_scale.get(), |
| 4677 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4678 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4679 | gfx::PointF(12.f, 12.f), |
| 4680 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4681 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4682 | true); |
| 4683 | |
| 4684 | root->AddChild(parent); |
| 4685 | |
| 4686 | parent->AddChild(child_scale); |
| 4687 | parent->AddChild(child_empty); |
| 4688 | parent->AddChild(child_no_scale); |
| 4689 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4690 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 4691 | host->SetRootLayer(root); |
| 4692 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4693 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4694 | |
| 4695 | float device_scale_factor = 2.5f; |
| 4696 | float page_scale_factor = 1.f; |
| 4697 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4698 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4699 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4700 | inputs.device_scale_factor = device_scale_factor; |
| 4701 | inputs.page_scale_factor = page_scale_factor; |
| 4702 | inputs.page_scale_application_layer = root.get(), |
| 4703 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4704 | |
| 4705 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent); |
| 4706 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4707 | child_scale); |
| 4708 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 4709 | child_empty); |
| 4710 | EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale); |
| 4711 | |
| 4712 | // Since the transform scale does not affect contents scale, it should affect |
| 4713 | // the draw transform instead. |
| 4714 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4715 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4716 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4717 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4718 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4719 | child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4720 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4721 | child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4722 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4723 | child_empty->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4724 | EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4725 | child_empty->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4726 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4727 | initial_parent_scale * initial_child_scale, |
| 4728 | child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4729 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4730 | initial_parent_scale * initial_child_scale, |
| 4731 | child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4732 | } |
| 4733 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4734 | TEST_F(LayerTreeHostCommonTest, SmallContentsScale) { |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4735 | MockContentLayerClient delegate; |
| 4736 | gfx::Transform identity_matrix; |
| 4737 | |
| 4738 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4739 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4740 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 4741 | |
| 4742 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4743 | SkMScalar initial_child_scale = 0.25; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4744 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 4745 | |
| 4746 | scoped_refptr<Layer> root = Layer::Create(); |
| 4747 | root->SetBounds(gfx::Size(100, 100)); |
| 4748 | |
| 4749 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4750 | SetLayerPropertiesForTesting(parent.get(), |
| 4751 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4752 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4753 | gfx::PointF(), |
| 4754 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4755 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4756 | true); |
| 4757 | |
| 4758 | scoped_refptr<ContentLayer> child_scale = |
| 4759 | CreateDrawableContentLayer(&delegate); |
| 4760 | SetLayerPropertiesForTesting(child_scale.get(), |
| 4761 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4762 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4763 | gfx::PointF(2.f, 2.f), |
| 4764 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4765 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4766 | true); |
| 4767 | |
| 4768 | root->AddChild(parent); |
| 4769 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4770 | parent->AddChild(child_scale); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4771 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4772 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 4773 | host->SetRootLayer(root); |
| 4774 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4775 | float device_scale_factor = 2.5f; |
| 4776 | float page_scale_factor = 0.01f; |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4777 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4778 | { |
| 4779 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4780 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4781 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4782 | inputs.device_scale_factor = device_scale_factor; |
| 4783 | inputs.page_scale_factor = page_scale_factor; |
| 4784 | inputs.page_scale_application_layer = root.get(); |
| 4785 | inputs.can_adjust_raster_scales = true; |
| 4786 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [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 | // The child's scale is < 1, so we should not save and use that scale |
| 4792 | // factor. |
| 4793 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * 1, |
| 4794 | child_scale); |
| 4795 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4796 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4797 | // When chilld's total scale becomes >= 1, we should save and use that scale |
| 4798 | // factor. |
| 4799 | child_scale_matrix.MakeIdentity(); |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4800 | SkMScalar final_child_scale = 0.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4801 | child_scale_matrix.Scale(final_child_scale, final_child_scale); |
| 4802 | child_scale->SetTransform(child_scale_matrix); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4803 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4804 | { |
| 4805 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4806 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4807 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4808 | inputs.device_scale_factor = device_scale_factor; |
| 4809 | inputs.page_scale_factor = page_scale_factor; |
| 4810 | inputs.page_scale_application_layer = root.get(); |
| 4811 | inputs.can_adjust_raster_scales = true; |
| 4812 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [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 | initial_parent_scale * final_child_scale, |
| 4819 | child_scale); |
| 4820 | } |
[email protected] | 11ec9297 | 2012-11-10 03:06:21 | [diff] [blame] | 4821 | } |
| 4822 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 4823 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4824 | MockContentLayerClient delegate; |
| 4825 | gfx::Transform identity_matrix; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4826 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4827 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4828 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4829 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4830 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4831 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4832 | SkMScalar initial_child_scale = 3.0; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4833 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4834 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4835 | scoped_refptr<Layer> root = Layer::Create(); |
| 4836 | root->SetBounds(gfx::Size(100, 100)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4837 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4838 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 4839 | SetLayerPropertiesForTesting(parent.get(), |
| 4840 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4841 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4842 | gfx::PointF(), |
| 4843 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4844 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4845 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4846 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4847 | scoped_refptr<ContentLayer> surface_scale = |
| 4848 | CreateDrawableContentLayer(&delegate); |
| 4849 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 4850 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4851 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4852 | gfx::PointF(2.f, 2.f), |
| 4853 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4854 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4855 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4856 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4857 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 4858 | CreateDrawableContentLayer(&delegate); |
| 4859 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 4860 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4861 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4862 | gfx::PointF(), |
| 4863 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4864 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4865 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4866 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4867 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 4868 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4869 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 4870 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4871 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4872 | gfx::PointF(), |
| 4873 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4874 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4875 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4876 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4877 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 4878 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4879 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 4880 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4881 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4882 | gfx::PointF(12.f, 12.f), |
| 4883 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4884 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4885 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4886 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4887 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 4888 | CreateDrawableContentLayer(&delegate); |
| 4889 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 4890 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4891 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4892 | gfx::PointF(), |
| 4893 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4894 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4895 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4896 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4897 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 4898 | CreateNoScaleDrawableContentLayer(&delegate); |
| 4899 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 4900 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 4901 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4902 | gfx::PointF(), |
| 4903 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 4904 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4905 | true); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4906 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 4907 | root->AddChild(parent); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4908 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4909 | parent->AddChild(surface_scale); |
| 4910 | parent->AddChild(surface_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4911 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4912 | surface_scale->SetForceRenderSurface(true); |
| 4913 | surface_scale->AddChild(surface_scale_child_scale); |
| 4914 | surface_scale->AddChild(surface_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4915 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4916 | surface_no_scale->SetForceRenderSurface(true); |
| 4917 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 4918 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4919 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 4920 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 4921 | host->SetRootLayer(root); |
| 4922 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4923 | SkMScalar device_scale_factor = 5; |
| 4924 | SkMScalar page_scale_factor = 7; |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4925 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4926 | RenderSurfaceLayerList render_surface_layer_list; |
| 4927 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 4928 | root.get(), root->bounds(), &render_surface_layer_list); |
| 4929 | inputs.device_scale_factor = device_scale_factor; |
| 4930 | inputs.page_scale_factor = page_scale_factor; |
| 4931 | inputs.page_scale_application_layer = root.get(); |
| 4932 | inputs.can_adjust_raster_scales = true; |
| 4933 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 4934 | |
| 4935 | EXPECT_CONTENTS_SCALE_EQ( |
| 4936 | device_scale_factor * page_scale_factor * initial_parent_scale, parent); |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 4937 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 4938 | initial_parent_scale * initial_child_scale, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4939 | surface_scale); |
| 4940 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale); |
| 4941 | EXPECT_CONTENTS_SCALE_EQ( |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4942 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 4943 | initial_child_scale * initial_child_scale, |
| 4944 | surface_scale_child_scale); |
| 4945 | EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale); |
| 4946 | EXPECT_CONTENTS_SCALE_EQ( |
| 4947 | device_scale_factor * page_scale_factor * initial_parent_scale * |
| 4948 | initial_child_scale * initial_child_scale, |
| 4949 | surface_no_scale_child_scale); |
| 4950 | EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4951 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4952 | // The parent is scaled up and shouldn't need to scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4953 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0)); |
| 4954 | EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4955 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4956 | // RenderSurfaces should always be 1:1 with their target. |
| 4957 | EXPECT_FLOAT_EQ( |
| 4958 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4959 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4960 | EXPECT_FLOAT_EQ( |
| 4961 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4962 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4963 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4964 | // The surface_scale can apply contents scale so the layer shouldn't need to |
| 4965 | // scale during draw. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4966 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 4967 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4968 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4969 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 4970 | // to scale during draw. |
| 4971 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4972 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4973 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4974 | 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4975 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4976 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 4977 | // to be scaled during draw. |
| 4978 | EXPECT_FLOAT_EQ( |
| 4979 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4980 | initial_child_scale * initial_child_scale, |
| 4981 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4982 | EXPECT_FLOAT_EQ( |
| 4983 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4984 | initial_child_scale * initial_child_scale, |
| 4985 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4986 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4987 | // RenderSurfaces should always be 1:1 with their target. |
| 4988 | EXPECT_FLOAT_EQ( |
| 4989 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4990 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4991 | EXPECT_FLOAT_EQ( |
| 4992 | 1.0, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4993 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 4994 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 4995 | // The surface_no_scale layer can not apply contents scale, so it needs to be |
| 4996 | // scaled during draw. |
| 4997 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 4998 | initial_parent_scale * initial_child_scale, |
| 4999 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5000 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5001 | initial_parent_scale * initial_child_scale, |
| 5002 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5003 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5004 | // The surface_scale_child_scale can apply contents scale so it shouldn't need |
| 5005 | // to scale during draw. |
| 5006 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5007 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5008 | EXPECT_FLOAT_EQ( |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5009 | 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5010 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5011 | // The surface_scale_child_no_scale can not apply contents scale, so it needs |
| 5012 | // to be scaled during draw. |
| 5013 | EXPECT_FLOAT_EQ( |
| 5014 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5015 | initial_child_scale * initial_child_scale, |
| 5016 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5017 | EXPECT_FLOAT_EQ( |
| 5018 | device_scale_factor * page_scale_factor * initial_parent_scale * |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5019 | initial_child_scale * initial_child_scale, |
| 5020 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5021 | } |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5022 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5023 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5024 | ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) { |
| 5025 | MockContentLayerClient delegate; |
| 5026 | gfx::Transform identity_matrix; |
| 5027 | |
| 5028 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5029 | SkMScalar initial_parent_scale = 2.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5030 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
| 5031 | |
| 5032 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5033 | SkMScalar initial_child_scale = 3.0; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5034 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
| 5035 | |
| 5036 | scoped_refptr<Layer> root = Layer::Create(); |
| 5037 | root->SetBounds(gfx::Size(100, 100)); |
| 5038 | |
| 5039 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 5040 | SetLayerPropertiesForTesting(parent.get(), |
| 5041 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5042 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5043 | gfx::PointF(), |
| 5044 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5045 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5046 | true); |
| 5047 | |
| 5048 | scoped_refptr<ContentLayer> surface_scale = |
| 5049 | CreateDrawableContentLayer(&delegate); |
| 5050 | SetLayerPropertiesForTesting(surface_scale.get(), |
| 5051 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5052 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5053 | gfx::PointF(2.f, 2.f), |
| 5054 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5055 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5056 | true); |
| 5057 | |
| 5058 | scoped_refptr<ContentLayer> surface_scale_child_scale = |
| 5059 | CreateDrawableContentLayer(&delegate); |
| 5060 | SetLayerPropertiesForTesting(surface_scale_child_scale.get(), |
| 5061 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5062 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5063 | gfx::PointF(), |
| 5064 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5065 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5066 | true); |
| 5067 | |
| 5068 | scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale = |
| 5069 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5070 | SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(), |
| 5071 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5072 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5073 | gfx::PointF(), |
| 5074 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5075 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5076 | true); |
| 5077 | |
| 5078 | scoped_refptr<NoScaleContentLayer> surface_no_scale = |
| 5079 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5080 | SetLayerPropertiesForTesting(surface_no_scale.get(), |
| 5081 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5082 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5083 | gfx::PointF(12.f, 12.f), |
| 5084 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5085 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5086 | true); |
| 5087 | |
| 5088 | scoped_refptr<ContentLayer> surface_no_scale_child_scale = |
| 5089 | CreateDrawableContentLayer(&delegate); |
| 5090 | SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(), |
| 5091 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5092 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5093 | gfx::PointF(), |
| 5094 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5095 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5096 | true); |
| 5097 | |
| 5098 | scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale = |
| 5099 | CreateNoScaleDrawableContentLayer(&delegate); |
| 5100 | SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(), |
| 5101 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5102 | gfx::Point3F(), |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5103 | gfx::PointF(), |
| 5104 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5105 | false, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5106 | true); |
| 5107 | |
| 5108 | root->AddChild(parent); |
| 5109 | |
| 5110 | parent->AddChild(surface_scale); |
| 5111 | parent->AddChild(surface_no_scale); |
| 5112 | |
| 5113 | surface_scale->SetForceRenderSurface(true); |
| 5114 | surface_scale->AddChild(surface_scale_child_scale); |
| 5115 | surface_scale->AddChild(surface_scale_child_no_scale); |
| 5116 | |
| 5117 | surface_no_scale->SetForceRenderSurface(true); |
| 5118 | surface_no_scale->AddChild(surface_no_scale_child_scale); |
| 5119 | surface_no_scale->AddChild(surface_no_scale_child_no_scale); |
| 5120 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5121 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 5122 | host->SetRootLayer(root); |
| 5123 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5124 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5125 | |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5126 | SkMScalar device_scale_factor = 5.0; |
| 5127 | SkMScalar page_scale_factor = 7.0; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5128 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5129 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5130 | inputs.device_scale_factor = device_scale_factor; |
| 5131 | inputs.page_scale_factor = page_scale_factor; |
| 5132 | inputs.page_scale_application_layer = root.get(); |
| 5133 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5134 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5135 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5136 | parent); |
| 5137 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5138 | surface_scale); |
| 5139 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale); |
| 5140 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5141 | surface_scale_child_scale); |
| 5142 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale); |
| 5143 | EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, |
| 5144 | surface_no_scale_child_scale); |
| 5145 | EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale); |
| 5146 | |
| 5147 | // The parent is scaled up during draw, since its contents are not scaled by |
| 5148 | // the transform hierarchy. |
| 5149 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5150 | parent->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5151 | EXPECT_FLOAT_EQ(initial_parent_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5152 | parent->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5153 | |
| 5154 | // The child surface is scaled up during draw since its subtree is not scaled |
| 5155 | // by the transform hierarchy. |
| 5156 | EXPECT_FLOAT_EQ( |
| 5157 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5158 | surface_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5159 | EXPECT_FLOAT_EQ( |
| 5160 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5161 | surface_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5162 | |
| 5163 | // The surface_scale's RenderSurface is scaled during draw, so the layer does |
| 5164 | // not need to be scaled when drawing into its surface. |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5165 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0)); |
| 5166 | EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5167 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5168 | // The surface_scale_child_scale is scaled when drawing into its surface, |
| 5169 | // since its content bounds are not scaled by the transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5170 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5171 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5172 | surface_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5173 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5174 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5175 | surface_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5176 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5177 | // The surface_scale_child_no_scale has a fixed contents scale of 1, so it |
| 5178 | // needs to be scaled by the device and page scale factors, along with the |
| 5179 | // transform hierarchy. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5180 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5181 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5182 | surface_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5183 | EXPECT_FLOAT_EQ( |
| 5184 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5185 | surface_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5186 | |
| 5187 | // The child surface is scaled up during draw since its subtree is not scaled |
| 5188 | // by the transform hierarchy. |
| 5189 | EXPECT_FLOAT_EQ( |
| 5190 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5191 | surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5192 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5193 | initial_parent_scale * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5194 | surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5195 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5196 | // The surface_no_scale layer has a fixed contents scale of 1, so it needs to |
| 5197 | // be scaled by the device and page scale factors. Its surface is already |
| 5198 | // scaled by the transform hierarchy so those don't need to scale the layer's |
| 5199 | // drawing. |
| 5200 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5201 | surface_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5202 | EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5203 | surface_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5204 | |
| 5205 | // The surface_no_scale_child_scale has its contents scaled by the page and |
| 5206 | // device scale factors, but needs to be scaled by the transform hierarchy |
| 5207 | // when drawing. |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5208 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5209 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5210 | surface_no_scale_child_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5211 | EXPECT_FLOAT_EQ( |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5212 | initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5213 | surface_no_scale_child_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5214 | |
| 5215 | // The surface_no_scale_child_no_scale has a fixed contents scale of 1, so it |
| 5216 | // needs to be scaled by the device and page scale factors. It also needs to |
| 5217 | // be scaled by any transform heirarchy below its target surface. |
| 5218 | EXPECT_FLOAT_EQ( |
| 5219 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5220 | surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0)); |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5221 | EXPECT_FLOAT_EQ( |
| 5222 | device_scale_factor * page_scale_factor * initial_child_scale, |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5223 | surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1)); |
[email protected] | 518ee58 | 2012-10-24 18:29:44 | [diff] [blame] | 5224 | } |
| 5225 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5226 | TEST_F(LayerTreeHostCommonTest, ContentsScaleForAnimatingLayer) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5227 | MockContentLayerClient delegate; |
| 5228 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5229 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5230 | gfx::Transform parent_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5231 | SkMScalar initial_parent_scale = 1.75; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5232 | parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5233 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5234 | gfx::Transform child_scale_matrix; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5235 | SkMScalar initial_child_scale = 1.25; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5236 | child_scale_matrix.Scale(initial_child_scale, initial_child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5237 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5238 | scoped_refptr<Layer> root = Layer::Create(); |
| 5239 | root->SetBounds(gfx::Size(100, 100)); |
| 5240 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5241 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 5242 | SetLayerPropertiesForTesting(parent.get(), |
| 5243 | parent_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5244 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5245 | gfx::PointF(), |
| 5246 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5247 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5248 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5249 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5250 | scoped_refptr<ContentLayer> child_scale = |
| 5251 | CreateDrawableContentLayer(&delegate); |
| 5252 | SetLayerPropertiesForTesting(child_scale.get(), |
| 5253 | child_scale_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5254 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5255 | gfx::PointF(2.f, 2.f), |
| 5256 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5257 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5258 | true); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5259 | |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 5260 | root->AddChild(parent); |
| 5261 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5262 | parent->AddChild(child_scale); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5263 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5264 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 5265 | host->SetRootLayer(root); |
| 5266 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5267 | // Now put an animating transform on child. |
| 5268 | int animation_id = AddAnimatedTransformToController( |
| 5269 | child_scale->layer_animation_controller(), 10.0, 30, 0); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5270 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5271 | { |
| 5272 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5273 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5274 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5275 | inputs.can_adjust_raster_scales = true; |
| 5276 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5277 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5278 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent); |
| 5279 | // The layers with animating transforms should not compute a contents scale |
| 5280 | // other than 1 until they finish animating. |
| 5281 | EXPECT_CONTENTS_SCALE_EQ(1, child_scale); |
| 5282 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5283 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5284 | // Remove the animation, now it can save a raster scale. |
| 5285 | child_scale->layer_animation_controller()->RemoveAnimation(animation_id); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5286 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5287 | { |
| 5288 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5289 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5290 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5291 | inputs.can_adjust_raster_scales = true; |
| 5292 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5293 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5294 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale, parent); |
| 5295 | // The layers with animating transforms should not compute a contents scale |
| 5296 | // other than 1 until they finish animating. |
| 5297 | EXPECT_CONTENTS_SCALE_EQ(initial_parent_scale * initial_child_scale, |
| 5298 | child_scale); |
| 5299 | } |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5300 | } |
| 5301 | |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5302 | TEST_F(LayerTreeHostCommonTest, |
| 5303 | ChangeInContentBoundsOrScaleTriggersPushProperties) { |
| 5304 | MockContentLayerClient delegate; |
| 5305 | scoped_refptr<Layer> root = Layer::Create(); |
| 5306 | scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate); |
| 5307 | root->AddChild(child); |
| 5308 | |
| 5309 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 5310 | host->SetRootLayer(root); |
| 5311 | |
| 5312 | gfx::Transform identity_matrix; |
| 5313 | SetLayerPropertiesForTesting(root.get(), |
| 5314 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5315 | gfx::Point3F(), |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5316 | gfx::PointF(), |
| 5317 | gfx::Size(100, 100), |
| 5318 | true, |
| 5319 | false); |
| 5320 | SetLayerPropertiesForTesting(child.get(), |
| 5321 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5322 | gfx::Point3F(), |
[email protected] | 7a5a932 | 2014-02-25 12:54:57 | [diff] [blame] | 5323 | gfx::PointF(), |
| 5324 | gfx::Size(100, 100), |
| 5325 | true, |
| 5326 | false); |
| 5327 | |
| 5328 | root->reset_needs_push_properties_for_testing(); |
| 5329 | child->reset_needs_push_properties_for_testing(); |
| 5330 | |
| 5331 | // This will change both layers' content bounds. |
| 5332 | ExecuteCalculateDrawProperties(root.get()); |
| 5333 | EXPECT_TRUE(root->needs_push_properties()); |
| 5334 | EXPECT_TRUE(child->needs_push_properties()); |
| 5335 | |
| 5336 | root->reset_needs_push_properties_for_testing(); |
| 5337 | child->reset_needs_push_properties_for_testing(); |
| 5338 | |
| 5339 | // This will change only the child layer's contents scale and content bounds, |
| 5340 | // since the root layer is not a ContentsScalingLayer. |
| 5341 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 5342 | EXPECT_FALSE(root->needs_push_properties()); |
| 5343 | EXPECT_TRUE(child->needs_push_properties()); |
| 5344 | |
| 5345 | root->reset_needs_push_properties_for_testing(); |
| 5346 | child->reset_needs_push_properties_for_testing(); |
| 5347 | |
| 5348 | // This will not change either layer's contents scale or content bounds. |
| 5349 | ExecuteCalculateDrawProperties(root.get(), 2.f); |
| 5350 | EXPECT_FALSE(root->needs_push_properties()); |
| 5351 | EXPECT_FALSE(child->needs_push_properties()); |
| 5352 | } |
| 5353 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5354 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5355 | MockContentLayerClient delegate; |
| 5356 | gfx::Transform identity_matrix; |
[email protected] | 6a9cff9 | 2012-11-08 11:53:26 | [diff] [blame] | 5357 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5358 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 5359 | SetLayerPropertiesForTesting(parent.get(), |
| 5360 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5361 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5362 | gfx::PointF(), |
| 5363 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5364 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5365 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5366 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5367 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 5368 | SetLayerPropertiesForTesting(child.get(), |
| 5369 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5370 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5371 | gfx::PointF(2.f, 2.f), |
| 5372 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5373 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5374 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5375 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5376 | gfx::Transform replica_transform; |
| 5377 | replica_transform.Scale(1.0, -1.0); |
| 5378 | scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate); |
| 5379 | SetLayerPropertiesForTesting(replica.get(), |
| 5380 | replica_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5381 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5382 | gfx::PointF(2.f, 2.f), |
| 5383 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5384 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5385 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5386 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5387 | // This layer should end up in the same surface as child, with the same draw |
| 5388 | // and screen space transforms. |
| 5389 | scoped_refptr<ContentLayer> duplicate_child_non_owner = |
| 5390 | CreateDrawableContentLayer(&delegate); |
| 5391 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 5392 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5393 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5394 | gfx::PointF(), |
| 5395 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5396 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5397 | true); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5398 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5399 | parent->AddChild(child); |
| 5400 | child->AddChild(duplicate_child_non_owner); |
| 5401 | child->SetReplicaLayer(replica.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5402 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5403 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 5404 | host->SetRootLayer(parent); |
| 5405 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5406 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5407 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5408 | float device_scale_factor = 1.5f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5409 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5410 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5411 | inputs.device_scale_factor = device_scale_factor; |
| 5412 | inputs.can_adjust_raster_scales = true; |
| 5413 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5414 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5415 | // We should have two render surfaces. The root's render surface and child's |
| 5416 | // render surface (it needs one because it has a replica layer). |
| 5417 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5418 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5419 | gfx::Transform expected_parent_transform; |
| 5420 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5421 | parent->screen_space_transform()); |
| 5422 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform, |
| 5423 | parent->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5424 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5425 | gfx::Transform expected_draw_transform; |
| 5426 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform, |
| 5427 | child->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5428 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5429 | gfx::Transform expected_screen_space_transform; |
| 5430 | expected_screen_space_transform.Translate( |
| 5431 | device_scale_factor * child->position().x(), |
| 5432 | device_scale_factor * child->position().y()); |
| 5433 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform, |
| 5434 | child->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5435 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5436 | gfx::Transform expected_duplicate_child_draw_transform = |
| 5437 | child->draw_transform(); |
| 5438 | EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(), |
| 5439 | duplicate_child_non_owner->draw_transform()); |
| 5440 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5441 | child->screen_space_transform(), |
| 5442 | duplicate_child_non_owner->screen_space_transform()); |
| 5443 | EXPECT_RECT_EQ(child->drawable_content_rect(), |
| 5444 | duplicate_child_non_owner->drawable_content_rect()); |
| 5445 | EXPECT_EQ(child->content_bounds(), |
| 5446 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5447 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5448 | gfx::Transform expected_render_surface_draw_transform; |
| 5449 | expected_render_surface_draw_transform.Translate( |
| 5450 | device_scale_factor * child->position().x(), |
| 5451 | device_scale_factor * child->position().y()); |
| 5452 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform, |
| 5453 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5454 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5455 | gfx::Transform expected_surface_draw_transform; |
| 5456 | expected_surface_draw_transform.Translate(device_scale_factor * 2.f, |
| 5457 | device_scale_factor * 2.f); |
| 5458 | EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, |
| 5459 | child->render_surface()->draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5460 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5461 | gfx::Transform expected_surface_screen_space_transform; |
| 5462 | expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f, |
| 5463 | device_scale_factor * 2.f); |
| 5464 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5465 | expected_surface_screen_space_transform, |
| 5466 | child->render_surface()->screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5467 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5468 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5469 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
| 5470 | expected_replica_draw_transform.matrix().set(0, 3, 6.0); |
| 5471 | expected_replica_draw_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5472 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5473 | expected_replica_draw_transform, |
| 5474 | child->render_surface()->replica_draw_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5475 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5476 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5477 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
| 5478 | expected_replica_screen_space_transform.matrix().set(0, 3, 6.0); |
| 5479 | expected_replica_screen_space_transform.matrix().set(1, 3, 6.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5480 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5481 | expected_replica_screen_space_transform, |
| 5482 | child->render_surface()->replica_screen_space_transform()); |
| 5483 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5484 | expected_replica_screen_space_transform, |
| 5485 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5486 | } |
| 5487 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5488 | TEST_F(LayerTreeHostCommonTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5489 | RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) { |
| 5490 | MockContentLayerClient delegate; |
| 5491 | gfx::Transform identity_matrix; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5492 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5493 | scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate); |
| 5494 | SetLayerPropertiesForTesting(parent.get(), |
| 5495 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5496 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5497 | gfx::PointF(), |
| 5498 | gfx::Size(33, 31), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5499 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5500 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5501 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5502 | scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate); |
| 5503 | SetLayerPropertiesForTesting(child.get(), |
| 5504 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5505 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5506 | gfx::PointF(), |
| 5507 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5508 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5509 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5510 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5511 | gfx::Transform replica_transform; |
| 5512 | replica_transform.Scale(1.0, -1.0); |
| 5513 | scoped_refptr<ContentLayer> replica = CreateDrawableContentLayer(&delegate); |
| 5514 | SetLayerPropertiesForTesting(replica.get(), |
| 5515 | replica_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5516 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5517 | gfx::PointF(), |
| 5518 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5519 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5520 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5521 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5522 | // This layer should end up in the same surface as child, with the same draw |
| 5523 | // and screen space transforms. |
| 5524 | scoped_refptr<ContentLayer> duplicate_child_non_owner = |
| 5525 | CreateDrawableContentLayer(&delegate); |
| 5526 | SetLayerPropertiesForTesting(duplicate_child_non_owner.get(), |
| 5527 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5528 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5529 | gfx::PointF(), |
| 5530 | gfx::Size(13, 11), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5531 | false, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5532 | true); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5533 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5534 | parent->AddChild(child); |
| 5535 | child->AddChild(duplicate_child_non_owner); |
| 5536 | child->SetReplicaLayer(replica.get()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5537 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5538 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 5539 | host->SetRootLayer(parent); |
| 5540 | |
[email protected] | 873639e | 2013-07-24 19:56:31 | [diff] [blame] | 5541 | float device_scale_factor = 1.7f; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5542 | |
| 5543 | RenderSurfaceLayerList render_surface_layer_list; |
| 5544 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5545 | parent.get(), parent->bounds(), &render_surface_layer_list); |
| 5546 | inputs.device_scale_factor = device_scale_factor; |
| 5547 | inputs.can_adjust_raster_scales = true; |
| 5548 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5549 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5550 | // We should have two render surfaces. The root's render surface and child's |
| 5551 | // render surface (it needs one because it has a replica layer). |
| 5552 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5553 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5554 | gfx::Transform identity_transform; |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5555 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5556 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5557 | parent->screen_space_transform()); |
| 5558 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, parent->draw_transform()); |
| 5559 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, child->draw_transform()); |
| 5560 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5561 | child->screen_space_transform()); |
| 5562 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5563 | duplicate_child_non_owner->draw_transform()); |
| 5564 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5565 | identity_transform, duplicate_child_non_owner->screen_space_transform()); |
| 5566 | EXPECT_RECT_EQ(child->drawable_content_rect(), |
| 5567 | duplicate_child_non_owner->drawable_content_rect()); |
| 5568 | EXPECT_EQ(child->content_bounds(), |
| 5569 | duplicate_child_non_owner->content_bounds()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5570 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5571 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5572 | child->render_surface()->draw_transform()); |
| 5573 | EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform, |
| 5574 | child->render_surface()->draw_transform()); |
| 5575 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5576 | identity_transform, child->render_surface()->screen_space_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5577 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5578 | gfx::Transform expected_replica_draw_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5579 | expected_replica_draw_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5580 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5581 | expected_replica_draw_transform, |
| 5582 | child->render_surface()->replica_draw_transform()); |
[email protected] | 904e913 | 2012-11-01 00:12:47 | [diff] [blame] | 5583 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5584 | gfx::Transform expected_replica_screen_space_transform; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 5585 | expected_replica_screen_space_transform.matrix().set(1, 1, -1.0); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5586 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 5587 | expected_replica_screen_space_transform, |
| 5588 | child->render_surface()->replica_screen_space_transform()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5589 | } |
| 5590 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5591 | TEST_F(LayerTreeHostCommonTest, SubtreeSearch) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5592 | scoped_refptr<Layer> root = Layer::Create(); |
| 5593 | scoped_refptr<Layer> child = Layer::Create(); |
| 5594 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5595 | scoped_refptr<Layer> mask_layer = Layer::Create(); |
| 5596 | scoped_refptr<Layer> replica_layer = Layer::Create(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5597 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5598 | grand_child->SetReplicaLayer(replica_layer.get()); |
| 5599 | child->AddChild(grand_child.get()); |
| 5600 | child->SetMaskLayer(mask_layer.get()); |
| 5601 | root->AddChild(child.get()); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5602 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5603 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 5604 | host->SetRootLayer(root); |
| 5605 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5606 | int nonexistent_id = -1; |
| 5607 | EXPECT_EQ(root, |
| 5608 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id())); |
| 5609 | EXPECT_EQ(child, |
| 5610 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id())); |
| 5611 | EXPECT_EQ( |
| 5612 | grand_child, |
| 5613 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id())); |
| 5614 | EXPECT_EQ( |
| 5615 | mask_layer, |
| 5616 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id())); |
| 5617 | EXPECT_EQ( |
| 5618 | replica_layer, |
| 5619 | LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id())); |
| 5620 | EXPECT_EQ( |
| 5621 | 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id)); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 5622 | } |
| 5623 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5624 | TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5625 | scoped_refptr<Layer> root = Layer::Create(); |
| 5626 | scoped_refptr<Layer> child = Layer::Create(); |
| 5627 | scoped_refptr<LayerWithForcedDrawsContent> grand_child = |
| 5628 | make_scoped_refptr(new LayerWithForcedDrawsContent()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5629 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5630 | const gfx::Transform identity_matrix; |
| 5631 | SetLayerPropertiesForTesting(root.get(), |
| 5632 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5633 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5634 | gfx::PointF(), |
| 5635 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5636 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5637 | false); |
| 5638 | SetLayerPropertiesForTesting(child.get(), |
| 5639 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5640 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5641 | gfx::PointF(), |
| 5642 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5643 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5644 | false); |
| 5645 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5646 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5647 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5648 | gfx::PointF(), |
| 5649 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5650 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5651 | false); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5652 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5653 | root->AddChild(child); |
| 5654 | child->AddChild(grand_child); |
| 5655 | child->SetOpacity(0.5f); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5656 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5657 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 5658 | host->SetRootLayer(root); |
| 5659 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5660 | ExecuteCalculateDrawProperties(root.get()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5661 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5662 | EXPECT_FALSE(child->render_surface()); |
[email protected] | 498ec6e0e | 2012-11-30 18:24:57 | [diff] [blame] | 5663 | } |
| 5664 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5665 | TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5666 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5667 | TestSharedBitmapManager shared_bitmap_manager; |
| 5668 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5669 | host_impl.CreatePendingTree(); |
| 5670 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5671 | |
| 5672 | const gfx::Transform identity_matrix; |
| 5673 | SetLayerPropertiesForTesting(root.get(), |
| 5674 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5675 | gfx::Point3F(), |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5676 | gfx::PointF(), |
| 5677 | gfx::Size(100, 100), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5678 | true, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5679 | false); |
| 5680 | root->SetDrawsContent(true); |
| 5681 | |
| 5682 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 5683 | SetLayerPropertiesForTesting(child.get(), |
| 5684 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5685 | gfx::Point3F(), |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5686 | gfx::PointF(), |
| 5687 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5688 | true, |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5689 | false); |
| 5690 | child->SetDrawsContent(true); |
| 5691 | child->SetOpacity(0.0f); |
| 5692 | |
| 5693 | // Add opacity animation. |
| 5694 | AddOpacityTransitionToController( |
| 5695 | child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false); |
| 5696 | |
| 5697 | root->AddChild(child.Pass()); |
| 5698 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5699 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5700 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5701 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5702 | inputs.can_adjust_raster_scales = true; |
| 5703 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | f90fc41 | 2013-03-30 20:13:16 | [diff] [blame] | 5704 | |
| 5705 | // We should have one render surface and two layers. The child |
| 5706 | // layer should be included even though it is transparent. |
| 5707 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5708 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 5709 | } |
| 5710 | |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5711 | typedef std::tr1::tuple<bool, bool> LCDTextTestParam; |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5712 | class LCDTextTest |
| 5713 | : public LayerTreeHostCommonTestBase, |
| 5714 | public testing::TestWithParam<LCDTextTestParam> { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5715 | protected: |
| 5716 | virtual void SetUp() { |
| 5717 | can_use_lcd_text_ = std::tr1::get<0>(GetParam()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5718 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5719 | root_ = Layer::Create(); |
| 5720 | child_ = Layer::Create(); |
| 5721 | grand_child_ = Layer::Create(); |
| 5722 | child_->AddChild(grand_child_.get()); |
| 5723 | root_->AddChild(child_.get()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5724 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5725 | gfx::Transform identity_matrix; |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5726 | SetLayerPropertiesForTesting(root_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5727 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5728 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5729 | gfx::PointF(), |
| 5730 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5731 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5732 | false); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5733 | SetLayerPropertiesForTesting(child_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5734 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5735 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5736 | gfx::PointF(), |
| 5737 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5738 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5739 | false); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5740 | SetLayerPropertiesForTesting(grand_child_.get(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5741 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5742 | gfx::Point3F(), |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5743 | gfx::PointF(), |
| 5744 | gfx::Size(1, 1), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5745 | true, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5746 | false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5747 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5748 | child_->SetForceRenderSurface(std::tr1::get<1>(GetParam())); |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5749 | |
| 5750 | host_ = FakeLayerTreeHost::Create(); |
| 5751 | host_->SetRootLayer(root_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5752 | } |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5753 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5754 | bool can_use_lcd_text_; |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5755 | scoped_ptr<FakeLayerTreeHost> host_; |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5756 | scoped_refptr<Layer> root_; |
| 5757 | scoped_refptr<Layer> child_; |
| 5758 | scoped_refptr<Layer> grand_child_; |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5759 | }; |
| 5760 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5761 | TEST_P(LCDTextTest, CanUseLCDText) { |
| 5762 | // Case 1: Identity transform. |
| 5763 | gfx::Transform identity_matrix; |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5764 | ExecuteCalculateDrawProperties( |
| 5765 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5766 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5767 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 5768 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5769 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5770 | // Case 2: Integral translation. |
| 5771 | gfx::Transform integral_translation; |
| 5772 | integral_translation.Translate(1.0, 2.0); |
| 5773 | child_->SetTransform(integral_translation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5774 | ExecuteCalculateDrawProperties( |
| 5775 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5776 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5777 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 5778 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5779 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5780 | // Case 3: Non-integral translation. |
| 5781 | gfx::Transform non_integral_translation; |
| 5782 | non_integral_translation.Translate(1.5, 2.5); |
| 5783 | child_->SetTransform(non_integral_translation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5784 | ExecuteCalculateDrawProperties( |
| 5785 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5786 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5787 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 5788 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5789 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5790 | // Case 4: Rotation. |
| 5791 | gfx::Transform rotation; |
| 5792 | rotation.Rotate(10.0); |
| 5793 | child_->SetTransform(rotation); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5794 | ExecuteCalculateDrawProperties( |
| 5795 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5796 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5797 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 5798 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5799 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5800 | // Case 5: Scale. |
| 5801 | gfx::Transform scale; |
| 5802 | scale.Scale(2.0, 2.0); |
| 5803 | child_->SetTransform(scale); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5804 | ExecuteCalculateDrawProperties( |
| 5805 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5806 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5807 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 5808 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5809 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5810 | // Case 6: Skew. |
| 5811 | gfx::Transform skew; |
| 5812 | skew.SkewX(10.0); |
| 5813 | child_->SetTransform(skew); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5814 | ExecuteCalculateDrawProperties( |
| 5815 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5816 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5817 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 5818 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5819 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5820 | // Case 7: Translucent. |
| 5821 | child_->SetTransform(identity_matrix); |
| 5822 | child_->SetOpacity(0.5f); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5823 | ExecuteCalculateDrawProperties( |
| 5824 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5825 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5826 | EXPECT_FALSE(child_->can_use_lcd_text()); |
| 5827 | EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5828 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5829 | // Case 8: Sanity check: restore transform and opacity. |
| 5830 | child_->SetTransform(identity_matrix); |
| 5831 | child_->SetOpacity(1.f); |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5832 | ExecuteCalculateDrawProperties( |
| 5833 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5834 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5835 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 5836 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5837 | } |
| 5838 | |
[email protected] | fd9a3b6d | 2013-08-03 00:46:17 | [diff] [blame] | 5839 | TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5840 | // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5841 | ExecuteCalculateDrawProperties( |
| 5842 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5843 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5844 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 5845 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5846 | |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5847 | // Add opacity animation. |
| 5848 | child_->SetOpacity(0.9f); |
| 5849 | AddOpacityTransitionToController( |
| 5850 | child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5851 | |
[email protected] | 22898ed | 2013-06-01 04:52:30 | [diff] [blame] | 5852 | ExecuteCalculateDrawProperties( |
| 5853 | root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5854 | // Text AA should not be adjusted while animation is active. |
| 5855 | // Make sure LCD text AA setting remains unchanged. |
| 5856 | EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5857 | EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 5858 | EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5859 | } |
| 5860 | |
| 5861 | INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5862 | LCDTextTest, |
[email protected] | fb66180 | 2013-03-25 01:59:32 | [diff] [blame] | 5863 | testing::Combine(testing::Bool(), testing::Bool())); |
[email protected] | 10aabcc3 | 2012-12-13 09:18:59 | [diff] [blame] | 5864 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5865 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5866 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5867 | TestSharedBitmapManager shared_bitmap_manager; |
| 5868 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5869 | host_impl.CreatePendingTree(); |
| 5870 | const gfx::Transform identity_matrix; |
| 5871 | |
| 5872 | scoped_refptr<Layer> root = Layer::Create(); |
| 5873 | SetLayerPropertiesForTesting(root.get(), |
| 5874 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5875 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5876 | gfx::PointF(), |
| 5877 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5878 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5879 | false); |
| 5880 | root->SetIsDrawable(true); |
| 5881 | |
| 5882 | scoped_refptr<Layer> child = Layer::Create(); |
| 5883 | SetLayerPropertiesForTesting(child.get(), |
| 5884 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5885 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5886 | gfx::PointF(), |
| 5887 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5888 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5889 | false); |
| 5890 | child->SetIsDrawable(true); |
| 5891 | |
| 5892 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 5893 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5894 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5895 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5896 | gfx::PointF(), |
| 5897 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5898 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5899 | false); |
| 5900 | grand_child->SetIsDrawable(true); |
| 5901 | grand_child->SetHideLayerAndSubtree(true); |
| 5902 | |
| 5903 | child->AddChild(grand_child); |
| 5904 | root->AddChild(child); |
| 5905 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 5906 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 5907 | host->SetRootLayer(root); |
| 5908 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5909 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5910 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 5911 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5912 | inputs.can_adjust_raster_scales = true; |
| 5913 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5914 | |
| 5915 | // We should have one render surface and two layers. The grand child has |
| 5916 | // hidden itself. |
| 5917 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5918 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5919 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 5920 | EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5921 | } |
| 5922 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5923 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5924 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5925 | TestSharedBitmapManager shared_bitmap_manager; |
| 5926 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5927 | host_impl.CreatePendingTree(); |
| 5928 | const gfx::Transform identity_matrix; |
| 5929 | |
| 5930 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 5931 | SetLayerPropertiesForTesting(root.get(), |
| 5932 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5933 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5934 | gfx::PointF(), |
| 5935 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5936 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5937 | false); |
| 5938 | root->SetDrawsContent(true); |
| 5939 | |
| 5940 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 5941 | SetLayerPropertiesForTesting(child.get(), |
| 5942 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5943 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5944 | gfx::PointF(), |
| 5945 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5946 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5947 | false); |
| 5948 | child->SetDrawsContent(true); |
| 5949 | |
| 5950 | scoped_ptr<LayerImpl> grand_child = |
| 5951 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 5952 | SetLayerPropertiesForTesting(grand_child.get(), |
| 5953 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5954 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5955 | gfx::PointF(), |
| 5956 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5957 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5958 | false); |
| 5959 | grand_child->SetDrawsContent(true); |
| 5960 | grand_child->SetHideLayerAndSubtree(true); |
| 5961 | |
| 5962 | child->AddChild(grand_child.Pass()); |
| 5963 | root->AddChild(child.Pass()); |
| 5964 | |
| 5965 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 5966 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 5967 | root.get(), root->bounds(), &render_surface_layer_list); |
| 5968 | inputs.can_adjust_raster_scales = true; |
| 5969 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5970 | |
| 5971 | // We should have one render surface and two layers. The grand child has |
| 5972 | // hidden itself. |
| 5973 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5974 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5975 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
| 5976 | EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5977 | } |
| 5978 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 5979 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5980 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 5981 | TestSharedBitmapManager shared_bitmap_manager; |
| 5982 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5983 | host_impl.CreatePendingTree(); |
| 5984 | const gfx::Transform identity_matrix; |
| 5985 | |
| 5986 | scoped_refptr<Layer> root = Layer::Create(); |
| 5987 | SetLayerPropertiesForTesting(root.get(), |
| 5988 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5989 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5990 | gfx::PointF(), |
| 5991 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 5992 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 5993 | false); |
| 5994 | root->SetIsDrawable(true); |
| 5995 | |
| 5996 | scoped_refptr<Layer> child = Layer::Create(); |
| 5997 | SetLayerPropertiesForTesting(child.get(), |
| 5998 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 5999 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6000 | gfx::PointF(), |
| 6001 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6002 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6003 | false); |
| 6004 | child->SetIsDrawable(true); |
| 6005 | child->SetHideLayerAndSubtree(true); |
| 6006 | |
| 6007 | scoped_refptr<Layer> grand_child = Layer::Create(); |
| 6008 | SetLayerPropertiesForTesting(grand_child.get(), |
| 6009 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6010 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6011 | gfx::PointF(), |
| 6012 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6013 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6014 | false); |
| 6015 | grand_child->SetIsDrawable(true); |
| 6016 | |
| 6017 | child->AddChild(grand_child); |
| 6018 | root->AddChild(child); |
| 6019 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6020 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6021 | host->SetRootLayer(root); |
| 6022 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6023 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6024 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6025 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6026 | inputs.can_adjust_raster_scales = true; |
| 6027 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6028 | |
| 6029 | // We should have one render surface and one layers. The child has |
| 6030 | // hidden itself and the grand child. |
| 6031 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6032 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6033 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6034 | } |
| 6035 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6036 | TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6037 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6038 | TestSharedBitmapManager shared_bitmap_manager; |
| 6039 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6040 | host_impl.CreatePendingTree(); |
| 6041 | const gfx::Transform identity_matrix; |
| 6042 | |
| 6043 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); |
| 6044 | SetLayerPropertiesForTesting(root.get(), |
| 6045 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6046 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6047 | gfx::PointF(), |
| 6048 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6049 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6050 | false); |
| 6051 | root->SetDrawsContent(true); |
| 6052 | |
| 6053 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2); |
| 6054 | SetLayerPropertiesForTesting(child.get(), |
| 6055 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6056 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6057 | gfx::PointF(), |
| 6058 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6059 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6060 | false); |
| 6061 | child->SetDrawsContent(true); |
| 6062 | child->SetHideLayerAndSubtree(true); |
| 6063 | |
| 6064 | scoped_ptr<LayerImpl> grand_child = |
| 6065 | LayerImpl::Create(host_impl.pending_tree(), 3); |
| 6066 | SetLayerPropertiesForTesting(grand_child.get(), |
| 6067 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6068 | gfx::Point3F(), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6069 | gfx::PointF(), |
| 6070 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6071 | true, |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6072 | false); |
| 6073 | grand_child->SetDrawsContent(true); |
| 6074 | |
| 6075 | child->AddChild(grand_child.Pass()); |
| 6076 | root->AddChild(child.Pass()); |
| 6077 | |
| 6078 | LayerImplList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6079 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 6080 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6081 | inputs.can_adjust_raster_scales = true; |
| 6082 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6083 | |
| 6084 | // We should have one render surface and one layers. The child has |
| 6085 | // hidden itself and the grand child. |
| 6086 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 6087 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6088 | EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 6089 | } |
| 6090 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6091 | void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} |
| 6092 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6093 | TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6094 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6095 | TestSharedBitmapManager shared_bitmap_manager; |
| 6096 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6097 | host_impl.CreatePendingTree(); |
| 6098 | const gfx::Transform identity_matrix; |
| 6099 | |
| 6100 | scoped_refptr<Layer> root = Layer::Create(); |
| 6101 | SetLayerPropertiesForTesting(root.get(), |
| 6102 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6103 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6104 | gfx::PointF(), |
| 6105 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6106 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6107 | false); |
| 6108 | root->SetIsDrawable(true); |
| 6109 | |
| 6110 | scoped_refptr<Layer> copy_grand_parent = Layer::Create(); |
| 6111 | SetLayerPropertiesForTesting(copy_grand_parent.get(), |
| 6112 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6113 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6114 | gfx::PointF(), |
| 6115 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6116 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6117 | false); |
| 6118 | copy_grand_parent->SetIsDrawable(true); |
| 6119 | |
| 6120 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 6121 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 6122 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6123 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6124 | gfx::PointF(), |
| 6125 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6126 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6127 | false); |
| 6128 | copy_parent->SetIsDrawable(true); |
| 6129 | copy_parent->SetForceRenderSurface(true); |
| 6130 | |
| 6131 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 6132 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 6133 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6134 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6135 | gfx::PointF(), |
| 6136 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6137 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6138 | false); |
| 6139 | copy_layer->SetIsDrawable(true); |
| 6140 | |
| 6141 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 6142 | SetLayerPropertiesForTesting(copy_child.get(), |
| 6143 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6144 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6145 | gfx::PointF(), |
| 6146 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6147 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6148 | false); |
| 6149 | copy_child->SetIsDrawable(true); |
| 6150 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6151 | scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create(); |
| 6152 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(), |
| 6153 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6154 | gfx::Point3F(), |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6155 | gfx::PointF(), |
| 6156 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6157 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6158 | false); |
| 6159 | copy_grand_parent_sibling_before->SetIsDrawable(true); |
| 6160 | |
| 6161 | scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create(); |
| 6162 | SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(), |
| 6163 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6164 | gfx::Point3F(), |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6165 | gfx::PointF(), |
| 6166 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6167 | true, |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6168 | false); |
| 6169 | copy_grand_parent_sibling_after->SetIsDrawable(true); |
| 6170 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6171 | copy_layer->AddChild(copy_child); |
| 6172 | copy_parent->AddChild(copy_layer); |
| 6173 | copy_grand_parent->AddChild(copy_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6174 | root->AddChild(copy_grand_parent_sibling_before); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6175 | root->AddChild(copy_grand_parent); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6176 | root->AddChild(copy_grand_parent_sibling_after); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6177 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6178 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6179 | host->SetRootLayer(root); |
| 6180 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6181 | // Hide the copy_grand_parent and its subtree. But make a copy request in that |
| 6182 | // hidden subtree on copy_layer. |
| 6183 | copy_grand_parent->SetHideLayerAndSubtree(true); |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6184 | copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true); |
| 6185 | copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6186 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 6187 | base::Bind(&EmptyCopyOutputCallback))); |
| 6188 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 6189 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6190 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6191 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6192 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6193 | inputs.can_adjust_raster_scales = true; |
| 6194 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6195 | |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6196 | EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request); |
| 6197 | EXPECT_TRUE(copy_grand_parent->draw_properties(). |
| 6198 | layer_or_descendant_has_copy_request); |
| 6199 | EXPECT_TRUE(copy_parent->draw_properties(). |
| 6200 | layer_or_descendant_has_copy_request); |
| 6201 | EXPECT_TRUE(copy_layer->draw_properties(). |
| 6202 | layer_or_descendant_has_copy_request); |
| 6203 | EXPECT_FALSE(copy_child->draw_properties(). |
| 6204 | layer_or_descendant_has_copy_request); |
| 6205 | EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties(). |
| 6206 | layer_or_descendant_has_copy_request); |
| 6207 | EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties(). |
| 6208 | layer_or_descendant_has_copy_request); |
| 6209 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6210 | // We should have three render surfaces, one for the root, one for the parent |
| 6211 | // since it owns a surface, and one for the copy_layer. |
| 6212 | ASSERT_EQ(3u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6213 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
| 6214 | EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id()); |
| 6215 | EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6216 | |
| 6217 | // The root render surface should have 2 contributing layers. The |
[email protected] | ac02012 | 2013-07-12 23:45:53 | [diff] [blame] | 6218 | // copy_grand_parent is hidden along with its siblings, but the copy_parent |
| 6219 | // will appear since something in its subtree needs to be drawn for a copy |
| 6220 | // request. |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6221 | ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6222 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
| 6223 | EXPECT_EQ(copy_parent->id(), |
| 6224 | root->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6225 | |
[email protected] | 7392c7b | 2014-02-07 08:28:28 | [diff] [blame] | 6226 | // Nothing actually draws into the copy parent, so only the copy_layer will |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6227 | // appear in its list, since it needs to be drawn for the copy request. |
| 6228 | ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size()); |
| 6229 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6230 | copy_parent->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6231 | |
| 6232 | // The copy_layer's render surface should have two contributing layers. |
| 6233 | ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size()); |
| 6234 | EXPECT_EQ(copy_layer->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6235 | copy_layer->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6236 | EXPECT_EQ(copy_child->id(), |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6237 | copy_layer->render_surface()->layer_list().at(1)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6238 | } |
| 6239 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6240 | TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6241 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6242 | TestSharedBitmapManager shared_bitmap_manager; |
| 6243 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6244 | host_impl.CreatePendingTree(); |
| 6245 | const gfx::Transform identity_matrix; |
| 6246 | |
| 6247 | scoped_refptr<Layer> root = Layer::Create(); |
| 6248 | SetLayerPropertiesForTesting(root.get(), |
| 6249 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6250 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6251 | gfx::PointF(), |
| 6252 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6253 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6254 | false); |
| 6255 | root->SetIsDrawable(true); |
| 6256 | |
| 6257 | scoped_refptr<Layer> copy_parent = Layer::Create(); |
| 6258 | SetLayerPropertiesForTesting(copy_parent.get(), |
| 6259 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6260 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6261 | gfx::PointF(), |
| 6262 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6263 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6264 | false); |
| 6265 | copy_parent->SetIsDrawable(true); |
| 6266 | copy_parent->SetMasksToBounds(true); |
| 6267 | |
| 6268 | scoped_refptr<Layer> copy_layer = Layer::Create(); |
| 6269 | SetLayerPropertiesForTesting(copy_layer.get(), |
| 6270 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6271 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6272 | gfx::PointF(), |
| 6273 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6274 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6275 | false); |
| 6276 | copy_layer->SetIsDrawable(true); |
| 6277 | |
| 6278 | scoped_refptr<Layer> copy_child = Layer::Create(); |
| 6279 | SetLayerPropertiesForTesting(copy_child.get(), |
| 6280 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6281 | gfx::Point3F(), |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6282 | gfx::PointF(), |
| 6283 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6284 | true, |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6285 | false); |
| 6286 | copy_child->SetIsDrawable(true); |
| 6287 | |
| 6288 | copy_layer->AddChild(copy_child); |
| 6289 | copy_parent->AddChild(copy_layer); |
| 6290 | root->AddChild(copy_parent); |
| 6291 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6292 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6293 | host->SetRootLayer(root); |
| 6294 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6295 | copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest( |
| 6296 | base::Bind(&EmptyCopyOutputCallback))); |
| 6297 | EXPECT_TRUE(copy_layer->HasCopyRequest()); |
| 6298 | |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6299 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6300 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6301 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6302 | inputs.can_adjust_raster_scales = true; |
| 6303 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6304 | |
| 6305 | // We should have one render surface, as the others are clipped out. |
| 6306 | ASSERT_EQ(1u, render_surface_layer_list.size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6307 | EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6308 | |
| 6309 | // The root render surface should only have 1 contributing layer, since the |
| 6310 | // other layers are empty/clipped away. |
| 6311 | ASSERT_EQ(1u, root->render_surface()->layer_list().size()); |
[email protected] | 989386c | 2013-07-18 21:37:23 | [diff] [blame] | 6312 | EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 6313 | } |
| 6314 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6315 | TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) { |
| 6316 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6317 | TestSharedBitmapManager shared_bitmap_manager; |
| 6318 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6319 | host_impl.CreatePendingTree(); |
| 6320 | const gfx::Transform identity_matrix; |
| 6321 | |
| 6322 | scoped_refptr<Layer> root = Layer::Create(); |
| 6323 | SetLayerPropertiesForTesting(root.get(), |
| 6324 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6325 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6326 | gfx::PointF(), |
| 6327 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6328 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6329 | false); |
| 6330 | root->SetIsDrawable(true); |
| 6331 | |
| 6332 | // The surface is moved slightly outside of the viewport. |
| 6333 | scoped_refptr<Layer> surface = Layer::Create(); |
| 6334 | SetLayerPropertiesForTesting(surface.get(), |
| 6335 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6336 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6337 | gfx::PointF(-10, -20), |
| 6338 | gfx::Size(), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6339 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6340 | false); |
| 6341 | surface->SetForceRenderSurface(true); |
| 6342 | |
| 6343 | scoped_refptr<Layer> surface_child = Layer::Create(); |
| 6344 | SetLayerPropertiesForTesting(surface_child.get(), |
| 6345 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6346 | gfx::Point3F(), |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6347 | gfx::PointF(), |
| 6348 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6349 | true, |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6350 | false); |
| 6351 | surface_child->SetIsDrawable(true); |
| 6352 | |
| 6353 | surface->AddChild(surface_child); |
| 6354 | root->AddChild(surface); |
| 6355 | |
[email protected] | d600df7d | 2013-08-03 02:34:28 | [diff] [blame] | 6356 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6357 | host->SetRootLayer(root); |
| 6358 | |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6359 | RenderSurfaceLayerList render_surface_layer_list; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 6360 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 6361 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6362 | inputs.can_adjust_raster_scales = true; |
| 6363 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 11a07b10 | 2013-07-24 17:33:19 | [diff] [blame] | 6364 | |
| 6365 | // The visible_content_rect for the |surface_child| should not be clipped by |
| 6366 | // the viewport. |
| 6367 | EXPECT_EQ(gfx::Rect(50, 50).ToString(), |
| 6368 | surface_child->visible_content_rect().ToString()); |
| 6369 | } |
| 6370 | |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6371 | TEST_F(LayerTreeHostCommonTest, TransformedClipParent) { |
| 6372 | // Ensure that a transform between the layer and its render surface is not a |
| 6373 | // problem. Constructs the following layer tree. |
| 6374 | // |
| 6375 | // root (a render surface) |
| 6376 | // + render_surface |
| 6377 | // + clip_parent (scaled) |
| 6378 | // + intervening_clipping_layer |
| 6379 | // + clip_child |
| 6380 | // |
| 6381 | // The render surface should be resized correctly and the clip child should |
| 6382 | // inherit the right clip rect. |
| 6383 | scoped_refptr<Layer> root = Layer::Create(); |
| 6384 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 6385 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6386 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6387 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6388 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6389 | |
| 6390 | root->AddChild(render_surface); |
| 6391 | render_surface->AddChild(clip_parent); |
| 6392 | clip_parent->AddChild(intervening); |
| 6393 | intervening->AddChild(clip_child); |
| 6394 | |
| 6395 | clip_child->SetClipParent(clip_parent.get()); |
| 6396 | |
| 6397 | intervening->SetMasksToBounds(true); |
| 6398 | clip_parent->SetMasksToBounds(true); |
| 6399 | |
| 6400 | render_surface->SetForceRenderSurface(true); |
| 6401 | |
| 6402 | gfx::Transform scale_transform; |
| 6403 | scale_transform.Scale(2, 2); |
| 6404 | |
| 6405 | gfx::Transform identity_transform; |
| 6406 | |
| 6407 | SetLayerPropertiesForTesting(root.get(), |
| 6408 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6409 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6410 | gfx::PointF(), |
| 6411 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6412 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6413 | false); |
| 6414 | SetLayerPropertiesForTesting(render_surface.get(), |
| 6415 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6416 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6417 | gfx::PointF(), |
| 6418 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6419 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6420 | false); |
| 6421 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6422 | scale_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6423 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6424 | gfx::PointF(1.f, 1.f), |
| 6425 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6426 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6427 | false); |
| 6428 | SetLayerPropertiesForTesting(intervening.get(), |
| 6429 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6430 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6431 | gfx::PointF(1.f, 1.f), |
| 6432 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6433 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6434 | false); |
| 6435 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6436 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6437 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6438 | gfx::PointF(1.f, 1.f), |
| 6439 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6440 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6441 | false); |
| 6442 | |
| 6443 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6444 | host->SetRootLayer(root); |
| 6445 | |
| 6446 | ExecuteCalculateDrawProperties(root.get()); |
| 6447 | |
| 6448 | ASSERT_TRUE(root->render_surface()); |
| 6449 | ASSERT_TRUE(render_surface->render_surface()); |
| 6450 | |
| 6451 | // Ensure that we've inherited our clip parent's clip and weren't affected |
| 6452 | // by the intervening clip layer. |
| 6453 | ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(), |
| 6454 | clip_parent->clip_rect().ToString()); |
| 6455 | ASSERT_EQ(clip_parent->clip_rect().ToString(), |
| 6456 | clip_child->clip_rect().ToString()); |
| 6457 | ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(), |
| 6458 | intervening->clip_rect().ToString()); |
| 6459 | |
| 6460 | // Ensure that the render surface reports a content rect that has been grown |
| 6461 | // to accomodate for the clip child. |
| 6462 | ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(), |
| 6463 | render_surface->render_surface()->content_rect().ToString()); |
| 6464 | |
| 6465 | // The above check implies the two below, but they nicely demonstrate that |
| 6466 | // we've grown, despite the intervening layer's clip. |
| 6467 | ASSERT_TRUE(clip_parent->clip_rect().Contains( |
| 6468 | render_surface->render_surface()->content_rect())); |
| 6469 | ASSERT_FALSE(intervening->clip_rect().Contains( |
| 6470 | render_surface->render_surface()->content_rect())); |
| 6471 | } |
| 6472 | |
| 6473 | TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) { |
| 6474 | // Ensure that intervening render surfaces are not a problem in the basic |
| 6475 | // case. In the following tree, both render surfaces should be resized to |
| 6476 | // accomodate for the clip child, despite an intervening clip. |
| 6477 | // |
| 6478 | // root (a render surface) |
| 6479 | // + clip_parent (masks to bounds) |
| 6480 | // + render_surface1 (sets opacity) |
| 6481 | // + intervening (masks to bounds) |
| 6482 | // + render_surface2 (also sets opacity) |
| 6483 | // + clip_child |
| 6484 | // |
| 6485 | scoped_refptr<Layer> root = Layer::Create(); |
| 6486 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6487 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6488 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6489 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6490 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6491 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6492 | |
| 6493 | root->AddChild(clip_parent); |
| 6494 | clip_parent->AddChild(render_surface1); |
| 6495 | render_surface1->AddChild(intervening); |
| 6496 | intervening->AddChild(render_surface2); |
| 6497 | render_surface2->AddChild(clip_child); |
| 6498 | |
| 6499 | clip_child->SetClipParent(clip_parent.get()); |
| 6500 | |
| 6501 | intervening->SetMasksToBounds(true); |
| 6502 | clip_parent->SetMasksToBounds(true); |
| 6503 | |
| 6504 | render_surface1->SetForceRenderSurface(true); |
| 6505 | render_surface2->SetForceRenderSurface(true); |
| 6506 | |
| 6507 | gfx::Transform translation_transform; |
| 6508 | translation_transform.Translate(2, 2); |
| 6509 | |
| 6510 | gfx::Transform identity_transform; |
| 6511 | SetLayerPropertiesForTesting(root.get(), |
| 6512 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6513 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6514 | gfx::PointF(), |
| 6515 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6516 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6517 | false); |
| 6518 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6519 | translation_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6520 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6521 | gfx::PointF(1.f, 1.f), |
| 6522 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6523 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6524 | false); |
| 6525 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6526 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6527 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6528 | gfx::PointF(), |
| 6529 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6530 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6531 | false); |
| 6532 | SetLayerPropertiesForTesting(intervening.get(), |
| 6533 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6534 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6535 | gfx::PointF(1.f, 1.f), |
| 6536 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6537 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6538 | false); |
| 6539 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6540 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6541 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6542 | gfx::PointF(), |
| 6543 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6544 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6545 | false); |
| 6546 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6547 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6548 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6549 | gfx::PointF(-10.f, -10.f), |
| 6550 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6551 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6552 | false); |
| 6553 | |
| 6554 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6555 | host->SetRootLayer(root); |
| 6556 | |
| 6557 | ExecuteCalculateDrawProperties(root.get()); |
| 6558 | |
| 6559 | EXPECT_TRUE(root->render_surface()); |
| 6560 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6561 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6562 | |
| 6563 | // Since the render surfaces could have expanded, they should not clip (their |
| 6564 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6565 | // in this case. |
| 6566 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6567 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6568 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6569 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6570 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6571 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6572 | |
| 6573 | // NB: clip rects are in target space. |
| 6574 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6575 | render_surface1->clip_rect().ToString()); |
| 6576 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6577 | |
| 6578 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6579 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6580 | render_surface2->clip_rect().ToString()); |
| 6581 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6582 | |
| 6583 | // The content rects of both render surfaces should both have expanded to |
| 6584 | // contain the clip child. |
| 6585 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6586 | render_surface1->render_surface()->content_rect().ToString()); |
| 6587 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6588 | render_surface2->render_surface()->content_rect().ToString()); |
| 6589 | |
| 6590 | // The clip child should have inherited the clip parent's clip (projected to |
| 6591 | // the right space, of course), and should have the correctly sized visible |
| 6592 | // content rect. |
| 6593 | EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(), |
| 6594 | clip_child->clip_rect().ToString()); |
| 6595 | EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(), |
| 6596 | clip_child->visible_content_rect().ToString()); |
| 6597 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6598 | } |
| 6599 | |
| 6600 | TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) { |
| 6601 | // Ensure that intervening render surfaces are not a problem, even if there |
| 6602 | // is a scroll involved. Note, we do _not_ have to consider any other sort |
| 6603 | // of transform. |
| 6604 | // |
| 6605 | // root (a render surface) |
| 6606 | // + clip_parent (masks to bounds) |
| 6607 | // + render_surface1 (sets opacity) |
| 6608 | // + intervening (masks to bounds AND scrolls) |
| 6609 | // + render_surface2 (also sets opacity) |
| 6610 | // + clip_child |
| 6611 | // |
| 6612 | scoped_refptr<Layer> root = Layer::Create(); |
| 6613 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6614 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6615 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6616 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6617 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6618 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6619 | |
| 6620 | root->AddChild(clip_parent); |
| 6621 | clip_parent->AddChild(render_surface1); |
| 6622 | render_surface1->AddChild(intervening); |
| 6623 | intervening->AddChild(render_surface2); |
| 6624 | render_surface2->AddChild(clip_child); |
| 6625 | |
| 6626 | clip_child->SetClipParent(clip_parent.get()); |
| 6627 | |
| 6628 | intervening->SetMasksToBounds(true); |
| 6629 | clip_parent->SetMasksToBounds(true); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 6630 | intervening->SetScrollClipLayerId(clip_parent->id()); |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6631 | intervening->SetScrollOffset(gfx::Vector2d(3, 3)); |
| 6632 | |
| 6633 | render_surface1->SetForceRenderSurface(true); |
| 6634 | render_surface2->SetForceRenderSurface(true); |
| 6635 | |
| 6636 | gfx::Transform translation_transform; |
| 6637 | translation_transform.Translate(2, 2); |
| 6638 | |
| 6639 | gfx::Transform identity_transform; |
| 6640 | SetLayerPropertiesForTesting(root.get(), |
| 6641 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6642 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6643 | gfx::PointF(), |
| 6644 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6645 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6646 | false); |
| 6647 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6648 | translation_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6649 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6650 | gfx::PointF(1.f, 1.f), |
| 6651 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6652 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6653 | false); |
| 6654 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6655 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6656 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6657 | gfx::PointF(), |
| 6658 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6659 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6660 | false); |
| 6661 | SetLayerPropertiesForTesting(intervening.get(), |
| 6662 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6663 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6664 | gfx::PointF(1.f, 1.f), |
| 6665 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6666 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6667 | false); |
| 6668 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6669 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6670 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6671 | gfx::PointF(), |
| 6672 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6673 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6674 | false); |
| 6675 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6676 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6677 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6678 | gfx::PointF(-10.f, -10.f), |
| 6679 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6680 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6681 | false); |
| 6682 | |
| 6683 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6684 | host->SetRootLayer(root); |
| 6685 | |
| 6686 | ExecuteCalculateDrawProperties(root.get()); |
| 6687 | |
| 6688 | EXPECT_TRUE(root->render_surface()); |
| 6689 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6690 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6691 | |
| 6692 | // Since the render surfaces could have expanded, they should not clip (their |
| 6693 | // bounds would no longer be reliable). We should resort to layer clipping |
| 6694 | // in this case. |
| 6695 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6696 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6697 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6698 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6699 | render_surface2->render_surface()->clip_rect().ToString()); |
| 6700 | EXPECT_FALSE(render_surface2->render_surface()->is_clipped()); |
| 6701 | |
| 6702 | // NB: clip rects are in target space. |
| 6703 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6704 | render_surface1->clip_rect().ToString()); |
| 6705 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6706 | |
| 6707 | // This value is inherited from the clipping ancestor layer, 'intervening'. |
| 6708 | EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(), |
| 6709 | render_surface2->clip_rect().ToString()); |
| 6710 | EXPECT_TRUE(render_surface2->is_clipped()); |
| 6711 | |
| 6712 | // The content rects of both render surfaces should both have expanded to |
| 6713 | // contain the clip child. |
| 6714 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6715 | render_surface1->render_surface()->content_rect().ToString()); |
| 6716 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6717 | render_surface2->render_surface()->content_rect().ToString()); |
| 6718 | |
| 6719 | // The clip child should have inherited the clip parent's clip (projected to |
| 6720 | // the right space, of course), and should have the correctly sized visible |
| 6721 | // content rect. |
| 6722 | EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(), |
| 6723 | clip_child->clip_rect().ToString()); |
| 6724 | EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(), |
| 6725 | clip_child->visible_content_rect().ToString()); |
| 6726 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6727 | } |
| 6728 | |
| 6729 | TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) { |
| 6730 | // Ensures that descendants of the clip child inherit the correct clip. |
| 6731 | // |
| 6732 | // root (a render surface) |
| 6733 | // + clip_parent (masks to bounds) |
| 6734 | // + intervening (masks to bounds) |
| 6735 | // + clip_child |
| 6736 | // + child |
| 6737 | // |
| 6738 | scoped_refptr<Layer> root = Layer::Create(); |
| 6739 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6740 | scoped_refptr<Layer> intervening = Layer::Create(); |
| 6741 | scoped_refptr<Layer> clip_child = Layer::Create(); |
| 6742 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 6743 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6744 | |
| 6745 | root->AddChild(clip_parent); |
| 6746 | clip_parent->AddChild(intervening); |
| 6747 | intervening->AddChild(clip_child); |
| 6748 | clip_child->AddChild(child); |
| 6749 | |
| 6750 | clip_child->SetClipParent(clip_parent.get()); |
| 6751 | |
| 6752 | intervening->SetMasksToBounds(true); |
| 6753 | clip_parent->SetMasksToBounds(true); |
| 6754 | |
| 6755 | gfx::Transform identity_transform; |
| 6756 | SetLayerPropertiesForTesting(root.get(), |
| 6757 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6758 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6759 | gfx::PointF(), |
| 6760 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6761 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6762 | false); |
| 6763 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6764 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6765 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6766 | gfx::PointF(), |
| 6767 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6768 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6769 | false); |
| 6770 | SetLayerPropertiesForTesting(intervening.get(), |
| 6771 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6772 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6773 | gfx::PointF(), |
| 6774 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6775 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6776 | false); |
| 6777 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6778 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6779 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6780 | gfx::PointF(), |
| 6781 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6782 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6783 | false); |
| 6784 | SetLayerPropertiesForTesting(child.get(), |
| 6785 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6786 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6787 | gfx::PointF(), |
| 6788 | gfx::Size(60, 60), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6789 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6790 | false); |
| 6791 | |
| 6792 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6793 | host->SetRootLayer(root); |
| 6794 | |
| 6795 | ExecuteCalculateDrawProperties(root.get()); |
| 6796 | |
| 6797 | EXPECT_TRUE(root->render_surface()); |
| 6798 | |
| 6799 | // Neither the clip child nor its descendant should have inherited the clip |
| 6800 | // from |intervening|. |
| 6801 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6802 | clip_child->clip_rect().ToString()); |
| 6803 | EXPECT_TRUE(clip_child->is_clipped()); |
| 6804 | EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(), |
| 6805 | child->visible_content_rect().ToString()); |
| 6806 | EXPECT_TRUE(child->is_clipped()); |
| 6807 | } |
| 6808 | |
| 6809 | TEST_F(LayerTreeHostCommonTest, |
| 6810 | SurfacesShouldBeUnaffectedByNonDescendantClipChildren) { |
| 6811 | // Ensures that non-descendant clip children in the tree do not affect |
| 6812 | // render surfaces. |
| 6813 | // |
| 6814 | // root (a render surface) |
| 6815 | // + clip_parent (masks to bounds) |
| 6816 | // + render_surface1 |
| 6817 | // + clip_child |
| 6818 | // + render_surface2 |
| 6819 | // + non_clip_child |
| 6820 | // |
| 6821 | // In this example render_surface2 should be unaffected by clip_child. |
| 6822 | scoped_refptr<Layer> root = Layer::Create(); |
| 6823 | scoped_refptr<Layer> clip_parent = Layer::Create(); |
| 6824 | scoped_refptr<Layer> render_surface1 = Layer::Create(); |
| 6825 | scoped_refptr<LayerWithForcedDrawsContent> clip_child = |
| 6826 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6827 | scoped_refptr<Layer> render_surface2 = Layer::Create(); |
| 6828 | scoped_refptr<LayerWithForcedDrawsContent> non_clip_child = |
| 6829 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 6830 | |
| 6831 | root->AddChild(clip_parent); |
| 6832 | clip_parent->AddChild(render_surface1); |
| 6833 | render_surface1->AddChild(clip_child); |
| 6834 | clip_parent->AddChild(render_surface2); |
| 6835 | render_surface2->AddChild(non_clip_child); |
| 6836 | |
| 6837 | clip_child->SetClipParent(clip_parent.get()); |
| 6838 | |
| 6839 | clip_parent->SetMasksToBounds(true); |
| 6840 | render_surface1->SetMasksToBounds(true); |
| 6841 | |
| 6842 | gfx::Transform identity_transform; |
| 6843 | SetLayerPropertiesForTesting(root.get(), |
| 6844 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6845 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6846 | gfx::PointF(), |
| 6847 | gfx::Size(15, 15), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6848 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6849 | false); |
| 6850 | SetLayerPropertiesForTesting(clip_parent.get(), |
| 6851 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6852 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6853 | gfx::PointF(), |
| 6854 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6855 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6856 | false); |
| 6857 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 6858 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6859 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6860 | gfx::PointF(5, 5), |
| 6861 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6862 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6863 | false); |
| 6864 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 6865 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6866 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6867 | gfx::PointF(), |
| 6868 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6869 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6870 | false); |
| 6871 | SetLayerPropertiesForTesting(clip_child.get(), |
| 6872 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6873 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6874 | gfx::PointF(-1, 1), |
| 6875 | gfx::Size(10, 10), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6876 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6877 | false); |
| 6878 | SetLayerPropertiesForTesting(non_clip_child.get(), |
| 6879 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6880 | gfx::Point3F(), |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6881 | gfx::PointF(), |
| 6882 | gfx::Size(5, 5), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6883 | true, |
[email protected] | 420fdf6e | 2013-08-26 20:36:38 | [diff] [blame] | 6884 | false); |
| 6885 | |
| 6886 | render_surface1->SetForceRenderSurface(true); |
| 6887 | render_surface2->SetForceRenderSurface(true); |
| 6888 | |
| 6889 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 6890 | host->SetRootLayer(root); |
| 6891 | |
| 6892 | ExecuteCalculateDrawProperties(root.get()); |
| 6893 | |
| 6894 | EXPECT_TRUE(root->render_surface()); |
| 6895 | EXPECT_TRUE(render_surface1->render_surface()); |
| 6896 | EXPECT_TRUE(render_surface2->render_surface()); |
| 6897 | |
| 6898 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6899 | render_surface1->clip_rect().ToString()); |
| 6900 | EXPECT_TRUE(render_surface1->is_clipped()); |
| 6901 | |
| 6902 | // The render surface should not clip (it has unclipped descendants), instead |
| 6903 | // it should rely on layer clipping. |
| 6904 | EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(), |
| 6905 | render_surface1->render_surface()->clip_rect().ToString()); |
| 6906 | EXPECT_FALSE(render_surface1->render_surface()->is_clipped()); |
| 6907 | |
| 6908 | // That said, it should have grown to accomodate the unclipped descendant. |
| 6909 | EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(), |
| 6910 | render_surface1->render_surface()->content_rect().ToString()); |
| 6911 | |
| 6912 | // This render surface should clip. It has no unclipped descendants. |
| 6913 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6914 | render_surface2->clip_rect().ToString()); |
| 6915 | EXPECT_TRUE(render_surface2->render_surface()->is_clipped()); |
| 6916 | |
| 6917 | // It also shouldn't have grown to accomodate the clip child. |
| 6918 | EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(), |
| 6919 | render_surface2->render_surface()->content_rect().ToString()); |
| 6920 | |
| 6921 | // Sanity check our num_unclipped_descendants values. |
| 6922 | EXPECT_EQ(1, render_surface1->num_unclipped_descendants()); |
| 6923 | EXPECT_EQ(0, render_surface2->num_unclipped_descendants()); |
| 6924 | } |
| 6925 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6926 | TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { |
| 6927 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 6928 | TestSharedBitmapManager shared_bitmap_manager; |
| 6929 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6930 | scoped_ptr<LayerImpl> root = |
| 6931 | LayerImpl::Create(host_impl.active_tree(), 12345); |
| 6932 | scoped_ptr<LayerImpl> child1 = |
| 6933 | LayerImpl::Create(host_impl.active_tree(), 123456); |
| 6934 | scoped_ptr<LayerImpl> child2 = |
| 6935 | LayerImpl::Create(host_impl.active_tree(), 1234567); |
| 6936 | scoped_ptr<LayerImpl> child3 = |
| 6937 | LayerImpl::Create(host_impl.active_tree(), 12345678); |
| 6938 | |
| 6939 | gfx::Transform identity_matrix; |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6940 | gfx::Point3F transform_origin; |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6941 | gfx::PointF position; |
| 6942 | gfx::Size bounds(100, 100); |
| 6943 | SetLayerPropertiesForTesting(root.get(), |
| 6944 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6945 | transform_origin, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6946 | position, |
| 6947 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6948 | true, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6949 | false); |
| 6950 | root->SetDrawsContent(true); |
| 6951 | |
| 6952 | // This layer structure normally forces render surface due to preserves3d |
| 6953 | // behavior. |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6954 | SetLayerPropertiesForTesting(child1.get(), |
| 6955 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6956 | transform_origin, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6957 | position, |
| 6958 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6959 | false, |
| 6960 | true); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6961 | child1->SetDrawsContent(true); |
| 6962 | SetLayerPropertiesForTesting(child2.get(), |
| 6963 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6964 | transform_origin, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6965 | position, |
| 6966 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6967 | true, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6968 | false); |
| 6969 | child2->SetDrawsContent(true); |
| 6970 | SetLayerPropertiesForTesting(child3.get(), |
| 6971 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 6972 | transform_origin, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6973 | position, |
| 6974 | bounds, |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6975 | true, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6976 | false); |
| 6977 | child3->SetDrawsContent(true); |
| 6978 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 6979 | child2->SetIs3dSorted(true); |
| 6980 | child3->SetIs3dSorted(true); |
| 6981 | |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 6982 | child2->AddChild(child3.Pass()); |
| 6983 | child1->AddChild(child2.Pass()); |
| 6984 | root->AddChild(child1.Pass()); |
| 6985 | |
| 6986 | { |
| 6987 | LayerImplList render_surface_layer_list; |
| 6988 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 6989 | root.get(), root->bounds(), &render_surface_layer_list); |
| 6990 | inputs.can_render_to_separate_surface = true; |
| 6991 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 6992 | |
| 6993 | EXPECT_EQ(2u, render_surface_layer_list.size()); |
| 6994 | } |
| 6995 | |
| 6996 | { |
| 6997 | LayerImplList render_surface_layer_list; |
| 6998 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 6999 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7000 | inputs.can_render_to_separate_surface = false; |
| 7001 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7002 | |
| 7003 | EXPECT_EQ(1u, render_surface_layer_list.size()); |
| 7004 | } |
| 7005 | } |
| 7006 | |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7007 | TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { |
| 7008 | scoped_refptr<Layer> root = Layer::Create(); |
| 7009 | scoped_refptr<Layer> render_surface = Layer::Create(); |
| 7010 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 7011 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7012 | |
| 7013 | root->AddChild(render_surface); |
| 7014 | render_surface->AddChild(child); |
| 7015 | |
| 7016 | gfx::Transform identity_transform; |
| 7017 | SetLayerPropertiesForTesting(root.get(), |
| 7018 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7019 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7020 | gfx::PointF(), |
| 7021 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7022 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7023 | false); |
| 7024 | SetLayerPropertiesForTesting(render_surface.get(), |
| 7025 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7026 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7027 | gfx::PointF(), |
| 7028 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7029 | false, |
| 7030 | true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7031 | SetLayerPropertiesForTesting(child.get(), |
| 7032 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7033 | gfx::Point3F(), |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7034 | gfx::PointF(), |
| 7035 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7036 | true, |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7037 | false); |
| 7038 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7039 | root->SetShouldFlattenTransform(false); |
| 7040 | root->SetIs3dSorted(true); |
[email protected] | a9aa60a8 | 2013-08-29 04:28:26 | [diff] [blame] | 7041 | render_surface->SetDoubleSided(false); |
| 7042 | render_surface->SetForceRenderSurface(true); |
| 7043 | |
| 7044 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7045 | host->SetRootLayer(root); |
| 7046 | |
| 7047 | ExecuteCalculateDrawProperties(root.get()); |
| 7048 | |
| 7049 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 7050 | EXPECT_EQ(1u, |
| 7051 | render_surface_layer_list()->at(0) |
| 7052 | ->render_surface()->layer_list().size()); |
| 7053 | EXPECT_EQ(1u, |
| 7054 | render_surface_layer_list()->at(1) |
| 7055 | ->render_surface()->layer_list().size()); |
| 7056 | |
| 7057 | gfx::Transform rotation_transform = identity_transform; |
| 7058 | rotation_transform.RotateAboutXAxis(180.0); |
| 7059 | |
| 7060 | render_surface->SetTransform(rotation_transform); |
| 7061 | |
| 7062 | ExecuteCalculateDrawProperties(root.get()); |
| 7063 | |
| 7064 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 7065 | EXPECT_EQ(0u, |
| 7066 | render_surface_layer_list()->at(0) |
| 7067 | ->render_surface()->layer_list().size()); |
| 7068 | } |
| 7069 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7070 | TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) { |
| 7071 | // Checks that the simple case (being clipped by a scroll parent that would |
| 7072 | // have been processed before you anyhow) results in the right clips. |
| 7073 | // |
| 7074 | // + root |
| 7075 | // + scroll_parent_border |
| 7076 | // | + scroll_parent_clip |
| 7077 | // | + scroll_parent |
| 7078 | // + scroll_child |
| 7079 | // |
| 7080 | scoped_refptr<Layer> root = Layer::Create(); |
| 7081 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7082 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7083 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7084 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7085 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7086 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7087 | |
| 7088 | root->AddChild(scroll_child); |
| 7089 | |
| 7090 | root->AddChild(scroll_parent_border); |
| 7091 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7092 | scroll_parent_clip->AddChild(scroll_parent); |
| 7093 | |
| 7094 | scroll_parent_clip->SetMasksToBounds(true); |
| 7095 | |
| 7096 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7097 | |
| 7098 | gfx::Transform identity_transform; |
| 7099 | SetLayerPropertiesForTesting(root.get(), |
| 7100 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7101 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7102 | gfx::PointF(), |
| 7103 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7104 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7105 | false); |
| 7106 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7107 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7108 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7109 | gfx::PointF(), |
| 7110 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7111 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7112 | false); |
| 7113 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7114 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7115 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7116 | gfx::PointF(), |
| 7117 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7118 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7119 | false); |
| 7120 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7121 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7122 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7123 | gfx::PointF(), |
| 7124 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7125 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7126 | false); |
| 7127 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7128 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7129 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7130 | gfx::PointF(), |
| 7131 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7132 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7133 | false); |
| 7134 | |
| 7135 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7136 | host->SetRootLayer(root); |
| 7137 | |
| 7138 | ExecuteCalculateDrawProperties(root.get()); |
| 7139 | |
| 7140 | EXPECT_TRUE(root->render_surface()); |
| 7141 | |
| 7142 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 7143 | scroll_child->clip_rect().ToString()); |
| 7144 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7145 | } |
| 7146 | |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7147 | TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) { |
| 7148 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 7149 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7150 | scoped_refptr<LayerWithForcedDrawsContent> parent = |
| 7151 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7152 | scoped_refptr<LayerWithForcedDrawsContent> child = |
| 7153 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7154 | |
| 7155 | root->AddChild(parent); |
| 7156 | parent->AddChild(child); |
| 7157 | |
| 7158 | gfx::Transform identity_transform; |
| 7159 | SetLayerPropertiesForTesting(root.get(), |
| 7160 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7161 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7162 | gfx::PointF(), |
| 7163 | gfx::Size(50, 50), |
| 7164 | true, |
| 7165 | true); |
| 7166 | root->SetForceRenderSurface(true); |
| 7167 | SetLayerPropertiesForTesting(parent.get(), |
| 7168 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7169 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7170 | gfx::PointF(), |
| 7171 | gfx::Size(30, 30), |
| 7172 | true, |
| 7173 | true); |
| 7174 | parent->SetForceRenderSurface(true); |
| 7175 | SetLayerPropertiesForTesting(child.get(), |
| 7176 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7177 | gfx::Point3F(), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 7178 | gfx::PointF(), |
| 7179 | gfx::Size(20, 20), |
| 7180 | true, |
| 7181 | true); |
| 7182 | child->SetForceRenderSurface(true); |
| 7183 | |
| 7184 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7185 | host->SetRootLayer(root); |
| 7186 | |
| 7187 | ExecuteCalculateDrawProperties(root.get()); |
| 7188 | |
| 7189 | EXPECT_EQ(3u, render_surface_layer_list()->size()); |
| 7190 | |
| 7191 | gfx::Transform singular_transform; |
| 7192 | singular_transform.Scale3d( |
| 7193 | SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0)); |
| 7194 | |
| 7195 | child->SetTransform(singular_transform); |
| 7196 | |
| 7197 | ExecuteCalculateDrawProperties(root.get()); |
| 7198 | |
| 7199 | EXPECT_EQ(2u, render_surface_layer_list()->size()); |
| 7200 | |
| 7201 | // Ensure that the entire subtree under a layer with singular transform does |
| 7202 | // not get rendered. |
| 7203 | parent->SetTransform(singular_transform); |
| 7204 | child->SetTransform(identity_transform); |
| 7205 | |
| 7206 | ExecuteCalculateDrawProperties(root.get()); |
| 7207 | |
| 7208 | EXPECT_EQ(1u, render_surface_layer_list()->size()); |
| 7209 | } |
| 7210 | |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7211 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) { |
| 7212 | // Checks that clipping by a scroll parent that follows you in paint order |
| 7213 | // still results in correct clipping. |
| 7214 | // |
| 7215 | // + root |
| 7216 | // + scroll_child |
| 7217 | // + scroll_parent_border |
| 7218 | // + scroll_parent_clip |
| 7219 | // + scroll_parent |
| 7220 | // |
| 7221 | scoped_refptr<Layer> root = Layer::Create(); |
| 7222 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7223 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7224 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7225 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7226 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7227 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7228 | |
| 7229 | root->AddChild(scroll_parent_border); |
| 7230 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7231 | scroll_parent_clip->AddChild(scroll_parent); |
| 7232 | |
| 7233 | root->AddChild(scroll_child); |
| 7234 | |
| 7235 | scroll_parent_clip->SetMasksToBounds(true); |
| 7236 | |
| 7237 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7238 | |
| 7239 | gfx::Transform identity_transform; |
| 7240 | SetLayerPropertiesForTesting(root.get(), |
| 7241 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7242 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7243 | gfx::PointF(), |
| 7244 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7245 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7246 | false); |
| 7247 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7248 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7249 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7250 | gfx::PointF(), |
| 7251 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7252 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7253 | false); |
| 7254 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7255 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7256 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7257 | gfx::PointF(), |
| 7258 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7259 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7260 | false); |
| 7261 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7262 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7263 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7264 | gfx::PointF(), |
| 7265 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7266 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7267 | false); |
| 7268 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7269 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7270 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7271 | gfx::PointF(), |
| 7272 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7273 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7274 | false); |
| 7275 | |
| 7276 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7277 | host->SetRootLayer(root); |
| 7278 | |
| 7279 | ExecuteCalculateDrawProperties(root.get()); |
| 7280 | |
| 7281 | EXPECT_TRUE(root->render_surface()); |
| 7282 | |
| 7283 | EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(), |
| 7284 | scroll_child->clip_rect().ToString()); |
| 7285 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7286 | } |
| 7287 | |
| 7288 | TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) { |
| 7289 | // Checks that clipping by a scroll parent and scroll grandparent that follow |
| 7290 | // you in paint order still results in correct clipping. |
| 7291 | // |
| 7292 | // + root |
| 7293 | // + scroll_child |
| 7294 | // + scroll_parent_border |
| 7295 | // | + scroll_parent_clip |
| 7296 | // | + scroll_parent |
| 7297 | // + scroll_grandparent_border |
| 7298 | // + scroll_grandparent_clip |
| 7299 | // + scroll_grandparent |
| 7300 | // |
| 7301 | scoped_refptr<Layer> root = Layer::Create(); |
| 7302 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7303 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7304 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7305 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7306 | |
| 7307 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 7308 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 7309 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 7310 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7311 | |
| 7312 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7313 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7314 | |
| 7315 | root->AddChild(scroll_child); |
| 7316 | |
| 7317 | root->AddChild(scroll_parent_border); |
| 7318 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7319 | scroll_parent_clip->AddChild(scroll_parent); |
| 7320 | |
| 7321 | root->AddChild(scroll_grandparent_border); |
| 7322 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 7323 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 7324 | |
| 7325 | scroll_parent_clip->SetMasksToBounds(true); |
| 7326 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 7327 | |
| 7328 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7329 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 7330 | |
| 7331 | gfx::Transform identity_transform; |
| 7332 | SetLayerPropertiesForTesting(root.get(), |
| 7333 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7334 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7335 | gfx::PointF(), |
| 7336 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7337 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7338 | false); |
| 7339 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 7340 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7341 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7342 | gfx::PointF(), |
| 7343 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7344 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7345 | false); |
| 7346 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 7347 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7348 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7349 | gfx::PointF(), |
| 7350 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7351 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7352 | false); |
| 7353 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 7354 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7355 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7356 | gfx::PointF(), |
| 7357 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7358 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7359 | false); |
| 7360 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7361 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7362 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7363 | gfx::PointF(), |
| 7364 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7365 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7366 | false); |
| 7367 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7368 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7369 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7370 | gfx::PointF(), |
| 7371 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7372 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7373 | false); |
| 7374 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7375 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7376 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7377 | gfx::PointF(), |
| 7378 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7379 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7380 | false); |
| 7381 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7382 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7383 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7384 | gfx::PointF(), |
| 7385 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7386 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7387 | false); |
| 7388 | |
| 7389 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7390 | host->SetRootLayer(root); |
| 7391 | |
| 7392 | ExecuteCalculateDrawProperties(root.get()); |
| 7393 | |
| 7394 | EXPECT_TRUE(root->render_surface()); |
| 7395 | |
| 7396 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 7397 | scroll_child->clip_rect().ToString()); |
| 7398 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7399 | |
| 7400 | // Despite the fact that we visited the above layers out of order to get the |
| 7401 | // correct clip, the layer lists should be unaffected. |
| 7402 | EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 7403 | EXPECT_EQ(scroll_child.get(), |
| 7404 | root->render_surface()->layer_list().at(0)); |
| 7405 | EXPECT_EQ(scroll_parent.get(), |
| 7406 | root->render_surface()->layer_list().at(1)); |
| 7407 | EXPECT_EQ(scroll_grandparent.get(), |
| 7408 | root->render_surface()->layer_list().at(2)); |
| 7409 | } |
| 7410 | |
| 7411 | TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) { |
| 7412 | // 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] | 7413 | // correctly ordered render surface layer list. |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7414 | // + root |
| 7415 | // + scroll_child |
| 7416 | // + scroll_parent_border |
| 7417 | // + scroll_parent_clip |
| 7418 | // + scroll_parent |
| 7419 | // + render_surface1 |
| 7420 | // + scroll_grandparent_border |
| 7421 | // + scroll_grandparent_clip |
| 7422 | // + scroll_grandparent |
| 7423 | // + render_surface2 |
| 7424 | // |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 7425 | scoped_refptr<LayerWithForcedDrawsContent> root = |
| 7426 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7427 | |
| 7428 | scoped_refptr<Layer> scroll_parent_border = Layer::Create(); |
| 7429 | scoped_refptr<Layer> scroll_parent_clip = Layer::Create(); |
| 7430 | scoped_refptr<LayerWithForcedDrawsContent> scroll_parent = |
| 7431 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7432 | scoped_refptr<LayerWithForcedDrawsContent> render_surface1 = |
| 7433 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7434 | |
| 7435 | scoped_refptr<Layer> scroll_grandparent_border = Layer::Create(); |
| 7436 | scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create(); |
| 7437 | scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent = |
| 7438 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7439 | scoped_refptr<LayerWithForcedDrawsContent> render_surface2 = |
| 7440 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7441 | |
| 7442 | scoped_refptr<LayerWithForcedDrawsContent> scroll_child = |
| 7443 | make_scoped_refptr(new LayerWithForcedDrawsContent); |
| 7444 | |
| 7445 | root->AddChild(scroll_child); |
| 7446 | |
| 7447 | root->AddChild(scroll_parent_border); |
| 7448 | scroll_parent_border->AddChild(scroll_parent_clip); |
| 7449 | scroll_parent_clip->AddChild(scroll_parent); |
| 7450 | scroll_parent->AddChild(render_surface2); |
| 7451 | |
| 7452 | root->AddChild(scroll_grandparent_border); |
| 7453 | scroll_grandparent_border->AddChild(scroll_grandparent_clip); |
| 7454 | scroll_grandparent_clip->AddChild(scroll_grandparent); |
| 7455 | scroll_grandparent->AddChild(render_surface1); |
| 7456 | |
| 7457 | scroll_parent_clip->SetMasksToBounds(true); |
| 7458 | scroll_grandparent_clip->SetMasksToBounds(true); |
| 7459 | |
| 7460 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7461 | scroll_parent_border->SetScrollParent(scroll_grandparent.get()); |
| 7462 | |
| 7463 | render_surface1->SetForceRenderSurface(true); |
| 7464 | render_surface2->SetForceRenderSurface(true); |
| 7465 | |
| 7466 | gfx::Transform identity_transform; |
| 7467 | SetLayerPropertiesForTesting(root.get(), |
| 7468 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7469 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7470 | gfx::PointF(), |
| 7471 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7472 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7473 | false); |
| 7474 | SetLayerPropertiesForTesting(scroll_grandparent_border.get(), |
| 7475 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7476 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7477 | gfx::PointF(), |
| 7478 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7479 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7480 | false); |
| 7481 | SetLayerPropertiesForTesting(scroll_grandparent_clip.get(), |
| 7482 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7483 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7484 | gfx::PointF(), |
| 7485 | gfx::Size(20, 20), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7486 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7487 | false); |
| 7488 | SetLayerPropertiesForTesting(scroll_grandparent.get(), |
| 7489 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7490 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7491 | gfx::PointF(), |
| 7492 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7493 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7494 | false); |
| 7495 | SetLayerPropertiesForTesting(render_surface1.get(), |
| 7496 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7497 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7498 | gfx::PointF(), |
| 7499 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7500 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7501 | false); |
| 7502 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7503 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7504 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7505 | gfx::PointF(), |
| 7506 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7507 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7508 | false); |
| 7509 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7510 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7511 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7512 | gfx::PointF(), |
| 7513 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7514 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7515 | false); |
| 7516 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7517 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7518 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7519 | gfx::PointF(), |
| 7520 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7521 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7522 | false); |
| 7523 | SetLayerPropertiesForTesting(render_surface2.get(), |
| 7524 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7525 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7526 | gfx::PointF(), |
| 7527 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7528 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7529 | false); |
| 7530 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7531 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7532 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7533 | gfx::PointF(), |
| 7534 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7535 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7536 | false); |
| 7537 | |
| 7538 | scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 7539 | host->SetRootLayer(root); |
| 7540 | |
| 7541 | RenderSurfaceLayerList render_surface_layer_list; |
| 7542 | LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( |
| 7543 | root.get(), |
| 7544 | root->bounds(), |
| 7545 | identity_transform, |
| 7546 | &render_surface_layer_list); |
| 7547 | |
| 7548 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7549 | |
| 7550 | EXPECT_TRUE(root->render_surface()); |
| 7551 | |
| 7552 | EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(), |
| 7553 | scroll_child->clip_rect().ToString()); |
| 7554 | EXPECT_TRUE(scroll_child->is_clipped()); |
| 7555 | |
| 7556 | // Despite the fact that we had to process the layers out of order to get the |
| 7557 | // right clip, our render_surface_layer_list's order should be unaffected. |
| 7558 | EXPECT_EQ(3u, render_surface_layer_list.size()); |
| 7559 | EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); |
| 7560 | EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); |
| 7561 | EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); |
[email protected] | 44d8e84c | 2013-10-19 19:13:22 | [diff] [blame] | 7562 | EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); |
| 7563 | EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); |
| 7564 | EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7565 | } |
| 7566 | |
| 7567 | TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) { |
| 7568 | // We rearrange layer list contributions if we have to visit children out of |
| 7569 | // order, but it should be a 'stable' rearrangement. That is, the layer list |
| 7570 | // additions for a single layer should not be reordered, though their position |
| 7571 | // wrt to the contributions due to a sibling may vary. |
| 7572 | // |
| 7573 | // + root |
| 7574 | // + scroll_child |
| 7575 | // + top_content |
| 7576 | // + bottom_content |
| 7577 | // + scroll_parent_border |
| 7578 | // + scroll_parent_clip |
| 7579 | // + scroll_parent |
| 7580 | // |
| 7581 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7582 | TestSharedBitmapManager shared_bitmap_manager; |
| 7583 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7584 | host_impl.CreatePendingTree(); |
| 7585 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7586 | scoped_ptr<LayerImpl> scroll_parent_border = |
| 7587 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7588 | scoped_ptr<LayerImpl> scroll_parent_clip = |
| 7589 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7590 | scoped_ptr<LayerImpl> scroll_parent = |
| 7591 | LayerImpl::Create(host_impl.active_tree(), 4); |
| 7592 | scoped_ptr<LayerImpl> scroll_child = |
| 7593 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 7594 | scoped_ptr<LayerImpl> bottom_content = |
| 7595 | LayerImpl::Create(host_impl.active_tree(), 6); |
| 7596 | scoped_ptr<LayerImpl> top_content = |
| 7597 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 7598 | |
| 7599 | scroll_parent_clip->SetMasksToBounds(true); |
| 7600 | |
| 7601 | scroll_child->SetScrollParent(scroll_parent.get()); |
| 7602 | scoped_ptr<std::set<LayerImpl*> > scroll_children(new std::set<LayerImpl*>); |
| 7603 | scroll_children->insert(scroll_child.get()); |
| 7604 | scroll_parent->SetScrollChildren(scroll_children.release()); |
| 7605 | |
| 7606 | scroll_child->SetDrawsContent(true); |
| 7607 | scroll_parent->SetDrawsContent(true); |
| 7608 | top_content->SetDrawsContent(true); |
| 7609 | bottom_content->SetDrawsContent(true); |
| 7610 | |
| 7611 | gfx::Transform identity_transform; |
| 7612 | gfx::Transform top_transform; |
| 7613 | top_transform.Translate3d(0.0, 0.0, 5.0); |
| 7614 | gfx::Transform bottom_transform; |
| 7615 | bottom_transform.Translate3d(0.0, 0.0, 3.0); |
| 7616 | |
| 7617 | SetLayerPropertiesForTesting(root.get(), |
| 7618 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7619 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7620 | gfx::PointF(), |
| 7621 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7622 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7623 | false); |
| 7624 | SetLayerPropertiesForTesting(scroll_parent_border.get(), |
| 7625 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7626 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7627 | gfx::PointF(), |
| 7628 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7629 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7630 | false); |
| 7631 | SetLayerPropertiesForTesting(scroll_parent_clip.get(), |
| 7632 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7633 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7634 | gfx::PointF(), |
| 7635 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7636 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7637 | false); |
| 7638 | SetLayerPropertiesForTesting(scroll_parent.get(), |
| 7639 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7640 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7641 | gfx::PointF(), |
| 7642 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7643 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7644 | false); |
| 7645 | SetLayerPropertiesForTesting(scroll_child.get(), |
| 7646 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7647 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7648 | gfx::PointF(), |
| 7649 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7650 | true, |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7651 | false); |
| 7652 | SetLayerPropertiesForTesting(top_content.get(), |
| 7653 | top_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7654 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7655 | gfx::PointF(), |
| 7656 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7657 | false, |
| 7658 | true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7659 | SetLayerPropertiesForTesting(bottom_content.get(), |
| 7660 | bottom_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7661 | gfx::Point3F(), |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7662 | gfx::PointF(), |
| 7663 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7664 | false, |
| 7665 | true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7666 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7667 | scroll_child->SetShouldFlattenTransform(false); |
| 7668 | scroll_child->SetIs3dSorted(true); |
[email protected] | 995708c5 | 2013-10-17 20:52:59 | [diff] [blame] | 7669 | |
| 7670 | scroll_child->AddChild(top_content.Pass()); |
| 7671 | scroll_child->AddChild(bottom_content.Pass()); |
| 7672 | root->AddChild(scroll_child.Pass()); |
| 7673 | |
| 7674 | scroll_parent_clip->AddChild(scroll_parent.Pass()); |
| 7675 | scroll_parent_border->AddChild(scroll_parent_clip.Pass()); |
| 7676 | root->AddChild(scroll_parent_border.Pass()); |
| 7677 | |
| 7678 | LayerImplList render_surface_layer_list; |
| 7679 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7680 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7681 | |
| 7682 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7683 | |
| 7684 | EXPECT_TRUE(root->render_surface()); |
| 7685 | |
| 7686 | // If we don't sort by depth and let the layers get added in the order they |
| 7687 | // would normally be visited in, then layers 6 and 7 will be out of order. In |
| 7688 | // other words, although we've had to shift 5, 6, and 7 to appear before 4 |
| 7689 | // in the list (because of the scroll parent relationship), this should not |
| 7690 | // have an effect on the the order of 5, 6, and 7 (which had been reordered |
| 7691 | // due to layer sorting). |
| 7692 | EXPECT_EQ(4u, root->render_surface()->layer_list().size()); |
| 7693 | EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id()); |
| 7694 | EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id()); |
| 7695 | EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id()); |
| 7696 | EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id()); |
| 7697 | } |
| 7698 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7699 | TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 7700 | // This test verifies that a scrolling layer that gets snapped to |
| 7701 | // integer coordinates doesn't move a fixed position child. |
| 7702 | // |
| 7703 | // + root |
| 7704 | // + container |
| 7705 | // + scroller |
| 7706 | // + fixed |
| 7707 | // |
| 7708 | FakeImplProxy proxy; |
[email protected] | 4e2eb35 | 2014-03-20 17:25:45 | [diff] [blame] | 7709 | TestSharedBitmapManager shared_bitmap_manager; |
| 7710 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7711 | host_impl.CreatePendingTree(); |
| 7712 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 7713 | scoped_ptr<LayerImpl> container = |
| 7714 | LayerImpl::Create(host_impl.active_tree(), 2); |
| 7715 | LayerImpl* container_layer = container.get(); |
| 7716 | scoped_ptr<LayerImpl> scroller = |
| 7717 | LayerImpl::Create(host_impl.active_tree(), 3); |
| 7718 | LayerImpl* scroll_layer = scroller.get(); |
| 7719 | scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); |
| 7720 | LayerImpl* fixed_layer = fixed.get(); |
| 7721 | |
| 7722 | container->SetIsContainerForFixedPositionLayers(true); |
| 7723 | |
| 7724 | LayerPositionConstraint constraint; |
| 7725 | constraint.set_is_fixed_position(true); |
| 7726 | fixed->SetPositionConstraint(constraint); |
| 7727 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 7728 | scroller->SetScrollClipLayer(container->id()); |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7729 | |
| 7730 | gfx::Transform identity_transform; |
| 7731 | gfx::Transform container_transform; |
| 7732 | container_transform.Translate3d(10.0, 20.0, 0.0); |
| 7733 | gfx::Vector2dF container_offset = container_transform.To2dTranslation(); |
| 7734 | |
| 7735 | SetLayerPropertiesForTesting(root.get(), |
| 7736 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7737 | gfx::Point3F(), |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7738 | gfx::PointF(), |
| 7739 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7740 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7741 | false); |
| 7742 | SetLayerPropertiesForTesting(container.get(), |
| 7743 | container_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7744 | gfx::Point3F(), |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7745 | gfx::PointF(), |
| 7746 | gfx::Size(40, 40), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7747 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7748 | false); |
| 7749 | SetLayerPropertiesForTesting(scroller.get(), |
| 7750 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7751 | gfx::Point3F(), |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7752 | gfx::PointF(), |
| 7753 | gfx::Size(30, 30), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7754 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7755 | false); |
| 7756 | SetLayerPropertiesForTesting(fixed.get(), |
| 7757 | identity_transform, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7758 | gfx::Point3F(), |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7759 | gfx::PointF(), |
| 7760 | gfx::Size(50, 50), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 7761 | true, |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7762 | false); |
| 7763 | |
| 7764 | scroller->AddChild(fixed.Pass()); |
| 7765 | container->AddChild(scroller.Pass()); |
| 7766 | root->AddChild(container.Pass()); |
| 7767 | |
| 7768 | // Rounded to integers already. |
| 7769 | { |
| 7770 | gfx::Vector2dF scroll_delta(3.0, 5.0); |
| 7771 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7772 | |
| 7773 | LayerImplList render_surface_layer_list; |
| 7774 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7775 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7776 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7777 | |
| 7778 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7779 | container_layer->draw_properties().screen_space_transform, |
| 7780 | fixed_layer->draw_properties().screen_space_transform); |
| 7781 | EXPECT_VECTOR_EQ( |
| 7782 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7783 | container_offset); |
| 7784 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7785 | .screen_space_transform.To2dTranslation(), |
| 7786 | container_offset - scroll_delta); |
| 7787 | } |
| 7788 | |
| 7789 | // Scroll delta requiring rounding. |
| 7790 | { |
| 7791 | gfx::Vector2dF scroll_delta(4.1f, 8.1f); |
| 7792 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7793 | |
| 7794 | gfx::Vector2dF rounded_scroll_delta(4.f, 8.f); |
| 7795 | |
| 7796 | LayerImplList render_surface_layer_list; |
| 7797 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7798 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7799 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7800 | |
| 7801 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7802 | container_layer->draw_properties().screen_space_transform, |
| 7803 | fixed_layer->draw_properties().screen_space_transform); |
| 7804 | EXPECT_VECTOR_EQ( |
| 7805 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7806 | container_offset); |
| 7807 | EXPECT_VECTOR_EQ(scroll_layer->draw_properties() |
| 7808 | .screen_space_transform.To2dTranslation(), |
| 7809 | container_offset - rounded_scroll_delta); |
| 7810 | } |
[email protected] | cf15ad7b | 2014-04-02 03:59:26 | [diff] [blame] | 7811 | |
| 7812 | // Scale is applied earlier in the tree. |
| 7813 | { |
| 7814 | gfx::Transform scaled_container_transform = container_transform; |
| 7815 | scaled_container_transform.Scale3d(3.0, 3.0, 1.0); |
| 7816 | container_layer->SetTransform(scaled_container_transform); |
| 7817 | |
| 7818 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7819 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7820 | |
| 7821 | LayerImplList render_surface_layer_list; |
| 7822 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7823 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7824 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7825 | |
| 7826 | EXPECT_TRANSFORMATION_MATRIX_EQ( |
| 7827 | container_layer->draw_properties().screen_space_transform, |
| 7828 | fixed_layer->draw_properties().screen_space_transform); |
| 7829 | EXPECT_VECTOR_EQ( |
| 7830 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7831 | container_offset); |
| 7832 | |
| 7833 | container_layer->SetTransform(container_transform); |
| 7834 | } |
| 7835 | |
| 7836 | // Scale is applied on the scroll layer itself. |
| 7837 | { |
| 7838 | gfx::Transform scale_transform; |
| 7839 | scale_transform.Scale3d(3.0, 3.0, 1.0); |
| 7840 | scroll_layer->SetTransform(scale_transform); |
| 7841 | |
| 7842 | gfx::Vector2dF scroll_delta(4.5f, 8.5f); |
| 7843 | scroll_layer->SetScrollDelta(scroll_delta); |
| 7844 | |
| 7845 | LayerImplList render_surface_layer_list; |
| 7846 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 7847 | root.get(), root->bounds(), &render_surface_layer_list); |
| 7848 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 7849 | |
| 7850 | EXPECT_VECTOR_EQ( |
| 7851 | fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7852 | container_offset); |
| 7853 | |
| 7854 | scroll_layer->SetTransform(identity_transform); |
| 7855 | } |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 7856 | } |
| 7857 | |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7858 | class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 7859 | public: |
| 7860 | static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
| 7861 | LayerTreeImpl* tree_impl, |
| 7862 | int id) { |
| 7863 | return make_scoped_ptr( |
| 7864 | new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7865 | } |
| 7866 | |
| 7867 | virtual ~AnimationScaleFactorTrackingLayerImpl() {} |
| 7868 | |
| 7869 | virtual void CalculateContentsScale(float ideal_contents_scale, |
| 7870 | float device_scale_factor, |
| 7871 | float page_scale_factor, |
| 7872 | float maximum_animation_contents_scale, |
| 7873 | bool animating_transform_to_screen, |
| 7874 | float* contents_scale_x, |
| 7875 | float* contents_scale_y, |
| 7876 | gfx::Size* content_bounds) OVERRIDE { |
| 7877 | last_maximum_animation_contents_scale_ = maximum_animation_contents_scale; |
| 7878 | LayerImpl::CalculateContentsScale(ideal_contents_scale, |
| 7879 | device_scale_factor, |
| 7880 | page_scale_factor, |
| 7881 | maximum_animation_contents_scale, |
| 7882 | animating_transform_to_screen, |
| 7883 | contents_scale_x, |
| 7884 | contents_scale_y, |
| 7885 | content_bounds); |
| 7886 | } |
| 7887 | |
| 7888 | float last_maximum_animation_contents_scale() { |
| 7889 | return last_maximum_animation_contents_scale_; |
| 7890 | } |
| 7891 | |
| 7892 | private: |
| 7893 | explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7894 | int id) |
| 7895 | : LayerImpl(tree_impl, id), last_maximum_animation_contents_scale_(0.f) { |
| 7896 | SetDrawsContent(true); |
| 7897 | } |
| 7898 | |
| 7899 | float last_maximum_animation_contents_scale_; |
| 7900 | }; |
| 7901 | |
| 7902 | TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
| 7903 | FakeImplProxy proxy; |
| 7904 | TestSharedBitmapManager shared_bitmap_manager; |
| 7905 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 7906 | gfx::Transform identity_matrix; |
| 7907 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
| 7908 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
| 7909 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
| 7910 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
| 7911 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
| 7912 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
| 7913 | scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
| 7914 | AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 7915 | |
| 7916 | AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 7917 | AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 7918 | AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
| 7919 | |
| 7920 | child->AddChild(grand_child.PassAs<LayerImpl>()); |
| 7921 | parent->AddChild(child.PassAs<LayerImpl>()); |
| 7922 | grand_parent->AddChild(parent.PassAs<LayerImpl>()); |
| 7923 | |
| 7924 | SetLayerPropertiesForTesting(grand_parent.get(), |
| 7925 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7926 | gfx::Point3F(), |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7927 | gfx::PointF(), |
| 7928 | gfx::Size(1, 2), |
| 7929 | true, |
| 7930 | false); |
| 7931 | SetLayerPropertiesForTesting(parent_raw, |
| 7932 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7933 | gfx::Point3F(), |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7934 | gfx::PointF(), |
| 7935 | gfx::Size(1, 2), |
| 7936 | true, |
| 7937 | false); |
| 7938 | SetLayerPropertiesForTesting(child_raw, |
| 7939 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7940 | gfx::Point3F(), |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7941 | gfx::PointF(), |
| 7942 | gfx::Size(1, 2), |
| 7943 | true, |
| 7944 | false); |
| 7945 | SetLayerPropertiesForTesting(grand_child_raw, |
| 7946 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 7947 | gfx::Point3F(), |
[email protected] | 1c3626e | 2014-04-09 17:49:22 | [diff] [blame] | 7948 | gfx::PointF(), |
| 7949 | gfx::Size(1, 2), |
| 7950 | true, |
| 7951 | false); |
| 7952 | |
| 7953 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7954 | |
| 7955 | // No layers have animations. |
| 7956 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 7957 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 7958 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 7959 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 7960 | |
| 7961 | TransformOperations translation; |
| 7962 | translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7963 | |
| 7964 | AddAnimatedTransformToLayer( |
| 7965 | parent_raw, 1.0, TransformOperations(), translation); |
| 7966 | |
| 7967 | // No layers have scale-affecting animations. |
| 7968 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 7969 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 7970 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 7971 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 7972 | |
| 7973 | TransformOperations scale; |
| 7974 | scale.AppendScale(5.f, 4.f, 3.f); |
| 7975 | |
| 7976 | AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); |
| 7977 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7978 | |
| 7979 | // Only |child| has a scale-affecting animation. |
| 7980 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 7981 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 7982 | EXPECT_EQ(5.f, child_raw->last_maximum_animation_contents_scale()); |
| 7983 | EXPECT_EQ(5.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 7984 | |
| 7985 | AddAnimatedTransformToLayer( |
| 7986 | grand_parent.get(), 1.0, TransformOperations(), scale); |
| 7987 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7988 | |
| 7989 | // |grand_parent| and |child| have scale-affecting animations. |
| 7990 | EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale()); |
| 7991 | EXPECT_EQ(5.f, parent_raw->last_maximum_animation_contents_scale()); |
| 7992 | // We don't support combining animated scales from two nodes; 0.f means |
| 7993 | // that the maximum scale could not be computed. |
| 7994 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 7995 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 7996 | |
| 7997 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 7998 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7999 | |
| 8000 | // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
| 8001 | EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale()); |
| 8002 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 8003 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 8004 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 8005 | |
| 8006 | grand_parent->layer_animation_controller()->AbortAnimations( |
| 8007 | Animation::Transform); |
| 8008 | parent_raw->layer_animation_controller()->AbortAnimations( |
| 8009 | Animation::Transform); |
| 8010 | child_raw->layer_animation_controller()->AbortAnimations( |
| 8011 | Animation::Transform); |
| 8012 | |
| 8013 | TransformOperations perspective; |
| 8014 | perspective.AppendPerspective(10.f); |
| 8015 | |
| 8016 | AddAnimatedTransformToLayer( |
| 8017 | child_raw, 1.0, TransformOperations(), perspective); |
| 8018 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8019 | |
| 8020 | // |child| has a scale-affecting animation but computing the maximum of this |
| 8021 | // animation is not supported. |
| 8022 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 8023 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 8024 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 8025 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 8026 | |
| 8027 | child_raw->layer_animation_controller()->AbortAnimations( |
| 8028 | Animation::Transform); |
| 8029 | |
| 8030 | gfx::Transform scale_matrix; |
| 8031 | scale_matrix.Scale(1.f, 2.f); |
| 8032 | grand_parent->SetTransform(scale_matrix); |
| 8033 | parent_raw->SetTransform(scale_matrix); |
| 8034 | AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 8035 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8036 | |
| 8037 | // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 8038 | // animation with maximum scale 5.f. |
| 8039 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 8040 | EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale()); |
| 8041 | EXPECT_EQ(10.f, child_raw->last_maximum_animation_contents_scale()); |
| 8042 | EXPECT_EQ(10.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 8043 | |
| 8044 | gfx::Transform perspective_matrix; |
| 8045 | perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 8046 | child_raw->SetTransform(perspective_matrix); |
| 8047 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8048 | |
| 8049 | // |child| has a transform that's neither a translation nor a scale. |
| 8050 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 8051 | EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale()); |
| 8052 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 8053 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 8054 | |
| 8055 | parent_raw->SetTransform(perspective_matrix); |
| 8056 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8057 | |
| 8058 | // |parent| and |child| have transforms that are neither translations nor |
| 8059 | // scales. |
| 8060 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 8061 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 8062 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 8063 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 8064 | |
| 8065 | parent_raw->SetTransform(identity_matrix); |
| 8066 | child_raw->SetTransform(identity_matrix); |
| 8067 | grand_parent->SetTransform(perspective_matrix); |
| 8068 | |
| 8069 | ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8070 | |
| 8071 | // |grand_parent| has a transform that's neither a translation nor a scale. |
| 8072 | EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 8073 | EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 8074 | EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 8075 | EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 8076 | } |
| 8077 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8078 | static int membership_id(LayerImpl* layer) { |
| 8079 | return layer->draw_properties().last_drawn_render_surface_layer_list_id; |
| 8080 | } |
| 8081 | |
| 8082 | static void GatherDrawnLayers(LayerImplList* rsll, |
| 8083 | std::set<LayerImpl*>* drawn_layers) { |
| 8084 | for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll), |
| 8085 | end = LayerIterator<LayerImpl>::End(rsll); |
| 8086 | it != end; |
| 8087 | ++it) { |
| 8088 | LayerImpl* layer = *it; |
| 8089 | if (it.represents_itself()) |
| 8090 | drawn_layers->insert(layer); |
| 8091 | |
| 8092 | if (!it.represents_contributing_render_surface()) |
| 8093 | continue; |
| 8094 | |
| 8095 | if (layer->mask_layer()) |
| 8096 | drawn_layers->insert(layer->mask_layer()); |
| 8097 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 8098 | drawn_layers->insert(layer->replica_layer()->mask_layer()); |
| 8099 | } |
| 8100 | } |
| 8101 | |
| 8102 | TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { |
| 8103 | FakeImplProxy proxy; |
| 8104 | TestSharedBitmapManager shared_bitmap_manager; |
| 8105 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 8106 | gfx::Transform identity_matrix; |
| 8107 | |
| 8108 | scoped_ptr<LayerImpl> grand_parent = |
| 8109 | LayerImpl::Create(host_impl.active_tree(), 1); |
| 8110 | scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3); |
| 8111 | scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5); |
| 8112 | scoped_ptr<LayerImpl> grand_child1 = |
| 8113 | LayerImpl::Create(host_impl.active_tree(), 7); |
| 8114 | scoped_ptr<LayerImpl> grand_child2 = |
| 8115 | LayerImpl::Create(host_impl.active_tree(), 9); |
| 8116 | |
| 8117 | LayerImpl* grand_parent_raw = grand_parent.get(); |
| 8118 | LayerImpl* parent_raw = parent.get(); |
| 8119 | LayerImpl* child_raw = child.get(); |
| 8120 | LayerImpl* grand_child1_raw = grand_child1.get(); |
| 8121 | LayerImpl* grand_child2_raw = grand_child2.get(); |
| 8122 | |
| 8123 | child->AddChild(grand_child1.Pass()); |
| 8124 | child->AddChild(grand_child2.Pass()); |
| 8125 | parent->AddChild(child.Pass()); |
| 8126 | grand_parent->AddChild(parent.Pass()); |
| 8127 | |
| 8128 | SetLayerPropertiesForTesting(grand_parent_raw, |
| 8129 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 8130 | gfx::Point3F(), |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8131 | gfx::PointF(), |
| 8132 | gfx::Size(1, 2), |
| 8133 | true, |
| 8134 | false); |
| 8135 | SetLayerPropertiesForTesting(parent_raw, |
| 8136 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 8137 | gfx::Point3F(), |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8138 | gfx::PointF(), |
| 8139 | gfx::Size(1, 2), |
| 8140 | true, |
| 8141 | false); |
| 8142 | SetLayerPropertiesForTesting(child_raw, |
| 8143 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 8144 | gfx::Point3F(), |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8145 | gfx::PointF(), |
| 8146 | gfx::Size(1, 2), |
| 8147 | true, |
| 8148 | false); |
| 8149 | SetLayerPropertiesForTesting(grand_child1_raw, |
| 8150 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 8151 | gfx::Point3F(), |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8152 | gfx::PointF(), |
| 8153 | gfx::Size(1, 2), |
| 8154 | true, |
| 8155 | false); |
| 8156 | SetLayerPropertiesForTesting(grand_child2_raw, |
| 8157 | identity_matrix, |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 8158 | gfx::Point3F(), |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 8159 | gfx::PointF(), |
| 8160 | gfx::Size(1, 2), |
| 8161 | true, |
| 8162 | false); |
| 8163 | |
| 8164 | // Start with nothing being drawn. |
| 8165 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8166 | int member_id = render_surface_layer_list_count(); |
| 8167 | |
| 8168 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8169 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8170 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8171 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8172 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8173 | |
| 8174 | std::set<LayerImpl*> expected; |
| 8175 | std::set<LayerImpl*> actual; |
| 8176 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8177 | EXPECT_EQ(expected, actual); |
| 8178 | |
| 8179 | // If we force render surface, but none of the layers are in the layer list, |
| 8180 | // then this layer should not appear in RSLL. |
| 8181 | grand_child1_raw->SetForceRenderSurface(true); |
| 8182 | |
| 8183 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8184 | member_id = render_surface_layer_list_count(); |
| 8185 | |
| 8186 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8187 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8188 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8189 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8190 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8191 | |
| 8192 | expected.clear(); |
| 8193 | actual.clear(); |
| 8194 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8195 | EXPECT_EQ(expected, actual); |
| 8196 | |
| 8197 | // However, if we say that this layer also draws content, it will appear in |
| 8198 | // RSLL. |
| 8199 | grand_child1_raw->SetDrawsContent(true); |
| 8200 | |
| 8201 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8202 | member_id = render_surface_layer_list_count(); |
| 8203 | |
| 8204 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8205 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8206 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8207 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 8208 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8209 | |
| 8210 | expected.clear(); |
| 8211 | expected.insert(grand_child1_raw); |
| 8212 | |
| 8213 | actual.clear(); |
| 8214 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8215 | EXPECT_EQ(expected, actual); |
| 8216 | |
| 8217 | // Now child is forced to have a render surface, and one if its children draws |
| 8218 | // content. |
| 8219 | grand_child1_raw->SetDrawsContent(false); |
| 8220 | grand_child1_raw->SetForceRenderSurface(false); |
| 8221 | child_raw->SetForceRenderSurface(true); |
| 8222 | grand_child2_raw->SetDrawsContent(true); |
| 8223 | |
| 8224 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8225 | member_id = render_surface_layer_list_count(); |
| 8226 | |
| 8227 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8228 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8229 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8230 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8231 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8232 | |
| 8233 | expected.clear(); |
| 8234 | expected.insert(grand_child2_raw); |
| 8235 | |
| 8236 | actual.clear(); |
| 8237 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8238 | EXPECT_EQ(expected, actual); |
| 8239 | |
| 8240 | // Add a mask layer to child. |
| 8241 | child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass()); |
| 8242 | |
| 8243 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8244 | member_id = render_surface_layer_list_count(); |
| 8245 | |
| 8246 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8247 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8248 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8249 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8250 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8251 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8252 | |
| 8253 | expected.clear(); |
| 8254 | expected.insert(grand_child2_raw); |
| 8255 | expected.insert(child_raw->mask_layer()); |
| 8256 | |
| 8257 | expected.clear(); |
| 8258 | expected.insert(grand_child2_raw); |
| 8259 | expected.insert(child_raw->mask_layer()); |
| 8260 | |
| 8261 | actual.clear(); |
| 8262 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8263 | EXPECT_EQ(expected, actual); |
| 8264 | |
| 8265 | // Add replica mask layer. |
| 8266 | scoped_ptr<LayerImpl> replica_layer = |
| 8267 | LayerImpl::Create(host_impl.active_tree(), 20); |
| 8268 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21)); |
| 8269 | child_raw->SetReplicaLayer(replica_layer.Pass()); |
| 8270 | |
| 8271 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8272 | member_id = render_surface_layer_list_count(); |
| 8273 | |
| 8274 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8275 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8276 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8277 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8278 | EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer())); |
| 8279 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8280 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8281 | |
| 8282 | expected.clear(); |
| 8283 | expected.insert(grand_child2_raw); |
| 8284 | expected.insert(child_raw->mask_layer()); |
| 8285 | expected.insert(child_raw->replica_layer()->mask_layer()); |
| 8286 | |
| 8287 | actual.clear(); |
| 8288 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8289 | EXPECT_EQ(expected, actual); |
| 8290 | |
| 8291 | child_raw->TakeReplicaLayer(); |
| 8292 | |
| 8293 | // With nothing drawing, we should have no layers. |
| 8294 | grand_child2_raw->SetDrawsContent(false); |
| 8295 | |
| 8296 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8297 | member_id = render_surface_layer_list_count(); |
| 8298 | |
| 8299 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8300 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8301 | EXPECT_NE(member_id, membership_id(child_raw)); |
| 8302 | EXPECT_NE(member_id, membership_id(child_raw->mask_layer())); |
| 8303 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8304 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8305 | |
| 8306 | expected.clear(); |
| 8307 | actual.clear(); |
| 8308 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8309 | EXPECT_EQ(expected, actual); |
| 8310 | |
| 8311 | // Child itself draws means that we should have the child and the mask in the |
| 8312 | // list. |
| 8313 | child_raw->SetDrawsContent(true); |
| 8314 | |
| 8315 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8316 | member_id = render_surface_layer_list_count(); |
| 8317 | |
| 8318 | EXPECT_NE(member_id, membership_id(grand_parent_raw)); |
| 8319 | EXPECT_NE(member_id, membership_id(parent_raw)); |
| 8320 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 8321 | EXPECT_EQ(member_id, membership_id(child_raw->mask_layer())); |
| 8322 | EXPECT_NE(member_id, membership_id(grand_child1_raw)); |
| 8323 | EXPECT_NE(member_id, membership_id(grand_child2_raw)); |
| 8324 | |
| 8325 | expected.clear(); |
| 8326 | expected.insert(child_raw); |
| 8327 | expected.insert(child_raw->mask_layer()); |
| 8328 | actual.clear(); |
| 8329 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8330 | EXPECT_EQ(expected, actual); |
| 8331 | |
| 8332 | child_raw->TakeMaskLayer(); |
| 8333 | |
| 8334 | // Now everyone's a member! |
| 8335 | grand_parent_raw->SetDrawsContent(true); |
| 8336 | parent_raw->SetDrawsContent(true); |
| 8337 | child_raw->SetDrawsContent(true); |
| 8338 | grand_child1_raw->SetDrawsContent(true); |
| 8339 | grand_child2_raw->SetDrawsContent(true); |
| 8340 | |
| 8341 | ExecuteCalculateDrawProperties(grand_parent_raw); |
| 8342 | member_id = render_surface_layer_list_count(); |
| 8343 | |
| 8344 | EXPECT_EQ(member_id, membership_id(grand_parent_raw)); |
| 8345 | EXPECT_EQ(member_id, membership_id(parent_raw)); |
| 8346 | EXPECT_EQ(member_id, membership_id(child_raw)); |
| 8347 | EXPECT_EQ(member_id, membership_id(grand_child1_raw)); |
| 8348 | EXPECT_EQ(member_id, membership_id(grand_child2_raw)); |
| 8349 | |
| 8350 | expected.clear(); |
| 8351 | expected.insert(grand_parent_raw); |
| 8352 | expected.insert(parent_raw); |
| 8353 | expected.insert(child_raw); |
| 8354 | expected.insert(grand_child1_raw); |
| 8355 | expected.insert(grand_child2_raw); |
| 8356 | |
| 8357 | actual.clear(); |
| 8358 | GatherDrawnLayers(render_surface_layer_list_impl(), &actual); |
| 8359 | EXPECT_EQ(expected, actual); |
| 8360 | } |
[email protected] | 18e6965 | 2014-06-13 12:50:58 | [diff] [blame^] | 8361 | |
| 8362 | TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { |
| 8363 | FakeImplProxy proxy; |
| 8364 | TestSharedBitmapManager shared_bitmap_manager; |
| 8365 | FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 8366 | |
| 8367 | scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); |
| 8368 | LayerImpl* root_layer = root.get(); |
| 8369 | scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2); |
| 8370 | LayerImpl* child1_layer = child1.get(); |
| 8371 | scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3); |
| 8372 | LayerImpl* child2_layer = child2.get(); |
| 8373 | |
| 8374 | root->AddChild(child1.Pass()); |
| 8375 | root->AddChild(child2.Pass()); |
| 8376 | |
| 8377 | gfx::Transform identity_matrix, scale_transform_child1, |
| 8378 | scale_transform_child2; |
| 8379 | scale_transform_child1.Scale(2, 3); |
| 8380 | scale_transform_child2.Scale(4, 5); |
| 8381 | |
| 8382 | SetLayerPropertiesForTesting(root_layer, |
| 8383 | identity_matrix, |
| 8384 | gfx::Point3F(), |
| 8385 | gfx::PointF(), |
| 8386 | gfx::Size(1, 1), |
| 8387 | true, |
| 8388 | false); |
| 8389 | SetLayerPropertiesForTesting(child1_layer, |
| 8390 | scale_transform_child1, |
| 8391 | gfx::Point3F(), |
| 8392 | gfx::PointF(), |
| 8393 | gfx::Size(), |
| 8394 | true, |
| 8395 | false); |
| 8396 | |
| 8397 | child1_layer->SetMaskLayer( |
| 8398 | LayerImpl::Create(host_impl.active_tree(), 4).Pass()); |
| 8399 | |
| 8400 | scoped_ptr<LayerImpl> replica_layer = |
| 8401 | LayerImpl::Create(host_impl.active_tree(), 5); |
| 8402 | replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6)); |
| 8403 | child1_layer->SetReplicaLayer(replica_layer.Pass()); |
| 8404 | |
| 8405 | ExecuteCalculateDrawProperties(root_layer); |
| 8406 | |
| 8407 | TransformOperations scale; |
| 8408 | scale.AppendScale(5.f, 8.f, 3.f); |
| 8409 | |
| 8410 | AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale); |
| 8411 | SetLayerPropertiesForTesting(child2_layer, |
| 8412 | scale_transform_child2, |
| 8413 | gfx::Point3F(), |
| 8414 | gfx::PointF(), |
| 8415 | gfx::Size(), |
| 8416 | true, |
| 8417 | false); |
| 8418 | |
| 8419 | ExecuteCalculateDrawProperties(root_layer); |
| 8420 | |
| 8421 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); |
| 8422 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8423 | EXPECT_FLOAT_EQ( |
| 8424 | 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8425 | EXPECT_FLOAT_EQ(3.f, |
| 8426 | child1_layer->replica_layer() |
| 8427 | ->mask_layer() |
| 8428 | ->draw_properties() |
| 8429 | .ideal_contents_scale); |
| 8430 | EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8431 | |
| 8432 | EXPECT_FLOAT_EQ( |
| 8433 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8434 | EXPECT_FLOAT_EQ( |
| 8435 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8436 | EXPECT_FLOAT_EQ(0.f, |
| 8437 | child1_layer->mask_layer() |
| 8438 | ->draw_properties() |
| 8439 | .maximum_animation_contents_scale); |
| 8440 | EXPECT_FLOAT_EQ(0.f, |
| 8441 | child1_layer->replica_layer() |
| 8442 | ->mask_layer() |
| 8443 | ->draw_properties() |
| 8444 | .maximum_animation_contents_scale); |
| 8445 | EXPECT_FLOAT_EQ( |
| 8446 | 8.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8447 | |
| 8448 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8449 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor); |
| 8450 | EXPECT_FLOAT_EQ( |
| 8451 | 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8452 | EXPECT_FLOAT_EQ(1.f, |
| 8453 | child1_layer->replica_layer() |
| 8454 | ->mask_layer() |
| 8455 | ->draw_properties() |
| 8456 | .page_scale_factor); |
| 8457 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor); |
| 8458 | |
| 8459 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); |
| 8460 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); |
| 8461 | EXPECT_FLOAT_EQ( |
| 8462 | 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8463 | EXPECT_FLOAT_EQ(1.f, |
| 8464 | child1_layer->replica_layer() |
| 8465 | ->mask_layer() |
| 8466 | ->draw_properties() |
| 8467 | .device_scale_factor); |
| 8468 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); |
| 8469 | |
| 8470 | // Changing page-scale would affect ideal_contents_scale and |
| 8471 | // maximum_animation_contents_scale. |
| 8472 | |
| 8473 | float page_scale_factor = 3.f; |
| 8474 | float device_scale_factor = 1.0f; |
| 8475 | std::vector<LayerImpl*> render_surface_layer_list; |
| 8476 | gfx::Size device_viewport_size = |
| 8477 | gfx::Size(root_layer->bounds().width() * device_scale_factor, |
| 8478 | root_layer->bounds().height() * device_scale_factor); |
| 8479 | LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 8480 | root_layer, device_viewport_size, &render_surface_layer_list); |
| 8481 | |
| 8482 | inputs.page_scale_factor = page_scale_factor; |
| 8483 | inputs.can_adjust_raster_scales = true; |
| 8484 | inputs.page_scale_application_layer = root_layer; |
| 8485 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8486 | |
| 8487 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale); |
| 8488 | EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8489 | EXPECT_FLOAT_EQ( |
| 8490 | 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8491 | EXPECT_FLOAT_EQ(9.f, |
| 8492 | child1_layer->replica_layer() |
| 8493 | ->mask_layer() |
| 8494 | ->draw_properties() |
| 8495 | .ideal_contents_scale); |
| 8496 | EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8497 | |
| 8498 | EXPECT_FLOAT_EQ( |
| 8499 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8500 | EXPECT_FLOAT_EQ( |
| 8501 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8502 | EXPECT_FLOAT_EQ(0.f, |
| 8503 | child1_layer->mask_layer() |
| 8504 | ->draw_properties() |
| 8505 | .maximum_animation_contents_scale); |
| 8506 | EXPECT_FLOAT_EQ(0.f, |
| 8507 | child1_layer->replica_layer() |
| 8508 | ->mask_layer() |
| 8509 | ->draw_properties() |
| 8510 | .maximum_animation_contents_scale); |
| 8511 | EXPECT_FLOAT_EQ( |
| 8512 | 24.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8513 | |
| 8514 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8515 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); |
| 8516 | EXPECT_FLOAT_EQ( |
| 8517 | 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8518 | EXPECT_FLOAT_EQ(3.f, |
| 8519 | child1_layer->replica_layer() |
| 8520 | ->mask_layer() |
| 8521 | ->draw_properties() |
| 8522 | .page_scale_factor); |
| 8523 | EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); |
| 8524 | |
| 8525 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor); |
| 8526 | EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor); |
| 8527 | EXPECT_FLOAT_EQ( |
| 8528 | 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8529 | EXPECT_FLOAT_EQ(1.f, |
| 8530 | child1_layer->replica_layer() |
| 8531 | ->mask_layer() |
| 8532 | ->draw_properties() |
| 8533 | .device_scale_factor); |
| 8534 | EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor); |
| 8535 | |
| 8536 | // Changing device-scale would affect ideal_contents_scale and |
| 8537 | // maximum_animation_contents_scale. |
| 8538 | |
| 8539 | device_scale_factor = 4.0f; |
| 8540 | inputs.device_scale_factor = device_scale_factor; |
| 8541 | inputs.can_adjust_raster_scales = true; |
| 8542 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 8543 | |
| 8544 | EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale); |
| 8545 | EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale); |
| 8546 | EXPECT_FLOAT_EQ( |
| 8547 | 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale); |
| 8548 | EXPECT_FLOAT_EQ(36.f, |
| 8549 | child1_layer->replica_layer() |
| 8550 | ->mask_layer() |
| 8551 | ->draw_properties() |
| 8552 | .ideal_contents_scale); |
| 8553 | EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale); |
| 8554 | |
| 8555 | EXPECT_FLOAT_EQ( |
| 8556 | 0.f, root_layer->draw_properties().maximum_animation_contents_scale); |
| 8557 | EXPECT_FLOAT_EQ( |
| 8558 | 0.f, child1_layer->draw_properties().maximum_animation_contents_scale); |
| 8559 | EXPECT_FLOAT_EQ(0.f, |
| 8560 | child1_layer->mask_layer() |
| 8561 | ->draw_properties() |
| 8562 | .maximum_animation_contents_scale); |
| 8563 | EXPECT_FLOAT_EQ(0.f, |
| 8564 | child1_layer->replica_layer() |
| 8565 | ->mask_layer() |
| 8566 | ->draw_properties() |
| 8567 | .maximum_animation_contents_scale); |
| 8568 | EXPECT_FLOAT_EQ( |
| 8569 | 96.f, child2_layer->draw_properties().maximum_animation_contents_scale); |
| 8570 | |
| 8571 | EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor); |
| 8572 | EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor); |
| 8573 | EXPECT_FLOAT_EQ( |
| 8574 | 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor); |
| 8575 | EXPECT_FLOAT_EQ(3.f, |
| 8576 | child1_layer->replica_layer() |
| 8577 | ->mask_layer() |
| 8578 | ->draw_properties() |
| 8579 | .page_scale_factor); |
| 8580 | EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor); |
| 8581 | |
| 8582 | EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor); |
| 8583 | EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor); |
| 8584 | EXPECT_FLOAT_EQ( |
| 8585 | 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor); |
| 8586 | EXPECT_FLOAT_EQ(4.f, |
| 8587 | child1_layer->replica_layer() |
| 8588 | ->mask_layer() |
| 8589 | ->draw_properties() |
| 8590 | .device_scale_factor); |
| 8591 | EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor); |
| 8592 | } |
| 8593 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 8594 | } // namespace |
| 8595 | } // namespace cc |