blob: 42130e0ff5f8df414d459b89dd2cfa8c630f8b07 [file] [log] [blame]
ajumae2b7a5c2015-09-30 21:41:421// Copyright 2011 The Chromium Authors. All rights reserved.
[email protected]94f206c12012-08-25 00:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/layer_tree_host_common.h"
[email protected]94f206c12012-08-25 00:09:146
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
danakj6496cba2014-10-16 01:31:089#include <algorithm>
[email protected]995708c52013-10-17 20:52:5910#include <set>
vmpstra370ef52015-11-18 10:41:2811#include <vector>
[email protected]995708c52013-10-17 20:52:5912
loyso968163c92016-01-04 23:18:4813#include "cc/animation/animation_host.h"
14#include "cc/animation/animation_id_provider.h"
ajuma315a4782015-07-24 21:16:3415#include "cc/animation/keyframed_animation_curve.h"
[email protected]95e4e1a02013-03-18 07:09:0916#include "cc/animation/layer_animation_controller.h"
[email protected]1c3626e2014-04-09 17:49:2217#include "cc/animation/transform_operations.h"
[email protected]681ccff2013-03-18 06:13:5218#include "cc/base/math_util.h"
sunxd29f17bf422016-02-03 02:47:4819#include "cc/input/main_thread_scrolling_reason.h"
[email protected]cc3cfaa2013-03-18 09:05:5220#include "cc/layers/content_layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5221#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5922#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5223#include "cc/layers/layer_impl.h"
[email protected]390bb1ff2014-05-09 17:14:4024#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2825#include "cc/layers/render_surface_impl.h"
[email protected]30fe19ff2013-07-04 00:54:4526#include "cc/output/copy_output_request.h"
27#include "cc/output/copy_output_result.h"
khushalsagar37694212016-01-15 20:46:4828#include "cc/proto/begin_main_frame_and_commit_state.pb.h"
29#include "cc/proto/gfx_conversions.h"
[email protected]101441ce2012-10-16 01:45:0330#include "cc/test/animation_test_common.h"
vollick2175fae82015-04-27 21:18:1231#include "cc/test/fake_content_layer_client.h"
khushalsagarb64b360d2015-10-21 19:25:1632#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]d600df7d2013-08-03 02:34:2833#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4534#include "cc/test/fake_layer_tree_host_impl.h"
ajumaae0dc2d2015-08-05 21:55:5635#include "cc/test/fake_output_surface.h"
sohan.jyotie3bd6192014-10-13 07:13:5936#include "cc/test/fake_picture_layer.h"
37#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0338#include "cc/test/geometry_test_utils.h"
[email protected]28336d52014-05-12 19:07:2839#include "cc/test/layer_tree_host_common_test.h"
reveman34b7a1522015-03-23 20:27:4740#include "cc/test/test_task_graph_runner.h"
ennef6903532015-08-18 05:10:1541#include "cc/trees/draw_property_utils.h"
[email protected]556fd292013-03-18 08:03:0442#include "cc/trees/layer_tree_impl.h"
[email protected]556fd292013-03-18 08:03:0443#include "cc/trees/single_thread_proxy.h"
khushalsagarb64b360d2015-10-21 19:25:1644#include "cc/trees/task_runner_provider.h"
[email protected]7f0c53db2012-10-02 00:23:1845#include "testing/gmock/include/gmock/gmock.h"
46#include "testing/gtest/include/gtest/gtest.h"
heejin.r.chungd28506ba2014-10-23 16:36:2047#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3748#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0049#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1450
[email protected]ba565742012-11-10 09:29:4851namespace cc {
[email protected]94f206c12012-08-25 00:09:1452namespace {
53
[email protected]96baf3e2012-10-22 23:09:5554class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:3255 public:
loysoa6edaaff2015-05-25 03:26:4456 explicit LayerWithForcedDrawsContent(const LayerSettings& settings)
57 : Layer(settings) {}
[email protected]94f206c12012-08-25 00:09:1458
dcheng716bedf2014-10-21 09:51:0859 bool DrawsContent() const override;
[email protected]d58499a2012-10-09 22:27:4760
[email protected]fb661802013-03-25 01:59:3261 private:
dcheng716bedf2014-10-21 09:51:0862 ~LayerWithForcedDrawsContent() override {}
[email protected]94f206c12012-08-25 00:09:1463};
64
[email protected]fb661802013-03-25 01:59:3265bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:4466
[email protected]96baf3e2012-10-22 23:09:5567class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:3268 public:
69 MockContentLayerClient() {}
dcheng716bedf2014-10-21 09:51:0870 ~MockContentLayerClient() override {}
chrishtr01539b802015-11-24 08:11:3271 gfx::Rect PaintableRegion() override { return gfx::Rect(); }
jbroman16d628c2015-05-29 20:11:5972 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
schenney0154bfa2015-02-05 19:46:4973 PaintingControlSetting picture_control) override {
ajuma5e77f7d42014-11-27 14:19:1474 NOTIMPLEMENTED();
jbroman16d628c2015-05-29 20:11:5975 return nullptr;
ajuma5e77f7d42014-11-27 14:19:1476 }
dcheng716bedf2014-10-21 09:51:0877 bool FillsBoundsCompletely() const override { return false; }
jbroman9f60f1a2015-07-16 21:40:3278 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
[email protected]f34a24232012-09-20 22:59:5579};
80
[email protected]989386c2013-07-18 21:37:2381#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
82 do { \
83 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
84 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:4785 } while (false)
86
enne637715732015-07-07 02:05:2687#define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
88 do { \
89 EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \
sohan.jyotie3bd6192014-10-13 07:13:5990 } while (false)
91
enne637715732015-07-07 02:05:2692class LayerTreeSettingsScaleContent : public LayerTreeSettings {
93 public:
94 LayerTreeSettingsScaleContent() {
95 layer_transforms_should_scale_layer_contents = true;
loyso8ce123b62016-01-06 23:10:3196 use_compositor_animation_timelines = true;
enne637715732015-07-07 02:05:2697 }
98};
99
100class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTest {
101 public:
102 LayerTreeHostCommonScalingTest()
103 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
104};
105
[email protected]989386c2013-07-18 21:37:23106TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32107 // Sanity check: For layers positioned at zero, with zero size,
108 // and with identity transforms, then the draw transform,
109 // screen space transform, and the hierarchy passed on to children
110 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14111
loysoa6edaaff2015-05-25 03:26:44112 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
113 scoped_refptr<Layer> child = Layer::Create(layer_settings());
114 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:32115 parent->AddChild(child);
116 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14117
ennea7b43c32015-06-18 20:01:33118 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:28119
[email protected]fb661802013-03-25 01:59:32120 gfx::Transform identity_matrix;
121 SetLayerPropertiesForTesting(parent.get(),
122 identity_matrix,
[email protected]a2566412014-06-05 03:14:20123 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32124 gfx::PointF(),
125 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:57126 true,
[email protected]fb661802013-03-25 01:59:32127 false);
128 SetLayerPropertiesForTesting(child.get(),
129 identity_matrix,
[email protected]a2566412014-06-05 03:14:20130 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32131 gfx::PointF(),
132 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57133 true,
[email protected]fb661802013-03-25 01:59:32134 false);
135 SetLayerPropertiesForTesting(grand_child.get(),
136 identity_matrix,
[email protected]a2566412014-06-05 03:14:20137 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32138 gfx::PointF(),
139 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57140 true,
[email protected]fb661802013-03-25 01:59:32141 false);
[email protected]94f206c12012-08-25 00:09:14142
[email protected]fb661802013-03-25 01:59:32143 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14144
[email protected]fb661802013-03-25 01:59:32145 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
146 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
147 child->screen_space_transform());
148 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
149 grand_child->draw_transform());
150 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
151 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14152}
153
jaydasika86654512016-01-27 17:05:07154TEST_F(LayerTreeHostCommonTest,
155 ScreenSpaceTransformOfSkippedLayersWithHandlers) {
156 // Even for layers that are skipped, we need to compute the correct screen
157 // space transform because it is used during hit testing.
enne367152322015-08-18 18:06:09158 LayerImpl* parent = root_layer();
159 LayerImpl* child = AddChild<LayerImpl>(parent);
160 LayerImpl* grand_child = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:36161 child->SetDrawsContent(true);
162 grand_child->SetDrawsContent(true);
[email protected]f9e56702014-06-13 01:19:59163
164 gfx::Transform identity_matrix;
enne367152322015-08-18 18:06:09165 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:26166 gfx::PointF(), gfx::Size(100, 100), true, false);
enne367152322015-08-18 18:06:09167 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
168 gfx::PointF(10, 10), gfx::Size(100, 100), true,
weiliangcc154ce22015-12-09 03:39:26169 false);
jaydasika86654512016-01-27 17:05:07170 // This will cause the subtree to be skipped.
[email protected]f9e56702014-06-13 01:19:59171 child->SetOpacity(0.f);
enne367152322015-08-18 18:06:09172 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
173 gfx::PointF(10, 10), gfx::Size(100, 100), true,
weiliangcc154ce22015-12-09 03:39:26174 false);
[email protected]f9e56702014-06-13 01:19:59175 grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
176
enne367152322015-08-18 18:06:09177 ExecuteCalculateDrawProperties(parent);
[email protected]f9e56702014-06-13 01:19:59178
weiliangcc154ce22015-12-09 03:39:26179 EXPECT_TRUE(child->has_render_surface());
180 EXPECT_FALSE(grand_child->has_render_surface());
[email protected]f9e56702014-06-13 01:19:59181 // Check that we've computed draw properties for the subtree rooted at
182 // |child|.
jaydasika86654512016-01-27 17:05:07183 EXPECT_FALSE(child->render_surface()->screen_space_transform().IsIdentity());
184 EXPECT_FALSE(grand_child->ScreenSpaceTransform().IsIdentity());
[email protected]f9e56702014-06-13 01:19:59185}
186
jaydasika322436372015-12-16 23:42:38187TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) {
188 // Tests that effect tree node gets a valid transform id when a layer
189 // has opacity but doesn't create a render surface.
190 LayerImpl* parent = root_layer();
191 LayerImpl* child = AddChild<LayerImpl>(parent);
192 child->SetDrawsContent(true);
193
194 gfx::Transform identity_matrix;
195 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
196 gfx::PointF(), gfx::Size(100, 100), true, false);
197 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
198 gfx::PointF(10, 10), gfx::Size(100, 100), true,
199 false);
200 child->SetOpacity(0.f);
201 ExecuteCalculateDrawProperties(parent);
202 EffectTree effect_tree =
203 parent->layer_tree_impl()->property_trees()->effect_tree;
204 EffectNode* node = effect_tree.Node(child->effect_tree_index());
205 const int transform_tree_size = parent->layer_tree_impl()
206 ->property_trees()
207 ->transform_tree.next_available_id();
208 EXPECT_LT(node->data.transform_id, transform_tree_size);
209}
210
[email protected]989386c2013-07-18 21:37:23211TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32212 gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:44213 scoped_refptr<Layer> layer = Layer::Create(layer_settings());
[email protected]94f206c12012-08-25 00:09:14214
loysoa6edaaff2015-05-25 03:26:44215 scoped_refptr<Layer> root = Layer::Create(layer_settings());
enne826452722015-08-18 22:22:31216 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
217 gfx::PointF(), gfx::Size(1, 2), true, false);
[email protected]fb661802013-03-25 01:59:32218 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42219
ennea7b43c32015-06-18 20:01:33220 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:28221
enne826452722015-08-18 22:22:31222 TransformTree& tree = host()->property_trees()->transform_tree;
223
[email protected]fb661802013-03-25 01:59:32224 // Case 2: Setting the bounds of the layer should not affect either the draw
225 // transform or the screenspace transform.
226 gfx::Transform translation_to_center;
227 translation_to_center.Translate(5.0, 6.0);
enne826452722015-08-18 22:22:31228 SetLayerPropertiesForTesting(layer.get(), identity_matrix, gfx::Point3F(),
229 gfx::PointF(), gfx::Size(10, 12), true, false);
[email protected]fb661802013-03-25 01:59:32230 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31231 EXPECT_TRANSFORMATION_MATRIX_EQ(
232 identity_matrix, DrawTransformFromPropertyTrees(layer.get(), tree));
233 EXPECT_TRANSFORMATION_MATRIX_EQ(
234 identity_matrix,
235 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
[email protected]94f206c12012-08-25 00:09:14236
[email protected]fb661802013-03-25 01:59:32237 // Case 3: The anchor point by itself (without a layer transform) should have
238 // no effect on the transforms.
enne826452722015-08-18 22:22:31239 SetLayerPropertiesForTesting(layer.get(), identity_matrix,
240 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
241 gfx::Size(10, 12), true, false);
[email protected]fb661802013-03-25 01:59:32242 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31243 EXPECT_TRANSFORMATION_MATRIX_EQ(
244 identity_matrix, DrawTransformFromPropertyTrees(layer.get(), tree));
245 EXPECT_TRANSFORMATION_MATRIX_EQ(
246 identity_matrix,
247 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
[email protected]94f206c12012-08-25 00:09:14248
[email protected]fb661802013-03-25 01:59:32249 // Case 4: A change in actual position affects both the draw transform and
250 // screen space transform.
251 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05252 position_transform.Translate(0.f, 1.2f);
enne826452722015-08-18 22:22:31253 SetLayerPropertiesForTesting(
254 layer.get(), identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
255 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
[email protected]fb661802013-03-25 01:59:32256 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31257 EXPECT_TRANSFORMATION_MATRIX_EQ(
258 position_transform, DrawTransformFromPropertyTrees(layer.get(), tree));
259 EXPECT_TRANSFORMATION_MATRIX_EQ(
260 position_transform,
261 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
[email protected]94f206c12012-08-25 00:09:14262
[email protected]fb661802013-03-25 01:59:32263 // Case 5: In the correct sequence of transforms, the layer transform should
264 // pre-multiply the translation_to_center. This is easily tested by using a
265 // scale transform, because scale and translation are not commutative.
266 gfx::Transform layer_transform;
267 layer_transform.Scale3d(2.0, 2.0, 1.0);
enne826452722015-08-18 22:22:31268 SetLayerPropertiesForTesting(layer.get(), layer_transform, gfx::Point3F(),
269 gfx::PointF(), gfx::Size(10, 12), true, false);
[email protected]fb661802013-03-25 01:59:32270 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31271 EXPECT_TRANSFORMATION_MATRIX_EQ(
272 layer_transform, DrawTransformFromPropertyTrees(layer.get(), tree));
273 EXPECT_TRANSFORMATION_MATRIX_EQ(
274 layer_transform,
275 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
[email protected]94f206c12012-08-25 00:09:14276
[email protected]fb661802013-03-25 01:59:32277 // Case 6: The layer transform should occur with respect to the anchor point.
278 gfx::Transform translation_to_anchor;
279 translation_to_anchor.Translate(5.0, 0.0);
280 gfx::Transform expected_result =
281 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
enne826452722015-08-18 22:22:31282 SetLayerPropertiesForTesting(layer.get(), layer_transform,
283 gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(),
284 gfx::Size(10, 12), true, false);
[email protected]fb661802013-03-25 01:59:32285 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31286 EXPECT_TRANSFORMATION_MATRIX_EQ(
287 expected_result, DrawTransformFromPropertyTrees(layer.get(), tree));
288 EXPECT_TRANSFORMATION_MATRIX_EQ(
289 expected_result,
290 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
[email protected]94f206c12012-08-25 00:09:14291
[email protected]fb661802013-03-25 01:59:32292 // Case 7: Verify that position pre-multiplies the layer transform. The
293 // current implementation of CalculateDrawProperties does this implicitly, but
294 // it is still worth testing to detect accidental regressions.
295 expected_result = position_transform * translation_to_anchor *
296 layer_transform * Inverse(translation_to_anchor);
enne826452722015-08-18 22:22:31297 SetLayerPropertiesForTesting(
298 layer.get(), layer_transform, gfx::Point3F(5.0f, 0.f, 0.f),
299 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
[email protected]fb661802013-03-25 01:59:32300 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31301 EXPECT_TRANSFORMATION_MATRIX_EQ(
302 expected_result, DrawTransformFromPropertyTrees(layer.get(), tree));
303 EXPECT_TRANSFORMATION_MATRIX_EQ(
304 expected_result,
305 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
[email protected]94f206c12012-08-25 00:09:14306}
307
[email protected]989386c2013-07-18 21:37:23308TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13309 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32310 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01311 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32312 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
313 -kScrollOffset.y());
314 const float kPageScale = 0.888f;
315 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20316
khushalsagarb64b360d2015-10-21 19:25:16317 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:45318 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:56319 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:16320 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:56321 &task_graph_runner);
[email protected]657b24c2013-03-06 09:01:20322
[email protected]fb661802013-03-25 01:59:32323 gfx::Transform identity_matrix;
324 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
325 LayerImpl::Create(host_impl.active_tree(), 1));
326 LayerImpl* sublayer = sublayer_scoped_ptr.get();
jaydasika0d98ba92015-11-17 05:17:28327 sublayer->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:00328 SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(),
329 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:32330 false);
[email protected]657b24c2013-03-06 09:01:20331
[email protected]adeda572014-01-31 00:49:47332 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32333 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47334 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
awoloszyne83f28c2014-12-22 15:40:00335 SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(),
336 gfx::PointF(), gfx::Size(10, 20), true, false,
[email protected]fb661802013-03-25 01:59:32337 false);
[email protected]adeda572014-01-31 00:49:47338 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
339 LayerImpl::Create(host_impl.active_tree(), 4));
340 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
341
342 scroll_layer->SetScrollClipLayer(clip_layer->id());
343 clip_layer->SetBounds(
344 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
345 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
346 scroll_layer->SetScrollClipLayer(clip_layer->id());
[email protected]fb661802013-03-25 01:59:32347 scroll_layer->SetScrollDelta(kScrollDelta);
348 gfx::Transform impl_transform;
danakja04855a2015-11-18 20:39:10349 scroll_layer->AddChild(std::move(sublayer_scoped_ptr));
[email protected]adeda572014-01-31 00:49:47350 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
danakja04855a2015-11-18 20:39:10351 clip_layer->AddChild(std::move(scroll_layer_scoped_ptr));
aeliasf998da82015-02-03 01:40:51352 scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20353
[email protected]fb661802013-03-25 01:59:32354 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
awoloszyne83f28c2014-12-22 15:40:00355 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
356 gfx::PointF(), gfx::Size(3, 4), true, false,
[email protected]fb661802013-03-25 01:59:32357 false);
danakja04855a2015-11-18 20:39:10358 root->AddChild(std::move(clip_layer_scoped_ptr));
awoloszyne83f28c2014-12-22 15:40:00359 root->SetHasRenderSurface(true);
[email protected]657b24c2013-03-06 09:01:20360
[email protected]f2136262013-04-26 21:10:19361 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32362 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32363 gfx::Transform expected_transform = identity_matrix;
364 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
danakj2c8d12c2015-06-18 06:15:33365 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
366 kPageScale * kDeviceScale),
367 MathUtil::Round(sub_layer_screen_position.y() *
368 kPageScale * kDeviceScale));
369 expected_transform.Scale(kPageScale * kDeviceScale,
370 kPageScale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32371 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44372 sublayer->DrawTransform());
[email protected]fb661802013-03-25 01:59:32373 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumab6aa1c62015-12-01 21:01:10374 sublayer->ScreenSpaceTransform());
[email protected]657b24c2013-03-06 09:01:20375
[email protected]fb661802013-03-25 01:59:32376 gfx::Transform arbitrary_translate;
377 const float kTranslateX = 10.6f;
378 const float kTranslateY = 20.6f;
379 arbitrary_translate.Translate(kTranslateX, kTranslateY);
awoloszyne83f28c2014-12-22 15:40:00380 SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate,
381 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
382 true, false, false);
jaydasika0d98ba92015-11-17 05:17:28383 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]f2136262013-04-26 21:10:19384 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32385 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32386 expected_transform.MakeIdentity();
387 expected_transform.Translate(
388 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
danakj2c8d12c2015-06-18 06:15:33389 sub_layer_screen_position.x() * kPageScale *
390 kDeviceScale),
[email protected]fb661802013-03-25 01:59:32391 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
danakj2c8d12c2015-06-18 06:15:33392 sub_layer_screen_position.y() * kPageScale *
393 kDeviceScale));
394 expected_transform.Scale(kPageScale * kDeviceScale,
395 kPageScale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32396 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44397 sublayer->DrawTransform());
[email protected]657b24c2013-03-06 09:01:20398}
399
[email protected]989386c2013-07-18 21:37:23400TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32401 gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:44402 scoped_refptr<Layer> root = Layer::Create(layer_settings());
403 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
404 scoped_refptr<Layer> child = Layer::Create(layer_settings());
405 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:32406 root->AddChild(parent);
407 parent->AddChild(child);
408 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14409
ennea7b43c32015-06-18 20:01:33410 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:28411
[email protected]fb661802013-03-25 01:59:32412 // One-time setup of root layer
enne826452722015-08-18 22:22:31413 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
414 gfx::PointF(), gfx::Size(1, 2), true, false);
415
416 TransformTree& tree = host()->property_trees()->transform_tree;
[email protected]ecc12622012-10-30 20:45:42417
[email protected]fb661802013-03-25 01:59:32418 // Case 1: parent's anchor point should not affect child or grand_child.
enne826452722015-08-18 22:22:31419 SetLayerPropertiesForTesting(parent.get(), identity_matrix,
420 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
421 gfx::Size(10, 12), true, false);
422 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
423 gfx::PointF(), gfx::Size(16, 18), true, false);
424 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
425 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
426 true, false);
[email protected]fb661802013-03-25 01:59:32427 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31428
429 EXPECT_TRANSFORMATION_MATRIX_EQ(
430 identity_matrix, DrawTransformFromPropertyTrees(child.get(), tree));
431 EXPECT_TRANSFORMATION_MATRIX_EQ(
432 identity_matrix,
433 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
434 EXPECT_TRANSFORMATION_MATRIX_EQ(
435 identity_matrix, DrawTransformFromPropertyTrees(grand_child.get(), tree));
436 EXPECT_TRANSFORMATION_MATRIX_EQ(
437 identity_matrix,
438 ScreenSpaceTransformFromPropertyTrees(grand_child.get(), tree));
[email protected]94f206c12012-08-25 00:09:14439
[email protected]fb661802013-03-25 01:59:32440 // Case 2: parent's position affects child and grand_child.
441 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05442 parent_position_transform.Translate(0.f, 1.2f);
enne826452722015-08-18 22:22:31443 SetLayerPropertiesForTesting(
444 parent.get(), identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
445 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
446 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
447 gfx::PointF(), gfx::Size(16, 18), true, false);
448 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
449 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
450 true, false);
[email protected]fb661802013-03-25 01:59:32451 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31452 EXPECT_TRANSFORMATION_MATRIX_EQ(
453 parent_position_transform,
454 DrawTransformFromPropertyTrees(child.get(), tree));
455 EXPECT_TRANSFORMATION_MATRIX_EQ(
456 parent_position_transform,
457 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
458 EXPECT_TRANSFORMATION_MATRIX_EQ(
459 parent_position_transform,
460 DrawTransformFromPropertyTrees(grand_child.get(), tree));
461 EXPECT_TRANSFORMATION_MATRIX_EQ(
462 parent_position_transform,
463 ScreenSpaceTransformFromPropertyTrees(grand_child.get(), tree));
[email protected]94f206c12012-08-25 00:09:14464
[email protected]fb661802013-03-25 01:59:32465 // Case 3: parent's local transform affects child and grandchild
466 gfx::Transform parent_layer_transform;
467 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
468 gfx::Transform parent_translation_to_anchor;
469 parent_translation_to_anchor.Translate(2.5, 3.0);
470 gfx::Transform parent_composite_transform =
471 parent_translation_to_anchor * parent_layer_transform *
472 Inverse(parent_translation_to_anchor);
enne826452722015-08-18 22:22:31473 SetLayerPropertiesForTesting(parent.get(), parent_layer_transform,
474 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
475 gfx::Size(10, 12), true, false);
476 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
477 gfx::PointF(), gfx::Size(16, 18), true, false);
478 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
479 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
480 true, false);
[email protected]fb661802013-03-25 01:59:32481 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31482 EXPECT_TRANSFORMATION_MATRIX_EQ(
483 parent_composite_transform,
484 DrawTransformFromPropertyTrees(child.get(), tree));
485 EXPECT_TRANSFORMATION_MATRIX_EQ(
486 parent_composite_transform,
487 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
488 EXPECT_TRANSFORMATION_MATRIX_EQ(
489 parent_composite_transform,
490 DrawTransformFromPropertyTrees(grand_child.get(), tree));
491 EXPECT_TRANSFORMATION_MATRIX_EQ(
492 parent_composite_transform,
493 ScreenSpaceTransformFromPropertyTrees(grand_child.get(), tree));
[email protected]94f206c12012-08-25 00:09:14494}
495
[email protected]989386c2013-07-18 21:37:23496TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
enne25dea3f2015-07-27 16:44:28497 LayerImpl* root = root_layer();
498 LayerImpl* parent = AddChildToRoot<LayerImpl>();
499 LayerImpl* child = AddChild<LayerImpl>(parent);
500 LayerImpl* grand_child = AddChild<LayerImpl>(child);
501 grand_child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:14502
[email protected]fb661802013-03-25 01:59:32503 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28504 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
505 gfx::PointF(), gfx::Size(1, 2), true, false,
506 true);
[email protected]ecc12622012-10-30 20:45:42507
[email protected]fb661802013-03-25 01:59:32508 // Child is set up so that a new render surface should be created.
509 child->SetOpacity(0.5f);
jaydasika8640f9f2015-11-10 01:34:36510 child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:14511
[email protected]fb661802013-03-25 01:59:32512 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05513 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32514 gfx::Transform parent_translation_to_anchor;
515 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44516
[email protected]fb661802013-03-25 01:59:32517 gfx::Transform parent_composite_transform =
518 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39519 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32520 gfx::Vector2dF parent_composite_scale =
521 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
522 1.f);
523 gfx::Transform surface_sublayer_transform;
524 surface_sublayer_transform.Scale(parent_composite_scale.x(),
525 parent_composite_scale.y());
526 gfx::Transform surface_sublayer_composite_transform =
527 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14528
enne25dea3f2015-07-27 16:44:28529 SetLayerPropertiesForTesting(parent, parent_layer_transform,
530 gfx::Point3F(25.0f, 30.0f, 0.f), gfx::PointF(),
531 gfx::Size(100, 120), true, false, false);
532 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
533 gfx::PointF(), gfx::Size(16, 18), true, false,
534 true);
535 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
536 gfx::PointF(), gfx::Size(8, 10), true, false,
[email protected]fb661802013-03-25 01:59:32537 false);
enne25dea3f2015-07-27 16:44:28538 ExecuteCalculateDrawProperties(root);
[email protected]94f206c12012-08-25 00:09:14539
[email protected]fb661802013-03-25 01:59:32540 // Render surface should have been created now.
541 ASSERT_TRUE(child->render_surface());
enne25dea3f2015-07-27 16:44:28542 ASSERT_EQ(child, child->render_target());
[email protected]94f206c12012-08-25 00:09:14543
[email protected]fb661802013-03-25 01:59:32544 // The child layer's draw transform should refer to its new render surface.
545 // The screen-space transform, however, should still refer to the root.
546 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
ajumad9432e32015-11-30 19:43:44547 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32548 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
ajumab6aa1c62015-12-01 21:01:10549 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14550
[email protected]fb661802013-03-25 01:59:32551 // Because the grand_child is the only drawable content, the child's render
552 // surface will tighten its bounds to the grand_child. The scale at which the
553 // surface's subtree is drawn must be removed from the composite transform.
554 EXPECT_TRANSFORMATION_MATRIX_EQ(
555 surface_sublayer_composite_transform,
556 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14557
[email protected]fb661802013-03-25 01:59:32558 // The screen space is the same as the target since the child surface draws
559 // into the root.
560 EXPECT_TRANSFORMATION_MATRIX_EQ(
561 surface_sublayer_composite_transform,
562 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14563}
564
ajuma51d73f72015-10-19 19:43:58565TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) {
566 LayerImpl* root = root_layer();
567 LayerImpl* parent = AddChildToRoot<LayerImpl>();
568 LayerImpl* child = AddChild<LayerImpl>(parent);
569 LayerImpl* grand_child = AddChild<LayerImpl>(child);
570 grand_child->SetDrawsContent(true);
571
572 gfx::Transform identity_matrix;
573 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
574 gfx::PointF(), gfx::Size(100, 100), true, false,
575 true);
576
577 gfx::Transform parent_transform;
578 parent_transform.Translate(10.0, 10.0);
579
580 gfx::Transform child_transform;
581 child_transform.Rotate(45.0);
582
583 // child gets a render surface when surfaces are enabled.
584 SetLayerPropertiesForTesting(parent, parent_transform, gfx::Point3F(),
585 gfx::PointF(), gfx::Size(10, 10), true, false,
586 false);
587 SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(),
588 gfx::PointF(), gfx::Size(10, 10), true, false,
589 true);
590 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
591 gfx::PointF(2.0, 2.0), gfx::Size(20, 20), true,
592 false, false);
593
594 gfx::Transform expected_grand_child_screen_space_transform;
595 expected_grand_child_screen_space_transform.Translate(10.0, 10.0);
596 expected_grand_child_screen_space_transform.Rotate(45.0);
597 expected_grand_child_screen_space_transform.Translate(2.0, 2.0);
598
599 // First compute draw properties with separate surfaces enabled.
600 ExecuteCalculateDrawProperties(root);
601
602 // The grand child's draw transform should be its offset wrt the child.
603 gfx::Transform expected_grand_child_draw_transform;
604 expected_grand_child_draw_transform.Translate(2.0, 2.0);
605 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44606 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58607 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10608 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58609
610 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
611
612 // With separate surfaces disabled, the grand child's draw transform should be
613 // the same as its screen space transform.
614 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumad9432e32015-11-30 19:43:44615 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58616 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10617 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58618}
619
[email protected]989386c2013-07-18 21:37:23620TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
enne25dea3f2015-07-27 16:44:28621 LayerImpl* root = root_layer();
622 LayerImpl* parent = AddChildToRoot<LayerImpl>();
623 LayerImpl* child = AddChild<LayerImpl>(parent);
624 LayerImpl* grand_child = AddChild<LayerImpl>(child);
625 grand_child->SetDrawsContent(true);
626 scoped_ptr<LayerImpl> child_replica =
627 LayerImpl::Create(host_impl()->active_tree(), 100);
[email protected]d600df7d2013-08-03 02:34:28628
[email protected]fb661802013-03-25 01:59:32629 // One-time setup of root layer
630 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28631 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
632 gfx::PointF(), gfx::Size(1, 2), true, false,
633 true);
[email protected]fb661802013-03-25 01:59:32634
635 // Child is set up so that a new render surface should be created.
636 child->SetOpacity(0.5f);
637
638 gfx::Transform parent_layer_transform;
639 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
640 gfx::Transform parent_translation_to_anchor;
641 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32642 gfx::Transform parent_composite_transform =
643 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39644 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32645 gfx::Transform replica_layer_transform;
646 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
647 gfx::Vector2dF parent_composite_scale =
648 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
649 1.f);
650 gfx::Transform surface_sublayer_transform;
651 surface_sublayer_transform.Scale(parent_composite_scale.x(),
652 parent_composite_scale.y());
653 gfx::Transform replica_composite_transform =
654 parent_composite_transform * replica_layer_transform *
655 Inverse(surface_sublayer_transform);
enne25dea3f2015-07-27 16:44:28656 child_replica->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32657 // Child's render surface should not exist yet.
658 ASSERT_FALSE(child->render_surface());
659
enne25dea3f2015-07-27 16:44:28660 SetLayerPropertiesForTesting(parent, parent_layer_transform,
661 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
662 gfx::Size(10, 12), true, false, false);
663 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
664 gfx::PointF(), gfx::Size(16, 18), true, false,
665 true);
666 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
667 gfx::PointF(-0.5f, -0.5f), gfx::Size(1, 1), true,
668 false, false);
669 SetLayerPropertiesForTesting(child_replica.get(), replica_layer_transform,
670 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
671 false, false);
danakja04855a2015-11-18 20:39:10672 child->SetReplicaLayer(std::move(child_replica));
enne25dea3f2015-07-27 16:44:28673
674 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32675
676 // Render surface should have been created now.
677 ASSERT_TRUE(child->render_surface());
enne25dea3f2015-07-27 16:44:28678 ASSERT_EQ(child, child->render_target());
[email protected]fb661802013-03-25 01:59:32679
680 EXPECT_TRANSFORMATION_MATRIX_EQ(
681 replica_composite_transform,
682 child->render_target()->render_surface()->replica_draw_transform());
683 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57684 child->render_target()
685 ->render_surface()
[email protected]fb661802013-03-25 01:59:32686 ->replica_screen_space_transform());
687}
688
[email protected]989386c2013-07-18 21:37:23689TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32690 // This test creates a more complex tree and verifies it all at once. This
691 // covers the following cases:
692 // - layers that are described w.r.t. a render surface: should have draw
693 // transforms described w.r.t. that surface
694 // - A render surface described w.r.t. an ancestor render surface: should
695 // have a draw transform described w.r.t. that ancestor surface
696 // - Replicas of a render surface are described w.r.t. the replica's
697 // transform around its anchor, along with the surface itself.
698 // - Sanity check on recursion: verify transforms of layers described w.r.t.
699 // a render surface that is described w.r.t. an ancestor render surface.
700 // - verifying that each layer has a reference to the correct render surface
701 // and render target values.
702
enne25dea3f2015-07-27 16:44:28703 LayerImpl* root = root_layer();
704 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36705 parent->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28706 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36707 render_surface1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28708 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36709 render_surface2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28710 LayerImpl* child_of_root = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36711 child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28712 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36713 child_of_rs1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28714 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:36715 child_of_rs2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28716 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
jaydasika8640f9f2015-11-10 01:34:36717 grand_child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28718 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
719 grand_child_of_rs1->SetDrawsContent(true);
720 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
721 grand_child_of_rs2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32722
enne25dea3f2015-07-27 16:44:28723 scoped_ptr<LayerImpl> replica_of_rs1 =
724 LayerImpl::Create(host_impl()->active_tree(), 101);
725 scoped_ptr<LayerImpl> replica_of_rs2 =
726 LayerImpl::Create(host_impl()->active_tree(), 102);
[email protected]d600df7d2013-08-03 02:34:28727
[email protected]fb661802013-03-25 01:59:32728 // In combination with descendant draws content, opacity != 1 forces the layer
729 // to have a new render surface.
730 render_surface1->SetOpacity(0.5f);
731 render_surface2->SetOpacity(0.33f);
732
733 // One-time setup of root layer
734 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28735 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
736 gfx::PointF(), gfx::Size(1, 2), true, false,
737 true);
[email protected]fb661802013-03-25 01:59:32738
739 // All layers in the tree are initialized with an anchor at .25 and a size of
740 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39741 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32742 gfx::Transform translation_to_anchor;
743 translation_to_anchor.Translate(2.5, 0.0);
744 gfx::Transform layer_transform;
745 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32746 gfx::Transform replica_layer_transform;
747 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
748
749 gfx::Transform A =
750 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32751 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
752 Inverse(translation_to_anchor);
753
754 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39755 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32756 gfx::Transform surface1_sublayer_transform;
757 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
758 surface1_parent_transform_scale.y());
759
760 // SS1 = transform given to the subtree of render_surface1
761 gfx::Transform SS1 = surface1_sublayer_transform;
762 // S1 = transform to move from render_surface1 pixels to the layer space of
763 // the owning layer
764 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
765
766 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39767 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32768 gfx::Transform surface2_sublayer_transform;
769 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
770 surface2_parent_transform_scale.y());
771
772 // SS2 = transform given to the subtree of render_surface2
773 gfx::Transform SS2 = surface2_sublayer_transform;
774 // S2 = transform to move from render_surface2 pixels to the layer space of
775 // the owning layer
776 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
777
enne25dea3f2015-07-27 16:44:28778 SetLayerPropertiesForTesting(parent, layer_transform,
779 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
780 gfx::Size(10, 10), true, false, false);
781 SetLayerPropertiesForTesting(render_surface1, layer_transform,
782 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
783 gfx::Size(10, 10), true, false, true);
784 SetLayerPropertiesForTesting(render_surface2, layer_transform,
785 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
786 gfx::Size(10, 10), true, false, true);
787 SetLayerPropertiesForTesting(child_of_root, layer_transform,
788 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
789 gfx::Size(10, 10), true, false, false);
790 SetLayerPropertiesForTesting(child_of_rs1, layer_transform,
791 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
792 gfx::Size(10, 10), true, false, false);
793 SetLayerPropertiesForTesting(child_of_rs2, layer_transform,
794 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
795 gfx::Size(10, 10), true, false, false);
796 SetLayerPropertiesForTesting(grand_child_of_root, layer_transform,
797 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
798 gfx::Size(10, 10), true, false, false);
799 SetLayerPropertiesForTesting(grand_child_of_rs1, layer_transform,
800 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
801 gfx::Size(10, 10), true, false, false);
802 SetLayerPropertiesForTesting(grand_child_of_rs2, layer_transform,
803 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
804 gfx::Size(10, 10), true, false, false);
805 SetLayerPropertiesForTesting(replica_of_rs1.get(), replica_layer_transform,
806 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
807 gfx::Size(), true, false, false);
808 SetLayerPropertiesForTesting(replica_of_rs2.get(), replica_layer_transform,
809 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
810 gfx::Size(), true, false, false);
[email protected]fb661802013-03-25 01:59:32811
danakja04855a2015-11-18 20:39:10812 render_surface1->SetReplicaLayer(std::move(replica_of_rs1));
813 render_surface2->SetReplicaLayer(std::move(replica_of_rs2));
enne25dea3f2015-07-27 16:44:28814 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32815
816 // Only layers that are associated with render surfaces should have an actual
817 // RenderSurface() value.
818 ASSERT_TRUE(root->render_surface());
819 ASSERT_FALSE(child_of_root->render_surface());
820 ASSERT_FALSE(grand_child_of_root->render_surface());
821
822 ASSERT_TRUE(render_surface1->render_surface());
823 ASSERT_FALSE(child_of_rs1->render_surface());
824 ASSERT_FALSE(grand_child_of_rs1->render_surface());
825
826 ASSERT_TRUE(render_surface2->render_surface());
827 ASSERT_FALSE(child_of_rs2->render_surface());
828 ASSERT_FALSE(grand_child_of_rs2->render_surface());
829
830 // Verify all render target accessors
enne25dea3f2015-07-27 16:44:28831 EXPECT_EQ(root, parent->render_target());
832 EXPECT_EQ(root, child_of_root->render_target());
833 EXPECT_EQ(root, grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32834
enne25dea3f2015-07-27 16:44:28835 EXPECT_EQ(render_surface1, render_surface1->render_target());
836 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
837 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32838
enne25dea3f2015-07-27 16:44:28839 EXPECT_EQ(render_surface2, render_surface2->render_target());
840 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
841 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32842
843 // Verify layer draw transforms note that draw transforms are described with
844 // respect to the nearest ancestor render surface but screen space transforms
845 // are described with respect to the root.
ajumad9432e32015-11-30 19:43:44846 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform());
847 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39848 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumad9432e32015-11-30 19:43:44849 grand_child_of_root->DrawTransform());
[email protected]fb661802013-03-25 01:59:32850
ajumad9432e32015-11-30 19:43:44851 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform());
852 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39853 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
ajumad9432e32015-11-30 19:43:44854 grand_child_of_rs1->DrawTransform());
[email protected]fb661802013-03-25 01:59:32855
ajumad9432e32015-11-30 19:43:44856 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform());
857 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39858 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
ajumad9432e32015-11-30 19:43:44859 grand_child_of_rs2->DrawTransform());
[email protected]fb661802013-03-25 01:59:32860
861 // Verify layer screen-space transforms
862 //
ajumab6aa1c62015-12-01 21:01:10863 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform());
864 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform());
865 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
866 grand_child_of_root->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32867
[email protected]baf64d062014-02-16 22:10:39868 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
ajumab6aa1c62015-12-01 21:01:10869 render_surface1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39870 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10871 child_of_rs1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39872 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10873 grand_child_of_rs1->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32874
[email protected]baf64d062014-02-16 22:10:39875 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10876 render_surface2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39877 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10878 child_of_rs2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39879 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10880 grand_child_of_rs2->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32881
882 // Verify render surface transforms.
883 //
884 // Draw transform of render surface 1 is described with respect to root.
885 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39886 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32887 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39888 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:32889 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39890 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32891 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39892 A * R * S1,
[email protected]fb661802013-03-25 01:59:32893 render_surface1->render_surface()->replica_screen_space_transform());
894 // Draw transform of render surface 2 is described with respect to render
895 // surface 1.
896 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39897 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32898 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39899 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:32900 render_surface2->render_surface()->replica_draw_transform());
901 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39902 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:32903 render_surface2->render_surface()->screen_space_transform());
904 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39905 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:32906 render_surface2->render_surface()->replica_screen_space_transform());
907
908 // Sanity check. If these fail there is probably a bug in the test itself. It
909 // is expected that we correctly set up transforms so that the y-component of
910 // the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:10911 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:26912 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:10913 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32914 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10915 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32916
[email protected]803f6b52013-09-12 00:51:26917 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:10918 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
919 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32920 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10921 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32922
[email protected]803f6b52013-09-12 00:51:26923 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:10924 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
925 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32926 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10927 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32928}
929
[email protected]989386c2013-07-18 21:37:23930TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:32931 // For layers that flatten their subtree, there should be an orthographic
932 // projection (for x and y values) in the middle of the transform sequence.
933 // Note that the way the code is currently implemented, it is not expected to
934 // use a canonical orthographic projection.
935
enne25dea3f2015-07-27 16:44:28936 LayerImpl* root = root_layer();
937 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36938 child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28939 LayerImpl* grand_child = AddChild<LayerImpl>(child);
940 grand_child->SetDrawsContent(true);
941 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
942 great_grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32943
944 gfx::Transform rotation_about_y_axis;
945 rotation_about_y_axis.RotateAboutYAxis(30.0);
946
947 const gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28948 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
949 gfx::PointF(), gfx::Size(100, 100), true, false,
950 true);
951 SetLayerPropertiesForTesting(child, rotation_about_y_axis, gfx::Point3F(),
952 gfx::PointF(), gfx::Size(10, 10), true, false,
953 true);
954 SetLayerPropertiesForTesting(grand_child, rotation_about_y_axis,
ajumad0d64422015-03-14 04:20:08955 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
enne25dea3f2015-07-27 16:44:28956 true, false, false);
957 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
958 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
959 true, false, false);
[email protected]d600df7d2013-08-03 02:34:28960
[email protected]fb661802013-03-25 01:59:32961 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:57962 ASSERT_TRUE(root->should_flatten_transform());
963 ASSERT_TRUE(child->should_flatten_transform());
964 ASSERT_TRUE(grand_child->should_flatten_transform());
ajumad0d64422015-03-14 04:20:08965 ASSERT_TRUE(great_grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:32966
967 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
968 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
969 gfx::Transform expected_grand_child_draw_transform =
970 rotation_about_y_axis; // draws onto child's render surface
971 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
972 flattened_rotation_about_y.FlattenTo2d();
973 gfx::Transform expected_grand_child_screen_space_transform =
974 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:08975 gfx::Transform expected_great_grand_child_draw_transform =
976 flattened_rotation_about_y;
977 gfx::Transform expected_great_grand_child_screen_space_transform =
978 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:32979
enne25dea3f2015-07-27 16:44:28980 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32981
982 // The child's draw transform should have been taken by its surface.
983 ASSERT_TRUE(child->render_surface());
984 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
985 child->render_surface()->draw_transform());
986 EXPECT_TRANSFORMATION_MATRIX_EQ(
987 expected_child_screen_space_transform,
988 child->render_surface()->screen_space_transform());
ajumad9432e32015-11-30 19:43:44989 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32990 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10991 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32992 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44993 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32994 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10995 grand_child->ScreenSpaceTransform());
ajumad0d64422015-03-14 04:20:08996 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44997 great_grand_child->DrawTransform());
ajumad0d64422015-03-14 04:20:08998 EXPECT_TRANSFORMATION_MATRIX_EQ(
999 expected_great_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101000 great_grand_child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321001}
1002
ajumadbd92cb2015-07-16 13:47:061003TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
1004 scoped_refptr<Layer> root = Layer::Create(layer_settings());
1005 scoped_refptr<Layer> child = Layer::Create(layer_settings());
1006 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1007 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1008
1009 gfx::Transform child_transform;
1010 child_transform.Translate(50.0, 50.0);
1011 child_transform.RotateAboutZAxis(30.0);
1012
1013 gfx::Transform grand_child_transform;
1014 grand_child_transform.RotateAboutYAxis(90.0);
1015
1016 const gfx::Transform identity_matrix;
1017 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
1018 gfx::PointF(), gfx::Size(200, 200), true, false);
1019 SetLayerPropertiesForTesting(child.get(), child_transform, gfx::Point3F(),
1020 gfx::PointF(), gfx::Size(10, 10), true, false);
1021 SetLayerPropertiesForTesting(grand_child.get(), grand_child_transform,
1022 gfx::Point3F(), gfx::PointF(),
1023 gfx::Size(100, 100), true, false);
1024
1025 root->AddChild(child);
1026 child->AddChild(grand_child);
1027 grand_child->SetShouldFlattenTransform(false);
1028
1029 host()->SetRootLayer(root);
1030
1031 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
1032
1033 // Mapping grand_child's bounds to target space produces a non-empty rect
1034 // that is fully contained within the target's bounds, so grand_child should
1035 // be considered fully visible.
1036 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
1037 grand_child->visible_rect_from_property_trees());
1038}
1039
[email protected]989386c2013-07-18 21:37:231040TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321041 // A layer that is empty in one axis, but not the other, was accidentally
1042 // skipping a necessary translation. Without that translation, the coordinate
1043 // space of the layer's draw transform is incorrect.
1044 //
1045 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1046 // but if that layer becomes a render surface, then its draw transform is
1047 // implicitly inherited by the rest of the subtree, which then is positioned
1048 // incorrectly as a result.
1049
ennec1332992015-08-24 19:45:091050 LayerImpl* root = root_layer();
1051 LayerImpl* child = AddChild<LayerImpl>(root);
1052 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1053 grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321054
1055 // The child height is zero, but has non-zero width that should be accounted
1056 // for while computing draw transforms.
1057 const gfx::Transform identity_matrix;
ennec1332992015-08-24 19:45:091058 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1059 gfx::PointF(), gfx::Size(100, 100), true, false,
1060 true);
1061 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1062 gfx::PointF(), gfx::Size(10, 0), true, false,
1063 true);
1064 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1065 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321066 false);
1067
ennec1332992015-08-24 19:45:091068 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321069
ennec1332992015-08-24 19:45:091070 ASSERT_TRUE(child->has_render_surface());
[email protected]fb661802013-03-25 01:59:321071 // This is the real test, the rest are sanity checks.
1072 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1073 child->render_surface()->draw_transform());
ajumad9432e32015-11-30 19:43:441074 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321075 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
ajumad9432e32015-11-30 19:43:441076 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321077}
1078
jaydasika9bbee9b2016-01-13 00:36:481079TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) {
1080 const gfx::Transform identity_matrix;
1081 LayerImpl* root = root_layer();
1082 LayerImpl* render_surface = AddChild<LayerImpl>(root);
1083 LayerImpl* child = AddChild<LayerImpl>(render_surface);
1084 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1085
1086 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1087 gfx::PointF(), gfx::Size(100, 100), true, false,
1088 true);
1089 gfx::Transform translate;
1090 translate.Translate3d(5, 5, 5);
1091 SetLayerPropertiesForTesting(render_surface, translate, gfx::Point3F(),
1092 gfx::PointF(), gfx::Size(100, 100), true, false,
1093 true);
1094 SetLayerPropertiesForTesting(child, translate, gfx::Point3F(), gfx::PointF(),
1095 gfx::Size(100, 100), true, false, false);
1096 SetLayerPropertiesForTesting(grand_child, translate, gfx::Point3F(),
1097 gfx::PointF(), gfx::Size(100, 100), true, false,
1098 false);
1099 grand_child->SetDrawsContent(true);
1100
1101 // render_surface will have a sublayer scale because of device scale factor.
1102 float device_scale_factor = 2.0f;
1103 LayerImplList render_surface_layer_list_impl;
1104 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
1105 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1106 root, root->bounds(), translate, &render_surface_layer_list_impl,
1107 root->layer_tree_impl()->current_render_surface_list_id());
1108 inputs.device_scale_factor = device_scale_factor;
1109 inputs.property_trees->needs_rebuild = true;
1110 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1111
1112 // Between grand_child and render_surface, we translate by (10, 10) and scale
1113 // by a factor of 2.
1114 gfx::Vector2dF expected_translation(20.0f, 20.0f);
1115 EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(),
1116 expected_translation);
1117}
1118
[email protected]989386c2013-07-18 21:37:231119TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321120 // Transformations applied at the root of the tree should be forwarded
1121 // to child layers instead of applied to the root RenderSurface.
1122 const gfx::Transform identity_matrix;
enned3f61fb02015-08-18 22:54:391123 LayerImpl* root = root_layer();
1124 root->SetDrawsContent(true);
1125 LayerImpl* child = AddChild<LayerImpl>(root);
1126 child->SetDrawsContent(true);
[email protected]f224cc92013-06-06 23:23:321127
enned3f61fb02015-08-18 22:54:391128 child->SetScrollClipLayer(root->id());
[email protected]d600df7d2013-08-03 02:34:281129
enned3f61fb02015-08-18 22:54:391130 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1131 gfx::PointF(), gfx::Size(20, 20), true, false,
1132 true);
1133 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1134 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]f224cc92013-06-06 23:23:321135 false);
1136
[email protected]f224cc92013-06-06 23:23:321137 gfx::Transform translate;
1138 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231139 {
enned3f61fb02015-08-18 22:54:391140 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441141 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391142 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441143 root, root->bounds(), translate, &render_surface_layer_list_impl,
1144 root->layer_tree_impl()->current_render_surface_list_id());
vollick5057e1e2015-04-17 19:12:321145 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531146 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231147 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1148 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1149 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1150 }
[email protected]f224cc92013-06-06 23:23:321151
1152 gfx::Transform scale;
1153 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231154 {
enned3f61fb02015-08-18 22:54:391155 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441156 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391157 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441158 root, root->bounds(), scale, &render_surface_layer_list_impl,
1159 root->layer_tree_impl()->current_render_surface_list_id());
vollick5057e1e2015-04-17 19:12:321160 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531161 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231162 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1163 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1164 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1165 }
[email protected]f224cc92013-06-06 23:23:321166
1167 gfx::Transform rotate;
1168 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231169 {
enned3f61fb02015-08-18 22:54:391170 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441171 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391172 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441173 root, root->bounds(), rotate, &render_surface_layer_list_impl,
1174 root->layer_tree_impl()->current_render_surface_list_id());
vollick5057e1e2015-04-17 19:12:321175 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531176 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231177 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1178 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1179 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1180 }
[email protected]f224cc92013-06-06 23:23:321181
1182 gfx::Transform composite;
1183 composite.ConcatTransform(translate);
1184 composite.ConcatTransform(scale);
1185 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231186 {
enned3f61fb02015-08-18 22:54:391187 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441188 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391189 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441190 root, root->bounds(), composite, &render_surface_layer_list_impl,
1191 root->layer_tree_impl()->current_render_surface_list_id());
vollick5057e1e2015-04-17 19:12:321192 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531193 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231194 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1195 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1196 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1197 }
[email protected]f224cc92013-06-06 23:23:321198
[email protected]9781afa2013-07-17 23:15:321199 // Verify it composes correctly with device scale.
1200 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231201
1202 {
enned3f61fb02015-08-18 22:54:391203 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441204 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391205 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441206 root, root->bounds(), translate, &render_surface_layer_list_impl,
1207 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:531208 inputs.device_scale_factor = device_scale_factor;
vollick5057e1e2015-04-17 19:12:321209 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531210 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231211 gfx::Transform device_scaled_translate = translate;
1212 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1213 EXPECT_EQ(device_scaled_translate,
1214 root->draw_properties().target_space_transform);
1215 EXPECT_EQ(device_scaled_translate,
1216 child->draw_properties().target_space_transform);
1217 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1218 }
[email protected]9781afa2013-07-17 23:15:321219
1220 // Verify it composes correctly with page scale.
1221 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231222
1223 {
enned3f61fb02015-08-18 22:54:391224 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441225 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391226 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441227 root, root->bounds(), translate, &render_surface_layer_list_impl,
1228 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:531229 inputs.page_scale_factor = page_scale_factor;
enned3f61fb02015-08-18 22:54:391230 inputs.page_scale_layer = root;
vollick5057e1e2015-04-17 19:12:321231 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531232 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231233 gfx::Transform page_scaled_translate = translate;
1234 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
enne6394d5b42015-05-26 22:23:111235 EXPECT_EQ(page_scaled_translate,
1236 root->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231237 EXPECT_EQ(page_scaled_translate,
1238 child->draw_properties().target_space_transform);
1239 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1240 }
[email protected]9781afa2013-07-17 23:15:321241
[email protected]f224cc92013-06-06 23:23:321242 // Verify that it composes correctly with transforms directly on root layer.
1243 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231244
1245 {
enned3f61fb02015-08-18 22:54:391246 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441247 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391248 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441249 root, root->bounds(), composite, &render_surface_layer_list_impl,
1250 root->layer_tree_impl()->current_render_surface_list_id());
enned3f61fb02015-08-18 22:54:391251 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531252 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231253 gfx::Transform compositeSquared = composite;
1254 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261255 EXPECT_TRANSFORMATION_MATRIX_EQ(
1256 compositeSquared, root->draw_properties().target_space_transform);
1257 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391258 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231259 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1260 }
[email protected]f224cc92013-06-06 23:23:321261}
1262
[email protected]989386c2013-07-18 21:37:231263TEST_F(LayerTreeHostCommonTest,
1264 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
enneea850232015-07-27 16:43:121265 LayerImpl* parent = root_layer();
1266 parent->SetMasksToBounds(true);
1267 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1268 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1269 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:281270
[email protected]fb661802013-03-25 01:59:321271 const gfx::Transform identity_matrix;
enneea850232015-07-27 16:43:121272 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1273 gfx::PointF(), gfx::Size(10, 10), true, false,
1274 true);
1275 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1276 gfx::PointF(), gfx::Size(10, 10), true, false,
1277 true);
1278 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1279 gfx::PointF(30.f, 30.f), gfx::Size(10, 10), true,
1280 false, false);
[email protected]fb661802013-03-25 01:59:321281
enneea850232015-07-27 16:43:121282 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321283
1284 // The child layer's content is entirely outside the parent's clip rect, so
1285 // the intermediate render surface should not be listed here, even if it was
1286 // forced to be created. Render surfaces without children or visible content
1287 // are unexpected at draw time (e.g. we might try to create a content texture
1288 // of size 0).
1289 ASSERT_TRUE(parent->render_surface());
enneea850232015-07-27 16:43:121290 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:321291}
1292
[email protected]989386c2013-07-18 21:37:231293TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
enne03b0e9a2015-06-19 00:08:021294 LayerImpl* parent = root_layer();
1295 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
1296 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1297 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:281298
[email protected]fb661802013-03-25 01:59:321299 const gfx::Transform identity_matrix;
enne03b0e9a2015-06-19 00:08:021300 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1301 gfx::PointF(), gfx::Size(10, 10), true, false,
1302 true);
1303 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1304 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321305 false);
[email protected]fb661802013-03-25 01:59:321306 render_surface1->SetOpacity(0.f);
1307
enne03b0e9a2015-06-19 00:08:021308 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:441309 parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enne03b0e9a2015-06-19 00:08:021310 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441311 parent, parent->bounds(), &render_surface_layer_list,
1312 parent->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:531313 inputs.can_adjust_raster_scales = true;
1314 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321315
1316 // Since the layer is transparent, render_surface1->render_surface() should
1317 // not have gotten added anywhere. Also, the drawable content rect should not
1318 // have been extended by the children.
1319 ASSERT_TRUE(parent->render_surface());
1320 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1321 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231322 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321323 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1324}
1325
hendrikwc266f7b2015-08-21 23:41:341326TEST_F(LayerTreeHostCommonTest,
1327 RenderSurfaceListForTransparentChildWithBackgroundFilter) {
1328 LayerImpl* parent = root_layer();
1329 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
1330 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1331 child->SetDrawsContent(true);
1332
1333 const gfx::Transform identity_matrix;
1334 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1335 gfx::PointF(), gfx::Size(10, 10), true, false,
1336 true);
1337 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1338 gfx::PointF(), gfx::Size(10, 10), true, false,
1339 true);
1340 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1341 gfx::PointF(), gfx::Size(10, 10), true, false,
1342 false);
1343 render_surface1->SetOpacity(0.f);
jaydasika86654512016-01-27 17:05:071344 render_surface1->SetDrawsContent(true);
1345 child->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341346 FilterOperations filters;
1347 filters.Append(FilterOperation::CreateBlurFilter(1.5f));
1348 render_surface1->SetBackgroundFilters(filters);
1349
1350 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:441351 parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
hendrikwc266f7b2015-08-21 23:41:341352 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441353 parent, parent->bounds(), &render_surface_layer_list,
1354 parent->layer_tree_impl()->current_render_surface_list_id());
hendrikwc266f7b2015-08-21 23:41:341355 inputs.can_adjust_raster_scales = true;
1356 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1357
1358 // The layer is fully transparent, but has a background filter, so it
1359 // shouldn't be skipped.
1360 ASSERT_TRUE(parent->render_surface());
1361 EXPECT_EQ(1U, parent->render_surface()->layer_list().size());
1362 EXPECT_EQ(2U, render_surface_layer_list.size());
jaydasika8640f9f2015-11-10 01:34:361363 EXPECT_EQ(gfx::RectF(0, 0, 10, 10),
1364 parent->render_surface()->DrawableContentRect());
hendrikwc266f7b2015-08-21 23:41:341365}
1366
senorblanco38858c52016-01-20 23:15:001367TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) {
1368 LayerImpl* root = root_layer();
1369 LayerImpl* parent = AddChild<LayerImpl>(root);
1370 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1371 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1372 child1->SetDrawsContent(true);
1373 child2->SetDrawsContent(true);
1374
1375 const gfx::Transform identity_matrix;
1376 gfx::Transform scale_matrix;
1377 scale_matrix.Scale(2.0f, 2.0f);
1378 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1379 gfx::PointF(), gfx::Size(100, 100), true, false,
1380 true);
1381 SetLayerPropertiesForTesting(parent, scale_matrix, gfx::Point3F(),
1382 gfx::PointF(), gfx::Size(), true, false, true);
1383 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1384 gfx::PointF(0, 0), gfx::Size(25, 25), true,
1385 false, true);
1386 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1387 gfx::PointF(25, 25), gfx::Size(25, 25), true,
1388 false, true);
1389 FilterOperations filters;
1390 filters.Append(FilterOperation::CreateBlurFilter(10.0f));
1391 parent->SetFilters(filters);
1392
1393 LayerImplList render_surface_layer_list;
1394 parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
1395 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1396 root, root->bounds(), &render_surface_layer_list,
1397 root->layer_tree_impl()->current_render_surface_list_id());
1398 inputs.can_adjust_raster_scales = true;
1399 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1400
1401 ASSERT_TRUE(parent->render_surface());
1402 EXPECT_EQ(2U, parent->render_surface()->layer_list().size());
1403 EXPECT_EQ(4U, render_surface_layer_list.size());
1404 EXPECT_EQ(gfx::RectF(-29, -29, 158, 158),
1405 parent->render_surface()->DrawableContentRect());
1406}
1407
rosca948d29d2014-11-09 10:25:131408TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
enned5f4ddd2015-08-18 16:50:061409 LayerImpl* parent = root_layer();
1410 LayerImpl* child = AddChild<LayerImpl>(parent);
1411 child->SetDrawsContent(true);
rosca948d29d2014-11-09 10:25:131412
1413 const gfx::Transform identity_matrix;
1414 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
enned5f4ddd2015-08-18 16:50:061415 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1416 gfx::PointF(), gfx::Size(10, 10), true, false,
1417 true);
1418 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1419 gfx::PointF(), gfx::Size(10, 10), true, false,
1420 true);
rosca948d29d2014-11-09 10:25:131421
rosca948d29d2014-11-09 10:25:131422 child->SetBlendMode(blend_mode);
weiliangc451b818f2015-07-24 17:52:291423 child->SetOpacity(0.5f);
rosca948d29d2014-11-09 10:25:131424
enned5f4ddd2015-08-18 16:50:061425 ExecuteCalculateDrawProperties(parent);
rosca948d29d2014-11-09 10:25:131426
1427 // Since the child layer has a blend mode other than normal, it should get
1428 // its own render surface. Also, layer's draw_properties should contain the
1429 // default blend mode, since the render surface becomes responsible for
1430 // applying the blend mode.
1431 ASSERT_TRUE(child->render_surface());
weiliangc451b818f2015-07-24 17:52:291432 EXPECT_EQ(1.0f, child->draw_opacity());
1433 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
jaydasika92239dc2015-08-15 02:59:261434 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode());
rosca948d29d2014-11-09 10:25:131435}
1436
jaydasikafbdb86e2016-01-21 18:57:511437TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) {
1438 LayerImpl* root = root_layer();
1439 LayerImpl* surface1 = AddChildToRoot<LayerImpl>();
1440 LayerImpl* not_surface = AddChild<LayerImpl>(surface1);
1441 LayerImpl* surface2 = AddChild<LayerImpl>(not_surface);
1442
1443 const gfx::Transform identity_matrix;
1444 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1445 gfx::PointF(), gfx::Size(10, 10), true, false,
1446 true);
1447 SetLayerPropertiesForTesting(surface1, identity_matrix, gfx::Point3F(),
1448 gfx::PointF(), gfx::Size(10, 10), true, false,
1449 true);
1450 SetLayerPropertiesForTesting(not_surface, identity_matrix, gfx::Point3F(),
1451 gfx::PointF(), gfx::Size(10, 10), true, false,
1452 false);
1453 SetLayerPropertiesForTesting(surface2, identity_matrix, gfx::Point3F(),
1454 gfx::PointF(), gfx::Size(10, 10), true, false,
1455 true);
1456 surface1->SetDrawsContent(true);
1457 surface2->SetDrawsContent(true);
1458
1459 surface1->SetOpacity(0.5f);
1460 not_surface->SetOpacity(0.5f);
1461 surface2->SetOpacity(0.5f);
1462
1463 ExecuteCalculateDrawProperties(root);
1464
1465 ASSERT_TRUE(surface1->render_surface());
1466 ASSERT_FALSE(not_surface->render_surface());
1467 ASSERT_TRUE(surface2->render_surface());
1468 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity());
1469 // surface2's draw opacity should include the opacity of not-surface and
1470 // itself, but not the opacity of surface1.
1471 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity());
1472}
1473
ajuma51d73f72015-10-19 19:43:581474TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) {
1475 // Tests that when separate surfaces are disabled, a layer's draw opacity is
1476 // the product of all ancestor layer opacties and the layer's own opacity.
1477 // (Rendering will still be incorrect in situations where we really do need
1478 // surfaces to apply opacity, such as when we have overlapping layers with an
1479 // ancestor whose opacity is <1.)
1480 LayerImpl* root = root_layer();
1481 LayerImpl* parent = AddChild<LayerImpl>(root);
1482 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1483 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1484 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1485 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1486 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1487
1488 root->SetDrawsContent(true);
1489 parent->SetDrawsContent(true);
1490 child1->SetDrawsContent(true);
1491 child2->SetDrawsContent(true);
1492 grand_child->SetDrawsContent(true);
1493 leaf_node1->SetDrawsContent(true);
1494 leaf_node2->SetDrawsContent(true);
1495
1496 const gfx::Transform identity_matrix;
1497
1498 // child1 and grand_child get render surfaces when surfaces are enabled.
1499 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1500 gfx::PointF(), gfx::Size(100, 100), true, false,
1501 true);
1502 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1503 gfx::PointF(), gfx::Size(100, 100), true, false,
1504 false);
1505 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1506 gfx::PointF(), gfx::Size(100, 100), true, false,
1507 true);
1508 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1509 gfx::PointF(), gfx::Size(100, 100), true, false,
1510 false);
1511 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1512 gfx::PointF(), gfx::Size(100, 100), true, false,
1513 true);
1514 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1515 gfx::PointF(), gfx::Size(100, 100), true, false,
1516 false);
1517 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1518 gfx::PointF(), gfx::Size(100, 100), true, false,
1519 false);
1520
1521 child1->SetOpacity(0.5f);
1522 grand_child->SetOpacity(0.5f);
1523 leaf_node1->SetOpacity(0.5f);
1524 leaf_node2->SetOpacity(0.5f);
1525
1526 // With surfaces enabled, each layer's draw opacity is the product of layer
1527 // opacities on the path from the layer to its render target, not including
1528 // the opacity of the layer that owns the target surface (since that opacity
1529 // is applied by the surface).
1530 ExecuteCalculateDrawProperties(root);
1531 EXPECT_EQ(1.f, root->draw_opacity());
1532 EXPECT_EQ(1.f, parent->draw_opacity());
1533 EXPECT_EQ(1.f, child1->draw_opacity());
1534 EXPECT_EQ(1.f, child2->draw_opacity());
1535 EXPECT_EQ(1.f, grand_child->draw_opacity());
1536 EXPECT_EQ(0.5f, leaf_node1->draw_opacity());
1537 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1538
1539 // With surfaces disabled, each layer's draw opacity is the product of layer
1540 // opacities on the path from the layer to the root.
1541 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1542 EXPECT_EQ(1.f, root->draw_opacity());
1543 EXPECT_EQ(1.f, parent->draw_opacity());
1544 EXPECT_EQ(0.5f, child1->draw_opacity());
1545 EXPECT_EQ(1.f, child2->draw_opacity());
1546 EXPECT_EQ(0.25f, grand_child->draw_opacity());
1547 EXPECT_EQ(0.125f, leaf_node1->draw_opacity());
1548 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1549}
1550
[email protected]989386c2013-07-18 21:37:231551TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
weiliangcc154ce22015-12-09 03:39:261552 LayerImpl* parent = root_layer();
1553 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1554 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
weiliangceffae0462015-12-08 23:17:261555
1556 const gfx::Transform identity_matrix;
weiliangcc154ce22015-12-09 03:39:261557 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
weiliangceffae0462015-12-08 23:17:261558 gfx::PointF(), gfx::Size(10, 10), true, false);
weiliangcc154ce22015-12-09 03:39:261559 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1560 gfx::PointF(), gfx::Size(10, 10), true, false);
1561 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
weiliangceffae0462015-12-08 23:17:261562 gfx::PointF(), gfx::Size(10, 10), true, false);
1563
weiliangcc154ce22015-12-09 03:39:261564 child->SetDrawsContent(true);
1565 render_surface1->SetForceRenderSurface(true);
weiliangceffae0462015-12-08 23:17:261566
[email protected]989386c2013-07-18 21:37:231567 {
weiliangcc154ce22015-12-09 03:39:261568 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:321569
[email protected]989386c2013-07-18 21:37:231570 // The root layer always creates a render surface
ennec1332992015-08-24 19:45:091571 EXPECT_TRUE(parent->has_render_surface());
1572 EXPECT_TRUE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231573 }
[email protected]fb661802013-03-25 01:59:321574
[email protected]989386c2013-07-18 21:37:231575 {
[email protected]989386c2013-07-18 21:37:231576 render_surface1->SetForceRenderSurface(false);
weiliangcc154ce22015-12-09 03:39:261577 render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true;
1578 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
ennec1332992015-08-24 19:45:091579 EXPECT_TRUE(parent->has_render_surface());
1580 EXPECT_FALSE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231581 }
[email protected]fb661802013-03-25 01:59:321582}
1583
ajuma246190a2015-03-11 20:56:031584TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1585 // Render surfaces act as a flattening point for their subtree, so should
1586 // always flatten the target-to-screen space transform seen by descendants.
1587
enne1a79c5542015-08-18 19:43:571588 LayerImpl* root = root_layer();
1589 LayerImpl* parent = AddChild<LayerImpl>(root);
1590 LayerImpl* child = AddChild<LayerImpl>(parent);
1591 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1592
1593 child->SetDrawsContent(true);
1594 grand_child->SetDrawsContent(true);
ajuma246190a2015-03-11 20:56:031595
1596 gfx::Transform rotation_about_y_axis;
1597 rotation_about_y_axis.RotateAboutYAxis(30.0);
1598 // Make |parent| have a render surface.
1599 parent->SetOpacity(0.9f);
1600
1601 const gfx::Transform identity_matrix;
enne1a79c5542015-08-18 19:43:571602 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1603 gfx::PointF(), gfx::Size(100, 100), true, false,
1604 true);
1605 SetLayerPropertiesForTesting(parent, rotation_about_y_axis, gfx::Point3F(),
1606 gfx::PointF(), gfx::Size(10, 10), true, false,
1607 true);
1608 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1609 gfx::PointF(), gfx::Size(10, 10), true, false,
1610 false);
1611 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1612 gfx::PointF(), gfx::Size(10, 10), true, false,
1613 false);
ajuma246190a2015-03-11 20:56:031614
1615 grand_child->SetShouldFlattenTransform(false);
1616
ajuma246190a2015-03-11 20:56:031617 // Only grand_child should preserve 3d.
1618 EXPECT_TRUE(root->should_flatten_transform());
1619 EXPECT_TRUE(parent->should_flatten_transform());
1620 EXPECT_TRUE(child->should_flatten_transform());
1621 EXPECT_FALSE(grand_child->should_flatten_transform());
1622
1623 gfx::Transform expected_child_draw_transform = identity_matrix;
1624 gfx::Transform expected_grand_child_draw_transform = identity_matrix;
1625
1626 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1627 flattened_rotation_about_y.FlattenTo2d();
1628
enne1a79c5542015-08-18 19:43:571629 ExecuteCalculateDrawProperties(root);
ajuma246190a2015-03-11 20:56:031630
1631 EXPECT_TRUE(parent->render_surface());
1632 EXPECT_FALSE(child->render_surface());
1633 EXPECT_FALSE(grand_child->render_surface());
1634
ajumad9432e32015-11-30 19:43:441635 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
ajuma246190a2015-03-11 20:56:031636 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
ajumad9432e32015-11-30 19:43:441637 grand_child->DrawTransform());
ajuma246190a2015-03-11 20:56:031638
1639 // The screen-space transform inherited by |child| and |grand_child| should
1640 // have been flattened at their render target. In particular, the fact that
1641 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1642 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101643 child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031644 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101645 grand_child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031646}
1647
[email protected]989386c2013-07-18 21:37:231648TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321649 // The entire subtree of layers that are outside the clip rect should be
1650 // culled away, and should not affect the render_surface_layer_list.
1651 //
1652 // The test tree is set up as follows:
1653 // - all layers except the leaf_nodes are forced to be a new render surface
1654 // that have something to draw.
1655 // - parent is a large container layer.
1656 // - child has masksToBounds=true to cause clipping.
1657 // - grand_child is positioned outside of the child's bounds
1658 // - great_grand_child is also kept outside child's bounds.
1659 //
1660 // In this configuration, grand_child and great_grand_child are completely
1661 // outside the clip rect, and they should never get scheduled on the list of
1662 // render surfaces.
[email protected]fb661802013-03-25 01:59:321663
weiliangcfb3d5eaa2015-07-28 23:54:571664 LayerImpl* parent = root_layer();
1665 LayerImpl* child = AddChildToRoot<LayerImpl>();
1666 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1667 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
[email protected]d600df7d2013-08-03 02:34:281668
[email protected]fb661802013-03-25 01:59:321669 // leaf_node1 ensures that parent and child are kept on the
1670 // render_surface_layer_list, even though grand_child and great_grand_child
1671 // should be clipped.
weiliangcfb3d5eaa2015-07-28 23:54:571672 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
1673 leaf_node1->SetDrawsContent(true);
1674 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
1675 leaf_node2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321676
weiliangcfb3d5eaa2015-07-28 23:54:571677 const gfx::Transform identity_matrix;
1678
1679 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1680 gfx::PointF(), gfx::Size(500, 500), true, false,
1681 true);
1682 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1683 gfx::PointF(), gfx::Size(20, 20), true, false,
1684 true);
1685 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1686 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1687 false, false);
1688 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
1689 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1690 true, false, false);
1691 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1692 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:321693 false);
weiliangcfb3d5eaa2015-07-28 23:54:571694 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1695 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]fb661802013-03-25 01:59:321696 false);
1697
1698 child->SetMasksToBounds(true);
1699 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321700 grand_child->SetOpacity(0.5f);
1701 great_grand_child->SetOpacity(0.4f);
1702
weiliangcfb3d5eaa2015-07-28 23:54:571703 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321704
weiliangcfb3d5eaa2015-07-28 23:54:571705 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
1706 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id());
1707 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id());
[email protected]fb661802013-03-25 01:59:321708}
1709
[email protected]989386c2013-07-18 21:37:231710TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321711 // When a render surface has a clip rect, it is used to clip the content rect
weiliangcfb3d5eaa2015-07-28 23:54:571712 // of the surface.
[email protected]fb661802013-03-25 01:59:321713
1714 // The test tree is set up as follows:
1715 // - parent is a container layer that masksToBounds=true to cause clipping.
1716 // - child is a render surface, which has a clip rect set to the bounds of
1717 // the parent.
1718 // - grand_child is a render surface, and the only visible content in child.
1719 // It is positioned outside of the clip rect from parent.
1720
1721 // In this configuration, grand_child should be outside the clipped
1722 // content rect of the child, making grand_child not appear in the
weiliangcfb3d5eaa2015-07-28 23:54:571723 // render_surface_layer_list.
1724
1725 LayerImpl* parent = root_layer();
1726 LayerImpl* child = AddChildToRoot<LayerImpl>();
1727 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1728 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
1729 leaf_node->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321730
1731 const gfx::Transform identity_matrix;
[email protected]fb661802013-03-25 01:59:321732
weiliangcfb3d5eaa2015-07-28 23:54:571733 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1734 gfx::PointF(), gfx::Size(100, 100), true, false,
1735 true);
1736 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1737 gfx::PointF(), gfx::Size(20, 20), true, false,
1738 true);
1739 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1740 gfx::PointF(200.f, 200.f), gfx::Size(10, 10),
1741 true, false, true);
1742 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
1743 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321744 false);
1745
1746 parent->SetMasksToBounds(true);
1747 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321748 grand_child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321749
weiliangcfb3d5eaa2015-07-28 23:54:571750 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321751
weiliangcfb3d5eaa2015-07-28 23:54:571752 // We should cull child and grand_child from the
1753 // render_surface_layer_list.
1754 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
1755 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id());
[email protected]fb661802013-03-25 01:59:321756}
1757
ajumae2b7a5c2015-09-30 21:41:421758TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1759 // Tests that LayerImpl's IsClipped() property is set to true when:
[email protected]fb661802013-03-25 01:59:321760 // - the layer clips its subtree, e.g. masks to bounds,
1761 // - the layer is clipped by an ancestor that contributes to the same
1762 // render target,
1763 // - a surface is clipped by an ancestor that contributes to the same
1764 // render target.
1765 //
1766 // In particular, for a layer that owns a render surface:
1767 // - the render surface inherits any clip from ancestors, and does NOT
1768 // pass that clipped status to the layer itself.
1769 // - but if the layer itself masks to bounds, it is considered clipped
1770 // and propagates the clip to the subtree.
1771
1772 const gfx::Transform identity_matrix;
enne76bf8982015-08-18 17:55:331773 LayerImpl* root = root_layer();
1774 LayerImpl* parent = AddChild<LayerImpl>(root);
jaydasika8640f9f2015-11-10 01:34:361775 parent->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331776 LayerImpl* child1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:361777 child1->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331778 LayerImpl* child2 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:361779 child2->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331780 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
jaydasika8640f9f2015-11-10 01:34:361781 grand_child->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331782 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1783 leaf_node1->SetDrawsContent(true);
1784 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1785 leaf_node2->SetDrawsContent(true);
1786
1787 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1788 gfx::PointF(), gfx::Size(100, 100), true, false,
1789 true);
1790 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1791 gfx::PointF(), gfx::Size(100, 100), true, false,
1792 false);
1793 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1794 gfx::PointF(), gfx::Size(100, 100), true, false,
1795 false);
1796 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1797 gfx::PointF(), gfx::Size(100, 100), true, false,
1798 true);
1799 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1800 gfx::PointF(), gfx::Size(100, 100), true, false,
1801 false);
1802 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1803 gfx::PointF(), gfx::Size(100, 100), true, false,
1804 false);
1805 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1806 gfx::PointF(), gfx::Size(100, 100), true, false,
1807 false);
1808
1809 // Case 1: nothing is clipped except the root render surface.
1810 {
1811 ExecuteCalculateDrawProperties(root);
1812
1813 ASSERT_TRUE(root->render_surface());
1814 ASSERT_TRUE(child2->render_surface());
1815
1816 EXPECT_FALSE(root->is_clipped());
1817 EXPECT_TRUE(root->render_surface()->is_clipped());
1818 EXPECT_FALSE(parent->is_clipped());
1819 EXPECT_FALSE(child1->is_clipped());
1820 EXPECT_FALSE(child2->is_clipped());
1821 EXPECT_FALSE(child2->render_surface()->is_clipped());
1822 EXPECT_FALSE(grand_child->is_clipped());
1823 EXPECT_FALSE(leaf_node1->is_clipped());
1824 EXPECT_FALSE(leaf_node2->is_clipped());
1825 }
1826
1827 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1828 // surface are clipped. But layers that contribute to child2's surface are
1829 // not clipped explicitly because child2's surface already accounts for
1830 // that clip.
1831 {
1832 parent->SetMasksToBounds(true);
enne76bf8982015-08-18 17:55:331833 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1834
1835 ExecuteCalculateDrawProperties(root);
1836
1837 ASSERT_TRUE(root->render_surface());
1838 ASSERT_TRUE(child2->render_surface());
1839
ajumae2b7a5c2015-09-30 21:41:421840 EXPECT_FALSE(root->is_clipped());
enne76bf8982015-08-18 17:55:331841 EXPECT_TRUE(root->render_surface()->is_clipped());
ajumae2b7a5c2015-09-30 21:41:421842 EXPECT_TRUE(parent->is_clipped());
1843 EXPECT_TRUE(child1->is_clipped());
1844 EXPECT_FALSE(child2->is_clipped());
enne76bf8982015-08-18 17:55:331845 EXPECT_TRUE(child2->render_surface()->is_clipped());
ajumae2b7a5c2015-09-30 21:41:421846 EXPECT_TRUE(grand_child->is_clipped());
1847 EXPECT_TRUE(leaf_node1->is_clipped());
1848 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331849
1850 parent->SetMasksToBounds(false);
enne76bf8982015-08-18 17:55:331851 }
1852
1853 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1854 // child2's render surface is not clipped.
1855 {
1856 child2->SetMasksToBounds(true);
enne76bf8982015-08-18 17:55:331857 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1858
1859 ExecuteCalculateDrawProperties(root);
1860
1861 ASSERT_TRUE(root->render_surface());
1862 ASSERT_TRUE(child2->render_surface());
1863
1864 EXPECT_FALSE(root->is_clipped());
[email protected]989386c2013-07-18 21:37:231865 EXPECT_TRUE(root->render_surface()->is_clipped());
1866 EXPECT_FALSE(parent->is_clipped());
1867 EXPECT_FALSE(child1->is_clipped());
1868 EXPECT_TRUE(child2->is_clipped());
1869 EXPECT_FALSE(child2->render_surface()->is_clipped());
1870 EXPECT_FALSE(grand_child->is_clipped());
1871 EXPECT_FALSE(leaf_node1->is_clipped());
1872 EXPECT_TRUE(leaf_node2->is_clipped());
1873 }
[email protected]fb661802013-03-25 01:59:321874}
1875
ajuma51d73f72015-10-19 19:43:581876TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) {
1877 // Tests that when separate surfaces are disabled, is_clipped is true exactly
1878 // when a layer or its ancestor has a clip; in particular, if a layer
1879 // is_clipped, so is its entire subtree (since there are no render surfaces
1880 // that can reset is_clipped).
1881 LayerImpl* root = root_layer();
1882 LayerImpl* parent = AddChild<LayerImpl>(root);
1883 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1884 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1885 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1886 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1887 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1888
1889 root->SetDrawsContent(true);
1890 parent->SetDrawsContent(true);
1891 child1->SetDrawsContent(true);
1892 child2->SetDrawsContent(true);
1893 grand_child->SetDrawsContent(true);
1894 leaf_node1->SetDrawsContent(true);
1895 leaf_node2->SetDrawsContent(true);
1896
1897 const gfx::Transform identity_matrix;
1898
1899 // child1 and grand_child get render surfaces when surfaces are enabled.
1900 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1901 gfx::PointF(), gfx::Size(100, 100), true, false,
1902 true);
1903 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1904 gfx::PointF(), gfx::Size(100, 100), true, false,
1905 false);
1906 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1907 gfx::PointF(), gfx::Size(100, 100), true, false,
1908 true);
1909 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1910 gfx::PointF(), gfx::Size(100, 100), true, false,
1911 false);
1912 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1913 gfx::PointF(), gfx::Size(100, 100), true, false,
1914 true);
1915 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1916 gfx::PointF(), gfx::Size(100, 100), true, false,
1917 false);
1918 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1919 gfx::PointF(), gfx::Size(100, 100), true, false,
1920 false);
1921
1922 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with
1923 // or without surfaces.
weiliangcc154ce22015-12-09 03:39:261924 root->SetHasRenderSurface(true);
1925 child1->SetHasRenderSurface(true);
1926 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:581927 ExecuteCalculateDrawProperties(root);
1928 EXPECT_FALSE(root->is_clipped());
1929 EXPECT_FALSE(parent->is_clipped());
1930 EXPECT_FALSE(child1->is_clipped());
1931 EXPECT_FALSE(child2->is_clipped());
1932 EXPECT_FALSE(grand_child->is_clipped());
1933 EXPECT_FALSE(leaf_node1->is_clipped());
1934 EXPECT_FALSE(leaf_node2->is_clipped());
1935
1936 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1937 EXPECT_FALSE(root->is_clipped());
1938 EXPECT_FALSE(parent->is_clipped());
1939 EXPECT_FALSE(child1->is_clipped());
1940 EXPECT_FALSE(child2->is_clipped());
1941 EXPECT_FALSE(grand_child->is_clipped());
1942 EXPECT_FALSE(leaf_node1->is_clipped());
1943 EXPECT_FALSE(leaf_node2->is_clipped());
1944
1945 // Case 2: The root is clipped. With surfaces, this only persists until the
1946 // next render surface. Without surfaces, the entire tree is clipped.
1947 root->SetMasksToBounds(true);
1948 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:261949 root->SetHasRenderSurface(true);
1950 child1->SetHasRenderSurface(true);
1951 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:581952 ExecuteCalculateDrawProperties(root);
1953 EXPECT_TRUE(root->is_clipped());
1954 EXPECT_TRUE(parent->is_clipped());
1955 EXPECT_FALSE(child1->is_clipped());
1956 EXPECT_TRUE(child2->is_clipped());
1957 EXPECT_FALSE(grand_child->is_clipped());
1958 EXPECT_FALSE(leaf_node1->is_clipped());
1959 EXPECT_TRUE(leaf_node2->is_clipped());
1960
1961 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1962 EXPECT_TRUE(root->is_clipped());
1963 EXPECT_TRUE(parent->is_clipped());
1964 EXPECT_TRUE(child1->is_clipped());
1965 EXPECT_TRUE(child2->is_clipped());
1966 EXPECT_TRUE(grand_child->is_clipped());
1967 EXPECT_TRUE(leaf_node1->is_clipped());
1968 EXPECT_TRUE(leaf_node2->is_clipped());
1969
1970 root->SetMasksToBounds(false);
1971
1972 // Case 3: The parent is clipped. Again, with surfaces, this only persists
1973 // until the next render surface. Without surfaces, parent's entire subtree is
1974 // clipped.
1975 parent->SetMasksToBounds(true);
1976 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:261977 root->SetHasRenderSurface(true);
1978 child1->SetHasRenderSurface(true);
1979 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:581980 ExecuteCalculateDrawProperties(root);
1981 EXPECT_FALSE(root->is_clipped());
1982 EXPECT_TRUE(parent->is_clipped());
1983 EXPECT_FALSE(child1->is_clipped());
1984 EXPECT_TRUE(child2->is_clipped());
1985 EXPECT_FALSE(grand_child->is_clipped());
1986 EXPECT_FALSE(leaf_node1->is_clipped());
1987 EXPECT_TRUE(leaf_node2->is_clipped());
1988
1989 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1990 EXPECT_FALSE(root->is_clipped());
1991 EXPECT_TRUE(parent->is_clipped());
1992 EXPECT_TRUE(child1->is_clipped());
1993 EXPECT_TRUE(child2->is_clipped());
1994 EXPECT_TRUE(grand_child->is_clipped());
1995 EXPECT_TRUE(leaf_node1->is_clipped());
1996 EXPECT_TRUE(leaf_node2->is_clipped());
1997
1998 parent->SetMasksToBounds(false);
1999
2000 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it
2001 // has no non-surface children. Without surfaces, child1's entire subtree is
2002 // clipped.
2003 child1->SetMasksToBounds(true);
2004 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262005 root->SetHasRenderSurface(true);
2006 child1->SetHasRenderSurface(true);
2007 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582008 ExecuteCalculateDrawProperties(root);
2009 EXPECT_FALSE(root->is_clipped());
2010 EXPECT_FALSE(parent->is_clipped());
2011 EXPECT_TRUE(child1->is_clipped());
2012 EXPECT_FALSE(child2->is_clipped());
2013 EXPECT_FALSE(grand_child->is_clipped());
2014 EXPECT_FALSE(leaf_node1->is_clipped());
2015 EXPECT_FALSE(leaf_node2->is_clipped());
2016
2017 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2018 EXPECT_FALSE(root->is_clipped());
2019 EXPECT_FALSE(parent->is_clipped());
2020 EXPECT_TRUE(child1->is_clipped());
2021 EXPECT_FALSE(child2->is_clipped());
2022 EXPECT_TRUE(grand_child->is_clipped());
2023 EXPECT_TRUE(leaf_node1->is_clipped());
2024 EXPECT_FALSE(leaf_node2->is_clipped());
2025
2026 child1->SetMasksToBounds(false);
2027
2028 // Case 5: Only the leaf nodes are clipped. The behavior with and without
2029 // surfaces is the same.
2030 leaf_node1->SetMasksToBounds(true);
2031 leaf_node2->SetMasksToBounds(true);
2032 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262033 root->SetHasRenderSurface(true);
2034 child1->SetHasRenderSurface(true);
2035 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582036 ExecuteCalculateDrawProperties(root);
2037 EXPECT_FALSE(root->is_clipped());
2038 EXPECT_FALSE(parent->is_clipped());
2039 EXPECT_FALSE(child1->is_clipped());
2040 EXPECT_FALSE(child2->is_clipped());
2041 EXPECT_FALSE(grand_child->is_clipped());
2042 EXPECT_TRUE(leaf_node1->is_clipped());
2043 EXPECT_TRUE(leaf_node2->is_clipped());
2044
2045 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2046 EXPECT_FALSE(root->is_clipped());
2047 EXPECT_FALSE(parent->is_clipped());
2048 EXPECT_FALSE(child1->is_clipped());
2049 EXPECT_FALSE(child2->is_clipped());
2050 EXPECT_FALSE(grand_child->is_clipped());
2051 EXPECT_TRUE(leaf_node1->is_clipped());
2052 EXPECT_TRUE(leaf_node2->is_clipped());
2053}
2054
[email protected]fd9a3b6d2013-08-03 00:46:172055TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:322056 // Verify that layers get the appropriate DrawableContentRect when their
2057 // parent masksToBounds is true.
2058 //
2059 // grand_child1 - completely inside the region; DrawableContentRect should
2060 // be the layer rect expressed in target space.
2061 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
2062 // will be the intersection of layer bounds and the mask region.
2063 // grand_child3 - partially clipped and masksToBounds; the
2064 // DrawableContentRect will still be the intersection of layer bounds and
2065 // the mask region.
2066 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2067 // be empty.
[email protected]fb661802013-03-25 01:59:322068
2069 const gfx::Transform identity_matrix;
enne07405c772015-08-18 17:56:452070 LayerImpl* parent = root_layer();
2071 LayerImpl* child = AddChild<LayerImpl>(parent);
2072 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362073 grand_child1->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452074 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362075 grand_child2->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452076 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362077 grand_child3->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452078 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362079 grand_child4->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322080
enne07405c772015-08-18 17:56:452081 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2082 gfx::PointF(), gfx::Size(500, 500), true, false,
2083 true);
2084 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2085 gfx::PointF(), gfx::Size(20, 20), true, false,
2086 true);
2087 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2088 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
2089 false, false);
2090 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2091 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2092 false, false);
2093 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2094 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2095 false, false);
2096 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
2097 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
2098 false, false);
[email protected]fb661802013-03-25 01:59:322099
2100 child->SetMasksToBounds(true);
2101 grand_child3->SetMasksToBounds(true);
2102
enne07405c772015-08-18 17:56:452103 // Force child to be a render surface.
[email protected]fb661802013-03-25 01:59:322104 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:322105
enne07405c772015-08-18 17:56:452106 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322107
hush6b614212014-12-04 22:37:322108 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2109 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2110 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322111 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2112}
2113
[email protected]989386c2013-07-18 21:37:232114TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322115 // Verify that render surfaces (and their layers) get the appropriate
2116 // clip rects when their parent masksToBounds is true.
2117 //
2118 // Layers that own render surfaces (at least for now) do not inherit any
2119 // clipping; instead the surface will enforce the clip for the entire subtree.
2120 // They may still have a clip rect of their own layer bounds, however, if
2121 // masksToBounds was true.
weiliangcfb3d5eaa2015-07-28 23:54:572122 LayerImpl* parent = root_layer();
2123 LayerImpl* child = AddChildToRoot<LayerImpl>();
2124 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2125 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2126 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2127 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
[email protected]fb661802013-03-25 01:59:322128 // the leaf nodes ensure that these grand_children become render surfaces for
2129 // this test.
weiliangcfb3d5eaa2015-07-28 23:54:572130 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
2131 leaf_node1->SetDrawsContent(true);
2132 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
2133 leaf_node2->SetDrawsContent(true);
2134 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
2135 leaf_node3->SetDrawsContent(true);
2136 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
2137 leaf_node4->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322138
weiliangcfb3d5eaa2015-07-28 23:54:572139 const gfx::Transform identity_matrix;
2140
2141 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2142 gfx::PointF(), gfx::Size(500, 500), true, false,
2143 true);
2144 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2145 gfx::PointF(), gfx::Size(20, 20), true, false,
2146 true);
2147 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2148 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
2149 false, true);
2150 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2151 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2152 false, true);
2153 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2154 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2155 false, true);
2156 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
2157 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
2158 false, true);
2159 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2160 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322161 false);
weiliangcfb3d5eaa2015-07-28 23:54:572162 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2163 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322164 false);
weiliangcfb3d5eaa2015-07-28 23:54:572165 SetLayerPropertiesForTesting(leaf_node3, identity_matrix, gfx::Point3F(),
2166 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322167 false);
weiliangcfb3d5eaa2015-07-28 23:54:572168 SetLayerPropertiesForTesting(leaf_node4, identity_matrix, gfx::Point3F(),
2169 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322170 false);
2171
2172 child->SetMasksToBounds(true);
2173 grand_child3->SetMasksToBounds(true);
2174 grand_child4->SetMasksToBounds(true);
2175
2176 // Force everyone to be a render surface.
2177 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:322178 grand_child1->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322179 grand_child2->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322180 grand_child3->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322181 grand_child4->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322182
weiliangcfb3d5eaa2015-07-28 23:54:572183 ExecuteCalculateDrawProperties(parent);
2184
[email protected]fb661802013-03-25 01:59:322185 ASSERT_TRUE(grand_child1->render_surface());
2186 ASSERT_TRUE(grand_child2->render_surface());
2187 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322188
2189 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2190 // masksToBounds.
hush6b614212014-12-04 22:37:322191 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2192 grand_child1->render_surface()->clip_rect());
2193 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2194 grand_child2->render_surface()->clip_rect());
2195 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2196 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322197}
2198
ajuma51d73f72015-10-19 19:43:582199TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) {
2200 // Tests that when separate surfaces are disabled, a layer's clip_rect is the
2201 // intersection of all ancestor clips in screen space; in particular, if a
2202 // layer masks to bounds, it contributes to the clip_rect of all layers in its
2203 // subtree (since there are no render surfaces that can reset the clip_rect).
2204 LayerImpl* root = root_layer();
2205 LayerImpl* parent = AddChild<LayerImpl>(root);
2206 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2207 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2208 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2209 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2210 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2211
2212 root->SetDrawsContent(true);
2213 parent->SetDrawsContent(true);
2214 child1->SetDrawsContent(true);
2215 child2->SetDrawsContent(true);
2216 grand_child->SetDrawsContent(true);
2217 leaf_node1->SetDrawsContent(true);
2218 leaf_node2->SetDrawsContent(true);
2219
2220 const gfx::Transform identity_matrix;
2221
2222 // child1 and grand_child get render surfaces when surfaces are enabled.
2223 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:262224 gfx::PointF(), gfx::Size(100, 100), true, false);
ajuma51d73f72015-10-19 19:43:582225 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2226 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
weiliangcc154ce22015-12-09 03:39:262227 false);
ajuma51d73f72015-10-19 19:43:582228 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2229 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
weiliangcc154ce22015-12-09 03:39:262230 false);
ajuma51d73f72015-10-19 19:43:582231 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2232 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
weiliangcc154ce22015-12-09 03:39:262233 false);
ajuma51d73f72015-10-19 19:43:582234 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2235 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
weiliangcc154ce22015-12-09 03:39:262236 true, false);
ajuma51d73f72015-10-19 19:43:582237 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2238 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
weiliangcc154ce22015-12-09 03:39:262239 true, false);
ajuma51d73f72015-10-19 19:43:582240 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2241 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
weiliangcc154ce22015-12-09 03:39:262242 true, false);
ajuma51d73f72015-10-19 19:43:582243
2244 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its
2245 // bounds in target space. The only thing that changes when surfaces are
2246 // disabled is that target space is always screen space.
weiliangcc154ce22015-12-09 03:39:262247 root->SetForceRenderSurface(true);
2248 child1->SetForceRenderSurface(true);
2249 grand_child->SetForceRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582250 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262251 EXPECT_TRUE(root->has_render_surface());
2252 EXPECT_FALSE(parent->has_render_surface());
2253 EXPECT_TRUE(child1->has_render_surface());
2254 EXPECT_FALSE(child2->has_render_surface());
2255 EXPECT_TRUE(grand_child->has_render_surface());
2256 EXPECT_FALSE(leaf_node1->has_render_surface());
2257 EXPECT_FALSE(leaf_node2->has_render_surface());
ajuma51d73f72015-10-19 19:43:582258 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2259 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2260 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2261 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->clip_rect());
2262 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child->clip_rect());
2263 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node1->clip_rect());
2264 EXPECT_EQ(gfx::Rect(14, 14, 2000, 2000), leaf_node2->clip_rect());
2265
2266 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2267 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2268 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2269 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->clip_rect());
2270 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->clip_rect());
2271 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), grand_child->clip_rect());
2272 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->clip_rect());
2273 EXPECT_EQ(gfx::Rect(14, 14, 2000, 2000), leaf_node2->clip_rect());
2274
2275 // Case 2: The root is clipped. In this case, layers that draw into the root
2276 // render surface are clipped by the root's bounds.
2277 root->SetMasksToBounds(true);
2278 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262279 root->SetForceRenderSurface(true);
2280 child1->SetForceRenderSurface(true);
2281 grand_child->SetForceRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582282 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262283 EXPECT_TRUE(root->has_render_surface());
2284 EXPECT_FALSE(parent->has_render_surface());
2285 EXPECT_TRUE(child1->has_render_surface());
2286 EXPECT_FALSE(child2->has_render_surface());
2287 EXPECT_TRUE(grand_child->has_render_surface());
2288 EXPECT_FALSE(leaf_node1->has_render_surface());
2289 EXPECT_FALSE(leaf_node2->has_render_surface());
ajuma51d73f72015-10-19 19:43:582290 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2291 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2292 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2293 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2294 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child->clip_rect());
2295 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node1->clip_rect());
2296 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2297
2298 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2299 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2300 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2301 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect());
2302 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2303 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect());
2304 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect());
2305 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2306
2307 root->SetMasksToBounds(false);
2308
2309 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the
2310 // parent clip rect only contributes to the subtree rooted at child2, since
2311 // the subtree rooted at child1 renders into a separate surface. Similarly,
2312 // child1's clip rect doesn't contribute to its descendants, since its only
2313 // child is a render surface. However, without surfaces, these clip rects
2314 // contribute to all descendants.
2315 parent->SetMasksToBounds(true);
2316 child1->SetMasksToBounds(true);
2317 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262318 root->SetForceRenderSurface(true);
2319 child1->SetForceRenderSurface(true);
2320 grand_child->SetForceRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582321 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262322 EXPECT_TRUE(root->has_render_surface());
2323 EXPECT_FALSE(parent->has_render_surface());
2324 EXPECT_TRUE(child1->has_render_surface());
2325 EXPECT_FALSE(child2->has_render_surface());
2326 EXPECT_TRUE(grand_child->has_render_surface());
2327 EXPECT_FALSE(leaf_node1->has_render_surface());
2328 EXPECT_FALSE(leaf_node2->has_render_surface());
ajuma51d73f72015-10-19 19:43:582329 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2330 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2331 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2332 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2333 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child->clip_rect());
2334 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node1->clip_rect());
2335 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2336
2337 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2338 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2339 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2340 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect());
2341 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2342 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect());
2343 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect());
2344 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2345}
2346
2347TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) {
2348 // Tests that draw properties are computed correctly when we disable and then
2349 // re-enable separate surfaces.
2350 LayerImpl* root = root_layer();
2351 LayerImpl* parent = AddChild<LayerImpl>(root);
2352 LayerImpl* child = AddChild<LayerImpl>(parent);
2353 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2354 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2355
2356 root->SetDrawsContent(true);
2357 parent->SetDrawsContent(true);
2358 child->SetDrawsContent(true);
2359 grand_child->SetDrawsContent(true);
2360 leaf_node->SetDrawsContent(true);
2361
2362 const gfx::Transform identity_matrix;
2363
2364 // child and grand_child get render surfaces when surfaces are enabled.
2365 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2366 gfx::PointF(), gfx::Size(100, 100), true, false,
2367 true);
2368 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2369 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2370 false, false);
2371 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2372 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2373 false, true);
2374 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2375 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2376 true, false, true);
2377 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
2378 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2379 true, false, false);
2380
2381 parent->SetMasksToBounds(true);
2382 child->SetMasksToBounds(true);
2383
weiliangcc154ce22015-12-09 03:39:262384 root->SetHasRenderSurface(true);
2385 child->SetHasRenderSurface(true);
2386 grand_child->SetHasRenderSurface(true);
2387
ajuma51d73f72015-10-19 19:43:582388 gfx::Transform expected_leaf_draw_transform_with_surfaces;
2389 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0);
2390
2391 gfx::Transform expected_leaf_draw_transform_without_surfaces;
2392 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0);
2393
2394 ExecuteCalculateDrawProperties(root);
2395 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->clip_rect());
2396 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2397 EXPECT_EQ(expected_leaf_draw_transform_with_surfaces,
ajumad9432e32015-11-30 19:43:442398 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582399
weiliangcc154ce22015-12-09 03:39:262400 root->SetHasRenderSurface(true);
2401 child->SetHasRenderSurface(true);
2402 grand_child->SetHasRenderSurface(true);
2403
ajuma51d73f72015-10-19 19:43:582404 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2405 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect());
2406 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect());
2407 EXPECT_EQ(expected_leaf_draw_transform_without_surfaces,
ajumad9432e32015-11-30 19:43:442408 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582409
weiliangcc154ce22015-12-09 03:39:262410 root->SetHasRenderSurface(true);
2411 child->SetHasRenderSurface(true);
2412 grand_child->SetHasRenderSurface(true);
2413
ajuma51d73f72015-10-19 19:43:582414 ExecuteCalculateDrawProperties(root);
2415 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->clip_rect());
2416 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2417 EXPECT_EQ(expected_leaf_draw_transform_with_surfaces,
ajumad9432e32015-11-30 19:43:442418 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582419}
2420
[email protected]989386c2013-07-18 21:37:232421TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
enneab0fee42015-07-07 17:36:422422 LayerImpl* parent = root_layer();
2423 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2424 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
2425 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
2426 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2427 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2428 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2429 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2430 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
[email protected]fb661802013-03-25 01:59:322431
jaydasika8640f9f2015-11-10 01:34:362432 parent->SetDrawsContent(true);
2433 render_surface1->SetDrawsContent(true);
2434 child_of_rs1->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422435 grand_child_of_rs1->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362436 render_surface2->SetDrawsContent(true);
2437 child_of_rs2->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422438 grand_child_of_rs2->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362439 child_of_root->SetDrawsContent(true);
2440 grand_child_of_root->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322441
2442 gfx::Transform layer_transform;
2443 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322444
enneab0fee42015-07-07 17:36:422445 SetLayerPropertiesForTesting(
2446 parent, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2447 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2448 SetLayerPropertiesForTesting(
2449 render_surface1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2450 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2451 SetLayerPropertiesForTesting(
2452 render_surface2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2453 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2454 SetLayerPropertiesForTesting(
2455 child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2456 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2457 SetLayerPropertiesForTesting(
2458 child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2459 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2460 SetLayerPropertiesForTesting(
2461 child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2462 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2463 SetLayerPropertiesForTesting(
2464 grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2465 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2466 SetLayerPropertiesForTesting(
2467 grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2468 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2469 SetLayerPropertiesForTesting(
2470 grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2471 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
[email protected]fb661802013-03-25 01:59:322472
loyso968163c92016-01-04 23:18:482473 if (layer_settings().use_compositor_animation_timelines) {
2474 // Put an animated opacity on the render surface.
2475 AddOpacityTransitionToLayerWithPlayer(
2476 render_surface1->id(), timeline_impl(), 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322477
loyso968163c92016-01-04 23:18:482478 // Also put an animated opacity on a layer without descendants.
2479 AddOpacityTransitionToLayerWithPlayer(
2480 grand_child_of_root->id(), timeline_impl(), 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322481
loyso968163c92016-01-04 23:18:482482 // Put a transform animation on the render surface.
2483 AddAnimatedTransformToLayerWithPlayer(render_surface2->id(),
2484 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322485
loyso968163c92016-01-04 23:18:482486 // Also put transform animations on grand_child_of_root, and
2487 // grand_child_of_rs2
2488 AddAnimatedTransformToLayerWithPlayer(grand_child_of_root->id(),
2489 timeline_impl(), 10.0, 30, 0);
2490 AddAnimatedTransformToLayerWithPlayer(grand_child_of_rs2->id(),
2491 timeline_impl(), 10.0, 30, 0);
2492 } else {
2493 // Put an animated opacity on the render surface.
2494 AddOpacityTransitionToController(
2495 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2496
2497 // Also put an animated opacity on a layer without descendants.
2498 AddOpacityTransitionToController(
2499 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f,
2500 false);
2501
2502 // Put a transform animation on the render surface.
2503 AddAnimatedTransformToController(
2504 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2505
2506 // Also put transform animations on grand_child_of_root, and
2507 // grand_child_of_rs2
2508 AddAnimatedTransformToController(
2509 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2510 AddAnimatedTransformToController(
2511 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2512 }
[email protected]fb661802013-03-25 01:59:322513
enneab0fee42015-07-07 17:36:422514 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322515
2516 // Only layers that are associated with render surfaces should have an actual
2517 // RenderSurface() value.
2518 ASSERT_TRUE(parent->render_surface());
2519 ASSERT_FALSE(child_of_root->render_surface());
2520 ASSERT_FALSE(grand_child_of_root->render_surface());
2521
2522 ASSERT_TRUE(render_surface1->render_surface());
2523 ASSERT_FALSE(child_of_rs1->render_surface());
2524 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2525
2526 ASSERT_TRUE(render_surface2->render_surface());
2527 ASSERT_FALSE(child_of_rs2->render_surface());
2528 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2529
2530 // Verify all render target accessors
enneab0fee42015-07-07 17:36:422531 EXPECT_EQ(parent, parent->render_target());
2532 EXPECT_EQ(parent, child_of_root->render_target());
2533 EXPECT_EQ(parent, grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322534
enneab0fee42015-07-07 17:36:422535 EXPECT_EQ(render_surface1, render_surface1->render_target());
2536 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
2537 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322538
enneab0fee42015-07-07 17:36:422539 EXPECT_EQ(render_surface2, render_surface2->render_target());
2540 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
2541 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322542
[email protected]fb661802013-03-25 01:59:322543 // Verify screen_space_transform_is_animating values
2544 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2545 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2546 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2547 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322548 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2549 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2550 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322551 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2552 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2553
2554 // Sanity check. If these fail there is probably a bug in the test itself.
2555 // It is expected that we correctly set up transforms so that the y-component
2556 // of the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:102557 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:262558 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102559 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322560 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102561 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322562
[email protected]803f6b52013-09-12 00:51:262563 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102564 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
2565 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322566 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102567 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322568
[email protected]803f6b52013-09-12 00:51:262569 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:102570 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
2571 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322572 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102573 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322574}
2575
ajuma9384b9c22015-09-17 20:35:032576TEST_F(LayerTreeHostCommonTest, LargeTransforms) {
2577 LayerImpl* parent = root_layer();
2578 LayerImpl* child = AddChildToRoot<LayerImpl>();
2579 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2580
2581 grand_child->SetDrawsContent(true);
2582
2583 gfx::Transform large_transform;
2584 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2585
2586 gfx::Transform identity;
2587
2588 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(),
2589 gfx::Size(10, 10), true, false, true);
2590 SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(),
2591 gfx::PointF(), gfx::Size(10, 10), true, false,
2592 false);
2593 SetLayerPropertiesForTesting(grand_child, large_transform, gfx::Point3F(),
2594 gfx::PointF(), gfx::Size(10, 10), true, false,
2595 false);
2596 ExecuteCalculateDrawProperties(parent);
2597
2598 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
2599}
2600
ajuma315a4782015-07-24 21:16:342601TEST_F(LayerTreeHostCommonTest,
2602 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
2603 LayerImpl* parent = root_layer();
2604 LayerImpl* child = AddChild<LayerImpl>(parent);
2605 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2606 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2607
2608 parent->SetDrawsContent(true);
2609 child->SetDrawsContent(true);
2610 grand_child->SetDrawsContent(true);
2611 great_grand_child->SetDrawsContent(true);
2612
2613 gfx::Transform identity;
2614
2615 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(),
2616 gfx::Size(10, 10), true, false, true);
2617 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
2618 gfx::Size(10, 10), true, false, false);
2619 SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(),
2620 gfx::PointF(), gfx::Size(10, 10), true, false,
2621 false);
2622 SetLayerPropertiesForTesting(great_grand_child, identity, gfx::Point3F(),
2623 gfx::PointF(), gfx::Size(10, 10), true, false,
2624 false);
2625
2626 // Add a transform animation with a start delay to |grand_child|.
2627 scoped_ptr<Animation> animation = Animation::Create(
danakja5a05ba02015-11-20 20:14:212628 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1,
ajuma315a4782015-07-24 21:16:342629 Animation::TRANSFORM);
2630 animation->set_fill_mode(Animation::FILL_MODE_NONE);
2631 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso968163c92016-01-04 23:18:482632 if (layer_settings().use_compositor_animation_timelines) {
2633 AddAnimationToLayerWithPlayer(grand_child->id(), timeline_impl(),
2634 std::move(animation));
2635 } else {
2636 grand_child->layer_animation_controller()->AddAnimation(
2637 std::move(animation));
2638 }
ajuma315a4782015-07-24 21:16:342639 ExecuteCalculateDrawProperties(parent);
2640
2641 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2642 EXPECT_FALSE(child->screen_space_transform_is_animating());
2643
2644 EXPECT_FALSE(grand_child->TransformIsAnimating());
2645 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2646 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2647 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2648}
2649
[email protected]989386c2013-07-18 21:37:232650TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322651 // Test the calculateVisibleRect() function works correctly for identity
2652 // transforms.
2653
[email protected]2c7c6702013-03-26 03:14:052654 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322655 gfx::Transform layer_to_surface_transform;
2656
2657 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232658 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052659 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322660 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2661 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322662 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322663
2664 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052665 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322666 actual = LayerTreeHostCommon::CalculateVisibleRect(
2667 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2668 EXPECT_TRUE(actual.IsEmpty());
2669
2670 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052671 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2672 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322673 actual = LayerTreeHostCommon::CalculateVisibleRect(
2674 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322675 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322676}
2677
[email protected]989386c2013-07-18 21:37:232678TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322679 // Test the calculateVisibleRect() function works correctly for scaling
2680 // transforms.
2681
[email protected]2c7c6702013-03-26 03:14:052682 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2683 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322684 gfx::Transform layer_to_surface_transform;
2685
2686 // Case 1: Layer is contained within the surface.
2687 layer_to_surface_transform.MakeIdentity();
2688 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052689 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322690 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2691 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322692 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322693
2694 // Case 2: Layer is outside the surface rect.
2695 layer_to_surface_transform.MakeIdentity();
2696 layer_to_surface_transform.Translate(120.0, 120.0);
2697 actual = LayerTreeHostCommon::CalculateVisibleRect(
2698 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2699 EXPECT_TRUE(actual.IsEmpty());
2700
2701 // Case 3: Layer is partially overlapping the surface rect.
2702 layer_to_surface_transform.MakeIdentity();
2703 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052704 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322705 actual = LayerTreeHostCommon::CalculateVisibleRect(
2706 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322707 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322708}
2709
[email protected]989386c2013-07-18 21:37:232710TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322711 // Test the calculateVisibleRect() function works correctly for rotations
2712 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2713 // should return the g in the layer's space.
2714
[email protected]2c7c6702013-03-26 03:14:052715 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2716 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322717 gfx::Transform layer_to_surface_transform;
2718
2719 // Case 1: Layer is contained within the surface.
2720 layer_to_surface_transform.MakeIdentity();
2721 layer_to_surface_transform.Translate(50.0, 50.0);
2722 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052723 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322724 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2725 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322726 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322727
2728 // Case 2: Layer is outside the surface rect.
2729 layer_to_surface_transform.MakeIdentity();
2730 layer_to_surface_transform.Translate(-50.0, 0.0);
2731 layer_to_surface_transform.Rotate(45.0);
2732 actual = LayerTreeHostCommon::CalculateVisibleRect(
2733 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2734 EXPECT_TRUE(actual.IsEmpty());
2735
2736 // Case 3: The layer is rotated about its top-left corner. In surface space,
2737 // the layer is oriented diagonally, with the left half outside of the render
2738 // surface. In this case, the g should still be the entire layer
2739 // (remember the g is computed in layer space); both the top-left
2740 // and bottom-right corners of the layer are still visible.
2741 layer_to_surface_transform.MakeIdentity();
2742 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052743 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322744 actual = LayerTreeHostCommon::CalculateVisibleRect(
2745 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322746 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322747
2748 // Case 4: The layer is rotated about its top-left corner, and translated
2749 // upwards. In surface space, the layer is oriented diagonally, with only the
2750 // top corner of the surface overlapping the layer. In layer space, the render
2751 // surface overlaps the right side of the layer. The g should be
2752 // the layer's right half.
2753 layer_to_surface_transform.MakeIdentity();
2754 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2755 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052756 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322757 actual = LayerTreeHostCommon::CalculateVisibleRect(
2758 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322759 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322760}
2761
[email protected]989386c2013-07-18 21:37:232762TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322763 // Test that the calculateVisibleRect() function works correctly for 3d
2764 // transforms.
2765
[email protected]2c7c6702013-03-26 03:14:052766 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2767 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322768 gfx::Transform layer_to_surface_transform;
2769
2770 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2771 // degrees, should be fully contained in the render surface.
2772 layer_to_surface_transform.MakeIdentity();
2773 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052774 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322775 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2776 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322777 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322778
2779 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2780 // degrees, but shifted to the side so only the right-half the layer would be
2781 // visible on the surface.
2782 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262783 SkMScalar half_width_of_rotated_layer =
2784 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322785 layer_to_surface_transform.MakeIdentity();
2786 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232787 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2788 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052789 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322790 actual = LayerTreeHostCommon::CalculateVisibleRect(
2791 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322792 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322793}
2794
[email protected]989386c2013-07-18 21:37:232795TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322796 // Test the calculateVisibleRect() function works correctly when the layer has
2797 // a perspective projection onto the target surface.
2798
[email protected]2c7c6702013-03-26 03:14:052799 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2800 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322801 gfx::Transform layer_to_surface_transform;
2802
2803 // Case 1: Even though the layer is twice as large as the surface, due to
2804 // perspective foreshortening, the layer will fit fully in the surface when
2805 // its translated more than the perspective amount.
2806 layer_to_surface_transform.MakeIdentity();
2807
2808 // The following sequence of transforms applies the perspective about the
2809 // center of the surface.
2810 layer_to_surface_transform.Translate(50.0, 50.0);
2811 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2812 layer_to_surface_transform.Translate(-50.0, -50.0);
2813
2814 // This translate places the layer in front of the surface's projection plane.
2815 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2816
[email protected]2c7c6702013-03-26 03:14:052817 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322818 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2819 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322820 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322821
2822 // Case 2: same projection as before, except that the layer is also translated
2823 // to the side, so that only the right half of the layer should be visible.
2824 //
2825 // Explanation of expected result: The perspective ratio is (z distance
2826 // between layer and camera origin) / (z distance between projection plane and
2827 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2828 // move a layer by translating -50 units in projected surface units (so that
2829 // only half of it is visible), then we would need to translate by (-36 / 9) *
2830 // -50 == -200 in the layer's units.
2831 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232832 expected = gfx::Rect(gfx::Point(50, -50),
2833 gfx::Size(100, 200)); // The right half of the layer's
2834 // bounding rect.
[email protected]fb661802013-03-25 01:59:322835 actual = LayerTreeHostCommon::CalculateVisibleRect(
2836 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322837 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322838}
2839
[email protected]989386c2013-07-18 21:37:232840TEST_F(LayerTreeHostCommonTest,
2841 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322842 // There is currently no explicit concept of an orthographic projection plane
2843 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2844 // are technically behind the surface in an orthographic world should not be
2845 // clipped when they are flattened to the surface.
2846
[email protected]2c7c6702013-03-26 03:14:052847 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2848 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322849 gfx::Transform layer_to_surface_transform;
2850
2851 // This sequence of transforms effectively rotates the layer about the y-axis
2852 // at the center of the layer.
2853 layer_to_surface_transform.MakeIdentity();
2854 layer_to_surface_transform.Translate(50.0, 0.0);
2855 layer_to_surface_transform.RotateAboutYAxis(45.0);
2856 layer_to_surface_transform.Translate(-50.0, 0.0);
2857
[email protected]2c7c6702013-03-26 03:14:052858 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322859 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2860 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322861 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322862}
2863
[email protected]989386c2013-07-18 21:37:232864TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322865 // Test the calculateVisibleRect() function works correctly when projecting a
2866 // surface onto a layer, but the layer is partially behind the camera (not
2867 // just behind the projection plane). In this case, the cartesian coordinates
2868 // may seem to be valid, but actually they are not. The visible rect needs to
2869 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2870 // converting to cartesian coordinates.
2871
[email protected]2c7c6702013-03-26 03:14:052872 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232873 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322874 gfx::Transform layer_to_surface_transform;
2875
2876 // The layer is positioned so that the right half of the layer should be in
2877 // front of the camera, while the other half is behind the surface's
2878 // projection plane. The following sequence of transforms applies the
2879 // perspective and rotation about the center of the layer.
2880 layer_to_surface_transform.MakeIdentity();
2881 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2882 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2883 layer_to_surface_transform.RotateAboutYAxis(45.0);
2884
2885 // Sanity check that this transform does indeed cause w < 0 when applying the
2886 // transform, otherwise this code is not testing the intended scenario.
2887 bool clipped;
2888 MathUtil::MapQuad(layer_to_surface_transform,
2889 gfx::QuadF(gfx::RectF(layer_content_rect)),
2890 &clipped);
2891 ASSERT_TRUE(clipped);
2892
2893 int expected_x_position = 0;
2894 int expected_width = 10;
2895 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2896 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2897 EXPECT_EQ(expected_x_position, actual.x());
2898 EXPECT_EQ(expected_width, actual.width());
2899}
2900
[email protected]989386c2013-07-18 21:37:232901TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322902 // To determine visible rect in layer space, there needs to be an
2903 // un-projection from surface space to layer space. When the original
2904 // transform was a perspective projection that was clipped, it returns a rect
2905 // that encloses the clipped bounds. Un-projecting this new rect may require
2906 // clipping again.
2907
2908 // This sequence of transforms causes one corner of the layer to protrude
2909 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232910 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2911 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322912 gfx::Transform layer_to_surface_transform;
2913 layer_to_surface_transform.MakeIdentity();
2914 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2915 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2916 layer_to_surface_transform.RotateAboutYAxis(45.0);
2917 layer_to_surface_transform.RotateAboutXAxis(80.0);
2918
2919 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2920 // code is not testing the intended scenario.
2921 bool clipped;
danakj5e6ff6d2015-09-05 04:43:442922 gfx::RectF clipped_rect = MathUtil::MapClippedRect(
2923 layer_to_surface_transform, gfx::RectF(layer_content_rect));
[email protected]fb661802013-03-25 01:59:322924 MathUtil::ProjectQuad(
2925 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2926 ASSERT_TRUE(clipped);
2927
2928 // Only the corner of the layer is not visible on the surface because of being
2929 // clipped. But, the net result of rounding visible region to an axis-aligned
2930 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052931 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322932 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2933 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322934 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322935}
2936
miletus9d3da522015-06-05 19:45:072937TEST_F(LayerTreeHostCommonTest,
2938 VisibleRectsForPositionedRootLayerClippedByViewport) {
enne6c281f6e2015-08-18 23:23:002939 LayerImpl* root = root_layer();
2940 root->SetDrawsContent(true);
miletus9d3da522015-06-05 19:45:072941
2942 gfx::Transform identity_matrix;
2943 // Root layer is positioned at (60, 70). The default device viewport size
2944 // is (0, 0, 100x100) in target space. So the root layer's visible rect
2945 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
enne6c281f6e2015-08-18 23:23:002946 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
miletus9d3da522015-06-05 19:45:072947 gfx::PointF(60, 70), gfx::Size(100, 100), true,
enne6c281f6e2015-08-18 23:23:002948 false, true);
2949 ExecuteCalculateDrawProperties(root);
miletus9d3da522015-06-05 19:45:072950
danakj5e6ff6d2015-09-05 04:43:442951 EXPECT_EQ(gfx::RectF(100.f, 100.f),
miletus9d3da522015-06-05 19:45:072952 root->render_surface()->DrawableContentRect());
2953 // In target space, not clipped.
2954 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
2955 // In layer space, clipped.
danakj5e6ff6d2015-09-05 04:43:442956 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
miletus9d3da522015-06-05 19:45:072957}
2958
[email protected]989386c2013-07-18 21:37:232959TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
weiliangc0dece732015-07-27 19:06:172960 LayerImpl* root = root_layer();
2961 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
2962 child1_layer->SetDrawsContent(true);
2963 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
2964 child2_layer->SetDrawsContent(true);
2965 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
2966 child3_layer->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:282967
[email protected]fb661802013-03-25 01:59:322968 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:172969 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2970 gfx::PointF(), gfx::Size(100, 100), true, false,
2971 true);
2972 SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(),
2973 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]fb661802013-03-25 01:59:322974 false);
weiliangc0dece732015-07-27 19:06:172975 SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(),
2976 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2977 false, false);
2978 SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(),
2979 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2980 true, false, false);
[email protected]fb661802013-03-25 01:59:322981
weiliangc0dece732015-07-27 19:06:172982 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322983
danakj5e6ff6d2015-09-05 04:43:442984 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:322985 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322986
danakj64767d902015-06-19 00:10:432987 // Layers that do not draw content should have empty visible_layer_rects.
2988 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:322989
danakj64767d902015-06-19 00:10:432990 // layer visible_layer_rects are clipped by their target surface.
weiliangc0dece732015-07-27 19:06:172991 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
2992 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
2993 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:322994
2995 // layer drawable_content_rects are not clipped.
weiliangc0dece732015-07-27 19:06:172996 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
2997 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
2998 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322999}
3000
[email protected]989386c2013-07-18 21:37:233001TEST_F(LayerTreeHostCommonTest,
3002 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
weiliangc0dece732015-07-27 19:06:173003 LayerImpl* root = root_layer();
3004 LayerImpl* child = AddChildToRoot<LayerImpl>();
3005 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
3006 grand_child1->SetDrawsContent(true);
3007 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
3008 grand_child2->SetDrawsContent(true);
3009 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
3010 grand_child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283011
[email protected]fb661802013-03-25 01:59:323012 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173013 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3014 gfx::PointF(), gfx::Size(100, 100), true, false,
3015 true);
3016 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
3017 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]fb661802013-03-25 01:59:323018 false);
weiliangc0dece732015-07-27 19:06:173019 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
3020 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3021 false, false);
3022 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
3023 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3024 false, false);
3025 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
3026 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3027 true, false, false);
[email protected]fb661802013-03-25 01:59:323028
3029 child->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:173030 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323031
danakj5e6ff6d2015-09-05 04:43:443032 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323033 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323034
3035 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433036 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3037 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323038
3039 // All grandchild visible content rects should be clipped by child.
danakj64767d902015-06-19 00:10:433040 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
3041 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
3042 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323043
3044 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:323045 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
3046 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323047 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
3048}
3049
ajuma27442dd2015-03-30 19:19:483050TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
loysoa6edaaff2015-05-25 03:26:443051 scoped_refptr<Layer> root = Layer::Create(layer_settings());
3052 scoped_refptr<Layer> child = Layer::Create(layer_settings());
ajuma27442dd2015-03-30 19:19:483053 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loysoa6edaaff2015-05-25 03:26:443054 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma27442dd2015-03-30 19:19:483055 root->AddChild(child);
3056 child->AddChild(grand_child);
3057
ennea7b43c32015-06-18 20:01:333058 host()->SetRootLayer(root);
ajuma27442dd2015-03-30 19:19:483059
3060 gfx::Transform identity_matrix;
3061 gfx::Transform child_scale_matrix;
3062 child_scale_matrix.Scale(0.25f, 0.25f);
3063 gfx::Transform grand_child_scale_matrix;
3064 grand_child_scale_matrix.Scale(0.246f, 0.246f);
3065 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
3066 gfx::PointF(), gfx::Size(100, 100), true, false);
3067 SetLayerPropertiesForTesting(child.get(), child_scale_matrix, gfx::Point3F(),
3068 gfx::PointF(), gfx::Size(10, 10), true, false);
3069 SetLayerPropertiesForTesting(grand_child.get(), grand_child_scale_matrix,
3070 gfx::Point3F(), gfx::PointF(),
3071 gfx::Size(100, 100), true, false);
3072
3073 child->SetMasksToBounds(true);
enne601f2ef12015-05-19 18:20:173074 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajuma27442dd2015-03-30 19:19:483075
3076 // The visible rect is expanded to integer coordinates in target space before
3077 // being projected back to layer space, where it is once again expanded to
3078 // integer coordinates.
3079 EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_rect_from_property_trees());
3080}
3081
[email protected]989386c2013-07-18 21:37:233082TEST_F(LayerTreeHostCommonTest,
3083 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
weiliangc0dece732015-07-27 19:06:173084 LayerImpl* root = root_layer();
3085 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3086 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3087 child1->SetDrawsContent(true);
3088 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
3089 child2->SetDrawsContent(true);
3090 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
3091 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283092
[email protected]fb661802013-03-25 01:59:323093 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173094 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3095 gfx::PointF(), gfx::Size(100, 100), true, false,
3096 true);
3097 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3098 gfx::PointF(), gfx::Size(3, 4), true, false,
3099 true);
3100 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3101 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3102 false, false);
3103 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3104 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3105 false, false);
3106 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3107 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3108 true, false, false);
[email protected]fb661802013-03-25 01:59:323109
weiliangc0dece732015-07-27 19:06:173110 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323111
weiliangc0dece732015-07-27 19:06:173112 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323113
danakj5e6ff6d2015-09-05 04:43:443114 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323115 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323116
3117 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433118 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173119 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323120
3121 // An unclipped surface grows its DrawableContentRect to include all drawable
3122 // regions of the subtree.
danakj5e6ff6d2015-09-05 04:43:443123 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
weiliangc0dece732015-07-27 19:06:173124 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323125
3126 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:433127 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3128 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3129 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323130
hush6b614212014-12-04 22:37:323131 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3132 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3133 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323134}
3135
[email protected]989386c2013-07-18 21:37:233136TEST_F(LayerTreeHostCommonTest,
ajuma51d73f72015-10-19 19:43:583137 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) {
3138 LayerImpl* root = root_layer();
3139 LayerImpl* parent = AddChild<LayerImpl>(root);
3140 LayerImpl* child1 = AddChild<LayerImpl>(parent);
3141 LayerImpl* child2 = AddChild<LayerImpl>(parent);
3142 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1);
3143 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2);
3144 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
3145 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
3146
3147 root->SetDrawsContent(true);
3148 parent->SetDrawsContent(true);
3149 child1->SetDrawsContent(true);
3150 child2->SetDrawsContent(true);
3151 grand_child1->SetDrawsContent(true);
3152 grand_child2->SetDrawsContent(true);
3153 leaf_node1->SetDrawsContent(true);
3154 leaf_node2->SetDrawsContent(true);
3155
3156 const gfx::Transform identity_matrix;
3157
3158 // child1 and child2 get render surfaces when surfaces are enabled.
3159 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3160 gfx::PointF(), gfx::Size(100, 100), true, false,
3161 true);
3162 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3163 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
3164 false, false);
3165 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3166 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
3167 false, true);
3168 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3169 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
3170 false, true);
3171 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
3172 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
3173 true, false, false);
3174 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
3175 gfx::PointF(7.f, 7.f), gfx::Size(1500, 1500),
3176 true, false, false);
3177 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
3178 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
3179 true, false, false);
3180 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
3181 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
3182 true, false, false);
3183
3184 // Case 1: No layers clip. Visible rects are clipped by the viewport, but the
3185 // viewport clip doesn't apply to layers that draw into unclipped surfaces.
3186 // Each layer's drawable content rect is its bounds in target space; the only
3187 // thing that changes with surfaces disabled is that target space is always
3188 // screen space.
weiliangcc154ce22015-12-09 03:39:263189 root->SetHasRenderSurface(true);
3190 child1->SetHasRenderSurface(true);
3191 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583192 ExecuteCalculateDrawProperties(root);
3193 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3194 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect());
3195 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3196 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3197 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child1->visible_layer_rect());
3198 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3199 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node1->visible_layer_rect());
3200 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node2->visible_layer_rect());
3201
3202 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3203 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3204 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3205 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3206 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3207 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3208 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3209 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3210
3211 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3212 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3213 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3214 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3215 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3216 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3217 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3218 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3219 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3220
3221 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3222 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3223 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3224 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3225 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500),
3226 grand_child1->drawable_content_rect());
3227 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3228 grand_child2->drawable_content_rect());
3229 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect());
3230 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect());
3231
3232 // Case 2: The parent clips. In this case, neither surface is unclipped, so
3233 // all visible layer rects are clipped by the intersection of all ancestor
3234 // clips, whether or not surfaces are disabled. However, drawable content
3235 // rects are clipped only until the next render surface is reached, so
3236 // descendants of parent have their drawable content rects clipped only when
3237 // surfaces are disabled.
3238 parent->SetMasksToBounds(true);
3239 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:263240 root->SetHasRenderSurface(true);
3241 child1->SetHasRenderSurface(true);
3242 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583243 ExecuteCalculateDrawProperties(root);
3244 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3245 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3246 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3247 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3248 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3249 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3250 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3251 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3252
3253 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3254 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3255 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3256 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3257 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3258 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3259 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3260 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3261
3262 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3263 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3264 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3265 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3266 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3267 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3268 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3269 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3270 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3271
3272 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3273 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3274 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect());
3275 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect());
3276 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect());
3277 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect());
3278 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect());
3279 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect());
3280
3281 parent->SetMasksToBounds(false);
3282
3283 // Case 3: child1 and grand_child2 clip. In this case, descendants of these
3284 // layers have their visible rects clipped by them; without surfaces, these
3285 // rects are also clipped by the viewport. Similarly, descendants of these
3286 // layers have their drawable content rects clipped by them.
3287 child1->SetMasksToBounds(true);
3288 grand_child2->SetMasksToBounds(true);
3289 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:263290 root->SetHasRenderSurface(true);
3291 child1->SetHasRenderSurface(true);
3292 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583293 ExecuteCalculateDrawProperties(root);
3294 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3295 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3296 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3297 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3298 EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect());
3299 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3300 EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect());
3301 EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect());
3302
3303 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3304 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3305 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3306 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3307 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect());
3308 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3309 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect());
3310 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect());
3311
3312 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3313 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3314 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3315 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3316 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3317 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3318 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3319 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3320 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3321
3322 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3323 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3324 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3325 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3326 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect());
3327 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3328 grand_child2->drawable_content_rect());
3329 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect());
3330 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect());
3331}
3332
3333TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:023334 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
enne6c281f6e2015-08-18 23:23:003335 LayerImpl* root = root_layer();
3336 LayerImpl* child1 = AddChild<LayerImpl>(root);
3337 LayerImpl* child2 = AddChild<LayerImpl>(root);
3338 LayerImpl* child3 = AddChild<LayerImpl>(root);
3339 child1->SetDrawsContent(true);
3340 child2->SetDrawsContent(true);
3341 child3->SetDrawsContent(true);
hush887bb542014-12-02 22:49:023342
3343 gfx::Transform identity_matrix;
enne6c281f6e2015-08-18 23:23:003344 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3345 gfx::PointF(), gfx::Size(100, 100), true, false,
3346 true);
3347 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023348 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
enne6c281f6e2015-08-18 23:23:003349 false, false);
3350 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023351 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
enne6c281f6e2015-08-18 23:23:003352 false, false);
3353 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023354 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
enne6c281f6e2015-08-18 23:23:003355 true, false, false);
hush887bb542014-12-02 22:49:023356
enne6c281f6e2015-08-18 23:23:003357 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:443358 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
hush887bb542014-12-02 22:49:023359 // Now set the root render surface an empty clip.
enne6c281f6e2015-08-18 23:23:003360 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:443361 root, gfx::Size(), &render_surface_layer_list_impl,
3362 root->layer_tree_impl()->current_render_surface_list_id());
hush887bb542014-12-02 22:49:023363
3364 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
3365 ASSERT_TRUE(root->render_surface());
3366 EXPECT_FALSE(root->is_clipped());
3367
3368 gfx::Rect empty;
3369 EXPECT_EQ(empty, root->render_surface()->clip_rect());
3370 EXPECT_TRUE(root->render_surface()->is_clipped());
3371
3372 // Visible content rect calculation will check if the target surface is
3373 // clipped or not. An empty clip rect does not indicate the render surface
3374 // is unclipped.
danakj64767d902015-06-19 00:10:433375 EXPECT_EQ(empty, child1->visible_layer_rect());
3376 EXPECT_EQ(empty, child2->visible_layer_rect());
3377 EXPECT_EQ(empty, child3->visible_layer_rect());
hush887bb542014-12-02 22:49:023378}
3379
3380TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233381 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
weiliangc0dece732015-07-27 19:06:173382 LayerImpl* root = root_layer();
3383 LayerImpl* child = AddChildToRoot<LayerImpl>();
3384 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283385
[email protected]630ddad2013-08-16 03:01:323386 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473387 gfx::Transform identity_matrix;
3388 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323389 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473390
weiliangc0dece732015-07-27 19:06:173391 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3392 gfx::PointF(), gfx::Size(100, 100), true, false,
3393 true);
3394 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3395 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3396 false, false);
[email protected]451107a32013-04-10 05:12:473397
weiliangc0dece732015-07-27 19:06:173398 ExecuteCalculateDrawProperties(root);
[email protected]451107a32013-04-10 05:12:473399
danakj64767d902015-06-19 00:10:433400 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473401 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323402
[email protected]08bdf1b2014-04-16 23:23:293403 // Case 2: a matrix with flattened z, uninvertible and not visible according
3404 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:323405 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263406 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323407 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3408
weiliangc0dece732015-07-27 19:06:173409 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3410 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3411 false, false);
[email protected]630ddad2013-08-16 03:01:323412
weiliangc0dece732015-07-27 19:06:173413 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323414
danakj64767d902015-06-19 00:10:433415 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293416 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323417
[email protected]08bdf1b2014-04-16 23:23:293418 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:323419 uninvertible_matrix.MakeIdentity();
3420 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263421 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323422 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3423
weiliangc0dece732015-07-27 19:06:173424 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3425 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3426 false, false);
[email protected]630ddad2013-08-16 03:01:323427
weiliangc0dece732015-07-27 19:06:173428 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323429
danakj64767d902015-06-19 00:10:433430 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293431 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473432}
3433
[email protected]989386c2013-07-18 21:37:233434TEST_F(LayerTreeHostCommonTest,
ajumaae0dc2d2015-08-05 21:55:563435 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
3436 LayerImpl* root = root_layer();
3437 LayerImpl* child = AddChildToRoot<LayerImpl>();
3438 LayerImpl* grand_child = AddChild<LayerImpl>(child);
3439 child->SetDrawsContent(true);
3440 grand_child->SetDrawsContent(true);
3441
3442 gfx::Transform identity_matrix;
3443
3444 gfx::Transform perspective;
3445 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3446
3447 gfx::Transform rotation;
3448 rotation.RotateAboutYAxis(45.0);
3449
3450 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3451 gfx::PointF(), gfx::Size(100, 100), true, false,
3452 true);
3453 SetLayerPropertiesForTesting(child, perspective, gfx::Point3F(),
3454 gfx::PointF(10.f, 10.f), gfx::Size(100, 100),
3455 false, true, false);
3456 SetLayerPropertiesForTesting(grand_child, rotation, gfx::Point3F(),
3457 gfx::PointF(), gfx::Size(100, 100), false, true,
3458 false);
3459
3460 ExecuteCalculateDrawProperties(root);
3461
3462 // Though all layers have invertible transforms, matrix multiplication using
3463 // floating-point math makes the draw transform uninvertible.
ajumad9432e32015-11-30 19:43:443464 EXPECT_FALSE(grand_child->DrawTransform().IsInvertible());
ajumaae0dc2d2015-08-05 21:55:563465
3466 // CalcDrawProps only skips a subtree when a layer's own transform is
3467 // uninvertible, not when its draw transform is invertible, since CDP makes
3468 // skipping decisions before computing a layer's draw transform. Property
3469 // trees make skipping decisions after computing draw transforms, so could be
3470 // made to skip layers with an uninvertible draw transform (once CDP is
3471 // deleted).
3472 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
3473 grand_child->visible_layer_rect());
3474}
3475
3476TEST_F(LayerTreeHostCommonTest,
3477 OcclusionForLayerWithUninvertibleDrawTransform) {
khushalsagarb64b360d2015-10-21 19:25:163478 FakeImplTaskRunnerProvider task_runner_provider;
ajumaae0dc2d2015-08-05 21:55:563479 TestSharedBitmapManager shared_bitmap_manager;
3480 TestTaskGraphRunner task_graph_runner;
revemand180dfc32015-09-24 00:19:433481 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
khushalsagarb64b360d2015-10-21 19:25:163482 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
ajumaae0dc2d2015-08-05 21:55:563483 &task_graph_runner);
3484 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
3485 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
3486 scoped_ptr<LayerImpl> grand_child =
3487 LayerImpl::Create(host_impl.active_tree(), 3);
3488 scoped_ptr<LayerImpl> occluding_child =
3489 LayerImpl::Create(host_impl.active_tree(), 4);
3490 child->SetDrawsContent(true);
3491 grand_child->SetDrawsContent(true);
3492 occluding_child->SetDrawsContent(true);
3493 occluding_child->SetContentsOpaque(true);
3494
3495 gfx::Transform identity_matrix;
3496 gfx::Transform perspective;
3497 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3498
3499 gfx::Transform rotation;
3500 rotation.RotateAboutYAxis(45.0);
3501
3502 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
3503 gfx::PointF(), gfx::Size(1000, 1000), true,
3504 false, true);
3505 SetLayerPropertiesForTesting(child.get(), perspective, gfx::Point3F(),
3506 gfx::PointF(10.f, 10.f), gfx::Size(300, 300),
3507 false, true, false);
3508 SetLayerPropertiesForTesting(grand_child.get(), rotation, gfx::Point3F(),
3509 gfx::PointF(), gfx::Size(200, 200), false, true,
3510 false);
3511 SetLayerPropertiesForTesting(occluding_child.get(), identity_matrix,
3512 gfx::Point3F(), gfx::PointF(),
3513 gfx::Size(200, 200), false, false, false);
3514
3515 host_impl.SetViewportSize(root->bounds());
3516
danakja04855a2015-11-18 20:39:103517 child->AddChild(std::move(grand_child));
3518 root->AddChild(std::move(child));
3519 root->AddChild(std::move(occluding_child));
3520 host_impl.active_tree()->SetRootLayer(std::move(root));
sievers71c62dd52015-10-07 01:44:393521 host_impl.SetVisible(true);
revemand180dfc32015-09-24 00:19:433522 host_impl.InitializeRenderer(output_surface.get());
jaydasikad7dea632015-11-06 04:40:123523 host_impl.active_tree()->BuildPropertyTreesForTesting();
ajumaae0dc2d2015-08-05 21:55:563524 bool update_lcd_text = false;
3525 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3526
3527 LayerImpl* grand_child_ptr =
vmpstra370ef52015-11-18 10:41:283528 host_impl.active_tree()->root_layer()->children()[0]->children()[0].get();
ajumaae0dc2d2015-08-05 21:55:563529
3530 // Though all layers have invertible transforms, matrix multiplication using
3531 // floating-point math makes the draw transform uninvertible.
ajumad9432e32015-11-30 19:43:443532 EXPECT_FALSE(grand_child_ptr->DrawTransform().IsInvertible());
ajumaae0dc2d2015-08-05 21:55:563533
3534 // Since |grand_child| has an uninvertible draw transform, it is treated as
3535 // unoccluded (even though |occluding_child| comes later in draw order, and
3536 // hence potentially occludes it).
3537 gfx::Rect layer_bounds = gfx::Rect(grand_child_ptr->bounds());
3538 EXPECT_EQ(
3539 layer_bounds,
3540 grand_child_ptr->draw_properties()
3541 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
3542}
3543
3544TEST_F(LayerTreeHostCommonTest,
[email protected]e43c68b2014-05-01 05:10:363545 SingularTransformDoesNotPreventClearingDrawProperties) {
loysoa6edaaff2015-05-25 03:26:443546 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]e43c68b2014-05-01 05:10:363547 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:443548 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]e43c68b2014-05-01 05:10:363549 root->AddChild(child);
3550
ennea7b43c32015-06-18 20:01:333551 host()->SetRootLayer(root);
[email protected]e43c68b2014-05-01 05:10:363552
3553 gfx::Transform identity_matrix;
3554 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3555 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3556
3557 SetLayerPropertiesForTesting(root.get(),
3558 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203559 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:363560 gfx::PointF(),
3561 gfx::Size(100, 100),
3562 true,
3563 false);
3564 SetLayerPropertiesForTesting(child.get(),
3565 identity_matrix,
[email protected]a2566412014-06-05 03:14:203566 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:363567 gfx::PointF(5.f, 5.f),
3568 gfx::Size(50, 50),
3569 true,
3570 false);
3571
jaydasika976cd10b2015-05-26 15:45:243572 child->set_sorted_for_recursion(true);
[email protected]e43c68b2014-05-01 05:10:363573
3574 TransformOperations start_transform_operations;
3575 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
3576
3577 TransformOperations end_transform_operations;
3578 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
3579
loyso968163c92016-01-04 23:18:483580 if (layer_settings().use_compositor_animation_timelines) {
3581 AddAnimatedTransformToLayerWithPlayer(root->id(), timeline(), 10.0,
3582 start_transform_operations,
3583 end_transform_operations);
3584 } else {
3585 AddAnimatedTransformToLayer(root.get(), 10.0, start_transform_operations,
3586 end_transform_operations);
3587 }
[email protected]e43c68b2014-05-01 05:10:363588 EXPECT_TRUE(root->TransformIsAnimating());
3589
3590 ExecuteCalculateDrawProperties(root.get());
3591
jaydasika976cd10b2015-05-26 15:45:243592 EXPECT_FALSE(child->sorted_for_recursion());
[email protected]e43c68b2014-05-01 05:10:363593}
3594
3595TEST_F(LayerTreeHostCommonTest,
[email protected]8dbc85c2014-05-03 03:21:063596 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
loysoa6edaaff2015-05-25 03:26:443597 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]8dbc85c2014-05-03 03:21:063598
ennea7b43c32015-06-18 20:01:333599 host()->SetRootLayer(root);
[email protected]8dbc85c2014-05-03 03:21:063600
3601 gfx::Transform identity_matrix;
3602 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3603 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3604
3605 SetLayerPropertiesForTesting(root.get(),
3606 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203607 gfx::Point3F(),
[email protected]8dbc85c2014-05-03 03:21:063608 gfx::PointF(),
3609 gfx::Size(100, 100),
3610 true,
3611 false);
3612
jaydasika976cd10b2015-05-26 15:45:243613 root->set_sorted_for_recursion(true);
[email protected]8dbc85c2014-05-03 03:21:063614
3615 EXPECT_FALSE(root->TransformIsAnimating());
3616
3617 ExecuteCalculateDrawProperties(root.get());
3618
jaydasika976cd10b2015-05-26 15:45:243619 EXPECT_FALSE(root->sorted_for_recursion());
[email protected]8dbc85c2014-05-03 03:21:063620}
3621
3622TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233623 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
weiliangc0dece732015-07-27 19:06:173624 LayerImpl* root = root_layer();
3625 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3626 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3627 child1->SetDrawsContent(true);
3628 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
3629 child2->SetDrawsContent(true);
3630 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
3631 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283632
[email protected]fb661802013-03-25 01:59:323633 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173634 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3635 gfx::PointF(), gfx::Size(100, 100), true, false,
3636 true);
3637 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3638 gfx::PointF(), gfx::Size(3, 4), true, false,
3639 true);
3640 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3641 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3642 false, false);
3643 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3644 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3645 false, false);
3646 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3647 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3648 true, false, false);
[email protected]fb661802013-03-25 01:59:323649
3650 root->SetMasksToBounds(true);
[email protected]fb661802013-03-25 01:59:323651
weiliangc0dece732015-07-27 19:06:173652 ExecuteCalculateDrawProperties(root);
3653
3654 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323655
danakj5e6ff6d2015-09-05 04:43:443656 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323657 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323658
3659 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433660 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173661 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323662
3663 // A clipped surface grows its DrawableContentRect to include all drawable
3664 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443665 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
weiliangc0dece732015-07-27 19:06:173666 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323667
3668 // All layers that draw content into the surface have their visible content
3669 // rect clipped by the surface clip rect.
danakj64767d902015-06-19 00:10:433670 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3671 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3672 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323673
3674 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323675 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3676 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3677 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323678}
3679
[email protected]989386c2013-07-18 21:37:233680TEST_F(LayerTreeHostCommonTest,
3681 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323682 // Check that clipping does not propagate down surfaces.
weiliangc0dece732015-07-27 19:06:173683 LayerImpl* root = root_layer();
3684 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3685 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
3686 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
3687 child1->SetDrawsContent(true);
3688 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
3689 child2->SetDrawsContent(true);
3690 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
3691 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283692
[email protected]fb661802013-03-25 01:59:323693 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173694 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3695 gfx::PointF(), gfx::Size(100, 100), true, false,
3696 true);
3697 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3698 gfx::PointF(), gfx::Size(3, 4), true, false,
3699 true);
3700 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3701 gfx::PointF(), gfx::Size(7, 13), true, false,
3702 true);
3703 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3704 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3705 false, false);
3706 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3707 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3708 false, false);
3709 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3710 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3711 true, false, false);
[email protected]fb661802013-03-25 01:59:323712
3713 root->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:173714
3715 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323716
3717 ASSERT_TRUE(render_surface1->render_surface());
3718 ASSERT_TRUE(render_surface2->render_surface());
3719
danakj5e6ff6d2015-09-05 04:43:443720 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323721 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323722
3723 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433724 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3725 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3726 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323727
3728 // A clipped surface grows its DrawableContentRect to include all drawable
3729 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443730 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
hush6b614212014-12-04 22:37:323731 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323732
3733 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3734 // is only implicitly clipped by render_surface1's content rect. So,
3735 // render_surface2 grows to enclose all drawable content of its subtree.
danakj5e6ff6d2015-09-05 04:43:443736 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
hush6b614212014-12-04 22:37:323737 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323738
3739 // All layers that draw content into render_surface2 think they are unclipped.
danakj64767d902015-06-19 00:10:433740 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3741 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3742 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323743
3744 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323745 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3746 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3747 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323748}
3749
[email protected]989386c2013-07-18 21:37:233750TEST_F(LayerTreeHostCommonTest,
jaydasika27d0f2e2015-10-16 23:52:463751 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) {
3752 LayerImpl* root = root_layer();
3753 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3754 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
3755 LayerImpl* child2 = AddChild<LayerImpl>(child1);
3756 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2);
3757 child1->SetDrawsContent(true);
3758 child2->SetDrawsContent(true);
3759 render_surface2->SetDrawsContent(true);
3760
3761 gfx::Transform identity_matrix;
3762 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3763 gfx::PointF(), gfx::Size(100, 100), true, false,
3764 true);
3765 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3766 gfx::PointF(), gfx::Size(100, 100), true, false,
3767 true);
3768 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3769 gfx::PointF(), gfx::Size(500, 500), true, false,
3770 false);
3771 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3772 gfx::PointF(), gfx::Size(700, 700), true, false,
3773 false);
3774 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3775 gfx::PointF(), gfx::Size(1000, 1000), true,
3776 false, true);
3777
3778 child1->SetMasksToBounds(true);
3779 child2->SetMasksToBounds(true);
3780
3781 ExecuteCalculateDrawProperties(root);
3782 EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect());
3783 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect());
3784}
3785
3786TEST_F(LayerTreeHostCommonTest,
3787 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) {
3788 LayerImpl* root = root_layer();
3789 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3790 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3791 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3792 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3793
3794 render_surface1->SetDrawsContent(true);
3795 render_surface2->SetDrawsContent(true);
3796 clip_child->SetDrawsContent(true);
3797 clip_child->SetClipParent(clip_parent);
3798 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3799 clip_children->insert(clip_child);
3800 clip_parent->SetClipChildren(clip_children.release());
3801
3802 gfx::Transform identity_matrix;
3803 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3804 gfx::PointF(), gfx::Size(100, 100), true, false,
3805 true);
3806 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3807 gfx::PointF(), gfx::Size(50, 50), true, false,
3808 false);
3809 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3810 gfx::PointF(), gfx::Size(20, 20), true, false,
3811 true);
3812 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3813 gfx::PointF(), gfx::Size(60, 60), true, false,
3814 false);
3815 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3816 gfx::PointF(), gfx::Size(60, 60), true, false,
3817 true);
3818 clip_parent->SetMasksToBounds(true);
3819 render_surface1->SetMasksToBounds(true);
3820
3821 ExecuteCalculateDrawProperties(root);
3822 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect());
3823 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect());
3824 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect());
3825}
3826
jaydasika1f5312d2015-10-21 21:34:323827TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) {
3828 LayerImpl* root = root_layer();
3829 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3830 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3831 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3832 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3833
3834 render_surface1->SetDrawsContent(true);
3835 render_surface2->SetDrawsContent(true);
3836 clip_child->SetDrawsContent(true);
3837 clip_child->SetClipParent(clip_parent);
3838 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3839 clip_children->insert(clip_child);
3840 clip_parent->SetClipChildren(clip_children.release());
3841
3842 gfx::Transform identity_matrix;
3843 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3844 gfx::PointF(), gfx::Size(100, 100), true, false,
3845 true);
3846 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3847 gfx::PointF(2.f, 2.f), gfx::Size(50, 50), true,
3848 false, false);
3849 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3850 gfx::PointF(), gfx::Size(20, 20), true, false,
3851 true);
3852 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3853 gfx::PointF(), gfx::Size(60, 60), true, false,
3854 false);
3855 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3856 gfx::PointF(), gfx::Size(60, 60), true, false,
3857 true);
3858 clip_parent->SetMasksToBounds(true);
3859 render_surface1->SetMasksToBounds(true);
3860
3861 ExecuteCalculateDrawProperties(root);
3862 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect());
3863}
3864
jaydasika77a4a072015-10-20 21:47:273865TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) {
3866 // Test that only drawn layers contribute to render surface content rect.
3867 LayerImpl* root = root_layer();
3868 LayerImpl* surface = AddChildToRoot<LayerImpl>();
3869 LayerImpl* test_layer = AddChild<LayerImpl>(surface);
3870
3871 test_layer->SetDrawsContent(false);
3872 surface->SetDrawsContent(true);
3873 gfx::Transform identity_matrix;
3874 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3875 gfx::PointF(), gfx::Size(200, 200), true, false,
3876 true);
3877 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
3878 gfx::PointF(), gfx::Size(100, 100), true, false,
3879 true);
3880 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
3881 gfx::PointF(), gfx::Size(150, 150), true, false,
3882 false);
3883
3884 ExecuteCalculateDrawProperties(root);
3885 EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect());
3886
3887 test_layer->SetDrawsContent(true);
3888 ExecuteCalculateDrawProperties(root);
3889 EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect());
3890}
3891
jaydasika27d0f2e2015-10-16 23:52:463892TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) {
3893 // Tests visible rects computation when we have unclipped_surface->
3894 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3895 // of surface_with_unclipped_descendants doesn't propagate to the
3896 // clipped_surface below it.
3897 LayerImpl* root = root_layer();
3898 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3899 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3900 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3901 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3902 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3903
3904 unclipped_surface->SetDrawsContent(true);
3905 unclipped_desc_surface->SetDrawsContent(true);
3906 clipped_surface->SetDrawsContent(true);
3907 clip_child->SetClipParent(clip_parent);
3908 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3909 clip_children->insert(clip_child);
3910 clip_parent->SetClipChildren(clip_children.release());
3911
3912 gfx::Transform identity_matrix;
3913 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3914 gfx::PointF(), gfx::Size(100, 100), true, false,
3915 true);
3916 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
3917 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
3918 true, false, true);
3919 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3920 gfx::PointF(), gfx::Size(50, 50), true, false,
3921 false);
3922 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
3923 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
3924 true, false, true);
3925 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3926 gfx::PointF(), gfx::Size(60, 60), true, false,
3927 false);
3928 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
3929 gfx::PointF(), gfx::Size(60, 60), true, false,
3930 true);
3931 clip_parent->SetMasksToBounds(true);
3932
3933 ExecuteCalculateDrawProperties(root);
3934 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect());
3935 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect());
3936 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect());
3937}
3938
3939TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) {
3940 // Tests visible rects computation when we have unclipped_surface->
3941 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3942 // of root propagate to the clipped_surface.
3943 LayerImpl* root = root_layer();
3944 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3945 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3946 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3947 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3948 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3949
3950 unclipped_surface->SetDrawsContent(true);
3951 unclipped_desc_surface->SetDrawsContent(true);
3952 clipped_surface->SetDrawsContent(true);
3953 clip_child->SetClipParent(clip_parent);
3954 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3955 clip_children->insert(clip_child);
3956 clip_parent->SetClipChildren(clip_children.release());
3957
3958 gfx::Transform identity_matrix;
3959 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3960 gfx::PointF(), gfx::Size(10, 10), true, false,
3961 true);
3962 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
3963 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
3964 true, false, true);
3965 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3966 gfx::PointF(), gfx::Size(50, 50), true, false,
3967 false);
3968 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
3969 gfx::Point3F(), gfx::PointF(),
3970 gfx::Size(100, 100), true, false, true);
3971 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3972 gfx::PointF(), gfx::Size(100, 100), true, false,
3973 false);
3974 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
3975 gfx::PointF(), gfx::Size(50, 50), true, false,
3976 true);
3977 clip_parent->SetMasksToBounds(true);
3978 unclipped_desc_surface->SetMasksToBounds(true);
3979
3980 ExecuteCalculateDrawProperties(root);
3981 EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect());
3982 EXPECT_EQ(gfx::Rect(100, 100), unclipped_desc_surface->visible_layer_rect());
3983 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect());
3984}
3985
3986TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233987 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323988 // Layers that have non-axis aligned bounds (due to transforms) have an
3989 // expanded, axis-aligned DrawableContentRect and visible content rect.
weiliangc0dece732015-07-27 19:06:173990 LayerImpl* root = root_layer();
3991 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3992 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3993 child1->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283994
[email protected]fb661802013-03-25 01:59:323995 gfx::Transform identity_matrix;
3996 gfx::Transform child_rotation;
3997 child_rotation.Rotate(45.0);
weiliangc0dece732015-07-27 19:06:173998 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3999 gfx::PointF(), gfx::Size(100, 100), true, false,
4000 true);
4001 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
4002 gfx::PointF(), gfx::Size(3, 4), true, false,
4003 true);
4004 SetLayerPropertiesForTesting(
4005 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
4006 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
[email protected]fb661802013-03-25 01:59:324007
weiliangc0dece732015-07-27 19:06:174008 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:324009
weiliangc0dece732015-07-27 19:06:174010 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324011
danakj5e6ff6d2015-09-05 04:43:444012 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:324013 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324014
4015 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:434016 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:174017 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324018
4019 // The unclipped surface grows its DrawableContentRect to include all drawable
4020 // regions of the subtree.
4021 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
4022 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:264023 gfx::Rect(50 - diagonal_radius,
4024 50 - diagonal_radius,
4025 diagonal_radius * 2,
4026 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444027 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content),
weiliangc0dece732015-07-27 19:06:174028 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324029
4030 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:434031 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
hush6b614212014-12-04 22:37:324032 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324033}
4034
[email protected]989386c2013-07-18 21:37:234035TEST_F(LayerTreeHostCommonTest,
4036 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:324037 // Layers that have non-axis aligned bounds (due to transforms) have an
4038 // expanded, axis-aligned DrawableContentRect and visible content rect.
weiliangc0dece732015-07-27 19:06:174039 LayerImpl* root = root_layer();
4040 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4041 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
4042 child1->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284043
[email protected]fb661802013-03-25 01:59:324044 gfx::Transform identity_matrix;
4045 gfx::Transform child_rotation;
4046 child_rotation.Rotate(45.0);
weiliangc0dece732015-07-27 19:06:174047 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4048 gfx::PointF(), gfx::Size(50, 50), true, false,
4049 true);
4050 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
4051 gfx::PointF(), gfx::Size(3, 4), true, false,
4052 true);
[email protected]a2566412014-06-05 03:14:204053
weiliangc0dece732015-07-27 19:06:174054 SetLayerPropertiesForTesting(
4055 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
4056 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
[email protected]fb661802013-03-25 01:59:324057
4058 root->SetMasksToBounds(true);
[email protected]fb661802013-03-25 01:59:324059
weiliangc0dece732015-07-27 19:06:174060 ExecuteCalculateDrawProperties(root);
4061
4062 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324063
4064 // The clipped surface clamps the DrawableContentRect that encloses the
4065 // rotated layer.
4066 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:264067 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
4068 50 - diagonal_radius,
4069 diagonal_radius * 2,
4070 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444071 gfx::RectF expected_surface_drawable_content(
4072 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
hush6b614212014-12-04 22:37:324073 EXPECT_EQ(expected_surface_drawable_content,
weiliangc0dece732015-07-27 19:06:174074 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324075
4076 // On the clipped surface, only a quarter of the child1 is visible, but when
4077 // rotating it back to child1's content space, the actual enclosing rect ends
4078 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:264079 //
4080 // Given the floating point math, this number is a little bit fuzzy.
danakj64767d902015-06-19 00:10:434081 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324082
4083 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:324084 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324085}
4086
[email protected]989386c2013-07-18 21:37:234087TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
weiliangc0dece732015-07-27 19:06:174088 LayerImpl* root = root_layer();
4089 FakePictureLayerImpl* render_surface1 =
4090 AddChildToRoot<FakePictureLayerImpl>();
4091 render_surface1->SetDrawsContent(true);
4092 FakePictureLayerImpl* render_surface2 =
4093 AddChild<FakePictureLayerImpl>(render_surface1);
4094 render_surface2->SetDrawsContent(true);
4095 FakePictureLayerImpl* child1 =
4096 AddChild<FakePictureLayerImpl>(render_surface2);
4097 child1->SetDrawsContent(true);
4098 FakePictureLayerImpl* child2 =
4099 AddChild<FakePictureLayerImpl>(render_surface2);
4100 child2->SetDrawsContent(true);
4101 FakePictureLayerImpl* child3 =
4102 AddChild<FakePictureLayerImpl>(render_surface2);
4103 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284104
[email protected]fb661802013-03-25 01:59:324105 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:174106 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4107 gfx::PointF(), gfx::Size(100, 100), true, false,
4108 true);
4109 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
4110 gfx::PointF(5.f, 5.f), gfx::Size(3, 4), true,
4111 false, true);
4112 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
4113 gfx::PointF(5.f, 5.f), gfx::Size(7, 13), true,
4114 false, true);
4115 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
4116 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
4117 false, false);
4118 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4119 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
4120 false, false);
4121 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
4122 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
4123 true, false, false);
[email protected]fb661802013-03-25 01:59:324124
4125 float device_scale_factor = 2.f;
4126
4127 root->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:174128
4129 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324130
4131 ASSERT_TRUE(render_surface1->render_surface());
4132 ASSERT_TRUE(render_surface2->render_surface());
4133
4134 // drawable_content_rects for all layers and surfaces are scaled by
4135 // device_scale_factor.
danakj5e6ff6d2015-09-05 04:43:444136 EXPECT_EQ(gfx::RectF(200.f, 200.f),
hush6b614212014-12-04 22:37:324137 root->render_surface()->DrawableContentRect());
danakj5e6ff6d2015-09-05 04:43:444138 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
hush6b614212014-12-04 22:37:324139 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324140
4141 // render_surface2 lives in the "unclipped universe" of render_surface1, and
4142 // is only implicitly clipped by render_surface1.
danakj5e6ff6d2015-09-05 04:43:444143 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f),
hush6b614212014-12-04 22:37:324144 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324145
hush6b614212014-12-04 22:37:324146 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
4147 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
4148 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324149
4150 // The root layer does not actually draw content of its own.
danakj64767d902015-06-19 00:10:434151 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324152
sohan.jyotie3bd6192014-10-13 07:13:594153 // All layer visible content rects are not expressed in content space of each
4154 // layer, so they are not scaled by the device_scale_factor.
danakj64767d902015-06-19 00:10:434155 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
4156 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
4157 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
4158 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
4159 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324160}
4161
[email protected]989386c2013-07-18 21:37:234162TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:324163 // Verify the behavior of back-face culling when there are no preserve-3d
4164 // layers. Note that 3d transforms still apply in this case, but they are
4165 // "flattened" to each parent layer according to current W3C spec.
4166
4167 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:444168 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:324169 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
loysoa6edaaff2015-05-25 03:26:444170 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324171 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
loysoa6edaaff2015-05-25 03:26:444172 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324173 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
loysoa6edaaff2015-05-25 03:26:444174 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324175 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
loysoa6edaaff2015-05-25 03:26:444176 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324177 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:234178 front_facing_child_of_front_facing_surface =
loysoa6edaaff2015-05-25 03:26:444179 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324180 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:234181 back_facing_child_of_front_facing_surface =
loysoa6edaaff2015-05-25 03:26:444182 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324183 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:234184 front_facing_child_of_back_facing_surface =
loysoa6edaaff2015-05-25 03:26:444185 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324186 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:234187 back_facing_child_of_back_facing_surface =
loysoa6edaaff2015-05-25 03:26:444188 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324189
4190 parent->AddChild(front_facing_child);
4191 parent->AddChild(back_facing_child);
4192 parent->AddChild(front_facing_surface);
4193 parent->AddChild(back_facing_surface);
4194 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
4195 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
4196 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
4197 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
4198
ennea7b43c32015-06-18 20:01:334199 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:284200
[email protected]fb661802013-03-25 01:59:324201 // Nothing is double-sided
4202 front_facing_child->SetDoubleSided(false);
4203 back_facing_child->SetDoubleSided(false);
4204 front_facing_surface->SetDoubleSided(false);
4205 back_facing_surface->SetDoubleSided(false);
4206 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
4207 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
4208 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
4209 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
4210
4211 gfx::Transform backface_matrix;
4212 backface_matrix.Translate(50.0, 50.0);
4213 backface_matrix.RotateAboutYAxis(180.0);
4214 backface_matrix.Translate(-50.0, -50.0);
4215
4216 // Having a descendant and opacity will force these to have render surfaces.
4217 front_facing_surface->SetOpacity(0.5f);
4218 back_facing_surface->SetOpacity(0.5f);
4219
4220 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
4221 // these layers should blindly use their own local transforms to determine
4222 // back-face culling.
4223 SetLayerPropertiesForTesting(parent.get(),
4224 identity_matrix,
[email protected]a2566412014-06-05 03:14:204225 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324226 gfx::PointF(),
4227 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574228 true,
[email protected]fb661802013-03-25 01:59:324229 false);
4230 SetLayerPropertiesForTesting(front_facing_child.get(),
4231 identity_matrix,
[email protected]a2566412014-06-05 03:14:204232 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324233 gfx::PointF(),
4234 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574235 true,
[email protected]fb661802013-03-25 01:59:324236 false);
4237 SetLayerPropertiesForTesting(back_facing_child.get(),
4238 backface_matrix,
[email protected]a2566412014-06-05 03:14:204239 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324240 gfx::PointF(),
4241 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574242 true,
[email protected]fb661802013-03-25 01:59:324243 false);
4244 SetLayerPropertiesForTesting(front_facing_surface.get(),
4245 identity_matrix,
[email protected]a2566412014-06-05 03:14:204246 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324247 gfx::PointF(),
4248 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574249 true,
[email protected]fb661802013-03-25 01:59:324250 false);
4251 SetLayerPropertiesForTesting(back_facing_surface.get(),
4252 backface_matrix,
[email protected]a2566412014-06-05 03:14:204253 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324254 gfx::PointF(),
4255 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574256 true,
[email protected]fb661802013-03-25 01:59:324257 false);
4258 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
4259 identity_matrix,
[email protected]a2566412014-06-05 03:14:204260 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324261 gfx::PointF(),
4262 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574263 true,
[email protected]fb661802013-03-25 01:59:324264 false);
4265 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
4266 backface_matrix,
[email protected]a2566412014-06-05 03:14:204267 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324268 gfx::PointF(),
4269 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574270 true,
[email protected]fb661802013-03-25 01:59:324271 false);
4272 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
4273 identity_matrix,
[email protected]a2566412014-06-05 03:14:204274 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324275 gfx::PointF(),
4276 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574277 true,
[email protected]fb661802013-03-25 01:59:324278 false);
4279 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
4280 backface_matrix,
[email protected]a2566412014-06-05 03:14:204281 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324282 gfx::PointF(),
4283 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574284 true,
[email protected]fb661802013-03-25 01:59:324285 false);
4286
enne7b2a2172015-07-14 00:04:534287 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
[email protected]fb661802013-03-25 01:59:324288
4289 // Verify which render surfaces were created.
ennec1332992015-08-24 19:45:094290 EXPECT_FALSE(front_facing_child->has_render_surface());
4291 EXPECT_FALSE(back_facing_child->has_render_surface());
4292 EXPECT_TRUE(front_facing_surface->has_render_surface());
4293 EXPECT_TRUE(back_facing_surface->has_render_surface());
4294 EXPECT_FALSE(
4295 front_facing_child_of_front_facing_surface->has_render_surface());
4296 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4297 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4298 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324299
enne7b2a2172015-07-14 00:04:534300 EXPECT_EQ(4u, update_layer_list().size());
4301 EXPECT_TRUE(UpdateLayerListContains(front_facing_child->id()));
4302 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
4303 EXPECT_TRUE(UpdateLayerListContains(
4304 front_facing_child_of_front_facing_surface->id()));
4305 EXPECT_TRUE(
4306 UpdateLayerListContains(front_facing_child_of_back_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324307}
4308
[email protected]989386c2013-07-18 21:37:234309TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:324310 // Verify the behavior of back-face culling when preserves-3d transform style
4311 // is used.
4312
4313 const gfx::Transform identity_matrix;
weiliangcc154ce22015-12-09 03:39:264314 LayerImpl* parent = root_layer();
4315 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4316 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4317 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4318 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4319 LayerImpl* front_facing_child_of_front_facing_surface =
4320 AddChild<LayerImpl>(front_facing_surface);
4321 LayerImpl* back_facing_child_of_front_facing_surface =
4322 AddChild<LayerImpl>(front_facing_surface);
4323 LayerImpl* front_facing_child_of_back_facing_surface =
4324 AddChild<LayerImpl>(back_facing_surface);
4325 LayerImpl* back_facing_child_of_back_facing_surface =
4326 AddChild<LayerImpl>(back_facing_surface);
4327 // Opacity will not force creation of render surfaces in this case because of
4328 // the preserve-3d transform style. Instead, an example of when a surface
4329 // would be created with preserve-3d is when there is a replica layer.
4330 LayerImpl* dummy_replica_layer1 =
4331 AddReplicaLayer<LayerImpl>(front_facing_surface);
4332 LayerImpl* dummy_replica_layer2 =
4333 AddReplicaLayer<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284334
[email protected]fb661802013-03-25 01:59:324335 // Nothing is double-sided
4336 front_facing_child->SetDoubleSided(false);
4337 back_facing_child->SetDoubleSided(false);
4338 front_facing_surface->SetDoubleSided(false);
4339 back_facing_surface->SetDoubleSided(false);
4340 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
4341 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
4342 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
4343 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
4344
weiliangcc154ce22015-12-09 03:39:264345 // Everything draws content.
4346 front_facing_child->SetDrawsContent(true);
4347 back_facing_child->SetDrawsContent(true);
4348 front_facing_surface->SetDrawsContent(true);
4349 back_facing_surface->SetDrawsContent(true);
4350 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4351 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4352 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4353 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
4354 dummy_replica_layer1->SetDrawsContent(true);
4355 dummy_replica_layer2->SetDrawsContent(true);
4356
[email protected]fb661802013-03-25 01:59:324357 gfx::Transform backface_matrix;
4358 backface_matrix.Translate(50.0, 50.0);
4359 backface_matrix.RotateAboutYAxis(180.0);
4360 backface_matrix.Translate(-50.0, -50.0);
4361
[email protected]fb661802013-03-25 01:59:324362 // Each surface creates its own new 3d rendering context (as defined by W3C
4363 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
4364 // rendering context should use the transform with respect to that context.
4365 // This 3d rendering context occurs when (a) parent's transform style is flat
4366 // and (b) the layer's transform style is preserve-3d.
weiliangcc154ce22015-12-09 03:39:264367 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
weiliangc4374c2cc2015-12-07 19:26:014368 gfx::PointF(), gfx::Size(100, 100), true,
[email protected]fb661802013-03-25 01:59:324369 false); // parent transform style is flat.
weiliangcc154ce22015-12-09 03:39:264370 SetLayerPropertiesForTesting(front_facing_child, identity_matrix,
weiliangc4374c2cc2015-12-07 19:26:014371 gfx::Point3F(), gfx::PointF(),
4372 gfx::Size(100, 100), true, false);
weiliangcc154ce22015-12-09 03:39:264373 SetLayerPropertiesForTesting(back_facing_child, backface_matrix,
weiliangc4374c2cc2015-12-07 19:26:014374 gfx::Point3F(), gfx::PointF(),
4375 gfx::Size(100, 100), true, false);
[email protected]56fffdd2014-02-11 19:50:574376 // surface transform style is preserve-3d.
weiliangcc154ce22015-12-09 03:39:264377 SetLayerPropertiesForTesting(front_facing_surface, identity_matrix,
weiliangc4374c2cc2015-12-07 19:26:014378 gfx::Point3F(), gfx::PointF(),
4379 gfx::Size(100, 100), false, true);
[email protected]56fffdd2014-02-11 19:50:574380 // surface transform style is preserve-3d.
weiliangcc154ce22015-12-09 03:39:264381 SetLayerPropertiesForTesting(back_facing_surface, backface_matrix,
weiliangc4374c2cc2015-12-07 19:26:014382 gfx::Point3F(), gfx::PointF(),
4383 gfx::Size(100, 100), false, true);
weiliangcc154ce22015-12-09 03:39:264384 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014385 identity_matrix, gfx::Point3F(), gfx::PointF(),
4386 gfx::Size(100, 100), true, true);
weiliangcc154ce22015-12-09 03:39:264387 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014388 backface_matrix, gfx::Point3F(), gfx::PointF(),
4389 gfx::Size(100, 100), true, true);
weiliangcc154ce22015-12-09 03:39:264390 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014391 identity_matrix, gfx::Point3F(), gfx::PointF(),
4392 gfx::Size(100, 100), true, true);
weiliangcc154ce22015-12-09 03:39:264393 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014394 backface_matrix, gfx::Point3F(), gfx::PointF(),
4395 gfx::Size(100, 100), true, true);
[email protected]fb661802013-03-25 01:59:324396
weiliangcc154ce22015-12-09 03:39:264397 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:324398
awoloszyne83f28c2014-12-22 15:40:004399 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094400 EXPECT_FALSE(front_facing_child->has_render_surface());
4401 EXPECT_FALSE(back_facing_child->has_render_surface());
4402 EXPECT_TRUE(front_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094403 // We expect that a has_render_surface was created but not used.
4404 EXPECT_TRUE(back_facing_surface->has_render_surface());
4405 EXPECT_FALSE(
4406 front_facing_child_of_front_facing_surface->has_render_surface());
4407 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4408 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4409 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324410
weiliangcc154ce22015-12-09 03:39:264411 EXPECT_EQ(3u, update_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:324412
weiliangcc154ce22015-12-09 03:39:264413 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4414 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4415 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534416 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324417}
4418
[email protected]989386c2013-07-18 21:37:234419TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:324420 // Verify that layers are appropriately culled when their back face is showing
4421 // and they are not double sided, while animations are going on.
4422 //
4423 // Layers that are animating do not get culled on the main thread, as their
4424 // transforms should be treated as "unknown" so we can not be sure that their
4425 // back face is really showing.
4426 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:444427 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:324428 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:444429 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324430 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
loysoa6edaaff2015-05-25 03:26:444431 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324432 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
loysoa6edaaff2015-05-25 03:26:444433 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324434 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
loysoa6edaaff2015-05-25 03:26:444435 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324436 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loysoa6edaaff2015-05-25 03:26:444437 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324438
4439 parent->AddChild(child);
4440 parent->AddChild(animating_surface);
4441 animating_surface->AddChild(child_of_animating_surface);
4442 parent->AddChild(animating_child);
4443 parent->AddChild(child2);
4444
ennea7b43c32015-06-18 20:01:334445 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:284446
[email protected]fb661802013-03-25 01:59:324447 // Nothing is double-sided
4448 child->SetDoubleSided(false);
4449 child2->SetDoubleSided(false);
4450 animating_surface->SetDoubleSided(false);
4451 child_of_animating_surface->SetDoubleSided(false);
4452 animating_child->SetDoubleSided(false);
4453
4454 gfx::Transform backface_matrix;
4455 backface_matrix.Translate(50.0, 50.0);
4456 backface_matrix.RotateAboutYAxis(180.0);
4457 backface_matrix.Translate(-50.0, -50.0);
4458
4459 // Make our render surface.
4460 animating_surface->SetForceRenderSurface(true);
4461
loyso968163c92016-01-04 23:18:484462 if (layer_settings().use_compositor_animation_timelines) {
4463 // Animate the transform on the render surface.
4464 AddAnimatedTransformToLayerWithPlayer(animating_surface->id(), timeline(),
4465 10.0, 30, 0);
4466 // This is just an animating layer, not a surface.
4467 AddAnimatedTransformToLayerWithPlayer(animating_child->id(), timeline(),
4468 10.0, 30, 0);
4469 } else {
4470 // Animate the transform on the render surface.
4471 AddAnimatedTransformToController(
4472 animating_surface->layer_animation_controller(), 10.0, 30, 0);
4473 // This is just an animating layer, not a surface.
4474 AddAnimatedTransformToController(
4475 animating_child->layer_animation_controller(), 10.0, 30, 0);
4476 }
[email protected]fb661802013-03-25 01:59:324477
4478 SetLayerPropertiesForTesting(parent.get(),
4479 identity_matrix,
[email protected]a2566412014-06-05 03:14:204480 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324481 gfx::PointF(),
4482 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574483 true,
[email protected]fb661802013-03-25 01:59:324484 false);
4485 SetLayerPropertiesForTesting(child.get(),
4486 backface_matrix,
[email protected]a2566412014-06-05 03:14:204487 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324488 gfx::PointF(),
4489 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574490 true,
[email protected]fb661802013-03-25 01:59:324491 false);
4492 SetLayerPropertiesForTesting(animating_surface.get(),
4493 backface_matrix,
[email protected]a2566412014-06-05 03:14:204494 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324495 gfx::PointF(),
4496 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574497 true,
[email protected]fb661802013-03-25 01:59:324498 false);
4499 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
4500 backface_matrix,
[email protected]a2566412014-06-05 03:14:204501 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324502 gfx::PointF(),
4503 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574504 true,
[email protected]fb661802013-03-25 01:59:324505 false);
4506 SetLayerPropertiesForTesting(animating_child.get(),
4507 backface_matrix,
[email protected]a2566412014-06-05 03:14:204508 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324509 gfx::PointF(),
4510 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574511 true,
[email protected]fb661802013-03-25 01:59:324512 false);
4513 SetLayerPropertiesForTesting(child2.get(),
4514 identity_matrix,
[email protected]a2566412014-06-05 03:14:204515 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324516 gfx::PointF(),
4517 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574518 true,
[email protected]fb661802013-03-25 01:59:324519 false);
4520
enne1e1008c2015-08-21 00:45:464521 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(parent.get(),
4522 parent->bounds());
[email protected]7aad55f2013-07-26 11:25:534523 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324524
ennec1332992015-08-24 19:45:094525 EXPECT_FALSE(child->has_render_surface());
4526 EXPECT_TRUE(animating_surface->has_render_surface());
4527 EXPECT_FALSE(child_of_animating_surface->has_render_surface());
4528 EXPECT_FALSE(animating_child->has_render_surface());
4529 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324530
enne7b2a2172015-07-14 00:04:534531 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
4532
4533 EXPECT_EQ(4u, update_layer_list().size());
[email protected]fb661802013-03-25 01:59:324534
4535 // The non-animating child be culled from the layer list for the parent render
4536 // surface.
enne7b2a2172015-07-14 00:04:534537 EXPECT_TRUE(UpdateLayerListContains(animating_surface->id()));
4538 EXPECT_TRUE(UpdateLayerListContains(animating_child->id()));
4539 EXPECT_TRUE(UpdateLayerListContains(child2->id()));
4540 EXPECT_TRUE(UpdateLayerListContains(child_of_animating_surface->id()));
[email protected]fb661802013-03-25 01:59:324541
enne7b2a2172015-07-14 00:04:534542 EXPECT_FALSE(child2->visible_rect_from_property_trees().IsEmpty());
[email protected]fb661802013-03-25 01:59:324543
4544 // The animating layers should have a visible content rect that represents the
4545 // area of the front face that is within the viewport.
enne7b2a2172015-07-14 00:04:534546 EXPECT_EQ(animating_child->visible_rect_from_property_trees(),
Dana Jansensc46d3742015-06-18 01:33:144547 gfx::Rect(animating_child->bounds()));
enne7b2a2172015-07-14 00:04:534548 EXPECT_EQ(animating_surface->visible_rect_from_property_trees(),
Dana Jansensc46d3742015-06-18 01:33:144549 gfx::Rect(animating_surface->bounds()));
[email protected]fb661802013-03-25 01:59:324550 // And layers in the subtree of the animating layer should have valid visible
4551 // content rects also.
enne7b2a2172015-07-14 00:04:534552 EXPECT_EQ(child_of_animating_surface->visible_rect_from_property_trees(),
Dana Jansensc46d3742015-06-18 01:33:144553 gfx::Rect(child_of_animating_surface->bounds()));
[email protected]fb661802013-03-25 01:59:324554}
4555
[email protected]989386c2013-07-18 21:37:234556TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324557 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4558 // Verify the behavior of back-face culling for a render surface that is
4559 // created when it flattens its subtree, and its parent has preserves-3d.
4560
4561 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:444562 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:324563 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
loysoa6edaaff2015-05-25 03:26:444564 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324565 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
loysoa6edaaff2015-05-25 03:26:444566 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324567 scoped_refptr<LayerWithForcedDrawsContent> child1 =
loysoa6edaaff2015-05-25 03:26:444568 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324569 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loysoa6edaaff2015-05-25 03:26:444570 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324571
4572 parent->AddChild(front_facing_surface);
4573 parent->AddChild(back_facing_surface);
4574 front_facing_surface->AddChild(child1);
4575 back_facing_surface->AddChild(child2);
4576
ennea7b43c32015-06-18 20:01:334577 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:284578
[email protected]fb661802013-03-25 01:59:324579 // RenderSurfaces are not double-sided
4580 front_facing_surface->SetDoubleSided(false);
4581 back_facing_surface->SetDoubleSided(false);
4582
4583 gfx::Transform backface_matrix;
4584 backface_matrix.Translate(50.0, 50.0);
4585 backface_matrix.RotateAboutYAxis(180.0);
4586 backface_matrix.Translate(-50.0, -50.0);
4587
4588 SetLayerPropertiesForTesting(parent.get(),
4589 identity_matrix,
[email protected]a2566412014-06-05 03:14:204590 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324591 gfx::PointF(),
4592 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574593 false,
4594 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:324595 SetLayerPropertiesForTesting(front_facing_surface.get(),
4596 identity_matrix,
[email protected]a2566412014-06-05 03:14:204597 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324598 gfx::PointF(),
4599 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574600 true,
4601 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324602 SetLayerPropertiesForTesting(back_facing_surface.get(),
4603 backface_matrix,
[email protected]a2566412014-06-05 03:14:204604 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324605 gfx::PointF(),
4606 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574607 true,
4608 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324609 SetLayerPropertiesForTesting(child1.get(),
4610 identity_matrix,
[email protected]a2566412014-06-05 03:14:204611 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324612 gfx::PointF(),
4613 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574614 true,
[email protected]fb661802013-03-25 01:59:324615 false);
4616 SetLayerPropertiesForTesting(child2.get(),
4617 identity_matrix,
[email protected]a2566412014-06-05 03:14:204618 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324619 gfx::PointF(),
4620 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574621 true,
[email protected]fb661802013-03-25 01:59:324622 false);
4623
[email protected]a9d4d4f2014-06-19 06:49:284624 front_facing_surface->Set3dSortingContextId(1);
4625 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574626
enne7b2a2172015-07-14 00:04:534627 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
[email protected]fb661802013-03-25 01:59:324628
awoloszyne83f28c2014-12-22 15:40:004629 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094630 EXPECT_TRUE(front_facing_surface->has_render_surface());
awoloszyne83f28c2014-12-22 15:40:004631
4632 // We expect the render surface to have been created, but remain unused.
ennec1332992015-08-24 19:45:094633 EXPECT_TRUE(back_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094634 EXPECT_FALSE(child1->has_render_surface());
4635 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324636
enne7b2a2172015-07-14 00:04:534637 EXPECT_EQ(2u, update_layer_list().size());
4638 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
4639 EXPECT_TRUE(UpdateLayerListContains(child1->id()));
[email protected]fb661802013-03-25 01:59:324640}
4641
enne637715732015-07-07 02:05:264642TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324643 // Verify draw and screen space transforms of layers not in a surface.
[email protected]fb661802013-03-25 01:59:324644 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:144645
enne637715732015-07-07 02:05:264646 LayerImpl* parent = root_layer();
jaydasika8640f9f2015-11-10 01:34:364647 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264648 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4649 gfx::PointF(), gfx::Size(100, 100), false, true,
[email protected]fb661802013-03-25 01:59:324650 true);
[email protected]94f206c12012-08-25 00:09:144651
enne637715732015-07-07 02:05:264652 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364653 child->SetDrawsContent(true);
enne637715732015-07-07 02:05:264654 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4655 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4656 true, false);
[email protected]94f206c12012-08-25 00:09:144657
jaydasika8640f9f2015-11-10 01:34:364658 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
4659 child2->SetDrawsContent(true);
4660 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4661 gfx::PointF(2.f, 2.f), gfx::Size(5, 5), false,
4662 true, false);
[email protected]d600df7d2013-08-03 02:34:284663
[email protected]fb661802013-03-25 01:59:324664 float device_scale_factor = 2.5f;
enne637715732015-07-07 02:05:264665 gfx::Size viewport_size(100, 100);
4666 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144667
enne637715732015-07-07 02:05:264668 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent);
4669 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child);
jaydasika8640f9f2015-11-10 01:34:364670 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child2);
[email protected]518ee582012-10-24 18:29:444671
enne637715732015-07-07 02:05:264672 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144673
[email protected]fb661802013-03-25 01:59:324674 // Verify parent transforms
4675 gfx::Transform expected_parent_transform;
enne637715732015-07-07 02:05:264676 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324677 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104678 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324679 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444680 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144681
[email protected]fb661802013-03-25 01:59:324682 // Verify results of transformed parent rects
danakjddaec912015-09-25 19:38:404683 gfx::RectF parent_bounds(gfx::SizeF(parent->bounds()));
[email protected]94f206c12012-08-25 00:09:144684
[email protected]fb661802013-03-25 01:59:324685 gfx::RectF parent_draw_rect =
ajumad9432e32015-11-30 19:43:444686 MathUtil::MapClippedRect(parent->DrawTransform(), parent_bounds);
Dana Jansensc46d3742015-06-18 01:33:144687 gfx::RectF parent_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104688 MathUtil::MapClippedRect(parent->ScreenSpaceTransform(), parent_bounds);
[email protected]94f206c12012-08-25 00:09:144689
danakjddaec912015-09-25 19:38:404690 gfx::RectF expected_parent_draw_rect(gfx::SizeF(parent->bounds()));
[email protected]fb661802013-03-25 01:59:324691 expected_parent_draw_rect.Scale(device_scale_factor);
4692 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4693 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144694
jaydasika8640f9f2015-11-10 01:34:364695 // Verify child and child2 transforms. They should match.
[email protected]fb661802013-03-25 01:59:324696 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594697 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4698 expected_child_transform.Translate(child->position().x(),
4699 child->position().y());
[email protected]fb661802013-03-25 01:59:324700 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444701 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:324702 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104703 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324704 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444705 child2->DrawTransform());
[email protected]fb661802013-03-25 01:59:324706 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104707 child2->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144708
jaydasika8640f9f2015-11-10 01:34:364709 // Verify results of transformed child and child2 rects. They should
[email protected]fb661802013-03-25 01:59:324710 // match.
danakjddaec912015-09-25 19:38:404711 gfx::RectF child_bounds(gfx::SizeF(child->bounds()));
[email protected]94f206c12012-08-25 00:09:144712
[email protected]fb661802013-03-25 01:59:324713 gfx::RectF child_draw_rect =
ajumad9432e32015-11-30 19:43:444714 MathUtil::MapClippedRect(child->DrawTransform(), child_bounds);
Dana Jansensc46d3742015-06-18 01:33:144715 gfx::RectF child_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104716 MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds);
[email protected]94f206c12012-08-25 00:09:144717
jaydasika8640f9f2015-11-10 01:34:364718 gfx::RectF child2_draw_rect =
ajumad9432e32015-11-30 19:43:444719 MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds);
jaydasika8640f9f2015-11-10 01:34:364720 gfx::RectF child2_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104721 MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds);
[email protected]f89f5632012-11-14 23:34:454722
danakjddaec912015-09-25 19:38:404723 gfx::RectF expected_child_draw_rect(child->position(),
4724 gfx::SizeF(child->bounds()));
[email protected]fb661802013-03-25 01:59:324725 expected_child_draw_rect.Scale(device_scale_factor);
4726 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4727 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
jaydasika8640f9f2015-11-10 01:34:364728 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect);
4729 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144730}
4731
enne637715732015-07-07 02:05:264732TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324733 // Verify draw and screen space transforms of layers in a surface.
[email protected]fb661802013-03-25 01:59:324734 gfx::Transform identity_matrix;
[email protected]fb661802013-03-25 01:59:324735 gfx::Transform perspective_matrix;
4736 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094737
[email protected]fb661802013-03-25 01:59:324738 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054739 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094740
enne637715732015-07-07 02:05:264741 LayerImpl* root = root_layer();
4742 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4743 gfx::PointF(), gfx::Size(100, 100), false, true,
4744 false);
4745 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364746 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264747 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4748 gfx::PointF(), gfx::Size(100, 100), false, true,
4749 false);
[email protected]9781afa2013-07-17 23:15:324750
enne637715732015-07-07 02:05:264751 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
4752 SetLayerPropertiesForTesting(perspective_surface,
[email protected]fb661802013-03-25 01:59:324753 perspective_matrix * scale_small_matrix,
enne637715732015-07-07 02:05:264754 gfx::Point3F(), gfx::PointF(2.f, 2.f),
4755 gfx::Size(10, 10), false, true, true);
4756 perspective_surface->SetDrawsContent(true);
[email protected]1b30e8e2012-12-21 02:59:094757
enne637715732015-07-07 02:05:264758 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
4759 SetLayerPropertiesForTesting(scale_surface, scale_small_matrix,
4760 gfx::Point3F(), gfx::PointF(2.f, 2.f),
4761 gfx::Size(10, 10), false, true, true);
4762 scale_surface->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284763
[email protected]fb661802013-03-25 01:59:324764 float device_scale_factor = 2.5f;
4765 float page_scale_factor = 3.f;
enne637715732015-07-07 02:05:264766 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4767 root);
[email protected]1b30e8e2012-12-21 02:59:094768
sohan.jyotie3bd6192014-10-13 07:13:594769 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4770 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
4771 perspective_surface);
4772 // Ideal scale is the max 2d scale component of the combined transform up to
4773 // the nearest render target. Here this includes the layer transform as well
4774 // as the device and page scale factors.
4775 gfx::Transform transform = scale_small_matrix;
4776 transform.Scale(device_scale_factor * page_scale_factor,
4777 device_scale_factor * page_scale_factor);
4778 gfx::Vector2dF scales =
4779 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4780 float max_2d_scale = std::max(scales.x(), scales.y());
4781 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
4782
4783 // The ideal scale will draw 1:1 with its render target space along
4784 // the larger-scale axis.
4785 gfx::Vector2dF target_space_transform_scales =
4786 MathUtil::ComputeTransform2dScaleComponents(
4787 scale_surface->draw_properties().target_space_transform, 0.f);
4788 EXPECT_FLOAT_EQ(max_2d_scale,
4789 std::max(target_space_transform_scales.x(),
4790 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094791
enne637715732015-07-07 02:05:264792 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]1b30e8e2012-12-21 02:59:094793
[email protected]fb661802013-03-25 01:59:324794 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594795 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4796 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324797 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
ajumad9432e32015-11-30 19:43:444798 parent->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094799
[email protected]fb661802013-03-25 01:59:324800 // The scale for the perspective surface is not known, so it is rendered 1:1
4801 // with the screen, and then scaled during drawing.
4802 gfx::Transform expected_perspective_surface_draw_transform;
4803 expected_perspective_surface_draw_transform.Translate(
4804 device_scale_factor * page_scale_factor *
4805 perspective_surface->position().x(),
4806 device_scale_factor * page_scale_factor *
4807 perspective_surface->position().y());
4808 expected_perspective_surface_draw_transform.PreconcatTransform(
4809 perspective_matrix);
4810 expected_perspective_surface_draw_transform.PreconcatTransform(
4811 scale_small_matrix);
4812 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594813 expected_perspective_surface_layer_draw_transform.Scale(
4814 device_scale_factor * page_scale_factor,
4815 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324816 EXPECT_TRANSFORMATION_MATRIX_EQ(
4817 expected_perspective_surface_draw_transform,
4818 perspective_surface->render_surface()->draw_transform());
4819 EXPECT_TRANSFORMATION_MATRIX_EQ(
4820 expected_perspective_surface_layer_draw_transform,
ajumad9432e32015-11-30 19:43:444821 perspective_surface->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094822}
4823
enne637715732015-07-07 02:05:264824TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294825 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264826 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294827 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4828
4829 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264830 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294831 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4832
enne637715732015-07-07 02:05:264833 LayerImpl* root = root_layer();
[email protected]35a99a12013-05-09 23:52:294834 root->SetBounds(gfx::Size(100, 100));
4835
enne637715732015-07-07 02:05:264836 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364837 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264838 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4839 gfx::PointF(), gfx::Size(100, 100), false, true,
4840 false);
[email protected]35a99a12013-05-09 23:52:294841
enne637715732015-07-07 02:05:264842 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:364843 child_scale->SetDrawsContent(true);
enne637715732015-07-07 02:05:264844 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4845 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4846 true, false);
[email protected]d600df7d2013-08-03 02:34:284847
[email protected]fb661802013-03-25 01:59:324848 float device_scale_factor = 2.5f;
4849 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214850
[email protected]989386c2013-07-18 21:37:234851 {
enne637715732015-07-07 02:05:264852 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4853 root);
[email protected]11ec92972012-11-10 03:06:214854
sohan.jyotie3bd6192014-10-13 07:13:594855 // The ideal scale is able to go below 1.
4856 float expected_ideal_scale =
4857 device_scale_factor * page_scale_factor * initial_parent_scale;
4858 EXPECT_LT(expected_ideal_scale, 1.f);
4859 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
[email protected]11ec92972012-11-10 03:06:214860
sohan.jyotie3bd6192014-10-13 07:13:594861 expected_ideal_scale = device_scale_factor * page_scale_factor *
4862 initial_parent_scale * initial_child_scale;
4863 EXPECT_LT(expected_ideal_scale, 1.f);
4864 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
[email protected]989386c2013-07-18 21:37:234865 }
[email protected]11ec92972012-11-10 03:06:214866}
4867
enne637715732015-07-07 02:05:264868TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:324869 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264870 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324871 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:264872
[email protected]fb661802013-03-25 01:59:324873 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264874 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324875 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:264876
enne637715732015-07-07 02:05:264877 LayerImpl* root = root_layer();
[email protected]35a99a12013-05-09 23:52:294878 root->SetBounds(gfx::Size(100, 100));
4879
enne637715732015-07-07 02:05:264880 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364881 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264882 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4883 gfx::PointF(), gfx::Size(100, 100), false, true,
4884 false);
[email protected]6a9cff92012-11-08 11:53:264885
enne637715732015-07-07 02:05:264886 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:364887 child_scale->SetDrawsContent(true);
enne637715732015-07-07 02:05:264888 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4889 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4890 true, false);
[email protected]d600df7d2013-08-03 02:34:284891
[email protected]989386c2013-07-18 21:37:234892 {
enne637715732015-07-07 02:05:264893 ExecuteCalculateDrawProperties(root);
[email protected]6a9cff92012-11-08 11:53:264894
sohan.jyotie3bd6192014-10-13 07:13:594895 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
4896 // Animating layers compute ideal scale in the same way as when
4897 // they are static.
4898 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
4899 child_scale);
[email protected]989386c2013-07-18 21:37:234900 }
[email protected]6a9cff92012-11-08 11:53:264901}
4902
[email protected]989386c2013-07-18 21:37:234903TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324904 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:264905
enneea850232015-07-27 16:43:124906 LayerImpl* parent = root_layer();
4907 parent->SetDrawsContent(true);
4908 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4909 gfx::PointF(), gfx::Size(30, 30), false, true,
[email protected]fb661802013-03-25 01:59:324910 true);
[email protected]94f206c12012-08-25 00:09:144911
enneea850232015-07-27 16:43:124912 LayerImpl* child = AddChildToRoot<LayerImpl>();
4913 child->SetDrawsContent(true);
4914 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4915 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4916 true, true);
[email protected]94f206c12012-08-25 00:09:144917
[email protected]fb661802013-03-25 01:59:324918 gfx::Transform replica_transform;
4919 replica_transform.Scale(1.0, -1.0);
enneea850232015-07-27 16:43:124920
4921 scoped_ptr<LayerImpl> replica =
4922 LayerImpl::Create(host_impl()->active_tree(), 7);
4923 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
4924 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4925 true, false);
danakja04855a2015-11-18 20:39:104926 child->SetReplicaLayer(std::move(replica));
[email protected]94f206c12012-08-25 00:09:144927
[email protected]fb661802013-03-25 01:59:324928 // This layer should end up in the same surface as child, with the same draw
4929 // and screen space transforms.
enneea850232015-07-27 16:43:124930 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
4931 duplicate_child_non_owner->SetDrawsContent(true);
4932 SetLayerPropertiesForTesting(duplicate_child_non_owner, identity_matrix,
4933 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4934 false, true, false);
[email protected]94f206c12012-08-25 00:09:144935
[email protected]fb661802013-03-25 01:59:324936 float device_scale_factor = 1.5f;
enneea850232015-07-27 16:43:124937 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144938
[email protected]fb661802013-03-25 01:59:324939 // We should have two render surfaces. The root's render surface and child's
4940 // render surface (it needs one because it has a replica layer).
enneea850232015-07-27 16:43:124941 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144942
[email protected]fb661802013-03-25 01:59:324943 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594944 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324945 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104946 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324947 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444948 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144949
[email protected]fb661802013-03-25 01:59:324950 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594951 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324952 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
ajumad9432e32015-11-30 19:43:444953 child->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144954
[email protected]fb661802013-03-25 01:59:324955 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:594956 expected_screen_space_transform.Scale(device_scale_factor,
4957 device_scale_factor);
4958 expected_screen_space_transform.Translate(child->position().x(),
4959 child->position().y());
[email protected]fb661802013-03-25 01:59:324960 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:104961 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144962
[email protected]fb661802013-03-25 01:59:324963 gfx::Transform expected_duplicate_child_draw_transform =
ajumad9432e32015-11-30 19:43:444964 child->DrawTransform();
4965 EXPECT_TRANSFORMATION_MATRIX_EQ(child->DrawTransform(),
4966 duplicate_child_non_owner->DrawTransform());
[email protected]fb661802013-03-25 01:59:324967 EXPECT_TRANSFORMATION_MATRIX_EQ(
ajumab6aa1c62015-12-01 21:01:104968 child->ScreenSpaceTransform(),
4969 duplicate_child_non_owner->ScreenSpaceTransform());
hush6b614212014-12-04 22:37:324970 EXPECT_EQ(child->drawable_content_rect(),
4971 duplicate_child_non_owner->drawable_content_rect());
Dana Jansensc46d3742015-06-18 01:33:144972 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
[email protected]94f206c12012-08-25 00:09:144973
[email protected]fb661802013-03-25 01:59:324974 gfx::Transform expected_render_surface_draw_transform;
4975 expected_render_surface_draw_transform.Translate(
4976 device_scale_factor * child->position().x(),
4977 device_scale_factor * child->position().y());
4978 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
4979 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144980
[email protected]fb661802013-03-25 01:59:324981 gfx::Transform expected_surface_draw_transform;
4982 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
4983 device_scale_factor * 2.f);
4984 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
4985 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144986
[email protected]fb661802013-03-25 01:59:324987 gfx::Transform expected_surface_screen_space_transform;
4988 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
4989 device_scale_factor * 2.f);
4990 EXPECT_TRANSFORMATION_MATRIX_EQ(
4991 expected_surface_screen_space_transform,
4992 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144993
[email protected]fb661802013-03-25 01:59:324994 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:264995 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
4996 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
4997 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:324998 EXPECT_TRANSFORMATION_MATRIX_EQ(
4999 expected_replica_draw_transform,
5000 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:145001
[email protected]fb661802013-03-25 01:59:325002 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265003 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
5004 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
5005 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325006 EXPECT_TRANSFORMATION_MATRIX_EQ(
5007 expected_replica_screen_space_transform,
5008 child->render_surface()->replica_screen_space_transform());
5009 EXPECT_TRANSFORMATION_MATRIX_EQ(
5010 expected_replica_screen_space_transform,
5011 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:475012}
5013
[email protected]989386c2013-07-18 21:37:235014TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325015 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
[email protected]fb661802013-03-25 01:59:325016 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:475017
enneea850232015-07-27 16:43:125018 LayerImpl* parent = root_layer();
5019 parent->SetDrawsContent(true);
5020 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
5021 gfx::PointF(), gfx::Size(33, 31), false, true,
[email protected]fb661802013-03-25 01:59:325022 true);
[email protected]904e9132012-11-01 00:12:475023
enneea850232015-07-27 16:43:125024 LayerImpl* child = AddChildToRoot<LayerImpl>();
5025 child->SetDrawsContent(true);
5026 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
5027 gfx::PointF(), gfx::Size(13, 11), false, true,
[email protected]fb661802013-03-25 01:59:325028 true);
[email protected]904e9132012-11-01 00:12:475029
[email protected]fb661802013-03-25 01:59:325030 gfx::Transform replica_transform;
5031 replica_transform.Scale(1.0, -1.0);
enneea850232015-07-27 16:43:125032 scoped_ptr<LayerImpl> replica =
5033 LayerImpl::Create(host_impl()->active_tree(), 7);
5034 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
5035 gfx::PointF(), gfx::Size(13, 11), false, true,
5036 false);
danakja04855a2015-11-18 20:39:105037 child->SetReplicaLayer(std::move(replica));
[email protected]d600df7d2013-08-03 02:34:285038
[email protected]873639e2013-07-24 19:56:315039 float device_scale_factor = 1.7f;
enneea850232015-07-27 16:43:125040 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]904e9132012-11-01 00:12:475041
[email protected]fb661802013-03-25 01:59:325042 // We should have two render surfaces. The root's render surface and child's
5043 // render surface (it needs one because it has a replica layer).
enneea850232015-07-27 16:43:125044 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]904e9132012-11-01 00:12:475045
[email protected]fb661802013-03-25 01:59:325046 gfx::Transform identity_transform;
[email protected]fb661802013-03-25 01:59:325047 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5048 child->render_surface()->draw_transform());
5049 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5050 child->render_surface()->draw_transform());
5051 EXPECT_TRANSFORMATION_MATRIX_EQ(
5052 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:475053
[email protected]fb661802013-03-25 01:59:325054 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265055 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325056 EXPECT_TRANSFORMATION_MATRIX_EQ(
5057 expected_replica_draw_transform,
5058 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:475059
[email protected]fb661802013-03-25 01:59:325060 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265061 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325062 EXPECT_TRANSFORMATION_MATRIX_EQ(
5063 expected_replica_screen_space_transform,
5064 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145065}
5066
[email protected]989386c2013-07-18 21:37:235067TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
loysoa6edaaff2015-05-25 03:26:445068 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5069 scoped_refptr<Layer> child = Layer::Create(layer_settings());
5070 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
5071 scoped_refptr<Layer> mask_layer = Layer::Create(layer_settings());
5072 scoped_refptr<Layer> replica_layer = Layer::Create(layer_settings());
[email protected]94f206c12012-08-25 00:09:145073
[email protected]fb661802013-03-25 01:59:325074 grand_child->SetReplicaLayer(replica_layer.get());
5075 child->AddChild(grand_child.get());
5076 child->SetMaskLayer(mask_layer.get());
5077 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:145078
ennea7b43c32015-06-18 20:01:335079 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:285080
[email protected]fb661802013-03-25 01:59:325081 int nonexistent_id = -1;
Daniel Chengeea98042014-08-26 00:28:105082 EXPECT_EQ(root.get(),
[email protected]fb661802013-03-25 01:59:325083 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
Daniel Chengeea98042014-08-26 00:28:105084 EXPECT_EQ(child.get(),
[email protected]fb661802013-03-25 01:59:325085 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
5086 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105087 grand_child.get(),
[email protected]fb661802013-03-25 01:59:325088 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
5089 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105090 mask_layer.get(),
[email protected]fb661802013-03-25 01:59:325091 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
5092 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105093 replica_layer.get(),
[email protected]fb661802013-03-25 01:59:325094 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
5095 EXPECT_EQ(
5096 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:145097}
5098
[email protected]989386c2013-07-18 21:37:235099TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
loysoa6edaaff2015-05-25 03:26:445100 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5101 scoped_refptr<Layer> child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:325102 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loysoa6edaaff2015-05-25 03:26:445103 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]498ec6e0e2012-11-30 18:24:575104
[email protected]fb661802013-03-25 01:59:325105 const gfx::Transform identity_matrix;
5106 SetLayerPropertiesForTesting(root.get(),
5107 identity_matrix,
[email protected]a2566412014-06-05 03:14:205108 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325109 gfx::PointF(),
5110 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575111 true,
[email protected]fb661802013-03-25 01:59:325112 false);
5113 SetLayerPropertiesForTesting(child.get(),
5114 identity_matrix,
[email protected]a2566412014-06-05 03:14:205115 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325116 gfx::PointF(),
5117 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575118 true,
[email protected]fb661802013-03-25 01:59:325119 false);
5120 SetLayerPropertiesForTesting(grand_child.get(),
5121 identity_matrix,
[email protected]a2566412014-06-05 03:14:205122 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325123 gfx::PointF(),
5124 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575125 true,
[email protected]fb661802013-03-25 01:59:325126 false);
[email protected]498ec6e0e2012-11-30 18:24:575127
[email protected]fb661802013-03-25 01:59:325128 root->AddChild(child);
5129 child->AddChild(grand_child);
5130 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:575131
ennea7b43c32015-06-18 20:01:335132 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:285133
[email protected]fb661802013-03-25 01:59:325134 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:575135
ennec1332992015-08-24 19:45:095136 EXPECT_FALSE(child->has_render_surface());
[email protected]498ec6e0e2012-11-30 18:24:575137}
5138
[email protected]989386c2013-07-18 21:37:235139TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
khushalsagarb64b360d2015-10-21 19:25:165140 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455141 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565142 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:485143 FakeLayerTreeHostImpl host_impl(host()->settings(), &task_runner_provider,
5144 &shared_bitmap_manager, &task_graph_runner);
[email protected]f90fc412013-03-30 20:13:165145 host_impl.CreatePendingTree();
5146 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5147
5148 const gfx::Transform identity_matrix;
awoloszyne83f28c2014-12-22 15:40:005149 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5150 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]f90fc412013-03-30 20:13:165151 false);
5152 root->SetDrawsContent(true);
5153
5154 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005155 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5156 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]f90fc412013-03-30 20:13:165157 false);
5158 child->SetDrawsContent(true);
5159 child->SetOpacity(0.0f);
5160
5161 // Add opacity animation.
loyso968163c92016-01-04 23:18:485162 if (layer_settings().use_compositor_animation_timelines) {
5163 scoped_refptr<AnimationTimeline> timeline =
5164 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
5165 host_impl.animation_host()->AddAnimationTimeline(timeline);
5166
5167 AddOpacityTransitionToLayerWithPlayer(child->id(), timeline, 10.0, 0.0f,
5168 1.0f, false);
5169 } else {
5170 AddOpacityTransitionToController(child->layer_animation_controller(), 10.0,
5171 0.0f, 1.0f, false);
5172 }
[email protected]f90fc412013-03-30 20:13:165173
danakja04855a2015-11-18 20:39:105174 root->AddChild(std::move(child));
awoloszyne83f28c2014-12-22 15:40:005175 root->SetHasRenderSurface(true);
[email protected]f90fc412013-03-30 20:13:165176
[email protected]c0ae06c12013-06-24 18:32:195177 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:445178 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]7aad55f2013-07-26 11:25:535179 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:445180 root.get(), root->bounds(), &render_surface_layer_list,
5181 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535182 inputs.can_adjust_raster_scales = true;
5183 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:165184
5185 // We should have one render surface and two layers. The child
5186 // layer should be included even though it is transparent.
5187 ASSERT_EQ(1u, render_surface_layer_list.size());
5188 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
jaydasika86654512016-01-27 17:05:075189
5190 // If the root itself is hidden, the child should not be drawn even if it has
5191 // an animating opacity.
jaydasikae99e83e2016-01-29 19:35:405192 root->SetOpacity(0.0f);
jaydasika86654512016-01-27 17:05:075193 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
5194 LayerImplList render_surface_layer_list2;
5195 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
5196 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2(
5197 root.get(), root->bounds(), &render_surface_layer_list2,
5198 root->layer_tree_impl()->current_render_surface_list_id());
5199 inputs2.can_adjust_raster_scales = true;
5200 LayerTreeHostCommon::CalculateDrawProperties(&inputs2);
5201
5202 LayerImpl* child_ptr = root->layer_tree_impl()->LayerById(2);
5203 EffectTree tree = root->layer_tree_impl()->property_trees()->effect_tree;
5204 EffectNode* node = tree.Node(child_ptr->effect_tree_index());
5205 EXPECT_FALSE(node->data.is_drawn);
jaydasikae99e83e2016-01-29 19:35:405206
5207 // A layer should be drawn and it should contribute to drawn surface when
5208 // it has animating opacity even if it has opacity 0.
5209 root->SetOpacity(1.0f);
5210 child_ptr->SetOpacity(0.0f);
5211 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
5212 LayerImplList render_surface_layer_list3;
5213 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
5214 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3(
5215 root.get(), root->bounds(), &render_surface_layer_list3,
5216 root->layer_tree_impl()->current_render_surface_list_id());
5217 inputs3.can_adjust_raster_scales = true;
5218 LayerTreeHostCommon::CalculateDrawProperties(&inputs3);
5219
5220 child_ptr = root->layer_tree_impl()->LayerById(2);
5221 tree = root->layer_tree_impl()->property_trees()->effect_tree;
5222 node = tree.Node(child_ptr->effect_tree_index());
5223 EXPECT_TRUE(node->data.is_drawn);
5224 EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index()));
[email protected]f90fc412013-03-30 20:13:165225}
5226
loyso968163c92016-01-04 23:18:485227class LayerTreeSettingsForLCDTextTest : public LayerTreeSettings {
5228 public:
5229 LayerTreeSettingsForLCDTextTest() {
5230 use_compositor_animation_timelines = true;
5231 }
5232};
5233
danakj3f76ace2014-11-18 16:56:005234using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
enne637715732015-07-07 02:05:265235class LCDTextTest : public LayerTreeHostCommonTestBase,
5236 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:365237 public:
5238 LCDTextTest()
loyso968163c92016-01-04 23:18:485239 : LayerTreeHostCommonTestBase(LayerTreeSettingsForLCDTextTest()),
5240 host_impl_(LayerTreeSettingsForLCDTextTest(),
5241 &task_runner_provider_,
khushalsagarb64b360d2015-10-21 19:25:165242 &shared_bitmap_manager_,
5243 &task_graph_runner_),
enneaf5bda32015-02-19 01:27:365244 root_(nullptr),
5245 child_(nullptr),
5246 grand_child_(nullptr) {}
5247
loyso968163c92016-01-04 23:18:485248 scoped_refptr<AnimationTimeline> timeline() { return timeline_; }
5249
[email protected]fb661802013-03-25 01:59:325250 protected:
dcheng93a52eb2014-12-23 02:14:235251 void SetUp() override {
loyso968163c92016-01-04 23:18:485252 if (layer_settings().use_compositor_animation_timelines) {
5253 timeline_ =
5254 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
5255 host_impl_.animation_host()->AddAnimationTimeline(timeline_);
5256 }
5257
[email protected]fb661802013-03-25 01:59:325258 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
danakj3f76ace2014-11-18 16:56:005259 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
[email protected]10aabcc32012-12-13 09:18:595260
enneaf5bda32015-02-19 01:27:365261 scoped_ptr<LayerImpl> root_ptr =
5262 LayerImpl::Create(host_impl_.active_tree(), 1);
5263 scoped_ptr<LayerImpl> child_ptr =
5264 LayerImpl::Create(host_impl_.active_tree(), 2);
5265 scoped_ptr<LayerImpl> grand_child_ptr =
5266 LayerImpl::Create(host_impl_.active_tree(), 3);
5267
5268 // Stash raw pointers to look at later.
5269 root_ = root_ptr.get();
5270 child_ = child_ptr.get();
5271 grand_child_ = grand_child_ptr.get();
5272
danakja04855a2015-11-18 20:39:105273 child_->AddChild(std::move(grand_child_ptr));
5274 root_->AddChild(std::move(child_ptr));
5275 host_impl_.active_tree()->SetRootLayer(std::move(root_ptr));
[email protected]10aabcc32012-12-13 09:18:595276
fmalita51b5e202014-11-18 20:11:505277 root_->SetContentsOpaque(true);
5278 child_->SetContentsOpaque(true);
5279 grand_child_->SetContentsOpaque(true);
5280
jaydasika3f930c12015-06-30 15:18:255281 root_->SetDrawsContent(true);
5282 child_->SetDrawsContent(true);
5283 grand_child_->SetDrawsContent(true);
5284
[email protected]fb661802013-03-25 01:59:325285 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365286 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
5287 gfx::PointF(), gfx::Size(1, 1), true, false,
5288 true);
5289 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
5290 gfx::PointF(), gfx::Size(1, 1), true, false,
5291 std::tr1::get<2>(GetParam()));
5292 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
5293 gfx::PointF(), gfx::Size(1, 1), true, false,
[email protected]fb661802013-03-25 01:59:325294 false);
[email protected]fb661802013-03-25 01:59:325295 }
[email protected]10aabcc32012-12-13 09:18:595296
[email protected]fb661802013-03-25 01:59:325297 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005298 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:365299
khushalsagarb64b360d2015-10-21 19:25:165300 FakeImplTaskRunnerProvider task_runner_provider_;
enneaf5bda32015-02-19 01:27:365301 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:475302 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:365303 FakeLayerTreeHostImpl host_impl_;
loyso968163c92016-01-04 23:18:485304 scoped_refptr<AnimationTimeline> timeline_;
enneaf5bda32015-02-19 01:27:365305
5306 LayerImpl* root_;
5307 LayerImpl* child_;
5308 LayerImpl* grand_child_;
[email protected]10aabcc32012-12-13 09:18:595309};
5310
[email protected]fb661802013-03-25 01:59:325311TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005312 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5313 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5314
[email protected]fb661802013-03-25 01:59:325315 // Case 1: Identity transform.
5316 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365317 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005318 layers_always_allowed_lcd_text_);
5319 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5320 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5321 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595322
[email protected]fb661802013-03-25 01:59:325323 // Case 2: Integral translation.
5324 gfx::Transform integral_translation;
5325 integral_translation.Translate(1.0, 2.0);
5326 child_->SetTransform(integral_translation);
jaydasika3f930c12015-06-30 15:18:255327 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365328 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005329 layers_always_allowed_lcd_text_);
5330 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5331 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5332 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595333
[email protected]fb661802013-03-25 01:59:325334 // Case 3: Non-integral translation.
5335 gfx::Transform non_integral_translation;
5336 non_integral_translation.Translate(1.5, 2.5);
5337 child_->SetTransform(non_integral_translation);
jaydasika3f930c12015-06-30 15:18:255338 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365339 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005340 layers_always_allowed_lcd_text_);
5341 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5342 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5343 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595344
[email protected]fb661802013-03-25 01:59:325345 // Case 4: Rotation.
5346 gfx::Transform rotation;
5347 rotation.Rotate(10.0);
5348 child_->SetTransform(rotation);
jaydasika3f930c12015-06-30 15:18:255349 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365350 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005351 layers_always_allowed_lcd_text_);
5352 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5353 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5354 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595355
[email protected]fb661802013-03-25 01:59:325356 // Case 5: Scale.
5357 gfx::Transform scale;
5358 scale.Scale(2.0, 2.0);
5359 child_->SetTransform(scale);
jaydasika3f930c12015-06-30 15:18:255360 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365361 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005362 layers_always_allowed_lcd_text_);
5363 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5364 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5365 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595366
[email protected]fb661802013-03-25 01:59:325367 // Case 6: Skew.
5368 gfx::Transform skew;
nainar8ca8ee62015-09-03 01:04:105369 skew.Skew(10.0, 0.0);
[email protected]fb661802013-03-25 01:59:325370 child_->SetTransform(skew);
jaydasika3f930c12015-06-30 15:18:255371 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365372 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005373 layers_always_allowed_lcd_text_);
5374 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5375 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5376 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595377
[email protected]fb661802013-03-25 01:59:325378 // Case 7: Translucent.
5379 child_->SetTransform(identity_matrix);
jaydasika3f930c12015-06-30 15:18:255380 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]fb661802013-03-25 01:59:325381 child_->SetOpacity(0.5f);
enneaf5bda32015-02-19 01:27:365382 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005383 layers_always_allowed_lcd_text_);
5384 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5385 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5386 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595387
[email protected]fb661802013-03-25 01:59:325388 // Case 8: Sanity check: restore transform and opacity.
5389 child_->SetTransform(identity_matrix);
jaydasika3f930c12015-06-30 15:18:255390 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]fb661802013-03-25 01:59:325391 child_->SetOpacity(1.f);
enneaf5bda32015-02-19 01:27:365392 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005393 layers_always_allowed_lcd_text_);
5394 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5395 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5396 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalita51b5e202014-11-18 20:11:505397
5398 // Case 9: Non-opaque content.
5399 child_->SetContentsOpaque(false);
enneaf5bda32015-02-19 01:27:365400 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505401 layers_always_allowed_lcd_text_);
5402 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5403 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5404 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5405
5406 // Case 10: Sanity check: restore content opaqueness.
5407 child_->SetContentsOpaque(true);
enneaf5bda32015-02-19 01:27:365408 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505409 layers_always_allowed_lcd_text_);
5410 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5411 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5412 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595413}
5414
[email protected]fd9a3b6d2013-08-03 00:46:175415TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005416 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
fmalitafcd926a2015-05-13 20:19:335417 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
danakj3f76ace2014-11-18 16:56:005418
[email protected]fb661802013-03-25 01:59:325419 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
enneaf5bda32015-02-19 01:27:365420 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005421 layers_always_allowed_lcd_text_);
5422 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5423 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5424 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595425
[email protected]fb661802013-03-25 01:59:325426 // Add opacity animation.
5427 child_->SetOpacity(0.9f);
jaydasika3f930c12015-06-30 15:18:255428 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:485429 if (layer_settings().use_compositor_animation_timelines) {
5430 AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f,
5431 0.1f, false);
5432 } else {
5433 AddOpacityTransitionToController(child_->layer_animation_controller(), 10.0,
5434 0.9f, 0.1f, false);
5435 }
enneaf5bda32015-02-19 01:27:365436 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005437 layers_always_allowed_lcd_text_);
fmalitafcd926a2015-05-13 20:19:335438 // Text LCD should be adjusted while animation is active.
5439 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5440 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5441 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5442}
5443
5444TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
5445 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5446 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5447
5448 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
5449 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5450 layers_always_allowed_lcd_text_);
danakj3f76ace2014-11-18 16:56:005451 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5452 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5453 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalitafcd926a2015-05-13 20:19:335454
5455 // Mark contents non-opaque within the first animation frame.
5456 child_->SetContentsOpaque(false);
loyso968163c92016-01-04 23:18:485457 if (layer_settings().use_compositor_animation_timelines) {
5458 AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f,
5459 0.1f, false);
5460 } else {
5461 AddOpacityTransitionToController(child_->layer_animation_controller(), 10.0,
5462 0.9f, 0.1f, false);
5463 }
fmalitafcd926a2015-05-13 20:19:335464 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5465 layers_always_allowed_lcd_text_);
5466 // LCD text should be disabled for non-opaque layers even during animations.
5467 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5468 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5469 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595470}
5471
5472INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5473 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005474 testing::Combine(testing::Bool(),
5475 testing::Bool(),
5476 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595477
[email protected]989386c2013-07-18 21:37:235478TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:165479 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455480 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565481 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165482 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565483 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195484 host_impl.CreatePendingTree();
5485 const gfx::Transform identity_matrix;
5486
5487 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:005488 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5489 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]c0ae06c12013-06-24 18:32:195490 false);
5491 root->SetDrawsContent(true);
5492
5493 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005494 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5495 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:195496 false);
5497 child->SetDrawsContent(true);
5498
5499 scoped_ptr<LayerImpl> grand_child =
5500 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:005501 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5502 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5503 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:195504 grand_child->SetDrawsContent(true);
5505 grand_child->SetHideLayerAndSubtree(true);
5506
danakja04855a2015-11-18 20:39:105507 child->AddChild(std::move(grand_child));
5508 root->AddChild(std::move(child));
awoloszyne83f28c2014-12-22 15:40:005509 root->SetHasRenderSurface(true);
[email protected]c0ae06c12013-06-24 18:32:195510
5511 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:445512 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]7aad55f2013-07-26 11:25:535513 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:445514 root.get(), root->bounds(), &render_surface_layer_list,
5515 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535516 inputs.can_adjust_raster_scales = true;
5517 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195518
5519 // We should have one render surface and two layers. The grand child has
5520 // hidden itself.
5521 ASSERT_EQ(1u, render_surface_layer_list.size());
5522 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235523 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
5524 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195525}
5526
[email protected]989386c2013-07-18 21:37:235527TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
khushalsagarb64b360d2015-10-21 19:25:165528 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455529 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565530 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165531 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565532 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195533 host_impl.CreatePendingTree();
5534 const gfx::Transform identity_matrix;
5535
5536 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:005537 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5538 gfx::PointF(), gfx::Size(50, 50), true, false,
5539 true);
[email protected]c0ae06c12013-06-24 18:32:195540 root->SetDrawsContent(true);
5541
5542 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005543 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5544 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:195545 false);
5546 child->SetDrawsContent(true);
5547 child->SetHideLayerAndSubtree(true);
5548
5549 scoped_ptr<LayerImpl> grand_child =
5550 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:005551 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5552 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5553 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:195554 grand_child->SetDrawsContent(true);
5555
danakja04855a2015-11-18 20:39:105556 child->AddChild(std::move(grand_child));
5557 root->AddChild(std::move(child));
[email protected]c0ae06c12013-06-24 18:32:195558
5559 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:445560 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]7aad55f2013-07-26 11:25:535561 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:445562 root.get(), root->bounds(), &render_surface_layer_list,
5563 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535564 inputs.can_adjust_raster_scales = true;
5565 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195566
5567 // We should have one render surface and one layers. The child has
5568 // hidden itself and the grand child.
5569 ASSERT_EQ(1u, render_surface_layer_list.size());
5570 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235571 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:195572}
5573
[email protected]30fe19ff2013-07-04 00:54:455574void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
5575
[email protected]989386c2013-07-18 21:37:235576TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165577 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455578 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565579 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165580 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565581 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455582 host_impl.CreatePendingTree();
5583 const gfx::Transform identity_matrix;
5584
weiliangc51fb255d2015-07-24 15:32:305585 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5586 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5587 gfx::PointF(), gfx::Size(50, 50), true, false,
5588 true);
5589 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455590
weiliangc51fb255d2015-07-24 15:32:305591 scoped_ptr<LayerImpl> copy_grand_parent =
5592 LayerImpl::Create(host_impl.pending_tree(), 2);
5593 SetLayerPropertiesForTesting(copy_grand_parent.get(), identity_matrix,
5594 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5595 true, false, false);
5596 copy_grand_parent->SetDrawsContent(true);
5597 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455598
weiliangc51fb255d2015-07-24 15:32:305599 scoped_ptr<LayerImpl> copy_parent =
5600 LayerImpl::Create(host_impl.pending_tree(), 3);
5601 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
5602 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5603 true, false, true);
5604 copy_parent->SetDrawsContent(true);
5605 LayerImpl* copy_parent_layer = copy_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455606
weiliangc51fb255d2015-07-24 15:32:305607 scoped_ptr<LayerImpl> copy_request =
5608 LayerImpl::Create(host_impl.pending_tree(), 4);
5609 SetLayerPropertiesForTesting(copy_request.get(), identity_matrix,
5610 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5611 true, false, true);
5612 copy_request->SetDrawsContent(true);
5613 LayerImpl* copy_layer = copy_request.get();
[email protected]30fe19ff2013-07-04 00:54:455614
weiliangc51fb255d2015-07-24 15:32:305615 scoped_ptr<LayerImpl> copy_child =
5616 LayerImpl::Create(host_impl.pending_tree(), 5);
5617 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
5618 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5619 true, false, false);
5620 copy_child->SetDrawsContent(true);
5621 LayerImpl* copy_child_layer = copy_child.get();
[email protected]30fe19ff2013-07-04 00:54:455622
jaydasika86654512016-01-27 17:05:075623 scoped_ptr<LayerImpl> copy_grand_child =
thakise53c5272016-01-24 01:20:405624 LayerImpl::Create(host_impl.pending_tree(), 6);
jaydasika86654512016-01-27 17:05:075625 SetLayerPropertiesForTesting(copy_grand_child.get(), identity_matrix,
5626 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5627 true, false, false);
5628 copy_child->SetDrawsContent(true);
5629 LayerImpl* copy_grand_child_layer = copy_grand_child.get();
5630
5631 scoped_ptr<LayerImpl> copy_grand_parent_sibling_before =
5632 LayerImpl::Create(host_impl.pending_tree(), 7);
[email protected]ac020122013-07-12 23:45:535633 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
weiliangc51fb255d2015-07-24 15:32:305634 identity_matrix, gfx::Point3F(), gfx::PointF(),
5635 gfx::Size(40, 40), true, false, false);
5636 copy_grand_parent_sibling_before->SetDrawsContent(true);
5637 LayerImpl* copy_grand_parent_sibling_before_layer =
5638 copy_grand_parent_sibling_before.get();
[email protected]ac020122013-07-12 23:45:535639
weiliangc51fb255d2015-07-24 15:32:305640 scoped_ptr<LayerImpl> copy_grand_parent_sibling_after =
jaydasika86654512016-01-27 17:05:075641 LayerImpl::Create(host_impl.pending_tree(), 8);
[email protected]ac020122013-07-12 23:45:535642 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
weiliangc51fb255d2015-07-24 15:32:305643 identity_matrix, gfx::Point3F(), gfx::PointF(),
5644 gfx::Size(40, 40), true, false, false);
5645 copy_grand_parent_sibling_after->SetDrawsContent(true);
5646 LayerImpl* copy_grand_parent_sibling_after_layer =
5647 copy_grand_parent_sibling_after.get();
[email protected]ac020122013-07-12 23:45:535648
jaydasika86654512016-01-27 17:05:075649 copy_child->AddChild(std::move(copy_grand_child));
danakja04855a2015-11-18 20:39:105650 copy_request->AddChild(std::move(copy_child));
5651 copy_parent->AddChild(std::move(copy_request));
5652 copy_grand_parent->AddChild(std::move(copy_parent));
5653 root->AddChild(std::move(copy_grand_parent_sibling_before));
5654 root->AddChild(std::move(copy_grand_parent));
5655 root->AddChild(std::move(copy_grand_parent_sibling_after));
[email protected]d600df7d2013-08-03 02:34:285656
[email protected]30fe19ff2013-07-04 00:54:455657 // Hide the copy_grand_parent and its subtree. But make a copy request in that
jaydasika86654512016-01-27 17:05:075658 // hidden subtree on copy_layer. Also hide the copy grand child and its
5659 // subtree.
weiliangc51fb255d2015-07-24 15:32:305660 copy_grand_parent_layer->SetHideLayerAndSubtree(true);
5661 copy_grand_parent_sibling_before_layer->SetHideLayerAndSubtree(true);
5662 copy_grand_parent_sibling_after_layer->SetHideLayerAndSubtree(true);
jaydasika86654512016-01-27 17:05:075663 copy_grand_child_layer->SetHideLayerAndSubtree(true);
weiliangc51fb255d2015-07-24 15:32:305664
vmpstra370ef52015-11-18 10:41:285665 std::vector<scoped_ptr<CopyOutputRequest>> copy_requests;
weiliangc51fb255d2015-07-24 15:32:305666 copy_requests.push_back(
5667 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5668 copy_layer->PassCopyRequests(&copy_requests);
[email protected]30fe19ff2013-07-04 00:54:455669 EXPECT_TRUE(copy_layer->HasCopyRequest());
5670
weiliangc51fb255d2015-07-24 15:32:305671 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:445672 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
weiliangc51fb255d2015-07-24 15:32:305673 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:445674 root.get(), root->bounds(), &render_surface_layer_list,
5675 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535676 inputs.can_adjust_raster_scales = true;
5677 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455678
sunxded58688e2016-01-11 21:01:025679 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
5680 EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0);
5681 EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0);
5682 EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0);
[email protected]ac020122013-07-12 23:45:535683
jaydasika86654512016-01-27 17:05:075684 // We should have four render surfaces, one for the root, one for the grand
5685 // parent since it has opacity and two drawing descendants, one for the parent
[email protected]30fe19ff2013-07-04 00:54:455686 // since it owns a surface, and one for the copy_layer.
jaydasika86654512016-01-27 17:05:075687 ASSERT_EQ(4u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:235688 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
jaydasika86654512016-01-27 17:05:075689 EXPECT_EQ(copy_grand_parent_layer->id(),
5690 render_surface_layer_list.at(1)->id());
5691 EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id());
5692 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id());
[email protected]30fe19ff2013-07-04 00:54:455693
jaydasika86654512016-01-27 17:05:075694 // The root render surface should have 2 contributing layers.
[email protected]30fe19ff2013-07-04 00:54:455695 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235696 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
jaydasika86654512016-01-27 17:05:075697 EXPECT_EQ(copy_grand_parent_layer->id(),
[email protected]989386c2013-07-18 21:37:235698 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:455699
[email protected]7392c7b2014-02-07 08:28:285700 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:455701 // appear in its list, since it needs to be drawn for the copy request.
weiliangc51fb255d2015-07-24 15:32:305702 ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size());
[email protected]30fe19ff2013-07-04 00:54:455703 EXPECT_EQ(copy_layer->id(),
jaydasika86654512016-01-27 17:05:075704 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455705
5706 // The copy_layer's render surface should have two contributing layers.
5707 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
5708 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:235709 copy_layer->render_surface()->layer_list().at(0)->id());
weiliangc51fb255d2015-07-24 15:32:305710 EXPECT_EQ(copy_child_layer->id(),
[email protected]989386c2013-07-18 21:37:235711 copy_layer->render_surface()->layer_list().at(1)->id());
jaydasika86654512016-01-27 17:05:075712
5713 // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden,
5714 // but the copy_layer and copy_child should be drawn for the copy request.
5715 // copy grand child should not be drawn as its hidden even in the copy
5716 // request.
5717 EffectTree tree = root->layer_tree_impl()->property_trees()->effect_tree;
5718 EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index());
5719 EXPECT_FALSE(node->data.is_drawn);
5720 node = tree.Node(copy_parent_layer->effect_tree_index());
5721 EXPECT_FALSE(node->data.is_drawn);
5722 node = tree.Node(copy_layer->effect_tree_index());
5723 EXPECT_TRUE(node->data.is_drawn);
5724 node = tree.Node(copy_child_layer->effect_tree_index());
5725 EXPECT_TRUE(node->data.is_drawn);
5726 node = tree.Node(copy_grand_child_layer->effect_tree_index());
5727 EXPECT_FALSE(node->data.is_drawn);
5728
5729 // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its
5730 // actually hidden.
5731 EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface());
[email protected]30fe19ff2013-07-04 00:54:455732}
5733
[email protected]989386c2013-07-18 21:37:235734TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165735 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455736 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565737 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165738 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565739 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455740 host_impl.CreatePendingTree();
5741 const gfx::Transform identity_matrix;
5742
weiliangc51fb255d2015-07-24 15:32:305743 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5744 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5745 gfx::PointF(), gfx::Size(50, 50), true, false,
5746 true);
5747 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455748
weiliangc51fb255d2015-07-24 15:32:305749 scoped_ptr<LayerImpl> copy_parent =
5750 LayerImpl::Create(host_impl.pending_tree(), 2);
5751 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
5752 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
5753 false, false);
5754 copy_parent->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455755 copy_parent->SetMasksToBounds(true);
5756
weiliangc51fb255d2015-07-24 15:32:305757 scoped_ptr<LayerImpl> copy_layer =
5758 LayerImpl::Create(host_impl.pending_tree(), 3);
5759 SetLayerPropertiesForTesting(copy_layer.get(), identity_matrix,
5760 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5761 true, false, true);
5762 copy_layer->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455763
weiliangc51fb255d2015-07-24 15:32:305764 scoped_ptr<LayerImpl> copy_child =
5765 LayerImpl::Create(host_impl.pending_tree(), 4);
5766 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
5767 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5768 true, false, false);
5769 copy_child->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455770
vmpstra370ef52015-11-18 10:41:285771 std::vector<scoped_ptr<CopyOutputRequest>> copy_requests;
weiliangc51fb255d2015-07-24 15:32:305772 copy_requests.push_back(
5773 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5774 copy_layer->PassCopyRequests(&copy_requests);
[email protected]30fe19ff2013-07-04 00:54:455775 EXPECT_TRUE(copy_layer->HasCopyRequest());
5776
danakja04855a2015-11-18 20:39:105777 copy_layer->AddChild(std::move(copy_child));
5778 copy_parent->AddChild(std::move(copy_layer));
5779 root->AddChild(std::move(copy_parent));
weiliangc51fb255d2015-07-24 15:32:305780
5781 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:445782 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
weiliangc51fb255d2015-07-24 15:32:305783 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:445784 root.get(), root->bounds(), &render_surface_layer_list,
5785 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535786 inputs.can_adjust_raster_scales = true;
5787 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455788
xjze19f76402015-11-06 21:48:445789 // We should have two render surface, as the others are clipped out.
5790 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:235791 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455792
xjze19f76402015-11-06 21:48:445793 // The root render surface should only have 2 contributing layer, since the
[email protected]30fe19ff2013-07-04 00:54:455794 // other layers are empty/clipped away.
xjze19f76402015-11-06 21:48:445795 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235796 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455797}
5798
[email protected]11a07b102013-07-24 17:33:195799TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
khushalsagarb64b360d2015-10-21 19:25:165800 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455801 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565802 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165803 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565804 &task_graph_runner);
[email protected]11a07b102013-07-24 17:33:195805 host_impl.CreatePendingTree();
5806 const gfx::Transform identity_matrix;
5807
loysoa6edaaff2015-05-25 03:26:445808 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]11a07b102013-07-24 17:33:195809 SetLayerPropertiesForTesting(root.get(),
5810 identity_matrix,
[email protected]a2566412014-06-05 03:14:205811 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:195812 gfx::PointF(),
5813 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575814 true,
[email protected]11a07b102013-07-24 17:33:195815 false);
5816 root->SetIsDrawable(true);
5817
5818 // The surface is moved slightly outside of the viewport.
loysoa6edaaff2015-05-25 03:26:445819 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
[email protected]11a07b102013-07-24 17:33:195820 SetLayerPropertiesForTesting(surface.get(),
5821 identity_matrix,
[email protected]a2566412014-06-05 03:14:205822 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:195823 gfx::PointF(-10, -20),
5824 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:575825 true,
[email protected]11a07b102013-07-24 17:33:195826 false);
5827 surface->SetForceRenderSurface(true);
5828
loysoa6edaaff2015-05-25 03:26:445829 scoped_refptr<Layer> surface_child = Layer::Create(layer_settings());
[email protected]11a07b102013-07-24 17:33:195830 SetLayerPropertiesForTesting(surface_child.get(),
5831 identity_matrix,
[email protected]a2566412014-06-05 03:14:205832 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:195833 gfx::PointF(),
5834 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575835 true,
[email protected]11a07b102013-07-24 17:33:195836 false);
5837 surface_child->SetIsDrawable(true);
5838
5839 surface->AddChild(surface_child);
5840 root->AddChild(surface);
5841
ennea7b43c32015-06-18 20:01:335842 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:285843
enne1e1008c2015-08-21 00:45:465844 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(root.get(),
5845 root->bounds());
[email protected]7aad55f2013-07-26 11:25:535846 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:195847
danakj64767d902015-06-19 00:10:435848 // The visible_layer_rect for the |surface_child| should not be clipped by
[email protected]11a07b102013-07-24 17:33:195849 // the viewport.
5850 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
enne6c281f6e2015-08-18 23:23:005851 surface_child->visible_rect_from_property_trees().ToString());
[email protected]11a07b102013-07-24 17:33:195852}
5853
[email protected]420fdf6e2013-08-26 20:36:385854TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5855 // Ensure that a transform between the layer and its render surface is not a
5856 // problem. Constructs the following layer tree.
5857 //
5858 // root (a render surface)
5859 // + render_surface
5860 // + clip_parent (scaled)
5861 // + intervening_clipping_layer
5862 // + clip_child
5863 //
5864 // The render surface should be resized correctly and the clip child should
5865 // inherit the right clip rect.
enne70aa712d2015-07-28 22:46:315866 LayerImpl* root = root_layer();
5867 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
5868 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
jaydasika0d98ba92015-11-17 05:17:285869 clip_parent->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315870 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285871 intervening->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315872 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5873 clip_child->SetDrawsContent(true);
5874 clip_child->SetClipParent(clip_parent);
5875 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
5876 clip_children->insert(clip_child);
5877 clip_parent->SetClipChildren(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385878
5879 intervening->SetMasksToBounds(true);
5880 clip_parent->SetMasksToBounds(true);
5881
[email protected]420fdf6e2013-08-26 20:36:385882 gfx::Transform scale_transform;
5883 scale_transform.Scale(2, 2);
5884
5885 gfx::Transform identity_transform;
5886
enne70aa712d2015-07-28 22:46:315887 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5888 gfx::PointF(), gfx::Size(50, 50), true, false,
5889 true);
5890 SetLayerPropertiesForTesting(render_surface, identity_transform,
5891 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5892 true, false, true);
5893 SetLayerPropertiesForTesting(clip_parent, scale_transform, gfx::Point3F(),
5894 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
5895 false, false);
5896 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5897 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5898 false, false);
5899 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5900 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
5901 false, false);
[email protected]420fdf6e2013-08-26 20:36:385902
enne70aa712d2015-07-28 22:46:315903 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385904
5905 ASSERT_TRUE(root->render_surface());
5906 ASSERT_TRUE(render_surface->render_surface());
5907
5908 // Ensure that we've inherited our clip parent's clip and weren't affected
5909 // by the intervening clip layer.
5910 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
5911 clip_parent->clip_rect().ToString());
5912 ASSERT_EQ(clip_parent->clip_rect().ToString(),
5913 clip_child->clip_rect().ToString());
5914 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
5915 intervening->clip_rect().ToString());
5916
5917 // Ensure that the render surface reports a content rect that has been grown
5918 // to accomodate for the clip child.
jaydasika0d98ba92015-11-17 05:17:285919 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
[email protected]420fdf6e2013-08-26 20:36:385920 render_surface->render_surface()->content_rect().ToString());
5921
5922 // The above check implies the two below, but they nicely demonstrate that
5923 // we've grown, despite the intervening layer's clip.
5924 ASSERT_TRUE(clip_parent->clip_rect().Contains(
5925 render_surface->render_surface()->content_rect()));
5926 ASSERT_FALSE(intervening->clip_rect().Contains(
5927 render_surface->render_surface()->content_rect()));
5928}
5929
5930TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5931 // Ensure that intervening render surfaces are not a problem in the basic
5932 // case. In the following tree, both render surfaces should be resized to
5933 // accomodate for the clip child, despite an intervening clip.
5934 //
5935 // root (a render surface)
5936 // + clip_parent (masks to bounds)
5937 // + render_surface1 (sets opacity)
5938 // + intervening (masks to bounds)
5939 // + render_surface2 (also sets opacity)
5940 // + clip_child
5941 //
weiliangcd6a836d2015-07-28 21:20:235942 LayerImpl* root = root_layer();
5943 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5944 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5945 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5946 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5947 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365948 render_surface1->SetDrawsContent(true);
5949 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235950 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385951
weiliangcd6a836d2015-07-28 21:20:235952 clip_child->SetClipParent(clip_parent);
[email protected]420fdf6e2013-08-26 20:36:385953
5954 intervening->SetMasksToBounds(true);
5955 clip_parent->SetMasksToBounds(true);
5956
[email protected]420fdf6e2013-08-26 20:36:385957 gfx::Transform translation_transform;
5958 translation_transform.Translate(2, 2);
5959
5960 gfx::Transform identity_transform;
weiliangcd6a836d2015-07-28 21:20:235961 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5962 gfx::PointF(), gfx::Size(50, 50), true, false,
5963 true);
5964 SetLayerPropertiesForTesting(clip_parent, translation_transform,
5965 gfx::Point3F(), gfx::PointF(1.f, 1.f),
5966 gfx::Size(40, 40), true, false, false);
5967 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5968 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5969 true, false, true);
5970 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5971 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5972 false, false);
5973 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5974 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5975 true, false, true);
5976 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5977 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
5978 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:385979
weiliangcd6a836d2015-07-28 21:20:235980 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385981
5982 EXPECT_TRUE(root->render_surface());
5983 EXPECT_TRUE(render_surface1->render_surface());
5984 EXPECT_TRUE(render_surface2->render_surface());
5985
5986 // Since the render surfaces could have expanded, they should not clip (their
5987 // bounds would no longer be reliable). We should resort to layer clipping
5988 // in this case.
5989 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5990 render_surface1->render_surface()->clip_rect().ToString());
5991 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5992 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5993 render_surface2->render_surface()->clip_rect().ToString());
5994 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5995
5996 // NB: clip rects are in target space.
5997 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5998 render_surface1->clip_rect().ToString());
5999 EXPECT_TRUE(render_surface1->is_clipped());
6000
6001 // This value is inherited from the clipping ancestor layer, 'intervening'.
6002 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6003 render_surface2->clip_rect().ToString());
6004 EXPECT_TRUE(render_surface2->is_clipped());
6005
6006 // The content rects of both render surfaces should both have expanded to
6007 // contain the clip child.
6008 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6009 render_surface1->render_surface()->content_rect().ToString());
6010 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6011 render_surface2->render_surface()->content_rect().ToString());
6012
6013 // The clip child should have inherited the clip parent's clip (projected to
6014 // the right space, of course), and should have the correctly sized visible
6015 // content rect.
6016 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6017 clip_child->clip_rect().ToString());
6018 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
danakj64767d902015-06-19 00:10:436019 clip_child->visible_layer_rect().ToString());
[email protected]420fdf6e2013-08-26 20:36:386020 EXPECT_TRUE(clip_child->is_clipped());
6021}
6022
6023TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
6024 // Ensure that intervening render surfaces are not a problem, even if there
6025 // is a scroll involved. Note, we do _not_ have to consider any other sort
6026 // of transform.
6027 //
6028 // root (a render surface)
6029 // + clip_parent (masks to bounds)
6030 // + render_surface1 (sets opacity)
6031 // + intervening (masks to bounds AND scrolls)
6032 // + render_surface2 (also sets opacity)
6033 // + clip_child
6034 //
weiliangcd6a836d2015-07-28 21:20:236035 LayerImpl* root = root_layer();
6036 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
6037 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
6038 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
6039 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
6040 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:366041 render_surface1->SetDrawsContent(true);
6042 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:236043 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:386044
weiliangcd6a836d2015-07-28 21:20:236045 clip_child->SetClipParent(clip_parent);
[email protected]420fdf6e2013-08-26 20:36:386046
6047 intervening->SetMasksToBounds(true);
6048 clip_parent->SetMasksToBounds(true);
weiliangcd6a836d2015-07-28 21:20:236049 intervening->SetScrollClipLayer(clip_parent->id());
6050 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:386051
6052 gfx::Transform translation_transform;
6053 translation_transform.Translate(2, 2);
6054
6055 gfx::Transform identity_transform;
weiliangcd6a836d2015-07-28 21:20:236056 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6057 gfx::PointF(), gfx::Size(50, 50), true, false,
6058 true);
6059 SetLayerPropertiesForTesting(clip_parent, translation_transform,
6060 gfx::Point3F(), gfx::PointF(1.f, 1.f),
6061 gfx::Size(40, 40), true, false, false);
6062 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6063 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
6064 true, false, true);
6065 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
6066 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
6067 false, false);
6068 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6069 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
6070 true, false, true);
6071 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
6072 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
6073 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:386074
weiliangcd6a836d2015-07-28 21:20:236075 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:386076
6077 EXPECT_TRUE(root->render_surface());
6078 EXPECT_TRUE(render_surface1->render_surface());
6079 EXPECT_TRUE(render_surface2->render_surface());
6080
6081 // Since the render surfaces could have expanded, they should not clip (their
6082 // bounds would no longer be reliable). We should resort to layer clipping
6083 // in this case.
6084 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6085 render_surface1->render_surface()->clip_rect().ToString());
6086 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6087 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6088 render_surface2->render_surface()->clip_rect().ToString());
6089 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6090
6091 // NB: clip rects are in target space.
6092 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6093 render_surface1->clip_rect().ToString());
6094 EXPECT_TRUE(render_surface1->is_clipped());
6095
6096 // This value is inherited from the clipping ancestor layer, 'intervening'.
6097 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6098 render_surface2->clip_rect().ToString());
6099 EXPECT_TRUE(render_surface2->is_clipped());
6100
6101 // The content rects of both render surfaces should both have expanded to
6102 // contain the clip child.
6103 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6104 render_surface1->render_surface()->content_rect().ToString());
6105 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6106 render_surface2->render_surface()->content_rect().ToString());
6107
6108 // The clip child should have inherited the clip parent's clip (projected to
6109 // the right space, of course), and should have the correctly sized visible
6110 // content rect.
6111 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6112 clip_child->clip_rect().ToString());
6113 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
danakj64767d902015-06-19 00:10:436114 clip_child->visible_layer_rect().ToString());
[email protected]420fdf6e2013-08-26 20:36:386115 EXPECT_TRUE(clip_child->is_clipped());
6116}
6117
6118TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
6119 // Ensures that descendants of the clip child inherit the correct clip.
6120 //
6121 // root (a render surface)
6122 // + clip_parent (masks to bounds)
6123 // + intervening (masks to bounds)
6124 // + clip_child
6125 // + child
6126 //
enne2d0d8e62015-08-18 18:29:176127 LayerImpl* root = root_layer();
6128 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
6129 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
6130 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
6131 LayerImpl* child = AddChild<LayerImpl>(clip_child);
jaydasika8640f9f2015-11-10 01:34:366132 clip_child->SetDrawsContent(true);
enne2d0d8e62015-08-18 18:29:176133 child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:386134
enne2d0d8e62015-08-18 18:29:176135 clip_child->SetClipParent(clip_parent);
6136 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
6137 clip_children->insert(clip_child);
6138 clip_parent->SetClipChildren(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:386139
6140 intervening->SetMasksToBounds(true);
6141 clip_parent->SetMasksToBounds(true);
6142
6143 gfx::Transform identity_transform;
enne2d0d8e62015-08-18 18:29:176144 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6145 gfx::PointF(), gfx::Size(50, 50), true, false,
6146 true);
6147 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
6148 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]420fdf6e2013-08-26 20:36:386149 false);
enne2d0d8e62015-08-18 18:29:176150 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
6151 gfx::PointF(), gfx::Size(5, 5), true, false,
[email protected]420fdf6e2013-08-26 20:36:386152 false);
enne2d0d8e62015-08-18 18:29:176153 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
6154 gfx::PointF(), gfx::Size(60, 60), true, false,
[email protected]420fdf6e2013-08-26 20:36:386155 false);
enne2d0d8e62015-08-18 18:29:176156 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6157 gfx::PointF(), gfx::Size(60, 60), true, false,
[email protected]420fdf6e2013-08-26 20:36:386158 false);
6159
enne2d0d8e62015-08-18 18:29:176160 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:386161
6162 EXPECT_TRUE(root->render_surface());
6163
6164 // Neither the clip child nor its descendant should have inherited the clip
6165 // from |intervening|.
6166 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6167 clip_child->clip_rect().ToString());
6168 EXPECT_TRUE(clip_child->is_clipped());
6169 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
danakj64767d902015-06-19 00:10:436170 child->visible_layer_rect().ToString());
[email protected]420fdf6e2013-08-26 20:36:386171 EXPECT_TRUE(child->is_clipped());
6172}
6173
6174TEST_F(LayerTreeHostCommonTest,
6175 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
6176 // Ensures that non-descendant clip children in the tree do not affect
6177 // render surfaces.
6178 //
6179 // root (a render surface)
6180 // + clip_parent (masks to bounds)
6181 // + render_surface1
6182 // + clip_child
6183 // + render_surface2
6184 // + non_clip_child
6185 //
6186 // In this example render_surface2 should be unaffected by clip_child.
enneb441cdd2015-07-28 22:47:506187 LayerImpl* root = root_layer();
6188 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
6189 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:286190 render_surface1->SetDrawsContent(true);
enneb441cdd2015-07-28 22:47:506191 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
6192 clip_child->SetDrawsContent(true);
6193 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:286194 render_surface2->SetDrawsContent(true);
enneb441cdd2015-07-28 22:47:506195 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
6196 non_clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:386197
enneb441cdd2015-07-28 22:47:506198 clip_child->SetClipParent(clip_parent);
6199 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
6200 clip_children->insert(clip_child);
6201 clip_parent->SetClipChildren(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:386202
6203 clip_parent->SetMasksToBounds(true);
6204 render_surface1->SetMasksToBounds(true);
6205
6206 gfx::Transform identity_transform;
enneb441cdd2015-07-28 22:47:506207 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6208 gfx::PointF(), gfx::Size(15, 15), true, false,
6209 true);
6210 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
6211 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]420fdf6e2013-08-26 20:36:386212 false);
enneb441cdd2015-07-28 22:47:506213 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6214 gfx::Point3F(), gfx::PointF(5, 5),
6215 gfx::Size(5, 5), true, false, true);
6216 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6217 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
6218 true, false, true);
6219 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
6220 gfx::PointF(-1, 1), gfx::Size(10, 10), true,
6221 false, false);
6222 SetLayerPropertiesForTesting(non_clip_child, identity_transform,
6223 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
6224 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:386225
enneb441cdd2015-07-28 22:47:506226 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:386227
6228 EXPECT_TRUE(root->render_surface());
6229 EXPECT_TRUE(render_surface1->render_surface());
6230 EXPECT_TRUE(render_surface2->render_surface());
6231
6232 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6233 render_surface1->clip_rect().ToString());
6234 EXPECT_TRUE(render_surface1->is_clipped());
6235
6236 // The render surface should not clip (it has unclipped descendants), instead
6237 // it should rely on layer clipping.
6238 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6239 render_surface1->render_surface()->clip_rect().ToString());
6240 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6241
jaydasika0d98ba92015-11-17 05:17:286242 // That said, it should have grown to accomodate the unclipped descendant and
6243 // its own size.
6244 EXPECT_EQ(gfx::Rect(-1, 0, 6, 5).ToString(),
[email protected]420fdf6e2013-08-26 20:36:386245 render_surface1->render_surface()->content_rect().ToString());
6246
6247 // This render surface should clip. It has no unclipped descendants.
6248 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6249 render_surface2->clip_rect().ToString());
6250 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
6251
6252 // It also shouldn't have grown to accomodate the clip child.
6253 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6254 render_surface2->render_surface()->content_rect().ToString());
6255
6256 // Sanity check our num_unclipped_descendants values.
vmpstr762e70d2015-06-10 02:12:576257 EXPECT_EQ(1u, render_surface1->num_unclipped_descendants());
6258 EXPECT_EQ(0u, render_surface2->num_unclipped_descendants());
[email protected]420fdf6e2013-08-26 20:36:386259}
6260
weiliangc9ced1592015-11-17 19:04:376261TEST_F(LayerTreeHostCommonTest,
6262 CreateRenderSurfaceWhenFlattenInsideRenderingContext) {
6263 // Verifies that Render Surfaces are created at the edge of rendering context.
6264
weiliangcc154ce22015-12-09 03:39:266265 LayerImpl* root = root_layer();
6266 LayerImpl* child1 = AddChildToRoot<LayerImpl>();
6267 LayerImpl* child2 = AddChild<LayerImpl>(child1);
6268 LayerImpl* child3 = AddChild<LayerImpl>(child2);
6269 root->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376270
6271 const gfx::Transform identity_matrix;
6272 gfx::Point3F transform_origin;
6273 gfx::PointF position;
6274 gfx::Size bounds(100, 100);
6275
6276 SetLayerPropertiesForTesting(root, identity_matrix, transform_origin,
6277 position, bounds, true, false);
6278 SetLayerPropertiesForTesting(child1, identity_matrix, transform_origin,
6279 position, bounds, false, true);
weiliangcc154ce22015-12-09 03:39:266280 child1->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376281 SetLayerPropertiesForTesting(child2, identity_matrix, transform_origin,
6282 position, bounds, true, false);
weiliangcc154ce22015-12-09 03:39:266283 child2->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376284 SetLayerPropertiesForTesting(child3, identity_matrix, transform_origin,
6285 position, bounds, true, false);
weiliangcc154ce22015-12-09 03:39:266286 child3->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376287
6288 child2->Set3dSortingContextId(1);
6289 child3->Set3dSortingContextId(1);
6290
weiliangcc154ce22015-12-09 03:39:266291 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
weiliangc9ced1592015-11-17 19:04:376292
6293 // Verify which render surfaces were created.
6294 EXPECT_TRUE(root->has_render_surface());
6295 EXPECT_FALSE(child1->has_render_surface());
6296 EXPECT_TRUE(child2->has_render_surface());
6297 EXPECT_FALSE(child3->has_render_surface());
6298}
6299
[email protected]45948712013-09-27 02:46:486300TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
khushalsagarb64b360d2015-10-21 19:25:166301 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:456302 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:566303 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:166304 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:566305 &task_graph_runner);
weiliangcc154ce22015-12-09 03:39:266306
[email protected]45948712013-09-27 02:46:486307 scoped_ptr<LayerImpl> root =
6308 LayerImpl::Create(host_impl.active_tree(), 12345);
6309 scoped_ptr<LayerImpl> child1 =
6310 LayerImpl::Create(host_impl.active_tree(), 123456);
6311 scoped_ptr<LayerImpl> child2 =
6312 LayerImpl::Create(host_impl.active_tree(), 1234567);
6313 scoped_ptr<LayerImpl> child3 =
6314 LayerImpl::Create(host_impl.active_tree(), 12345678);
6315
6316 gfx::Transform identity_matrix;
[email protected]a2566412014-06-05 03:14:206317 gfx::Point3F transform_origin;
[email protected]45948712013-09-27 02:46:486318 gfx::PointF position;
6319 gfx::Size bounds(100, 100);
awoloszyne83f28c2014-12-22 15:40:006320 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
6321 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:486322 root->SetDrawsContent(true);
6323
6324 // This layer structure normally forces render surface due to preserves3d
6325 // behavior.
awoloszyne83f28c2014-12-22 15:40:006326 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin,
weiliangc9ced1592015-11-17 19:04:376327 position, bounds, false, true, false);
[email protected]45948712013-09-27 02:46:486328 child1->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:006329 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin,
weiliangc9ced1592015-11-17 19:04:376330 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:486331 child2->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:006332 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin,
6333 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:486334 child3->SetDrawsContent(true);
6335
[email protected]a9d4d4f2014-06-19 06:49:286336 child2->Set3dSortingContextId(1);
6337 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:576338
danakja04855a2015-11-18 20:39:106339 child2->AddChild(std::move(child3));
6340 child1->AddChild(std::move(child2));
6341 root->AddChild(std::move(child1));
[email protected]45948712013-09-27 02:46:486342
6343 {
6344 LayerImplList render_surface_layer_list;
[email protected]ad63b2f2014-08-11 17:39:546345 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get());
ajumad9432e32015-11-30 19:43:446346 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]45948712013-09-27 02:46:486347 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:446348 root.get(), root->bounds(), &render_surface_layer_list,
6349 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]45948712013-09-27 02:46:486350 inputs.can_render_to_separate_surface = true;
6351 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6352
6353 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026354
6355 int count_represents_target_render_surface = 0;
6356 int count_represents_contributing_render_surface = 0;
6357 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516358 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6359 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026360 it != end; ++it) {
6361 if (it.represents_target_render_surface())
6362 count_represents_target_render_surface++;
6363 if (it.represents_contributing_render_surface())
6364 count_represents_contributing_render_surface++;
6365 if (it.represents_itself())
6366 count_represents_itself++;
6367 }
6368
6369 // Two render surfaces.
6370 EXPECT_EQ(2, count_represents_target_render_surface);
6371 // Second render surface contributes to root render surface.
6372 EXPECT_EQ(1, count_represents_contributing_render_surface);
6373 // All 4 layers represent itself.
6374 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486375 }
6376
6377 {
6378 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:446379 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]45948712013-09-27 02:46:486380 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:446381 root.get(), root->bounds(), &render_surface_layer_list,
6382 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]45948712013-09-27 02:46:486383 inputs.can_render_to_separate_surface = false;
6384 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6385
6386 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026387
6388 int count_represents_target_render_surface = 0;
6389 int count_represents_contributing_render_surface = 0;
6390 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516391 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6392 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026393 it != end; ++it) {
6394 if (it.represents_target_render_surface())
6395 count_represents_target_render_surface++;
6396 if (it.represents_contributing_render_surface())
6397 count_represents_contributing_render_surface++;
6398 if (it.represents_itself())
6399 count_represents_itself++;
6400 }
6401
6402 // Only root layer has a render surface.
6403 EXPECT_EQ(1, count_represents_target_render_surface);
6404 // No layer contributes a render surface to root render surface.
6405 EXPECT_EQ(0, count_represents_contributing_render_surface);
6406 // All 4 layers represent itself.
6407 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486408 }
6409}
6410
[email protected]a9aa60a82013-08-29 04:28:266411TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
enne03b0e9a2015-06-19 00:08:026412 LayerImpl* root = root_layer();
jaydasikae00c8a42016-01-28 20:18:336413 LayerImpl* back_facing = AddChild<LayerImpl>(root);
6414 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
6415 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
6416 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
6417 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
6418 child1->SetDrawsContent(true);
6419 child2->SetDrawsContent(true);
[email protected]a9aa60a82013-08-29 04:28:266420
6421 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026422 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6423 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]56fffdd2014-02-11 19:50:576424 true);
jaydasikae00c8a42016-01-28 20:18:336425 SetLayerPropertiesForTesting(back_facing, identity_transform, gfx::Point3F(),
6426 gfx::PointF(), gfx::Size(50, 50), true, false,
6427 false);
6428 SetLayerPropertiesForTesting(render_surface1, identity_transform,
enne03b0e9a2015-06-19 00:08:026429 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6430 false, true, true);
jaydasikae00c8a42016-01-28 20:18:336431 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6432 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6433 false, true, true);
6434 SetLayerPropertiesForTesting(child1, identity_transform, gfx::Point3F(),
6435 gfx::PointF(), gfx::Size(20, 20), true, false,
6436 false);
6437 SetLayerPropertiesForTesting(child2, identity_transform, gfx::Point3F(),
enne03b0e9a2015-06-19 00:08:026438 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]a9aa60a82013-08-29 04:28:266439 false);
6440
[email protected]56fffdd2014-02-11 19:50:576441 root->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:286442 root->Set3dSortingContextId(1);
jaydasikae00c8a42016-01-28 20:18:336443 back_facing->Set3dSortingContextId(1);
6444 back_facing->SetShouldFlattenTransform(false);
6445 render_surface1->SetDoubleSided(false);
6446 render_surface2->Set3dSortingContextId(2);
6447 render_surface2->SetDoubleSided(false);
[email protected]a9aa60a82013-08-29 04:28:266448
enne03b0e9a2015-06-19 00:08:026449 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266450
jaydasikae00c8a42016-01-28 20:18:336451 EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id());
6452 EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id());
6453 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6454 EXPECT_EQ(2u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026455 ->at(0)
6456 ->render_surface()
6457 ->layer_list()
6458 .size());
6459 EXPECT_EQ(1u, render_surface_layer_list_impl()
6460 ->at(1)
6461 ->render_surface()
6462 ->layer_list()
6463 .size());
[email protected]a9aa60a82013-08-29 04:28:266464
6465 gfx::Transform rotation_transform = identity_transform;
6466 rotation_transform.RotateAboutXAxis(180.0);
6467
jaydasikae00c8a42016-01-28 20:18:336468 back_facing->SetTransform(rotation_transform);
jaydasika5aa88b82015-11-10 01:48:036469 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]a9aa60a82013-08-29 04:28:266470
enne03b0e9a2015-06-19 00:08:026471 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266472
jaydasikae00c8a42016-01-28 20:18:336473 // render_surface1 is in the same 3d rendering context as back_facing and is
6474 // not double sided, so it should not be in RSLL. render_surface2 is also not
6475 // double-sided, but will still be in RSLL as it's in a different 3d rendering
6476 // context.
6477 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
6478 EXPECT_EQ(1u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026479 ->at(0)
6480 ->render_surface()
6481 ->layer_list()
6482 .size());
[email protected]a9aa60a82013-08-29 04:28:266483}
6484
ajumaaa0d3862015-11-09 22:24:466485TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) {
6486 LayerImpl* root = root_layer();
6487 LayerImpl* child = AddChild<LayerImpl>(root);
6488 LayerImpl* grand_child = AddChild<LayerImpl>(child);
6489 grand_child->SetDrawsContent(true);
6490
6491 child->SetDoubleSided(false);
6492 grand_child->SetUseParentBackfaceVisibility(true);
6493
6494 gfx::Transform identity_transform;
6495 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6496 gfx::PointF(), gfx::Size(50, 50), false, true,
6497 true);
6498 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6499 gfx::PointF(), gfx::Size(30, 30), false, true,
6500 false);
6501 SetLayerPropertiesForTesting(grand_child, identity_transform, gfx::Point3F(),
6502 gfx::PointF(), gfx::Size(20, 20), false, true,
6503 false);
6504
6505 ExecuteCalculateDrawProperties(root);
6506
6507 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6508 EXPECT_EQ(grand_child, render_surface_layer_list_impl()
6509 ->at(0)
6510 ->render_surface()
6511 ->layer_list()[0]);
6512 gfx::Transform rotation_transform = identity_transform;
6513 rotation_transform.RotateAboutXAxis(180.0);
6514
6515 child->SetTransform(rotation_transform);
6516 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6517
6518 ExecuteCalculateDrawProperties(root);
6519 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6520 EXPECT_EQ(0u, render_surface_layer_list_impl()
6521 ->at(0)
6522 ->render_surface()
6523 ->layer_list()
6524 .size());
6525}
6526
[email protected]995708c52013-10-17 20:52:596527TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
6528 // Checks that the simple case (being clipped by a scroll parent that would
6529 // have been processed before you anyhow) results in the right clips.
6530 //
6531 // + root
6532 // + scroll_parent_border
6533 // | + scroll_parent_clip
6534 // | + scroll_parent
6535 // + scroll_child
6536 //
enne085b48a2015-08-18 17:54:486537 LayerImpl* root = root_layer();
6538 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
6539 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6540 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6541 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596542
enne085b48a2015-08-18 17:54:486543 scroll_parent->SetDrawsContent(true);
6544 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596545 scroll_parent_clip->SetMasksToBounds(true);
6546
enne085b48a2015-08-18 17:54:486547 scroll_child->SetScrollParent(scroll_parent);
6548 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6549 scroll_children->insert(scroll_child);
6550 scroll_parent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596551
6552 gfx::Transform identity_transform;
enne085b48a2015-08-18 17:54:486553 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6554 gfx::PointF(), gfx::Size(50, 50), true, false,
6555 true);
6556 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6557 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6558 true, false, false);
6559 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6560 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6561 true, false, false);
6562 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6563 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6564 true, false, false);
6565 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6566 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596567 false);
6568
enne085b48a2015-08-18 17:54:486569 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596570
6571 EXPECT_TRUE(root->render_surface());
6572
6573 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6574 scroll_child->clip_rect().ToString());
6575 EXPECT_TRUE(scroll_child->is_clipped());
6576}
6577
jaydasika8ccff3d2016-01-20 19:51:306578TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) {
6579 // Tests the computation of draw transform for the scroll child when its
6580 // target is different from its scroll parent's target.
6581 LayerImpl* root = root_layer();
6582 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
6583 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
6584 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target);
6585 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
6586
6587 scroll_parent->SetDrawsContent(true);
6588 scroll_child->SetDrawsContent(true);
6589
6590 scroll_child->SetScrollParent(scroll_parent);
6591 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6592 scroll_children->insert(scroll_child);
6593 scroll_parent->SetScrollChildren(scroll_children.release());
6594
6595 gfx::Transform identity_transform;
6596 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6597 gfx::PointF(), gfx::Size(50, 50), true, false,
6598 true);
6599 SetLayerPropertiesForTesting(scroll_child_target, identity_transform,
6600 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6601 true, false, true);
6602 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6603 gfx::PointF(), gfx::Size(50, 50), true, false,
6604 false);
6605 SetLayerPropertiesForTesting(scroll_parent_target, identity_transform,
6606 gfx::Point3F(), gfx::PointF(10, 10),
6607 gfx::Size(50, 50), true, false, true);
6608 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6609 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
jaydasika2489a442016-01-29 02:26:006610 true, false, false);
6611 scroll_parent_target->SetMasksToBounds(true);
jaydasika8ccff3d2016-01-20 19:51:306612
jaydasika2489a442016-01-29 02:26:006613 float device_scale_factor = 1.5f;
6614 LayerImplList render_surface_layer_list_impl;
6615 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
6616 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6617 root, root->bounds(), identity_transform, &render_surface_layer_list_impl,
6618 root->layer_tree_impl()->current_render_surface_list_id());
6619 inputs.device_scale_factor = device_scale_factor;
6620 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6621
6622 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40));
6623 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75));
6624 gfx::Transform scale;
6625 scale.Scale(1.5f, 1.5f);
6626 EXPECT_EQ(scroll_child->DrawTransform(), scale);
jaydasika8ccff3d2016-01-20 19:51:306627}
6628
[email protected]08bdf1b2014-04-16 23:23:296629TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
enneca33fed2015-07-27 18:22:196630 LayerImpl* root = root_layer();
6631 root->SetDrawsContent(true);
6632 LayerImpl* parent = AddChildToRoot<LayerImpl>();
6633 parent->SetDrawsContent(true);
6634 LayerImpl* child = AddChild<LayerImpl>(parent);
6635 child->SetDrawsContent(true);
[email protected]08bdf1b2014-04-16 23:23:296636
6637 gfx::Transform identity_transform;
enneca33fed2015-07-27 18:22:196638 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6639 gfx::PointF(), gfx::Size(50, 50), true, true,
[email protected]08bdf1b2014-04-16 23:23:296640 true);
enneca33fed2015-07-27 18:22:196641 SetLayerPropertiesForTesting(parent, identity_transform, gfx::Point3F(),
6642 gfx::PointF(), gfx::Size(30, 30), true, true,
[email protected]08bdf1b2014-04-16 23:23:296643 true);
enneca33fed2015-07-27 18:22:196644 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6645 gfx::PointF(), gfx::Size(20, 20), true, true,
[email protected]08bdf1b2014-04-16 23:23:296646 true);
[email protected]08bdf1b2014-04-16 23:23:296647
enneca33fed2015-07-27 18:22:196648 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296649
enneca33fed2015-07-27 18:22:196650 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296651
6652 gfx::Transform singular_transform;
6653 singular_transform.Scale3d(
6654 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6655
6656 child->SetTransform(singular_transform);
6657
enneca33fed2015-07-27 18:22:196658 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296659
enneca33fed2015-07-27 18:22:196660 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296661
6662 // Ensure that the entire subtree under a layer with singular transform does
6663 // not get rendered.
6664 parent->SetTransform(singular_transform);
6665 child->SetTransform(identity_transform);
6666
enneca33fed2015-07-27 18:22:196667 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296668
enneca33fed2015-07-27 18:22:196669 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296670}
6671
[email protected]995708c52013-10-17 20:52:596672TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
6673 // Checks that clipping by a scroll parent that follows you in paint order
6674 // still results in correct clipping.
6675 //
6676 // + root
[email protected]995708c52013-10-17 20:52:596677 // + scroll_parent_border
6678 // + scroll_parent_clip
6679 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026680 // + scroll_child
[email protected]995708c52013-10-17 20:52:596681 //
enne03b0e9a2015-06-19 00:08:026682 LayerImpl* root = root_layer();
6683 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6684 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6685 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6686 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596687
enne03b0e9a2015-06-19 00:08:026688 scroll_parent->SetDrawsContent(true);
6689 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596690
6691 scroll_parent_clip->SetMasksToBounds(true);
6692
enne03b0e9a2015-06-19 00:08:026693 scroll_child->SetScrollParent(scroll_parent);
ajuma9af2e92b2015-06-29 22:26:386694 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6695 scroll_children->insert(scroll_child);
6696 scroll_parent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596697
6698 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026699 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6700 gfx::PointF(), gfx::Size(50, 50), true, false,
6701 true);
6702 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6703 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6704 true, false, false);
6705 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6706 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6707 true, false, false);
6708 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6709 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6710 true, false, false);
6711 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6712 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596713 false);
6714
enne03b0e9a2015-06-19 00:08:026715 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596716
6717 EXPECT_TRUE(root->render_surface());
6718
6719 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6720 scroll_child->clip_rect().ToString());
6721 EXPECT_TRUE(scroll_child->is_clipped());
6722}
6723
6724TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
6725 // Checks that clipping by a scroll parent and scroll grandparent that follow
6726 // you in paint order still results in correct clipping.
6727 //
6728 // + root
6729 // + scroll_child
6730 // + scroll_parent_border
6731 // | + scroll_parent_clip
6732 // | + scroll_parent
6733 // + scroll_grandparent_border
6734 // + scroll_grandparent_clip
6735 // + scroll_grandparent
6736 //
enne03b0e9a2015-06-19 00:08:026737 LayerImpl* root = root_layer();
6738 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6739 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6740 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6741 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6742 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6743 LayerImpl* scroll_grandparent_clip =
6744 AddChild<LayerImpl>(scroll_grandparent_border);
6745 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:596746
enne03b0e9a2015-06-19 00:08:026747 scroll_parent->SetDrawsContent(true);
6748 scroll_grandparent->SetDrawsContent(true);
6749 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596750
6751 scroll_parent_clip->SetMasksToBounds(true);
6752 scroll_grandparent_clip->SetMasksToBounds(true);
6753
enne03b0e9a2015-06-19 00:08:026754 scroll_child->SetScrollParent(scroll_parent);
ajuma9af2e92b2015-06-29 22:26:386755 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6756 scroll_children->insert(scroll_child);
6757 scroll_parent->SetScrollChildren(scroll_children.release());
6758
enne03b0e9a2015-06-19 00:08:026759 scroll_parent_border->SetScrollParent(scroll_grandparent);
ajuma9af2e92b2015-06-29 22:26:386760 scroll_children.reset(new std::set<LayerImpl*>);
6761 scroll_children->insert(scroll_parent_border);
6762 scroll_grandparent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596763
6764 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026765 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6766 gfx::PointF(), gfx::Size(50, 50), true, false,
6767 true);
6768 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6769 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6770 true, false, false);
6771 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6772 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6773 true, false, false);
6774 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6775 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6776 true, false, false);
6777 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6778 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6779 true, false, false);
6780 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6781 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6782 true, false, false);
6783 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6784 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6785 true, false, false);
6786 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6787 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596788 false);
6789
enne03b0e9a2015-06-19 00:08:026790 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596791
6792 EXPECT_TRUE(root->render_surface());
6793
6794 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
6795 scroll_child->clip_rect().ToString());
6796 EXPECT_TRUE(scroll_child->is_clipped());
6797
6798 // Despite the fact that we visited the above layers out of order to get the
6799 // correct clip, the layer lists should be unaffected.
6800 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
enne03b0e9a2015-06-19 00:08:026801 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
6802 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
6803 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
[email protected]995708c52013-10-17 20:52:596804}
6805
6806TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
6807 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:226808 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:596809 // + root
6810 // + scroll_child
6811 // + scroll_parent_border
6812 // + scroll_parent_clip
6813 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026814 // + render_surface2
[email protected]995708c52013-10-17 20:52:596815 // + scroll_grandparent_border
6816 // + scroll_grandparent_clip
6817 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:026818 // + render_surface1
[email protected]995708c52013-10-17 20:52:596819 //
enne03b0e9a2015-06-19 00:08:026820 LayerImpl* root = root_layer();
6821 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596822
enne03b0e9a2015-06-19 00:08:026823 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6824 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596825
enne03b0e9a2015-06-19 00:08:026826 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6827 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6828 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6829 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
6830 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6831 LayerImpl* scroll_grandparent_clip =
6832 AddChild<LayerImpl>(scroll_grandparent_border);
6833 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6834 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:596835
enne03b0e9a2015-06-19 00:08:026836 scroll_parent->SetDrawsContent(true);
6837 render_surface1->SetDrawsContent(true);
6838 scroll_grandparent->SetDrawsContent(true);
6839 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596840
6841 scroll_parent_clip->SetMasksToBounds(true);
6842 scroll_grandparent_clip->SetMasksToBounds(true);
6843
enne03b0e9a2015-06-19 00:08:026844 scroll_child->SetScrollParent(scroll_parent);
ajuma9af2e92b2015-06-29 22:26:386845 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6846 scroll_children->insert(scroll_child);
6847 scroll_parent->SetScrollChildren(scroll_children.release());
6848
enne03b0e9a2015-06-19 00:08:026849 scroll_parent_border->SetScrollParent(scroll_grandparent);
ajuma9af2e92b2015-06-29 22:26:386850 scroll_children.reset(new std::set<LayerImpl*>);
6851 scroll_children->insert(scroll_parent_border);
6852 scroll_grandparent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596853
6854 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026855 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6856 gfx::PointF(), gfx::Size(50, 50), true, false,
6857 true);
6858 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6859 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6860 true, false, false);
6861 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6862 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6863 true, false, false);
6864 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6865 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6866 true, false, false);
6867 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6868 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6869 true, false, true);
6870 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6871 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6872 true, false, false);
6873 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6874 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6875 true, false, false);
6876 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6877 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6878 true, false, false);
6879 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6880 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6881 true, false, true);
6882 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6883 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596884 false);
6885
enne03b0e9a2015-06-19 00:08:026886 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596887
6888 EXPECT_TRUE(root->render_surface());
6889
6890 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
6891 scroll_child->clip_rect().ToString());
6892 EXPECT_TRUE(scroll_child->is_clipped());
6893
6894 // Despite the fact that we had to process the layers out of order to get the
6895 // right clip, our render_surface_layer_list's order should be unaffected.
enne03b0e9a2015-06-19 00:08:026896 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6897 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
6898 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
6899 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
6900 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6901 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6902 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:596903}
6904
ajuma0b10f942015-03-21 07:45:536905TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
6906 // Ensures that when we have a render surface between a fixed position layer
6907 // and its container, we compute the fixed position layer's draw transform
6908 // with respect to that intervening render surface, not with respect to its
6909 // container's render target.
6910 //
6911 // + root
6912 // + render_surface
6913 // + fixed
ajuma737b2702015-05-06 01:18:376914 // + child
ajuma0b10f942015-03-21 07:45:536915 //
loysoa6edaaff2015-05-25 03:26:446916 scoped_refptr<Layer> root = Layer::Create(layer_settings());
ajuma0b10f942015-03-21 07:45:536917 scoped_refptr<LayerWithForcedDrawsContent> render_surface =
loysoa6edaaff2015-05-25 03:26:446918 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma0b10f942015-03-21 07:45:536919 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:446920 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma737b2702015-05-06 01:18:376921 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:446922 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma0b10f942015-03-21 07:45:536923
6924 root->AddChild(render_surface);
6925 render_surface->AddChild(fixed);
ajuma737b2702015-05-06 01:18:376926 fixed->AddChild(child);
ajuma0b10f942015-03-21 07:45:536927
6928 root->SetIsContainerForFixedPositionLayers(true);
6929 render_surface->SetForceRenderSurface(true);
6930
6931 LayerPositionConstraint constraint;
6932 constraint.set_is_fixed_position(true);
6933 fixed->SetPositionConstraint(constraint);
6934
6935 SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(),
6936 gfx::PointF(), gfx::Size(50, 50), true, false);
6937 SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(),
6938 gfx::Point3F(), gfx::PointF(7.f, 9.f),
6939 gfx::Size(50, 50), true, false);
6940 SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(),
6941 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true,
6942 false);
ajuma737b2702015-05-06 01:18:376943 SetLayerPropertiesForTesting(child.get(), gfx::Transform(), gfx::Point3F(),
6944 gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true,
6945 false);
ajuma0b10f942015-03-21 07:45:536946
ennea7b43c32015-06-18 20:01:336947 host()->SetRootLayer(root);
ajuma0b10f942015-03-21 07:45:536948
6949 ExecuteCalculateDrawProperties(root.get());
6950
ennef6903532015-08-18 05:10:156951 TransformTree& tree = host()->property_trees()->transform_tree;
6952
ajuma737b2702015-05-06 01:18:376953 gfx::Transform expected_fixed_draw_transform;
6954 expected_fixed_draw_transform.Translate(10.f, 15.f);
ennef6903532015-08-18 05:10:156955 EXPECT_EQ(expected_fixed_draw_transform,
6956 DrawTransformFromPropertyTrees(fixed.get(), tree));
ajuma0b10f942015-03-21 07:45:536957
ajuma737b2702015-05-06 01:18:376958 gfx::Transform expected_fixed_screen_space_transform;
6959 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
6960 EXPECT_EQ(expected_fixed_screen_space_transform,
ennef6903532015-08-18 05:10:156961 ScreenSpaceTransformFromPropertyTrees(fixed.get(), tree));
ajuma737b2702015-05-06 01:18:376962
6963 gfx::Transform expected_child_draw_transform;
6964 expected_child_draw_transform.Translate(11.f, 17.f);
ennef6903532015-08-18 05:10:156965 EXPECT_EQ(expected_child_draw_transform,
6966 DrawTransformFromPropertyTrees(child.get(), tree));
ajuma737b2702015-05-06 01:18:376967
6968 gfx::Transform expected_child_screen_space_transform;
6969 expected_child_screen_space_transform.Translate(18.f, 26.f);
6970 EXPECT_EQ(expected_child_screen_space_transform,
ennef6903532015-08-18 05:10:156971 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
ajuma0b10f942015-03-21 07:45:536972}
6973
[email protected]d81752b2013-10-25 08:32:236974TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
6975 // This test verifies that a scrolling layer that gets snapped to
6976 // integer coordinates doesn't move a fixed position child.
6977 //
6978 // + root
6979 // + container
6980 // + scroller
6981 // + fixed
6982 //
khushalsagarb64b360d2015-10-21 19:25:166983 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:456984 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:566985 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:166986 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:566987 &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:236988 host_impl.CreatePendingTree();
6989 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
6990 scoped_ptr<LayerImpl> container =
6991 LayerImpl::Create(host_impl.active_tree(), 2);
6992 LayerImpl* container_layer = container.get();
6993 scoped_ptr<LayerImpl> scroller =
6994 LayerImpl::Create(host_impl.active_tree(), 3);
6995 LayerImpl* scroll_layer = scroller.get();
6996 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
6997 LayerImpl* fixed_layer = fixed.get();
6998
6999 container->SetIsContainerForFixedPositionLayers(true);
7000
7001 LayerPositionConstraint constraint;
7002 constraint.set_is_fixed_position(true);
7003 fixed->SetPositionConstraint(constraint);
7004
[email protected]adeda572014-01-31 00:49:477005 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:237006
7007 gfx::Transform identity_transform;
7008 gfx::Transform container_transform;
7009 container_transform.Translate3d(10.0, 20.0, 0.0);
7010 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7011
awoloszyne83f28c2014-12-22 15:40:007012 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7013 gfx::PointF(), gfx::Size(50, 50), true, false,
7014 true);
7015 SetLayerPropertiesForTesting(container.get(), container_transform,
7016 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7017 true, false, false);
7018 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7019 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7020 true, false, false);
7021 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7022 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]d81752b2013-10-25 08:32:237023 false);
7024
jaydasika0d98ba92015-11-17 05:17:287025 root->SetDrawsContent(true);
7026 container->SetDrawsContent(true);
7027 scroller->SetDrawsContent(true);
7028 fixed->SetDrawsContent(true);
danakja04855a2015-11-18 20:39:107029 scroller->AddChild(std::move(fixed));
7030 container->AddChild(std::move(scroller));
7031 root->AddChild(std::move(container));
[email protected]d81752b2013-10-25 08:32:237032
7033 // Rounded to integers already.
7034 {
7035 gfx::Vector2dF scroll_delta(3.0, 5.0);
7036 scroll_layer->SetScrollDelta(scroll_delta);
7037
7038 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:447039 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]d81752b2013-10-25 08:32:237040 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:447041 root.get(), root->bounds(), &render_surface_layer_list,
7042 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]d81752b2013-10-25 08:32:237043 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7044
7045 EXPECT_TRANSFORMATION_MATRIX_EQ(
7046 container_layer->draw_properties().screen_space_transform,
7047 fixed_layer->draw_properties().screen_space_transform);
7048 EXPECT_VECTOR_EQ(
7049 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7050 container_offset);
7051 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7052 .screen_space_transform.To2dTranslation(),
7053 container_offset - scroll_delta);
7054 }
7055
7056 // Scroll delta requiring rounding.
7057 {
7058 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
7059 scroll_layer->SetScrollDelta(scroll_delta);
7060
7061 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
7062
7063 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:447064 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]d81752b2013-10-25 08:32:237065 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:447066 root.get(), root->bounds(), &render_surface_layer_list,
7067 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]d81752b2013-10-25 08:32:237068 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7069
7070 EXPECT_TRANSFORMATION_MATRIX_EQ(
7071 container_layer->draw_properties().screen_space_transform,
7072 fixed_layer->draw_properties().screen_space_transform);
7073 EXPECT_VECTOR_EQ(
7074 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7075 container_offset);
7076 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7077 .screen_space_transform.To2dTranslation(),
7078 container_offset - rounded_scroll_delta);
7079 }
[email protected]cf15ad7b2014-04-02 03:59:267080
7081 // Scale is applied earlier in the tree.
7082 {
7083 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:287084 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
[email protected]cf15ad7b2014-04-02 03:59:267085 container_layer->SetTransform(scaled_container_transform);
jaydasika0d98ba92015-11-17 05:17:287086 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
7087 root->layer_tree_impl()
7088 ->property_trees()
7089 ->transform_tree.set_source_to_parent_updates_allowed(true);
[email protected]cf15ad7b2014-04-02 03:59:267090
7091 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7092 scroll_layer->SetScrollDelta(scroll_delta);
7093
7094 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:447095 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]cf15ad7b2014-04-02 03:59:267096 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:447097 root.get(), root->bounds(), &render_surface_layer_list,
7098 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]cf15ad7b2014-04-02 03:59:267099 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7100
7101 EXPECT_TRANSFORMATION_MATRIX_EQ(
7102 container_layer->draw_properties().screen_space_transform,
7103 fixed_layer->draw_properties().screen_space_transform);
7104 EXPECT_VECTOR_EQ(
7105 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7106 container_offset);
7107
7108 container_layer->SetTransform(container_transform);
7109 }
[email protected]d81752b2013-10-25 08:32:237110}
7111
miletus2c78036b2015-01-29 20:52:377112TEST_F(LayerTreeHostCommonTest,
7113 ScrollCompensationMainScrollOffsetFractionalPart) {
7114 // This test verifies that a scrolling layer that has fractional scroll offset
7115 // from main doesn't move a fixed position child.
7116 //
7117 // + root
7118 // + container
7119 // + scroller
7120 // + fixed
7121 //
khushalsagarb64b360d2015-10-21 19:25:167122 FakeImplTaskRunnerProvider task_runner_provider;
miletus2c78036b2015-01-29 20:52:377123 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567124 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167125 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567126 &task_graph_runner);
miletus2c78036b2015-01-29 20:52:377127 host_impl.CreatePendingTree();
7128 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7129 scoped_ptr<LayerImpl> container =
7130 LayerImpl::Create(host_impl.active_tree(), 2);
7131 LayerImpl* container_layer = container.get();
7132 scoped_ptr<LayerImpl> scroller =
7133 LayerImpl::Create(host_impl.active_tree(), 3);
7134 LayerImpl* scroll_layer = scroller.get();
7135 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7136 LayerImpl* fixed_layer = fixed.get();
7137
7138 container->SetIsContainerForFixedPositionLayers(true);
7139
7140 LayerPositionConstraint constraint;
7141 constraint.set_is_fixed_position(true);
jaydasika8640f9f2015-11-10 01:34:367142 container->SetDrawsContent(true);
7143 fixed->SetDrawsContent(true);
miletus2c78036b2015-01-29 20:52:377144 fixed->SetPositionConstraint(constraint);
7145
jaydasika8640f9f2015-11-10 01:34:367146 scroller->SetDrawsContent(true);
miletus2c78036b2015-01-29 20:52:377147 scroller->SetScrollClipLayer(container->id());
7148
7149 gfx::Transform identity_transform;
7150 gfx::Transform container_transform;
7151 container_transform.Translate3d(10.0, 20.0, 0.0);
7152 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7153
7154 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7155 gfx::PointF(), gfx::Size(50, 50), true, false,
7156 true);
7157 SetLayerPropertiesForTesting(container.get(), container_transform,
7158 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7159 true, false, false);
7160 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7161 gfx::Point3F(), gfx::PointF(0.0, 0.0),
7162 gfx::Size(30, 30), true, false, false);
7163
7164 gfx::ScrollOffset scroll_offset(3.3, 4.2);
7165 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f);
7166 gfx::Vector2dF scroll_delta(0.1f, 0.4f);
7167 // Blink only uses the integer part of the scroll_offset for fixed
7168 // position layer.
7169 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7170 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true,
7171 false, false);
aeliasf998da82015-02-03 01:40:517172 scroll_layer->PushScrollOffsetFromMainThread(scroll_offset);
aeliasd0070ba2015-01-31 13:44:497173 scroll_layer->SetScrollDelta(scroll_delta);
miletusff93ab72015-01-30 04:30:447174 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part);
miletus2c78036b2015-01-29 20:52:377175
danakja04855a2015-11-18 20:39:107176 scroller->AddChild(std::move(fixed));
7177 container->AddChild(std::move(scroller));
7178 root->AddChild(std::move(container));
miletus2c78036b2015-01-29 20:52:377179
7180 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:447181 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
miletus2c78036b2015-01-29 20:52:377182 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:447183 root.get(), root->bounds(), &render_surface_layer_list,
7184 root->layer_tree_impl()->current_render_surface_list_id());
miletus2c78036b2015-01-29 20:52:377185 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7186
7187 EXPECT_TRANSFORMATION_MATRIX_EQ(
7188 container_layer->draw_properties().screen_space_transform,
7189 fixed_layer->draw_properties().screen_space_transform);
7190 EXPECT_VECTOR_EQ(
7191 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7192 container_offset);
7193
7194 gfx::ScrollOffset effective_scroll_offset =
7195 ScrollOffsetWithDelta(scroll_offset, scroll_delta);
7196 gfx::Vector2d rounded_effective_scroll_offset =
7197 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset));
7198 EXPECT_VECTOR_EQ(
7199 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(),
7200 container_offset - rounded_effective_scroll_offset);
7201}
7202
ajuma5e8e40d2015-07-31 01:50:507203TEST_F(LayerTreeHostCommonTest,
7204 ScrollSnappingWithAnimatedScreenSpaceTransform) {
7205 // This test verifies that a scrolling layer whose screen space transform is
7206 // animating doesn't get snapped to integer coordinates.
7207 //
7208 // + root
7209 // + animated layer
7210 // + surface
7211 // + container
7212 // + scroller
7213 //
7214 LayerImpl* root = root_layer();
7215 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
7216 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
7217 LayerImpl* container = AddChild<LayerImpl>(surface);
7218 LayerImpl* scroller = AddChild<LayerImpl>(container);
7219 scroller->SetScrollClipLayer(container->id());
7220 scroller->SetDrawsContent(true);
7221
7222 gfx::Transform identity_transform;
7223 gfx::Transform start_scale;
7224 start_scale.Scale(1.5f, 1.5f);
7225 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
7226 gfx::PointF(), gfx::Size(50, 50), true, false,
7227 true);
7228 SetLayerPropertiesForTesting(animated_layer, start_scale, gfx::Point3F(),
7229 gfx::PointF(), gfx::Size(50, 50), true, false,
7230 false);
7231 SetLayerPropertiesForTesting(surface, identity_transform, gfx::Point3F(),
7232 gfx::PointF(), gfx::Size(50, 50), true, false,
7233 true);
7234 SetLayerPropertiesForTesting(container, identity_transform, gfx::Point3F(),
7235 gfx::PointF(), gfx::Size(50, 50), true, false,
7236 false);
7237 SetLayerPropertiesForTesting(scroller, identity_transform, gfx::Point3F(),
7238 gfx::PointF(), gfx::Size(100, 100), true, false,
7239 false);
7240
7241 gfx::Transform end_scale;
7242 end_scale.Scale(2.f, 2.f);
7243 TransformOperations start_operations;
7244 start_operations.AppendMatrix(start_scale);
7245 TransformOperations end_operations;
7246 end_operations.AppendMatrix(end_scale);
loyso968163c92016-01-04 23:18:487247 if (layer_settings().use_compositor_animation_timelines) {
7248 AddAnimatedTransformToLayerWithPlayer(animated_layer->id(), timeline_impl(),
7249 1.0, start_operations,
7250 end_operations);
7251 } else {
7252 AddAnimatedTransformToLayer(animated_layer, 1.0, start_operations,
7253 end_operations);
7254 }
ajuma5e8e40d2015-07-31 01:50:507255 gfx::Vector2dF scroll_delta(5.f, 9.f);
7256 scroller->SetScrollDelta(scroll_delta);
7257
7258 ExecuteCalculateDrawProperties(root);
7259
7260 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
7261 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:447262 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:507263}
7264
[email protected]1c3626e2014-04-09 17:49:227265class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7266 public:
7267 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
7268 LayerTreeImpl* tree_impl,
7269 int id) {
7270 return make_scoped_ptr(
7271 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7272 }
7273
dcheng716bedf2014-10-21 09:51:087274 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227275
[email protected]1c3626e2014-04-09 17:49:227276 private:
7277 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7278 int id)
[email protected]a57cb8b12014-06-13 18:15:377279 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227280 SetDrawsContent(true);
7281 }
[email protected]1c3626e2014-04-09 17:49:227282};
7283
7284TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:167285 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]1c3626e2014-04-09 17:49:227286 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567287 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:487288 LayerTreeSettings settings = host()->settings();
ajumab4a846f22015-08-24 19:13:447289 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167290 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7291 &shared_bitmap_manager, &task_graph_runner);
[email protected]1c3626e2014-04-09 17:49:227292 gfx::Transform identity_matrix;
7293 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
7294 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
7295 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
7296 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
7297 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
7298 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
7299 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
7300 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7301
7302 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7303 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7304 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
7305
danakja04855a2015-11-18 20:39:107306 child->AddChild(std::move(grand_child));
7307 parent->AddChild(std::move(child));
7308 grand_parent->AddChild(std::move(parent));
[email protected]1c3626e2014-04-09 17:49:227309
awoloszyne83f28c2014-12-22 15:40:007310 SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix,
7311 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7312 true, false, true);
7313 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7314 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227315 false);
awoloszyne83f28c2014-12-22 15:40:007316 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7317 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227318 false);
awoloszyne83f28c2014-12-22 15:40:007319
7320 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
7321 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227322 false);
7323
7324 ExecuteCalculateDrawProperties(grand_parent.get());
7325
7326 // No layers have animations.
[email protected]a57cb8b12014-06-13 18:15:377327 EXPECT_EQ(0.f,
7328 grand_parent->draw_properties().maximum_animation_contents_scale);
7329 EXPECT_EQ(0.f,
7330 parent_raw->draw_properties().maximum_animation_contents_scale);
7331 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7332 EXPECT_EQ(
7333 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227334
ajuma052892e2015-08-21 14:39:037335 EXPECT_EQ(0.f,
7336 grand_parent->draw_properties().starting_animation_contents_scale);
7337 EXPECT_EQ(0.f,
7338 parent_raw->draw_properties().starting_animation_contents_scale);
7339 EXPECT_EQ(0.f,
7340 child_raw->draw_properties().starting_animation_contents_scale);
7341 EXPECT_EQ(
7342 0.f,
7343 grand_child_raw->draw_properties().starting_animation_contents_scale);
7344
[email protected]1c3626e2014-04-09 17:49:227345 TransformOperations translation;
7346 translation.AppendTranslate(1.f, 2.f, 3.f);
7347
loyso968163c92016-01-04 23:18:487348 scoped_refptr<AnimationTimeline> timeline;
7349 if (layer_settings().use_compositor_animation_timelines) {
7350 timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7351 host_impl.animation_host()->AddAnimationTimeline(timeline);
7352
7353 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7354 TransformOperations(), translation);
7355 } else {
7356 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(),
7357 translation);
7358 }
[email protected]1c3626e2014-04-09 17:49:227359
7360 // No layers have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377361 EXPECT_EQ(0.f,
7362 grand_parent->draw_properties().maximum_animation_contents_scale);
7363 EXPECT_EQ(0.f,
7364 parent_raw->draw_properties().maximum_animation_contents_scale);
7365 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7366 EXPECT_EQ(
7367 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227368
ajuma052892e2015-08-21 14:39:037369 EXPECT_EQ(0.f,
7370 grand_parent->draw_properties().starting_animation_contents_scale);
7371 EXPECT_EQ(0.f,
7372 parent_raw->draw_properties().starting_animation_contents_scale);
7373 EXPECT_EQ(0.f,
7374 child_raw->draw_properties().starting_animation_contents_scale);
7375 EXPECT_EQ(
7376 0.f,
7377 grand_child_raw->draw_properties().starting_animation_contents_scale);
7378
[email protected]1c3626e2014-04-09 17:49:227379 TransformOperations scale;
7380 scale.AppendScale(5.f, 4.f, 3.f);
7381
loyso968163c92016-01-04 23:18:487382 if (layer_settings().use_compositor_animation_timelines) {
7383 AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0,
7384 TransformOperations(), scale);
7385 } else {
7386 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
7387 }
ajumacaaa9b32015-08-04 15:55:297388 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227389 ExecuteCalculateDrawProperties(grand_parent.get());
7390
7391 // Only |child| has a scale-affecting animation.
[email protected]a57cb8b12014-06-13 18:15:377392 EXPECT_EQ(0.f,
7393 grand_parent->draw_properties().maximum_animation_contents_scale);
7394 EXPECT_EQ(0.f,
7395 parent_raw->draw_properties().maximum_animation_contents_scale);
7396 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
7397 EXPECT_EQ(
7398 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227399
ajuma052892e2015-08-21 14:39:037400 EXPECT_EQ(0.f,
7401 grand_parent->draw_properties().starting_animation_contents_scale);
7402 EXPECT_EQ(0.f,
7403 parent_raw->draw_properties().starting_animation_contents_scale);
7404 EXPECT_EQ(1.f,
7405 child_raw->draw_properties().starting_animation_contents_scale);
7406 EXPECT_EQ(
7407 1.f,
7408 grand_child_raw->draw_properties().starting_animation_contents_scale);
7409
loyso968163c92016-01-04 23:18:487410 if (layer_settings().use_compositor_animation_timelines) {
7411 AddAnimatedTransformToLayerWithPlayer(grand_parent->id(), timeline, 1.0,
7412 TransformOperations(), scale);
7413 } else {
7414 AddAnimatedTransformToLayer(grand_parent.get(), 1.0, TransformOperations(),
7415 scale);
7416 }
ajumacaaa9b32015-08-04 15:55:297417 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227418 ExecuteCalculateDrawProperties(grand_parent.get());
7419
7420 // |grand_parent| and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377421 EXPECT_EQ(5.f,
7422 grand_parent->draw_properties().maximum_animation_contents_scale);
7423 EXPECT_EQ(5.f,
7424 parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227425 // We don't support combining animated scales from two nodes; 0.f means
7426 // that the maximum scale could not be computed.
[email protected]a57cb8b12014-06-13 18:15:377427 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7428 EXPECT_EQ(
7429 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227430
ajuma052892e2015-08-21 14:39:037431 EXPECT_EQ(1.f,
7432 grand_parent->draw_properties().starting_animation_contents_scale);
7433 EXPECT_EQ(1.f,
7434 parent_raw->draw_properties().starting_animation_contents_scale);
7435 EXPECT_EQ(0.f,
7436 child_raw->draw_properties().starting_animation_contents_scale);
7437 EXPECT_EQ(
7438 0.f,
7439 grand_child_raw->draw_properties().starting_animation_contents_scale);
7440
loyso968163c92016-01-04 23:18:487441 if (layer_settings().use_compositor_animation_timelines) {
7442 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7443 TransformOperations(), scale);
7444 } else {
7445 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
7446 }
ajumacaaa9b32015-08-04 15:55:297447 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227448 ExecuteCalculateDrawProperties(grand_parent.get());
7449
7450 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377451 EXPECT_EQ(5.f,
7452 grand_parent->draw_properties().maximum_animation_contents_scale);
7453 EXPECT_EQ(0.f,
7454 parent_raw->draw_properties().maximum_animation_contents_scale);
7455 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7456 EXPECT_EQ(
7457 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227458
ajuma052892e2015-08-21 14:39:037459 EXPECT_EQ(1.f,
7460 grand_parent->draw_properties().starting_animation_contents_scale);
7461 EXPECT_EQ(0.f,
7462 parent_raw->draw_properties().starting_animation_contents_scale);
7463 EXPECT_EQ(0.f,
7464 child_raw->draw_properties().starting_animation_contents_scale);
7465 EXPECT_EQ(
7466 0.f,
7467 grand_child_raw->draw_properties().starting_animation_contents_scale);
7468
loyso968163c92016-01-04 23:18:487469 if (layer_settings().use_compositor_animation_timelines) {
7470 AbortAnimationsOnLayerWithPlayer(grand_parent->id(), timeline,
7471 Animation::TRANSFORM);
7472 AbortAnimationsOnLayerWithPlayer(parent_raw->id(), timeline,
7473 Animation::TRANSFORM);
7474 AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline,
7475 Animation::TRANSFORM);
7476 } else {
7477 grand_parent->layer_animation_controller()->AbortAnimations(
7478 Animation::TRANSFORM);
7479 parent_raw->layer_animation_controller()->AbortAnimations(
7480 Animation::TRANSFORM);
7481 child_raw->layer_animation_controller()->AbortAnimations(
7482 Animation::TRANSFORM);
7483 }
[email protected]1c3626e2014-04-09 17:49:227484
7485 TransformOperations perspective;
7486 perspective.AppendPerspective(10.f);
7487
loyso968163c92016-01-04 23:18:487488 if (layer_settings().use_compositor_animation_timelines) {
7489 AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0,
7490 TransformOperations(), perspective);
7491 } else {
7492 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(),
7493 perspective);
7494 }
ajumab4a846f22015-08-24 19:13:447495 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227496 ExecuteCalculateDrawProperties(grand_parent.get());
7497
7498 // |child| has a scale-affecting animation but computing the maximum of this
7499 // animation is not supported.
[email protected]a57cb8b12014-06-13 18:15:377500 EXPECT_EQ(0.f,
7501 grand_parent->draw_properties().maximum_animation_contents_scale);
7502 EXPECT_EQ(0.f,
7503 parent_raw->draw_properties().maximum_animation_contents_scale);
7504 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7505 EXPECT_EQ(
7506 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227507
ajuma052892e2015-08-21 14:39:037508 EXPECT_EQ(0.f,
7509 grand_parent->draw_properties().starting_animation_contents_scale);
7510 EXPECT_EQ(0.f,
7511 parent_raw->draw_properties().starting_animation_contents_scale);
7512 EXPECT_EQ(0.f,
7513 child_raw->draw_properties().starting_animation_contents_scale);
7514 EXPECT_EQ(
7515 0.f,
7516 grand_child_raw->draw_properties().starting_animation_contents_scale);
7517
loyso968163c92016-01-04 23:18:487518 if (layer_settings().use_compositor_animation_timelines) {
7519 AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline,
7520 Animation::TRANSFORM);
7521 } else {
7522 child_raw->layer_animation_controller()->AbortAnimations(
7523 Animation::TRANSFORM);
7524 }
[email protected]1c3626e2014-04-09 17:49:227525 gfx::Transform scale_matrix;
7526 scale_matrix.Scale(1.f, 2.f);
7527 grand_parent->SetTransform(scale_matrix);
7528 parent_raw->SetTransform(scale_matrix);
miletus843080c2015-06-11 22:11:017529 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:487530
7531 if (layer_settings().use_compositor_animation_timelines) {
7532 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7533 TransformOperations(), scale);
7534 } else {
7535 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
7536 }
[email protected]1c3626e2014-04-09 17:49:227537 ExecuteCalculateDrawProperties(grand_parent.get());
7538
7539 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7540 // animation with maximum scale 5.f.
[email protected]a57cb8b12014-06-13 18:15:377541 EXPECT_EQ(0.f,
7542 grand_parent->draw_properties().maximum_animation_contents_scale);
7543 EXPECT_EQ(10.f,
7544 parent_raw->draw_properties().maximum_animation_contents_scale);
7545 EXPECT_EQ(10.f,
7546 child_raw->draw_properties().maximum_animation_contents_scale);
7547 EXPECT_EQ(
7548 10.f,
7549 grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227550
ajuma052892e2015-08-21 14:39:037551 EXPECT_EQ(0.f,
7552 grand_parent->draw_properties().starting_animation_contents_scale);
7553 EXPECT_EQ(2.f,
7554 parent_raw->draw_properties().starting_animation_contents_scale);
7555 EXPECT_EQ(2.f,
7556 child_raw->draw_properties().starting_animation_contents_scale);
7557 EXPECT_EQ(
7558 2.f,
7559 grand_child_raw->draw_properties().starting_animation_contents_scale);
7560
[email protected]1c3626e2014-04-09 17:49:227561 gfx::Transform perspective_matrix;
7562 perspective_matrix.ApplyPerspectiveDepth(2.f);
7563 child_raw->SetTransform(perspective_matrix);
miletus843080c2015-06-11 22:11:017564 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227565 ExecuteCalculateDrawProperties(grand_parent.get());
7566
7567 // |child| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:377568 EXPECT_EQ(0.f,
7569 grand_parent->draw_properties().maximum_animation_contents_scale);
7570 EXPECT_EQ(10.f,
7571 parent_raw->draw_properties().maximum_animation_contents_scale);
7572 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7573 EXPECT_EQ(
7574 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227575
ajuma052892e2015-08-21 14:39:037576 EXPECT_EQ(0.f,
7577 grand_parent->draw_properties().starting_animation_contents_scale);
7578 EXPECT_EQ(2.f,
7579 parent_raw->draw_properties().starting_animation_contents_scale);
7580 EXPECT_EQ(0.f,
7581 child_raw->draw_properties().starting_animation_contents_scale);
7582 EXPECT_EQ(
7583 0.f,
7584 grand_child_raw->draw_properties().starting_animation_contents_scale);
7585
[email protected]1c3626e2014-04-09 17:49:227586 parent_raw->SetTransform(perspective_matrix);
miletus843080c2015-06-11 22:11:017587 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227588 ExecuteCalculateDrawProperties(grand_parent.get());
7589
7590 // |parent| and |child| have transforms that are neither translations nor
7591 // scales.
[email protected]a57cb8b12014-06-13 18:15:377592 EXPECT_EQ(0.f,
7593 grand_parent->draw_properties().maximum_animation_contents_scale);
7594 EXPECT_EQ(0.f,
7595 parent_raw->draw_properties().maximum_animation_contents_scale);
7596 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7597 EXPECT_EQ(
7598 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227599
ajuma052892e2015-08-21 14:39:037600 EXPECT_EQ(0.f,
7601 grand_parent->draw_properties().starting_animation_contents_scale);
7602 EXPECT_EQ(0.f,
7603 parent_raw->draw_properties().starting_animation_contents_scale);
7604 EXPECT_EQ(0.f,
7605 child_raw->draw_properties().starting_animation_contents_scale);
7606 EXPECT_EQ(
7607 0.f,
7608 grand_child_raw->draw_properties().starting_animation_contents_scale);
7609
[email protected]1c3626e2014-04-09 17:49:227610 parent_raw->SetTransform(identity_matrix);
7611 child_raw->SetTransform(identity_matrix);
7612 grand_parent->SetTransform(perspective_matrix);
miletus843080c2015-06-11 22:11:017613 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227614
7615 ExecuteCalculateDrawProperties(grand_parent.get());
7616
7617 // |grand_parent| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:377618 EXPECT_EQ(0.f,
7619 grand_parent->draw_properties().maximum_animation_contents_scale);
7620 EXPECT_EQ(0.f,
7621 parent_raw->draw_properties().maximum_animation_contents_scale);
7622 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7623 EXPECT_EQ(
7624 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037625
7626 EXPECT_EQ(0.f,
7627 grand_parent->draw_properties().starting_animation_contents_scale);
7628 EXPECT_EQ(0.f,
7629 parent_raw->draw_properties().starting_animation_contents_scale);
7630 EXPECT_EQ(0.f,
7631 child_raw->draw_properties().starting_animation_contents_scale);
7632 EXPECT_EQ(
7633 0.f,
7634 grand_child_raw->draw_properties().starting_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227635}
7636
[email protected]390bb1ff2014-05-09 17:14:407637static int membership_id(LayerImpl* layer) {
7638 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
7639}
7640
7641static void GatherDrawnLayers(LayerImplList* rsll,
7642 std::set<LayerImpl*>* drawn_layers) {
enne389d1a12015-06-18 20:40:517643 for (LayerIterator it = LayerIterator::Begin(rsll),
7644 end = LayerIterator::End(rsll);
7645 it != end; ++it) {
[email protected]390bb1ff2014-05-09 17:14:407646 LayerImpl* layer = *it;
7647 if (it.represents_itself())
7648 drawn_layers->insert(layer);
7649
7650 if (!it.represents_contributing_render_surface())
7651 continue;
7652
7653 if (layer->mask_layer())
7654 drawn_layers->insert(layer->mask_layer());
7655 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
7656 drawn_layers->insert(layer->replica_layer()->mask_layer());
7657 }
7658}
7659
7660TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:167661 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]390bb1ff2014-05-09 17:14:407662 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567663 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167664 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567665 &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:407666 gfx::Transform identity_matrix;
7667
7668 scoped_ptr<LayerImpl> grand_parent =
7669 LayerImpl::Create(host_impl.active_tree(), 1);
7670 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
7671 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
7672 scoped_ptr<LayerImpl> grand_child1 =
7673 LayerImpl::Create(host_impl.active_tree(), 7);
7674 scoped_ptr<LayerImpl> grand_child2 =
7675 LayerImpl::Create(host_impl.active_tree(), 9);
7676
7677 LayerImpl* grand_parent_raw = grand_parent.get();
7678 LayerImpl* parent_raw = parent.get();
7679 LayerImpl* child_raw = child.get();
7680 LayerImpl* grand_child1_raw = grand_child1.get();
7681 LayerImpl* grand_child2_raw = grand_child2.get();
7682
danakja04855a2015-11-18 20:39:107683 child->AddChild(std::move(grand_child1));
7684 child->AddChild(std::move(grand_child2));
7685 parent->AddChild(std::move(child));
7686 grand_parent->AddChild(std::move(parent));
[email protected]390bb1ff2014-05-09 17:14:407687
awoloszyne83f28c2014-12-22 15:40:007688 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
7689 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7690 true, false, true);
7691 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7692 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:407693 false);
awoloszyne83f28c2014-12-22 15:40:007694
7695 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7696 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:407697 false);
awoloszyne83f28c2014-12-22 15:40:007698
7699 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
7700 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7701 true, false, false);
7702
7703 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
7704 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7705 true, false, false);
[email protected]390bb1ff2014-05-09 17:14:407706
7707 // Start with nothing being drawn.
7708 ExecuteCalculateDrawProperties(grand_parent_raw);
7709 int member_id = render_surface_layer_list_count();
7710
7711 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7712 EXPECT_NE(member_id, membership_id(parent_raw));
7713 EXPECT_NE(member_id, membership_id(child_raw));
7714 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7715 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7716
7717 std::set<LayerImpl*> expected;
7718 std::set<LayerImpl*> actual;
7719 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7720 EXPECT_EQ(expected, actual);
7721
7722 // If we force render surface, but none of the layers are in the layer list,
7723 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:007724 grand_child1_raw->SetHasRenderSurface(true);
jaydasikaebf9e4ea2015-08-14 21:29:127725 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407726
7727 ExecuteCalculateDrawProperties(grand_parent_raw);
7728 member_id = render_surface_layer_list_count();
7729
7730 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7731 EXPECT_NE(member_id, membership_id(parent_raw));
7732 EXPECT_NE(member_id, membership_id(child_raw));
7733 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7734 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7735
7736 expected.clear();
7737 actual.clear();
7738 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7739 EXPECT_EQ(expected, actual);
7740
7741 // However, if we say that this layer also draws content, it will appear in
7742 // RSLL.
7743 grand_child1_raw->SetDrawsContent(true);
7744
7745 ExecuteCalculateDrawProperties(grand_parent_raw);
7746 member_id = render_surface_layer_list_count();
7747
7748 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7749 EXPECT_NE(member_id, membership_id(parent_raw));
7750 EXPECT_NE(member_id, membership_id(child_raw));
7751 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
7752 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7753
7754 expected.clear();
7755 expected.insert(grand_child1_raw);
7756
7757 actual.clear();
7758 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7759 EXPECT_EQ(expected, actual);
7760
7761 // Now child is forced to have a render surface, and one if its children draws
7762 // content.
7763 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:007764 grand_child1_raw->SetHasRenderSurface(false);
jaydasikaebf9e4ea2015-08-14 21:29:127765 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
awoloszyne83f28c2014-12-22 15:40:007766 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:407767 grand_child2_raw->SetDrawsContent(true);
7768
7769 ExecuteCalculateDrawProperties(grand_parent_raw);
7770 member_id = render_surface_layer_list_count();
7771
7772 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7773 EXPECT_NE(member_id, membership_id(parent_raw));
7774 EXPECT_NE(member_id, membership_id(child_raw));
7775 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7776 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7777
7778 expected.clear();
7779 expected.insert(grand_child2_raw);
7780
7781 actual.clear();
7782 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7783 EXPECT_EQ(expected, actual);
7784
7785 // Add a mask layer to child.
danakja5a05ba02015-11-20 20:14:217786 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:047787 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407788
7789 ExecuteCalculateDrawProperties(grand_parent_raw);
7790 member_id = render_surface_layer_list_count();
7791
7792 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7793 EXPECT_NE(member_id, membership_id(parent_raw));
7794 EXPECT_NE(member_id, membership_id(child_raw));
7795 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7796 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7797 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7798
7799 expected.clear();
7800 expected.insert(grand_child2_raw);
7801 expected.insert(child_raw->mask_layer());
7802
7803 expected.clear();
7804 expected.insert(grand_child2_raw);
7805 expected.insert(child_raw->mask_layer());
7806
7807 actual.clear();
7808 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7809 EXPECT_EQ(expected, actual);
7810
7811 // Add replica mask layer.
7812 scoped_ptr<LayerImpl> replica_layer =
7813 LayerImpl::Create(host_impl.active_tree(), 20);
7814 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
danakja04855a2015-11-18 20:39:107815 child_raw->SetReplicaLayer(std::move(replica_layer));
jaydasika23fb3822015-08-25 03:22:597816 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407817
7818 ExecuteCalculateDrawProperties(grand_parent_raw);
7819 member_id = render_surface_layer_list_count();
7820
7821 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7822 EXPECT_NE(member_id, membership_id(parent_raw));
7823 EXPECT_NE(member_id, membership_id(child_raw));
7824 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7825 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
7826 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7827 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7828
7829 expected.clear();
7830 expected.insert(grand_child2_raw);
7831 expected.insert(child_raw->mask_layer());
7832 expected.insert(child_raw->replica_layer()->mask_layer());
7833
7834 actual.clear();
7835 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7836 EXPECT_EQ(expected, actual);
7837
7838 child_raw->TakeReplicaLayer();
7839
7840 // With nothing drawing, we should have no layers.
7841 grand_child2_raw->SetDrawsContent(false);
7842
7843 ExecuteCalculateDrawProperties(grand_parent_raw);
7844 member_id = render_surface_layer_list_count();
7845
7846 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7847 EXPECT_NE(member_id, membership_id(parent_raw));
7848 EXPECT_NE(member_id, membership_id(child_raw));
7849 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
7850 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7851 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7852
7853 expected.clear();
7854 actual.clear();
7855 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7856 EXPECT_EQ(expected, actual);
7857
7858 // Child itself draws means that we should have the child and the mask in the
7859 // list.
7860 child_raw->SetDrawsContent(true);
7861
7862 ExecuteCalculateDrawProperties(grand_parent_raw);
7863 member_id = render_surface_layer_list_count();
7864
7865 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7866 EXPECT_NE(member_id, membership_id(parent_raw));
7867 EXPECT_EQ(member_id, membership_id(child_raw));
7868 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7869 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7870 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7871
7872 expected.clear();
7873 expected.insert(child_raw);
7874 expected.insert(child_raw->mask_layer());
7875 actual.clear();
7876 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7877 EXPECT_EQ(expected, actual);
7878
7879 child_raw->TakeMaskLayer();
jaydasikad36e7fa2015-07-14 15:15:047880 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407881
7882 // Now everyone's a member!
7883 grand_parent_raw->SetDrawsContent(true);
7884 parent_raw->SetDrawsContent(true);
7885 child_raw->SetDrawsContent(true);
7886 grand_child1_raw->SetDrawsContent(true);
7887 grand_child2_raw->SetDrawsContent(true);
7888
7889 ExecuteCalculateDrawProperties(grand_parent_raw);
7890 member_id = render_surface_layer_list_count();
7891
7892 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
7893 EXPECT_EQ(member_id, membership_id(parent_raw));
7894 EXPECT_EQ(member_id, membership_id(child_raw));
7895 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
7896 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7897
7898 expected.clear();
7899 expected.insert(grand_parent_raw);
7900 expected.insert(parent_raw);
7901 expected.insert(child_raw);
7902 expected.insert(grand_child1_raw);
7903 expected.insert(grand_child2_raw);
7904
7905 actual.clear();
7906 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7907 EXPECT_EQ(expected, actual);
7908}
[email protected]18e69652014-06-13 12:50:587909
7910TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:167911 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]18e69652014-06-13 12:50:587912 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567913 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:487914 LayerTreeSettings settings = host()->settings();
enne637715732015-07-07 02:05:267915 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167916 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7917 &shared_bitmap_manager, &task_graph_runner);
[email protected]18e69652014-06-13 12:50:587918
7919 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7920 LayerImpl* root_layer = root.get();
7921 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
7922 LayerImpl* child1_layer = child1.get();
7923 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
7924 LayerImpl* child2_layer = child2.get();
7925
danakja04855a2015-11-18 20:39:107926 root->AddChild(std::move(child1));
7927 root->AddChild(std::move(child2));
weiliangcc154ce22015-12-09 03:39:267928 root->SetForceRenderSurface(true);
jaydasika0d98ba92015-11-17 05:17:287929 root->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587930
7931 gfx::Transform identity_matrix, scale_transform_child1,
7932 scale_transform_child2;
7933 scale_transform_child1.Scale(2, 3);
7934 scale_transform_child2.Scale(4, 5);
7935
awoloszyne83f28c2014-12-22 15:40:007936 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
7937 gfx::PointF(), gfx::Size(1, 1), true, false,
7938 true);
7939 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
jaydasika0d98ba92015-11-17 05:17:287940 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1),
7941 true, false, false);
[email protected]18e69652014-06-13 12:50:587942
danakja5a05ba02015-11-20 20:14:217943 child1_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4));
jaydasika0d98ba92015-11-17 05:17:287944 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587945
7946 scoped_ptr<LayerImpl> replica_layer =
7947 LayerImpl::Create(host_impl.active_tree(), 5);
7948 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
danakja04855a2015-11-18 20:39:107949 child1_layer->SetReplicaLayer(std::move(replica_layer));
awoloszyne83f28c2014-12-22 15:40:007950 child1_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:587951
7952 ExecuteCalculateDrawProperties(root_layer);
7953
7954 TransformOperations scale;
7955 scale.AppendScale(5.f, 8.f, 3.f);
7956
loyso968163c92016-01-04 23:18:487957 if (layer_settings().use_compositor_animation_timelines) {
7958 scoped_refptr<AnimationTimeline> timeline =
7959 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7960 host_impl.animation_host()->AddAnimationTimeline(timeline);
7961
7962 AddAnimatedTransformToLayerWithPlayer(child2_layer->id(), timeline, 1.0,
7963 TransformOperations(), scale);
7964 } else {
7965 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(),
7966 scale);
7967 }
7968
awoloszyne83f28c2014-12-22 15:40:007969 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
jaydasika0d98ba92015-11-17 05:17:287970 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1),
7971 true, false, false);
7972 child2_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587973
jaydasika0d98ba92015-11-17 05:17:287974 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:587975 ExecuteCalculateDrawProperties(root_layer);
7976
enne637715732015-07-07 02:05:267977 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
7978 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
7979 EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale());
7980 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587981
7982 EXPECT_FLOAT_EQ(
7983 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7984 EXPECT_FLOAT_EQ(
7985 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7986 EXPECT_FLOAT_EQ(0.f,
7987 child1_layer->mask_layer()
7988 ->draw_properties()
7989 .maximum_animation_contents_scale);
7990 EXPECT_FLOAT_EQ(0.f,
7991 child1_layer->replica_layer()
7992 ->mask_layer()
7993 ->draw_properties()
7994 .maximum_animation_contents_scale);
7995 EXPECT_FLOAT_EQ(
7996 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
7997
[email protected]18e69652014-06-13 12:50:587998 // Changing page-scale would affect ideal_contents_scale and
7999 // maximum_animation_contents_scale.
8000
8001 float page_scale_factor = 3.f;
8002 float device_scale_factor = 1.0f;
8003 std::vector<LayerImpl*> render_surface_layer_list;
8004 gfx::Size device_viewport_size =
8005 gfx::Size(root_layer->bounds().width() * device_scale_factor,
8006 root_layer->bounds().height() * device_scale_factor);
ajumad9432e32015-11-30 19:43:448007 root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]18e69652014-06-13 12:50:588008 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:448009 root_layer, device_viewport_size, &render_surface_layer_list,
8010 root_layer->layer_tree_impl()->current_render_surface_list_id());
[email protected]18e69652014-06-13 12:50:588011
8012 inputs.page_scale_factor = page_scale_factor;
8013 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:118014 inputs.page_scale_layer = root_layer;
[email protected]18e69652014-06-13 12:50:588015 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8016
enne637715732015-07-07 02:05:268017 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
8018 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
8019 EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588020 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:268021 9.f,
8022 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
8023 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588024
8025 EXPECT_FLOAT_EQ(
8026 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8027 EXPECT_FLOAT_EQ(
8028 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8029 EXPECT_FLOAT_EQ(0.f,
8030 child1_layer->mask_layer()
8031 ->draw_properties()
8032 .maximum_animation_contents_scale);
8033 EXPECT_FLOAT_EQ(0.f,
8034 child1_layer->replica_layer()
8035 ->mask_layer()
8036 ->draw_properties()
8037 .maximum_animation_contents_scale);
8038 EXPECT_FLOAT_EQ(
8039 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8040
[email protected]18e69652014-06-13 12:50:588041 // Changing device-scale would affect ideal_contents_scale and
8042 // maximum_animation_contents_scale.
8043
8044 device_scale_factor = 4.0f;
8045 inputs.device_scale_factor = device_scale_factor;
8046 inputs.can_adjust_raster_scales = true;
jaydasika0d98ba92015-11-17 05:17:288047 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:588048 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8049
enne637715732015-07-07 02:05:268050 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
8051 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
8052 EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588053 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:268054 36.f,
8055 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
8056 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588057
8058 EXPECT_FLOAT_EQ(
8059 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8060 EXPECT_FLOAT_EQ(
8061 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8062 EXPECT_FLOAT_EQ(0.f,
8063 child1_layer->mask_layer()
8064 ->draw_properties()
8065 .maximum_animation_contents_scale);
8066 EXPECT_FLOAT_EQ(0.f,
8067 child1_layer->replica_layer()
8068 ->mask_layer()
8069 ->draw_properties()
8070 .maximum_animation_contents_scale);
8071 EXPECT_FLOAT_EQ(
8072 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
[email protected]18e69652014-06-13 12:50:588073}
8074
danakjf6069db2014-09-13 00:46:478075TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
loysoa6edaaff2015-05-25 03:26:448076 scoped_refptr<Layer> root = Layer::Create(layer_settings());
danakjf6069db2014-09-13 00:46:478077 SetLayerPropertiesForTesting(root.get(),
8078 gfx::Transform(),
8079 gfx::Point3F(),
8080 gfx::PointF(),
8081 gfx::Size(768 / 2, 3000),
8082 true,
8083 false);
8084 root->SetIsDrawable(true);
8085
loysoa6edaaff2015-05-25 03:26:448086 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
danakjf6069db2014-09-13 00:46:478087 SetLayerPropertiesForTesting(clip.get(),
8088 gfx::Transform(),
8089 gfx::Point3F(),
8090 gfx::PointF(),
8091 gfx::Size(768 / 2, 10000),
8092 true,
8093 false);
8094 clip->SetMasksToBounds(true);
8095
loysoa6edaaff2015-05-25 03:26:448096 scoped_refptr<Layer> content = Layer::Create(layer_settings());
danakjf6069db2014-09-13 00:46:478097 SetLayerPropertiesForTesting(content.get(),
8098 gfx::Transform(),
8099 gfx::Point3F(),
8100 gfx::PointF(),
8101 gfx::Size(768 / 2, 10000),
8102 true,
8103 false);
8104 content->SetIsDrawable(true);
8105 content->SetForceRenderSurface(true);
8106
8107 root->AddChild(clip);
8108 clip->AddChild(content);
8109
ennea7b43c32015-06-18 20:01:338110 host()->SetRootLayer(root);
danakjf6069db2014-09-13 00:46:478111
8112 gfx::Size device_viewport_size(768, 582);
enne1e1008c2015-08-21 00:45:468113 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(host()->root_layer(),
8114 device_viewport_size);
danakjf6069db2014-09-13 00:46:478115 inputs.device_scale_factor = 2.f;
8116 inputs.page_scale_factor = 1.f;
enne6394d5b42015-05-26 22:23:118117 inputs.page_scale_layer = NULL;
danakjf6069db2014-09-13 00:46:478118 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8119
8120 // Layers in the root render surface have their visible content rect clipped
8121 // by the viewport.
weiliangc2d58b2c2015-07-29 00:42:438122 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
8123 root->visible_rect_from_property_trees());
danakjf6069db2014-09-13 00:46:478124
8125 // Layers drawing to a child render surface should still have their visible
8126 // content rect clipped by the viewport.
weiliangc2d58b2c2015-07-29 00:42:438127 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
8128 content->visible_rect_from_property_trees());
danakjf6069db2014-09-13 00:46:478129}
8130
timav599f4359d2014-12-05 00:12:228131TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:168132 FakeImplTaskRunnerProvider task_runner_provider;
timav599f4359d2014-12-05 00:12:228133 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:568134 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:168135 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:568136 &task_graph_runner);
timav599f4359d2014-12-05 00:12:228137
8138 // Set two layers: the root layer clips it's child,
8139 // the child draws its content.
8140
8141 gfx::Size root_size = gfx::Size(300, 500);
8142
8143 // Sublayer should be bigger than the root enlarged by bounds_delta.
8144 gfx::Size sublayer_size = gfx::Size(300, 1000);
8145
8146 // Device viewport accomidated the root and the top controls.
8147 gfx::Size device_viewport_size = gfx::Size(300, 600);
8148 gfx::Transform identity_matrix;
8149
miletus8bd08a622015-06-16 18:44:528150 host_impl.SetViewportSize(device_viewport_size);
timav599f4359d2014-12-05 00:12:228151 host_impl.active_tree()->SetRootLayer(
8152 LayerImpl::Create(host_impl.active_tree(), 1));
8153
8154 LayerImpl* root = host_impl.active_tree()->root_layer();
8155 SetLayerPropertiesForTesting(root,
8156 identity_matrix,
8157 gfx::Point3F(),
8158 gfx::PointF(),
8159 root_size,
8160 false,
awoloszyne83f28c2014-12-22 15:40:008161 false,
8162 true);
timav599f4359d2014-12-05 00:12:228163 root->SetMasksToBounds(true);
8164
8165 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
8166
8167 LayerImpl* sublayer = root->child_at(0);
8168 SetLayerPropertiesForTesting(sublayer,
8169 identity_matrix,
8170 gfx::Point3F(),
8171 gfx::PointF(),
8172 sublayer_size,
8173 false,
awoloszyne83f28c2014-12-22 15:40:008174 false,
timav599f4359d2014-12-05 00:12:228175 false);
timav599f4359d2014-12-05 00:12:228176 sublayer->SetDrawsContent(true);
8177
8178 LayerImplList layer_impl_list;
ajumad9432e32015-11-30 19:43:448179 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
timav599f4359d2014-12-05 00:12:228180 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:448181 root, device_viewport_size, &layer_impl_list,
8182 root->layer_tree_impl()->current_render_surface_list_id());
timav599f4359d2014-12-05 00:12:228183
8184 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
danakj64767d902015-06-19 00:10:438185 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228186
8187 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
timav599f4359d2014-12-05 00:12:228188 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8189
8190 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8191 root_size.height() + 50);
danakj64767d902015-06-19 00:10:438192 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228193}
8194
ajumadd2802e72015-06-30 20:28:298195TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
8196 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8197 scoped_refptr<Layer> inner_viewport_container_layer =
8198 Layer::Create(layer_settings());
8199 scoped_refptr<Layer> inner_viewport_scroll_layer =
8200 Layer::Create(layer_settings());
8201 scoped_refptr<Layer> outer_viewport_container_layer =
8202 Layer::Create(layer_settings());
8203 scoped_refptr<Layer> outer_viewport_scroll_layer =
8204 Layer::Create(layer_settings());
8205
8206 root->AddChild(inner_viewport_container_layer);
8207 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
8208 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
8209 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
8210
8211 inner_viewport_scroll_layer->SetScrollClipLayerId(
8212 inner_viewport_container_layer->id());
8213 outer_viewport_scroll_layer->SetScrollClipLayerId(
8214 outer_viewport_container_layer->id());
8215
8216 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8217 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8218
8219 host()->SetRootLayer(root);
8220 host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer,
8221 outer_viewport_scroll_layer);
8222
8223 scoped_refptr<Layer> fixed_to_inner = Layer::Create(layer_settings());
8224 scoped_refptr<Layer> fixed_to_outer = Layer::Create(layer_settings());
8225
8226 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
8227 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
8228
8229 LayerPositionConstraint fixed_to_right;
8230 fixed_to_right.set_is_fixed_position(true);
8231 fixed_to_right.set_is_fixed_to_right_edge(true);
8232
8233 fixed_to_inner->SetPositionConstraint(fixed_to_right);
8234 fixed_to_outer->SetPositionConstraint(fixed_to_right);
8235
8236 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8237
8238 TransformTree& transform_tree = host()->property_trees()->transform_tree;
8239 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8240 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8241
8242 LayerPositionConstraint fixed_to_left;
8243 fixed_to_left.set_is_fixed_position(true);
8244 fixed_to_inner->SetPositionConstraint(fixed_to_left);
8245
8246 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8247 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8248 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8249
8250 fixed_to_outer->SetPositionConstraint(fixed_to_left);
8251
8252 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8253 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8254 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8255}
8256
vollick7d83b452015-02-24 20:18:068257TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
8258 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:448259 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick7d83b452015-02-24 20:18:068260 scoped_refptr<LayerWithForcedDrawsContent> animated =
loysoa6edaaff2015-05-25 03:26:448261 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick7d83b452015-02-24 20:18:068262
8263 root->AddChild(animated);
8264
ennea7b43c32015-06-18 20:01:338265 host()->SetRootLayer(root);
vollick7d83b452015-02-24 20:18:068266
8267 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8268 gfx::PointF(), gfx::Size(100, 100), true, false);
8269 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
8270 gfx::PointF(), gfx::Size(20, 20), true, false);
8271
8272 root->SetMasksToBounds(true);
8273 root->SetForceRenderSurface(true);
8274 animated->SetOpacity(0.f);
8275
loyso968163c92016-01-04 23:18:488276 if (layer_settings().use_compositor_animation_timelines) {
8277 AddOpacityTransitionToLayerWithPlayer(animated->id(), timeline(), 10.0, 0.f,
8278 1.f, false);
8279 } else {
8280 AddOpacityTransitionToController(animated->layer_animation_controller(),
8281 10.0, 0.f, 1.f, false);
8282 }
enne601f2ef12015-05-19 18:20:178283 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick7d83b452015-02-24 20:18:068284
8285 EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty());
8286}
8287
ajumaa92fdc12015-03-31 22:47:418288TEST_F(LayerTreeHostCommonTest,
8289 VisibleContentRectForAnimatedLayerWithSingularTransform) {
8290 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:448291 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8292 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
ajumaa92fdc12015-03-31 22:47:418293 scoped_refptr<LayerWithForcedDrawsContent> animated =
loysoa6edaaff2015-05-25 03:26:448294 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaa92fdc12015-03-31 22:47:418295 scoped_refptr<LayerWithForcedDrawsContent> surface =
loysoa6edaaff2015-05-25 03:26:448296 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaa92fdc12015-03-31 22:47:418297 scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation =
loysoa6edaaff2015-05-25 03:26:448298 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaa92fdc12015-03-31 22:47:418299
8300 root->AddChild(clip);
8301 clip->AddChild(animated);
8302 animated->AddChild(surface);
8303 surface->AddChild(descendant_of_animation);
8304
8305 clip->SetMasksToBounds(true);
8306 surface->SetForceRenderSurface(true);
8307
ennea7b43c32015-06-18 20:01:338308 host()->SetRootLayer(root);
ajumaa92fdc12015-03-31 22:47:418309
8310 gfx::Transform uninvertible_matrix;
8311 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
8312
8313 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8314 gfx::PointF(), gfx::Size(100, 100), true, false);
8315 SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(),
8316 gfx::PointF(), gfx::Size(10, 10), true, false);
8317 SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix,
8318 gfx::Point3F(), gfx::PointF(),
8319 gfx::Size(120, 120), true, false);
8320 SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(),
8321 gfx::PointF(), gfx::Size(100, 100), true, false);
8322 SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix,
8323 gfx::Point3F(), gfx::PointF(),
8324 gfx::Size(200, 200), true, false);
8325
8326 TransformOperations start_transform_operations;
8327 start_transform_operations.AppendMatrix(uninvertible_matrix);
8328 TransformOperations end_transform_operations;
8329
loyso968163c92016-01-04 23:18:488330 if (layer_settings().use_compositor_animation_timelines) {
8331 AddAnimatedTransformToLayerWithPlayer(animated->id(), timeline(), 10.0,
8332 start_transform_operations,
8333 end_transform_operations);
8334 } else {
8335 AddAnimatedTransformToLayer(animated.get(), 10.0,
8336 start_transform_operations,
8337 end_transform_operations);
8338 }
enne601f2ef12015-05-19 18:20:178339 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:418340
8341 // The animated layer has a singular transform and maps to a non-empty rect in
8342 // clipped target space, so is treated as fully visible.
8343 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_rect_from_property_trees());
8344
8345 // The singular transform on |animated| is flattened when inherited by
8346 // |surface|, and this happens to make it invertible.
8347 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_rect_from_property_trees());
8348 EXPECT_EQ(gfx::Rect(2, 2),
8349 descendant_of_animation->visible_rect_from_property_trees());
8350
8351 gfx::Transform zero_matrix;
8352 zero_matrix.Scale3d(0.f, 0.f, 0.f);
8353 SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(),
8354 gfx::PointF(), gfx::Size(120, 120), true, false);
8355
enne601f2ef12015-05-19 18:20:178356 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:418357
8358 // The animated layer maps to the empty rect in clipped target space, so is
8359 // treated as having an empty visible rect.
8360 EXPECT_EQ(gfx::Rect(), animated->visible_rect_from_property_trees());
8361
8362 // This time, flattening does not make |animated|'s transform invertible. This
8363 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:348364 // |surface| and layers that draw into it as having empty visible rect.
8365 EXPECT_EQ(gfx::Rect(), surface->visible_rect_from_property_trees());
8366 EXPECT_EQ(gfx::Rect(),
ajumaa92fdc12015-03-31 22:47:418367 descendant_of_animation->visible_rect_from_property_trees());
8368}
8369
enne92f2f6d92015-02-25 23:13:318370// Verify that having an animated filter (but no current filter, as these
8371// are mutually exclusive) correctly creates a render surface.
8372TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
loysoa6edaaff2015-05-25 03:26:448373 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8374 scoped_refptr<Layer> child = Layer::Create(layer_settings());
8375 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
enne92f2f6d92015-02-25 23:13:318376 root->AddChild(child);
8377 child->AddChild(grandchild);
8378
8379 gfx::Transform identity_transform;
8380 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8381 gfx::PointF(), gfx::Size(50, 50), true, false);
8382 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8383 gfx::PointF(), gfx::Size(50, 50), true, false);
8384 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8385 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
8386 true, false);
ennea7b43c32015-06-18 20:01:338387 host()->SetRootLayer(root);
enne92f2f6d92015-02-25 23:13:318388
loyso968163c92016-01-04 23:18:488389 if (layer_settings().use_compositor_animation_timelines) {
8390 AddAnimatedFilterToLayerWithPlayer(child->id(), timeline(), 10.0, 0.1f,
8391 0.2f);
8392 } else {
8393 AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f);
8394 }
enne92f2f6d92015-02-25 23:13:318395 ExecuteCalculateDrawProperties(root.get());
8396
ennec1332992015-08-24 19:45:098397 EXPECT_TRUE(root->has_render_surface());
8398 EXPECT_TRUE(child->has_render_surface());
8399 EXPECT_FALSE(grandchild->has_render_surface());
enne92f2f6d92015-02-25 23:13:318400
8401 EXPECT_TRUE(root->filters().IsEmpty());
8402 EXPECT_TRUE(child->filters().IsEmpty());
8403 EXPECT_TRUE(grandchild->filters().IsEmpty());
8404
8405 EXPECT_FALSE(root->FilterIsAnimating());
8406 EXPECT_TRUE(child->FilterIsAnimating());
8407 EXPECT_FALSE(grandchild->FilterIsAnimating());
8408}
8409
ajuma315a4782015-07-24 21:16:348410// Verify that having a filter animation with a delayed start time creates a
8411// render surface.
8412TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
8413 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8414 scoped_refptr<Layer> child = Layer::Create(layer_settings());
8415 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
8416 root->AddChild(child);
8417 child->AddChild(grandchild);
8418
8419 gfx::Transform identity_transform;
8420 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8421 gfx::PointF(), gfx::Size(50, 50), true, false);
8422 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8423 gfx::PointF(), gfx::Size(50, 50), true, false);
8424 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8425 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
8426 true, false);
8427 host()->SetRootLayer(root);
8428
8429 scoped_ptr<KeyframedFilterAnimationCurve> curve(
8430 KeyframedFilterAnimationCurve::Create());
8431 FilterOperations start_filters;
8432 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
8433 FilterOperations end_filters;
8434 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
8435 curve->AddKeyframe(
8436 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
8437 curve->AddKeyframe(FilterKeyframe::Create(
8438 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
8439 scoped_ptr<Animation> animation =
danakja04855a2015-11-18 20:39:108440 Animation::Create(std::move(curve), 0, 1, Animation::FILTER);
ajuma315a4782015-07-24 21:16:348441 animation->set_fill_mode(Animation::FILL_MODE_NONE);
8442 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
ajuma315a4782015-07-24 21:16:348443
loyso968163c92016-01-04 23:18:488444 if (layer_settings().use_compositor_animation_timelines) {
8445 AddAnimationToLayerWithPlayer(child->id(), timeline(),
8446 std::move(animation));
8447 } else {
8448 child->layer_animation_controller()->AddAnimation(std::move(animation));
8449 }
ajuma315a4782015-07-24 21:16:348450 ExecuteCalculateDrawProperties(root.get());
8451
ennec1332992015-08-24 19:45:098452 EXPECT_TRUE(root->has_render_surface());
8453 EXPECT_TRUE(child->has_render_surface());
8454 EXPECT_FALSE(grandchild->has_render_surface());
ajuma315a4782015-07-24 21:16:348455
8456 EXPECT_TRUE(root->filters().IsEmpty());
8457 EXPECT_TRUE(child->filters().IsEmpty());
8458 EXPECT_TRUE(grandchild->filters().IsEmpty());
8459
8460 EXPECT_FALSE(root->FilterIsAnimating());
8461 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
8462 EXPECT_FALSE(child->FilterIsAnimating());
8463 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
8464 EXPECT_FALSE(grandchild->FilterIsAnimating());
8465 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
8466}
8467
vollick0120eb22015-03-02 03:07:348468// Ensures that the property tree code accounts for offsets between fixed
8469// position layers and their respective containers.
8470TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
loysoa6edaaff2015-05-25 03:26:448471 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8472 scoped_refptr<Layer> child = Layer::Create(layer_settings());
vollick0120eb22015-03-02 03:07:348473 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loysoa6edaaff2015-05-25 03:26:448474 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick0120eb22015-03-02 03:07:348475
8476 root->AddChild(child);
8477 child->AddChild(grandchild);
8478
8479 gfx::Transform identity_transform;
8480 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8481 gfx::PointF(), gfx::Size(50, 50), true, false);
8482 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8483 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
8484 false);
8485 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8486 gfx::Point3F(), gfx::PointF(-1000, -1000),
8487 gfx::Size(50, 50), true, false);
8488
8489 root->SetMasksToBounds(true);
8490 root->SetIsContainerForFixedPositionLayers(true);
8491 LayerPositionConstraint constraint;
8492 constraint.set_is_fixed_position(true);
8493 grandchild->SetPositionConstraint(constraint);
8494
8495 root->SetIsContainerForFixedPositionLayers(true);
8496
ennea7b43c32015-06-18 20:01:338497 host()->SetRootLayer(root);
vollick0120eb22015-03-02 03:07:348498
enne601f2ef12015-05-19 18:20:178499 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick0120eb22015-03-02 03:07:348500
8501 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
8502 grandchild->visible_rect_from_property_trees());
8503}
8504
ajuma0178b522015-07-02 21:08:418505// Ensures that the property tree code accounts for offsets between fixed
8506// position containers and their transform tree parents, when a fixed position
8507// layer's container is its layer tree parent, but this parent doesn't have its
8508// own transform tree node.
8509TEST_F(LayerTreeHostCommonTest,
8510 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
8511 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8512 scoped_refptr<Layer> child = Layer::Create(layer_settings());
8513 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
8514 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8515
8516 root->AddChild(child);
8517 child->AddChild(grandchild);
8518
8519 gfx::Transform identity_transform;
8520 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8521 gfx::PointF(), gfx::Size(50, 50), true, false);
8522 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8523 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
8524 false);
8525 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8526 gfx::Point3F(), gfx::PointF(-1000, -1000),
8527 gfx::Size(50, 50), true, false);
8528
8529 root->SetMasksToBounds(true);
8530 child->SetIsContainerForFixedPositionLayers(true);
8531 LayerPositionConstraint constraint;
8532 constraint.set_is_fixed_position(true);
8533 grandchild->SetPositionConstraint(constraint);
8534
8535 root->SetIsContainerForFixedPositionLayers(true);
8536
8537 host()->SetRootLayer(root);
8538
8539 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8540
8541 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
8542 grandchild->visible_rect_from_property_trees());
8543}
8544
vollick67394b42015-03-10 00:22:308545TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) {
8546 // In the following layer tree, the layer |box|'s render target is |surface|.
8547 // |surface| also creates a transform node. We want to combine clips for |box|
8548 // in the space of its target (i.e., |surface|), not its target's target. This
8549 // test ensures that happens.
8550
8551 gfx::Transform rotate;
8552 rotate.Rotate(5);
8553 gfx::Transform identity;
8554
loysoa6edaaff2015-05-25 03:26:448555 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:308556 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8557 gfx::PointF(), gfx::Size(2500, 1500), true,
8558 false);
8559
loysoa6edaaff2015-05-25 03:26:448560 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:308561 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8562 gfx::PointF(), gfx::Size(2500, 1500), true,
8563 false);
8564 frame_clip->SetMasksToBounds(true);
8565
loysoa6edaaff2015-05-25 03:26:448566 scoped_refptr<Layer> rotated = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:308567 SetLayerPropertiesForTesting(rotated.get(), rotate,
8568 gfx::Point3F(1250, 250, 0), gfx::PointF(),
8569 gfx::Size(2500, 500), true, false);
8570
loysoa6edaaff2015-05-25 03:26:448571 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:308572 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(),
8573 gfx::PointF(), gfx::Size(2500, 500), true,
8574 false);
8575 surface->SetOpacity(0.5);
8576
8577 scoped_refptr<LayerWithForcedDrawsContent> container =
loysoa6edaaff2015-05-25 03:26:448578 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick67394b42015-03-10 00:22:308579 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(),
8580 gfx::PointF(), gfx::Size(300, 300), true, false);
8581
8582 scoped_refptr<LayerWithForcedDrawsContent> box =
loysoa6edaaff2015-05-25 03:26:448583 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick67394b42015-03-10 00:22:308584 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(),
8585 gfx::PointF(), gfx::Size(100, 100), true, false);
8586
8587 root->AddChild(frame_clip);
8588 frame_clip->AddChild(rotated);
8589 rotated->AddChild(surface);
8590 surface->AddChild(container);
8591 surface->AddChild(box);
8592
ennea7b43c32015-06-18 20:01:338593 host()->SetRootLayer(root);
vollick67394b42015-03-10 00:22:308594
8595 ExecuteCalculateDrawProperties(root.get());
8596}
8597
vollick8c824742015-03-20 22:21:088598TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
8599 gfx::Transform identity;
8600 gfx::Transform translate_z;
8601 translate_z.Translate3d(0, 0, 10);
8602
loysoa6edaaff2015-05-25 03:26:448603 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick8c824742015-03-20 22:21:088604 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8605 gfx::PointF(), gfx::Size(800, 800), true, false);
8606 root->SetIsContainerForFixedPositionLayers(true);
8607
loysoa6edaaff2015-05-25 03:26:448608 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollick8c824742015-03-20 22:21:088609 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
8610 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8611 false);
8612 frame_clip->SetMasksToBounds(true);
8613
8614 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:448615 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick8c824742015-03-20 22:21:088616 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8617 gfx::PointF(), gfx::Size(1000, 1000), true,
8618 false);
8619
8620 LayerPositionConstraint constraint;
8621 constraint.set_is_fixed_position(true);
8622 fixed->SetPositionConstraint(constraint);
8623
8624 root->AddChild(frame_clip);
8625 frame_clip->AddChild(fixed);
8626
ennea7b43c32015-06-18 20:01:338627 host()->SetRootLayer(root);
vollick8c824742015-03-20 22:21:088628
enne601f2ef12015-05-19 18:20:178629 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick8c824742015-03-20 22:21:088630
8631 gfx::Rect expected(0, 0, 100, 100);
8632 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
8633}
8634
vollickf6281c42015-03-30 21:44:418635TEST_F(LayerTreeHostCommonTest,
8636 PropertyTreesAccountForScrollCompensationAdjustment) {
8637 gfx::Transform identity;
8638 gfx::Transform translate_z;
8639 translate_z.Translate3d(0, 0, 10);
8640
loysoa6edaaff2015-05-25 03:26:448641 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollickf6281c42015-03-30 21:44:418642 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8643 gfx::PointF(), gfx::Size(800, 800), true, false);
8644 root->SetIsContainerForFixedPositionLayers(true);
8645
loysoa6edaaff2015-05-25 03:26:448646 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollickf6281c42015-03-30 21:44:418647 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
8648 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8649 false);
8650 frame_clip->SetMasksToBounds(true);
8651
8652 scoped_refptr<LayerWithForcedDrawsContent> scroller =
loysoa6edaaff2015-05-25 03:26:448653 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollickf6281c42015-03-30 21:44:418654 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
8655 gfx::PointF(), gfx::Size(1000, 1000), true,
8656 false);
8657
8658 scroller->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f, 0.7f));
8659 scroller->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
8660 scroller->SetScrollClipLayerId(frame_clip->id());
8661
8662 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:448663 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollickf6281c42015-03-30 21:44:418664 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8665 gfx::PointF(), gfx::Size(50, 50), true, false);
8666
8667 LayerPositionConstraint constraint;
8668 constraint.set_is_fixed_position(true);
8669 fixed->SetPositionConstraint(constraint);
8670
8671 scoped_refptr<LayerWithForcedDrawsContent> fixed_child =
loysoa6edaaff2015-05-25 03:26:448672 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollickf6281c42015-03-30 21:44:418673 SetLayerPropertiesForTesting(fixed_child.get(), identity, gfx::Point3F(),
8674 gfx::PointF(), gfx::Size(10, 10), true, false);
8675
8676 fixed_child->SetPositionConstraint(constraint);
8677
8678 root->AddChild(frame_clip);
8679 frame_clip->AddChild(scroller);
8680 scroller->AddChild(fixed);
8681 fixed->AddChild(fixed_child);
8682
ennea7b43c32015-06-18 20:01:338683 host()->SetRootLayer(root);
vollickf6281c42015-03-30 21:44:418684
enne601f2ef12015-05-19 18:20:178685 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollickf6281c42015-03-30 21:44:418686
8687 gfx::Rect expected(0, 0, 50, 50);
8688 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
8689
8690 expected = gfx::Rect(0, 0, 10, 10);
8691 EXPECT_EQ(expected, fixed_child->visible_rect_from_property_trees());
8692}
8693
vollick06ca3e832015-03-31 19:37:128694TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
8695 gfx::Transform identity;
8696
loysoa6edaaff2015-05-25 03:26:448697 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick06ca3e832015-03-31 19:37:128698 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8699 gfx::PointF(), gfx::Size(800, 800), true, false);
8700 root->SetIsContainerForFixedPositionLayers(true);
8701
loysoa6edaaff2015-05-25 03:26:448702 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollick06ca3e832015-03-31 19:37:128703 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8704 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8705 false);
8706 frame_clip->SetMasksToBounds(true);
8707
8708 scoped_refptr<LayerWithForcedDrawsContent> scroller =
loysoa6edaaff2015-05-25 03:26:448709 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick06ca3e832015-03-31 19:37:128710 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
8711 gfx::PointF(), gfx::Size(1000, 1000), true,
8712 false);
8713
8714 scroller->SetScrollOffset(gfx::ScrollOffset(100, 100));
8715 scroller->SetScrollClipLayerId(frame_clip->id());
8716
8717 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:448718 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick06ca3e832015-03-31 19:37:128719 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8720 gfx::PointF(100, 100), gfx::Size(50, 50), true,
8721 false);
8722
8723 LayerPositionConstraint constraint;
8724 constraint.set_is_fixed_position(true);
8725 fixed->SetPositionConstraint(constraint);
8726 fixed->SetForceRenderSurface(true);
8727 fixed->SetMasksToBounds(true);
8728
8729 root->AddChild(frame_clip);
8730 frame_clip->AddChild(scroller);
8731 scroller->AddChild(fixed);
8732
ennea7b43c32015-06-18 20:01:338733 host()->SetRootLayer(root);
vollick06ca3e832015-03-31 19:37:128734
enne601f2ef12015-05-19 18:20:178735 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick06ca3e832015-03-31 19:37:128736
8737 gfx::Rect expected(0, 0, 50, 50);
8738 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
8739}
8740
vollick5057e1e2015-04-17 19:12:328741TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
8742 gfx::Transform identity;
8743 gfx::Transform translate;
8744 gfx::Transform rotate;
8745
8746 translate.Translate(10, 10);
8747 rotate.Rotate(45);
8748
loysoa6edaaff2015-05-25 03:26:448749 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick5057e1e2015-04-17 19:12:328750 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8751 gfx::PointF(), gfx::Size(800, 800), true, false);
8752 root->SetIsContainerForFixedPositionLayers(true);
8753
ennea7b43c32015-06-18 20:01:338754 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:328755
enne601f2ef12015-05-19 18:20:178756 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ennea7b43c32015-06-18 20:01:338757 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328758
8759 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:338760 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328761
8762 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:338763 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328764}
8765
ajumab0e0c1c2015-04-23 00:29:238766TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
loysoa6edaaff2015-05-25 03:26:448767 scoped_refptr<Layer> root = Layer::Create(layer_settings());
ajumab0e0c1c2015-04-23 00:29:238768 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:448769 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumab0e0c1c2015-04-23 00:29:238770 root->AddChild(child);
8771
ennea7b43c32015-06-18 20:01:338772 host()->SetRootLayer(root);
ajumab0e0c1c2015-04-23 00:29:238773
8774 gfx::Transform identity_matrix;
8775 gfx::Transform scale_matrix;
8776 scale_matrix.Scale(2.f, 2.f);
8777 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8778 gfx::PointF(), gfx::Size(100, 100), true, false);
8779 SetLayerPropertiesForTesting(child.get(), scale_matrix, gfx::Point3F(),
8780 gfx::PointF(), gfx::Size(10, 10), true, false);
8781
enne601f2ef12015-05-19 18:20:178782 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumab0e0c1c2015-04-23 00:29:238783 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
8784
8785 child->SetTransformOrigin(gfx::Point3F(10.f, 10.f, 10.f));
8786
enne601f2ef12015-05-19 18:20:178787 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumab0e0c1c2015-04-23 00:29:238788 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_rect_from_property_trees());
8789}
8790
ajumaf09db8962015-04-24 21:55:348791TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
loysoa6edaaff2015-05-25 03:26:448792 scoped_refptr<Layer> root = Layer::Create(layer_settings());
ajumaf09db8962015-04-24 21:55:348793 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
loysoa6edaaff2015-05-25 03:26:448794 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaf09db8962015-04-24 21:55:348795 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
loysoa6edaaff2015-05-25 03:26:448796 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaf09db8962015-04-24 21:55:348797
8798 root->AddChild(scroll_child);
8799 root->AddChild(scroll_parent);
8800 scroll_child->SetScrollParent(scroll_parent.get());
8801 scroll_parent->SetScrollClipLayerId(root->id());
8802
ennea7b43c32015-06-18 20:01:338803 host()->SetRootLayer(root);
ajumaf09db8962015-04-24 21:55:348804
8805 gfx::Transform identity_transform;
8806 gfx::Transform scale;
8807 scale.Scale(2.f, 2.f);
8808 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8809 gfx::PointF(), gfx::Size(50, 50), true, false);
8810 SetLayerPropertiesForTesting(scroll_child.get(), scale, gfx::Point3F(),
8811 gfx::PointF(), gfx::Size(40, 40), true, false);
8812 SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform,
8813 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
8814 true, false);
8815
enne601f2ef12015-05-19 18:20:178816 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaf09db8962015-04-24 21:55:348817 EXPECT_EQ(gfx::Rect(25, 25),
8818 scroll_child->visible_rect_from_property_trees());
8819
8820 scroll_child->SetPosition(gfx::PointF(0, -10.f));
8821 scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f));
enne601f2ef12015-05-19 18:20:178822 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaf09db8962015-04-24 21:55:348823 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
8824 scroll_child->visible_rect_from_property_trees());
8825}
8826
vollick2175fae82015-04-27 21:18:128827static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
8828}
8829
sunxded58688e2016-01-11 21:01:028830TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) {
8831 // If the layer has a node in effect_tree, the return value of
8832 // num_copy_requests_in_target_subtree() must be equal to the actual number
8833 // of copy requests in the sub-layer_tree; Otherwise, the number is expected
8834 // to be the value of its nearest ancestor that owns an effect node and
8835 // greater than or equal to the actual number of copy requests in the
8836 // sub-layer_tree.
8837
8838 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8839 scoped_refptr<Layer> child1 = Layer::Create(layer_settings());
8840 scoped_refptr<Layer> child2 = Layer::Create(layer_settings());
8841 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
8842 scoped_refptr<Layer> greatgrandchild = Layer::Create(layer_settings());
8843
8844 root->AddChild(child1);
8845 root->AddChild(child2);
8846 child1->AddChild(grandchild);
8847 grandchild->AddChild(greatgrandchild);
8848 host()->SetRootLayer(root);
8849
8850 child1->RequestCopyOfOutput(
8851 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8852 greatgrandchild->RequestCopyOfOutput(
8853 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8854 child2->SetOpacity(0.f);
8855 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8856
8857 EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2);
8858 EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2);
8859 EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0);
8860 EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2);
8861 EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1);
8862}
8863
vollick2175fae82015-04-27 21:18:128864TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
8865 gfx::Transform identity;
loysoa6edaaff2015-05-25 03:26:448866 scoped_refptr<Layer> root = Layer::Create(layer_settings());
chrishtr01539b802015-11-24 08:11:328867 FakeContentLayerClient client;
8868 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:128869 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:448870 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick2175fae82015-04-27 21:18:128871 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loysoa6edaaff2015-05-25 03:26:448872 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
danakj4e95f7632015-06-05 19:46:258873 scoped_refptr<FakePictureLayer> greatgrandchild(
8874 FakePictureLayer::Create(layer_settings(), &client));
vollick2175fae82015-04-27 21:18:128875 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8876 gfx::PointF(), gfx::Size(100, 100), true, false);
8877 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8878 gfx::PointF(), gfx::Size(10, 10), true, false);
8879 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8880 gfx::PointF(), gfx::Size(10, 10), true, false);
8881 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
8882 gfx::PointF(), gfx::Size(10, 10), true, false);
8883
8884 root->AddChild(child);
8885 child->AddChild(grandchild);
8886 grandchild->AddChild(greatgrandchild);
8887
ennea7b43c32015-06-18 20:01:338888 host()->SetRootLayer(root);
vollick2175fae82015-04-27 21:18:128889
8890 // Check the non-skipped case.
enne601f2ef12015-05-19 18:20:178891 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128892 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
8893
8894 // Now we will reset the visible rect from property trees for the grandchild,
8895 // and we will configure |child| in several ways that should force the subtree
8896 // to be skipped. The visible content rect for |grandchild| should, therefore,
8897 // remain empty.
8898 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
8899 gfx::Transform singular;
8900 singular.matrix().set(0, 0, 0);
8901
8902 child->SetTransform(singular);
enne601f2ef12015-05-19 18:20:178903 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128904 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8905 child->SetTransform(identity);
8906
8907 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:178908 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128909 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8910 child->SetHideLayerAndSubtree(false);
8911
ajuma315a4782015-07-24 21:16:348912 gfx::Transform zero_z_scale;
8913 zero_z_scale.Scale3d(1, 1, 0);
8914 child->SetTransform(zero_z_scale);
8915
8916 // Add a transform animation with a start delay. Now, even though |child| has
8917 // a singular transform, the subtree should still get processed.
8918 int animation_id = 0;
8919 scoped_ptr<Animation> animation = Animation::Create(
danakja5a05ba02015-11-20 20:14:218920 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
ajuma315a4782015-07-24 21:16:348921 animation_id, 1, Animation::TRANSFORM);
8922 animation->set_fill_mode(Animation::FILL_MODE_NONE);
8923 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso968163c92016-01-04 23:18:488924 if (layer_settings().use_compositor_animation_timelines) {
8925 AddAnimationToLayerWithPlayer(child->id(), timeline(),
8926 std::move(animation));
8927 } else {
8928 child->AddAnimation(std::move(animation));
8929 }
ajuma315a4782015-07-24 21:16:348930 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8931 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
8932 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
8933
loyso968163c92016-01-04 23:18:488934 if (layer_settings().use_compositor_animation_timelines) {
8935 RemoveAnimationFromLayerWithExistingPlayer(child->id(), timeline(),
8936 animation_id);
8937 } else {
8938 child->RemoveAnimation(animation_id);
8939 }
ajuma315a4782015-07-24 21:16:348940 child->SetTransform(identity);
vollick2175fae82015-04-27 21:18:128941 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:178942 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128943 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8944
8945 // Now, even though child has zero opacity, we will configure |grandchild| and
8946 // |greatgrandchild| in several ways that should force the subtree to be
8947 // processed anyhow.
jaydasika86654512016-01-27 17:05:078948 grandchild->RequestCopyOfOutput(
vollick2175fae82015-04-27 21:18:128949 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
enne601f2ef12015-05-19 18:20:178950 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128951 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
jaydasika86654512016-01-27 17:05:078952 greatgrandchild->set_visible_rect_from_property_trees(gfx::Rect());
ajuma315a4782015-07-24 21:16:348953
8954 // Add an opacity animation with a start delay.
8955 animation_id = 1;
8956 animation = Animation::Create(
danakja5a05ba02015-11-20 20:14:218957 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
ajuma315a4782015-07-24 21:16:348958 animation_id, 1, Animation::OPACITY);
8959 animation->set_fill_mode(Animation::FILL_MODE_NONE);
8960 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso968163c92016-01-04 23:18:488961 if (layer_settings().use_compositor_animation_timelines) {
8962 AddAnimationToLayerWithExistingPlayer(child->id(), timeline(),
8963 std::move(animation));
8964 } else {
8965 child->AddAnimation(std::move(animation));
8966 }
ajuma315a4782015-07-24 21:16:348967 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8968 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
vollick2175fae82015-04-27 21:18:128969}
8970
8971TEST_F(LayerTreeHostCommonTest, SkippingSubtreeImpl) {
khushalsagarb64b360d2015-10-21 19:25:168972 FakeImplTaskRunnerProvider task_runner_provider;
vollick2175fae82015-04-27 21:18:128973 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:568974 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:168975 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:568976 &task_graph_runner);
vollick2175fae82015-04-27 21:18:128977
8978 gfx::Transform identity;
8979 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
8980 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
8981 scoped_ptr<LayerImpl> grandchild =
8982 LayerImpl::Create(host_impl.active_tree(), 3);
8983
danakj4e95f7632015-06-05 19:46:258984 scoped_ptr<FakePictureLayerImpl> greatgrandchild(
8985 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:128986
8987 child->SetDrawsContent(true);
8988 grandchild->SetDrawsContent(true);
8989 greatgrandchild->SetDrawsContent(true);
8990
8991 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8992 gfx::PointF(), gfx::Size(100, 100), true, false,
8993 true);
8994 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8995 gfx::PointF(), gfx::Size(10, 10), true, false,
8996 false);
8997 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8998 gfx::PointF(), gfx::Size(10, 10), true, false,
8999 false);
vollick2175fae82015-04-27 21:18:129000
9001 LayerImpl* child_ptr = child.get();
9002 LayerImpl* grandchild_ptr = grandchild.get();
vollick2175fae82015-04-27 21:18:129003
danakja04855a2015-11-18 20:39:109004 child->AddChild(std::move(grandchild));
9005 root->AddChild(std::move(child));
vollick2175fae82015-04-27 21:18:129006
9007 // Check the non-skipped case.
enne601f2ef12015-05-19 18:20:179008 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129009 EXPECT_EQ(gfx::Rect(10, 10),
9010 grandchild_ptr->visible_rect_from_property_trees());
9011
9012 // Now we will reset the visible rect from property trees for the grandchild,
9013 // and we will configure |child| in several ways that should force the subtree
9014 // to be skipped. The visible content rect for |grandchild| should, therefore,
9015 // remain empty.
9016 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
9017 gfx::Transform singular;
9018 singular.matrix().set(0, 0, 0);
9019
9020 child_ptr->SetTransform(singular);
enne601f2ef12015-05-19 18:20:179021 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129022 EXPECT_EQ(gfx::Rect(0, 0),
9023 grandchild_ptr->visible_rect_from_property_trees());
9024 child_ptr->SetTransform(identity);
9025
9026 child_ptr->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:179027 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129028 EXPECT_EQ(gfx::Rect(0, 0),
9029 grandchild_ptr->visible_rect_from_property_trees());
9030 child_ptr->SetHideLayerAndSubtree(false);
9031
9032 child_ptr->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:179033 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129034 EXPECT_EQ(gfx::Rect(0, 0),
9035 grandchild_ptr->visible_rect_from_property_trees());
9036
9037 // Now, even though child has zero opacity, we will configure |grandchild| and
9038 // |greatgrandchild| in several ways that should force the subtree to be
9039 // processed anyhow.
vmpstra370ef52015-11-18 10:41:289040 std::vector<scoped_ptr<CopyOutputRequest>> requests;
vollick2175fae82015-04-27 21:18:129041 requests.push_back(CopyOutputRequest::CreateEmptyRequest());
9042
jaydasika86654512016-01-27 17:05:079043 grandchild_ptr->PassCopyRequests(&requests);
sunxded58688e2016-01-11 21:01:029044 root.get()->layer_tree_impl()->property_trees()->needs_rebuild = true;
enne601f2ef12015-05-19 18:20:179045 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129046 EXPECT_EQ(gfx::Rect(10, 10),
9047 grandchild_ptr->visible_rect_from_property_trees());
9048}
9049
9050TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
9051 gfx::Transform identity;
loysoa6edaaff2015-05-25 03:26:449052 scoped_refptr<Layer> root = Layer::Create(layer_settings());
chrishtr01539b802015-11-24 08:11:329053 FakeContentLayerClient client;
9054 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:129055 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:449056 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick2175fae82015-04-27 21:18:129057 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9058 gfx::PointF(), gfx::Size(100, 100), true, false);
9059 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9060 gfx::PointF(), gfx::Size(10, 10), true, false);
9061 root->AddChild(child);
9062
ennea7b43c32015-06-18 20:01:339063 host()->SetRootLayer(root);
vollick2175fae82015-04-27 21:18:129064
enne601f2ef12015-05-19 18:20:179065 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129066 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
9067 child->set_visible_rect_from_property_trees(gfx::Rect());
9068
9069 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:179070 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129071 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9072 child->SetHideLayerAndSubtree(false);
9073
9074 child->SetBounds(gfx::Size());
enne601f2ef12015-05-19 18:20:179075 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129076 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9077 child->SetBounds(gfx::Size(10, 10));
9078
9079 gfx::Transform rotate;
9080 child->SetDoubleSided(false);
9081 rotate.RotateAboutXAxis(180.f);
9082 child->SetTransform(rotate);
enne601f2ef12015-05-19 18:20:179083 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129084 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9085 child->SetDoubleSided(true);
9086 child->SetTransform(identity);
9087
9088 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:179089 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129090 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9091}
9092
jaydasika3d10aa62015-05-06 17:50:449093TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
9094 // Ensure that the treewalk in LayerTreeHostCommom::
9095 // PreCalculateMetaInformation happens when its required.
loysoa6edaaff2015-05-25 03:26:449096 scoped_refptr<Layer> root = Layer::Create(layer_settings());
9097 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
9098 scoped_refptr<Layer> child = Layer::Create(layer_settings());
jaydasika3d10aa62015-05-06 17:50:449099
9100 root->AddChild(parent);
9101 parent->AddChild(child);
9102
9103 child->SetClipParent(root.get());
9104
9105 gfx::Transform identity;
9106
9107 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9108 gfx::PointF(), gfx::Size(100, 100), true, false);
9109 SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(),
9110 gfx::PointF(), gfx::Size(100, 100), true, false);
9111 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9112 gfx::PointF(), gfx::Size(100, 100), true, false);
9113
ennea7b43c32015-06-18 20:01:339114 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:449115
jaydasika3d10aa62015-05-06 17:50:449116 child->RequestCopyOfOutput(
9117 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
sunxded58688e2016-01-11 21:01:029118
9119 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9120 EXPECT_EQ(parent->num_unclipped_descendants(), 1u);
9121
9122 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
9123 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9124 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika3d10aa62015-05-06 17:50:449125}
9126
9127TEST_F(LayerTreeHostCommonTest, InputHandlersRecursiveUpdateTest) {
9128 // Ensure that the treewalk in LayertreeHostCommon::
9129 // PreCalculateMetaInformation updates input handlers correctly.
ennecf94ff0c2015-08-18 22:58:059130 LayerImpl* root = root_layer();
9131 LayerImpl* child = AddChild<LayerImpl>(root);
jaydasika3d10aa62015-05-06 17:50:449132
9133 gfx::Transform identity;
9134
ennecf94ff0c2015-08-18 22:58:059135 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
9136 gfx::Size(100, 100), true, false, true);
9137 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
9138 gfx::Size(100, 100), true, false, false);
jaydasika3d10aa62015-05-06 17:50:449139
dtapuskaee0b6982016-01-29 15:14:489140 EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), false);
jaydasika3d10aa62015-05-06 17:50:449141
dtapuskaee0b6982016-01-29 15:14:489142 child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
ennecf94ff0c2015-08-18 22:58:059143 ExecuteCalculateDrawProperties(root);
dtapuskaee0b6982016-01-29 15:14:489144 EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), true);
ennecf94ff0c2015-08-18 22:58:059145
dtapuskaee0b6982016-01-29 15:14:489146 child->SetTouchEventHandlerRegion(gfx::Rect());
ennecf94ff0c2015-08-18 22:58:059147 ExecuteCalculateDrawProperties(root);
dtapuskaee0b6982016-01-29 15:14:489148 EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), false);
jaydasika3d10aa62015-05-06 17:50:449149}
9150
vollick692444f2015-05-20 15:39:149151TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
9152 gfx::Transform identity;
9153 gfx::Transform translate_z;
9154 translate_z.Translate3d(0, 0, 10);
9155
loysoa6edaaff2015-05-25 03:26:449156 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick692444f2015-05-20 15:39:149157 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9158 gfx::PointF(), gfx::Size(800, 800), true, false);
9159
loysoa6edaaff2015-05-25 03:26:449160 scoped_refptr<Layer> child = Layer::Create(layer_settings());
vollick692444f2015-05-20 15:39:149161 SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(),
9162 gfx::PointF(), gfx::Size(100, 100), true, false);
9163
9164 root->AddChild(child);
9165
ennea7b43c32015-06-18 20:01:339166 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:149167
9168 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9169 EXPECT_NE(-1, child->transform_tree_index());
9170
9171 child->RemoveFromParent();
9172
9173 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9174 EXPECT_EQ(-1, child->transform_tree_index());
9175}
9176
jaydasika976cd10b2015-05-26 15:45:249177TEST_F(LayerTreeHostCommonTest, ResetLayerDrawPropertiestest) {
9178 scoped_refptr<Layer> root = Layer::Create(layer_settings());
9179 scoped_refptr<Layer> child = Layer::Create(layer_settings());
9180
9181 root->AddChild(child);
9182 gfx::Transform identity;
9183
9184 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9185 gfx::PointF(), gfx::Size(100, 100), true, false);
9186 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9187 gfx::PointF(), gfx::Size(100, 100), true, false);
9188
ennea7b43c32015-06-18 20:01:339189 host()->SetRootLayer(root);
jaydasika976cd10b2015-05-26 15:45:249190
9191 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
9192 EXPECT_FALSE(root->visited());
9193 EXPECT_FALSE(root->sorted_for_recursion());
9194 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
9195 EXPECT_FALSE(child->visited());
9196 EXPECT_FALSE(child->sorted_for_recursion());
9197
9198 root->set_layer_or_descendant_is_drawn(true);
9199 root->set_visited(true);
9200 root->set_sorted_for_recursion(true);
9201 child->set_layer_or_descendant_is_drawn(true);
9202 child->set_visited(true);
9203 child->set_sorted_for_recursion(true);
9204
9205 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root.get());
9206
9207 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
9208 EXPECT_FALSE(root->visited());
9209 EXPECT_FALSE(root->sorted_for_recursion());
9210 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
9211 EXPECT_FALSE(child->visited());
9212 EXPECT_FALSE(child->sorted_for_recursion());
9213}
9214
jaydasika67d7989e2015-08-06 21:55:349215TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
9216 // Ensure that a Clip Node is added when a render surface applies clip.
9217 LayerImpl* root = root_layer();
9218 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
9219 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
9220 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
9221 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9222
9223 const gfx::Transform identity_matrix;
9224 // This transform should be a significant one so that a transform node is
9225 // formed for it.
9226 gfx::Transform transform1;
9227 transform1.RotateAboutYAxis(45);
9228 transform1.RotateAboutXAxis(30);
9229 // This transform should be a 3d transform as we want the render surface
9230 // to flatten the transform
9231 gfx::Transform transform2;
9232 transform2.Translate3d(10, 10, 10);
9233
9234 layer_clips_subtree->SetMasksToBounds(true);
9235 test_layer->SetDrawsContent(true);
9236
9237 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269238 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349239 SetLayerPropertiesForTesting(significant_transform, transform1,
9240 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
weiliangcc154ce22015-12-09 03:39:269241 true, false);
jaydasika67d7989e2015-08-06 21:55:349242 SetLayerPropertiesForTesting(layer_clips_subtree, identity_matrix,
9243 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
weiliangcc154ce22015-12-09 03:39:269244 true, false);
jaydasika67d7989e2015-08-06 21:55:349245 SetLayerPropertiesForTesting(render_surface, transform2, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269246 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349247 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269248 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349249
weiliangcc154ce22015-12-09 03:39:269250 root->SetForceRenderSurface(true);
9251 significant_transform->SetForceRenderSurface(false);
9252 layer_clips_subtree->SetForceRenderSurface(true);
9253 render_surface->SetForceRenderSurface(true);
9254 test_layer->SetForceRenderSurface(false);
jaydasika67d7989e2015-08-06 21:55:349255 ExecuteCalculateDrawProperties(root);
9256
9257 TransformTree transform_tree =
9258 root->layer_tree_impl()->property_trees()->transform_tree;
9259 TransformNode* transform_node =
9260 transform_tree.Node(significant_transform->transform_tree_index());
9261 EXPECT_EQ(transform_node->owner_id, significant_transform->id());
9262
weiliangcc154ce22015-12-09 03:39:269263 EXPECT_TRUE(root->has_render_surface());
9264 EXPECT_FALSE(significant_transform->has_render_surface());
9265 EXPECT_TRUE(layer_clips_subtree->has_render_surface());
9266 EXPECT_TRUE(render_surface->has_render_surface());
9267 EXPECT_FALSE(test_layer->has_render_surface());
9268
jaydasika67d7989e2015-08-06 21:55:349269 ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
9270 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
ajuma01734dd02015-10-07 01:22:089271 EXPECT_FALSE(clip_node->data.applies_local_clip);
weiliangcc154ce22015-12-09 03:39:269272 EXPECT_EQ(gfx::Rect(22, 21), test_layer->visible_rect_from_property_trees());
jaydasika67d7989e2015-08-06 21:55:349273}
9274
9275TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
9276 // Ensure that when parent clip node's transform is an ancestor of current
9277 // clip node's target, clip is 'projected' from parent space to current
9278 // target space and visible rects are calculated correctly.
9279 LayerImpl* root = root_layer();
9280 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9281 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
9282 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
9283
9284 const gfx::Transform identity_matrix;
9285 gfx::Transform transform;
9286 transform.RotateAboutYAxis(45);
9287 clip_layer->SetMasksToBounds(true);
9288 target_layer->SetMasksToBounds(true);
9289 test_layer->SetDrawsContent(true);
9290
9291 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9292 gfx::PointF(), gfx::Size(30, 30), true, false,
9293 true);
9294 SetLayerPropertiesForTesting(clip_layer, transform, gfx::Point3F(),
9295 gfx::PointF(), gfx::Size(30, 30), true, false,
9296 false);
9297 SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(),
9298 gfx::PointF(), gfx::Size(30, 30), true, false,
9299 true);
9300 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9301 gfx::PointF(), gfx::Size(30, 30), true, false,
9302 false);
9303 ExecuteCalculateDrawProperties(root);
9304
danakj5e6ff6d2015-09-05 04:43:449305 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_rect_from_property_trees());
jaydasika67d7989e2015-08-06 21:55:349306}
9307
jaydasika7d5c1ed2015-08-14 14:27:029308TEST_F(LayerTreeHostCommonTest,
9309 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
9310 // Ensure clip rect is calculated correctly when render surface has unclipped
9311 // descendants.
9312 LayerImpl* root = root_layer();
9313 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9314 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
9315 LayerImpl* render_surface =
9316 AddChild<LayerImpl>(between_clip_parent_and_child);
9317 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9318
9319 const gfx::Transform identity_matrix;
9320 gfx::Transform transform;
9321 transform.Translate(2.0, 2.0);
9322
9323 test_layer->SetDrawsContent(true);
9324 render_surface->SetClipParent(clip_parent);
jaydasikae9d09702015-09-15 01:26:419325 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9326 clip_children->insert(render_surface);
9327 clip_parent->SetClipChildren(clip_children.release());
jaydasika7d5c1ed2015-08-14 14:27:029328 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9329 gfx::PointF(), gfx::Size(30, 30), true, false,
9330 true);
9331 SetLayerPropertiesForTesting(clip_parent, transform, gfx::Point3F(),
9332 gfx::PointF(), gfx::Size(30, 30), true, false,
9333 false);
9334 SetLayerPropertiesForTesting(between_clip_parent_and_child, transform,
9335 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
9336 true, false, false);
9337 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9338 gfx::PointF(), gfx::Size(30, 30), true, false,
9339 true);
9340 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9341 gfx::PointF(), gfx::Size(30, 30), true, false,
9342 false);
9343
9344 ExecuteCalculateDrawProperties(root);
9345
jaydasikae9d09702015-09-15 01:26:419346 EXPECT_EQ(gfx::Rect(30, 30), test_layer->clip_rect());
jaydasika7d5c1ed2015-08-14 14:27:029347}
9348
jaydasika571dd2cf2015-09-25 20:55:429349TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:089350 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
9351 // Ensure that the visible layer rect of a descendant of a surface with
9352 // unclipped descendants is computed correctly, when the surface doesn't apply
9353 // a clip.
9354 LayerImpl* root = root_layer();
9355 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9356 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9357 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9358 LayerImpl* child = AddChild<LayerImpl>(render_surface);
9359
9360 const gfx::Transform identity_matrix;
9361
9362 clip_child->SetDrawsContent(true);
9363 child->SetDrawsContent(true);
9364 clip_child->SetClipParent(clip_parent);
9365 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9366 clip_children->insert(clip_child);
9367 clip_parent->SetClipChildren(clip_children.release());
9368 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9369 gfx::PointF(), gfx::Size(30, 10), true, false,
9370 true);
9371 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9372 gfx::PointF(), gfx::Size(30, 30), true, false,
9373 false);
9374 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9375 gfx::PointF(), gfx::Size(10, 15), true, false,
9376 true);
9377 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9378 gfx::PointF(), gfx::Size(10, 10), true, false,
9379 false);
9380 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
9381 gfx::PointF(), gfx::Size(40, 40), true, false,
9382 false);
9383
9384 ExecuteCalculateDrawProperties(root);
9385 EXPECT_EQ(gfx::Rect(40, 40), child->visible_layer_rect());
9386}
9387
9388TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:429389 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
9390 LayerImpl* root = root_layer();
9391 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9392 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9393 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
9394 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
9395 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
9396
9397 const gfx::Transform identity_matrix;
9398 root->SetMasksToBounds(true);
9399 render_surface->SetMasksToBounds(true);
9400 render_surface->SetDrawsContent(true);
9401 clip_child->SetDrawsContent(true);
9402 test_layer1->SetDrawsContent(true);
9403 test_layer2->SetDrawsContent(true);
9404 clip_child->SetClipParent(clip_parent);
9405 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9406 clip_children->insert(clip_child);
9407 clip_parent->SetClipChildren(clip_children.release());
9408
9409 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9410 gfx::PointF(), gfx::Size(30, 30), true, false,
9411 true);
9412 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9413 gfx::PointF(), gfx::Size(30, 30), true, false,
9414 false);
9415 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9416 gfx::PointF(), gfx::Size(50, 50), true, false,
9417 true);
9418 SetLayerPropertiesForTesting(test_layer1, identity_matrix, gfx::Point3F(),
9419 gfx::PointF(), gfx::Size(50, 50), true, false,
9420 false);
9421 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9422 gfx::PointF(), gfx::Size(50, 50), true, false,
9423 false);
9424 SetLayerPropertiesForTesting(test_layer2, identity_matrix, gfx::Point3F(),
9425 gfx::PointF(), gfx::Size(50, 50), true, false,
9426 false);
9427
9428 ExecuteCalculateDrawProperties(root);
9429 EXPECT_EQ(gfx::Rect(50, 50), render_surface->visible_layer_rect());
9430 EXPECT_EQ(gfx::Rect(50, 50), test_layer1->visible_layer_rect());
9431 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
9432 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
9433}
9434
ajumae2b7a5c2015-09-30 21:41:429435TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
9436 LayerImpl* root = root_layer();
9437 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9438 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9439 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9440
9441 const gfx::Transform identity_matrix;
9442 clip_parent->SetDrawsContent(true);
9443 render_surface->SetMasksToBounds(true);
9444 render_surface->SetDrawsContent(true);
9445 clip_child->SetDrawsContent(true);
9446
9447 clip_child->SetClipParent(clip_parent);
9448 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9449 clip_children->insert(clip_child);
9450 clip_parent->SetClipChildren(clip_children.release());
9451
9452 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9453 gfx::PointF(), gfx::Size(50, 50), true, false,
9454 true);
9455 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9456 gfx::PointF(), gfx::Size(50, 50), true, false,
9457 false);
9458 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9459 gfx::PointF(), gfx::Size(30, 30), true, false,
9460 true);
9461 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9462 gfx::PointF(), gfx::Size(50, 50), true, false,
9463 false);
9464
9465 ExecuteCalculateDrawProperties(root);
9466
9467 // The clip child should inherit its clip parent's clipping state, not its
9468 // tree parent's clipping state.
9469 EXPECT_FALSE(clip_parent->is_clipped());
9470 EXPECT_TRUE(render_surface->is_clipped());
9471 EXPECT_FALSE(clip_child->is_clipped());
9472}
9473
jaydasika77a4a072015-10-20 21:47:279474TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
9475 // Tests the value of render surface content rect when we have multiple types
9476 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
9477 // clipped surfaces.
9478 LayerImpl* root = root_layer();
9479 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
9480 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
9481 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9482 LayerImpl* unclipped_desc_surface2 =
9483 AddChild<LayerImpl>(unclipped_desc_surface);
9484 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
9485 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
9486
9487 unclipped_surface->SetDrawsContent(true);
9488 unclipped_desc_surface->SetDrawsContent(true);
9489 unclipped_desc_surface2->SetDrawsContent(true);
9490 clipped_surface->SetDrawsContent(true);
9491 clip_child->SetClipParent(clip_parent);
9492 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9493 clip_children->insert(clip_child);
9494 clip_parent->SetClipChildren(clip_children.release());
9495
9496 gfx::Transform identity_matrix;
9497 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9498 gfx::PointF(), gfx::Size(80, 80), true, false,
9499 true);
9500 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
9501 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
9502 true, false, true);
9503 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9504 gfx::PointF(), gfx::Size(50, 50), true, false,
9505 false);
9506 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
9507 gfx::Point3F(), gfx::PointF(),
9508 gfx::Size(100, 100), true, false, true);
9509 SetLayerPropertiesForTesting(unclipped_desc_surface2, identity_matrix,
9510 gfx::Point3F(), gfx::PointF(), gfx::Size(60, 60),
9511 true, false, true);
9512 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9513 gfx::PointF(), gfx::Size(100, 100), true, false,
9514 false);
9515 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
9516 gfx::PointF(), gfx::Size(70, 70), true, false,
9517 true);
9518 clip_parent->SetMasksToBounds(true);
9519 unclipped_surface->SetMasksToBounds(true);
9520 unclipped_desc_surface->SetMasksToBounds(true);
9521
9522 ExecuteCalculateDrawProperties(root);
9523 EXPECT_EQ(gfx::Rect(50, 50),
9524 unclipped_surface->render_surface()->content_rect());
9525 EXPECT_EQ(gfx::Rect(100, 100),
9526 unclipped_desc_surface->render_surface()->content_rect());
9527 EXPECT_EQ(gfx::Rect(50, 50),
9528 unclipped_desc_surface2->render_surface()->content_rect());
9529 EXPECT_EQ(gfx::Rect(50, 50),
9530 clipped_surface->render_surface()->content_rect());
9531}
9532
9533TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
9534 // Tests the value of render surface content rect when we have a layer that
9535 // clips between the clip parent's target and clip child's target.
9536 LayerImpl* root = root_layer();
9537 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9538 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9539 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9540 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9541 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9542
9543 clip_child->SetDrawsContent(true);
9544 unclipped_desc_surface->SetDrawsContent(true);
9545 clip_child->SetClipParent(clip_parent);
9546 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9547 clip_children->insert(clip_child);
9548 clip_parent->SetClipChildren(clip_children.release());
9549
9550 gfx::Transform identity_matrix;
9551 gfx::Transform translate;
9552 translate.Translate(10, 10);
9553 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9554 gfx::PointF(), gfx::Size(100, 100), true, false,
9555 true);
9556 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
9557 gfx::PointF(), gfx::Size(100, 100), true, false,
9558 true);
9559 SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(),
9560 gfx::PointF(), gfx::Size(20, 20), true, false,
9561 false);
9562 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9563 gfx::PointF(), gfx::Size(50, 50), true, false,
9564 false);
9565 SetLayerPropertiesForTesting(unclipped_desc_surface, translate,
9566 gfx::Point3F(), gfx::PointF(),
9567 gfx::Size(100, 100), true, false, true);
9568 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9569 gfx::PointF(), gfx::Size(100, 100), true, false,
9570 false);
9571 surface->SetMasksToBounds(true);
9572 clip_layer->SetMasksToBounds(true);
9573
9574 ExecuteCalculateDrawProperties(root);
9575
9576 EXPECT_EQ(gfx::Rect(10, 10),
9577 unclipped_desc_surface->render_surface()->content_rect());
9578}
9579
jaydasika2c8c2872015-10-21 23:28:219580TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
9581 LayerImpl* root = root_layer();
9582 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9583 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9584 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9585 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9586 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9587
9588 clip_child->SetDrawsContent(true);
9589 unclipped_desc_surface->SetDrawsContent(true);
9590 clip_child->SetClipParent(clip_parent);
9591 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9592 clip_children->insert(clip_child);
9593 clip_parent->SetClipChildren(clip_children.release());
9594
9595 gfx::Transform identity_matrix;
9596 gfx::Transform scale;
9597 scale.Scale(2, 2);
9598 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9599 gfx::PointF(), gfx::Size(100, 100), true, false,
9600 true);
9601 SetLayerPropertiesForTesting(surface, scale, gfx::Point3F(), gfx::PointF(),
9602 gfx::Size(100, 100), true, false, true);
9603 SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(),
9604 gfx::PointF(), gfx::Size(20, 20), true, false,
9605 false);
9606 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9607 gfx::PointF(), gfx::Size(50, 50), true, false,
9608 false);
9609 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
9610 gfx::Point3F(), gfx::PointF(),
9611 gfx::Size(100, 100), true, false, true);
9612 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9613 gfx::PointF(), gfx::Size(100, 100), true, false,
9614 false);
9615 surface->SetMasksToBounds(true);
9616 clip_layer->SetMasksToBounds(true);
9617
9618 ExecuteCalculateDrawProperties(root);
9619
9620 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9621}
9622
jaydasika60f85862015-10-01 20:36:149623TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
9624 LayerImpl* root = root_layer();
9625 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9626 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9627
9628 const gfx::Transform identity_matrix;
9629 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9630 gfx::PointF(), gfx::Size(30, 30), true, false,
9631 true);
9632 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9633 gfx::PointF(), gfx::Size(30, 30), true, false,
9634 true);
jaydasika86654512016-01-27 17:05:079635 gfx::Transform translation;
9636 translation.Translate(10, 10);
9637 SetLayerPropertiesForTesting(test_layer, translation, gfx::Point3F(),
jaydasika60f85862015-10-01 20:36:149638 gfx::PointF(), gfx::Size(20, 20), true, false,
9639 false);
9640
9641 render_surface->SetMasksToBounds(true);
9642 test_layer->SetDrawsContent(true);
9643 test_layer->SetOpacity(0);
dtapuskaee0b6982016-01-29 15:14:489644 test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20));
jaydasika60f85862015-10-01 20:36:149645
9646 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079647 EXPECT_EQ(translation, test_layer->ScreenSpaceTransform());
jaydasika60f85862015-10-01 20:36:149648}
9649
jaydasikae4910fa22015-10-09 00:52:099650TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
9651 LayerImpl* root = root_layer();
9652 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9653 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9654 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9655
9656 const gfx::Transform identity_matrix;
9657 clip_parent->SetMasksToBounds(true);
9658 render_surface->SetMasksToBounds(true);
9659 render_surface->SetDrawsContent(true);
9660 clip_child->SetDrawsContent(true);
9661 clip_child->SetClipParent(clip_parent);
9662 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9663 clip_children->insert(clip_child);
9664 clip_parent->SetClipChildren(clip_children.release());
9665
9666 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9667 gfx::PointF(), gfx::Size(30, 30), true, false,
9668 true);
9669 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9670 gfx::PointF(10.f, 10.f), gfx::Size(40, 40), true,
9671 false, false);
9672 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9673 gfx::PointF(), gfx::Size(50, 50), true, false,
9674 true);
9675 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9676 gfx::PointF(), gfx::Size(50, 50), true, false,
9677 false);
9678
9679 ExecuteCalculateDrawProperties(root);
9680 EXPECT_EQ(gfx::Rect(40, 40), clip_child->visible_layer_rect());
9681}
9682
jaydasika571dd2cf2015-09-25 20:55:429683TEST_F(LayerTreeHostCommonTest,
9684 LayerClipRectLargerThanClippingRenderSurfaceRect) {
9685 LayerImpl* root = root_layer();
9686 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9687 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9688 const gfx::Transform identity_matrix;
9689 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9690 gfx::PointF(), gfx::Size(30, 30), true, false,
9691 true);
9692 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9693 gfx::PointF(), gfx::Size(50, 50), true, false,
9694 true);
9695 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9696 gfx::PointF(), gfx::Size(50, 50), true, false,
9697 false);
9698 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369699 root->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429700 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369701 render_surface->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429702 test_layer->SetMasksToBounds(true);
9703 test_layer->SetDrawsContent(true);
9704 ExecuteCalculateDrawProperties(root);
9705
9706 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
9707 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
9708 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
9709}
9710
jaydasikab5504ca2015-12-18 23:41:559711TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) {
9712 // Tests that subtree is hidden is updated.
9713 LayerImpl* root = root_layer();
9714 LayerImpl* hidden = AddChild<LayerImpl>(root);
9715 LayerImpl* test = AddChild<LayerImpl>(hidden);
9716
9717 const gfx::Transform identity_matrix;
9718 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9719 gfx::PointF(), gfx::Size(30, 30), true, false,
9720 true);
9721 SetLayerPropertiesForTesting(hidden, identity_matrix, gfx::Point3F(),
9722 gfx::PointF(10, 10), gfx::Size(30, 30), true,
9723 false, true);
9724 SetLayerPropertiesForTesting(test, identity_matrix, gfx::Point3F(),
9725 gfx::PointF(), gfx::Size(30, 30), true, false,
9726 true);
9727
9728 hidden->SetHideLayerAndSubtree(true);
9729 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079730 EXPECT_TRUE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559731
9732 hidden->SetHideLayerAndSubtree(false);
9733 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9734 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079735 EXPECT_FALSE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559736}
9737
jaydasikac0137282015-10-01 15:50:309738TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
9739 LayerImpl* root = root_layer();
9740 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9741 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9742 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
9743
9744 const gfx::Transform identity_matrix;
9745 clip_child->SetClipParent(root);
9746 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9747 clip_children->insert(clip_child);
9748 root->SetClipChildren(clip_children.release());
9749 root->SetMasksToBounds(true);
9750 render_surface1->SetDrawsContent(true);
9751 render_surface2->SetDrawsContent(true);
9752
9753 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9754 gfx::PointF(), gfx::Size(30, 30), true, false,
9755 true);
9756 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
9757 gfx::PointF(10, 10), gfx::Size(30, 30), true,
9758 false, true);
9759 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
9760 gfx::PointF(), gfx::Size(30, 30), true, false,
9761 true);
9762 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9763 gfx::PointF(), gfx::Size(30, 30), true, false,
9764 false);
9765 ExecuteCalculateDrawProperties(root);
9766
9767 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
jaydasikadaf0af02016-01-06 15:33:379768 // A clip node is created for every render surface and for layers that have
9769 // local clip. So, here it should be craeted for every layer.
9770 EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u);
jaydasikac0137282015-10-01 15:50:309771}
9772
jaydasika224bca02015-12-18 02:37:099773TEST_F(LayerTreeHostCommonTest, MaskLayerScreenSpaceTransform) {
9774 // Tests that the mask layer gets its owning layer's screen space transform.
9775 LayerImpl* root = root_layer();
9776 LayerImpl* child = AddChild<LayerImpl>(root);
9777
9778 const gfx::Transform identity_matrix;
9779 gfx::Transform transform;
9780 transform.Translate(10, 10);
9781
9782 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9783 gfx::PointF(), gfx::Size(30, 30), true, false,
9784 true);
9785 SetLayerPropertiesForTesting(child, transform, gfx::Point3F(), gfx::PointF(),
9786 gfx::Size(30, 30), true, false, false);
9787 root->SetDrawsContent(true);
9788 child->SetDrawsContent(false);
9789 child->SetMaskLayer(LayerImpl::Create(root->layer_tree_impl(), 100));
9790 ExecuteCalculateDrawProperties(root);
9791
9792 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
9793 child->mask_layer()->ScreenSpaceTransform());
9794 transform.Translate(10, 10);
9795 child->SetTransform(transform);
9796 child->SetDrawsContent(true);
9797 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9798 ExecuteCalculateDrawProperties(root);
9799 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
9800 child->mask_layer()->ScreenSpaceTransform());
9801}
9802
jaydasika5160e672015-10-15 15:25:149803TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
9804 LayerImpl* root = root_layer();
9805 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9806 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9807
9808 const gfx::Transform identity_matrix;
9809 render_surface1->SetDrawsContent(true);
9810 render_surface2->SetDrawsContent(true);
jaydasika445176f2015-11-04 20:14:039811 render_surface2->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:149812
9813 gfx::Transform large_transform;
9814 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
9815 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
9816 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
9817 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
9818
9819 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9820 gfx::PointF(), gfx::Size(30, 30), true, false,
9821 true);
9822 SetLayerPropertiesForTesting(render_surface1, large_transform, gfx::Point3F(),
9823 gfx::PointF(), gfx::Size(30, 30), true, false,
9824 true);
9825 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
9826 gfx::PointF(), gfx::Size(30, 30), true, false,
9827 true);
9828
9829 ExecuteCalculateDrawProperties(root);
9830
jaydasika8640f9f2015-11-10 01:34:369831 bool is_inf_or_nan =
9832 std::isinf(
9833 render_surface2->render_surface()->draw_transform().matrix().get(
9834 0, 0)) ||
9835 std::isnan(
9836 render_surface2->render_surface()->draw_transform().matrix().get(0,
9837 0));
9838 EXPECT_TRUE(is_inf_or_nan);
9839 is_inf_or_nan =
9840 std::isinf(
9841 render_surface2->render_surface()->draw_transform().matrix().get(
9842 1, 1)) ||
9843 std::isnan(
9844 render_surface2->render_surface()->draw_transform().matrix().get(1,
9845 1));
9846 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:149847 EXPECT_EQ(gfx::RectF(),
9848 render_surface2->render_surface()->DrawableContentRect());
9849
9850 std::vector<LayerImpl*>* rsll = render_surface_layer_list_impl();
9851 bool root_in_rsll =
9852 std::find(rsll->begin(), rsll->end(), root) != rsll->end();
9853 EXPECT_TRUE(root_in_rsll);
9854 bool render_surface2_in_rsll =
9855 std::find(rsll->begin(), rsll->end(), render_surface2) != rsll->end();
9856 EXPECT_FALSE(render_surface2_in_rsll);
9857}
9858
khushalsagar37694212016-01-15 20:46:489859TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) {
9860 LayerTreeHostCommon::ScrollUpdateInfo scroll;
9861 scroll.layer_id = 2;
9862 scroll.scroll_delta = gfx::Vector2d(5, 10);
9863
9864 proto::ScrollUpdateInfo proto;
9865 scroll.ToProtobuf(&proto);
9866 LayerTreeHostCommon::ScrollUpdateInfo new_scroll;
9867 new_scroll.FromProtobuf(proto);
9868
9869 EXPECT_EQ(scroll, new_scroll);
9870}
9871
9872TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) {
9873 ScrollAndScaleSet scroll_and_scale_set;
9874
9875 LayerTreeHostCommon::ScrollUpdateInfo scroll1;
9876 scroll1.layer_id = 1;
9877 scroll1.scroll_delta = gfx::Vector2d(5, 10);
9878 LayerTreeHostCommon::ScrollUpdateInfo scroll2;
9879 scroll2.layer_id = 2;
9880 scroll2.scroll_delta = gfx::Vector2d(1, 5);
9881 scroll_and_scale_set.scrolls.push_back(scroll1);
9882 scroll_and_scale_set.scrolls.push_back(scroll2);
9883
9884 scroll_and_scale_set.page_scale_delta = 0.3f;
9885 scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f);
9886 scroll_and_scale_set.top_controls_delta = 0.9f;
9887
9888 proto::ScrollAndScaleSet proto;
9889 scroll_and_scale_set.ToProtobuf(&proto);
9890 ScrollAndScaleSet new_scroll_and_scale_set;
9891 new_scroll_and_scale_set.FromProtobuf(proto);
9892
9893 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set));
9894}
9895
sunxdea1df782016-01-28 00:12:339896TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) {
9897 // Test the behavior of scroll tree builder
9898 // Topology:
9899 // +root1(1)
sunxd29f17bf422016-02-03 02:47:489900 // +--parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling &
9901 // scrollable]
9902 // +----child6(6)[kScrollbarScrolling]
9903 // +------grand_child10(10)[kScrollbarScrolling]
sunxdea1df782016-01-28 00:12:339904 // +--parent3(3)
9905 // +----child7(7)[scrollable]
9906 // +----child8(8)[scroll_parent=7]
9907 // +------grand_child11(11)[scrollable]
9908 // +--parent4(4)
9909 // +----child9(9)
9910 // +------grand_child12(12)
9911 // +--parent5(5)[contains_non_fast_scrollable_region]
9912 //
9913 // Expected scroll tree topology:
9914 // +property_tree_root---owner:-1
9915 // +--root---owner:1, id:1
9916 // +----node---owner:2, id:2
9917 // +------node---owner:6, id:3
9918 // +----node---owner:7, id:4
9919 // +------node---owner:11, id:5
9920 // +----node---owner:5, id:6
9921 //
9922 // Extra check:
9923 // scroll_tree_index() of:
9924 // grand_child10:3
9925 // parent3:1
9926 // child8:4
9927 // parent4:1
9928 // child9:1
9929 // grand_child12:1
9930 scoped_refptr<Layer> root1 = Layer::Create(layer_settings());
9931 scoped_refptr<Layer> parent2 = Layer::Create(layer_settings());
9932 scoped_refptr<Layer> parent3 = Layer::Create(layer_settings());
9933 scoped_refptr<Layer> parent4 = Layer::Create(layer_settings());
9934 scoped_refptr<Layer> parent5 = Layer::Create(layer_settings());
9935 scoped_refptr<Layer> child6 = Layer::Create(layer_settings());
9936 scoped_refptr<Layer> child7 = Layer::Create(layer_settings());
9937 scoped_refptr<Layer> child8 = Layer::Create(layer_settings());
9938 scoped_refptr<Layer> child9 = Layer::Create(layer_settings());
9939 scoped_refptr<Layer> grand_child10 = Layer::Create(layer_settings());
9940 scoped_refptr<Layer> grand_child11 = Layer::Create(layer_settings());
9941 scoped_refptr<Layer> grand_child12 = Layer::Create(layer_settings());
9942
9943 root1->AddChild(parent2);
9944 root1->AddChild(parent3);
9945 root1->AddChild(parent4);
9946 root1->AddChild(parent5);
9947 parent2->AddChild(child6);
9948 parent3->AddChild(child7);
9949 parent3->AddChild(child8);
9950 parent4->AddChild(child9);
9951 child6->AddChild(grand_child10);
9952 child8->AddChild(grand_child11);
9953 child9->AddChild(grand_child12);
9954 host()->SetRootLayer(root1);
9955
9956 parent2->AddMainThreadScrollingReasons(
9957 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
sunxd29f17bf422016-02-03 02:47:489958 parent2->AddMainThreadScrollingReasons(
9959 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:339960 parent2->SetScrollClipLayerId(root1->id());
9961 child6->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:489962 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:339963 grand_child10->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:489964 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:339965
9966 child7->SetScrollClipLayerId(root1->id());
9967 child8->SetScrollParent(child7.get());
9968 grand_child11->SetScrollClipLayerId(root1->id());
9969
9970 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
9971
9972 ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get());
9973
9974 const int kInvalidPropertyTreeNodeId = -1;
9975 const int kRootPropertyTreeNodeId = 0;
9976
9977 // Property tree root
9978 ScrollTree scroll_tree = host()->property_trees()->scroll_tree;
9979 ScrollTree expected_scroll_tree;
9980 ScrollNode* property_tree_root = expected_scroll_tree.Node(0);
9981 property_tree_root->id = kRootPropertyTreeNodeId;
9982 property_tree_root->parent_id = kInvalidPropertyTreeNodeId;
9983 property_tree_root->owner_id = kInvalidPropertyTreeNodeId;
9984 property_tree_root->data.scrollable = false;
sunxd29f17bf422016-02-03 02:47:489985 property_tree_root->data.main_thread_scrolling_reasons =
9986 MainThreadScrollingReason::kNotScrollingOnMain;
sunxdea1df782016-01-28 00:12:339987 property_tree_root->data.contains_non_fast_scrollable_region = false;
9988 property_tree_root->data.transform_id = kRootPropertyTreeNodeId;
9989
9990 // The node owned by root1
9991 ScrollNode scroll_root1;
9992 scroll_root1.id = 1;
9993 scroll_root1.owner_id = root1->id();
9994 scroll_root1.data.transform_id = root1->transform_tree_index();
9995 expected_scroll_tree.Insert(scroll_root1, 0);
9996
9997 // The node owned by parent2
9998 ScrollNode scroll_parent2;
9999 scroll_parent2.id = 2;
10000 scroll_parent2.owner_id = parent2->id();
10001 scroll_parent2.data.scrollable = true;
sunxd29f17bf422016-02-03 02:47:4810002 scroll_parent2.data.main_thread_scrolling_reasons =
10003 parent2->main_thread_scrolling_reasons();
sunxdea1df782016-01-28 00:12:3310004 scroll_parent2.data.transform_id = parent2->transform_tree_index();
10005 expected_scroll_tree.Insert(scroll_parent2, 1);
10006
10007 // The node owned by child6
10008 ScrollNode scroll_child6;
10009 scroll_child6.id = 3;
10010 scroll_child6.owner_id = child6->id();
sunxd29f17bf422016-02-03 02:47:4810011 scroll_child6.data.main_thread_scrolling_reasons =
10012 child6->main_thread_scrolling_reasons();
sunxdea1df782016-01-28 00:12:3310013 scroll_child6.data.transform_id = child6->transform_tree_index();
10014 expected_scroll_tree.Insert(scroll_child6, 2);
10015
10016 // The node owned by child7, child7 also owns a transform node
10017 ScrollNode scroll_child7;
10018 scroll_child7.id = 4;
10019 scroll_child7.owner_id = child7->id();
10020 scroll_child7.data.scrollable = true;
10021 scroll_child7.data.transform_id = child7->transform_tree_index();
10022 expected_scroll_tree.Insert(scroll_child7, 1);
10023
10024 // The node owned by grand_child11, grand_child11 also owns a transform node
10025 ScrollNode scroll_grand_child11;
10026 scroll_grand_child11.id = 5;
10027 scroll_grand_child11.owner_id = grand_child11->id();
10028 scroll_grand_child11.data.scrollable = true;
10029 scroll_grand_child11.data.transform_id =
10030 grand_child11->transform_tree_index();
10031 expected_scroll_tree.Insert(scroll_grand_child11, 4);
10032
10033 // The node owned by parent5
10034 ScrollNode scroll_parent5;
10035 scroll_parent5.id = 8;
10036 scroll_parent5.owner_id = parent5->id();
10037 scroll_parent5.data.contains_non_fast_scrollable_region = true;
10038 scroll_parent5.data.transform_id = parent5->transform_tree_index();
10039 expected_scroll_tree.Insert(scroll_parent5, 1);
10040
10041 expected_scroll_tree.set_needs_update(false);
10042
10043 EXPECT_EQ(expected_scroll_tree, scroll_tree);
10044
10045 // Check other layers' scroll_tree_index
10046 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10047 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10048 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10049 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10050 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10051 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10052}
10053
[email protected]ba565742012-11-10 09:29:4810054} // namespace
10055} // namespace cc