blob: 1c1eba9f23961a73c7ef950a3c623daf09c0ec54 [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"
sunxd29f17bf2016-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(),
jaydasika62bd3dd2016-02-04 18:52:556496 gfx::PointF(), gfx::Size(50, 50), false, false,
ajumaaa0d3862015-11-09 22:24:466497 true);
6498 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
jaydasika62bd3dd2016-02-04 18:52:556499 gfx::PointF(), gfx::Size(30, 30), false, false,
ajumaaa0d3862015-11-09 22:24:466500 false);
6501 SetLayerPropertiesForTesting(grand_child, identity_transform, gfx::Point3F(),
jaydasika62bd3dd2016-02-04 18:52:556502 gfx::PointF(), gfx::Size(20, 20), false, false,
ajumaaa0d3862015-11-09 22:24:466503 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]);
jaydasika62bd3dd2016-02-04 18:52:556512
6513 // As all layers have identity transform, we shouldn't check for backface
6514 // visibility.
6515 EXPECT_FALSE(root->should_check_backface_visibility());
6516 EXPECT_FALSE(child->should_check_backface_visibility());
6517 EXPECT_FALSE(grand_child->should_check_backface_visibility());
6518 // As there are no 3d rendering contexts, all layers should use their local
6519 // transform for backface visibility.
6520 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6521 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6522 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6523
ajumaaa0d3862015-11-09 22:24:466524 gfx::Transform rotation_transform = identity_transform;
6525 rotation_transform.RotateAboutXAxis(180.0);
6526
6527 child->SetTransform(rotation_transform);
jaydasika62bd3dd2016-02-04 18:52:556528 child->Set3dSortingContextId(1);
6529 grand_child->Set3dSortingContextId(1);
ajumaaa0d3862015-11-09 22:24:466530 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6531
6532 ExecuteCalculateDrawProperties(root);
6533 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6534 EXPECT_EQ(0u, render_surface_layer_list_impl()
6535 ->at(0)
6536 ->render_surface()
6537 ->layer_list()
6538 .size());
jaydasika62bd3dd2016-02-04 18:52:556539
6540 // We should check for backface visibilty of child as it has a rotation
6541 // transform. We should also check for grand_child as it uses the backface
6542 // visibility of its parent.
6543 EXPECT_FALSE(root->should_check_backface_visibility());
6544 EXPECT_TRUE(child->should_check_backface_visibility());
6545 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6546 // child uses its local transform for backface visibility as it is the root of
6547 // a 3d rendering context. grand_child is in a 3d rendering context and is not
6548 // the root, but it derives its backface visibility from its parent which uses
6549 // its local transform.
6550 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6551 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6552 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6553
6554 grand_child->SetUseParentBackfaceVisibility(false);
6555 grand_child->SetDoubleSided(false);
6556 grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6557
6558 ExecuteCalculateDrawProperties(root);
6559 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6560 EXPECT_EQ(0u, render_surface_layer_list_impl()
6561 ->at(0)
6562 ->render_surface()
6563 ->layer_list()
6564 .size());
6565
6566 // We should check the backface visibility of child as it has a rotation
6567 // transform and for grand_child as it is in a 3d rendering context and not
6568 // the root of it.
6569 EXPECT_FALSE(root->should_check_backface_visibility());
6570 EXPECT_TRUE(child->should_check_backface_visibility());
6571 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6572 // grand_child is in an existing 3d rendering context, so it should not use
6573 // local transform for backface visibility.
6574 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6575 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6576 EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility());
ajumaaa0d3862015-11-09 22:24:466577}
6578
[email protected]995708c52013-10-17 20:52:596579TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
6580 // Checks that the simple case (being clipped by a scroll parent that would
6581 // have been processed before you anyhow) results in the right clips.
6582 //
6583 // + root
6584 // + scroll_parent_border
6585 // | + scroll_parent_clip
6586 // | + scroll_parent
6587 // + scroll_child
6588 //
enne085b48a2015-08-18 17:54:486589 LayerImpl* root = root_layer();
6590 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
6591 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6592 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6593 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596594
enne085b48a2015-08-18 17:54:486595 scroll_parent->SetDrawsContent(true);
6596 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596597 scroll_parent_clip->SetMasksToBounds(true);
6598
enne085b48a2015-08-18 17:54:486599 scroll_child->SetScrollParent(scroll_parent);
6600 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6601 scroll_children->insert(scroll_child);
6602 scroll_parent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596603
6604 gfx::Transform identity_transform;
enne085b48a2015-08-18 17:54:486605 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6606 gfx::PointF(), gfx::Size(50, 50), true, false,
6607 true);
6608 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6609 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6610 true, false, false);
6611 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6612 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6613 true, false, false);
6614 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6615 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6616 true, false, false);
6617 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6618 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596619 false);
6620
enne085b48a2015-08-18 17:54:486621 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596622
6623 EXPECT_TRUE(root->render_surface());
6624
6625 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6626 scroll_child->clip_rect().ToString());
6627 EXPECT_TRUE(scroll_child->is_clipped());
6628}
6629
jaydasika8ccff3d2016-01-20 19:51:306630TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) {
6631 // Tests the computation of draw transform for the scroll child when its
6632 // target is different from its scroll parent's target.
6633 LayerImpl* root = root_layer();
6634 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
6635 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
6636 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target);
6637 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
6638
6639 scroll_parent->SetDrawsContent(true);
6640 scroll_child->SetDrawsContent(true);
6641
6642 scroll_child->SetScrollParent(scroll_parent);
6643 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6644 scroll_children->insert(scroll_child);
6645 scroll_parent->SetScrollChildren(scroll_children.release());
6646
6647 gfx::Transform identity_transform;
6648 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6649 gfx::PointF(), gfx::Size(50, 50), true, false,
6650 true);
6651 SetLayerPropertiesForTesting(scroll_child_target, identity_transform,
6652 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6653 true, false, true);
6654 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6655 gfx::PointF(), gfx::Size(50, 50), true, false,
6656 false);
6657 SetLayerPropertiesForTesting(scroll_parent_target, identity_transform,
6658 gfx::Point3F(), gfx::PointF(10, 10),
6659 gfx::Size(50, 50), true, false, true);
6660 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6661 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
jaydasika2489a442016-01-29 02:26:006662 true, false, false);
6663 scroll_parent_target->SetMasksToBounds(true);
jaydasika8ccff3d2016-01-20 19:51:306664
jaydasika2489a442016-01-29 02:26:006665 float device_scale_factor = 1.5f;
6666 LayerImplList render_surface_layer_list_impl;
6667 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
6668 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6669 root, root->bounds(), identity_transform, &render_surface_layer_list_impl,
6670 root->layer_tree_impl()->current_render_surface_list_id());
6671 inputs.device_scale_factor = device_scale_factor;
6672 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6673
6674 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40));
6675 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75));
6676 gfx::Transform scale;
6677 scale.Scale(1.5f, 1.5f);
6678 EXPECT_EQ(scroll_child->DrawTransform(), scale);
jaydasika8ccff3d2016-01-20 19:51:306679}
6680
[email protected]08bdf1b2014-04-16 23:23:296681TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
enneca33fed2015-07-27 18:22:196682 LayerImpl* root = root_layer();
6683 root->SetDrawsContent(true);
6684 LayerImpl* parent = AddChildToRoot<LayerImpl>();
6685 parent->SetDrawsContent(true);
6686 LayerImpl* child = AddChild<LayerImpl>(parent);
6687 child->SetDrawsContent(true);
[email protected]08bdf1b2014-04-16 23:23:296688
6689 gfx::Transform identity_transform;
enneca33fed2015-07-27 18:22:196690 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6691 gfx::PointF(), gfx::Size(50, 50), true, true,
[email protected]08bdf1b2014-04-16 23:23:296692 true);
enneca33fed2015-07-27 18:22:196693 SetLayerPropertiesForTesting(parent, identity_transform, gfx::Point3F(),
6694 gfx::PointF(), gfx::Size(30, 30), true, true,
[email protected]08bdf1b2014-04-16 23:23:296695 true);
enneca33fed2015-07-27 18:22:196696 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6697 gfx::PointF(), gfx::Size(20, 20), true, true,
[email protected]08bdf1b2014-04-16 23:23:296698 true);
[email protected]08bdf1b2014-04-16 23:23:296699
enneca33fed2015-07-27 18:22:196700 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296701
enneca33fed2015-07-27 18:22:196702 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296703
6704 gfx::Transform singular_transform;
6705 singular_transform.Scale3d(
6706 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6707
6708 child->SetTransform(singular_transform);
6709
enneca33fed2015-07-27 18:22:196710 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296711
enneca33fed2015-07-27 18:22:196712 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296713
6714 // Ensure that the entire subtree under a layer with singular transform does
6715 // not get rendered.
6716 parent->SetTransform(singular_transform);
6717 child->SetTransform(identity_transform);
6718
enneca33fed2015-07-27 18:22:196719 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296720
enneca33fed2015-07-27 18:22:196721 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296722}
6723
[email protected]995708c52013-10-17 20:52:596724TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
6725 // Checks that clipping by a scroll parent that follows you in paint order
6726 // still results in correct clipping.
6727 //
6728 // + root
[email protected]995708c52013-10-17 20:52:596729 // + scroll_parent_border
6730 // + scroll_parent_clip
6731 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026732 // + scroll_child
[email protected]995708c52013-10-17 20:52:596733 //
enne03b0e9a2015-06-19 00:08:026734 LayerImpl* root = root_layer();
6735 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6736 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6737 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6738 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596739
enne03b0e9a2015-06-19 00:08:026740 scroll_parent->SetDrawsContent(true);
6741 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596742
6743 scroll_parent_clip->SetMasksToBounds(true);
6744
enne03b0e9a2015-06-19 00:08:026745 scroll_child->SetScrollParent(scroll_parent);
ajuma9af2e92b2015-06-29 22:26:386746 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6747 scroll_children->insert(scroll_child);
6748 scroll_parent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596749
6750 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026751 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6752 gfx::PointF(), gfx::Size(50, 50), true, false,
6753 true);
6754 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6755 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6756 true, false, false);
6757 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6758 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6759 true, false, false);
6760 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6761 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6762 true, false, false);
6763 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6764 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596765 false);
6766
enne03b0e9a2015-06-19 00:08:026767 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596768
6769 EXPECT_TRUE(root->render_surface());
6770
6771 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6772 scroll_child->clip_rect().ToString());
6773 EXPECT_TRUE(scroll_child->is_clipped());
6774}
6775
6776TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
6777 // Checks that clipping by a scroll parent and scroll grandparent that follow
6778 // you in paint order still results in correct clipping.
6779 //
6780 // + root
6781 // + scroll_child
6782 // + scroll_parent_border
6783 // | + scroll_parent_clip
6784 // | + scroll_parent
6785 // + scroll_grandparent_border
6786 // + scroll_grandparent_clip
6787 // + scroll_grandparent
6788 //
enne03b0e9a2015-06-19 00:08:026789 LayerImpl* root = root_layer();
6790 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6791 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6792 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6793 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6794 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6795 LayerImpl* scroll_grandparent_clip =
6796 AddChild<LayerImpl>(scroll_grandparent_border);
6797 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:596798
enne03b0e9a2015-06-19 00:08:026799 scroll_parent->SetDrawsContent(true);
6800 scroll_grandparent->SetDrawsContent(true);
6801 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596802
6803 scroll_parent_clip->SetMasksToBounds(true);
6804 scroll_grandparent_clip->SetMasksToBounds(true);
6805
enne03b0e9a2015-06-19 00:08:026806 scroll_child->SetScrollParent(scroll_parent);
ajuma9af2e92b2015-06-29 22:26:386807 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6808 scroll_children->insert(scroll_child);
6809 scroll_parent->SetScrollChildren(scroll_children.release());
6810
enne03b0e9a2015-06-19 00:08:026811 scroll_parent_border->SetScrollParent(scroll_grandparent);
ajuma9af2e92b2015-06-29 22:26:386812 scroll_children.reset(new std::set<LayerImpl*>);
6813 scroll_children->insert(scroll_parent_border);
6814 scroll_grandparent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596815
6816 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026817 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6818 gfx::PointF(), gfx::Size(50, 50), true, false,
6819 true);
6820 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6821 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6822 true, false, false);
6823 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6824 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6825 true, false, false);
6826 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6827 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6828 true, false, false);
6829 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6830 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6831 true, false, false);
6832 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6833 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6834 true, false, false);
6835 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6836 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6837 true, false, false);
6838 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6839 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596840 false);
6841
enne03b0e9a2015-06-19 00:08:026842 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596843
6844 EXPECT_TRUE(root->render_surface());
6845
6846 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
6847 scroll_child->clip_rect().ToString());
6848 EXPECT_TRUE(scroll_child->is_clipped());
6849
6850 // Despite the fact that we visited the above layers out of order to get the
6851 // correct clip, the layer lists should be unaffected.
6852 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
enne03b0e9a2015-06-19 00:08:026853 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
6854 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
6855 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
[email protected]995708c52013-10-17 20:52:596856}
6857
6858TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
6859 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:226860 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:596861 // + root
6862 // + scroll_child
6863 // + scroll_parent_border
6864 // + scroll_parent_clip
6865 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026866 // + render_surface2
[email protected]995708c52013-10-17 20:52:596867 // + scroll_grandparent_border
6868 // + scroll_grandparent_clip
6869 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:026870 // + render_surface1
[email protected]995708c52013-10-17 20:52:596871 //
enne03b0e9a2015-06-19 00:08:026872 LayerImpl* root = root_layer();
6873 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596874
enne03b0e9a2015-06-19 00:08:026875 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6876 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596877
enne03b0e9a2015-06-19 00:08:026878 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6879 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6880 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6881 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
6882 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6883 LayerImpl* scroll_grandparent_clip =
6884 AddChild<LayerImpl>(scroll_grandparent_border);
6885 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6886 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:596887
enne03b0e9a2015-06-19 00:08:026888 scroll_parent->SetDrawsContent(true);
6889 render_surface1->SetDrawsContent(true);
6890 scroll_grandparent->SetDrawsContent(true);
6891 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596892
6893 scroll_parent_clip->SetMasksToBounds(true);
6894 scroll_grandparent_clip->SetMasksToBounds(true);
6895
enne03b0e9a2015-06-19 00:08:026896 scroll_child->SetScrollParent(scroll_parent);
ajuma9af2e92b2015-06-29 22:26:386897 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6898 scroll_children->insert(scroll_child);
6899 scroll_parent->SetScrollChildren(scroll_children.release());
6900
enne03b0e9a2015-06-19 00:08:026901 scroll_parent_border->SetScrollParent(scroll_grandparent);
ajuma9af2e92b2015-06-29 22:26:386902 scroll_children.reset(new std::set<LayerImpl*>);
6903 scroll_children->insert(scroll_parent_border);
6904 scroll_grandparent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596905
6906 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026907 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6908 gfx::PointF(), gfx::Size(50, 50), true, false,
6909 true);
6910 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6911 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6912 true, false, false);
6913 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6914 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6915 true, false, false);
6916 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6917 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6918 true, false, false);
6919 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6920 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6921 true, false, true);
6922 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6923 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6924 true, false, false);
6925 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6926 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6927 true, false, false);
6928 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6929 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6930 true, false, false);
6931 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6932 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6933 true, false, true);
6934 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6935 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596936 false);
6937
enne03b0e9a2015-06-19 00:08:026938 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596939
6940 EXPECT_TRUE(root->render_surface());
6941
6942 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
6943 scroll_child->clip_rect().ToString());
6944 EXPECT_TRUE(scroll_child->is_clipped());
6945
6946 // Despite the fact that we had to process the layers out of order to get the
6947 // right clip, our render_surface_layer_list's order should be unaffected.
enne03b0e9a2015-06-19 00:08:026948 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6949 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
6950 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
6951 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
6952 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6953 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6954 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:596955}
6956
ajuma0b10f942015-03-21 07:45:536957TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
6958 // Ensures that when we have a render surface between a fixed position layer
6959 // and its container, we compute the fixed position layer's draw transform
6960 // with respect to that intervening render surface, not with respect to its
6961 // container's render target.
6962 //
6963 // + root
6964 // + render_surface
6965 // + fixed
ajuma737b2702015-05-06 01:18:376966 // + child
ajuma0b10f942015-03-21 07:45:536967 //
loysoa6edaaff2015-05-25 03:26:446968 scoped_refptr<Layer> root = Layer::Create(layer_settings());
ajuma0b10f942015-03-21 07:45:536969 scoped_refptr<LayerWithForcedDrawsContent> render_surface =
loysoa6edaaff2015-05-25 03:26:446970 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma0b10f942015-03-21 07:45:536971 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:446972 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma737b2702015-05-06 01:18:376973 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:446974 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma0b10f942015-03-21 07:45:536975
6976 root->AddChild(render_surface);
6977 render_surface->AddChild(fixed);
ajuma737b2702015-05-06 01:18:376978 fixed->AddChild(child);
ajuma0b10f942015-03-21 07:45:536979
6980 root->SetIsContainerForFixedPositionLayers(true);
6981 render_surface->SetForceRenderSurface(true);
6982
6983 LayerPositionConstraint constraint;
6984 constraint.set_is_fixed_position(true);
6985 fixed->SetPositionConstraint(constraint);
6986
6987 SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(),
6988 gfx::PointF(), gfx::Size(50, 50), true, false);
6989 SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(),
6990 gfx::Point3F(), gfx::PointF(7.f, 9.f),
6991 gfx::Size(50, 50), true, false);
6992 SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(),
6993 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true,
6994 false);
ajuma737b2702015-05-06 01:18:376995 SetLayerPropertiesForTesting(child.get(), gfx::Transform(), gfx::Point3F(),
6996 gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true,
6997 false);
ajuma0b10f942015-03-21 07:45:536998
ennea7b43c32015-06-18 20:01:336999 host()->SetRootLayer(root);
ajuma0b10f942015-03-21 07:45:537000
7001 ExecuteCalculateDrawProperties(root.get());
7002
ennef6903532015-08-18 05:10:157003 TransformTree& tree = host()->property_trees()->transform_tree;
7004
ajuma737b2702015-05-06 01:18:377005 gfx::Transform expected_fixed_draw_transform;
7006 expected_fixed_draw_transform.Translate(10.f, 15.f);
ennef6903532015-08-18 05:10:157007 EXPECT_EQ(expected_fixed_draw_transform,
7008 DrawTransformFromPropertyTrees(fixed.get(), tree));
ajuma0b10f942015-03-21 07:45:537009
ajuma737b2702015-05-06 01:18:377010 gfx::Transform expected_fixed_screen_space_transform;
7011 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
7012 EXPECT_EQ(expected_fixed_screen_space_transform,
ennef6903532015-08-18 05:10:157013 ScreenSpaceTransformFromPropertyTrees(fixed.get(), tree));
ajuma737b2702015-05-06 01:18:377014
7015 gfx::Transform expected_child_draw_transform;
7016 expected_child_draw_transform.Translate(11.f, 17.f);
ennef6903532015-08-18 05:10:157017 EXPECT_EQ(expected_child_draw_transform,
7018 DrawTransformFromPropertyTrees(child.get(), tree));
ajuma737b2702015-05-06 01:18:377019
7020 gfx::Transform expected_child_screen_space_transform;
7021 expected_child_screen_space_transform.Translate(18.f, 26.f);
7022 EXPECT_EQ(expected_child_screen_space_transform,
ennef6903532015-08-18 05:10:157023 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
ajuma0b10f942015-03-21 07:45:537024}
7025
[email protected]d81752b2013-10-25 08:32:237026TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
7027 // This test verifies that a scrolling layer that gets snapped to
7028 // integer coordinates doesn't move a fixed position child.
7029 //
7030 // + root
7031 // + container
7032 // + scroller
7033 // + fixed
7034 //
khushalsagarb64b360d2015-10-21 19:25:167035 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:457036 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567037 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167038 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567039 &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:237040 host_impl.CreatePendingTree();
7041 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7042 scoped_ptr<LayerImpl> container =
7043 LayerImpl::Create(host_impl.active_tree(), 2);
7044 LayerImpl* container_layer = container.get();
7045 scoped_ptr<LayerImpl> scroller =
7046 LayerImpl::Create(host_impl.active_tree(), 3);
7047 LayerImpl* scroll_layer = scroller.get();
7048 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7049 LayerImpl* fixed_layer = fixed.get();
7050
7051 container->SetIsContainerForFixedPositionLayers(true);
7052
7053 LayerPositionConstraint constraint;
7054 constraint.set_is_fixed_position(true);
7055 fixed->SetPositionConstraint(constraint);
7056
[email protected]adeda572014-01-31 00:49:477057 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:237058
7059 gfx::Transform identity_transform;
7060 gfx::Transform container_transform;
7061 container_transform.Translate3d(10.0, 20.0, 0.0);
7062 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7063
awoloszyne83f28c2014-12-22 15:40:007064 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7065 gfx::PointF(), gfx::Size(50, 50), true, false,
7066 true);
7067 SetLayerPropertiesForTesting(container.get(), container_transform,
7068 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7069 true, false, false);
7070 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7071 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7072 true, false, false);
7073 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7074 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]d81752b2013-10-25 08:32:237075 false);
7076
jaydasika0d98ba92015-11-17 05:17:287077 root->SetDrawsContent(true);
7078 container->SetDrawsContent(true);
7079 scroller->SetDrawsContent(true);
7080 fixed->SetDrawsContent(true);
danakja04855a2015-11-18 20:39:107081 scroller->AddChild(std::move(fixed));
7082 container->AddChild(std::move(scroller));
7083 root->AddChild(std::move(container));
[email protected]d81752b2013-10-25 08:32:237084
7085 // Rounded to integers already.
7086 {
7087 gfx::Vector2dF scroll_delta(3.0, 5.0);
7088 scroll_layer->SetScrollDelta(scroll_delta);
7089
7090 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:447091 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]d81752b2013-10-25 08:32:237092 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:447093 root.get(), root->bounds(), &render_surface_layer_list,
7094 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]d81752b2013-10-25 08:32:237095 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7096
7097 EXPECT_TRANSFORMATION_MATRIX_EQ(
7098 container_layer->draw_properties().screen_space_transform,
7099 fixed_layer->draw_properties().screen_space_transform);
7100 EXPECT_VECTOR_EQ(
7101 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7102 container_offset);
7103 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7104 .screen_space_transform.To2dTranslation(),
7105 container_offset - scroll_delta);
7106 }
7107
7108 // Scroll delta requiring rounding.
7109 {
7110 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
7111 scroll_layer->SetScrollDelta(scroll_delta);
7112
7113 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
7114
7115 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:447116 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]d81752b2013-10-25 08:32:237117 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:447118 root.get(), root->bounds(), &render_surface_layer_list,
7119 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]d81752b2013-10-25 08:32:237120 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7121
7122 EXPECT_TRANSFORMATION_MATRIX_EQ(
7123 container_layer->draw_properties().screen_space_transform,
7124 fixed_layer->draw_properties().screen_space_transform);
7125 EXPECT_VECTOR_EQ(
7126 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7127 container_offset);
7128 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7129 .screen_space_transform.To2dTranslation(),
7130 container_offset - rounded_scroll_delta);
7131 }
[email protected]cf15ad7b2014-04-02 03:59:267132
7133 // Scale is applied earlier in the tree.
7134 {
7135 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:287136 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
[email protected]cf15ad7b2014-04-02 03:59:267137 container_layer->SetTransform(scaled_container_transform);
jaydasika0d98ba92015-11-17 05:17:287138 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
7139 root->layer_tree_impl()
7140 ->property_trees()
7141 ->transform_tree.set_source_to_parent_updates_allowed(true);
[email protected]cf15ad7b2014-04-02 03:59:267142
7143 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7144 scroll_layer->SetScrollDelta(scroll_delta);
7145
7146 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:447147 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]cf15ad7b2014-04-02 03:59:267148 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:447149 root.get(), root->bounds(), &render_surface_layer_list,
7150 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]cf15ad7b2014-04-02 03:59:267151 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7152
7153 EXPECT_TRANSFORMATION_MATRIX_EQ(
7154 container_layer->draw_properties().screen_space_transform,
7155 fixed_layer->draw_properties().screen_space_transform);
7156 EXPECT_VECTOR_EQ(
7157 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7158 container_offset);
7159
7160 container_layer->SetTransform(container_transform);
7161 }
[email protected]d81752b2013-10-25 08:32:237162}
7163
miletus2c78036b2015-01-29 20:52:377164TEST_F(LayerTreeHostCommonTest,
7165 ScrollCompensationMainScrollOffsetFractionalPart) {
7166 // This test verifies that a scrolling layer that has fractional scroll offset
7167 // from main doesn't move a fixed position child.
7168 //
7169 // + root
7170 // + container
7171 // + scroller
7172 // + fixed
7173 //
khushalsagarb64b360d2015-10-21 19:25:167174 FakeImplTaskRunnerProvider task_runner_provider;
miletus2c78036b2015-01-29 20:52:377175 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567176 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167177 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567178 &task_graph_runner);
miletus2c78036b2015-01-29 20:52:377179 host_impl.CreatePendingTree();
7180 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7181 scoped_ptr<LayerImpl> container =
7182 LayerImpl::Create(host_impl.active_tree(), 2);
7183 LayerImpl* container_layer = container.get();
7184 scoped_ptr<LayerImpl> scroller =
7185 LayerImpl::Create(host_impl.active_tree(), 3);
7186 LayerImpl* scroll_layer = scroller.get();
7187 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7188 LayerImpl* fixed_layer = fixed.get();
7189
7190 container->SetIsContainerForFixedPositionLayers(true);
7191
7192 LayerPositionConstraint constraint;
7193 constraint.set_is_fixed_position(true);
jaydasika8640f9f2015-11-10 01:34:367194 container->SetDrawsContent(true);
7195 fixed->SetDrawsContent(true);
miletus2c78036b2015-01-29 20:52:377196 fixed->SetPositionConstraint(constraint);
7197
jaydasika8640f9f2015-11-10 01:34:367198 scroller->SetDrawsContent(true);
miletus2c78036b2015-01-29 20:52:377199 scroller->SetScrollClipLayer(container->id());
7200
7201 gfx::Transform identity_transform;
7202 gfx::Transform container_transform;
7203 container_transform.Translate3d(10.0, 20.0, 0.0);
7204 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7205
7206 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7207 gfx::PointF(), gfx::Size(50, 50), true, false,
7208 true);
7209 SetLayerPropertiesForTesting(container.get(), container_transform,
7210 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7211 true, false, false);
7212 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7213 gfx::Point3F(), gfx::PointF(0.0, 0.0),
7214 gfx::Size(30, 30), true, false, false);
7215
7216 gfx::ScrollOffset scroll_offset(3.3, 4.2);
7217 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f);
7218 gfx::Vector2dF scroll_delta(0.1f, 0.4f);
7219 // Blink only uses the integer part of the scroll_offset for fixed
7220 // position layer.
7221 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7222 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true,
7223 false, false);
aeliasf998da82015-02-03 01:40:517224 scroll_layer->PushScrollOffsetFromMainThread(scroll_offset);
aeliasd0070ba2015-01-31 13:44:497225 scroll_layer->SetScrollDelta(scroll_delta);
miletusff93ab72015-01-30 04:30:447226 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part);
miletus2c78036b2015-01-29 20:52:377227
danakja04855a2015-11-18 20:39:107228 scroller->AddChild(std::move(fixed));
7229 container->AddChild(std::move(scroller));
7230 root->AddChild(std::move(container));
miletus2c78036b2015-01-29 20:52:377231
7232 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:447233 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
miletus2c78036b2015-01-29 20:52:377234 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:447235 root.get(), root->bounds(), &render_surface_layer_list,
7236 root->layer_tree_impl()->current_render_surface_list_id());
miletus2c78036b2015-01-29 20:52:377237 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7238
7239 EXPECT_TRANSFORMATION_MATRIX_EQ(
7240 container_layer->draw_properties().screen_space_transform,
7241 fixed_layer->draw_properties().screen_space_transform);
7242 EXPECT_VECTOR_EQ(
7243 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7244 container_offset);
7245
7246 gfx::ScrollOffset effective_scroll_offset =
7247 ScrollOffsetWithDelta(scroll_offset, scroll_delta);
7248 gfx::Vector2d rounded_effective_scroll_offset =
7249 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset));
7250 EXPECT_VECTOR_EQ(
7251 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(),
7252 container_offset - rounded_effective_scroll_offset);
7253}
7254
ajuma5e8e40d2015-07-31 01:50:507255TEST_F(LayerTreeHostCommonTest,
7256 ScrollSnappingWithAnimatedScreenSpaceTransform) {
7257 // This test verifies that a scrolling layer whose screen space transform is
7258 // animating doesn't get snapped to integer coordinates.
7259 //
7260 // + root
7261 // + animated layer
7262 // + surface
7263 // + container
7264 // + scroller
7265 //
7266 LayerImpl* root = root_layer();
7267 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
7268 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
7269 LayerImpl* container = AddChild<LayerImpl>(surface);
7270 LayerImpl* scroller = AddChild<LayerImpl>(container);
7271 scroller->SetScrollClipLayer(container->id());
7272 scroller->SetDrawsContent(true);
7273
7274 gfx::Transform identity_transform;
7275 gfx::Transform start_scale;
7276 start_scale.Scale(1.5f, 1.5f);
7277 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
7278 gfx::PointF(), gfx::Size(50, 50), true, false,
7279 true);
7280 SetLayerPropertiesForTesting(animated_layer, start_scale, gfx::Point3F(),
7281 gfx::PointF(), gfx::Size(50, 50), true, false,
7282 false);
7283 SetLayerPropertiesForTesting(surface, identity_transform, gfx::Point3F(),
7284 gfx::PointF(), gfx::Size(50, 50), true, false,
7285 true);
7286 SetLayerPropertiesForTesting(container, identity_transform, gfx::Point3F(),
7287 gfx::PointF(), gfx::Size(50, 50), true, false,
7288 false);
7289 SetLayerPropertiesForTesting(scroller, identity_transform, gfx::Point3F(),
7290 gfx::PointF(), gfx::Size(100, 100), true, false,
7291 false);
7292
7293 gfx::Transform end_scale;
7294 end_scale.Scale(2.f, 2.f);
7295 TransformOperations start_operations;
7296 start_operations.AppendMatrix(start_scale);
7297 TransformOperations end_operations;
7298 end_operations.AppendMatrix(end_scale);
loyso968163c92016-01-04 23:18:487299 if (layer_settings().use_compositor_animation_timelines) {
7300 AddAnimatedTransformToLayerWithPlayer(animated_layer->id(), timeline_impl(),
7301 1.0, start_operations,
7302 end_operations);
7303 } else {
7304 AddAnimatedTransformToLayer(animated_layer, 1.0, start_operations,
7305 end_operations);
7306 }
ajuma5e8e40d2015-07-31 01:50:507307 gfx::Vector2dF scroll_delta(5.f, 9.f);
7308 scroller->SetScrollDelta(scroll_delta);
7309
7310 ExecuteCalculateDrawProperties(root);
7311
7312 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
7313 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:447314 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:507315}
7316
[email protected]1c3626e2014-04-09 17:49:227317class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7318 public:
7319 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
7320 LayerTreeImpl* tree_impl,
7321 int id) {
7322 return make_scoped_ptr(
7323 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7324 }
7325
dcheng716bedf2014-10-21 09:51:087326 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227327
[email protected]1c3626e2014-04-09 17:49:227328 private:
7329 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7330 int id)
[email protected]a57cb8b12014-06-13 18:15:377331 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227332 SetDrawsContent(true);
7333 }
[email protected]1c3626e2014-04-09 17:49:227334};
7335
7336TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:167337 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]1c3626e2014-04-09 17:49:227338 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567339 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:487340 LayerTreeSettings settings = host()->settings();
ajumab4a846f22015-08-24 19:13:447341 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167342 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7343 &shared_bitmap_manager, &task_graph_runner);
[email protected]1c3626e2014-04-09 17:49:227344 gfx::Transform identity_matrix;
7345 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
7346 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
7347 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
7348 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
7349 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
7350 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
7351 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
7352 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7353
7354 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7355 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7356 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
7357
danakja04855a2015-11-18 20:39:107358 child->AddChild(std::move(grand_child));
7359 parent->AddChild(std::move(child));
7360 grand_parent->AddChild(std::move(parent));
[email protected]1c3626e2014-04-09 17:49:227361
awoloszyne83f28c2014-12-22 15:40:007362 SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix,
7363 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7364 true, false, true);
7365 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7366 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227367 false);
awoloszyne83f28c2014-12-22 15:40:007368 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7369 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227370 false);
awoloszyne83f28c2014-12-22 15:40:007371
7372 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
7373 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227374 false);
7375
7376 ExecuteCalculateDrawProperties(grand_parent.get());
7377
7378 // No layers have animations.
[email protected]a57cb8b12014-06-13 18:15:377379 EXPECT_EQ(0.f,
7380 grand_parent->draw_properties().maximum_animation_contents_scale);
7381 EXPECT_EQ(0.f,
7382 parent_raw->draw_properties().maximum_animation_contents_scale);
7383 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7384 EXPECT_EQ(
7385 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227386
ajuma052892e2015-08-21 14:39:037387 EXPECT_EQ(0.f,
7388 grand_parent->draw_properties().starting_animation_contents_scale);
7389 EXPECT_EQ(0.f,
7390 parent_raw->draw_properties().starting_animation_contents_scale);
7391 EXPECT_EQ(0.f,
7392 child_raw->draw_properties().starting_animation_contents_scale);
7393 EXPECT_EQ(
7394 0.f,
7395 grand_child_raw->draw_properties().starting_animation_contents_scale);
7396
[email protected]1c3626e2014-04-09 17:49:227397 TransformOperations translation;
7398 translation.AppendTranslate(1.f, 2.f, 3.f);
7399
loyso968163c92016-01-04 23:18:487400 scoped_refptr<AnimationTimeline> timeline;
7401 if (layer_settings().use_compositor_animation_timelines) {
7402 timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7403 host_impl.animation_host()->AddAnimationTimeline(timeline);
7404
7405 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7406 TransformOperations(), translation);
7407 } else {
7408 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(),
7409 translation);
7410 }
[email protected]1c3626e2014-04-09 17:49:227411
7412 // No layers have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377413 EXPECT_EQ(0.f,
7414 grand_parent->draw_properties().maximum_animation_contents_scale);
7415 EXPECT_EQ(0.f,
7416 parent_raw->draw_properties().maximum_animation_contents_scale);
7417 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7418 EXPECT_EQ(
7419 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227420
ajuma052892e2015-08-21 14:39:037421 EXPECT_EQ(0.f,
7422 grand_parent->draw_properties().starting_animation_contents_scale);
7423 EXPECT_EQ(0.f,
7424 parent_raw->draw_properties().starting_animation_contents_scale);
7425 EXPECT_EQ(0.f,
7426 child_raw->draw_properties().starting_animation_contents_scale);
7427 EXPECT_EQ(
7428 0.f,
7429 grand_child_raw->draw_properties().starting_animation_contents_scale);
7430
[email protected]1c3626e2014-04-09 17:49:227431 TransformOperations scale;
7432 scale.AppendScale(5.f, 4.f, 3.f);
7433
loyso968163c92016-01-04 23:18:487434 if (layer_settings().use_compositor_animation_timelines) {
7435 AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0,
7436 TransformOperations(), scale);
7437 } else {
7438 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
7439 }
ajumacaaa9b32015-08-04 15:55:297440 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227441 ExecuteCalculateDrawProperties(grand_parent.get());
7442
7443 // Only |child| has a scale-affecting animation.
[email protected]a57cb8b12014-06-13 18:15:377444 EXPECT_EQ(0.f,
7445 grand_parent->draw_properties().maximum_animation_contents_scale);
7446 EXPECT_EQ(0.f,
7447 parent_raw->draw_properties().maximum_animation_contents_scale);
7448 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
7449 EXPECT_EQ(
7450 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227451
ajuma052892e2015-08-21 14:39:037452 EXPECT_EQ(0.f,
7453 grand_parent->draw_properties().starting_animation_contents_scale);
7454 EXPECT_EQ(0.f,
7455 parent_raw->draw_properties().starting_animation_contents_scale);
7456 EXPECT_EQ(1.f,
7457 child_raw->draw_properties().starting_animation_contents_scale);
7458 EXPECT_EQ(
7459 1.f,
7460 grand_child_raw->draw_properties().starting_animation_contents_scale);
7461
loyso968163c92016-01-04 23:18:487462 if (layer_settings().use_compositor_animation_timelines) {
7463 AddAnimatedTransformToLayerWithPlayer(grand_parent->id(), timeline, 1.0,
7464 TransformOperations(), scale);
7465 } else {
7466 AddAnimatedTransformToLayer(grand_parent.get(), 1.0, TransformOperations(),
7467 scale);
7468 }
ajumacaaa9b32015-08-04 15:55:297469 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227470 ExecuteCalculateDrawProperties(grand_parent.get());
7471
7472 // |grand_parent| and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377473 EXPECT_EQ(5.f,
7474 grand_parent->draw_properties().maximum_animation_contents_scale);
7475 EXPECT_EQ(5.f,
7476 parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227477 // We don't support combining animated scales from two nodes; 0.f means
7478 // that the maximum scale could not be computed.
[email protected]a57cb8b12014-06-13 18:15:377479 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7480 EXPECT_EQ(
7481 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227482
ajuma052892e2015-08-21 14:39:037483 EXPECT_EQ(1.f,
7484 grand_parent->draw_properties().starting_animation_contents_scale);
7485 EXPECT_EQ(1.f,
7486 parent_raw->draw_properties().starting_animation_contents_scale);
7487 EXPECT_EQ(0.f,
7488 child_raw->draw_properties().starting_animation_contents_scale);
7489 EXPECT_EQ(
7490 0.f,
7491 grand_child_raw->draw_properties().starting_animation_contents_scale);
7492
loyso968163c92016-01-04 23:18:487493 if (layer_settings().use_compositor_animation_timelines) {
7494 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7495 TransformOperations(), scale);
7496 } else {
7497 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
7498 }
ajumacaaa9b32015-08-04 15:55:297499 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227500 ExecuteCalculateDrawProperties(grand_parent.get());
7501
7502 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377503 EXPECT_EQ(5.f,
7504 grand_parent->draw_properties().maximum_animation_contents_scale);
7505 EXPECT_EQ(0.f,
7506 parent_raw->draw_properties().maximum_animation_contents_scale);
7507 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7508 EXPECT_EQ(
7509 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227510
ajuma052892e2015-08-21 14:39:037511 EXPECT_EQ(1.f,
7512 grand_parent->draw_properties().starting_animation_contents_scale);
7513 EXPECT_EQ(0.f,
7514 parent_raw->draw_properties().starting_animation_contents_scale);
7515 EXPECT_EQ(0.f,
7516 child_raw->draw_properties().starting_animation_contents_scale);
7517 EXPECT_EQ(
7518 0.f,
7519 grand_child_raw->draw_properties().starting_animation_contents_scale);
7520
loyso968163c92016-01-04 23:18:487521 if (layer_settings().use_compositor_animation_timelines) {
7522 AbortAnimationsOnLayerWithPlayer(grand_parent->id(), timeline,
7523 Animation::TRANSFORM);
7524 AbortAnimationsOnLayerWithPlayer(parent_raw->id(), timeline,
7525 Animation::TRANSFORM);
7526 AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline,
7527 Animation::TRANSFORM);
7528 } else {
7529 grand_parent->layer_animation_controller()->AbortAnimations(
7530 Animation::TRANSFORM);
7531 parent_raw->layer_animation_controller()->AbortAnimations(
7532 Animation::TRANSFORM);
7533 child_raw->layer_animation_controller()->AbortAnimations(
7534 Animation::TRANSFORM);
7535 }
[email protected]1c3626e2014-04-09 17:49:227536
7537 TransformOperations perspective;
7538 perspective.AppendPerspective(10.f);
7539
loyso968163c92016-01-04 23:18:487540 if (layer_settings().use_compositor_animation_timelines) {
7541 AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0,
7542 TransformOperations(), perspective);
7543 } else {
7544 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(),
7545 perspective);
7546 }
ajumab4a846f22015-08-24 19:13:447547 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227548 ExecuteCalculateDrawProperties(grand_parent.get());
7549
7550 // |child| has a scale-affecting animation but computing the maximum of this
7551 // animation is not supported.
[email protected]a57cb8b12014-06-13 18:15:377552 EXPECT_EQ(0.f,
7553 grand_parent->draw_properties().maximum_animation_contents_scale);
7554 EXPECT_EQ(0.f,
7555 parent_raw->draw_properties().maximum_animation_contents_scale);
7556 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7557 EXPECT_EQ(
7558 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227559
ajuma052892e2015-08-21 14:39:037560 EXPECT_EQ(0.f,
7561 grand_parent->draw_properties().starting_animation_contents_scale);
7562 EXPECT_EQ(0.f,
7563 parent_raw->draw_properties().starting_animation_contents_scale);
7564 EXPECT_EQ(0.f,
7565 child_raw->draw_properties().starting_animation_contents_scale);
7566 EXPECT_EQ(
7567 0.f,
7568 grand_child_raw->draw_properties().starting_animation_contents_scale);
7569
loyso968163c92016-01-04 23:18:487570 if (layer_settings().use_compositor_animation_timelines) {
7571 AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline,
7572 Animation::TRANSFORM);
7573 } else {
7574 child_raw->layer_animation_controller()->AbortAnimations(
7575 Animation::TRANSFORM);
7576 }
[email protected]1c3626e2014-04-09 17:49:227577 gfx::Transform scale_matrix;
7578 scale_matrix.Scale(1.f, 2.f);
7579 grand_parent->SetTransform(scale_matrix);
7580 parent_raw->SetTransform(scale_matrix);
miletus843080c2015-06-11 22:11:017581 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:487582
7583 if (layer_settings().use_compositor_animation_timelines) {
7584 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7585 TransformOperations(), scale);
7586 } else {
7587 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
7588 }
[email protected]1c3626e2014-04-09 17:49:227589 ExecuteCalculateDrawProperties(grand_parent.get());
7590
7591 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7592 // animation with maximum scale 5.f.
[email protected]a57cb8b12014-06-13 18:15:377593 EXPECT_EQ(0.f,
7594 grand_parent->draw_properties().maximum_animation_contents_scale);
7595 EXPECT_EQ(10.f,
7596 parent_raw->draw_properties().maximum_animation_contents_scale);
7597 EXPECT_EQ(10.f,
7598 child_raw->draw_properties().maximum_animation_contents_scale);
7599 EXPECT_EQ(
7600 10.f,
7601 grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227602
ajuma052892e2015-08-21 14:39:037603 EXPECT_EQ(0.f,
7604 grand_parent->draw_properties().starting_animation_contents_scale);
7605 EXPECT_EQ(2.f,
7606 parent_raw->draw_properties().starting_animation_contents_scale);
7607 EXPECT_EQ(2.f,
7608 child_raw->draw_properties().starting_animation_contents_scale);
7609 EXPECT_EQ(
7610 2.f,
7611 grand_child_raw->draw_properties().starting_animation_contents_scale);
7612
[email protected]1c3626e2014-04-09 17:49:227613 gfx::Transform perspective_matrix;
7614 perspective_matrix.ApplyPerspectiveDepth(2.f);
7615 child_raw->SetTransform(perspective_matrix);
miletus843080c2015-06-11 22:11:017616 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227617 ExecuteCalculateDrawProperties(grand_parent.get());
7618
7619 // |child| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:377620 EXPECT_EQ(0.f,
7621 grand_parent->draw_properties().maximum_animation_contents_scale);
7622 EXPECT_EQ(10.f,
7623 parent_raw->draw_properties().maximum_animation_contents_scale);
7624 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7625 EXPECT_EQ(
7626 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227627
ajuma052892e2015-08-21 14:39:037628 EXPECT_EQ(0.f,
7629 grand_parent->draw_properties().starting_animation_contents_scale);
7630 EXPECT_EQ(2.f,
7631 parent_raw->draw_properties().starting_animation_contents_scale);
7632 EXPECT_EQ(0.f,
7633 child_raw->draw_properties().starting_animation_contents_scale);
7634 EXPECT_EQ(
7635 0.f,
7636 grand_child_raw->draw_properties().starting_animation_contents_scale);
7637
[email protected]1c3626e2014-04-09 17:49:227638 parent_raw->SetTransform(perspective_matrix);
miletus843080c2015-06-11 22:11:017639 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227640 ExecuteCalculateDrawProperties(grand_parent.get());
7641
7642 // |parent| and |child| have transforms that are neither translations nor
7643 // scales.
[email protected]a57cb8b12014-06-13 18:15:377644 EXPECT_EQ(0.f,
7645 grand_parent->draw_properties().maximum_animation_contents_scale);
7646 EXPECT_EQ(0.f,
7647 parent_raw->draw_properties().maximum_animation_contents_scale);
7648 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7649 EXPECT_EQ(
7650 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227651
ajuma052892e2015-08-21 14:39:037652 EXPECT_EQ(0.f,
7653 grand_parent->draw_properties().starting_animation_contents_scale);
7654 EXPECT_EQ(0.f,
7655 parent_raw->draw_properties().starting_animation_contents_scale);
7656 EXPECT_EQ(0.f,
7657 child_raw->draw_properties().starting_animation_contents_scale);
7658 EXPECT_EQ(
7659 0.f,
7660 grand_child_raw->draw_properties().starting_animation_contents_scale);
7661
[email protected]1c3626e2014-04-09 17:49:227662 parent_raw->SetTransform(identity_matrix);
7663 child_raw->SetTransform(identity_matrix);
7664 grand_parent->SetTransform(perspective_matrix);
miletus843080c2015-06-11 22:11:017665 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227666
7667 ExecuteCalculateDrawProperties(grand_parent.get());
7668
7669 // |grand_parent| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:377670 EXPECT_EQ(0.f,
7671 grand_parent->draw_properties().maximum_animation_contents_scale);
7672 EXPECT_EQ(0.f,
7673 parent_raw->draw_properties().maximum_animation_contents_scale);
7674 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7675 EXPECT_EQ(
7676 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037677
7678 EXPECT_EQ(0.f,
7679 grand_parent->draw_properties().starting_animation_contents_scale);
7680 EXPECT_EQ(0.f,
7681 parent_raw->draw_properties().starting_animation_contents_scale);
7682 EXPECT_EQ(0.f,
7683 child_raw->draw_properties().starting_animation_contents_scale);
7684 EXPECT_EQ(
7685 0.f,
7686 grand_child_raw->draw_properties().starting_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227687}
7688
[email protected]390bb1ff2014-05-09 17:14:407689static int membership_id(LayerImpl* layer) {
7690 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
7691}
7692
7693static void GatherDrawnLayers(LayerImplList* rsll,
7694 std::set<LayerImpl*>* drawn_layers) {
enne389d1a12015-06-18 20:40:517695 for (LayerIterator it = LayerIterator::Begin(rsll),
7696 end = LayerIterator::End(rsll);
7697 it != end; ++it) {
[email protected]390bb1ff2014-05-09 17:14:407698 LayerImpl* layer = *it;
7699 if (it.represents_itself())
7700 drawn_layers->insert(layer);
7701
7702 if (!it.represents_contributing_render_surface())
7703 continue;
7704
7705 if (layer->mask_layer())
7706 drawn_layers->insert(layer->mask_layer());
7707 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
7708 drawn_layers->insert(layer->replica_layer()->mask_layer());
7709 }
7710}
7711
7712TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:167713 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]390bb1ff2014-05-09 17:14:407714 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567715 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167716 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567717 &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:407718 gfx::Transform identity_matrix;
7719
7720 scoped_ptr<LayerImpl> grand_parent =
7721 LayerImpl::Create(host_impl.active_tree(), 1);
7722 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
7723 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
7724 scoped_ptr<LayerImpl> grand_child1 =
7725 LayerImpl::Create(host_impl.active_tree(), 7);
7726 scoped_ptr<LayerImpl> grand_child2 =
7727 LayerImpl::Create(host_impl.active_tree(), 9);
7728
7729 LayerImpl* grand_parent_raw = grand_parent.get();
7730 LayerImpl* parent_raw = parent.get();
7731 LayerImpl* child_raw = child.get();
7732 LayerImpl* grand_child1_raw = grand_child1.get();
7733 LayerImpl* grand_child2_raw = grand_child2.get();
7734
danakja04855a2015-11-18 20:39:107735 child->AddChild(std::move(grand_child1));
7736 child->AddChild(std::move(grand_child2));
7737 parent->AddChild(std::move(child));
7738 grand_parent->AddChild(std::move(parent));
[email protected]390bb1ff2014-05-09 17:14:407739
awoloszyne83f28c2014-12-22 15:40:007740 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
7741 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7742 true, false, true);
7743 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7744 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:407745 false);
awoloszyne83f28c2014-12-22 15:40:007746
7747 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7748 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:407749 false);
awoloszyne83f28c2014-12-22 15:40:007750
7751 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
7752 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7753 true, false, false);
7754
7755 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
7756 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7757 true, false, false);
[email protected]390bb1ff2014-05-09 17:14:407758
7759 // Start with nothing being drawn.
7760 ExecuteCalculateDrawProperties(grand_parent_raw);
7761 int member_id = render_surface_layer_list_count();
7762
7763 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7764 EXPECT_NE(member_id, membership_id(parent_raw));
7765 EXPECT_NE(member_id, membership_id(child_raw));
7766 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7767 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7768
7769 std::set<LayerImpl*> expected;
7770 std::set<LayerImpl*> actual;
7771 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7772 EXPECT_EQ(expected, actual);
7773
7774 // If we force render surface, but none of the layers are in the layer list,
7775 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:007776 grand_child1_raw->SetHasRenderSurface(true);
jaydasikaebf9e4ea2015-08-14 21:29:127777 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407778
7779 ExecuteCalculateDrawProperties(grand_parent_raw);
7780 member_id = render_surface_layer_list_count();
7781
7782 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7783 EXPECT_NE(member_id, membership_id(parent_raw));
7784 EXPECT_NE(member_id, membership_id(child_raw));
7785 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7786 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7787
7788 expected.clear();
7789 actual.clear();
7790 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7791 EXPECT_EQ(expected, actual);
7792
7793 // However, if we say that this layer also draws content, it will appear in
7794 // RSLL.
7795 grand_child1_raw->SetDrawsContent(true);
7796
7797 ExecuteCalculateDrawProperties(grand_parent_raw);
7798 member_id = render_surface_layer_list_count();
7799
7800 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7801 EXPECT_NE(member_id, membership_id(parent_raw));
7802 EXPECT_NE(member_id, membership_id(child_raw));
7803 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
7804 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7805
7806 expected.clear();
7807 expected.insert(grand_child1_raw);
7808
7809 actual.clear();
7810 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7811 EXPECT_EQ(expected, actual);
7812
7813 // Now child is forced to have a render surface, and one if its children draws
7814 // content.
7815 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:007816 grand_child1_raw->SetHasRenderSurface(false);
jaydasikaebf9e4ea2015-08-14 21:29:127817 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
awoloszyne83f28c2014-12-22 15:40:007818 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:407819 grand_child2_raw->SetDrawsContent(true);
7820
7821 ExecuteCalculateDrawProperties(grand_parent_raw);
7822 member_id = render_surface_layer_list_count();
7823
7824 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7825 EXPECT_NE(member_id, membership_id(parent_raw));
7826 EXPECT_NE(member_id, membership_id(child_raw));
7827 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7828 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7829
7830 expected.clear();
7831 expected.insert(grand_child2_raw);
7832
7833 actual.clear();
7834 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7835 EXPECT_EQ(expected, actual);
7836
7837 // Add a mask layer to child.
danakja5a05ba02015-11-20 20:14:217838 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:047839 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407840
7841 ExecuteCalculateDrawProperties(grand_parent_raw);
7842 member_id = render_surface_layer_list_count();
7843
7844 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7845 EXPECT_NE(member_id, membership_id(parent_raw));
7846 EXPECT_NE(member_id, membership_id(child_raw));
7847 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7848 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7849 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7850
7851 expected.clear();
7852 expected.insert(grand_child2_raw);
7853 expected.insert(child_raw->mask_layer());
7854
7855 expected.clear();
7856 expected.insert(grand_child2_raw);
7857 expected.insert(child_raw->mask_layer());
7858
7859 actual.clear();
7860 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7861 EXPECT_EQ(expected, actual);
7862
7863 // Add replica mask layer.
7864 scoped_ptr<LayerImpl> replica_layer =
7865 LayerImpl::Create(host_impl.active_tree(), 20);
7866 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
danakja04855a2015-11-18 20:39:107867 child_raw->SetReplicaLayer(std::move(replica_layer));
jaydasika23fb3822015-08-25 03:22:597868 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407869
7870 ExecuteCalculateDrawProperties(grand_parent_raw);
7871 member_id = render_surface_layer_list_count();
7872
7873 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7874 EXPECT_NE(member_id, membership_id(parent_raw));
7875 EXPECT_NE(member_id, membership_id(child_raw));
7876 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7877 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
7878 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7879 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7880
7881 expected.clear();
7882 expected.insert(grand_child2_raw);
7883 expected.insert(child_raw->mask_layer());
7884 expected.insert(child_raw->replica_layer()->mask_layer());
7885
7886 actual.clear();
7887 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7888 EXPECT_EQ(expected, actual);
7889
7890 child_raw->TakeReplicaLayer();
7891
7892 // With nothing drawing, we should have no layers.
7893 grand_child2_raw->SetDrawsContent(false);
7894
7895 ExecuteCalculateDrawProperties(grand_parent_raw);
7896 member_id = render_surface_layer_list_count();
7897
7898 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7899 EXPECT_NE(member_id, membership_id(parent_raw));
7900 EXPECT_NE(member_id, membership_id(child_raw));
7901 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
7902 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7903 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7904
7905 expected.clear();
7906 actual.clear();
7907 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7908 EXPECT_EQ(expected, actual);
7909
7910 // Child itself draws means that we should have the child and the mask in the
7911 // list.
7912 child_raw->SetDrawsContent(true);
7913
7914 ExecuteCalculateDrawProperties(grand_parent_raw);
7915 member_id = render_surface_layer_list_count();
7916
7917 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7918 EXPECT_NE(member_id, membership_id(parent_raw));
7919 EXPECT_EQ(member_id, membership_id(child_raw));
7920 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7921 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7922 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7923
7924 expected.clear();
7925 expected.insert(child_raw);
7926 expected.insert(child_raw->mask_layer());
7927 actual.clear();
7928 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7929 EXPECT_EQ(expected, actual);
7930
7931 child_raw->TakeMaskLayer();
jaydasikad36e7fa2015-07-14 15:15:047932 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407933
7934 // Now everyone's a member!
7935 grand_parent_raw->SetDrawsContent(true);
7936 parent_raw->SetDrawsContent(true);
7937 child_raw->SetDrawsContent(true);
7938 grand_child1_raw->SetDrawsContent(true);
7939 grand_child2_raw->SetDrawsContent(true);
7940
7941 ExecuteCalculateDrawProperties(grand_parent_raw);
7942 member_id = render_surface_layer_list_count();
7943
7944 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
7945 EXPECT_EQ(member_id, membership_id(parent_raw));
7946 EXPECT_EQ(member_id, membership_id(child_raw));
7947 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
7948 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7949
7950 expected.clear();
7951 expected.insert(grand_parent_raw);
7952 expected.insert(parent_raw);
7953 expected.insert(child_raw);
7954 expected.insert(grand_child1_raw);
7955 expected.insert(grand_child2_raw);
7956
7957 actual.clear();
7958 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7959 EXPECT_EQ(expected, actual);
7960}
[email protected]18e69652014-06-13 12:50:587961
7962TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:167963 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]18e69652014-06-13 12:50:587964 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567965 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:487966 LayerTreeSettings settings = host()->settings();
enne637715732015-07-07 02:05:267967 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167968 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7969 &shared_bitmap_manager, &task_graph_runner);
[email protected]18e69652014-06-13 12:50:587970
7971 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7972 LayerImpl* root_layer = root.get();
7973 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
7974 LayerImpl* child1_layer = child1.get();
7975 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
7976 LayerImpl* child2_layer = child2.get();
7977
danakja04855a2015-11-18 20:39:107978 root->AddChild(std::move(child1));
7979 root->AddChild(std::move(child2));
weiliangcc154ce22015-12-09 03:39:267980 root->SetForceRenderSurface(true);
jaydasika0d98ba92015-11-17 05:17:287981 root->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587982
7983 gfx::Transform identity_matrix, scale_transform_child1,
7984 scale_transform_child2;
7985 scale_transform_child1.Scale(2, 3);
7986 scale_transform_child2.Scale(4, 5);
7987
awoloszyne83f28c2014-12-22 15:40:007988 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
7989 gfx::PointF(), gfx::Size(1, 1), true, false,
7990 true);
7991 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
jaydasika0d98ba92015-11-17 05:17:287992 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1),
7993 true, false, false);
[email protected]18e69652014-06-13 12:50:587994
danakja5a05ba02015-11-20 20:14:217995 child1_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4));
jaydasika0d98ba92015-11-17 05:17:287996 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587997
7998 scoped_ptr<LayerImpl> replica_layer =
7999 LayerImpl::Create(host_impl.active_tree(), 5);
8000 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
danakja04855a2015-11-18 20:39:108001 child1_layer->SetReplicaLayer(std::move(replica_layer));
awoloszyne83f28c2014-12-22 15:40:008002 child1_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588003
8004 ExecuteCalculateDrawProperties(root_layer);
8005
8006 TransformOperations scale;
8007 scale.AppendScale(5.f, 8.f, 3.f);
8008
loyso968163c92016-01-04 23:18:488009 if (layer_settings().use_compositor_animation_timelines) {
8010 scoped_refptr<AnimationTimeline> timeline =
8011 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
8012 host_impl.animation_host()->AddAnimationTimeline(timeline);
8013
8014 AddAnimatedTransformToLayerWithPlayer(child2_layer->id(), timeline, 1.0,
8015 TransformOperations(), scale);
8016 } else {
8017 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(),
8018 scale);
8019 }
8020
awoloszyne83f28c2014-12-22 15:40:008021 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
jaydasika0d98ba92015-11-17 05:17:288022 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1),
8023 true, false, false);
8024 child2_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:588025
jaydasika0d98ba92015-11-17 05:17:288026 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:588027 ExecuteCalculateDrawProperties(root_layer);
8028
enne637715732015-07-07 02:05:268029 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
8030 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
8031 EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale());
8032 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588033
8034 EXPECT_FLOAT_EQ(
8035 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8036 EXPECT_FLOAT_EQ(
8037 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8038 EXPECT_FLOAT_EQ(0.f,
8039 child1_layer->mask_layer()
8040 ->draw_properties()
8041 .maximum_animation_contents_scale);
8042 EXPECT_FLOAT_EQ(0.f,
8043 child1_layer->replica_layer()
8044 ->mask_layer()
8045 ->draw_properties()
8046 .maximum_animation_contents_scale);
8047 EXPECT_FLOAT_EQ(
8048 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8049
[email protected]18e69652014-06-13 12:50:588050 // Changing page-scale would affect ideal_contents_scale and
8051 // maximum_animation_contents_scale.
8052
8053 float page_scale_factor = 3.f;
8054 float device_scale_factor = 1.0f;
8055 std::vector<LayerImpl*> render_surface_layer_list;
8056 gfx::Size device_viewport_size =
8057 gfx::Size(root_layer->bounds().width() * device_scale_factor,
8058 root_layer->bounds().height() * device_scale_factor);
ajumad9432e32015-11-30 19:43:448059 root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]18e69652014-06-13 12:50:588060 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:448061 root_layer, device_viewport_size, &render_surface_layer_list,
8062 root_layer->layer_tree_impl()->current_render_surface_list_id());
[email protected]18e69652014-06-13 12:50:588063
8064 inputs.page_scale_factor = page_scale_factor;
8065 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:118066 inputs.page_scale_layer = root_layer;
[email protected]18e69652014-06-13 12:50:588067 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8068
enne637715732015-07-07 02:05:268069 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
8070 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
8071 EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588072 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:268073 9.f,
8074 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
8075 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588076
8077 EXPECT_FLOAT_EQ(
8078 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8079 EXPECT_FLOAT_EQ(
8080 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8081 EXPECT_FLOAT_EQ(0.f,
8082 child1_layer->mask_layer()
8083 ->draw_properties()
8084 .maximum_animation_contents_scale);
8085 EXPECT_FLOAT_EQ(0.f,
8086 child1_layer->replica_layer()
8087 ->mask_layer()
8088 ->draw_properties()
8089 .maximum_animation_contents_scale);
8090 EXPECT_FLOAT_EQ(
8091 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8092
[email protected]18e69652014-06-13 12:50:588093 // Changing device-scale would affect ideal_contents_scale and
8094 // maximum_animation_contents_scale.
8095
8096 device_scale_factor = 4.0f;
8097 inputs.device_scale_factor = device_scale_factor;
8098 inputs.can_adjust_raster_scales = true;
jaydasika0d98ba92015-11-17 05:17:288099 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:588100 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8101
enne637715732015-07-07 02:05:268102 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
8103 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
8104 EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588105 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:268106 36.f,
8107 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
8108 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588109
8110 EXPECT_FLOAT_EQ(
8111 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8112 EXPECT_FLOAT_EQ(
8113 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8114 EXPECT_FLOAT_EQ(0.f,
8115 child1_layer->mask_layer()
8116 ->draw_properties()
8117 .maximum_animation_contents_scale);
8118 EXPECT_FLOAT_EQ(0.f,
8119 child1_layer->replica_layer()
8120 ->mask_layer()
8121 ->draw_properties()
8122 .maximum_animation_contents_scale);
8123 EXPECT_FLOAT_EQ(
8124 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
[email protected]18e69652014-06-13 12:50:588125}
8126
danakjf6069db2014-09-13 00:46:478127TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
loysoa6edaaff2015-05-25 03:26:448128 scoped_refptr<Layer> root = Layer::Create(layer_settings());
danakjf6069db2014-09-13 00:46:478129 SetLayerPropertiesForTesting(root.get(),
8130 gfx::Transform(),
8131 gfx::Point3F(),
8132 gfx::PointF(),
8133 gfx::Size(768 / 2, 3000),
8134 true,
8135 false);
8136 root->SetIsDrawable(true);
8137
loysoa6edaaff2015-05-25 03:26:448138 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
danakjf6069db2014-09-13 00:46:478139 SetLayerPropertiesForTesting(clip.get(),
8140 gfx::Transform(),
8141 gfx::Point3F(),
8142 gfx::PointF(),
8143 gfx::Size(768 / 2, 10000),
8144 true,
8145 false);
8146 clip->SetMasksToBounds(true);
8147
loysoa6edaaff2015-05-25 03:26:448148 scoped_refptr<Layer> content = Layer::Create(layer_settings());
danakjf6069db2014-09-13 00:46:478149 SetLayerPropertiesForTesting(content.get(),
8150 gfx::Transform(),
8151 gfx::Point3F(),
8152 gfx::PointF(),
8153 gfx::Size(768 / 2, 10000),
8154 true,
8155 false);
8156 content->SetIsDrawable(true);
8157 content->SetForceRenderSurface(true);
8158
8159 root->AddChild(clip);
8160 clip->AddChild(content);
8161
ennea7b43c32015-06-18 20:01:338162 host()->SetRootLayer(root);
danakjf6069db2014-09-13 00:46:478163
8164 gfx::Size device_viewport_size(768, 582);
enne1e1008c2015-08-21 00:45:468165 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(host()->root_layer(),
8166 device_viewport_size);
danakjf6069db2014-09-13 00:46:478167 inputs.device_scale_factor = 2.f;
8168 inputs.page_scale_factor = 1.f;
enne6394d5b42015-05-26 22:23:118169 inputs.page_scale_layer = NULL;
danakjf6069db2014-09-13 00:46:478170 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8171
8172 // Layers in the root render surface have their visible content rect clipped
8173 // by the viewport.
weiliangc2d58b2c2015-07-29 00:42:438174 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
8175 root->visible_rect_from_property_trees());
danakjf6069db2014-09-13 00:46:478176
8177 // Layers drawing to a child render surface should still have their visible
8178 // content rect clipped by the viewport.
weiliangc2d58b2c2015-07-29 00:42:438179 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
8180 content->visible_rect_from_property_trees());
danakjf6069db2014-09-13 00:46:478181}
8182
timav599f4359d2014-12-05 00:12:228183TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:168184 FakeImplTaskRunnerProvider task_runner_provider;
timav599f4359d2014-12-05 00:12:228185 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:568186 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:168187 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:568188 &task_graph_runner);
timav599f4359d2014-12-05 00:12:228189
8190 // Set two layers: the root layer clips it's child,
8191 // the child draws its content.
8192
8193 gfx::Size root_size = gfx::Size(300, 500);
8194
8195 // Sublayer should be bigger than the root enlarged by bounds_delta.
8196 gfx::Size sublayer_size = gfx::Size(300, 1000);
8197
8198 // Device viewport accomidated the root and the top controls.
8199 gfx::Size device_viewport_size = gfx::Size(300, 600);
8200 gfx::Transform identity_matrix;
8201
miletus8bd08a622015-06-16 18:44:528202 host_impl.SetViewportSize(device_viewport_size);
timav599f4359d2014-12-05 00:12:228203 host_impl.active_tree()->SetRootLayer(
8204 LayerImpl::Create(host_impl.active_tree(), 1));
8205
8206 LayerImpl* root = host_impl.active_tree()->root_layer();
8207 SetLayerPropertiesForTesting(root,
8208 identity_matrix,
8209 gfx::Point3F(),
8210 gfx::PointF(),
8211 root_size,
8212 false,
awoloszyne83f28c2014-12-22 15:40:008213 false,
8214 true);
timav599f4359d2014-12-05 00:12:228215 root->SetMasksToBounds(true);
8216
8217 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
8218
8219 LayerImpl* sublayer = root->child_at(0);
8220 SetLayerPropertiesForTesting(sublayer,
8221 identity_matrix,
8222 gfx::Point3F(),
8223 gfx::PointF(),
8224 sublayer_size,
8225 false,
awoloszyne83f28c2014-12-22 15:40:008226 false,
timav599f4359d2014-12-05 00:12:228227 false);
timav599f4359d2014-12-05 00:12:228228 sublayer->SetDrawsContent(true);
8229
8230 LayerImplList layer_impl_list;
ajumad9432e32015-11-30 19:43:448231 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
timav599f4359d2014-12-05 00:12:228232 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:448233 root, device_viewport_size, &layer_impl_list,
8234 root->layer_tree_impl()->current_render_surface_list_id());
timav599f4359d2014-12-05 00:12:228235
8236 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
danakj64767d902015-06-19 00:10:438237 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228238
8239 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
timav599f4359d2014-12-05 00:12:228240 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8241
8242 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8243 root_size.height() + 50);
danakj64767d902015-06-19 00:10:438244 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228245}
8246
ajumadd2802e72015-06-30 20:28:298247TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
8248 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8249 scoped_refptr<Layer> inner_viewport_container_layer =
8250 Layer::Create(layer_settings());
8251 scoped_refptr<Layer> inner_viewport_scroll_layer =
8252 Layer::Create(layer_settings());
8253 scoped_refptr<Layer> outer_viewport_container_layer =
8254 Layer::Create(layer_settings());
8255 scoped_refptr<Layer> outer_viewport_scroll_layer =
8256 Layer::Create(layer_settings());
8257
8258 root->AddChild(inner_viewport_container_layer);
8259 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
8260 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
8261 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
8262
8263 inner_viewport_scroll_layer->SetScrollClipLayerId(
8264 inner_viewport_container_layer->id());
8265 outer_viewport_scroll_layer->SetScrollClipLayerId(
8266 outer_viewport_container_layer->id());
8267
8268 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8269 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8270
8271 host()->SetRootLayer(root);
8272 host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer,
8273 outer_viewport_scroll_layer);
8274
8275 scoped_refptr<Layer> fixed_to_inner = Layer::Create(layer_settings());
8276 scoped_refptr<Layer> fixed_to_outer = Layer::Create(layer_settings());
8277
8278 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
8279 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
8280
8281 LayerPositionConstraint fixed_to_right;
8282 fixed_to_right.set_is_fixed_position(true);
8283 fixed_to_right.set_is_fixed_to_right_edge(true);
8284
8285 fixed_to_inner->SetPositionConstraint(fixed_to_right);
8286 fixed_to_outer->SetPositionConstraint(fixed_to_right);
8287
8288 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8289
8290 TransformTree& transform_tree = host()->property_trees()->transform_tree;
8291 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8292 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8293
8294 LayerPositionConstraint fixed_to_left;
8295 fixed_to_left.set_is_fixed_position(true);
8296 fixed_to_inner->SetPositionConstraint(fixed_to_left);
8297
8298 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8299 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8300 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8301
8302 fixed_to_outer->SetPositionConstraint(fixed_to_left);
8303
8304 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8305 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8306 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8307}
8308
vollick7d83b452015-02-24 20:18:068309TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
8310 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:448311 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick7d83b452015-02-24 20:18:068312 scoped_refptr<LayerWithForcedDrawsContent> animated =
loysoa6edaaff2015-05-25 03:26:448313 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick7d83b452015-02-24 20:18:068314
8315 root->AddChild(animated);
8316
ennea7b43c32015-06-18 20:01:338317 host()->SetRootLayer(root);
vollick7d83b452015-02-24 20:18:068318
8319 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8320 gfx::PointF(), gfx::Size(100, 100), true, false);
8321 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
8322 gfx::PointF(), gfx::Size(20, 20), true, false);
8323
8324 root->SetMasksToBounds(true);
8325 root->SetForceRenderSurface(true);
8326 animated->SetOpacity(0.f);
8327
loyso968163c92016-01-04 23:18:488328 if (layer_settings().use_compositor_animation_timelines) {
8329 AddOpacityTransitionToLayerWithPlayer(animated->id(), timeline(), 10.0, 0.f,
8330 1.f, false);
8331 } else {
8332 AddOpacityTransitionToController(animated->layer_animation_controller(),
8333 10.0, 0.f, 1.f, false);
8334 }
enne601f2ef12015-05-19 18:20:178335 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick7d83b452015-02-24 20:18:068336
8337 EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty());
8338}
8339
ajumaa92fdc12015-03-31 22:47:418340TEST_F(LayerTreeHostCommonTest,
8341 VisibleContentRectForAnimatedLayerWithSingularTransform) {
8342 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:448343 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8344 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
ajumaa92fdc12015-03-31 22:47:418345 scoped_refptr<LayerWithForcedDrawsContent> animated =
loysoa6edaaff2015-05-25 03:26:448346 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaa92fdc12015-03-31 22:47:418347 scoped_refptr<LayerWithForcedDrawsContent> surface =
loysoa6edaaff2015-05-25 03:26:448348 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaa92fdc12015-03-31 22:47:418349 scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation =
loysoa6edaaff2015-05-25 03:26:448350 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaa92fdc12015-03-31 22:47:418351
8352 root->AddChild(clip);
8353 clip->AddChild(animated);
8354 animated->AddChild(surface);
8355 surface->AddChild(descendant_of_animation);
8356
8357 clip->SetMasksToBounds(true);
8358 surface->SetForceRenderSurface(true);
8359
ennea7b43c32015-06-18 20:01:338360 host()->SetRootLayer(root);
ajumaa92fdc12015-03-31 22:47:418361
8362 gfx::Transform uninvertible_matrix;
8363 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
8364
8365 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8366 gfx::PointF(), gfx::Size(100, 100), true, false);
8367 SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(),
8368 gfx::PointF(), gfx::Size(10, 10), true, false);
8369 SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix,
8370 gfx::Point3F(), gfx::PointF(),
8371 gfx::Size(120, 120), true, false);
8372 SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(),
8373 gfx::PointF(), gfx::Size(100, 100), true, false);
8374 SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix,
8375 gfx::Point3F(), gfx::PointF(),
8376 gfx::Size(200, 200), true, false);
8377
8378 TransformOperations start_transform_operations;
8379 start_transform_operations.AppendMatrix(uninvertible_matrix);
8380 TransformOperations end_transform_operations;
8381
loyso968163c92016-01-04 23:18:488382 if (layer_settings().use_compositor_animation_timelines) {
8383 AddAnimatedTransformToLayerWithPlayer(animated->id(), timeline(), 10.0,
8384 start_transform_operations,
8385 end_transform_operations);
8386 } else {
8387 AddAnimatedTransformToLayer(animated.get(), 10.0,
8388 start_transform_operations,
8389 end_transform_operations);
8390 }
enne601f2ef12015-05-19 18:20:178391 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:418392
8393 // The animated layer has a singular transform and maps to a non-empty rect in
8394 // clipped target space, so is treated as fully visible.
8395 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_rect_from_property_trees());
8396
8397 // The singular transform on |animated| is flattened when inherited by
8398 // |surface|, and this happens to make it invertible.
8399 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_rect_from_property_trees());
8400 EXPECT_EQ(gfx::Rect(2, 2),
8401 descendant_of_animation->visible_rect_from_property_trees());
8402
8403 gfx::Transform zero_matrix;
8404 zero_matrix.Scale3d(0.f, 0.f, 0.f);
8405 SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(),
8406 gfx::PointF(), gfx::Size(120, 120), true, false);
8407
enne601f2ef12015-05-19 18:20:178408 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:418409
8410 // The animated layer maps to the empty rect in clipped target space, so is
8411 // treated as having an empty visible rect.
8412 EXPECT_EQ(gfx::Rect(), animated->visible_rect_from_property_trees());
8413
8414 // This time, flattening does not make |animated|'s transform invertible. This
8415 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:348416 // |surface| and layers that draw into it as having empty visible rect.
8417 EXPECT_EQ(gfx::Rect(), surface->visible_rect_from_property_trees());
8418 EXPECT_EQ(gfx::Rect(),
ajumaa92fdc12015-03-31 22:47:418419 descendant_of_animation->visible_rect_from_property_trees());
8420}
8421
enne92f2f6d92015-02-25 23:13:318422// Verify that having an animated filter (but no current filter, as these
8423// are mutually exclusive) correctly creates a render surface.
8424TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
loysoa6edaaff2015-05-25 03:26:448425 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8426 scoped_refptr<Layer> child = Layer::Create(layer_settings());
8427 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
enne92f2f6d92015-02-25 23:13:318428 root->AddChild(child);
8429 child->AddChild(grandchild);
8430
8431 gfx::Transform identity_transform;
8432 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8433 gfx::PointF(), gfx::Size(50, 50), true, false);
8434 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8435 gfx::PointF(), gfx::Size(50, 50), true, false);
8436 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8437 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
8438 true, false);
ennea7b43c32015-06-18 20:01:338439 host()->SetRootLayer(root);
enne92f2f6d92015-02-25 23:13:318440
loyso968163c92016-01-04 23:18:488441 if (layer_settings().use_compositor_animation_timelines) {
8442 AddAnimatedFilterToLayerWithPlayer(child->id(), timeline(), 10.0, 0.1f,
8443 0.2f);
8444 } else {
8445 AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f);
8446 }
enne92f2f6d92015-02-25 23:13:318447 ExecuteCalculateDrawProperties(root.get());
8448
ennec1332992015-08-24 19:45:098449 EXPECT_TRUE(root->has_render_surface());
8450 EXPECT_TRUE(child->has_render_surface());
8451 EXPECT_FALSE(grandchild->has_render_surface());
enne92f2f6d92015-02-25 23:13:318452
8453 EXPECT_TRUE(root->filters().IsEmpty());
8454 EXPECT_TRUE(child->filters().IsEmpty());
8455 EXPECT_TRUE(grandchild->filters().IsEmpty());
8456
8457 EXPECT_FALSE(root->FilterIsAnimating());
8458 EXPECT_TRUE(child->FilterIsAnimating());
8459 EXPECT_FALSE(grandchild->FilterIsAnimating());
8460}
8461
ajuma315a4782015-07-24 21:16:348462// Verify that having a filter animation with a delayed start time creates a
8463// render surface.
8464TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
8465 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8466 scoped_refptr<Layer> child = Layer::Create(layer_settings());
8467 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
8468 root->AddChild(child);
8469 child->AddChild(grandchild);
8470
8471 gfx::Transform identity_transform;
8472 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8473 gfx::PointF(), gfx::Size(50, 50), true, false);
8474 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8475 gfx::PointF(), gfx::Size(50, 50), true, false);
8476 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8477 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
8478 true, false);
8479 host()->SetRootLayer(root);
8480
8481 scoped_ptr<KeyframedFilterAnimationCurve> curve(
8482 KeyframedFilterAnimationCurve::Create());
8483 FilterOperations start_filters;
8484 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
8485 FilterOperations end_filters;
8486 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
8487 curve->AddKeyframe(
8488 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
8489 curve->AddKeyframe(FilterKeyframe::Create(
8490 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
8491 scoped_ptr<Animation> animation =
danakja04855a2015-11-18 20:39:108492 Animation::Create(std::move(curve), 0, 1, Animation::FILTER);
ajuma315a4782015-07-24 21:16:348493 animation->set_fill_mode(Animation::FILL_MODE_NONE);
8494 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
ajuma315a4782015-07-24 21:16:348495
loyso968163c92016-01-04 23:18:488496 if (layer_settings().use_compositor_animation_timelines) {
8497 AddAnimationToLayerWithPlayer(child->id(), timeline(),
8498 std::move(animation));
8499 } else {
8500 child->layer_animation_controller()->AddAnimation(std::move(animation));
8501 }
ajuma315a4782015-07-24 21:16:348502 ExecuteCalculateDrawProperties(root.get());
8503
ennec1332992015-08-24 19:45:098504 EXPECT_TRUE(root->has_render_surface());
8505 EXPECT_TRUE(child->has_render_surface());
8506 EXPECT_FALSE(grandchild->has_render_surface());
ajuma315a4782015-07-24 21:16:348507
8508 EXPECT_TRUE(root->filters().IsEmpty());
8509 EXPECT_TRUE(child->filters().IsEmpty());
8510 EXPECT_TRUE(grandchild->filters().IsEmpty());
8511
8512 EXPECT_FALSE(root->FilterIsAnimating());
8513 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
8514 EXPECT_FALSE(child->FilterIsAnimating());
8515 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
8516 EXPECT_FALSE(grandchild->FilterIsAnimating());
8517 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
8518}
8519
vollick0120eb22015-03-02 03:07:348520// Ensures that the property tree code accounts for offsets between fixed
8521// position layers and their respective containers.
8522TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
loysoa6edaaff2015-05-25 03:26:448523 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8524 scoped_refptr<Layer> child = Layer::Create(layer_settings());
vollick0120eb22015-03-02 03:07:348525 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loysoa6edaaff2015-05-25 03:26:448526 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick0120eb22015-03-02 03:07:348527
8528 root->AddChild(child);
8529 child->AddChild(grandchild);
8530
8531 gfx::Transform identity_transform;
8532 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8533 gfx::PointF(), gfx::Size(50, 50), true, false);
8534 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8535 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
8536 false);
8537 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8538 gfx::Point3F(), gfx::PointF(-1000, -1000),
8539 gfx::Size(50, 50), true, false);
8540
8541 root->SetMasksToBounds(true);
8542 root->SetIsContainerForFixedPositionLayers(true);
8543 LayerPositionConstraint constraint;
8544 constraint.set_is_fixed_position(true);
8545 grandchild->SetPositionConstraint(constraint);
8546
8547 root->SetIsContainerForFixedPositionLayers(true);
8548
ennea7b43c32015-06-18 20:01:338549 host()->SetRootLayer(root);
vollick0120eb22015-03-02 03:07:348550
enne601f2ef12015-05-19 18:20:178551 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick0120eb22015-03-02 03:07:348552
8553 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
8554 grandchild->visible_rect_from_property_trees());
8555}
8556
ajuma0178b522015-07-02 21:08:418557// Ensures that the property tree code accounts for offsets between fixed
8558// position containers and their transform tree parents, when a fixed position
8559// layer's container is its layer tree parent, but this parent doesn't have its
8560// own transform tree node.
8561TEST_F(LayerTreeHostCommonTest,
8562 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
8563 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8564 scoped_refptr<Layer> child = Layer::Create(layer_settings());
8565 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
8566 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8567
8568 root->AddChild(child);
8569 child->AddChild(grandchild);
8570
8571 gfx::Transform identity_transform;
8572 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8573 gfx::PointF(), gfx::Size(50, 50), true, false);
8574 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8575 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
8576 false);
8577 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8578 gfx::Point3F(), gfx::PointF(-1000, -1000),
8579 gfx::Size(50, 50), true, false);
8580
8581 root->SetMasksToBounds(true);
8582 child->SetIsContainerForFixedPositionLayers(true);
8583 LayerPositionConstraint constraint;
8584 constraint.set_is_fixed_position(true);
8585 grandchild->SetPositionConstraint(constraint);
8586
8587 root->SetIsContainerForFixedPositionLayers(true);
8588
8589 host()->SetRootLayer(root);
8590
8591 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8592
8593 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
8594 grandchild->visible_rect_from_property_trees());
8595}
8596
vollick67394b42015-03-10 00:22:308597TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) {
8598 // In the following layer tree, the layer |box|'s render target is |surface|.
8599 // |surface| also creates a transform node. We want to combine clips for |box|
8600 // in the space of its target (i.e., |surface|), not its target's target. This
8601 // test ensures that happens.
8602
8603 gfx::Transform rotate;
8604 rotate.Rotate(5);
8605 gfx::Transform identity;
8606
loysoa6edaaff2015-05-25 03:26:448607 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:308608 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8609 gfx::PointF(), gfx::Size(2500, 1500), true,
8610 false);
8611
loysoa6edaaff2015-05-25 03:26:448612 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:308613 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8614 gfx::PointF(), gfx::Size(2500, 1500), true,
8615 false);
8616 frame_clip->SetMasksToBounds(true);
8617
loysoa6edaaff2015-05-25 03:26:448618 scoped_refptr<Layer> rotated = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:308619 SetLayerPropertiesForTesting(rotated.get(), rotate,
8620 gfx::Point3F(1250, 250, 0), gfx::PointF(),
8621 gfx::Size(2500, 500), true, false);
8622
loysoa6edaaff2015-05-25 03:26:448623 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:308624 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(),
8625 gfx::PointF(), gfx::Size(2500, 500), true,
8626 false);
8627 surface->SetOpacity(0.5);
8628
8629 scoped_refptr<LayerWithForcedDrawsContent> container =
loysoa6edaaff2015-05-25 03:26:448630 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick67394b42015-03-10 00:22:308631 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(),
8632 gfx::PointF(), gfx::Size(300, 300), true, false);
8633
8634 scoped_refptr<LayerWithForcedDrawsContent> box =
loysoa6edaaff2015-05-25 03:26:448635 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick67394b42015-03-10 00:22:308636 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(),
8637 gfx::PointF(), gfx::Size(100, 100), true, false);
8638
8639 root->AddChild(frame_clip);
8640 frame_clip->AddChild(rotated);
8641 rotated->AddChild(surface);
8642 surface->AddChild(container);
8643 surface->AddChild(box);
8644
ennea7b43c32015-06-18 20:01:338645 host()->SetRootLayer(root);
vollick67394b42015-03-10 00:22:308646
8647 ExecuteCalculateDrawProperties(root.get());
8648}
8649
vollick8c824742015-03-20 22:21:088650TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
8651 gfx::Transform identity;
8652 gfx::Transform translate_z;
8653 translate_z.Translate3d(0, 0, 10);
8654
loysoa6edaaff2015-05-25 03:26:448655 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick8c824742015-03-20 22:21:088656 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8657 gfx::PointF(), gfx::Size(800, 800), true, false);
8658 root->SetIsContainerForFixedPositionLayers(true);
8659
loysoa6edaaff2015-05-25 03:26:448660 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollick8c824742015-03-20 22:21:088661 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
8662 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8663 false);
8664 frame_clip->SetMasksToBounds(true);
8665
8666 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:448667 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick8c824742015-03-20 22:21:088668 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8669 gfx::PointF(), gfx::Size(1000, 1000), true,
8670 false);
8671
8672 LayerPositionConstraint constraint;
8673 constraint.set_is_fixed_position(true);
8674 fixed->SetPositionConstraint(constraint);
8675
8676 root->AddChild(frame_clip);
8677 frame_clip->AddChild(fixed);
8678
ennea7b43c32015-06-18 20:01:338679 host()->SetRootLayer(root);
vollick8c824742015-03-20 22:21:088680
enne601f2ef12015-05-19 18:20:178681 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick8c824742015-03-20 22:21:088682
8683 gfx::Rect expected(0, 0, 100, 100);
8684 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
8685}
8686
vollickf6281c42015-03-30 21:44:418687TEST_F(LayerTreeHostCommonTest,
8688 PropertyTreesAccountForScrollCompensationAdjustment) {
8689 gfx::Transform identity;
8690 gfx::Transform translate_z;
8691 translate_z.Translate3d(0, 0, 10);
8692
loysoa6edaaff2015-05-25 03:26:448693 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollickf6281c42015-03-30 21:44:418694 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8695 gfx::PointF(), gfx::Size(800, 800), true, false);
8696 root->SetIsContainerForFixedPositionLayers(true);
8697
loysoa6edaaff2015-05-25 03:26:448698 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollickf6281c42015-03-30 21:44:418699 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
8700 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8701 false);
8702 frame_clip->SetMasksToBounds(true);
8703
8704 scoped_refptr<LayerWithForcedDrawsContent> scroller =
loysoa6edaaff2015-05-25 03:26:448705 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollickf6281c42015-03-30 21:44:418706 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
8707 gfx::PointF(), gfx::Size(1000, 1000), true,
8708 false);
8709
8710 scroller->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f, 0.7f));
8711 scroller->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
8712 scroller->SetScrollClipLayerId(frame_clip->id());
8713
8714 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:448715 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollickf6281c42015-03-30 21:44:418716 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8717 gfx::PointF(), gfx::Size(50, 50), true, false);
8718
8719 LayerPositionConstraint constraint;
8720 constraint.set_is_fixed_position(true);
8721 fixed->SetPositionConstraint(constraint);
8722
8723 scoped_refptr<LayerWithForcedDrawsContent> fixed_child =
loysoa6edaaff2015-05-25 03:26:448724 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollickf6281c42015-03-30 21:44:418725 SetLayerPropertiesForTesting(fixed_child.get(), identity, gfx::Point3F(),
8726 gfx::PointF(), gfx::Size(10, 10), true, false);
8727
8728 fixed_child->SetPositionConstraint(constraint);
8729
8730 root->AddChild(frame_clip);
8731 frame_clip->AddChild(scroller);
8732 scroller->AddChild(fixed);
8733 fixed->AddChild(fixed_child);
8734
ennea7b43c32015-06-18 20:01:338735 host()->SetRootLayer(root);
vollickf6281c42015-03-30 21:44:418736
enne601f2ef12015-05-19 18:20:178737 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollickf6281c42015-03-30 21:44:418738
8739 gfx::Rect expected(0, 0, 50, 50);
8740 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
8741
8742 expected = gfx::Rect(0, 0, 10, 10);
8743 EXPECT_EQ(expected, fixed_child->visible_rect_from_property_trees());
8744}
8745
vollick06ca3e832015-03-31 19:37:128746TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
8747 gfx::Transform identity;
8748
loysoa6edaaff2015-05-25 03:26:448749 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick06ca3e832015-03-31 19:37:128750 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8751 gfx::PointF(), gfx::Size(800, 800), true, false);
8752 root->SetIsContainerForFixedPositionLayers(true);
8753
loysoa6edaaff2015-05-25 03:26:448754 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollick06ca3e832015-03-31 19:37:128755 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8756 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8757 false);
8758 frame_clip->SetMasksToBounds(true);
8759
8760 scoped_refptr<LayerWithForcedDrawsContent> scroller =
loysoa6edaaff2015-05-25 03:26:448761 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick06ca3e832015-03-31 19:37:128762 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
8763 gfx::PointF(), gfx::Size(1000, 1000), true,
8764 false);
8765
8766 scroller->SetScrollOffset(gfx::ScrollOffset(100, 100));
8767 scroller->SetScrollClipLayerId(frame_clip->id());
8768
8769 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:448770 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick06ca3e832015-03-31 19:37:128771 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8772 gfx::PointF(100, 100), gfx::Size(50, 50), true,
8773 false);
8774
8775 LayerPositionConstraint constraint;
8776 constraint.set_is_fixed_position(true);
8777 fixed->SetPositionConstraint(constraint);
8778 fixed->SetForceRenderSurface(true);
8779 fixed->SetMasksToBounds(true);
8780
8781 root->AddChild(frame_clip);
8782 frame_clip->AddChild(scroller);
8783 scroller->AddChild(fixed);
8784
ennea7b43c32015-06-18 20:01:338785 host()->SetRootLayer(root);
vollick06ca3e832015-03-31 19:37:128786
enne601f2ef12015-05-19 18:20:178787 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick06ca3e832015-03-31 19:37:128788
8789 gfx::Rect expected(0, 0, 50, 50);
8790 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
8791}
8792
vollick5057e1e2015-04-17 19:12:328793TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
8794 gfx::Transform identity;
8795 gfx::Transform translate;
8796 gfx::Transform rotate;
8797
8798 translate.Translate(10, 10);
8799 rotate.Rotate(45);
8800
loysoa6edaaff2015-05-25 03:26:448801 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick5057e1e2015-04-17 19:12:328802 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8803 gfx::PointF(), gfx::Size(800, 800), true, false);
8804 root->SetIsContainerForFixedPositionLayers(true);
8805
ennea7b43c32015-06-18 20:01:338806 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:328807
enne601f2ef12015-05-19 18:20:178808 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ennea7b43c32015-06-18 20:01:338809 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328810
8811 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:338812 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328813
8814 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:338815 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328816}
8817
ajumab0e0c1c2015-04-23 00:29:238818TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
loysoa6edaaff2015-05-25 03:26:448819 scoped_refptr<Layer> root = Layer::Create(layer_settings());
ajumab0e0c1c2015-04-23 00:29:238820 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:448821 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumab0e0c1c2015-04-23 00:29:238822 root->AddChild(child);
8823
ennea7b43c32015-06-18 20:01:338824 host()->SetRootLayer(root);
ajumab0e0c1c2015-04-23 00:29:238825
8826 gfx::Transform identity_matrix;
8827 gfx::Transform scale_matrix;
8828 scale_matrix.Scale(2.f, 2.f);
8829 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8830 gfx::PointF(), gfx::Size(100, 100), true, false);
8831 SetLayerPropertiesForTesting(child.get(), scale_matrix, gfx::Point3F(),
8832 gfx::PointF(), gfx::Size(10, 10), true, false);
8833
enne601f2ef12015-05-19 18:20:178834 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumab0e0c1c2015-04-23 00:29:238835 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
8836
8837 child->SetTransformOrigin(gfx::Point3F(10.f, 10.f, 10.f));
8838
enne601f2ef12015-05-19 18:20:178839 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumab0e0c1c2015-04-23 00:29:238840 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_rect_from_property_trees());
8841}
8842
ajumaf09db8962015-04-24 21:55:348843TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
loysoa6edaaff2015-05-25 03:26:448844 scoped_refptr<Layer> root = Layer::Create(layer_settings());
ajumaf09db8962015-04-24 21:55:348845 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
loysoa6edaaff2015-05-25 03:26:448846 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaf09db8962015-04-24 21:55:348847 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
loysoa6edaaff2015-05-25 03:26:448848 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaf09db8962015-04-24 21:55:348849
8850 root->AddChild(scroll_child);
8851 root->AddChild(scroll_parent);
8852 scroll_child->SetScrollParent(scroll_parent.get());
8853 scroll_parent->SetScrollClipLayerId(root->id());
8854
ennea7b43c32015-06-18 20:01:338855 host()->SetRootLayer(root);
ajumaf09db8962015-04-24 21:55:348856
8857 gfx::Transform identity_transform;
8858 gfx::Transform scale;
8859 scale.Scale(2.f, 2.f);
8860 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8861 gfx::PointF(), gfx::Size(50, 50), true, false);
8862 SetLayerPropertiesForTesting(scroll_child.get(), scale, gfx::Point3F(),
8863 gfx::PointF(), gfx::Size(40, 40), true, false);
8864 SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform,
8865 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
8866 true, false);
8867
enne601f2ef12015-05-19 18:20:178868 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaf09db8962015-04-24 21:55:348869 EXPECT_EQ(gfx::Rect(25, 25),
8870 scroll_child->visible_rect_from_property_trees());
8871
8872 scroll_child->SetPosition(gfx::PointF(0, -10.f));
8873 scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f));
enne601f2ef12015-05-19 18:20:178874 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaf09db8962015-04-24 21:55:348875 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
8876 scroll_child->visible_rect_from_property_trees());
8877}
8878
vollick2175fae82015-04-27 21:18:128879static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
8880}
8881
sunxded58688e2016-01-11 21:01:028882TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) {
8883 // If the layer has a node in effect_tree, the return value of
8884 // num_copy_requests_in_target_subtree() must be equal to the actual number
8885 // of copy requests in the sub-layer_tree; Otherwise, the number is expected
8886 // to be the value of its nearest ancestor that owns an effect node and
8887 // greater than or equal to the actual number of copy requests in the
8888 // sub-layer_tree.
8889
8890 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8891 scoped_refptr<Layer> child1 = Layer::Create(layer_settings());
8892 scoped_refptr<Layer> child2 = Layer::Create(layer_settings());
8893 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
8894 scoped_refptr<Layer> greatgrandchild = Layer::Create(layer_settings());
8895
8896 root->AddChild(child1);
8897 root->AddChild(child2);
8898 child1->AddChild(grandchild);
8899 grandchild->AddChild(greatgrandchild);
8900 host()->SetRootLayer(root);
8901
8902 child1->RequestCopyOfOutput(
8903 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8904 greatgrandchild->RequestCopyOfOutput(
8905 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8906 child2->SetOpacity(0.f);
8907 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8908
8909 EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2);
8910 EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2);
8911 EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0);
8912 EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2);
8913 EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1);
8914}
8915
vollick2175fae82015-04-27 21:18:128916TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
8917 gfx::Transform identity;
loysoa6edaaff2015-05-25 03:26:448918 scoped_refptr<Layer> root = Layer::Create(layer_settings());
chrishtr01539b802015-11-24 08:11:328919 FakeContentLayerClient client;
8920 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:128921 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:448922 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick2175fae82015-04-27 21:18:128923 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loysoa6edaaff2015-05-25 03:26:448924 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
danakj4e95f7632015-06-05 19:46:258925 scoped_refptr<FakePictureLayer> greatgrandchild(
8926 FakePictureLayer::Create(layer_settings(), &client));
vollick2175fae82015-04-27 21:18:128927 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8928 gfx::PointF(), gfx::Size(100, 100), true, false);
8929 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8930 gfx::PointF(), gfx::Size(10, 10), true, false);
8931 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8932 gfx::PointF(), gfx::Size(10, 10), true, false);
8933 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
8934 gfx::PointF(), gfx::Size(10, 10), true, false);
8935
8936 root->AddChild(child);
8937 child->AddChild(grandchild);
8938 grandchild->AddChild(greatgrandchild);
8939
ennea7b43c32015-06-18 20:01:338940 host()->SetRootLayer(root);
vollick2175fae82015-04-27 21:18:128941
8942 // Check the non-skipped case.
enne601f2ef12015-05-19 18:20:178943 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128944 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
8945
8946 // Now we will reset the visible rect from property trees for the grandchild,
8947 // and we will configure |child| in several ways that should force the subtree
8948 // to be skipped. The visible content rect for |grandchild| should, therefore,
8949 // remain empty.
8950 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
8951 gfx::Transform singular;
8952 singular.matrix().set(0, 0, 0);
8953
8954 child->SetTransform(singular);
enne601f2ef12015-05-19 18:20:178955 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128956 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8957 child->SetTransform(identity);
8958
8959 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:178960 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128961 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8962 child->SetHideLayerAndSubtree(false);
8963
ajuma315a4782015-07-24 21:16:348964 gfx::Transform zero_z_scale;
8965 zero_z_scale.Scale3d(1, 1, 0);
8966 child->SetTransform(zero_z_scale);
8967
8968 // Add a transform animation with a start delay. Now, even though |child| has
8969 // a singular transform, the subtree should still get processed.
8970 int animation_id = 0;
8971 scoped_ptr<Animation> animation = Animation::Create(
danakja5a05ba02015-11-20 20:14:218972 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
ajuma315a4782015-07-24 21:16:348973 animation_id, 1, Animation::TRANSFORM);
8974 animation->set_fill_mode(Animation::FILL_MODE_NONE);
8975 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso968163c92016-01-04 23:18:488976 if (layer_settings().use_compositor_animation_timelines) {
8977 AddAnimationToLayerWithPlayer(child->id(), timeline(),
8978 std::move(animation));
8979 } else {
8980 child->AddAnimation(std::move(animation));
8981 }
ajuma315a4782015-07-24 21:16:348982 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8983 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
8984 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
8985
loyso968163c92016-01-04 23:18:488986 if (layer_settings().use_compositor_animation_timelines) {
8987 RemoveAnimationFromLayerWithExistingPlayer(child->id(), timeline(),
8988 animation_id);
8989 } else {
8990 child->RemoveAnimation(animation_id);
8991 }
ajuma315a4782015-07-24 21:16:348992 child->SetTransform(identity);
vollick2175fae82015-04-27 21:18:128993 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:178994 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128995 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8996
8997 // Now, even though child has zero opacity, we will configure |grandchild| and
8998 // |greatgrandchild| in several ways that should force the subtree to be
8999 // processed anyhow.
jaydasika86654512016-01-27 17:05:079000 grandchild->RequestCopyOfOutput(
vollick2175fae82015-04-27 21:18:129001 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
enne601f2ef12015-05-19 18:20:179002 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129003 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
jaydasika86654512016-01-27 17:05:079004 greatgrandchild->set_visible_rect_from_property_trees(gfx::Rect());
ajuma315a4782015-07-24 21:16:349005
9006 // Add an opacity animation with a start delay.
9007 animation_id = 1;
9008 animation = Animation::Create(
danakja5a05ba02015-11-20 20:14:219009 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
ajuma315a4782015-07-24 21:16:349010 animation_id, 1, Animation::OPACITY);
9011 animation->set_fill_mode(Animation::FILL_MODE_NONE);
9012 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso968163c92016-01-04 23:18:489013 if (layer_settings().use_compositor_animation_timelines) {
9014 AddAnimationToLayerWithExistingPlayer(child->id(), timeline(),
9015 std::move(animation));
9016 } else {
9017 child->AddAnimation(std::move(animation));
9018 }
ajuma315a4782015-07-24 21:16:349019 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9020 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
vollick2175fae82015-04-27 21:18:129021}
9022
9023TEST_F(LayerTreeHostCommonTest, SkippingSubtreeImpl) {
khushalsagarb64b360d2015-10-21 19:25:169024 FakeImplTaskRunnerProvider task_runner_provider;
vollick2175fae82015-04-27 21:18:129025 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:569026 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:169027 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:569028 &task_graph_runner);
vollick2175fae82015-04-27 21:18:129029
9030 gfx::Transform identity;
9031 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9032 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
9033 scoped_ptr<LayerImpl> grandchild =
9034 LayerImpl::Create(host_impl.active_tree(), 3);
9035
danakj4e95f7632015-06-05 19:46:259036 scoped_ptr<FakePictureLayerImpl> greatgrandchild(
9037 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:129038
9039 child->SetDrawsContent(true);
9040 grandchild->SetDrawsContent(true);
9041 greatgrandchild->SetDrawsContent(true);
9042
9043 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9044 gfx::PointF(), gfx::Size(100, 100), true, false,
9045 true);
9046 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9047 gfx::PointF(), gfx::Size(10, 10), true, false,
9048 false);
9049 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
9050 gfx::PointF(), gfx::Size(10, 10), true, false,
9051 false);
vollick2175fae82015-04-27 21:18:129052
9053 LayerImpl* child_ptr = child.get();
9054 LayerImpl* grandchild_ptr = grandchild.get();
vollick2175fae82015-04-27 21:18:129055
danakja04855a2015-11-18 20:39:109056 child->AddChild(std::move(grandchild));
9057 root->AddChild(std::move(child));
vollick2175fae82015-04-27 21:18:129058
9059 // Check the non-skipped case.
enne601f2ef12015-05-19 18:20:179060 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129061 EXPECT_EQ(gfx::Rect(10, 10),
9062 grandchild_ptr->visible_rect_from_property_trees());
9063
9064 // Now we will reset the visible rect from property trees for the grandchild,
9065 // and we will configure |child| in several ways that should force the subtree
9066 // to be skipped. The visible content rect for |grandchild| should, therefore,
9067 // remain empty.
9068 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
9069 gfx::Transform singular;
9070 singular.matrix().set(0, 0, 0);
9071
9072 child_ptr->SetTransform(singular);
enne601f2ef12015-05-19 18:20:179073 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129074 EXPECT_EQ(gfx::Rect(0, 0),
9075 grandchild_ptr->visible_rect_from_property_trees());
9076 child_ptr->SetTransform(identity);
9077
9078 child_ptr->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:179079 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129080 EXPECT_EQ(gfx::Rect(0, 0),
9081 grandchild_ptr->visible_rect_from_property_trees());
9082 child_ptr->SetHideLayerAndSubtree(false);
9083
9084 child_ptr->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:179085 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129086 EXPECT_EQ(gfx::Rect(0, 0),
9087 grandchild_ptr->visible_rect_from_property_trees());
9088
9089 // Now, even though child has zero opacity, we will configure |grandchild| and
9090 // |greatgrandchild| in several ways that should force the subtree to be
9091 // processed anyhow.
vmpstra370ef52015-11-18 10:41:289092 std::vector<scoped_ptr<CopyOutputRequest>> requests;
vollick2175fae82015-04-27 21:18:129093 requests.push_back(CopyOutputRequest::CreateEmptyRequest());
9094
jaydasika86654512016-01-27 17:05:079095 grandchild_ptr->PassCopyRequests(&requests);
sunxded58688e2016-01-11 21:01:029096 root.get()->layer_tree_impl()->property_trees()->needs_rebuild = true;
enne601f2ef12015-05-19 18:20:179097 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129098 EXPECT_EQ(gfx::Rect(10, 10),
9099 grandchild_ptr->visible_rect_from_property_trees());
9100}
9101
9102TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
9103 gfx::Transform identity;
loysoa6edaaff2015-05-25 03:26:449104 scoped_refptr<Layer> root = Layer::Create(layer_settings());
chrishtr01539b802015-11-24 08:11:329105 FakeContentLayerClient client;
9106 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:129107 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:449108 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick2175fae82015-04-27 21:18:129109 SetLayerPropertiesForTesting(root.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(10, 10), true, false);
9113 root->AddChild(child);
9114
ennea7b43c32015-06-18 20:01:339115 host()->SetRootLayer(root);
vollick2175fae82015-04-27 21:18:129116
enne601f2ef12015-05-19 18:20:179117 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129118 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
9119 child->set_visible_rect_from_property_trees(gfx::Rect());
9120
9121 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:179122 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129123 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9124 child->SetHideLayerAndSubtree(false);
9125
9126 child->SetBounds(gfx::Size());
enne601f2ef12015-05-19 18:20:179127 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129128 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9129 child->SetBounds(gfx::Size(10, 10));
9130
9131 gfx::Transform rotate;
9132 child->SetDoubleSided(false);
9133 rotate.RotateAboutXAxis(180.f);
9134 child->SetTransform(rotate);
enne601f2ef12015-05-19 18:20:179135 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129136 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9137 child->SetDoubleSided(true);
9138 child->SetTransform(identity);
9139
9140 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:179141 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129142 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9143}
9144
jaydasika3d10aa62015-05-06 17:50:449145TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
9146 // Ensure that the treewalk in LayerTreeHostCommom::
9147 // PreCalculateMetaInformation happens when its required.
loysoa6edaaff2015-05-25 03:26:449148 scoped_refptr<Layer> root = Layer::Create(layer_settings());
9149 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
9150 scoped_refptr<Layer> child = Layer::Create(layer_settings());
jaydasika3d10aa62015-05-06 17:50:449151
9152 root->AddChild(parent);
9153 parent->AddChild(child);
9154
9155 child->SetClipParent(root.get());
9156
9157 gfx::Transform identity;
9158
9159 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9160 gfx::PointF(), gfx::Size(100, 100), true, false);
9161 SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(),
9162 gfx::PointF(), gfx::Size(100, 100), true, false);
9163 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9164 gfx::PointF(), gfx::Size(100, 100), true, false);
9165
ennea7b43c32015-06-18 20:01:339166 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:449167
jaydasika3d10aa62015-05-06 17:50:449168 child->RequestCopyOfOutput(
9169 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
sunxded58688e2016-01-11 21:01:029170
9171 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9172 EXPECT_EQ(parent->num_unclipped_descendants(), 1u);
9173
9174 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
9175 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9176 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika3d10aa62015-05-06 17:50:449177}
9178
9179TEST_F(LayerTreeHostCommonTest, InputHandlersRecursiveUpdateTest) {
9180 // Ensure that the treewalk in LayertreeHostCommon::
9181 // PreCalculateMetaInformation updates input handlers correctly.
ennecf94ff0c2015-08-18 22:58:059182 LayerImpl* root = root_layer();
9183 LayerImpl* child = AddChild<LayerImpl>(root);
jaydasika3d10aa62015-05-06 17:50:449184
9185 gfx::Transform identity;
9186
ennecf94ff0c2015-08-18 22:58:059187 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
9188 gfx::Size(100, 100), true, false, true);
9189 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
9190 gfx::Size(100, 100), true, false, false);
jaydasika3d10aa62015-05-06 17:50:449191
dtapuskaee0b6982016-01-29 15:14:489192 EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), false);
jaydasika3d10aa62015-05-06 17:50:449193
dtapuskaee0b6982016-01-29 15:14:489194 child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
ennecf94ff0c2015-08-18 22:58:059195 ExecuteCalculateDrawProperties(root);
dtapuskaee0b6982016-01-29 15:14:489196 EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), true);
ennecf94ff0c2015-08-18 22:58:059197
dtapuskaee0b6982016-01-29 15:14:489198 child->SetTouchEventHandlerRegion(gfx::Rect());
ennecf94ff0c2015-08-18 22:58:059199 ExecuteCalculateDrawProperties(root);
dtapuskaee0b6982016-01-29 15:14:489200 EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), false);
jaydasika3d10aa62015-05-06 17:50:449201}
9202
vollick692444f2015-05-20 15:39:149203TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
9204 gfx::Transform identity;
9205 gfx::Transform translate_z;
9206 translate_z.Translate3d(0, 0, 10);
9207
loysoa6edaaff2015-05-25 03:26:449208 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick692444f2015-05-20 15:39:149209 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9210 gfx::PointF(), gfx::Size(800, 800), true, false);
9211
loysoa6edaaff2015-05-25 03:26:449212 scoped_refptr<Layer> child = Layer::Create(layer_settings());
vollick692444f2015-05-20 15:39:149213 SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(),
9214 gfx::PointF(), gfx::Size(100, 100), true, false);
9215
9216 root->AddChild(child);
9217
ennea7b43c32015-06-18 20:01:339218 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:149219
9220 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9221 EXPECT_NE(-1, child->transform_tree_index());
9222
9223 child->RemoveFromParent();
9224
9225 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9226 EXPECT_EQ(-1, child->transform_tree_index());
9227}
9228
jaydasika976cd10b2015-05-26 15:45:249229TEST_F(LayerTreeHostCommonTest, ResetLayerDrawPropertiestest) {
9230 scoped_refptr<Layer> root = Layer::Create(layer_settings());
9231 scoped_refptr<Layer> child = Layer::Create(layer_settings());
9232
9233 root->AddChild(child);
9234 gfx::Transform identity;
9235
9236 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9237 gfx::PointF(), gfx::Size(100, 100), true, false);
9238 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9239 gfx::PointF(), gfx::Size(100, 100), true, false);
9240
ennea7b43c32015-06-18 20:01:339241 host()->SetRootLayer(root);
jaydasika976cd10b2015-05-26 15:45:249242
9243 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
9244 EXPECT_FALSE(root->visited());
9245 EXPECT_FALSE(root->sorted_for_recursion());
9246 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
9247 EXPECT_FALSE(child->visited());
9248 EXPECT_FALSE(child->sorted_for_recursion());
9249
9250 root->set_layer_or_descendant_is_drawn(true);
9251 root->set_visited(true);
9252 root->set_sorted_for_recursion(true);
9253 child->set_layer_or_descendant_is_drawn(true);
9254 child->set_visited(true);
9255 child->set_sorted_for_recursion(true);
9256
9257 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root.get());
9258
9259 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
9260 EXPECT_FALSE(root->visited());
9261 EXPECT_FALSE(root->sorted_for_recursion());
9262 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
9263 EXPECT_FALSE(child->visited());
9264 EXPECT_FALSE(child->sorted_for_recursion());
9265}
9266
jaydasika67d7989e2015-08-06 21:55:349267TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
9268 // Ensure that a Clip Node is added when a render surface applies clip.
9269 LayerImpl* root = root_layer();
9270 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
9271 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
9272 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
9273 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9274
9275 const gfx::Transform identity_matrix;
9276 // This transform should be a significant one so that a transform node is
9277 // formed for it.
9278 gfx::Transform transform1;
9279 transform1.RotateAboutYAxis(45);
9280 transform1.RotateAboutXAxis(30);
9281 // This transform should be a 3d transform as we want the render surface
9282 // to flatten the transform
9283 gfx::Transform transform2;
9284 transform2.Translate3d(10, 10, 10);
9285
9286 layer_clips_subtree->SetMasksToBounds(true);
9287 test_layer->SetDrawsContent(true);
9288
9289 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269290 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349291 SetLayerPropertiesForTesting(significant_transform, transform1,
9292 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
weiliangcc154ce22015-12-09 03:39:269293 true, false);
jaydasika67d7989e2015-08-06 21:55:349294 SetLayerPropertiesForTesting(layer_clips_subtree, identity_matrix,
9295 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
weiliangcc154ce22015-12-09 03:39:269296 true, false);
jaydasika67d7989e2015-08-06 21:55:349297 SetLayerPropertiesForTesting(render_surface, transform2, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269298 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349299 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269300 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349301
weiliangcc154ce22015-12-09 03:39:269302 root->SetForceRenderSurface(true);
9303 significant_transform->SetForceRenderSurface(false);
9304 layer_clips_subtree->SetForceRenderSurface(true);
9305 render_surface->SetForceRenderSurface(true);
9306 test_layer->SetForceRenderSurface(false);
jaydasika67d7989e2015-08-06 21:55:349307 ExecuteCalculateDrawProperties(root);
9308
9309 TransformTree transform_tree =
9310 root->layer_tree_impl()->property_trees()->transform_tree;
9311 TransformNode* transform_node =
9312 transform_tree.Node(significant_transform->transform_tree_index());
9313 EXPECT_EQ(transform_node->owner_id, significant_transform->id());
9314
weiliangcc154ce22015-12-09 03:39:269315 EXPECT_TRUE(root->has_render_surface());
9316 EXPECT_FALSE(significant_transform->has_render_surface());
9317 EXPECT_TRUE(layer_clips_subtree->has_render_surface());
9318 EXPECT_TRUE(render_surface->has_render_surface());
9319 EXPECT_FALSE(test_layer->has_render_surface());
9320
jaydasika67d7989e2015-08-06 21:55:349321 ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
9322 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
ajuma01734dd02015-10-07 01:22:089323 EXPECT_FALSE(clip_node->data.applies_local_clip);
weiliangcc154ce22015-12-09 03:39:269324 EXPECT_EQ(gfx::Rect(22, 21), test_layer->visible_rect_from_property_trees());
jaydasika67d7989e2015-08-06 21:55:349325}
9326
9327TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
9328 // Ensure that when parent clip node's transform is an ancestor of current
9329 // clip node's target, clip is 'projected' from parent space to current
9330 // target space and visible rects are calculated correctly.
9331 LayerImpl* root = root_layer();
9332 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9333 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
9334 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
9335
9336 const gfx::Transform identity_matrix;
9337 gfx::Transform transform;
9338 transform.RotateAboutYAxis(45);
9339 clip_layer->SetMasksToBounds(true);
9340 target_layer->SetMasksToBounds(true);
9341 test_layer->SetDrawsContent(true);
9342
9343 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9344 gfx::PointF(), gfx::Size(30, 30), true, false,
9345 true);
9346 SetLayerPropertiesForTesting(clip_layer, transform, gfx::Point3F(),
9347 gfx::PointF(), gfx::Size(30, 30), true, false,
9348 false);
9349 SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(),
9350 gfx::PointF(), gfx::Size(30, 30), true, false,
9351 true);
9352 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9353 gfx::PointF(), gfx::Size(30, 30), true, false,
9354 false);
9355 ExecuteCalculateDrawProperties(root);
9356
danakj5e6ff6d2015-09-05 04:43:449357 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_rect_from_property_trees());
jaydasika67d7989e2015-08-06 21:55:349358}
9359
jaydasika7d5c1ed2015-08-14 14:27:029360TEST_F(LayerTreeHostCommonTest,
9361 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
9362 // Ensure clip rect is calculated correctly when render surface has unclipped
9363 // descendants.
9364 LayerImpl* root = root_layer();
9365 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9366 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
9367 LayerImpl* render_surface =
9368 AddChild<LayerImpl>(between_clip_parent_and_child);
9369 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9370
9371 const gfx::Transform identity_matrix;
9372 gfx::Transform transform;
9373 transform.Translate(2.0, 2.0);
9374
9375 test_layer->SetDrawsContent(true);
9376 render_surface->SetClipParent(clip_parent);
jaydasikae9d09702015-09-15 01:26:419377 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9378 clip_children->insert(render_surface);
9379 clip_parent->SetClipChildren(clip_children.release());
jaydasika7d5c1ed2015-08-14 14:27:029380 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9381 gfx::PointF(), gfx::Size(30, 30), true, false,
9382 true);
9383 SetLayerPropertiesForTesting(clip_parent, transform, gfx::Point3F(),
9384 gfx::PointF(), gfx::Size(30, 30), true, false,
9385 false);
9386 SetLayerPropertiesForTesting(between_clip_parent_and_child, transform,
9387 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
9388 true, false, false);
9389 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9390 gfx::PointF(), gfx::Size(30, 30), true, false,
9391 true);
9392 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9393 gfx::PointF(), gfx::Size(30, 30), true, false,
9394 false);
9395
9396 ExecuteCalculateDrawProperties(root);
9397
jaydasikae9d09702015-09-15 01:26:419398 EXPECT_EQ(gfx::Rect(30, 30), test_layer->clip_rect());
jaydasika7d5c1ed2015-08-14 14:27:029399}
9400
jaydasika571dd2cf2015-09-25 20:55:429401TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:089402 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
9403 // Ensure that the visible layer rect of a descendant of a surface with
9404 // unclipped descendants is computed correctly, when the surface doesn't apply
9405 // a clip.
9406 LayerImpl* root = root_layer();
9407 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9408 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9409 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9410 LayerImpl* child = AddChild<LayerImpl>(render_surface);
9411
9412 const gfx::Transform identity_matrix;
9413
9414 clip_child->SetDrawsContent(true);
9415 child->SetDrawsContent(true);
9416 clip_child->SetClipParent(clip_parent);
9417 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9418 clip_children->insert(clip_child);
9419 clip_parent->SetClipChildren(clip_children.release());
9420 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9421 gfx::PointF(), gfx::Size(30, 10), true, false,
9422 true);
9423 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9424 gfx::PointF(), gfx::Size(30, 30), true, false,
9425 false);
9426 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9427 gfx::PointF(), gfx::Size(10, 15), true, false,
9428 true);
9429 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9430 gfx::PointF(), gfx::Size(10, 10), true, false,
9431 false);
9432 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
9433 gfx::PointF(), gfx::Size(40, 40), true, false,
9434 false);
9435
9436 ExecuteCalculateDrawProperties(root);
9437 EXPECT_EQ(gfx::Rect(40, 40), child->visible_layer_rect());
9438}
9439
9440TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:429441 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
9442 LayerImpl* root = root_layer();
9443 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9444 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9445 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
9446 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
9447 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
9448
9449 const gfx::Transform identity_matrix;
9450 root->SetMasksToBounds(true);
9451 render_surface->SetMasksToBounds(true);
9452 render_surface->SetDrawsContent(true);
9453 clip_child->SetDrawsContent(true);
9454 test_layer1->SetDrawsContent(true);
9455 test_layer2->SetDrawsContent(true);
9456 clip_child->SetClipParent(clip_parent);
9457 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9458 clip_children->insert(clip_child);
9459 clip_parent->SetClipChildren(clip_children.release());
9460
9461 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9462 gfx::PointF(), gfx::Size(30, 30), true, false,
9463 true);
9464 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9465 gfx::PointF(), gfx::Size(30, 30), true, false,
9466 false);
9467 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9468 gfx::PointF(), gfx::Size(50, 50), true, false,
9469 true);
9470 SetLayerPropertiesForTesting(test_layer1, identity_matrix, gfx::Point3F(),
9471 gfx::PointF(), gfx::Size(50, 50), true, false,
9472 false);
9473 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9474 gfx::PointF(), gfx::Size(50, 50), true, false,
9475 false);
9476 SetLayerPropertiesForTesting(test_layer2, identity_matrix, gfx::Point3F(),
9477 gfx::PointF(), gfx::Size(50, 50), true, false,
9478 false);
9479
9480 ExecuteCalculateDrawProperties(root);
9481 EXPECT_EQ(gfx::Rect(50, 50), render_surface->visible_layer_rect());
9482 EXPECT_EQ(gfx::Rect(50, 50), test_layer1->visible_layer_rect());
9483 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
9484 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
9485}
9486
ajumae2b7a5c2015-09-30 21:41:429487TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
9488 LayerImpl* root = root_layer();
9489 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9490 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9491 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9492
9493 const gfx::Transform identity_matrix;
9494 clip_parent->SetDrawsContent(true);
9495 render_surface->SetMasksToBounds(true);
9496 render_surface->SetDrawsContent(true);
9497 clip_child->SetDrawsContent(true);
9498
9499 clip_child->SetClipParent(clip_parent);
9500 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9501 clip_children->insert(clip_child);
9502 clip_parent->SetClipChildren(clip_children.release());
9503
9504 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9505 gfx::PointF(), gfx::Size(50, 50), true, false,
9506 true);
9507 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9508 gfx::PointF(), gfx::Size(50, 50), true, false,
9509 false);
9510 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9511 gfx::PointF(), gfx::Size(30, 30), true, false,
9512 true);
9513 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9514 gfx::PointF(), gfx::Size(50, 50), true, false,
9515 false);
9516
9517 ExecuteCalculateDrawProperties(root);
9518
9519 // The clip child should inherit its clip parent's clipping state, not its
9520 // tree parent's clipping state.
9521 EXPECT_FALSE(clip_parent->is_clipped());
9522 EXPECT_TRUE(render_surface->is_clipped());
9523 EXPECT_FALSE(clip_child->is_clipped());
9524}
9525
jaydasika77a4a072015-10-20 21:47:279526TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
9527 // Tests the value of render surface content rect when we have multiple types
9528 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
9529 // clipped surfaces.
9530 LayerImpl* root = root_layer();
9531 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
9532 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
9533 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9534 LayerImpl* unclipped_desc_surface2 =
9535 AddChild<LayerImpl>(unclipped_desc_surface);
9536 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
9537 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
9538
9539 unclipped_surface->SetDrawsContent(true);
9540 unclipped_desc_surface->SetDrawsContent(true);
9541 unclipped_desc_surface2->SetDrawsContent(true);
9542 clipped_surface->SetDrawsContent(true);
9543 clip_child->SetClipParent(clip_parent);
9544 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9545 clip_children->insert(clip_child);
9546 clip_parent->SetClipChildren(clip_children.release());
9547
9548 gfx::Transform identity_matrix;
9549 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9550 gfx::PointF(), gfx::Size(80, 80), true, false,
9551 true);
9552 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
9553 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
9554 true, false, true);
9555 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9556 gfx::PointF(), gfx::Size(50, 50), true, false,
9557 false);
9558 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
9559 gfx::Point3F(), gfx::PointF(),
9560 gfx::Size(100, 100), true, false, true);
9561 SetLayerPropertiesForTesting(unclipped_desc_surface2, identity_matrix,
9562 gfx::Point3F(), gfx::PointF(), gfx::Size(60, 60),
9563 true, false, true);
9564 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9565 gfx::PointF(), gfx::Size(100, 100), true, false,
9566 false);
9567 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
9568 gfx::PointF(), gfx::Size(70, 70), true, false,
9569 true);
9570 clip_parent->SetMasksToBounds(true);
9571 unclipped_surface->SetMasksToBounds(true);
9572 unclipped_desc_surface->SetMasksToBounds(true);
9573
9574 ExecuteCalculateDrawProperties(root);
9575 EXPECT_EQ(gfx::Rect(50, 50),
9576 unclipped_surface->render_surface()->content_rect());
9577 EXPECT_EQ(gfx::Rect(100, 100),
9578 unclipped_desc_surface->render_surface()->content_rect());
9579 EXPECT_EQ(gfx::Rect(50, 50),
9580 unclipped_desc_surface2->render_surface()->content_rect());
9581 EXPECT_EQ(gfx::Rect(50, 50),
9582 clipped_surface->render_surface()->content_rect());
9583}
9584
9585TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
9586 // Tests the value of render surface content rect when we have a layer that
9587 // clips between the clip parent's target and clip child's target.
9588 LayerImpl* root = root_layer();
9589 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9590 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9591 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9592 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9593 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9594
9595 clip_child->SetDrawsContent(true);
9596 unclipped_desc_surface->SetDrawsContent(true);
9597 clip_child->SetClipParent(clip_parent);
9598 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9599 clip_children->insert(clip_child);
9600 clip_parent->SetClipChildren(clip_children.release());
9601
9602 gfx::Transform identity_matrix;
9603 gfx::Transform translate;
9604 translate.Translate(10, 10);
9605 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9606 gfx::PointF(), gfx::Size(100, 100), true, false,
9607 true);
9608 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
9609 gfx::PointF(), gfx::Size(100, 100), true, false,
9610 true);
9611 SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(),
9612 gfx::PointF(), gfx::Size(20, 20), true, false,
9613 false);
9614 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9615 gfx::PointF(), gfx::Size(50, 50), true, false,
9616 false);
9617 SetLayerPropertiesForTesting(unclipped_desc_surface, translate,
9618 gfx::Point3F(), gfx::PointF(),
9619 gfx::Size(100, 100), true, false, true);
9620 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9621 gfx::PointF(), gfx::Size(100, 100), true, false,
9622 false);
9623 surface->SetMasksToBounds(true);
9624 clip_layer->SetMasksToBounds(true);
9625
9626 ExecuteCalculateDrawProperties(root);
9627
9628 EXPECT_EQ(gfx::Rect(10, 10),
9629 unclipped_desc_surface->render_surface()->content_rect());
9630}
9631
jaydasika2c8c2872015-10-21 23:28:219632TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
9633 LayerImpl* root = root_layer();
9634 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9635 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9636 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9637 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9638 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9639
9640 clip_child->SetDrawsContent(true);
9641 unclipped_desc_surface->SetDrawsContent(true);
9642 clip_child->SetClipParent(clip_parent);
9643 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9644 clip_children->insert(clip_child);
9645 clip_parent->SetClipChildren(clip_children.release());
9646
9647 gfx::Transform identity_matrix;
9648 gfx::Transform scale;
9649 scale.Scale(2, 2);
9650 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9651 gfx::PointF(), gfx::Size(100, 100), true, false,
9652 true);
9653 SetLayerPropertiesForTesting(surface, scale, gfx::Point3F(), gfx::PointF(),
9654 gfx::Size(100, 100), true, false, true);
9655 SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(),
9656 gfx::PointF(), gfx::Size(20, 20), true, false,
9657 false);
9658 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9659 gfx::PointF(), gfx::Size(50, 50), true, false,
9660 false);
9661 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
9662 gfx::Point3F(), gfx::PointF(),
9663 gfx::Size(100, 100), true, false, true);
9664 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9665 gfx::PointF(), gfx::Size(100, 100), true, false,
9666 false);
9667 surface->SetMasksToBounds(true);
9668 clip_layer->SetMasksToBounds(true);
9669
9670 ExecuteCalculateDrawProperties(root);
9671
9672 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9673}
9674
jaydasika60f85862015-10-01 20:36:149675TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
9676 LayerImpl* root = root_layer();
9677 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9678 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9679
9680 const gfx::Transform identity_matrix;
9681 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9682 gfx::PointF(), gfx::Size(30, 30), true, false,
9683 true);
9684 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9685 gfx::PointF(), gfx::Size(30, 30), true, false,
9686 true);
jaydasika86654512016-01-27 17:05:079687 gfx::Transform translation;
9688 translation.Translate(10, 10);
9689 SetLayerPropertiesForTesting(test_layer, translation, gfx::Point3F(),
jaydasika60f85862015-10-01 20:36:149690 gfx::PointF(), gfx::Size(20, 20), true, false,
9691 false);
9692
9693 render_surface->SetMasksToBounds(true);
9694 test_layer->SetDrawsContent(true);
9695 test_layer->SetOpacity(0);
dtapuskaee0b6982016-01-29 15:14:489696 test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20));
jaydasika60f85862015-10-01 20:36:149697
9698 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079699 EXPECT_EQ(translation, test_layer->ScreenSpaceTransform());
jaydasika60f85862015-10-01 20:36:149700}
9701
jaydasikae4910fa22015-10-09 00:52:099702TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
9703 LayerImpl* root = root_layer();
9704 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9705 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9706 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9707
9708 const gfx::Transform identity_matrix;
9709 clip_parent->SetMasksToBounds(true);
9710 render_surface->SetMasksToBounds(true);
9711 render_surface->SetDrawsContent(true);
9712 clip_child->SetDrawsContent(true);
9713 clip_child->SetClipParent(clip_parent);
9714 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9715 clip_children->insert(clip_child);
9716 clip_parent->SetClipChildren(clip_children.release());
9717
9718 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9719 gfx::PointF(), gfx::Size(30, 30), true, false,
9720 true);
9721 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9722 gfx::PointF(10.f, 10.f), gfx::Size(40, 40), true,
9723 false, false);
9724 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9725 gfx::PointF(), gfx::Size(50, 50), true, false,
9726 true);
9727 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9728 gfx::PointF(), gfx::Size(50, 50), true, false,
9729 false);
9730
9731 ExecuteCalculateDrawProperties(root);
9732 EXPECT_EQ(gfx::Rect(40, 40), clip_child->visible_layer_rect());
9733}
9734
jaydasika571dd2cf2015-09-25 20:55:429735TEST_F(LayerTreeHostCommonTest,
9736 LayerClipRectLargerThanClippingRenderSurfaceRect) {
9737 LayerImpl* root = root_layer();
9738 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9739 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9740 const gfx::Transform identity_matrix;
9741 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9742 gfx::PointF(), gfx::Size(30, 30), true, false,
9743 true);
9744 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9745 gfx::PointF(), gfx::Size(50, 50), true, false,
9746 true);
9747 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9748 gfx::PointF(), gfx::Size(50, 50), true, false,
9749 false);
9750 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369751 root->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429752 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369753 render_surface->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429754 test_layer->SetMasksToBounds(true);
9755 test_layer->SetDrawsContent(true);
9756 ExecuteCalculateDrawProperties(root);
9757
9758 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
9759 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
9760 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
9761}
9762
jaydasikab5504ca2015-12-18 23:41:559763TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) {
9764 // Tests that subtree is hidden is updated.
9765 LayerImpl* root = root_layer();
9766 LayerImpl* hidden = AddChild<LayerImpl>(root);
9767 LayerImpl* test = AddChild<LayerImpl>(hidden);
9768
9769 const gfx::Transform identity_matrix;
9770 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9771 gfx::PointF(), gfx::Size(30, 30), true, false,
9772 true);
9773 SetLayerPropertiesForTesting(hidden, identity_matrix, gfx::Point3F(),
9774 gfx::PointF(10, 10), gfx::Size(30, 30), true,
9775 false, true);
9776 SetLayerPropertiesForTesting(test, identity_matrix, gfx::Point3F(),
9777 gfx::PointF(), gfx::Size(30, 30), true, false,
9778 true);
9779
9780 hidden->SetHideLayerAndSubtree(true);
9781 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079782 EXPECT_TRUE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559783
9784 hidden->SetHideLayerAndSubtree(false);
9785 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9786 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079787 EXPECT_FALSE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559788}
9789
jaydasikac0137282015-10-01 15:50:309790TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
9791 LayerImpl* root = root_layer();
9792 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9793 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9794 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
9795
9796 const gfx::Transform identity_matrix;
9797 clip_child->SetClipParent(root);
9798 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9799 clip_children->insert(clip_child);
9800 root->SetClipChildren(clip_children.release());
9801 root->SetMasksToBounds(true);
9802 render_surface1->SetDrawsContent(true);
9803 render_surface2->SetDrawsContent(true);
9804
9805 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9806 gfx::PointF(), gfx::Size(30, 30), true, false,
9807 true);
9808 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
9809 gfx::PointF(10, 10), gfx::Size(30, 30), true,
9810 false, true);
9811 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
9812 gfx::PointF(), gfx::Size(30, 30), true, false,
9813 true);
9814 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9815 gfx::PointF(), gfx::Size(30, 30), true, false,
9816 false);
9817 ExecuteCalculateDrawProperties(root);
9818
9819 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
jaydasikadaf0af02016-01-06 15:33:379820 // A clip node is created for every render surface and for layers that have
9821 // local clip. So, here it should be craeted for every layer.
9822 EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u);
jaydasikac0137282015-10-01 15:50:309823}
9824
jaydasika224bca02015-12-18 02:37:099825TEST_F(LayerTreeHostCommonTest, MaskLayerScreenSpaceTransform) {
9826 // Tests that the mask layer gets its owning layer's screen space transform.
9827 LayerImpl* root = root_layer();
9828 LayerImpl* child = AddChild<LayerImpl>(root);
9829
9830 const gfx::Transform identity_matrix;
9831 gfx::Transform transform;
9832 transform.Translate(10, 10);
9833
9834 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9835 gfx::PointF(), gfx::Size(30, 30), true, false,
9836 true);
9837 SetLayerPropertiesForTesting(child, transform, gfx::Point3F(), gfx::PointF(),
9838 gfx::Size(30, 30), true, false, false);
9839 root->SetDrawsContent(true);
9840 child->SetDrawsContent(false);
9841 child->SetMaskLayer(LayerImpl::Create(root->layer_tree_impl(), 100));
9842 ExecuteCalculateDrawProperties(root);
9843
9844 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
9845 child->mask_layer()->ScreenSpaceTransform());
9846 transform.Translate(10, 10);
9847 child->SetTransform(transform);
9848 child->SetDrawsContent(true);
9849 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9850 ExecuteCalculateDrawProperties(root);
9851 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
9852 child->mask_layer()->ScreenSpaceTransform());
9853}
9854
jaydasika5160e672015-10-15 15:25:149855TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
9856 LayerImpl* root = root_layer();
9857 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9858 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9859
9860 const gfx::Transform identity_matrix;
9861 render_surface1->SetDrawsContent(true);
9862 render_surface2->SetDrawsContent(true);
jaydasika445176f2015-11-04 20:14:039863 render_surface2->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:149864
9865 gfx::Transform large_transform;
9866 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
9867 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
9868 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
9869 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
9870
9871 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9872 gfx::PointF(), gfx::Size(30, 30), true, false,
9873 true);
9874 SetLayerPropertiesForTesting(render_surface1, large_transform, gfx::Point3F(),
9875 gfx::PointF(), gfx::Size(30, 30), true, false,
9876 true);
9877 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
9878 gfx::PointF(), gfx::Size(30, 30), true, false,
9879 true);
9880
9881 ExecuteCalculateDrawProperties(root);
9882
jaydasika8640f9f2015-11-10 01:34:369883 bool is_inf_or_nan =
9884 std::isinf(
9885 render_surface2->render_surface()->draw_transform().matrix().get(
9886 0, 0)) ||
9887 std::isnan(
9888 render_surface2->render_surface()->draw_transform().matrix().get(0,
9889 0));
9890 EXPECT_TRUE(is_inf_or_nan);
9891 is_inf_or_nan =
9892 std::isinf(
9893 render_surface2->render_surface()->draw_transform().matrix().get(
9894 1, 1)) ||
9895 std::isnan(
9896 render_surface2->render_surface()->draw_transform().matrix().get(1,
9897 1));
9898 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:149899 EXPECT_EQ(gfx::RectF(),
9900 render_surface2->render_surface()->DrawableContentRect());
9901
9902 std::vector<LayerImpl*>* rsll = render_surface_layer_list_impl();
9903 bool root_in_rsll =
9904 std::find(rsll->begin(), rsll->end(), root) != rsll->end();
9905 EXPECT_TRUE(root_in_rsll);
9906 bool render_surface2_in_rsll =
9907 std::find(rsll->begin(), rsll->end(), render_surface2) != rsll->end();
9908 EXPECT_FALSE(render_surface2_in_rsll);
9909}
9910
khushalsagar37694212016-01-15 20:46:489911TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) {
9912 LayerTreeHostCommon::ScrollUpdateInfo scroll;
9913 scroll.layer_id = 2;
9914 scroll.scroll_delta = gfx::Vector2d(5, 10);
9915
9916 proto::ScrollUpdateInfo proto;
9917 scroll.ToProtobuf(&proto);
9918 LayerTreeHostCommon::ScrollUpdateInfo new_scroll;
9919 new_scroll.FromProtobuf(proto);
9920
9921 EXPECT_EQ(scroll, new_scroll);
9922}
9923
9924TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) {
9925 ScrollAndScaleSet scroll_and_scale_set;
9926
9927 LayerTreeHostCommon::ScrollUpdateInfo scroll1;
9928 scroll1.layer_id = 1;
9929 scroll1.scroll_delta = gfx::Vector2d(5, 10);
9930 LayerTreeHostCommon::ScrollUpdateInfo scroll2;
9931 scroll2.layer_id = 2;
9932 scroll2.scroll_delta = gfx::Vector2d(1, 5);
9933 scroll_and_scale_set.scrolls.push_back(scroll1);
9934 scroll_and_scale_set.scrolls.push_back(scroll2);
9935
9936 scroll_and_scale_set.page_scale_delta = 0.3f;
9937 scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f);
9938 scroll_and_scale_set.top_controls_delta = 0.9f;
9939
9940 proto::ScrollAndScaleSet proto;
9941 scroll_and_scale_set.ToProtobuf(&proto);
9942 ScrollAndScaleSet new_scroll_and_scale_set;
9943 new_scroll_and_scale_set.FromProtobuf(proto);
9944
9945 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set));
9946}
9947
sunxdea1df782016-01-28 00:12:339948TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) {
9949 // Test the behavior of scroll tree builder
9950 // Topology:
sunxdcfccd1b32016-02-11 00:54:209951 // +root1(1)[inner_viewport_container_layer]
9952 // +-page_scale_layer
9953 // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling &
9954 // scrollable, inner_viewport_scroll_layer]
9955 // +------child6(6)[kScrollbarScrolling]
9956 // +--------grand_child10(10)[kScrollbarScrolling]
9957 // +----parent3(3)
9958 // +------child7(7)[scrollable]
9959 // +------child8(8)[scroll_parent=7]
9960 // +--------grand_child11(11)[scrollable]
9961 // +----parent4(4)
9962 // +------child9(9)
9963 // +--------grand_child12(12)
9964 // +----parent5(5)[contains_non_fast_scrollable_region]
sunxdea1df782016-01-28 00:12:339965 //
9966 // Expected scroll tree topology:
9967 // +property_tree_root---owner:-1
9968 // +--root---owner:1, id:1
9969 // +----node---owner:2, id:2
9970 // +------node---owner:6, id:3
9971 // +----node---owner:7, id:4
9972 // +------node---owner:11, id:5
9973 // +----node---owner:5, id:6
9974 //
9975 // Extra check:
9976 // scroll_tree_index() of:
9977 // grand_child10:3
9978 // parent3:1
9979 // child8:4
9980 // parent4:1
9981 // child9:1
9982 // grand_child12:1
9983 scoped_refptr<Layer> root1 = Layer::Create(layer_settings());
sunxdcfccd1b32016-02-11 00:54:209984 scoped_refptr<Layer> page_scale_layer = Layer::Create(layer_settings());
sunxdea1df782016-01-28 00:12:339985 scoped_refptr<Layer> parent2 = Layer::Create(layer_settings());
9986 scoped_refptr<Layer> parent3 = Layer::Create(layer_settings());
9987 scoped_refptr<Layer> parent4 = Layer::Create(layer_settings());
9988 scoped_refptr<Layer> parent5 = Layer::Create(layer_settings());
9989 scoped_refptr<Layer> child6 = Layer::Create(layer_settings());
9990 scoped_refptr<Layer> child7 = Layer::Create(layer_settings());
9991 scoped_refptr<Layer> child8 = Layer::Create(layer_settings());
9992 scoped_refptr<Layer> child9 = Layer::Create(layer_settings());
9993 scoped_refptr<Layer> grand_child10 = Layer::Create(layer_settings());
9994 scoped_refptr<Layer> grand_child11 = Layer::Create(layer_settings());
9995 scoped_refptr<Layer> grand_child12 = Layer::Create(layer_settings());
9996
sunxdcfccd1b32016-02-11 00:54:209997 root1->AddChild(page_scale_layer);
9998 page_scale_layer->AddChild(parent2);
9999 page_scale_layer->AddChild(parent3);
10000 page_scale_layer->AddChild(parent4);
10001 page_scale_layer->AddChild(parent5);
sunxdea1df782016-01-28 00:12:3310002 parent2->AddChild(child6);
10003 parent3->AddChild(child7);
10004 parent3->AddChild(child8);
10005 parent4->AddChild(child9);
10006 child6->AddChild(grand_child10);
10007 child8->AddChild(grand_child11);
10008 child9->AddChild(grand_child12);
10009 host()->SetRootLayer(root1);
10010
10011 parent2->AddMainThreadScrollingReasons(
10012 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
sunxd29f17bf2016-02-03 02:47:4810013 parent2->AddMainThreadScrollingReasons(
10014 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310015 parent2->SetScrollClipLayerId(root1->id());
10016 child6->AddMainThreadScrollingReasons(
sunxd29f17bf2016-02-03 02:47:4810017 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310018 grand_child10->AddMainThreadScrollingReasons(
sunxd29f17bf2016-02-03 02:47:4810019 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310020
sunxdcfccd1b32016-02-11 00:54:2010021 child7->SetScrollClipLayerId(parent3->id());
10022
sunxdea1df782016-01-28 00:12:3310023 child8->SetScrollParent(child7.get());
sunxdcfccd1b32016-02-11 00:54:2010024 grand_child11->SetScrollClipLayerId(parent3->id());
sunxdea1df782016-01-28 00:12:3310025
10026 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
sunxdcfccd1b32016-02-11 00:54:2010027 parent5->SetBounds(gfx::Size(10, 10));
sunxdea1df782016-01-28 00:12:3310028
sunxdcfccd1b32016-02-11 00:54:2010029 host()->RegisterViewportLayers(NULL, page_scale_layer, parent2, NULL);
sunxdea1df782016-01-28 00:12:3310030 ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get());
10031
10032 const int kInvalidPropertyTreeNodeId = -1;
10033 const int kRootPropertyTreeNodeId = 0;
10034
10035 // Property tree root
10036 ScrollTree scroll_tree = host()->property_trees()->scroll_tree;
10037 ScrollTree expected_scroll_tree;
10038 ScrollNode* property_tree_root = expected_scroll_tree.Node(0);
10039 property_tree_root->id = kRootPropertyTreeNodeId;
10040 property_tree_root->parent_id = kInvalidPropertyTreeNodeId;
10041 property_tree_root->owner_id = kInvalidPropertyTreeNodeId;
10042 property_tree_root->data.scrollable = false;
sunxd29f17bf2016-02-03 02:47:4810043 property_tree_root->data.main_thread_scrolling_reasons =
10044 MainThreadScrollingReason::kNotScrollingOnMain;
sunxdea1df782016-01-28 00:12:3310045 property_tree_root->data.contains_non_fast_scrollable_region = false;
sunxdea1df782016-01-28 00:12:3310046
10047 // The node owned by root1
10048 ScrollNode scroll_root1;
10049 scroll_root1.id = 1;
10050 scroll_root1.owner_id = root1->id();
sunxdea1df782016-01-28 00:12:3310051 expected_scroll_tree.Insert(scroll_root1, 0);
10052
10053 // The node owned by parent2
10054 ScrollNode scroll_parent2;
10055 scroll_parent2.id = 2;
10056 scroll_parent2.owner_id = parent2->id();
10057 scroll_parent2.data.scrollable = true;
sunxd29f17bf2016-02-03 02:47:4810058 scroll_parent2.data.main_thread_scrolling_reasons =
10059 parent2->main_thread_scrolling_reasons();
sunxdcfccd1b32016-02-11 00:54:2010060 scroll_parent2.data.scroll_clip_layer_bounds = root1->bounds();
10061 scroll_parent2.data.bounds = parent2->bounds();
10062 scroll_parent2.data.max_scroll_offset_affected_by_page_scale = true;
10063 scroll_parent2.data.is_inner_viewport_scroll_layer = true;
sunxdea1df782016-01-28 00:12:3310064 expected_scroll_tree.Insert(scroll_parent2, 1);
10065
10066 // The node owned by child6
10067 ScrollNode scroll_child6;
10068 scroll_child6.id = 3;
10069 scroll_child6.owner_id = child6->id();
sunxd29f17bf2016-02-03 02:47:4810070 scroll_child6.data.main_thread_scrolling_reasons =
10071 child6->main_thread_scrolling_reasons();
sunxdea1df782016-01-28 00:12:3310072 expected_scroll_tree.Insert(scroll_child6, 2);
10073
10074 // The node owned by child7, child7 also owns a transform node
10075 ScrollNode scroll_child7;
10076 scroll_child7.id = 4;
10077 scroll_child7.owner_id = child7->id();
10078 scroll_child7.data.scrollable = true;
sunxdcfccd1b32016-02-11 00:54:2010079 scroll_parent2.data.scroll_clip_layer_bounds = parent3->bounds();
10080 scroll_parent2.data.bounds = child7->bounds();
sunxdea1df782016-01-28 00:12:3310081 expected_scroll_tree.Insert(scroll_child7, 1);
10082
10083 // The node owned by grand_child11, grand_child11 also owns a transform node
10084 ScrollNode scroll_grand_child11;
10085 scroll_grand_child11.id = 5;
10086 scroll_grand_child11.owner_id = grand_child11->id();
10087 scroll_grand_child11.data.scrollable = true;
sunxdea1df782016-01-28 00:12:3310088 expected_scroll_tree.Insert(scroll_grand_child11, 4);
10089
10090 // The node owned by parent5
10091 ScrollNode scroll_parent5;
10092 scroll_parent5.id = 8;
10093 scroll_parent5.owner_id = parent5->id();
10094 scroll_parent5.data.contains_non_fast_scrollable_region = true;
sunxdcfccd1b32016-02-11 00:54:2010095 scroll_parent5.data.bounds = gfx::Size(10, 10);
sunxdea1df782016-01-28 00:12:3310096 expected_scroll_tree.Insert(scroll_parent5, 1);
10097
10098 expected_scroll_tree.set_needs_update(false);
10099
10100 EXPECT_EQ(expected_scroll_tree, scroll_tree);
10101
10102 // Check other layers' scroll_tree_index
sunxdcfccd1b32016-02-11 00:54:2010103 EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index());
sunxdea1df782016-01-28 00:12:3310104 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10105 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10106 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10107 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10108 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10109 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10110}
10111
[email protected]ba565742012-11-10 09:29:4810112} // namespace
10113} // namespace cc