blob: 394548d092360883fe2cf4918136b5bbdac07394 [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"
sunxd71aea3e2016-04-01 23:48:0515#include "cc/animation/animation_player.h"
ajuma315a4782015-07-24 21:16:3416#include "cc/animation/keyframed_animation_curve.h"
[email protected]95e4e1a02013-03-18 07:09:0917#include "cc/animation/layer_animation_controller.h"
[email protected]1c3626e2014-04-09 17:49:2218#include "cc/animation/transform_operations.h"
[email protected]681ccff2013-03-18 06:13:5219#include "cc/base/math_util.h"
sunxd29f17bf422016-02-03 02:47:4820#include "cc/input/main_thread_scrolling_reason.h"
[email protected]cc3cfaa2013-03-18 09:05:5221#include "cc/layers/content_layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5222#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5923#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5224#include "cc/layers/layer_impl.h"
[email protected]390bb1ff2014-05-09 17:14:4025#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2826#include "cc/layers/render_surface_impl.h"
[email protected]30fe19ff2013-07-04 00:54:4527#include "cc/output/copy_output_request.h"
28#include "cc/output/copy_output_result.h"
khushalsagar37694212016-01-15 20:46:4829#include "cc/proto/begin_main_frame_and_commit_state.pb.h"
30#include "cc/proto/gfx_conversions.h"
[email protected]101441ce2012-10-16 01:45:0331#include "cc/test/animation_test_common.h"
vollick2175fae82015-04-27 21:18:1232#include "cc/test/fake_content_layer_client.h"
khushalsagarb64b360d2015-10-21 19:25:1633#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]d600df7d2013-08-03 02:34:2834#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4535#include "cc/test/fake_layer_tree_host_impl.h"
ajumaae0dc2d2015-08-05 21:55:5636#include "cc/test/fake_output_surface.h"
sohan.jyotie3bd6192014-10-13 07:13:5937#include "cc/test/fake_picture_layer.h"
38#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0339#include "cc/test/geometry_test_utils.h"
[email protected]28336d52014-05-12 19:07:2840#include "cc/test/layer_tree_host_common_test.h"
reveman34b7a1522015-03-23 20:27:4741#include "cc/test/test_task_graph_runner.h"
ennef6903532015-08-18 05:10:1542#include "cc/trees/draw_property_utils.h"
[email protected]556fd292013-03-18 08:03:0443#include "cc/trees/layer_tree_impl.h"
[email protected]556fd292013-03-18 08:03:0444#include "cc/trees/single_thread_proxy.h"
khushalsagarb64b360d2015-10-21 19:25:1645#include "cc/trees/task_runner_provider.h"
[email protected]7f0c53db2012-10-02 00:23:1846#include "testing/gmock/include/gmock/gmock.h"
47#include "testing/gtest/include/gtest/gtest.h"
heejin.r.chungd28506ba2014-10-23 16:36:2048#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3749#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0050#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1451
[email protected]ba565742012-11-10 09:29:4852namespace cc {
[email protected]94f206c12012-08-25 00:09:1453namespace {
54
[email protected]96baf3e2012-10-22 23:09:5555class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:3256 public:
loyso0940d412016-03-14 01:30:3157 LayerWithForcedDrawsContent() {}
[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;
96 }
97};
98
99class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTest {
100 public:
101 LayerTreeHostCommonScalingTest()
102 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
103};
104
[email protected]989386c2013-07-18 21:37:23105TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32106 // Sanity check: For layers positioned at zero, with zero size,
107 // and with identity transforms, then the draw transform,
108 // screen space transform, and the hierarchy passed on to children
109 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14110
sunxdfd920f3f2016-04-05 16:17:51111 LayerImpl* parent = root_layer();
112 LayerImpl* child = AddChild<LayerImpl>(parent);
113 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28114
[email protected]fb661802013-03-25 01:59:32115 gfx::Transform identity_matrix;
sunxdfd920f3f2016-04-05 16:17:51116 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
117 gfx::PointF(), gfx::Size(100, 100), true, false);
118 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
119 gfx::PointF(), gfx::Size(), true, false);
120 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
121 gfx::PointF(), gfx::Size(), true, false);
[email protected]94f206c12012-08-25 00:09:14122
sunxdfd920f3f2016-04-05 16:17:51123 ExecuteCalculateDrawProperties(parent);
[email protected]94f206c12012-08-25 00:09:14124
sunxdfd920f3f2016-04-05 16:17:51125 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32126 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
sunxdfd920f3f2016-04-05 16:17:51127 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32128 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
sunxdfd920f3f2016-04-05 16:17:51129 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32130 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
sunxdfd920f3f2016-04-05 16:17:51131 grand_child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14132}
133
jaydasika322436372015-12-16 23:42:38134TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) {
135 // Tests that effect tree node gets a valid transform id when a layer
136 // has opacity but doesn't create a render surface.
137 LayerImpl* parent = root_layer();
138 LayerImpl* child = AddChild<LayerImpl>(parent);
139 child->SetDrawsContent(true);
140
141 gfx::Transform identity_matrix;
142 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
143 gfx::PointF(), gfx::Size(100, 100), true, false);
144 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
145 gfx::PointF(10, 10), gfx::Size(100, 100), true,
146 false);
147 child->SetOpacity(0.f);
148 ExecuteCalculateDrawProperties(parent);
149 EffectTree effect_tree =
150 parent->layer_tree_impl()->property_trees()->effect_tree;
151 EffectNode* node = effect_tree.Node(child->effect_tree_index());
152 const int transform_tree_size = parent->layer_tree_impl()
153 ->property_trees()
154 ->transform_tree.next_available_id();
155 EXPECT_LT(node->data.transform_id, transform_tree_size);
156}
157
[email protected]989386c2013-07-18 21:37:23158TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32159 gfx::Transform identity_matrix;
sunxdfd920f3f2016-04-05 16:17:51160 LayerImpl* root = root_layer();
161 LayerImpl* layer = AddChild<LayerImpl>(root);
[email protected]94f206c12012-08-25 00:09:14162
sunxdfd920f3f2016-04-05 16:17:51163 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31164 gfx::PointF(), gfx::Size(1, 2), true, false);
[email protected]ecc12622012-10-30 20:45:42165
sunxdfd920f3f2016-04-05 16:17:51166 TransformTree& tree =
167 host_impl()->active_tree()->property_trees()->transform_tree;
enne826452722015-08-18 22:22:31168
[email protected]fb661802013-03-25 01:59:32169 // Case 2: Setting the bounds of the layer should not affect either the draw
170 // transform or the screenspace transform.
171 gfx::Transform translation_to_center;
172 translation_to_center.Translate(5.0, 6.0);
sunxdfd920f3f2016-04-05 16:17:51173 SetLayerPropertiesForTesting(layer, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31174 gfx::PointF(), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51175 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31176 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51177 identity_matrix, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31178 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51179 identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14180
[email protected]fb661802013-03-25 01:59:32181 // Case 3: The anchor point by itself (without a layer transform) should have
182 // no effect on the transforms.
sunxdfd920f3f2016-04-05 16:17:51183 SetLayerPropertiesForTesting(layer, identity_matrix,
enne826452722015-08-18 22:22:31184 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
185 gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51186 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
187 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31188 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51189 identity_matrix, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31190 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51191 identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14192
[email protected]fb661802013-03-25 01:59:32193 // Case 4: A change in actual position affects both the draw transform and
194 // screen space transform.
195 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05196 position_transform.Translate(0.f, 1.2f);
enne826452722015-08-18 22:22:31197 SetLayerPropertiesForTesting(
sunxdfd920f3f2016-04-05 16:17:51198 layer, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
enne826452722015-08-18 22:22:31199 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51200 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
201 ExecuteCalculateDrawProperties(root);
202 EXPECT_TRANSFORMATION_MATRIX_EQ(
203 position_transform, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31204 EXPECT_TRANSFORMATION_MATRIX_EQ(
weiliangcc97575c2016-03-03 18:34:27205 position_transform,
sunxdfd920f3f2016-04-05 16:17:51206 draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14207
[email protected]fb661802013-03-25 01:59:32208 // Case 5: In the correct sequence of transforms, the layer transform should
209 // pre-multiply the translation_to_center. This is easily tested by using a
210 // scale transform, because scale and translation are not commutative.
211 gfx::Transform layer_transform;
212 layer_transform.Scale3d(2.0, 2.0, 1.0);
sunxdfd920f3f2016-04-05 16:17:51213 SetLayerPropertiesForTesting(layer, layer_transform, gfx::Point3F(),
enne826452722015-08-18 22:22:31214 gfx::PointF(), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51215 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
216 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31217 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51218 layer_transform, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31219 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51220 layer_transform, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14221
[email protected]fb661802013-03-25 01:59:32222 // Case 6: The layer transform should occur with respect to the anchor point.
223 gfx::Transform translation_to_anchor;
224 translation_to_anchor.Translate(5.0, 0.0);
225 gfx::Transform expected_result =
226 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
sunxdfd920f3f2016-04-05 16:17:51227 SetLayerPropertiesForTesting(layer, layer_transform,
enne826452722015-08-18 22:22:31228 gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(),
229 gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51230 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
231 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31232 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51233 expected_result, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31234 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51235 expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14236
[email protected]fb661802013-03-25 01:59:32237 // Case 7: Verify that position pre-multiplies the layer transform. The
238 // current implementation of CalculateDrawProperties does this implicitly, but
239 // it is still worth testing to detect accidental regressions.
240 expected_result = position_transform * translation_to_anchor *
241 layer_transform * Inverse(translation_to_anchor);
enne826452722015-08-18 22:22:31242 SetLayerPropertiesForTesting(
sunxdfd920f3f2016-04-05 16:17:51243 layer, layer_transform, gfx::Point3F(5.0f, 0.f, 0.f),
enne826452722015-08-18 22:22:31244 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51245 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
246 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31247 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51248 expected_result, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31249 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51250 expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14251}
252
[email protected]989386c2013-07-18 21:37:23253TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13254 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32255 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01256 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32257 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
258 -kScrollOffset.y());
jaydasikaa534a472016-03-31 01:12:16259 float page_scale = 0.888f;
[email protected]fb661802013-03-25 01:59:32260 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20261
khushalsagarb64b360d2015-10-21 19:25:16262 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:45263 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:56264 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:16265 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:56266 &task_graph_runner);
[email protected]657b24c2013-03-06 09:01:20267
[email protected]fb661802013-03-25 01:59:32268 gfx::Transform identity_matrix;
269 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
270 LayerImpl::Create(host_impl.active_tree(), 1));
271 LayerImpl* sublayer = sublayer_scoped_ptr.get();
jaydasika0d98ba92015-11-17 05:17:28272 sublayer->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:00273 SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(),
274 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:32275 false);
[email protected]657b24c2013-03-06 09:01:20276
[email protected]adeda572014-01-31 00:49:47277 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32278 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47279 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
awoloszyne83f28c2014-12-22 15:40:00280 SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(),
281 gfx::PointF(), gfx::Size(10, 20), true, false,
[email protected]fb661802013-03-25 01:59:32282 false);
[email protected]adeda572014-01-31 00:49:47283 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
284 LayerImpl::Create(host_impl.active_tree(), 4));
285 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
286
287 scroll_layer->SetScrollClipLayer(clip_layer->id());
288 clip_layer->SetBounds(
289 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
290 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
291 scroll_layer->SetScrollClipLayer(clip_layer->id());
sunxdb7e79432016-03-09 21:13:42292 SetScrollOffsetDelta(scroll_layer, kScrollDelta);
[email protected]fb661802013-03-25 01:59:32293 gfx::Transform impl_transform;
danakja04855a2015-11-18 20:39:10294 scroll_layer->AddChild(std::move(sublayer_scoped_ptr));
[email protected]adeda572014-01-31 00:49:47295 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
danakja04855a2015-11-18 20:39:10296 clip_layer->AddChild(std::move(scroll_layer_scoped_ptr));
sunxdb7e79432016-03-09 21:13:42297 scroll_layer_raw_ptr->layer_tree_impl()
298 ->property_trees()
299 ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(),
300 kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20301
[email protected]fb661802013-03-25 01:59:32302 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
awoloszyne83f28c2014-12-22 15:40:00303 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
304 gfx::PointF(), gfx::Size(3, 4), true, false,
[email protected]fb661802013-03-25 01:59:32305 false);
danakja04855a2015-11-18 20:39:10306 root->AddChild(std::move(clip_layer_scoped_ptr));
awoloszyne83f28c2014-12-22 15:40:00307 root->SetHasRenderSurface(true);
jaydasika2411692c2016-03-23 01:56:09308 LayerImpl* root_layer = root.get();
309 host_impl.active_tree()->SetRootLayer(std::move(root));
[email protected]657b24c2013-03-06 09:01:20310
jaydasikaa534a472016-03-31 01:12:16311 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
jaydasika2411692c2016-03-23 01:56:09312 scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32313 gfx::Transform expected_transform = identity_matrix;
314 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
danakj2c8d12c2015-06-18 06:15:33315 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
jaydasikaa534a472016-03-31 01:12:16316 page_scale * kDeviceScale),
danakj2c8d12c2015-06-18 06:15:33317 MathUtil::Round(sub_layer_screen_position.y() *
jaydasikaa534a472016-03-31 01:12:16318 page_scale * kDeviceScale));
319 expected_transform.Scale(page_scale * kDeviceScale,
320 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32321 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44322 sublayer->DrawTransform());
[email protected]fb661802013-03-25 01:59:32323 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumab6aa1c62015-12-01 21:01:10324 sublayer->ScreenSpaceTransform());
[email protected]657b24c2013-03-06 09:01:20325
[email protected]fb661802013-03-25 01:59:32326 gfx::Transform arbitrary_translate;
327 const float kTranslateX = 10.6f;
328 const float kTranslateY = 20.6f;
329 arbitrary_translate.Translate(kTranslateX, kTranslateY);
awoloszyne83f28c2014-12-22 15:40:00330 SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate,
331 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
332 true, false, false);
jaydasika2411692c2016-03-23 01:56:09333 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaa534a472016-03-31 01:12:16334 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
jaydasika2411692c2016-03-23 01:56:09335 scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32336 expected_transform.MakeIdentity();
337 expected_transform.Translate(
jaydasikaa534a472016-03-31 01:12:16338 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
339 sub_layer_screen_position.x() * page_scale *
danakj2c8d12c2015-06-18 06:15:33340 kDeviceScale),
jaydasikaa534a472016-03-31 01:12:16341 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
342 sub_layer_screen_position.y() * page_scale *
danakj2c8d12c2015-06-18 06:15:33343 kDeviceScale));
jaydasikaa534a472016-03-31 01:12:16344 expected_transform.Scale(page_scale * kDeviceScale,
345 page_scale * kDeviceScale);
346 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
347 sublayer->DrawTransform());
348
349 // Test that page scale is updated even when we don't rebuild property trees.
350 page_scale = 1.888f;
351 root_layer->layer_tree_impl()->SetViewportLayersFromIds(
352 Layer::INVALID_ID, scroll_layer->parent()->id(), Layer::INVALID_ID,
353 Layer::INVALID_ID);
354 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale);
355 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild);
356 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
357 scroll_layer->parent());
358
359 expected_transform.MakeIdentity();
360 expected_transform.Translate(
361 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
362 sub_layer_screen_position.x() * page_scale *
363 kDeviceScale),
364 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
365 sub_layer_screen_position.y() * page_scale *
366 kDeviceScale));
367 expected_transform.Scale(page_scale * kDeviceScale,
368 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32369 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44370 sublayer->DrawTransform());
[email protected]657b24c2013-03-06 09:01:20371}
372
[email protected]989386c2013-07-18 21:37:23373TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32374 gfx::Transform identity_matrix;
sunxdfd920f3f2016-04-05 16:17:51375 LayerImpl* root = root_layer();
376 LayerImpl* parent = AddChild<LayerImpl>(root);
377 LayerImpl* child = AddChild<LayerImpl>(parent);
378 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28379
[email protected]fb661802013-03-25 01:59:32380 // One-time setup of root layer
sunxdfd920f3f2016-04-05 16:17:51381 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31382 gfx::PointF(), gfx::Size(1, 2), true, false);
383
sunxdfd920f3f2016-04-05 16:17:51384 TransformTree& tree =
385 host_impl()->active_tree()->property_trees()->transform_tree;
[email protected]ecc12622012-10-30 20:45:42386
[email protected]fb661802013-03-25 01:59:32387 // Case 1: parent's anchor point should not affect child or grand_child.
sunxdfd920f3f2016-04-05 16:17:51388 SetLayerPropertiesForTesting(parent, identity_matrix,
enne826452722015-08-18 22:22:31389 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
390 gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51391 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31392 gfx::PointF(), gfx::Size(16, 18), true, false);
sunxdfd920f3f2016-04-05 16:17:51393 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
394 gfx::PointF(), gfx::Size(76, 78), true, false);
395 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31396
397 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51398 identity_matrix, draw_property_utils::DrawTransform(child, tree));
399 EXPECT_TRANSFORMATION_MATRIX_EQ(
400 identity_matrix, draw_property_utils::ScreenSpaceTransform(child, tree));
401 EXPECT_TRANSFORMATION_MATRIX_EQ(
402 identity_matrix, draw_property_utils::DrawTransform(grand_child, tree));
enne826452722015-08-18 22:22:31403 EXPECT_TRANSFORMATION_MATRIX_EQ(
404 identity_matrix,
sunxdfd920f3f2016-04-05 16:17:51405 draw_property_utils::ScreenSpaceTransform(grand_child, tree));
[email protected]94f206c12012-08-25 00:09:14406
[email protected]fb661802013-03-25 01:59:32407 // Case 2: parent's position affects child and grand_child.
408 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05409 parent_position_transform.Translate(0.f, 1.2f);
enne826452722015-08-18 22:22:31410 SetLayerPropertiesForTesting(
sunxdfd920f3f2016-04-05 16:17:51411 parent, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
enne826452722015-08-18 22:22:31412 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51413 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31414 gfx::PointF(), gfx::Size(16, 18), true, false);
sunxdfd920f3f2016-04-05 16:17:51415 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
416 gfx::PointF(), gfx::Size(76, 78), true, false);
417 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
418 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31419 EXPECT_TRANSFORMATION_MATRIX_EQ(
420 parent_position_transform,
sunxdfd920f3f2016-04-05 16:17:51421 draw_property_utils::DrawTransform(child, tree));
enne826452722015-08-18 22:22:31422 EXPECT_TRANSFORMATION_MATRIX_EQ(
423 parent_position_transform,
sunxdfd920f3f2016-04-05 16:17:51424 draw_property_utils::ScreenSpaceTransform(child, tree));
enne826452722015-08-18 22:22:31425 EXPECT_TRANSFORMATION_MATRIX_EQ(
426 parent_position_transform,
sunxdfd920f3f2016-04-05 16:17:51427 draw_property_utils::DrawTransform(grand_child, tree));
enne826452722015-08-18 22:22:31428 EXPECT_TRANSFORMATION_MATRIX_EQ(
429 parent_position_transform,
sunxdfd920f3f2016-04-05 16:17:51430 draw_property_utils::ScreenSpaceTransform(grand_child, tree));
[email protected]94f206c12012-08-25 00:09:14431
[email protected]fb661802013-03-25 01:59:32432 // Case 3: parent's local transform affects child and grandchild
433 gfx::Transform parent_layer_transform;
434 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
435 gfx::Transform parent_translation_to_anchor;
436 parent_translation_to_anchor.Translate(2.5, 3.0);
437 gfx::Transform parent_composite_transform =
438 parent_translation_to_anchor * parent_layer_transform *
439 Inverse(parent_translation_to_anchor);
sunxdfd920f3f2016-04-05 16:17:51440 SetLayerPropertiesForTesting(parent, parent_layer_transform,
enne826452722015-08-18 22:22:31441 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
442 gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51443 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31444 gfx::PointF(), gfx::Size(16, 18), true, false);
sunxdfd920f3f2016-04-05 16:17:51445 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
446 gfx::PointF(), gfx::Size(76, 78), true, false);
447 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
448 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31449 EXPECT_TRANSFORMATION_MATRIX_EQ(
450 parent_composite_transform,
sunxdfd920f3f2016-04-05 16:17:51451 draw_property_utils::DrawTransform(child, tree));
enne826452722015-08-18 22:22:31452 EXPECT_TRANSFORMATION_MATRIX_EQ(
453 parent_composite_transform,
sunxdfd920f3f2016-04-05 16:17:51454 draw_property_utils::ScreenSpaceTransform(child, tree));
enne826452722015-08-18 22:22:31455 EXPECT_TRANSFORMATION_MATRIX_EQ(
456 parent_composite_transform,
sunxdfd920f3f2016-04-05 16:17:51457 draw_property_utils::DrawTransform(grand_child, tree));
enne826452722015-08-18 22:22:31458 EXPECT_TRANSFORMATION_MATRIX_EQ(
459 parent_composite_transform,
sunxdfd920f3f2016-04-05 16:17:51460 draw_property_utils::ScreenSpaceTransform(grand_child, tree));
[email protected]94f206c12012-08-25 00:09:14461}
462
jaydasika5f7a7b82016-04-05 20:24:29463// Render target should get cleared when subtree is skipped.
464TEST_F(LayerTreeHostCommonTest, ClearRenderTargetForSkippedLayers) {
465 LayerImpl* root = root_layer();
466 LayerImpl* parent = AddChildToRoot<LayerImpl>();
467 LayerImpl* child = AddChild<LayerImpl>(parent);
468 child->SetDrawsContent(true);
469
470 gfx::Transform identity_matrix;
471 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
472 gfx::PointF(), gfx::Size(1, 2), true, false,
473 true);
474 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
475 gfx::PointF(), gfx::Size(1, 2), true, false,
476 true);
477 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
478 gfx::PointF(), gfx::Size(1, 2), true, false,
479 false);
480
481 ExecuteCalculateDrawProperties(root);
482 ASSERT_TRUE(parent->render_surface());
483 EXPECT_EQ(parent, child->render_target());
484
485 // child is skipped when root's opacity is set to 0. So, its render target
486 // should be reset.
487 root->OnOpacityAnimated(0.0f);
488 ExecuteCalculateDrawProperties(root);
489 EXPECT_FALSE(child->render_target());
490}
491
[email protected]989386c2013-07-18 21:37:23492TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
enne25dea3f2015-07-27 16:44:28493 LayerImpl* root = root_layer();
494 LayerImpl* parent = AddChildToRoot<LayerImpl>();
495 LayerImpl* child = AddChild<LayerImpl>(parent);
496 LayerImpl* grand_child = AddChild<LayerImpl>(child);
497 grand_child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:14498
[email protected]fb661802013-03-25 01:59:32499 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28500 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
501 gfx::PointF(), gfx::Size(1, 2), true, false,
502 true);
[email protected]ecc12622012-10-30 20:45:42503
[email protected]fb661802013-03-25 01:59:32504 // Child is set up so that a new render surface should be created.
505 child->SetOpacity(0.5f);
jaydasika8640f9f2015-11-10 01:34:36506 child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:14507
[email protected]fb661802013-03-25 01:59:32508 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05509 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32510 gfx::Transform parent_translation_to_anchor;
511 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44512
[email protected]fb661802013-03-25 01:59:32513 gfx::Transform parent_composite_transform =
514 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39515 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32516 gfx::Vector2dF parent_composite_scale =
517 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
518 1.f);
519 gfx::Transform surface_sublayer_transform;
520 surface_sublayer_transform.Scale(parent_composite_scale.x(),
521 parent_composite_scale.y());
522 gfx::Transform surface_sublayer_composite_transform =
523 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14524
enne25dea3f2015-07-27 16:44:28525 SetLayerPropertiesForTesting(parent, parent_layer_transform,
526 gfx::Point3F(25.0f, 30.0f, 0.f), gfx::PointF(),
527 gfx::Size(100, 120), true, false, false);
528 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
529 gfx::PointF(), gfx::Size(16, 18), true, false,
530 true);
531 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
532 gfx::PointF(), gfx::Size(8, 10), true, false,
[email protected]fb661802013-03-25 01:59:32533 false);
enne25dea3f2015-07-27 16:44:28534 ExecuteCalculateDrawProperties(root);
[email protected]94f206c12012-08-25 00:09:14535
[email protected]fb661802013-03-25 01:59:32536 // Render surface should have been created now.
537 ASSERT_TRUE(child->render_surface());
enne25dea3f2015-07-27 16:44:28538 ASSERT_EQ(child, child->render_target());
[email protected]94f206c12012-08-25 00:09:14539
[email protected]fb661802013-03-25 01:59:32540 // The child layer's draw transform should refer to its new render surface.
541 // The screen-space transform, however, should still refer to the root.
542 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
ajumad9432e32015-11-30 19:43:44543 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32544 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
ajumab6aa1c62015-12-01 21:01:10545 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14546
[email protected]fb661802013-03-25 01:59:32547 // Because the grand_child is the only drawable content, the child's render
548 // surface will tighten its bounds to the grand_child. The scale at which the
549 // surface's subtree is drawn must be removed from the composite transform.
550 EXPECT_TRANSFORMATION_MATRIX_EQ(
551 surface_sublayer_composite_transform,
552 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14553
[email protected]fb661802013-03-25 01:59:32554 // The screen space is the same as the target since the child surface draws
555 // into the root.
556 EXPECT_TRANSFORMATION_MATRIX_EQ(
557 surface_sublayer_composite_transform,
558 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14559}
560
ajuma51d73f72015-10-19 19:43:58561TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) {
562 LayerImpl* root = root_layer();
563 LayerImpl* parent = AddChildToRoot<LayerImpl>();
564 LayerImpl* child = AddChild<LayerImpl>(parent);
565 LayerImpl* grand_child = AddChild<LayerImpl>(child);
566 grand_child->SetDrawsContent(true);
567
568 gfx::Transform identity_matrix;
569 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
570 gfx::PointF(), gfx::Size(100, 100), true, false,
571 true);
572
573 gfx::Transform parent_transform;
574 parent_transform.Translate(10.0, 10.0);
575
576 gfx::Transform child_transform;
577 child_transform.Rotate(45.0);
578
579 // child gets a render surface when surfaces are enabled.
580 SetLayerPropertiesForTesting(parent, parent_transform, gfx::Point3F(),
581 gfx::PointF(), gfx::Size(10, 10), true, false,
582 false);
583 SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(),
584 gfx::PointF(), gfx::Size(10, 10), true, false,
585 true);
586 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
587 gfx::PointF(2.0, 2.0), gfx::Size(20, 20), true,
588 false, false);
589
590 gfx::Transform expected_grand_child_screen_space_transform;
591 expected_grand_child_screen_space_transform.Translate(10.0, 10.0);
592 expected_grand_child_screen_space_transform.Rotate(45.0);
593 expected_grand_child_screen_space_transform.Translate(2.0, 2.0);
594
595 // First compute draw properties with separate surfaces enabled.
596 ExecuteCalculateDrawProperties(root);
597
598 // The grand child's draw transform should be its offset wrt the child.
599 gfx::Transform expected_grand_child_draw_transform;
600 expected_grand_child_draw_transform.Translate(2.0, 2.0);
601 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44602 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58603 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10604 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58605
606 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
607
608 // With separate surfaces disabled, the grand child's draw transform should be
609 // the same as its screen space transform.
610 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumad9432e32015-11-30 19:43:44611 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58612 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10613 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58614}
615
[email protected]989386c2013-07-18 21:37:23616TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
enne25dea3f2015-07-27 16:44:28617 LayerImpl* root = root_layer();
618 LayerImpl* parent = AddChildToRoot<LayerImpl>();
619 LayerImpl* child = AddChild<LayerImpl>(parent);
620 LayerImpl* grand_child = AddChild<LayerImpl>(child);
621 grand_child->SetDrawsContent(true);
622 scoped_ptr<LayerImpl> child_replica =
623 LayerImpl::Create(host_impl()->active_tree(), 100);
[email protected]d600df7d2013-08-03 02:34:28624
[email protected]fb661802013-03-25 01:59:32625 // One-time setup of root layer
626 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28627 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
628 gfx::PointF(), gfx::Size(1, 2), true, false,
629 true);
[email protected]fb661802013-03-25 01:59:32630
631 // Child is set up so that a new render surface should be created.
632 child->SetOpacity(0.5f);
633
634 gfx::Transform parent_layer_transform;
635 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
636 gfx::Transform parent_translation_to_anchor;
637 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32638 gfx::Transform parent_composite_transform =
639 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39640 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32641 gfx::Transform replica_layer_transform;
642 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
643 gfx::Vector2dF parent_composite_scale =
644 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
645 1.f);
646 gfx::Transform surface_sublayer_transform;
647 surface_sublayer_transform.Scale(parent_composite_scale.x(),
648 parent_composite_scale.y());
649 gfx::Transform replica_composite_transform =
650 parent_composite_transform * replica_layer_transform *
651 Inverse(surface_sublayer_transform);
enne25dea3f2015-07-27 16:44:28652 child_replica->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32653 // Child's render surface should not exist yet.
654 ASSERT_FALSE(child->render_surface());
655
enne25dea3f2015-07-27 16:44:28656 SetLayerPropertiesForTesting(parent, parent_layer_transform,
657 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
658 gfx::Size(10, 12), true, false, false);
659 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
660 gfx::PointF(), gfx::Size(16, 18), true, false,
661 true);
662 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
663 gfx::PointF(-0.5f, -0.5f), gfx::Size(1, 1), true,
664 false, false);
665 SetLayerPropertiesForTesting(child_replica.get(), replica_layer_transform,
666 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
667 false, false);
danakja04855a2015-11-18 20:39:10668 child->SetReplicaLayer(std::move(child_replica));
enne25dea3f2015-07-27 16:44:28669
670 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32671
672 // Render surface should have been created now.
673 ASSERT_TRUE(child->render_surface());
enne25dea3f2015-07-27 16:44:28674 ASSERT_EQ(child, child->render_target());
[email protected]fb661802013-03-25 01:59:32675
676 EXPECT_TRANSFORMATION_MATRIX_EQ(
677 replica_composite_transform,
678 child->render_target()->render_surface()->replica_draw_transform());
679 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57680 child->render_target()
681 ->render_surface()
[email protected]fb661802013-03-25 01:59:32682 ->replica_screen_space_transform());
683}
684
[email protected]989386c2013-07-18 21:37:23685TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32686 // This test creates a more complex tree and verifies it all at once. This
687 // covers the following cases:
688 // - layers that are described w.r.t. a render surface: should have draw
689 // transforms described w.r.t. that surface
690 // - A render surface described w.r.t. an ancestor render surface: should
691 // have a draw transform described w.r.t. that ancestor surface
692 // - Replicas of a render surface are described w.r.t. the replica's
693 // transform around its anchor, along with the surface itself.
694 // - Sanity check on recursion: verify transforms of layers described w.r.t.
695 // a render surface that is described w.r.t. an ancestor render surface.
696 // - verifying that each layer has a reference to the correct render surface
697 // and render target values.
698
enne25dea3f2015-07-27 16:44:28699 LayerImpl* root = root_layer();
700 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36701 parent->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28702 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36703 render_surface1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28704 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36705 render_surface2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28706 LayerImpl* child_of_root = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36707 child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28708 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36709 child_of_rs1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28710 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:36711 child_of_rs2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28712 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
jaydasika8640f9f2015-11-10 01:34:36713 grand_child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28714 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
715 grand_child_of_rs1->SetDrawsContent(true);
716 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
717 grand_child_of_rs2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32718
enne25dea3f2015-07-27 16:44:28719 scoped_ptr<LayerImpl> replica_of_rs1 =
720 LayerImpl::Create(host_impl()->active_tree(), 101);
721 scoped_ptr<LayerImpl> replica_of_rs2 =
722 LayerImpl::Create(host_impl()->active_tree(), 102);
[email protected]d600df7d2013-08-03 02:34:28723
[email protected]fb661802013-03-25 01:59:32724 // In combination with descendant draws content, opacity != 1 forces the layer
725 // to have a new render surface.
726 render_surface1->SetOpacity(0.5f);
727 render_surface2->SetOpacity(0.33f);
728
729 // One-time setup of root layer
730 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28731 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
732 gfx::PointF(), gfx::Size(1, 2), true, false,
733 true);
[email protected]fb661802013-03-25 01:59:32734
735 // All layers in the tree are initialized with an anchor at .25 and a size of
736 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39737 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32738 gfx::Transform translation_to_anchor;
739 translation_to_anchor.Translate(2.5, 0.0);
740 gfx::Transform layer_transform;
741 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32742 gfx::Transform replica_layer_transform;
743 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
744
745 gfx::Transform A =
746 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32747 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
748 Inverse(translation_to_anchor);
749
750 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39751 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32752 gfx::Transform surface1_sublayer_transform;
753 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
754 surface1_parent_transform_scale.y());
755
756 // SS1 = transform given to the subtree of render_surface1
757 gfx::Transform SS1 = surface1_sublayer_transform;
758 // S1 = transform to move from render_surface1 pixels to the layer space of
759 // the owning layer
760 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
761
762 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39763 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32764 gfx::Transform surface2_sublayer_transform;
765 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
766 surface2_parent_transform_scale.y());
767
768 // SS2 = transform given to the subtree of render_surface2
769 gfx::Transform SS2 = surface2_sublayer_transform;
770 // S2 = transform to move from render_surface2 pixels to the layer space of
771 // the owning layer
772 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
773
enne25dea3f2015-07-27 16:44:28774 SetLayerPropertiesForTesting(parent, layer_transform,
775 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
776 gfx::Size(10, 10), true, false, false);
777 SetLayerPropertiesForTesting(render_surface1, layer_transform,
778 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
779 gfx::Size(10, 10), true, false, true);
780 SetLayerPropertiesForTesting(render_surface2, layer_transform,
781 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
782 gfx::Size(10, 10), true, false, true);
783 SetLayerPropertiesForTesting(child_of_root, layer_transform,
784 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
785 gfx::Size(10, 10), true, false, false);
786 SetLayerPropertiesForTesting(child_of_rs1, layer_transform,
787 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
788 gfx::Size(10, 10), true, false, false);
789 SetLayerPropertiesForTesting(child_of_rs2, layer_transform,
790 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
791 gfx::Size(10, 10), true, false, false);
792 SetLayerPropertiesForTesting(grand_child_of_root, layer_transform,
793 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
794 gfx::Size(10, 10), true, false, false);
795 SetLayerPropertiesForTesting(grand_child_of_rs1, layer_transform,
796 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
797 gfx::Size(10, 10), true, false, false);
798 SetLayerPropertiesForTesting(grand_child_of_rs2, layer_transform,
799 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
800 gfx::Size(10, 10), true, false, false);
801 SetLayerPropertiesForTesting(replica_of_rs1.get(), replica_layer_transform,
802 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
803 gfx::Size(), true, false, false);
804 SetLayerPropertiesForTesting(replica_of_rs2.get(), replica_layer_transform,
805 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
806 gfx::Size(), true, false, false);
[email protected]fb661802013-03-25 01:59:32807
jaydasika5017a332016-03-31 01:06:22808 // We need to set parent on replica layers for property tree building.
809 replica_of_rs1->SetParent(render_surface1);
810 replica_of_rs2->SetParent(render_surface2);
danakja04855a2015-11-18 20:39:10811 render_surface1->SetReplicaLayer(std::move(replica_of_rs1));
812 render_surface2->SetReplicaLayer(std::move(replica_of_rs2));
enne25dea3f2015-07-27 16:44:28813 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32814
815 // Only layers that are associated with render surfaces should have an actual
816 // RenderSurface() value.
817 ASSERT_TRUE(root->render_surface());
818 ASSERT_FALSE(child_of_root->render_surface());
819 ASSERT_FALSE(grand_child_of_root->render_surface());
820
821 ASSERT_TRUE(render_surface1->render_surface());
822 ASSERT_FALSE(child_of_rs1->render_surface());
823 ASSERT_FALSE(grand_child_of_rs1->render_surface());
824
825 ASSERT_TRUE(render_surface2->render_surface());
826 ASSERT_FALSE(child_of_rs2->render_surface());
827 ASSERT_FALSE(grand_child_of_rs2->render_surface());
828
829 // Verify all render target accessors
enne25dea3f2015-07-27 16:44:28830 EXPECT_EQ(root, parent->render_target());
831 EXPECT_EQ(root, child_of_root->render_target());
832 EXPECT_EQ(root, grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32833
enne25dea3f2015-07-27 16:44:28834 EXPECT_EQ(render_surface1, render_surface1->render_target());
835 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
836 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32837
enne25dea3f2015-07-27 16:44:28838 EXPECT_EQ(render_surface2, render_surface2->render_target());
839 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
840 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32841
842 // Verify layer draw transforms note that draw transforms are described with
843 // respect to the nearest ancestor render surface but screen space transforms
844 // are described with respect to the root.
ajumad9432e32015-11-30 19:43:44845 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform());
846 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39847 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumad9432e32015-11-30 19:43:44848 grand_child_of_root->DrawTransform());
[email protected]fb661802013-03-25 01:59:32849
ajumad9432e32015-11-30 19:43:44850 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform());
851 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39852 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
ajumad9432e32015-11-30 19:43:44853 grand_child_of_rs1->DrawTransform());
[email protected]fb661802013-03-25 01:59:32854
ajumad9432e32015-11-30 19:43:44855 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform());
856 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39857 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
ajumad9432e32015-11-30 19:43:44858 grand_child_of_rs2->DrawTransform());
[email protected]fb661802013-03-25 01:59:32859
860 // Verify layer screen-space transforms
861 //
ajumab6aa1c62015-12-01 21:01:10862 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform());
863 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform());
864 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
865 grand_child_of_root->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32866
[email protected]baf64d062014-02-16 22:10:39867 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
ajumab6aa1c62015-12-01 21:01:10868 render_surface1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39869 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10870 child_of_rs1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39871 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10872 grand_child_of_rs1->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32873
[email protected]baf64d062014-02-16 22:10:39874 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10875 render_surface2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39876 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10877 child_of_rs2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39878 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10879 grand_child_of_rs2->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32880
881 // Verify render surface transforms.
882 //
883 // Draw transform of render surface 1 is described with respect to root.
884 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39885 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32886 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39887 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:32888 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39889 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32890 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39891 A * R * S1,
[email protected]fb661802013-03-25 01:59:32892 render_surface1->render_surface()->replica_screen_space_transform());
893 // Draw transform of render surface 2 is described with respect to render
894 // surface 1.
895 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39896 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32897 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39898 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:32899 render_surface2->render_surface()->replica_draw_transform());
900 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39901 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:32902 render_surface2->render_surface()->screen_space_transform());
903 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39904 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:32905 render_surface2->render_surface()->replica_screen_space_transform());
906
907 // Sanity check. If these fail there is probably a bug in the test itself. It
908 // is expected that we correctly set up transforms so that the y-component of
909 // the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:10910 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:26911 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:10912 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32913 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10914 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32915
[email protected]803f6b52013-09-12 00:51:26916 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:10917 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
918 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32919 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10920 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32921
[email protected]803f6b52013-09-12 00:51:26922 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:10923 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
924 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32925 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10926 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32927}
928
[email protected]989386c2013-07-18 21:37:23929TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:32930 // For layers that flatten their subtree, there should be an orthographic
931 // projection (for x and y values) in the middle of the transform sequence.
932 // Note that the way the code is currently implemented, it is not expected to
933 // use a canonical orthographic projection.
934
enne25dea3f2015-07-27 16:44:28935 LayerImpl* root = root_layer();
936 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36937 child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28938 LayerImpl* grand_child = AddChild<LayerImpl>(child);
939 grand_child->SetDrawsContent(true);
940 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
941 great_grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32942
943 gfx::Transform rotation_about_y_axis;
944 rotation_about_y_axis.RotateAboutYAxis(30.0);
945
946 const gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28947 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
948 gfx::PointF(), gfx::Size(100, 100), true, false,
949 true);
950 SetLayerPropertiesForTesting(child, rotation_about_y_axis, gfx::Point3F(),
951 gfx::PointF(), gfx::Size(10, 10), true, false,
952 true);
953 SetLayerPropertiesForTesting(grand_child, rotation_about_y_axis,
ajumad0d64422015-03-14 04:20:08954 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
enne25dea3f2015-07-27 16:44:28955 true, false, false);
956 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
957 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
958 true, false, false);
[email protected]d600df7d2013-08-03 02:34:28959
[email protected]fb661802013-03-25 01:59:32960 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:57961 ASSERT_TRUE(root->should_flatten_transform());
962 ASSERT_TRUE(child->should_flatten_transform());
963 ASSERT_TRUE(grand_child->should_flatten_transform());
ajumad0d64422015-03-14 04:20:08964 ASSERT_TRUE(great_grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:32965
966 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
967 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
968 gfx::Transform expected_grand_child_draw_transform =
969 rotation_about_y_axis; // draws onto child's render surface
970 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
971 flattened_rotation_about_y.FlattenTo2d();
972 gfx::Transform expected_grand_child_screen_space_transform =
973 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:08974 gfx::Transform expected_great_grand_child_draw_transform =
975 flattened_rotation_about_y;
976 gfx::Transform expected_great_grand_child_screen_space_transform =
977 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:32978
enne25dea3f2015-07-27 16:44:28979 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32980
981 // The child's draw transform should have been taken by its surface.
982 ASSERT_TRUE(child->render_surface());
983 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
984 child->render_surface()->draw_transform());
985 EXPECT_TRANSFORMATION_MATRIX_EQ(
986 expected_child_screen_space_transform,
987 child->render_surface()->screen_space_transform());
ajumad9432e32015-11-30 19:43:44988 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32989 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10990 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32991 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44992 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32993 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10994 grand_child->ScreenSpaceTransform());
ajumad0d64422015-03-14 04:20:08995 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44996 great_grand_child->DrawTransform());
ajumad0d64422015-03-14 04:20:08997 EXPECT_TRANSFORMATION_MATRIX_EQ(
998 expected_great_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10999 great_grand_child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321000}
1001
ajumadbd92cb2015-07-16 13:47:061002TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
loyso0940d412016-03-14 01:30:311003 scoped_refptr<Layer> root = Layer::Create();
1004 scoped_refptr<Layer> child = Layer::Create();
ajumadbd92cb2015-07-16 13:47:061005 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loyso0940d412016-03-14 01:30:311006 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumadbd92cb2015-07-16 13:47:061007
1008 gfx::Transform child_transform;
1009 child_transform.Translate(50.0, 50.0);
1010 child_transform.RotateAboutZAxis(30.0);
1011
1012 gfx::Transform grand_child_transform;
1013 grand_child_transform.RotateAboutYAxis(90.0);
1014
1015 const gfx::Transform identity_matrix;
1016 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
1017 gfx::PointF(), gfx::Size(200, 200), true, false);
1018 SetLayerPropertiesForTesting(child.get(), child_transform, gfx::Point3F(),
1019 gfx::PointF(), gfx::Size(10, 10), true, false);
1020 SetLayerPropertiesForTesting(grand_child.get(), grand_child_transform,
1021 gfx::Point3F(), gfx::PointF(),
1022 gfx::Size(100, 100), true, false);
1023
1024 root->AddChild(child);
1025 child->AddChild(grand_child);
1026 grand_child->SetShouldFlattenTransform(false);
1027
1028 host()->SetRootLayer(root);
1029
1030 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
1031
1032 // Mapping grand_child's bounds to target space produces a non-empty rect
1033 // that is fully contained within the target's bounds, so grand_child should
1034 // be considered fully visible.
1035 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
jaydasika74bf516f2016-04-01 19:48:151036 grand_child->visible_layer_rect_for_testing());
ajumadbd92cb2015-07-16 13:47:061037}
1038
[email protected]989386c2013-07-18 21:37:231039TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321040 // A layer that is empty in one axis, but not the other, was accidentally
1041 // skipping a necessary translation. Without that translation, the coordinate
1042 // space of the layer's draw transform is incorrect.
1043 //
1044 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1045 // but if that layer becomes a render surface, then its draw transform is
1046 // implicitly inherited by the rest of the subtree, which then is positioned
1047 // incorrectly as a result.
1048
ennec1332992015-08-24 19:45:091049 LayerImpl* root = root_layer();
1050 LayerImpl* child = AddChild<LayerImpl>(root);
1051 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1052 grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321053
1054 // The child height is zero, but has non-zero width that should be accounted
1055 // for while computing draw transforms.
1056 const gfx::Transform identity_matrix;
ennec1332992015-08-24 19:45:091057 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1058 gfx::PointF(), gfx::Size(100, 100), true, false,
1059 true);
1060 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1061 gfx::PointF(), gfx::Size(10, 0), true, false,
1062 true);
1063 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1064 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321065 false);
1066
ennec1332992015-08-24 19:45:091067 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321068
ennec1332992015-08-24 19:45:091069 ASSERT_TRUE(child->has_render_surface());
[email protected]fb661802013-03-25 01:59:321070 // This is the real test, the rest are sanity checks.
1071 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1072 child->render_surface()->draw_transform());
ajumad9432e32015-11-30 19:43:441073 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321074 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
ajumad9432e32015-11-30 19:43:441075 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321076}
1077
jaydasika9bbee9b2016-01-13 00:36:481078TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) {
1079 const gfx::Transform identity_matrix;
1080 LayerImpl* root = root_layer();
1081 LayerImpl* render_surface = AddChild<LayerImpl>(root);
1082 LayerImpl* child = AddChild<LayerImpl>(render_surface);
1083 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1084
1085 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1086 gfx::PointF(), gfx::Size(100, 100), true, false,
1087 true);
1088 gfx::Transform translate;
1089 translate.Translate3d(5, 5, 5);
1090 SetLayerPropertiesForTesting(render_surface, translate, gfx::Point3F(),
1091 gfx::PointF(), gfx::Size(100, 100), true, false,
1092 true);
1093 SetLayerPropertiesForTesting(child, translate, gfx::Point3F(), gfx::PointF(),
1094 gfx::Size(100, 100), true, false, false);
1095 SetLayerPropertiesForTesting(grand_child, translate, gfx::Point3F(),
1096 gfx::PointF(), gfx::Size(100, 100), true, false,
1097 false);
1098 grand_child->SetDrawsContent(true);
1099
1100 // render_surface will have a sublayer scale because of device scale factor.
1101 float device_scale_factor = 2.0f;
1102 LayerImplList render_surface_layer_list_impl;
1103 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
1104 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1105 root, root->bounds(), translate, &render_surface_layer_list_impl,
1106 root->layer_tree_impl()->current_render_surface_list_id());
1107 inputs.device_scale_factor = device_scale_factor;
1108 inputs.property_trees->needs_rebuild = true;
1109 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1110
1111 // Between grand_child and render_surface, we translate by (10, 10) and scale
1112 // by a factor of 2.
1113 gfx::Vector2dF expected_translation(20.0f, 20.0f);
1114 EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(),
1115 expected_translation);
1116}
1117
[email protected]989386c2013-07-18 21:37:231118TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321119 // Transformations applied at the root of the tree should be forwarded
1120 // to child layers instead of applied to the root RenderSurface.
1121 const gfx::Transform identity_matrix;
enned3f61fb02015-08-18 22:54:391122 LayerImpl* root = root_layer();
1123 root->SetDrawsContent(true);
1124 LayerImpl* child = AddChild<LayerImpl>(root);
1125 child->SetDrawsContent(true);
[email protected]f224cc92013-06-06 23:23:321126
enned3f61fb02015-08-18 22:54:391127 child->SetScrollClipLayer(root->id());
[email protected]d600df7d2013-08-03 02:34:281128
enned3f61fb02015-08-18 22:54:391129 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1130 gfx::PointF(), gfx::Size(20, 20), true, false,
1131 true);
1132 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1133 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]f224cc92013-06-06 23:23:321134 false);
1135
[email protected]f224cc92013-06-06 23:23:321136 gfx::Transform translate;
1137 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231138 {
enned3f61fb02015-08-18 22:54:391139 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441140 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391141 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441142 root, root->bounds(), translate, &render_surface_layer_list_impl,
1143 root->layer_tree_impl()->current_render_surface_list_id());
vollick5057e1e2015-04-17 19:12:321144 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531145 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231146 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1147 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1148 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1149 }
[email protected]f224cc92013-06-06 23:23:321150
1151 gfx::Transform scale;
1152 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231153 {
enned3f61fb02015-08-18 22:54:391154 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441155 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391156 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441157 root, root->bounds(), scale, &render_surface_layer_list_impl,
1158 root->layer_tree_impl()->current_render_surface_list_id());
vollick5057e1e2015-04-17 19:12:321159 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531160 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231161 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1162 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1163 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1164 }
[email protected]f224cc92013-06-06 23:23:321165
1166 gfx::Transform rotate;
1167 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231168 {
enned3f61fb02015-08-18 22:54:391169 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441170 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391171 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441172 root, root->bounds(), rotate, &render_surface_layer_list_impl,
1173 root->layer_tree_impl()->current_render_surface_list_id());
vollick5057e1e2015-04-17 19:12:321174 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531175 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231176 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1177 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1178 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1179 }
[email protected]f224cc92013-06-06 23:23:321180
1181 gfx::Transform composite;
1182 composite.ConcatTransform(translate);
1183 composite.ConcatTransform(scale);
1184 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231185 {
enned3f61fb02015-08-18 22:54:391186 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441187 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391188 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441189 root, root->bounds(), composite, &render_surface_layer_list_impl,
1190 root->layer_tree_impl()->current_render_surface_list_id());
vollick5057e1e2015-04-17 19:12:321191 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531192 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231193 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1194 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1195 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1196 }
[email protected]f224cc92013-06-06 23:23:321197
[email protected]9781afa2013-07-17 23:15:321198 // Verify it composes correctly with device scale.
1199 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231200
1201 {
enned3f61fb02015-08-18 22:54:391202 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441203 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391204 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441205 root, root->bounds(), translate, &render_surface_layer_list_impl,
1206 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:531207 inputs.device_scale_factor = device_scale_factor;
vollick5057e1e2015-04-17 19:12:321208 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531209 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231210 gfx::Transform device_scaled_translate = translate;
1211 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1212 EXPECT_EQ(device_scaled_translate,
1213 root->draw_properties().target_space_transform);
1214 EXPECT_EQ(device_scaled_translate,
1215 child->draw_properties().target_space_transform);
1216 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1217 }
[email protected]9781afa2013-07-17 23:15:321218
1219 // Verify it composes correctly with page scale.
1220 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231221
1222 {
enned3f61fb02015-08-18 22:54:391223 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441224 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391225 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441226 root, root->bounds(), translate, &render_surface_layer_list_impl,
1227 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:531228 inputs.page_scale_factor = page_scale_factor;
enned3f61fb02015-08-18 22:54:391229 inputs.page_scale_layer = root;
vollick5057e1e2015-04-17 19:12:321230 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531231 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231232 gfx::Transform page_scaled_translate = translate;
1233 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
enne6394d5b42015-05-26 22:23:111234 EXPECT_EQ(page_scaled_translate,
1235 root->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231236 EXPECT_EQ(page_scaled_translate,
1237 child->draw_properties().target_space_transform);
1238 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1239 }
[email protected]9781afa2013-07-17 23:15:321240
[email protected]f224cc92013-06-06 23:23:321241 // Verify that it composes correctly with transforms directly on root layer.
1242 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231243
1244 {
enned3f61fb02015-08-18 22:54:391245 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441246 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391247 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441248 root, root->bounds(), composite, &render_surface_layer_list_impl,
1249 root->layer_tree_impl()->current_render_surface_list_id());
enned3f61fb02015-08-18 22:54:391250 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531251 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231252 gfx::Transform compositeSquared = composite;
1253 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261254 EXPECT_TRANSFORMATION_MATRIX_EQ(
1255 compositeSquared, root->draw_properties().target_space_transform);
1256 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391257 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231258 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1259 }
[email protected]f224cc92013-06-06 23:23:321260}
1261
[email protected]989386c2013-07-18 21:37:231262TEST_F(LayerTreeHostCommonTest,
1263 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
enneea850232015-07-27 16:43:121264 LayerImpl* parent = root_layer();
1265 parent->SetMasksToBounds(true);
1266 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1267 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1268 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:281269
[email protected]fb661802013-03-25 01:59:321270 const gfx::Transform identity_matrix;
enneea850232015-07-27 16:43:121271 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1272 gfx::PointF(), gfx::Size(10, 10), true, false,
1273 true);
1274 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1275 gfx::PointF(), gfx::Size(10, 10), true, false,
1276 true);
1277 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1278 gfx::PointF(30.f, 30.f), gfx::Size(10, 10), true,
1279 false, false);
[email protected]fb661802013-03-25 01:59:321280
enneea850232015-07-27 16:43:121281 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321282
1283 // The child layer's content is entirely outside the parent's clip rect, so
1284 // the intermediate render surface should not be listed here, even if it was
1285 // forced to be created. Render surfaces without children or visible content
1286 // are unexpected at draw time (e.g. we might try to create a content texture
1287 // of size 0).
1288 ASSERT_TRUE(parent->render_surface());
enneea850232015-07-27 16:43:121289 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:321290}
1291
[email protected]989386c2013-07-18 21:37:231292TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
enne03b0e9a2015-06-19 00:08:021293 LayerImpl* parent = root_layer();
1294 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
1295 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1296 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:281297
[email protected]fb661802013-03-25 01:59:321298 const gfx::Transform identity_matrix;
enne03b0e9a2015-06-19 00:08:021299 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1300 gfx::PointF(), gfx::Size(10, 10), true, false,
1301 true);
1302 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1303 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321304 false);
[email protected]fb661802013-03-25 01:59:321305 render_surface1->SetOpacity(0.f);
1306
enne03b0e9a2015-06-19 00:08:021307 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:441308 parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enne03b0e9a2015-06-19 00:08:021309 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441310 parent, parent->bounds(), &render_surface_layer_list,
1311 parent->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:531312 inputs.can_adjust_raster_scales = true;
1313 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321314
1315 // Since the layer is transparent, render_surface1->render_surface() should
1316 // not have gotten added anywhere. Also, the drawable content rect should not
1317 // have been extended by the children.
1318 ASSERT_TRUE(parent->render_surface());
1319 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1320 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231321 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321322 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1323}
1324
hendrikwc266f7b2015-08-21 23:41:341325TEST_F(LayerTreeHostCommonTest,
1326 RenderSurfaceListForTransparentChildWithBackgroundFilter) {
1327 LayerImpl* parent = root_layer();
1328 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
1329 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1330 child->SetDrawsContent(true);
1331
1332 const gfx::Transform identity_matrix;
1333 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1334 gfx::PointF(), gfx::Size(10, 10), true, false,
1335 true);
1336 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1337 gfx::PointF(), gfx::Size(10, 10), true, false,
1338 true);
1339 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1340 gfx::PointF(), gfx::Size(10, 10), true, false,
1341 false);
1342 render_surface1->SetOpacity(0.f);
jaydasika86654512016-01-27 17:05:071343 render_surface1->SetDrawsContent(true);
1344 child->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341345 FilterOperations filters;
1346 filters.Append(FilterOperation::CreateBlurFilter(1.5f));
1347 render_surface1->SetBackgroundFilters(filters);
1348
jaydasika369c24b2016-04-06 23:44:161349 {
1350 LayerImplList render_surface_layer_list;
1351 parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
1352 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1353 parent, parent->bounds(), &render_surface_layer_list,
1354 parent->layer_tree_impl()->current_render_surface_list_id());
1355 inputs.can_adjust_raster_scales = true;
1356 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1357 EXPECT_EQ(2U, render_surface_layer_list.size());
1358 }
hendrikwc266f7b2015-08-21 23:41:341359 // The layer is fully transparent, but has a background filter, so it
jaydasika369c24b2016-04-06 23:44:161360 // shouldn't be skipped and should be drawn.
hendrikwc266f7b2015-08-21 23:41:341361 ASSERT_TRUE(parent->render_surface());
1362 EXPECT_EQ(1U, parent->render_surface()->layer_list().size());
jaydasika8640f9f2015-11-10 01:34:361363 EXPECT_EQ(gfx::RectF(0, 0, 10, 10),
1364 parent->render_surface()->DrawableContentRect());
jaydasika369c24b2016-04-06 23:44:161365 EffectTree& effect_tree =
1366 parent->layer_tree_impl()->property_trees()->effect_tree;
1367 EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index());
1368 EXPECT_TRUE(node->data.is_drawn);
1369
1370 // When parent is transparent, the layer should not be drawn.
1371 parent->OnOpacityAnimated(0.f);
1372 render_surface1->OnOpacityAnimated(1.f);
1373 {
1374 LayerImplList render_surface_layer_list;
1375 parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
1376 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1377 parent, parent->bounds(), &render_surface_layer_list,
1378 parent->layer_tree_impl()->current_render_surface_list_id());
1379 inputs.can_adjust_raster_scales = true;
1380 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1381 }
1382
1383 node = effect_tree.Node(render_surface1->effect_tree_index());
1384 EXPECT_FALSE(node->data.is_drawn);
hendrikwc266f7b2015-08-21 23:41:341385}
1386
senorblanco38858c52016-01-20 23:15:001387TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) {
1388 LayerImpl* root = root_layer();
1389 LayerImpl* parent = AddChild<LayerImpl>(root);
1390 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1391 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1392 child1->SetDrawsContent(true);
1393 child2->SetDrawsContent(true);
1394
1395 const gfx::Transform identity_matrix;
1396 gfx::Transform scale_matrix;
1397 scale_matrix.Scale(2.0f, 2.0f);
1398 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1399 gfx::PointF(), gfx::Size(100, 100), true, false,
1400 true);
1401 SetLayerPropertiesForTesting(parent, scale_matrix, gfx::Point3F(),
1402 gfx::PointF(), gfx::Size(), true, false, true);
1403 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1404 gfx::PointF(0, 0), gfx::Size(25, 25), true,
1405 false, true);
1406 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1407 gfx::PointF(25, 25), gfx::Size(25, 25), true,
1408 false, true);
1409 FilterOperations filters;
1410 filters.Append(FilterOperation::CreateBlurFilter(10.0f));
1411 parent->SetFilters(filters);
1412
1413 LayerImplList render_surface_layer_list;
1414 parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
1415 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
1416 root, root->bounds(), &render_surface_layer_list,
1417 root->layer_tree_impl()->current_render_surface_list_id());
1418 inputs.can_adjust_raster_scales = true;
1419 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1420
1421 ASSERT_TRUE(parent->render_surface());
1422 EXPECT_EQ(2U, parent->render_surface()->layer_list().size());
1423 EXPECT_EQ(4U, render_surface_layer_list.size());
1424 EXPECT_EQ(gfx::RectF(-29, -29, 158, 158),
1425 parent->render_surface()->DrawableContentRect());
1426}
1427
rosca948d29d2014-11-09 10:25:131428TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
enned5f4ddd2015-08-18 16:50:061429 LayerImpl* parent = root_layer();
1430 LayerImpl* child = AddChild<LayerImpl>(parent);
1431 child->SetDrawsContent(true);
rosca948d29d2014-11-09 10:25:131432
1433 const gfx::Transform identity_matrix;
1434 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
enned5f4ddd2015-08-18 16:50:061435 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1436 gfx::PointF(), gfx::Size(10, 10), true, false,
1437 true);
1438 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1439 gfx::PointF(), gfx::Size(10, 10), true, false,
1440 true);
rosca948d29d2014-11-09 10:25:131441
rosca948d29d2014-11-09 10:25:131442 child->SetBlendMode(blend_mode);
weiliangc451b818f2015-07-24 17:52:291443 child->SetOpacity(0.5f);
rosca948d29d2014-11-09 10:25:131444
enned5f4ddd2015-08-18 16:50:061445 ExecuteCalculateDrawProperties(parent);
rosca948d29d2014-11-09 10:25:131446
1447 // Since the child layer has a blend mode other than normal, it should get
1448 // its own render surface. Also, layer's draw_properties should contain the
1449 // default blend mode, since the render surface becomes responsible for
1450 // applying the blend mode.
1451 ASSERT_TRUE(child->render_surface());
weiliangc451b818f2015-07-24 17:52:291452 EXPECT_EQ(1.0f, child->draw_opacity());
1453 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
jaydasika92239dc2015-08-15 02:59:261454 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode());
rosca948d29d2014-11-09 10:25:131455}
1456
jaydasikafbdb86e2016-01-21 18:57:511457TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) {
1458 LayerImpl* root = root_layer();
1459 LayerImpl* surface1 = AddChildToRoot<LayerImpl>();
1460 LayerImpl* not_surface = AddChild<LayerImpl>(surface1);
1461 LayerImpl* surface2 = AddChild<LayerImpl>(not_surface);
1462
1463 const gfx::Transform identity_matrix;
1464 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1465 gfx::PointF(), gfx::Size(10, 10), true, false,
1466 true);
1467 SetLayerPropertiesForTesting(surface1, identity_matrix, gfx::Point3F(),
1468 gfx::PointF(), gfx::Size(10, 10), true, false,
1469 true);
1470 SetLayerPropertiesForTesting(not_surface, identity_matrix, gfx::Point3F(),
1471 gfx::PointF(), gfx::Size(10, 10), true, false,
1472 false);
1473 SetLayerPropertiesForTesting(surface2, identity_matrix, gfx::Point3F(),
1474 gfx::PointF(), gfx::Size(10, 10), true, false,
1475 true);
1476 surface1->SetDrawsContent(true);
1477 surface2->SetDrawsContent(true);
1478
1479 surface1->SetOpacity(0.5f);
1480 not_surface->SetOpacity(0.5f);
1481 surface2->SetOpacity(0.5f);
1482
1483 ExecuteCalculateDrawProperties(root);
1484
1485 ASSERT_TRUE(surface1->render_surface());
1486 ASSERT_FALSE(not_surface->render_surface());
1487 ASSERT_TRUE(surface2->render_surface());
1488 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity());
1489 // surface2's draw opacity should include the opacity of not-surface and
1490 // itself, but not the opacity of surface1.
1491 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity());
1492}
1493
ajuma51d73f72015-10-19 19:43:581494TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) {
1495 // Tests that when separate surfaces are disabled, a layer's draw opacity is
1496 // the product of all ancestor layer opacties and the layer's own opacity.
1497 // (Rendering will still be incorrect in situations where we really do need
1498 // surfaces to apply opacity, such as when we have overlapping layers with an
1499 // ancestor whose opacity is <1.)
1500 LayerImpl* root = root_layer();
1501 LayerImpl* parent = AddChild<LayerImpl>(root);
1502 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1503 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1504 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1505 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1506 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1507
1508 root->SetDrawsContent(true);
1509 parent->SetDrawsContent(true);
1510 child1->SetDrawsContent(true);
1511 child2->SetDrawsContent(true);
1512 grand_child->SetDrawsContent(true);
1513 leaf_node1->SetDrawsContent(true);
1514 leaf_node2->SetDrawsContent(true);
1515
1516 const gfx::Transform identity_matrix;
1517
1518 // child1 and grand_child get render surfaces when surfaces are enabled.
1519 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1520 gfx::PointF(), gfx::Size(100, 100), true, false,
1521 true);
1522 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1523 gfx::PointF(), gfx::Size(100, 100), true, false,
1524 false);
1525 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1526 gfx::PointF(), gfx::Size(100, 100), true, false,
1527 true);
1528 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1529 gfx::PointF(), gfx::Size(100, 100), true, false,
1530 false);
1531 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1532 gfx::PointF(), gfx::Size(100, 100), true, false,
1533 true);
1534 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1535 gfx::PointF(), gfx::Size(100, 100), true, false,
1536 false);
1537 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1538 gfx::PointF(), gfx::Size(100, 100), true, false,
1539 false);
1540
1541 child1->SetOpacity(0.5f);
1542 grand_child->SetOpacity(0.5f);
1543 leaf_node1->SetOpacity(0.5f);
1544 leaf_node2->SetOpacity(0.5f);
1545
1546 // With surfaces enabled, each layer's draw opacity is the product of layer
1547 // opacities on the path from the layer to its render target, not including
1548 // the opacity of the layer that owns the target surface (since that opacity
1549 // is applied by the surface).
1550 ExecuteCalculateDrawProperties(root);
1551 EXPECT_EQ(1.f, root->draw_opacity());
1552 EXPECT_EQ(1.f, parent->draw_opacity());
1553 EXPECT_EQ(1.f, child1->draw_opacity());
1554 EXPECT_EQ(1.f, child2->draw_opacity());
1555 EXPECT_EQ(1.f, grand_child->draw_opacity());
1556 EXPECT_EQ(0.5f, leaf_node1->draw_opacity());
1557 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1558
1559 // With surfaces disabled, each layer's draw opacity is the product of layer
1560 // opacities on the path from the layer to the root.
1561 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1562 EXPECT_EQ(1.f, root->draw_opacity());
1563 EXPECT_EQ(1.f, parent->draw_opacity());
1564 EXPECT_EQ(0.5f, child1->draw_opacity());
1565 EXPECT_EQ(1.f, child2->draw_opacity());
1566 EXPECT_EQ(0.25f, grand_child->draw_opacity());
1567 EXPECT_EQ(0.125f, leaf_node1->draw_opacity());
1568 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1569}
1570
[email protected]989386c2013-07-18 21:37:231571TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
weiliangcc154ce22015-12-09 03:39:261572 LayerImpl* parent = root_layer();
1573 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1574 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
weiliangceffae0462015-12-08 23:17:261575
1576 const gfx::Transform identity_matrix;
weiliangcc154ce22015-12-09 03:39:261577 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
weiliangceffae0462015-12-08 23:17:261578 gfx::PointF(), gfx::Size(10, 10), true, false);
weiliangcc154ce22015-12-09 03:39:261579 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1580 gfx::PointF(), gfx::Size(10, 10), true, false);
1581 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
weiliangceffae0462015-12-08 23:17:261582 gfx::PointF(), gfx::Size(10, 10), true, false);
1583
weiliangcc154ce22015-12-09 03:39:261584 child->SetDrawsContent(true);
1585 render_surface1->SetForceRenderSurface(true);
weiliangceffae0462015-12-08 23:17:261586
[email protected]989386c2013-07-18 21:37:231587 {
weiliangcc154ce22015-12-09 03:39:261588 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:321589
[email protected]989386c2013-07-18 21:37:231590 // The root layer always creates a render surface
ennec1332992015-08-24 19:45:091591 EXPECT_TRUE(parent->has_render_surface());
1592 EXPECT_TRUE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231593 }
[email protected]fb661802013-03-25 01:59:321594
[email protected]989386c2013-07-18 21:37:231595 {
[email protected]989386c2013-07-18 21:37:231596 render_surface1->SetForceRenderSurface(false);
weiliangcc154ce22015-12-09 03:39:261597 render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true;
1598 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
ennec1332992015-08-24 19:45:091599 EXPECT_TRUE(parent->has_render_surface());
1600 EXPECT_FALSE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231601 }
[email protected]fb661802013-03-25 01:59:321602}
1603
ajuma246190a2015-03-11 20:56:031604TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1605 // Render surfaces act as a flattening point for their subtree, so should
1606 // always flatten the target-to-screen space transform seen by descendants.
1607
enne1a79c5542015-08-18 19:43:571608 LayerImpl* root = root_layer();
1609 LayerImpl* parent = AddChild<LayerImpl>(root);
1610 LayerImpl* child = AddChild<LayerImpl>(parent);
1611 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1612
1613 child->SetDrawsContent(true);
1614 grand_child->SetDrawsContent(true);
ajuma246190a2015-03-11 20:56:031615
1616 gfx::Transform rotation_about_y_axis;
1617 rotation_about_y_axis.RotateAboutYAxis(30.0);
1618 // Make |parent| have a render surface.
1619 parent->SetOpacity(0.9f);
1620
1621 const gfx::Transform identity_matrix;
enne1a79c5542015-08-18 19:43:571622 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1623 gfx::PointF(), gfx::Size(100, 100), true, false,
1624 true);
1625 SetLayerPropertiesForTesting(parent, rotation_about_y_axis, gfx::Point3F(),
1626 gfx::PointF(), gfx::Size(10, 10), true, false,
1627 true);
1628 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1629 gfx::PointF(), gfx::Size(10, 10), true, false,
1630 false);
1631 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1632 gfx::PointF(), gfx::Size(10, 10), true, false,
1633 false);
ajuma246190a2015-03-11 20:56:031634
1635 grand_child->SetShouldFlattenTransform(false);
1636
ajuma246190a2015-03-11 20:56:031637 // Only grand_child should preserve 3d.
1638 EXPECT_TRUE(root->should_flatten_transform());
1639 EXPECT_TRUE(parent->should_flatten_transform());
1640 EXPECT_TRUE(child->should_flatten_transform());
1641 EXPECT_FALSE(grand_child->should_flatten_transform());
1642
1643 gfx::Transform expected_child_draw_transform = identity_matrix;
1644 gfx::Transform expected_grand_child_draw_transform = identity_matrix;
1645
1646 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1647 flattened_rotation_about_y.FlattenTo2d();
1648
enne1a79c5542015-08-18 19:43:571649 ExecuteCalculateDrawProperties(root);
ajuma246190a2015-03-11 20:56:031650
1651 EXPECT_TRUE(parent->render_surface());
1652 EXPECT_FALSE(child->render_surface());
1653 EXPECT_FALSE(grand_child->render_surface());
1654
ajumad9432e32015-11-30 19:43:441655 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
ajuma246190a2015-03-11 20:56:031656 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
ajumad9432e32015-11-30 19:43:441657 grand_child->DrawTransform());
ajuma246190a2015-03-11 20:56:031658
1659 // The screen-space transform inherited by |child| and |grand_child| should
1660 // have been flattened at their render target. In particular, the fact that
1661 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1662 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101663 child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031664 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101665 grand_child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031666}
1667
[email protected]989386c2013-07-18 21:37:231668TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321669 // The entire subtree of layers that are outside the clip rect should be
1670 // culled away, and should not affect the render_surface_layer_list.
1671 //
1672 // The test tree is set up as follows:
1673 // - all layers except the leaf_nodes are forced to be a new render surface
1674 // that have something to draw.
1675 // - parent is a large container layer.
1676 // - child has masksToBounds=true to cause clipping.
1677 // - grand_child is positioned outside of the child's bounds
1678 // - great_grand_child is also kept outside child's bounds.
1679 //
1680 // In this configuration, grand_child and great_grand_child are completely
1681 // outside the clip rect, and they should never get scheduled on the list of
1682 // render surfaces.
[email protected]fb661802013-03-25 01:59:321683
weiliangcfb3d5eaa2015-07-28 23:54:571684 LayerImpl* parent = root_layer();
1685 LayerImpl* child = AddChildToRoot<LayerImpl>();
1686 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1687 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
[email protected]d600df7d2013-08-03 02:34:281688
[email protected]fb661802013-03-25 01:59:321689 // leaf_node1 ensures that parent and child are kept on the
1690 // render_surface_layer_list, even though grand_child and great_grand_child
1691 // should be clipped.
weiliangcfb3d5eaa2015-07-28 23:54:571692 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
1693 leaf_node1->SetDrawsContent(true);
1694 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
1695 leaf_node2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321696
weiliangcfb3d5eaa2015-07-28 23:54:571697 const gfx::Transform identity_matrix;
1698
1699 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1700 gfx::PointF(), gfx::Size(500, 500), true, false,
1701 true);
1702 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1703 gfx::PointF(), gfx::Size(20, 20), true, false,
1704 true);
1705 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1706 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1707 false, false);
1708 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
1709 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1710 true, false, false);
1711 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1712 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:321713 false);
weiliangcfb3d5eaa2015-07-28 23:54:571714 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1715 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]fb661802013-03-25 01:59:321716 false);
1717
1718 child->SetMasksToBounds(true);
1719 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321720 grand_child->SetOpacity(0.5f);
1721 great_grand_child->SetOpacity(0.4f);
1722
weiliangcfb3d5eaa2015-07-28 23:54:571723 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321724
weiliangcfb3d5eaa2015-07-28 23:54:571725 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
1726 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id());
1727 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id());
[email protected]fb661802013-03-25 01:59:321728}
1729
[email protected]989386c2013-07-18 21:37:231730TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321731 // When a render surface has a clip rect, it is used to clip the content rect
weiliangcfb3d5eaa2015-07-28 23:54:571732 // of the surface.
[email protected]fb661802013-03-25 01:59:321733
1734 // The test tree is set up as follows:
1735 // - parent is a container layer that masksToBounds=true to cause clipping.
1736 // - child is a render surface, which has a clip rect set to the bounds of
1737 // the parent.
1738 // - grand_child is a render surface, and the only visible content in child.
1739 // It is positioned outside of the clip rect from parent.
1740
1741 // In this configuration, grand_child should be outside the clipped
1742 // content rect of the child, making grand_child not appear in the
weiliangcfb3d5eaa2015-07-28 23:54:571743 // render_surface_layer_list.
1744
1745 LayerImpl* parent = root_layer();
1746 LayerImpl* child = AddChildToRoot<LayerImpl>();
1747 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1748 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
1749 leaf_node->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321750
1751 const gfx::Transform identity_matrix;
[email protected]fb661802013-03-25 01:59:321752
weiliangcfb3d5eaa2015-07-28 23:54:571753 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1754 gfx::PointF(), gfx::Size(100, 100), true, false,
1755 true);
1756 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1757 gfx::PointF(), gfx::Size(20, 20), true, false,
1758 true);
1759 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1760 gfx::PointF(200.f, 200.f), gfx::Size(10, 10),
1761 true, false, true);
1762 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
1763 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321764 false);
1765
1766 parent->SetMasksToBounds(true);
1767 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321768 grand_child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321769
weiliangcfb3d5eaa2015-07-28 23:54:571770 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321771
weiliangcfb3d5eaa2015-07-28 23:54:571772 // We should cull child and grand_child from the
1773 // render_surface_layer_list.
1774 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
1775 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id());
[email protected]fb661802013-03-25 01:59:321776}
1777
ajumae2b7a5c2015-09-30 21:41:421778TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1779 // Tests that LayerImpl's IsClipped() property is set to true when:
[email protected]fb661802013-03-25 01:59:321780 // - the layer clips its subtree, e.g. masks to bounds,
1781 // - the layer is clipped by an ancestor that contributes to the same
1782 // render target,
1783 // - a surface is clipped by an ancestor that contributes to the same
1784 // render target.
1785 //
1786 // In particular, for a layer that owns a render surface:
1787 // - the render surface inherits any clip from ancestors, and does NOT
1788 // pass that clipped status to the layer itself.
1789 // - but if the layer itself masks to bounds, it is considered clipped
1790 // and propagates the clip to the subtree.
1791
1792 const gfx::Transform identity_matrix;
enne76bf8982015-08-18 17:55:331793 LayerImpl* root = root_layer();
1794 LayerImpl* parent = AddChild<LayerImpl>(root);
jaydasika8640f9f2015-11-10 01:34:361795 parent->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331796 LayerImpl* child1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:361797 child1->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331798 LayerImpl* child2 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:361799 child2->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331800 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
jaydasika8640f9f2015-11-10 01:34:361801 grand_child->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331802 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1803 leaf_node1->SetDrawsContent(true);
1804 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1805 leaf_node2->SetDrawsContent(true);
1806
1807 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1808 gfx::PointF(), gfx::Size(100, 100), true, false,
1809 true);
1810 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1811 gfx::PointF(), gfx::Size(100, 100), true, false,
1812 false);
1813 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1814 gfx::PointF(), gfx::Size(100, 100), true, false,
1815 false);
1816 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1817 gfx::PointF(), gfx::Size(100, 100), true, false,
1818 true);
1819 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1820 gfx::PointF(), gfx::Size(100, 100), true, false,
1821 false);
1822 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1823 gfx::PointF(), gfx::Size(100, 100), true, false,
1824 false);
1825 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1826 gfx::PointF(), gfx::Size(100, 100), true, false,
1827 false);
1828
1829 // Case 1: nothing is clipped except the root render surface.
weiliangce3f09a612016-03-16 17:02:521830 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331831
weiliangce3f09a612016-03-16 17:02:521832 ASSERT_TRUE(root->render_surface());
1833 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331834
weiliangce3f09a612016-03-16 17:02:521835 EXPECT_FALSE(root->is_clipped());
1836 EXPECT_TRUE(root->render_surface()->is_clipped());
1837 EXPECT_FALSE(parent->is_clipped());
1838 EXPECT_FALSE(child1->is_clipped());
1839 EXPECT_FALSE(child2->is_clipped());
1840 EXPECT_FALSE(child2->render_surface()->is_clipped());
1841 EXPECT_FALSE(grand_child->is_clipped());
1842 EXPECT_FALSE(leaf_node1->is_clipped());
1843 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331844
1845 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1846 // surface are clipped. But layers that contribute to child2's surface are
1847 // not clipped explicitly because child2's surface already accounts for
1848 // that clip.
weiliangce3f09a612016-03-16 17:02:521849 parent->SetMasksToBounds(true);
1850 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331851
weiliangce3f09a612016-03-16 17:02:521852 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331853
weiliangce3f09a612016-03-16 17:02:521854 ASSERT_TRUE(root->render_surface());
1855 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331856
weiliangce3f09a612016-03-16 17:02:521857 EXPECT_FALSE(root->is_clipped());
1858 EXPECT_TRUE(root->render_surface()->is_clipped());
1859 EXPECT_TRUE(parent->is_clipped());
1860 EXPECT_TRUE(child1->is_clipped());
1861 EXPECT_FALSE(child2->is_clipped());
1862 EXPECT_TRUE(child2->render_surface()->is_clipped());
1863 EXPECT_TRUE(grand_child->is_clipped());
1864 EXPECT_TRUE(leaf_node1->is_clipped());
1865 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331866
weiliangce3f09a612016-03-16 17:02:521867 parent->SetMasksToBounds(false);
enne76bf8982015-08-18 17:55:331868
1869 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1870 // child2's render surface is not clipped.
weiliangce3f09a612016-03-16 17:02:521871 child2->SetMasksToBounds(true);
1872 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331873
weiliangce3f09a612016-03-16 17:02:521874 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331875
weiliangce3f09a612016-03-16 17:02:521876 ASSERT_TRUE(root->render_surface());
1877 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331878
weiliangce3f09a612016-03-16 17:02:521879 EXPECT_FALSE(root->is_clipped());
1880 EXPECT_TRUE(root->render_surface()->is_clipped());
1881 EXPECT_FALSE(parent->is_clipped());
1882 EXPECT_FALSE(child1->is_clipped());
1883 EXPECT_TRUE(child2->is_clipped());
1884 EXPECT_FALSE(child2->render_surface()->is_clipped());
1885 EXPECT_FALSE(grand_child->is_clipped());
1886 EXPECT_FALSE(leaf_node1->is_clipped());
1887 EXPECT_TRUE(leaf_node2->is_clipped());
1888}
1889
1890TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) {
1891 // Tests that when as long as layer is clipped, it's clip rect is set to
1892 // correct value.
1893 LayerImpl* root = root_layer();
1894 LayerImpl* parent = AddChild<LayerImpl>(root);
1895 LayerImpl* child = AddChild<LayerImpl>(parent);
1896
1897 root->SetDrawsContent(true);
1898 parent->SetDrawsContent(true);
1899 child->SetDrawsContent(true);
1900
1901 const gfx::Transform identity_matrix;
1902
1903 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1904 gfx::PointF(), gfx::Size(100, 100), true, false,
1905 true);
1906 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1907 gfx::PointF(), gfx::Size(100, 100), true, false,
1908 false);
1909 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1910 gfx::PointF(), gfx::Size(100, 100), true, false,
1911 false);
1912 child->SetMasksToBounds(true);
1913
1914 ExecuteCalculateDrawProperties(root);
1915
1916 EXPECT_FALSE(root->is_clipped());
1917 EXPECT_FALSE(parent->is_clipped());
1918 EXPECT_TRUE(child->is_clipped());
1919 EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect());
1920
1921 parent->SetMasksToBounds(true);
1922 child->SetPosition(gfx::PointF(100, 100));
1923 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1924
1925 ExecuteCalculateDrawProperties(root);
1926
1927 EXPECT_FALSE(root->is_clipped());
1928 EXPECT_TRUE(parent->is_clipped());
1929 EXPECT_TRUE(child->is_clipped());
1930 EXPECT_EQ(gfx::Rect(), child->clip_rect());
[email protected]fb661802013-03-25 01:59:321931}
1932
ajuma51d73f72015-10-19 19:43:581933TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) {
1934 // Tests that when separate surfaces are disabled, is_clipped is true exactly
1935 // when a layer or its ancestor has a clip; in particular, if a layer
1936 // is_clipped, so is its entire subtree (since there are no render surfaces
1937 // that can reset is_clipped).
1938 LayerImpl* root = root_layer();
1939 LayerImpl* parent = AddChild<LayerImpl>(root);
1940 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1941 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1942 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1943 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1944 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1945
1946 root->SetDrawsContent(true);
1947 parent->SetDrawsContent(true);
1948 child1->SetDrawsContent(true);
1949 child2->SetDrawsContent(true);
1950 grand_child->SetDrawsContent(true);
1951 leaf_node1->SetDrawsContent(true);
1952 leaf_node2->SetDrawsContent(true);
1953
1954 const gfx::Transform identity_matrix;
1955
1956 // child1 and grand_child get render surfaces when surfaces are enabled.
1957 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1958 gfx::PointF(), gfx::Size(100, 100), true, false,
1959 true);
1960 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1961 gfx::PointF(), gfx::Size(100, 100), true, false,
1962 false);
1963 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1964 gfx::PointF(), gfx::Size(100, 100), true, false,
1965 true);
1966 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1967 gfx::PointF(), gfx::Size(100, 100), true, false,
1968 false);
1969 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1970 gfx::PointF(), gfx::Size(100, 100), true, false,
1971 true);
1972 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1973 gfx::PointF(), gfx::Size(100, 100), true, false,
1974 false);
1975 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1976 gfx::PointF(), gfx::Size(100, 100), true, false,
1977 false);
1978
1979 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with
1980 // or without surfaces.
weiliangcc154ce22015-12-09 03:39:261981 root->SetHasRenderSurface(true);
1982 child1->SetHasRenderSurface(true);
1983 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:581984 ExecuteCalculateDrawProperties(root);
1985 EXPECT_FALSE(root->is_clipped());
1986 EXPECT_FALSE(parent->is_clipped());
1987 EXPECT_FALSE(child1->is_clipped());
1988 EXPECT_FALSE(child2->is_clipped());
1989 EXPECT_FALSE(grand_child->is_clipped());
1990 EXPECT_FALSE(leaf_node1->is_clipped());
1991 EXPECT_FALSE(leaf_node2->is_clipped());
1992
1993 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1994 EXPECT_FALSE(root->is_clipped());
1995 EXPECT_FALSE(parent->is_clipped());
1996 EXPECT_FALSE(child1->is_clipped());
1997 EXPECT_FALSE(child2->is_clipped());
1998 EXPECT_FALSE(grand_child->is_clipped());
1999 EXPECT_FALSE(leaf_node1->is_clipped());
2000 EXPECT_FALSE(leaf_node2->is_clipped());
2001
2002 // Case 2: The root is clipped. With surfaces, this only persists until the
2003 // next render surface. Without surfaces, the entire tree is clipped.
2004 root->SetMasksToBounds(true);
2005 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262006 root->SetHasRenderSurface(true);
2007 child1->SetHasRenderSurface(true);
2008 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582009 ExecuteCalculateDrawProperties(root);
2010 EXPECT_TRUE(root->is_clipped());
2011 EXPECT_TRUE(parent->is_clipped());
2012 EXPECT_FALSE(child1->is_clipped());
2013 EXPECT_TRUE(child2->is_clipped());
2014 EXPECT_FALSE(grand_child->is_clipped());
2015 EXPECT_FALSE(leaf_node1->is_clipped());
2016 EXPECT_TRUE(leaf_node2->is_clipped());
2017
2018 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2019 EXPECT_TRUE(root->is_clipped());
2020 EXPECT_TRUE(parent->is_clipped());
2021 EXPECT_TRUE(child1->is_clipped());
2022 EXPECT_TRUE(child2->is_clipped());
2023 EXPECT_TRUE(grand_child->is_clipped());
2024 EXPECT_TRUE(leaf_node1->is_clipped());
2025 EXPECT_TRUE(leaf_node2->is_clipped());
2026
2027 root->SetMasksToBounds(false);
2028
2029 // Case 3: The parent is clipped. Again, with surfaces, this only persists
2030 // until the next render surface. Without surfaces, parent's entire subtree is
2031 // clipped.
2032 parent->SetMasksToBounds(true);
2033 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262034 root->SetHasRenderSurface(true);
2035 child1->SetHasRenderSurface(true);
2036 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582037 ExecuteCalculateDrawProperties(root);
2038 EXPECT_FALSE(root->is_clipped());
2039 EXPECT_TRUE(parent->is_clipped());
2040 EXPECT_FALSE(child1->is_clipped());
2041 EXPECT_TRUE(child2->is_clipped());
2042 EXPECT_FALSE(grand_child->is_clipped());
2043 EXPECT_FALSE(leaf_node1->is_clipped());
2044 EXPECT_TRUE(leaf_node2->is_clipped());
2045
2046 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2047 EXPECT_FALSE(root->is_clipped());
2048 EXPECT_TRUE(parent->is_clipped());
2049 EXPECT_TRUE(child1->is_clipped());
2050 EXPECT_TRUE(child2->is_clipped());
2051 EXPECT_TRUE(grand_child->is_clipped());
2052 EXPECT_TRUE(leaf_node1->is_clipped());
2053 EXPECT_TRUE(leaf_node2->is_clipped());
2054
2055 parent->SetMasksToBounds(false);
2056
2057 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it
2058 // has no non-surface children. Without surfaces, child1's entire subtree is
2059 // clipped.
2060 child1->SetMasksToBounds(true);
2061 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262062 root->SetHasRenderSurface(true);
2063 child1->SetHasRenderSurface(true);
2064 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582065 ExecuteCalculateDrawProperties(root);
2066 EXPECT_FALSE(root->is_clipped());
2067 EXPECT_FALSE(parent->is_clipped());
2068 EXPECT_TRUE(child1->is_clipped());
2069 EXPECT_FALSE(child2->is_clipped());
2070 EXPECT_FALSE(grand_child->is_clipped());
2071 EXPECT_FALSE(leaf_node1->is_clipped());
2072 EXPECT_FALSE(leaf_node2->is_clipped());
2073
2074 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2075 EXPECT_FALSE(root->is_clipped());
2076 EXPECT_FALSE(parent->is_clipped());
2077 EXPECT_TRUE(child1->is_clipped());
2078 EXPECT_FALSE(child2->is_clipped());
2079 EXPECT_TRUE(grand_child->is_clipped());
2080 EXPECT_TRUE(leaf_node1->is_clipped());
2081 EXPECT_FALSE(leaf_node2->is_clipped());
2082
2083 child1->SetMasksToBounds(false);
2084
2085 // Case 5: Only the leaf nodes are clipped. The behavior with and without
2086 // surfaces is the same.
2087 leaf_node1->SetMasksToBounds(true);
2088 leaf_node2->SetMasksToBounds(true);
2089 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262090 root->SetHasRenderSurface(true);
2091 child1->SetHasRenderSurface(true);
2092 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582093 ExecuteCalculateDrawProperties(root);
2094 EXPECT_FALSE(root->is_clipped());
2095 EXPECT_FALSE(parent->is_clipped());
2096 EXPECT_FALSE(child1->is_clipped());
2097 EXPECT_FALSE(child2->is_clipped());
2098 EXPECT_FALSE(grand_child->is_clipped());
2099 EXPECT_TRUE(leaf_node1->is_clipped());
2100 EXPECT_TRUE(leaf_node2->is_clipped());
2101
2102 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2103 EXPECT_FALSE(root->is_clipped());
2104 EXPECT_FALSE(parent->is_clipped());
2105 EXPECT_FALSE(child1->is_clipped());
2106 EXPECT_FALSE(child2->is_clipped());
2107 EXPECT_FALSE(grand_child->is_clipped());
2108 EXPECT_TRUE(leaf_node1->is_clipped());
2109 EXPECT_TRUE(leaf_node2->is_clipped());
2110}
2111
[email protected]fd9a3b6d2013-08-03 00:46:172112TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:322113 // Verify that layers get the appropriate DrawableContentRect when their
2114 // parent masksToBounds is true.
2115 //
2116 // grand_child1 - completely inside the region; DrawableContentRect should
2117 // be the layer rect expressed in target space.
2118 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
2119 // will be the intersection of layer bounds and the mask region.
2120 // grand_child3 - partially clipped and masksToBounds; the
2121 // DrawableContentRect will still be the intersection of layer bounds and
2122 // the mask region.
2123 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2124 // be empty.
[email protected]fb661802013-03-25 01:59:322125
2126 const gfx::Transform identity_matrix;
enne07405c772015-08-18 17:56:452127 LayerImpl* parent = root_layer();
2128 LayerImpl* child = AddChild<LayerImpl>(parent);
2129 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362130 grand_child1->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452131 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362132 grand_child2->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452133 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362134 grand_child3->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452135 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362136 grand_child4->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322137
enne07405c772015-08-18 17:56:452138 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2139 gfx::PointF(), gfx::Size(500, 500), true, false,
2140 true);
2141 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2142 gfx::PointF(), gfx::Size(20, 20), true, false,
2143 true);
2144 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2145 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
2146 false, false);
2147 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2148 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2149 false, false);
2150 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2151 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2152 false, false);
2153 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
2154 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
2155 false, false);
[email protected]fb661802013-03-25 01:59:322156
2157 child->SetMasksToBounds(true);
2158 grand_child3->SetMasksToBounds(true);
2159
enne07405c772015-08-18 17:56:452160 // Force child to be a render surface.
[email protected]fb661802013-03-25 01:59:322161 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:322162
enne07405c772015-08-18 17:56:452163 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322164
hush6b614212014-12-04 22:37:322165 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2166 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2167 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322168 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2169}
2170
[email protected]989386c2013-07-18 21:37:232171TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322172 // Verify that render surfaces (and their layers) get the appropriate
2173 // clip rects when their parent masksToBounds is true.
2174 //
2175 // Layers that own render surfaces (at least for now) do not inherit any
2176 // clipping; instead the surface will enforce the clip for the entire subtree.
2177 // They may still have a clip rect of their own layer bounds, however, if
2178 // masksToBounds was true.
weiliangcfb3d5eaa2015-07-28 23:54:572179 LayerImpl* parent = root_layer();
2180 LayerImpl* child = AddChildToRoot<LayerImpl>();
2181 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2182 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2183 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2184 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
[email protected]fb661802013-03-25 01:59:322185 // the leaf nodes ensure that these grand_children become render surfaces for
2186 // this test.
weiliangcfb3d5eaa2015-07-28 23:54:572187 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
2188 leaf_node1->SetDrawsContent(true);
2189 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
2190 leaf_node2->SetDrawsContent(true);
2191 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
2192 leaf_node3->SetDrawsContent(true);
2193 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
2194 leaf_node4->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322195
weiliangcfb3d5eaa2015-07-28 23:54:572196 const gfx::Transform identity_matrix;
2197
2198 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2199 gfx::PointF(), gfx::Size(500, 500), true, false,
2200 true);
2201 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2202 gfx::PointF(), gfx::Size(20, 20), true, false,
2203 true);
2204 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2205 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
2206 false, true);
2207 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2208 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2209 false, true);
2210 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2211 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2212 false, true);
2213 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
2214 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
2215 false, true);
2216 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2217 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322218 false);
weiliangcfb3d5eaa2015-07-28 23:54:572219 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2220 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322221 false);
weiliangcfb3d5eaa2015-07-28 23:54:572222 SetLayerPropertiesForTesting(leaf_node3, identity_matrix, gfx::Point3F(),
2223 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322224 false);
weiliangcfb3d5eaa2015-07-28 23:54:572225 SetLayerPropertiesForTesting(leaf_node4, identity_matrix, gfx::Point3F(),
2226 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322227 false);
2228
2229 child->SetMasksToBounds(true);
2230 grand_child3->SetMasksToBounds(true);
2231 grand_child4->SetMasksToBounds(true);
2232
2233 // Force everyone to be a render surface.
2234 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:322235 grand_child1->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322236 grand_child2->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322237 grand_child3->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322238 grand_child4->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322239
weiliangcfb3d5eaa2015-07-28 23:54:572240 ExecuteCalculateDrawProperties(parent);
2241
[email protected]fb661802013-03-25 01:59:322242 ASSERT_TRUE(grand_child1->render_surface());
2243 ASSERT_TRUE(grand_child2->render_surface());
2244 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322245
2246 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2247 // masksToBounds.
hush6b614212014-12-04 22:37:322248 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2249 grand_child1->render_surface()->clip_rect());
2250 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2251 grand_child2->render_surface()->clip_rect());
2252 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2253 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322254}
2255
ajuma51d73f72015-10-19 19:43:582256TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) {
2257 // Tests that when separate surfaces are disabled, a layer's clip_rect is the
2258 // intersection of all ancestor clips in screen space; in particular, if a
2259 // layer masks to bounds, it contributes to the clip_rect of all layers in its
2260 // subtree (since there are no render surfaces that can reset the clip_rect).
2261 LayerImpl* root = root_layer();
2262 LayerImpl* parent = AddChild<LayerImpl>(root);
2263 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2264 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2265 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2266 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2267 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2268
2269 root->SetDrawsContent(true);
2270 parent->SetDrawsContent(true);
2271 child1->SetDrawsContent(true);
2272 child2->SetDrawsContent(true);
2273 grand_child->SetDrawsContent(true);
2274 leaf_node1->SetDrawsContent(true);
2275 leaf_node2->SetDrawsContent(true);
2276
2277 const gfx::Transform identity_matrix;
2278
2279 // child1 and grand_child get render surfaces when surfaces are enabled.
2280 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:262281 gfx::PointF(), gfx::Size(100, 100), true, false);
ajuma51d73f72015-10-19 19:43:582282 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2283 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
weiliangcc154ce22015-12-09 03:39:262284 false);
ajuma51d73f72015-10-19 19:43:582285 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2286 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
weiliangcc154ce22015-12-09 03:39:262287 false);
ajuma51d73f72015-10-19 19:43:582288 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2289 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
weiliangcc154ce22015-12-09 03:39:262290 false);
ajuma51d73f72015-10-19 19:43:582291 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2292 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
weiliangcc154ce22015-12-09 03:39:262293 true, false);
ajuma51d73f72015-10-19 19:43:582294 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2295 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
weiliangcc154ce22015-12-09 03:39:262296 true, false);
ajuma51d73f72015-10-19 19:43:582297 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2298 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
weiliangcc154ce22015-12-09 03:39:262299 true, false);
ajuma51d73f72015-10-19 19:43:582300
2301 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its
2302 // bounds in target space. The only thing that changes when surfaces are
2303 // disabled is that target space is always screen space.
weiliangcc154ce22015-12-09 03:39:262304 root->SetForceRenderSurface(true);
2305 child1->SetForceRenderSurface(true);
2306 grand_child->SetForceRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582307 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262308 EXPECT_TRUE(root->has_render_surface());
2309 EXPECT_FALSE(parent->has_render_surface());
2310 EXPECT_TRUE(child1->has_render_surface());
2311 EXPECT_FALSE(child2->has_render_surface());
2312 EXPECT_TRUE(grand_child->has_render_surface());
2313 EXPECT_FALSE(leaf_node1->has_render_surface());
2314 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422315 EXPECT_FALSE(root->is_clipped());
2316 EXPECT_FALSE(parent->is_clipped());
2317 EXPECT_FALSE(child1->is_clipped());
2318 EXPECT_FALSE(child2->is_clipped());
2319 EXPECT_FALSE(grand_child->is_clipped());
2320 EXPECT_FALSE(leaf_node1->is_clipped());
2321 EXPECT_FALSE(leaf_node2->is_clipped());
2322 EXPECT_TRUE(root->render_surface()->is_clipped());
2323 EXPECT_FALSE(child1->render_surface()->is_clipped());
2324 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2325 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582326
2327 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422328 EXPECT_FALSE(root->is_clipped());
2329 EXPECT_FALSE(parent->is_clipped());
2330 EXPECT_FALSE(child1->is_clipped());
2331 EXPECT_FALSE(child2->is_clipped());
2332 EXPECT_FALSE(grand_child->is_clipped());
2333 EXPECT_FALSE(leaf_node1->is_clipped());
2334 EXPECT_FALSE(leaf_node2->is_clipped());
2335 EXPECT_TRUE(root->render_surface()->is_clipped());
2336 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582337
2338 // Case 2: The root is clipped. In this case, layers that draw into the root
2339 // render surface are clipped by the root's bounds.
2340 root->SetMasksToBounds(true);
2341 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262342 root->SetForceRenderSurface(true);
2343 child1->SetForceRenderSurface(true);
2344 grand_child->SetForceRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582345 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262346 EXPECT_TRUE(root->has_render_surface());
2347 EXPECT_FALSE(parent->has_render_surface());
2348 EXPECT_TRUE(child1->has_render_surface());
2349 EXPECT_FALSE(child2->has_render_surface());
2350 EXPECT_TRUE(grand_child->has_render_surface());
2351 EXPECT_FALSE(leaf_node1->has_render_surface());
2352 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422353 EXPECT_TRUE(root->is_clipped());
2354 EXPECT_TRUE(parent->is_clipped());
2355 EXPECT_FALSE(child1->is_clipped());
2356 EXPECT_TRUE(child1->render_surface()->is_clipped());
2357 EXPECT_TRUE(child2->is_clipped());
2358 EXPECT_FALSE(grand_child->is_clipped());
2359 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2360 EXPECT_FALSE(leaf_node1->is_clipped());
2361 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582362 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2363 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422364 EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582365 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
ajuma51d73f72015-10-19 19:43:582366 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2367
2368 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422369 EXPECT_TRUE(root->is_clipped());
2370 EXPECT_TRUE(parent->is_clipped());
2371 EXPECT_TRUE(child1->is_clipped());
2372 EXPECT_TRUE(child2->is_clipped());
2373 EXPECT_TRUE(grand_child->is_clipped());
2374 EXPECT_TRUE(leaf_node1->is_clipped());
2375 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582376 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2377 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2378 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect());
2379 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2380 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect());
2381 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect());
2382 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2383
2384 root->SetMasksToBounds(false);
2385
2386 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the
2387 // parent clip rect only contributes to the subtree rooted at child2, since
2388 // the subtree rooted at child1 renders into a separate surface. Similarly,
2389 // child1's clip rect doesn't contribute to its descendants, since its only
2390 // child is a render surface. However, without surfaces, these clip rects
2391 // contribute to all descendants.
2392 parent->SetMasksToBounds(true);
2393 child1->SetMasksToBounds(true);
2394 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262395 root->SetForceRenderSurface(true);
2396 child1->SetForceRenderSurface(true);
2397 grand_child->SetForceRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582398 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262399 EXPECT_TRUE(root->has_render_surface());
2400 EXPECT_FALSE(parent->has_render_surface());
2401 EXPECT_TRUE(child1->has_render_surface());
2402 EXPECT_FALSE(child2->has_render_surface());
2403 EXPECT_TRUE(grand_child->has_render_surface());
2404 EXPECT_FALSE(leaf_node1->has_render_surface());
2405 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422406 EXPECT_FALSE(root->is_clipped());
2407 EXPECT_TRUE(root->render_surface()->is_clipped());
2408 EXPECT_TRUE(parent->is_clipped());
2409 EXPECT_TRUE(child1->is_clipped());
2410 EXPECT_TRUE(child2->is_clipped());
2411 EXPECT_FALSE(grand_child->is_clipped());
2412 EXPECT_TRUE(grand_child->render_surface()->is_clipped());
2413 EXPECT_FALSE(leaf_node1->is_clipped());
2414 EXPECT_TRUE(leaf_node2->is_clipped());
2415 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582416 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2417 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2418 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422419 EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582420 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2421
2422 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422423 EXPECT_FALSE(root->is_clipped());
2424 EXPECT_TRUE(root->render_surface()->is_clipped());
2425 EXPECT_TRUE(parent->is_clipped());
2426 EXPECT_TRUE(child1->is_clipped());
2427 EXPECT_TRUE(child2->is_clipped());
2428 EXPECT_TRUE(grand_child->is_clipped());
2429 EXPECT_TRUE(leaf_node1->is_clipped());
2430 EXPECT_TRUE(leaf_node2->is_clipped());
2431 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582432 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2433 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect());
2434 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2435 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect());
2436 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect());
2437 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2438}
2439
2440TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) {
2441 // Tests that draw properties are computed correctly when we disable and then
2442 // re-enable separate surfaces.
2443 LayerImpl* root = root_layer();
2444 LayerImpl* parent = AddChild<LayerImpl>(root);
2445 LayerImpl* child = AddChild<LayerImpl>(parent);
2446 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2447 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2448
2449 root->SetDrawsContent(true);
2450 parent->SetDrawsContent(true);
2451 child->SetDrawsContent(true);
2452 grand_child->SetDrawsContent(true);
2453 leaf_node->SetDrawsContent(true);
2454
2455 const gfx::Transform identity_matrix;
2456
2457 // child and grand_child get render surfaces when surfaces are enabled.
2458 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2459 gfx::PointF(), gfx::Size(100, 100), true, false,
2460 true);
2461 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2462 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2463 false, false);
2464 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2465 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2466 false, true);
2467 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2468 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2469 true, false, true);
2470 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
2471 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2472 true, false, false);
2473
2474 parent->SetMasksToBounds(true);
2475 child->SetMasksToBounds(true);
2476
weiliangcc154ce22015-12-09 03:39:262477 root->SetHasRenderSurface(true);
2478 child->SetHasRenderSurface(true);
2479 grand_child->SetHasRenderSurface(true);
2480
ajuma51d73f72015-10-19 19:43:582481 gfx::Transform expected_leaf_draw_transform_with_surfaces;
2482 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0);
2483
2484 gfx::Transform expected_leaf_draw_transform_without_surfaces;
2485 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0);
2486
2487 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422488 EXPECT_FALSE(leaf_node->is_clipped());
2489 EXPECT_TRUE(leaf_node->render_target()->render_surface()->is_clipped());
ajuma51d73f72015-10-19 19:43:582490 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2491 EXPECT_EQ(expected_leaf_draw_transform_with_surfaces,
ajumad9432e32015-11-30 19:43:442492 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582493
weiliangcc154ce22015-12-09 03:39:262494 root->SetHasRenderSurface(true);
2495 child->SetHasRenderSurface(true);
2496 grand_child->SetHasRenderSurface(true);
2497
ajuma51d73f72015-10-19 19:43:582498 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422499 EXPECT_TRUE(leaf_node->is_clipped());
ajuma51d73f72015-10-19 19:43:582500 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect());
2501 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect());
2502 EXPECT_EQ(expected_leaf_draw_transform_without_surfaces,
ajumad9432e32015-11-30 19:43:442503 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582504
weiliangcc154ce22015-12-09 03:39:262505 root->SetHasRenderSurface(true);
2506 child->SetHasRenderSurface(true);
2507 grand_child->SetHasRenderSurface(true);
2508
ajuma51d73f72015-10-19 19:43:582509 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422510 EXPECT_FALSE(leaf_node->is_clipped());
2511 EXPECT_TRUE(leaf_node->render_target()->render_surface()->is_clipped());
ajuma51d73f72015-10-19 19:43:582512 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2513 EXPECT_EQ(expected_leaf_draw_transform_with_surfaces,
ajumad9432e32015-11-30 19:43:442514 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582515}
2516
[email protected]989386c2013-07-18 21:37:232517TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
enneab0fee42015-07-07 17:36:422518 LayerImpl* parent = root_layer();
2519 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2520 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
2521 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
2522 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2523 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2524 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2525 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2526 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
[email protected]fb661802013-03-25 01:59:322527
jaydasika8640f9f2015-11-10 01:34:362528 parent->SetDrawsContent(true);
2529 render_surface1->SetDrawsContent(true);
2530 child_of_rs1->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422531 grand_child_of_rs1->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362532 render_surface2->SetDrawsContent(true);
2533 child_of_rs2->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422534 grand_child_of_rs2->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362535 child_of_root->SetDrawsContent(true);
2536 grand_child_of_root->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322537
2538 gfx::Transform layer_transform;
2539 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322540
enneab0fee42015-07-07 17:36:422541 SetLayerPropertiesForTesting(
2542 parent, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2543 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2544 SetLayerPropertiesForTesting(
2545 render_surface1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2546 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2547 SetLayerPropertiesForTesting(
2548 render_surface2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2549 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2550 SetLayerPropertiesForTesting(
2551 child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2552 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2553 SetLayerPropertiesForTesting(
2554 child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2555 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2556 SetLayerPropertiesForTesting(
2557 child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2558 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2559 SetLayerPropertiesForTesting(
2560 grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2561 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2562 SetLayerPropertiesForTesting(
2563 grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2564 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2565 SetLayerPropertiesForTesting(
2566 grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2567 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
[email protected]fb661802013-03-25 01:59:322568
loyso9556c732016-03-11 07:54:582569 // Put an animated opacity on the render surface.
2570 AddOpacityTransitionToLayerWithPlayer(render_surface1->id(), timeline_impl(),
2571 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322572
loyso9556c732016-03-11 07:54:582573 // Also put an animated opacity on a layer without descendants.
2574 AddOpacityTransitionToLayerWithPlayer(grand_child_of_root->id(),
2575 timeline_impl(), 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322576
loyso9556c732016-03-11 07:54:582577 // Put a transform animation on the render surface.
2578 AddAnimatedTransformToLayerWithPlayer(render_surface2->id(), timeline_impl(),
2579 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322580
loyso9556c732016-03-11 07:54:582581 // Also put transform animations on grand_child_of_root, and
2582 // grand_child_of_rs2
2583 AddAnimatedTransformToLayerWithPlayer(grand_child_of_root->id(),
2584 timeline_impl(), 10.0, 30, 0);
2585 AddAnimatedTransformToLayerWithPlayer(grand_child_of_rs2->id(),
2586 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322587
enneab0fee42015-07-07 17:36:422588 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322589
2590 // Only layers that are associated with render surfaces should have an actual
2591 // RenderSurface() value.
2592 ASSERT_TRUE(parent->render_surface());
2593 ASSERT_FALSE(child_of_root->render_surface());
2594 ASSERT_FALSE(grand_child_of_root->render_surface());
2595
2596 ASSERT_TRUE(render_surface1->render_surface());
2597 ASSERT_FALSE(child_of_rs1->render_surface());
2598 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2599
2600 ASSERT_TRUE(render_surface2->render_surface());
2601 ASSERT_FALSE(child_of_rs2->render_surface());
2602 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2603
2604 // Verify all render target accessors
enneab0fee42015-07-07 17:36:422605 EXPECT_EQ(parent, parent->render_target());
2606 EXPECT_EQ(parent, child_of_root->render_target());
2607 EXPECT_EQ(parent, grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322608
enneab0fee42015-07-07 17:36:422609 EXPECT_EQ(render_surface1, render_surface1->render_target());
2610 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
2611 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322612
enneab0fee42015-07-07 17:36:422613 EXPECT_EQ(render_surface2, render_surface2->render_target());
2614 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
2615 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322616
[email protected]fb661802013-03-25 01:59:322617 // Verify screen_space_transform_is_animating values
2618 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2619 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2620 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2621 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322622 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2623 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2624 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322625 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2626 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2627
2628 // Sanity check. If these fail there is probably a bug in the test itself.
2629 // It is expected that we correctly set up transforms so that the y-component
2630 // of the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:102631 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:262632 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102633 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322634 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102635 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322636
[email protected]803f6b52013-09-12 00:51:262637 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102638 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
2639 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322640 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102641 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322642
[email protected]803f6b52013-09-12 00:51:262643 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:102644 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
2645 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322646 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102647 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322648}
2649
ajuma9384b9c22015-09-17 20:35:032650TEST_F(LayerTreeHostCommonTest, LargeTransforms) {
2651 LayerImpl* parent = root_layer();
2652 LayerImpl* child = AddChildToRoot<LayerImpl>();
2653 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2654
2655 grand_child->SetDrawsContent(true);
2656
2657 gfx::Transform large_transform;
2658 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2659
2660 gfx::Transform identity;
2661
2662 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(),
2663 gfx::Size(10, 10), true, false, true);
2664 SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(),
2665 gfx::PointF(), gfx::Size(10, 10), true, false,
2666 false);
2667 SetLayerPropertiesForTesting(grand_child, large_transform, gfx::Point3F(),
2668 gfx::PointF(), gfx::Size(10, 10), true, false,
2669 false);
2670 ExecuteCalculateDrawProperties(parent);
2671
2672 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
2673}
2674
ajuma315a4782015-07-24 21:16:342675TEST_F(LayerTreeHostCommonTest,
2676 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
2677 LayerImpl* parent = root_layer();
2678 LayerImpl* child = AddChild<LayerImpl>(parent);
2679 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2680 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2681
2682 parent->SetDrawsContent(true);
2683 child->SetDrawsContent(true);
2684 grand_child->SetDrawsContent(true);
2685 great_grand_child->SetDrawsContent(true);
2686
2687 gfx::Transform identity;
2688
2689 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(),
2690 gfx::Size(10, 10), true, false, true);
2691 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
2692 gfx::Size(10, 10), true, false, false);
2693 SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(),
2694 gfx::PointF(), gfx::Size(10, 10), true, false,
2695 false);
2696 SetLayerPropertiesForTesting(great_grand_child, identity, gfx::Point3F(),
2697 gfx::PointF(), gfx::Size(10, 10), true, false,
2698 false);
2699
2700 // Add a transform animation with a start delay to |grand_child|.
2701 scoped_ptr<Animation> animation = Animation::Create(
danakja5a05ba02015-11-20 20:14:212702 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1,
loyso0c8e4402016-02-25 04:12:302703 TargetProperty::TRANSFORM);
ajuma315a4782015-07-24 21:16:342704 animation->set_fill_mode(Animation::FILL_MODE_NONE);
2705 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso9556c732016-03-11 07:54:582706 AddAnimationToLayerWithPlayer(grand_child->id(), timeline_impl(),
2707 std::move(animation));
ajuma315a4782015-07-24 21:16:342708 ExecuteCalculateDrawProperties(parent);
2709
2710 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2711 EXPECT_FALSE(child->screen_space_transform_is_animating());
2712
2713 EXPECT_FALSE(grand_child->TransformIsAnimating());
2714 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2715 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2716 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2717}
2718
[email protected]989386c2013-07-18 21:37:232719TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322720 // Test the calculateVisibleRect() function works correctly for identity
2721 // transforms.
2722
[email protected]2c7c6702013-03-26 03:14:052723 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322724 gfx::Transform layer_to_surface_transform;
2725
2726 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232727 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052728 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322729 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2730 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322731 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322732
2733 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052734 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322735 actual = LayerTreeHostCommon::CalculateVisibleRect(
2736 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2737 EXPECT_TRUE(actual.IsEmpty());
2738
2739 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052740 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2741 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322742 actual = LayerTreeHostCommon::CalculateVisibleRect(
2743 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322744 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322745}
2746
[email protected]989386c2013-07-18 21:37:232747TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322748 // Test the calculateVisibleRect() function works correctly for scaling
2749 // transforms.
2750
[email protected]2c7c6702013-03-26 03:14:052751 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2752 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322753 gfx::Transform layer_to_surface_transform;
2754
2755 // Case 1: Layer is contained within the surface.
2756 layer_to_surface_transform.MakeIdentity();
2757 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052758 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322759 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2760 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322761 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322762
2763 // Case 2: Layer is outside the surface rect.
2764 layer_to_surface_transform.MakeIdentity();
2765 layer_to_surface_transform.Translate(120.0, 120.0);
2766 actual = LayerTreeHostCommon::CalculateVisibleRect(
2767 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2768 EXPECT_TRUE(actual.IsEmpty());
2769
2770 // Case 3: Layer is partially overlapping the surface rect.
2771 layer_to_surface_transform.MakeIdentity();
2772 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052773 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322774 actual = LayerTreeHostCommon::CalculateVisibleRect(
2775 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322776 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322777}
2778
[email protected]989386c2013-07-18 21:37:232779TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322780 // Test the calculateVisibleRect() function works correctly for rotations
2781 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2782 // should return the g in the layer's space.
2783
[email protected]2c7c6702013-03-26 03:14:052784 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2785 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322786 gfx::Transform layer_to_surface_transform;
2787
2788 // Case 1: Layer is contained within the surface.
2789 layer_to_surface_transform.MakeIdentity();
2790 layer_to_surface_transform.Translate(50.0, 50.0);
2791 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052792 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322793 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2794 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322795 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322796
2797 // Case 2: Layer is outside the surface rect.
2798 layer_to_surface_transform.MakeIdentity();
2799 layer_to_surface_transform.Translate(-50.0, 0.0);
2800 layer_to_surface_transform.Rotate(45.0);
2801 actual = LayerTreeHostCommon::CalculateVisibleRect(
2802 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2803 EXPECT_TRUE(actual.IsEmpty());
2804
2805 // Case 3: The layer is rotated about its top-left corner. In surface space,
2806 // the layer is oriented diagonally, with the left half outside of the render
2807 // surface. In this case, the g should still be the entire layer
2808 // (remember the g is computed in layer space); both the top-left
2809 // and bottom-right corners of the layer are still visible.
2810 layer_to_surface_transform.MakeIdentity();
2811 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052812 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322813 actual = LayerTreeHostCommon::CalculateVisibleRect(
2814 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322815 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322816
2817 // Case 4: The layer is rotated about its top-left corner, and translated
2818 // upwards. In surface space, the layer is oriented diagonally, with only the
2819 // top corner of the surface overlapping the layer. In layer space, the render
2820 // surface overlaps the right side of the layer. The g should be
2821 // the layer's right half.
2822 layer_to_surface_transform.MakeIdentity();
2823 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2824 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052825 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322826 actual = LayerTreeHostCommon::CalculateVisibleRect(
2827 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322828 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322829}
2830
[email protected]989386c2013-07-18 21:37:232831TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322832 // Test that the calculateVisibleRect() function works correctly for 3d
2833 // transforms.
2834
[email protected]2c7c6702013-03-26 03:14:052835 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2836 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322837 gfx::Transform layer_to_surface_transform;
2838
2839 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2840 // degrees, should be fully contained in the render surface.
2841 layer_to_surface_transform.MakeIdentity();
2842 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052843 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322844 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2845 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322846 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322847
2848 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2849 // degrees, but shifted to the side so only the right-half the layer would be
2850 // visible on the surface.
2851 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262852 SkMScalar half_width_of_rotated_layer =
2853 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322854 layer_to_surface_transform.MakeIdentity();
2855 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232856 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2857 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052858 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322859 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, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322865 // Test the calculateVisibleRect() function works correctly when the layer has
2866 // a perspective projection onto the target surface.
2867
[email protected]2c7c6702013-03-26 03:14:052868 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2869 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322870 gfx::Transform layer_to_surface_transform;
2871
2872 // Case 1: Even though the layer is twice as large as the surface, due to
2873 // perspective foreshortening, the layer will fit fully in the surface when
2874 // its translated more than the perspective amount.
2875 layer_to_surface_transform.MakeIdentity();
2876
2877 // The following sequence of transforms applies the perspective about the
2878 // center of the surface.
2879 layer_to_surface_transform.Translate(50.0, 50.0);
2880 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2881 layer_to_surface_transform.Translate(-50.0, -50.0);
2882
2883 // This translate places the layer in front of the surface's projection plane.
2884 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2885
[email protected]2c7c6702013-03-26 03:14:052886 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322887 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2888 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322889 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322890
2891 // Case 2: same projection as before, except that the layer is also translated
2892 // to the side, so that only the right half of the layer should be visible.
2893 //
2894 // Explanation of expected result: The perspective ratio is (z distance
2895 // between layer and camera origin) / (z distance between projection plane and
2896 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2897 // move a layer by translating -50 units in projected surface units (so that
2898 // only half of it is visible), then we would need to translate by (-36 / 9) *
2899 // -50 == -200 in the layer's units.
2900 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232901 expected = gfx::Rect(gfx::Point(50, -50),
2902 gfx::Size(100, 200)); // The right half of the layer's
2903 // bounding rect.
[email protected]fb661802013-03-25 01:59:322904 actual = LayerTreeHostCommon::CalculateVisibleRect(
2905 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322906 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322907}
2908
[email protected]989386c2013-07-18 21:37:232909TEST_F(LayerTreeHostCommonTest,
2910 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322911 // There is currently no explicit concept of an orthographic projection plane
2912 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2913 // are technically behind the surface in an orthographic world should not be
2914 // clipped when they are flattened to the surface.
2915
[email protected]2c7c6702013-03-26 03:14:052916 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2917 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322918 gfx::Transform layer_to_surface_transform;
2919
2920 // This sequence of transforms effectively rotates the layer about the y-axis
2921 // at the center of the layer.
2922 layer_to_surface_transform.MakeIdentity();
2923 layer_to_surface_transform.Translate(50.0, 0.0);
2924 layer_to_surface_transform.RotateAboutYAxis(45.0);
2925 layer_to_surface_transform.Translate(-50.0, 0.0);
2926
[email protected]2c7c6702013-03-26 03:14:052927 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322928 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2929 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322930 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322931}
2932
[email protected]989386c2013-07-18 21:37:232933TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322934 // Test the calculateVisibleRect() function works correctly when projecting a
2935 // surface onto a layer, but the layer is partially behind the camera (not
2936 // just behind the projection plane). In this case, the cartesian coordinates
2937 // may seem to be valid, but actually they are not. The visible rect needs to
2938 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2939 // converting to cartesian coordinates.
2940
[email protected]2c7c6702013-03-26 03:14:052941 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232942 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322943 gfx::Transform layer_to_surface_transform;
2944
2945 // The layer is positioned so that the right half of the layer should be in
2946 // front of the camera, while the other half is behind the surface's
2947 // projection plane. The following sequence of transforms applies the
2948 // perspective and rotation about the center of the layer.
2949 layer_to_surface_transform.MakeIdentity();
2950 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2951 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2952 layer_to_surface_transform.RotateAboutYAxis(45.0);
2953
2954 // Sanity check that this transform does indeed cause w < 0 when applying the
2955 // transform, otherwise this code is not testing the intended scenario.
2956 bool clipped;
2957 MathUtil::MapQuad(layer_to_surface_transform,
2958 gfx::QuadF(gfx::RectF(layer_content_rect)),
2959 &clipped);
2960 ASSERT_TRUE(clipped);
2961
2962 int expected_x_position = 0;
2963 int expected_width = 10;
2964 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2965 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2966 EXPECT_EQ(expected_x_position, actual.x());
2967 EXPECT_EQ(expected_width, actual.width());
2968}
2969
[email protected]989386c2013-07-18 21:37:232970TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322971 // To determine visible rect in layer space, there needs to be an
2972 // un-projection from surface space to layer space. When the original
2973 // transform was a perspective projection that was clipped, it returns a rect
2974 // that encloses the clipped bounds. Un-projecting this new rect may require
2975 // clipping again.
2976
2977 // This sequence of transforms causes one corner of the layer to protrude
2978 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232979 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2980 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322981 gfx::Transform layer_to_surface_transform;
2982 layer_to_surface_transform.MakeIdentity();
2983 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2984 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2985 layer_to_surface_transform.RotateAboutYAxis(45.0);
2986 layer_to_surface_transform.RotateAboutXAxis(80.0);
2987
2988 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2989 // code is not testing the intended scenario.
2990 bool clipped;
danakj5e6ff6d2015-09-05 04:43:442991 gfx::RectF clipped_rect = MathUtil::MapClippedRect(
2992 layer_to_surface_transform, gfx::RectF(layer_content_rect));
[email protected]fb661802013-03-25 01:59:322993 MathUtil::ProjectQuad(
2994 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2995 ASSERT_TRUE(clipped);
2996
2997 // Only the corner of the layer is not visible on the surface because of being
2998 // clipped. But, the net result of rounding visible region to an axis-aligned
2999 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:053000 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:323001 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
3002 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:323003 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:323004}
3005
miletus9d3da522015-06-05 19:45:073006TEST_F(LayerTreeHostCommonTest,
3007 VisibleRectsForPositionedRootLayerClippedByViewport) {
enne6c281f6e2015-08-18 23:23:003008 LayerImpl* root = root_layer();
3009 root->SetDrawsContent(true);
miletus9d3da522015-06-05 19:45:073010
3011 gfx::Transform identity_matrix;
3012 // Root layer is positioned at (60, 70). The default device viewport size
3013 // is (0, 0, 100x100) in target space. So the root layer's visible rect
3014 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
enne6c281f6e2015-08-18 23:23:003015 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
miletus9d3da522015-06-05 19:45:073016 gfx::PointF(60, 70), gfx::Size(100, 100), true,
enne6c281f6e2015-08-18 23:23:003017 false, true);
3018 ExecuteCalculateDrawProperties(root);
miletus9d3da522015-06-05 19:45:073019
danakj5e6ff6d2015-09-05 04:43:443020 EXPECT_EQ(gfx::RectF(100.f, 100.f),
miletus9d3da522015-06-05 19:45:073021 root->render_surface()->DrawableContentRect());
3022 // In target space, not clipped.
3023 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
3024 // In layer space, clipped.
danakj5e6ff6d2015-09-05 04:43:443025 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
miletus9d3da522015-06-05 19:45:073026}
3027
[email protected]989386c2013-07-18 21:37:233028TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
weiliangc0dece732015-07-27 19:06:173029 LayerImpl* root = root_layer();
3030 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
3031 child1_layer->SetDrawsContent(true);
3032 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
3033 child2_layer->SetDrawsContent(true);
3034 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
3035 child3_layer->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283036
[email protected]fb661802013-03-25 01:59:323037 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173038 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3039 gfx::PointF(), gfx::Size(100, 100), true, false,
3040 true);
3041 SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(),
3042 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]fb661802013-03-25 01:59:323043 false);
weiliangc0dece732015-07-27 19:06:173044 SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(),
3045 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3046 false, false);
3047 SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(),
3048 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3049 true, false, false);
[email protected]fb661802013-03-25 01:59:323050
weiliangc0dece732015-07-27 19:06:173051 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323052
danakj5e6ff6d2015-09-05 04:43:443053 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323054 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323055
danakj64767d902015-06-19 00:10:433056 // Layers that do not draw content should have empty visible_layer_rects.
3057 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323058
danakj64767d902015-06-19 00:10:433059 // layer visible_layer_rects are clipped by their target surface.
weiliangc0dece732015-07-27 19:06:173060 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
3061 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
3062 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323063
3064 // layer drawable_content_rects are not clipped.
weiliangc0dece732015-07-27 19:06:173065 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
3066 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
3067 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323068}
3069
[email protected]989386c2013-07-18 21:37:233070TEST_F(LayerTreeHostCommonTest,
3071 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
weiliangc0dece732015-07-27 19:06:173072 LayerImpl* root = root_layer();
3073 LayerImpl* child = AddChildToRoot<LayerImpl>();
3074 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
3075 grand_child1->SetDrawsContent(true);
3076 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
3077 grand_child2->SetDrawsContent(true);
3078 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
3079 grand_child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283080
[email protected]fb661802013-03-25 01:59:323081 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173082 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3083 gfx::PointF(), gfx::Size(100, 100), true, false,
3084 true);
3085 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
3086 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]fb661802013-03-25 01:59:323087 false);
weiliangc0dece732015-07-27 19:06:173088 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
3089 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3090 false, false);
3091 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
3092 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3093 false, false);
3094 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
3095 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3096 true, false, false);
[email protected]fb661802013-03-25 01:59:323097
3098 child->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:173099 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323100
danakj5e6ff6d2015-09-05 04:43:443101 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323102 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323103
3104 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433105 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3106 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323107
3108 // All grandchild visible content rects should be clipped by child.
danakj64767d902015-06-19 00:10:433109 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
3110 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
3111 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323112
3113 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:323114 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
3115 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323116 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
3117}
3118
ajuma27442dd2015-03-30 19:19:483119TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
loyso0940d412016-03-14 01:30:313120 scoped_refptr<Layer> root = Layer::Create();
3121 scoped_refptr<Layer> child = Layer::Create();
ajuma27442dd2015-03-30 19:19:483122 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loyso0940d412016-03-14 01:30:313123 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajuma27442dd2015-03-30 19:19:483124 root->AddChild(child);
3125 child->AddChild(grand_child);
3126
ennea7b43c32015-06-18 20:01:333127 host()->SetRootLayer(root);
ajuma27442dd2015-03-30 19:19:483128
3129 gfx::Transform identity_matrix;
3130 gfx::Transform child_scale_matrix;
3131 child_scale_matrix.Scale(0.25f, 0.25f);
3132 gfx::Transform grand_child_scale_matrix;
3133 grand_child_scale_matrix.Scale(0.246f, 0.246f);
3134 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
3135 gfx::PointF(), gfx::Size(100, 100), true, false);
3136 SetLayerPropertiesForTesting(child.get(), child_scale_matrix, gfx::Point3F(),
3137 gfx::PointF(), gfx::Size(10, 10), true, false);
3138 SetLayerPropertiesForTesting(grand_child.get(), grand_child_scale_matrix,
3139 gfx::Point3F(), gfx::PointF(),
3140 gfx::Size(100, 100), true, false);
3141
3142 child->SetMasksToBounds(true);
enne601f2ef12015-05-19 18:20:173143 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajuma27442dd2015-03-30 19:19:483144
3145 // The visible rect is expanded to integer coordinates in target space before
3146 // being projected back to layer space, where it is once again expanded to
3147 // integer coordinates.
jaydasika74bf516f2016-04-01 19:48:153148 EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_layer_rect_for_testing());
ajuma27442dd2015-03-30 19:19:483149}
3150
[email protected]989386c2013-07-18 21:37:233151TEST_F(LayerTreeHostCommonTest,
3152 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
weiliangc0dece732015-07-27 19:06:173153 LayerImpl* root = root_layer();
3154 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3155 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3156 child1->SetDrawsContent(true);
3157 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
3158 child2->SetDrawsContent(true);
3159 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
3160 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283161
[email protected]fb661802013-03-25 01:59:323162 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173163 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3164 gfx::PointF(), gfx::Size(100, 100), true, false,
3165 true);
3166 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3167 gfx::PointF(), gfx::Size(3, 4), true, false,
3168 true);
3169 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3170 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3171 false, false);
3172 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3173 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3174 false, false);
3175 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3176 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3177 true, false, false);
[email protected]fb661802013-03-25 01:59:323178
weiliangc0dece732015-07-27 19:06:173179 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323180
weiliangc0dece732015-07-27 19:06:173181 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323182
danakj5e6ff6d2015-09-05 04:43:443183 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323184 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323185
3186 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433187 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173188 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323189
3190 // An unclipped surface grows its DrawableContentRect to include all drawable
3191 // regions of the subtree.
danakj5e6ff6d2015-09-05 04:43:443192 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
weiliangc0dece732015-07-27 19:06:173193 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323194
3195 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:433196 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3197 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3198 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323199
hush6b614212014-12-04 22:37:323200 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3201 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3202 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323203}
3204
[email protected]989386c2013-07-18 21:37:233205TEST_F(LayerTreeHostCommonTest,
ajuma51d73f72015-10-19 19:43:583206 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) {
3207 LayerImpl* root = root_layer();
3208 LayerImpl* parent = AddChild<LayerImpl>(root);
3209 LayerImpl* child1 = AddChild<LayerImpl>(parent);
3210 LayerImpl* child2 = AddChild<LayerImpl>(parent);
3211 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1);
3212 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2);
3213 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
3214 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
3215
3216 root->SetDrawsContent(true);
3217 parent->SetDrawsContent(true);
3218 child1->SetDrawsContent(true);
3219 child2->SetDrawsContent(true);
3220 grand_child1->SetDrawsContent(true);
3221 grand_child2->SetDrawsContent(true);
3222 leaf_node1->SetDrawsContent(true);
3223 leaf_node2->SetDrawsContent(true);
3224
3225 const gfx::Transform identity_matrix;
3226
3227 // child1 and child2 get render surfaces when surfaces are enabled.
3228 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3229 gfx::PointF(), gfx::Size(100, 100), true, false,
3230 true);
3231 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3232 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
3233 false, false);
3234 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3235 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
3236 false, true);
3237 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3238 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
3239 false, true);
3240 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
3241 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
3242 true, false, false);
3243 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
3244 gfx::PointF(7.f, 7.f), gfx::Size(1500, 1500),
3245 true, false, false);
3246 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
3247 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
3248 true, false, false);
3249 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
3250 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
3251 true, false, false);
3252
3253 // Case 1: No layers clip. Visible rects are clipped by the viewport, but the
3254 // viewport clip doesn't apply to layers that draw into unclipped surfaces.
3255 // Each layer's drawable content rect is its bounds in target space; the only
3256 // thing that changes with surfaces disabled is that target space is always
3257 // screen space.
weiliangcc154ce22015-12-09 03:39:263258 root->SetHasRenderSurface(true);
3259 child1->SetHasRenderSurface(true);
3260 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583261 ExecuteCalculateDrawProperties(root);
3262 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3263 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect());
3264 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3265 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3266 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child1->visible_layer_rect());
3267 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3268 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node1->visible_layer_rect());
3269 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node2->visible_layer_rect());
3270
3271 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3272 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3273 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3274 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3275 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3276 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3277 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3278 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3279
3280 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3281 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3282 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3283 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3284 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3285 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3286 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3287 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3288 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3289
3290 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3291 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3292 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3293 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3294 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500),
3295 grand_child1->drawable_content_rect());
3296 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3297 grand_child2->drawable_content_rect());
3298 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect());
3299 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect());
3300
3301 // Case 2: The parent clips. In this case, neither surface is unclipped, so
3302 // all visible layer rects are clipped by the intersection of all ancestor
3303 // clips, whether or not surfaces are disabled. However, drawable content
3304 // rects are clipped only until the next render surface is reached, so
3305 // descendants of parent have their drawable content rects clipped only when
3306 // surfaces are disabled.
3307 parent->SetMasksToBounds(true);
3308 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:263309 root->SetHasRenderSurface(true);
3310 child1->SetHasRenderSurface(true);
3311 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583312 ExecuteCalculateDrawProperties(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(800, 800), child1->drawable_content_rect());
3325 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3326 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3327 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3328 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3329 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3330
3331 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3332 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3333 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3334 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3335 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3336 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3337 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3338 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3339 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3340
3341 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3342 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3343 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect());
3344 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect());
3345 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect());
3346 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect());
3347 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect());
3348 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect());
3349
3350 parent->SetMasksToBounds(false);
3351
3352 // Case 3: child1 and grand_child2 clip. In this case, descendants of these
3353 // layers have their visible rects clipped by them; without surfaces, these
3354 // rects are also clipped by the viewport. Similarly, descendants of these
3355 // layers have their drawable content rects clipped by them.
3356 child1->SetMasksToBounds(true);
3357 grand_child2->SetMasksToBounds(true);
3358 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:263359 root->SetHasRenderSurface(true);
3360 child1->SetHasRenderSurface(true);
3361 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583362 ExecuteCalculateDrawProperties(root);
3363 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3364 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3365 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3366 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3367 EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect());
3368 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3369 EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect());
3370 EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect());
3371
3372 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3373 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3374 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3375 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3376 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect());
3377 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3378 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect());
3379 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect());
3380
3381 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3382 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3383 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3384 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3385 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3386 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3387 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3388 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3389 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3390
3391 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3392 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3393 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3394 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3395 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect());
3396 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3397 grand_child2->drawable_content_rect());
3398 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect());
3399 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect());
3400}
3401
3402TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:023403 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
enne6c281f6e2015-08-18 23:23:003404 LayerImpl* root = root_layer();
3405 LayerImpl* child1 = AddChild<LayerImpl>(root);
3406 LayerImpl* child2 = AddChild<LayerImpl>(root);
3407 LayerImpl* child3 = AddChild<LayerImpl>(root);
3408 child1->SetDrawsContent(true);
3409 child2->SetDrawsContent(true);
3410 child3->SetDrawsContent(true);
hush887bb542014-12-02 22:49:023411
3412 gfx::Transform identity_matrix;
enne6c281f6e2015-08-18 23:23:003413 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3414 gfx::PointF(), gfx::Size(100, 100), true, false,
3415 true);
3416 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023417 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
enne6c281f6e2015-08-18 23:23:003418 false, false);
3419 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023420 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
enne6c281f6e2015-08-18 23:23:003421 false, false);
3422 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023423 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
enne6c281f6e2015-08-18 23:23:003424 true, false, false);
hush887bb542014-12-02 22:49:023425
enne6c281f6e2015-08-18 23:23:003426 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:443427 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
hush887bb542014-12-02 22:49:023428 // Now set the root render surface an empty clip.
enne6c281f6e2015-08-18 23:23:003429 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:443430 root, gfx::Size(), &render_surface_layer_list_impl,
3431 root->layer_tree_impl()->current_render_surface_list_id());
hush887bb542014-12-02 22:49:023432
3433 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
3434 ASSERT_TRUE(root->render_surface());
3435 EXPECT_FALSE(root->is_clipped());
3436
3437 gfx::Rect empty;
3438 EXPECT_EQ(empty, root->render_surface()->clip_rect());
3439 EXPECT_TRUE(root->render_surface()->is_clipped());
3440
3441 // Visible content rect calculation will check if the target surface is
3442 // clipped or not. An empty clip rect does not indicate the render surface
3443 // is unclipped.
danakj64767d902015-06-19 00:10:433444 EXPECT_EQ(empty, child1->visible_layer_rect());
3445 EXPECT_EQ(empty, child2->visible_layer_rect());
3446 EXPECT_EQ(empty, child3->visible_layer_rect());
hush887bb542014-12-02 22:49:023447}
3448
3449TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233450 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
weiliangc0dece732015-07-27 19:06:173451 LayerImpl* root = root_layer();
3452 LayerImpl* child = AddChildToRoot<LayerImpl>();
3453 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283454
[email protected]630ddad2013-08-16 03:01:323455 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473456 gfx::Transform identity_matrix;
3457 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323458 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473459
weiliangc0dece732015-07-27 19:06:173460 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3461 gfx::PointF(), gfx::Size(100, 100), true, false,
3462 true);
3463 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3464 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3465 false, false);
[email protected]451107a32013-04-10 05:12:473466
weiliangc0dece732015-07-27 19:06:173467 ExecuteCalculateDrawProperties(root);
[email protected]451107a32013-04-10 05:12:473468
danakj64767d902015-06-19 00:10:433469 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473470 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323471
[email protected]08bdf1b2014-04-16 23:23:293472 // Case 2: a matrix with flattened z, uninvertible and not visible according
3473 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:323474 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263475 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323476 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3477
weiliangc0dece732015-07-27 19:06:173478 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3479 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3480 false, false);
[email protected]630ddad2013-08-16 03:01:323481
weiliangc0dece732015-07-27 19:06:173482 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323483
danakj64767d902015-06-19 00:10:433484 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293485 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323486
[email protected]08bdf1b2014-04-16 23:23:293487 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:323488 uninvertible_matrix.MakeIdentity();
3489 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263490 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323491 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3492
weiliangc0dece732015-07-27 19:06:173493 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3494 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3495 false, false);
[email protected]630ddad2013-08-16 03:01:323496
weiliangc0dece732015-07-27 19:06:173497 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323498
danakj64767d902015-06-19 00:10:433499 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293500 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473501}
3502
[email protected]989386c2013-07-18 21:37:233503TEST_F(LayerTreeHostCommonTest,
ajumaae0dc2d2015-08-05 21:55:563504 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
3505 LayerImpl* root = root_layer();
3506 LayerImpl* child = AddChildToRoot<LayerImpl>();
3507 LayerImpl* grand_child = AddChild<LayerImpl>(child);
3508 child->SetDrawsContent(true);
3509 grand_child->SetDrawsContent(true);
3510
3511 gfx::Transform identity_matrix;
3512
3513 gfx::Transform perspective;
3514 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3515
3516 gfx::Transform rotation;
3517 rotation.RotateAboutYAxis(45.0);
3518
3519 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3520 gfx::PointF(), gfx::Size(100, 100), true, false,
3521 true);
3522 SetLayerPropertiesForTesting(child, perspective, gfx::Point3F(),
3523 gfx::PointF(10.f, 10.f), gfx::Size(100, 100),
3524 false, true, false);
3525 SetLayerPropertiesForTesting(grand_child, rotation, gfx::Point3F(),
3526 gfx::PointF(), gfx::Size(100, 100), false, true,
3527 false);
3528
3529 ExecuteCalculateDrawProperties(root);
3530
3531 // Though all layers have invertible transforms, matrix multiplication using
3532 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053533 EXPECT_FALSE(root->layer_tree_impl()
3534 ->property_trees()
3535 ->transform_tree.Node(grand_child->transform_tree_index())
3536 ->data.ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563537
sunxd71aea3e2016-04-01 23:48:053538 // CalcDrawProps skips a subtree when a layer's screen space transform is
3539 // uninvertible
3540 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
ajumaae0dc2d2015-08-05 21:55:563541}
3542
3543TEST_F(LayerTreeHostCommonTest,
3544 OcclusionForLayerWithUninvertibleDrawTransform) {
khushalsagarb64b360d2015-10-21 19:25:163545 FakeImplTaskRunnerProvider task_runner_provider;
ajumaae0dc2d2015-08-05 21:55:563546 TestSharedBitmapManager shared_bitmap_manager;
3547 TestTaskGraphRunner task_graph_runner;
revemand180dfc32015-09-24 00:19:433548 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
khushalsagarb64b360d2015-10-21 19:25:163549 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
ajumaae0dc2d2015-08-05 21:55:563550 &task_graph_runner);
3551 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
3552 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
3553 scoped_ptr<LayerImpl> grand_child =
3554 LayerImpl::Create(host_impl.active_tree(), 3);
3555 scoped_ptr<LayerImpl> occluding_child =
3556 LayerImpl::Create(host_impl.active_tree(), 4);
3557 child->SetDrawsContent(true);
3558 grand_child->SetDrawsContent(true);
3559 occluding_child->SetDrawsContent(true);
3560 occluding_child->SetContentsOpaque(true);
3561
3562 gfx::Transform identity_matrix;
3563 gfx::Transform perspective;
3564 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3565
3566 gfx::Transform rotation;
3567 rotation.RotateAboutYAxis(45.0);
3568
3569 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
3570 gfx::PointF(), gfx::Size(1000, 1000), true,
3571 false, true);
3572 SetLayerPropertiesForTesting(child.get(), perspective, gfx::Point3F(),
3573 gfx::PointF(10.f, 10.f), gfx::Size(300, 300),
3574 false, true, false);
3575 SetLayerPropertiesForTesting(grand_child.get(), rotation, gfx::Point3F(),
3576 gfx::PointF(), gfx::Size(200, 200), false, true,
3577 false);
3578 SetLayerPropertiesForTesting(occluding_child.get(), identity_matrix,
3579 gfx::Point3F(), gfx::PointF(),
3580 gfx::Size(200, 200), false, false, false);
3581
3582 host_impl.SetViewportSize(root->bounds());
3583
danakja04855a2015-11-18 20:39:103584 child->AddChild(std::move(grand_child));
3585 root->AddChild(std::move(child));
3586 root->AddChild(std::move(occluding_child));
3587 host_impl.active_tree()->SetRootLayer(std::move(root));
sievers71c62dd52015-10-07 01:44:393588 host_impl.SetVisible(true);
revemand180dfc32015-09-24 00:19:433589 host_impl.InitializeRenderer(output_surface.get());
jaydasikad7dea632015-11-06 04:40:123590 host_impl.active_tree()->BuildPropertyTreesForTesting();
ajumaae0dc2d2015-08-05 21:55:563591 bool update_lcd_text = false;
3592 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3593
3594 LayerImpl* grand_child_ptr =
vollick83fbfc82016-03-22 18:33:273595 host_impl.active_tree()->root_layer()->children()[0]->children()[0];
ajumaae0dc2d2015-08-05 21:55:563596
3597 // Though all layers have invertible transforms, matrix multiplication using
3598 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053599 EXPECT_FALSE(
3600 host_impl.active_tree()
3601 ->property_trees()
3602 ->transform_tree.Node(grand_child_ptr->transform_tree_index())
3603 ->data.ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563604
sunxd71aea3e2016-04-01 23:48:053605 // Since |grand_child| has an uninvertible screen space transform, it is
3606 // skipped so
3607 // that we are not computing its occlusion_in_content_space.
3608 gfx::Rect layer_bounds = gfx::Rect();
ajumaae0dc2d2015-08-05 21:55:563609 EXPECT_EQ(
3610 layer_bounds,
3611 grand_child_ptr->draw_properties()
3612 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
3613}
3614
3615TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233616 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
weiliangc0dece732015-07-27 19:06:173617 LayerImpl* root = root_layer();
3618 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3619 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3620 child1->SetDrawsContent(true);
3621 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
3622 child2->SetDrawsContent(true);
3623 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
3624 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283625
[email protected]fb661802013-03-25 01:59:323626 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173627 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3628 gfx::PointF(), gfx::Size(100, 100), true, false,
3629 true);
3630 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3631 gfx::PointF(), gfx::Size(3, 4), true, false,
3632 true);
3633 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3634 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3635 false, false);
3636 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3637 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3638 false, false);
3639 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3640 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3641 true, false, false);
[email protected]fb661802013-03-25 01:59:323642
3643 root->SetMasksToBounds(true);
[email protected]fb661802013-03-25 01:59:323644
weiliangc0dece732015-07-27 19:06:173645 ExecuteCalculateDrawProperties(root);
3646
3647 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323648
danakj5e6ff6d2015-09-05 04:43:443649 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323650 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323651
3652 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433653 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173654 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323655
3656 // A clipped surface grows its DrawableContentRect to include all drawable
3657 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443658 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
weiliangc0dece732015-07-27 19:06:173659 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323660
3661 // All layers that draw content into the surface have their visible content
3662 // rect clipped by the surface clip rect.
danakj64767d902015-06-19 00:10:433663 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3664 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3665 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323666
3667 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323668 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3669 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3670 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323671}
3672
[email protected]989386c2013-07-18 21:37:233673TEST_F(LayerTreeHostCommonTest,
3674 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323675 // Check that clipping does not propagate down surfaces.
weiliangc0dece732015-07-27 19:06:173676 LayerImpl* root = root_layer();
3677 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3678 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
3679 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
3680 child1->SetDrawsContent(true);
3681 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
3682 child2->SetDrawsContent(true);
3683 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
3684 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283685
[email protected]fb661802013-03-25 01:59:323686 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173687 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3688 gfx::PointF(), gfx::Size(100, 100), true, false,
3689 true);
3690 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3691 gfx::PointF(), gfx::Size(3, 4), true, false,
3692 true);
3693 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3694 gfx::PointF(), gfx::Size(7, 13), true, false,
3695 true);
3696 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3697 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3698 false, false);
3699 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3700 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3701 false, false);
3702 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3703 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3704 true, false, false);
[email protected]fb661802013-03-25 01:59:323705
3706 root->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:173707
3708 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323709
3710 ASSERT_TRUE(render_surface1->render_surface());
3711 ASSERT_TRUE(render_surface2->render_surface());
3712
danakj5e6ff6d2015-09-05 04:43:443713 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323714 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323715
3716 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433717 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3718 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3719 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323720
3721 // A clipped surface grows its DrawableContentRect to include all drawable
3722 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443723 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
hush6b614212014-12-04 22:37:323724 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323725
3726 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3727 // is only implicitly clipped by render_surface1's content rect. So,
3728 // render_surface2 grows to enclose all drawable content of its subtree.
danakj5e6ff6d2015-09-05 04:43:443729 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
hush6b614212014-12-04 22:37:323730 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323731
3732 // All layers that draw content into render_surface2 think they are unclipped.
danakj64767d902015-06-19 00:10:433733 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3734 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3735 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323736
3737 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323738 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3739 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3740 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323741}
3742
[email protected]989386c2013-07-18 21:37:233743TEST_F(LayerTreeHostCommonTest,
jaydasika27d0f2e2015-10-16 23:52:463744 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) {
3745 LayerImpl* root = root_layer();
3746 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3747 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
3748 LayerImpl* child2 = AddChild<LayerImpl>(child1);
3749 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2);
3750 child1->SetDrawsContent(true);
3751 child2->SetDrawsContent(true);
3752 render_surface2->SetDrawsContent(true);
3753
3754 gfx::Transform identity_matrix;
3755 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3756 gfx::PointF(), gfx::Size(100, 100), true, false,
3757 true);
3758 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3759 gfx::PointF(), gfx::Size(100, 100), true, false,
3760 true);
3761 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3762 gfx::PointF(), gfx::Size(500, 500), true, false,
3763 false);
3764 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3765 gfx::PointF(), gfx::Size(700, 700), true, false,
3766 false);
3767 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3768 gfx::PointF(), gfx::Size(1000, 1000), true,
3769 false, true);
3770
3771 child1->SetMasksToBounds(true);
3772 child2->SetMasksToBounds(true);
3773
3774 ExecuteCalculateDrawProperties(root);
3775 EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect());
3776 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect());
3777}
3778
jaydasika75ad0a42016-02-12 19:47:193779TEST_F(LayerTreeHostCommonTest, ClipChildWithSingularTransform) {
3780 LayerImpl* root = root_layer();
3781 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3782 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
3783 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
3784
3785 clip_child->SetDrawsContent(true);
3786 clip_child->SetClipParent(clip_parent);
3787 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3788 clip_children->insert(clip_child);
3789 clip_parent->SetClipChildren(clip_children.release());
3790
3791 gfx::Transform identity_matrix;
3792 gfx::Transform singular_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3793 ASSERT_FALSE(singular_matrix.IsInvertible());
3794
3795 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3796 gfx::PointF(), gfx::Size(100, 100), true, false,
3797 true);
3798 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3799 gfx::PointF(), gfx::Size(50, 50), true, false,
3800 false);
3801 SetLayerPropertiesForTesting(intervening, identity_matrix, gfx::Point3F(),
3802 gfx::PointF(), gfx::Size(50, 50), true, false,
3803 false);
3804 SetLayerPropertiesForTesting(clip_child, singular_matrix, gfx::Point3F(),
3805 gfx::PointF(), gfx::Size(60, 60), true, false,
3806 false);
3807
3808 ExecuteCalculateDrawProperties(root);
3809 EXPECT_EQ(intervening->num_unclipped_descendants(), 1u);
3810}
3811
jaydasika27d0f2e2015-10-16 23:52:463812TEST_F(LayerTreeHostCommonTest,
3813 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) {
3814 LayerImpl* root = root_layer();
3815 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3816 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3817 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3818 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3819
3820 render_surface1->SetDrawsContent(true);
3821 render_surface2->SetDrawsContent(true);
3822 clip_child->SetDrawsContent(true);
3823 clip_child->SetClipParent(clip_parent);
3824 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3825 clip_children->insert(clip_child);
3826 clip_parent->SetClipChildren(clip_children.release());
3827
3828 gfx::Transform identity_matrix;
3829 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3830 gfx::PointF(), gfx::Size(100, 100), true, false,
3831 true);
3832 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3833 gfx::PointF(), gfx::Size(50, 50), true, false,
3834 false);
3835 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3836 gfx::PointF(), gfx::Size(20, 20), true, false,
3837 true);
3838 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3839 gfx::PointF(), gfx::Size(60, 60), true, false,
3840 false);
3841 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3842 gfx::PointF(), gfx::Size(60, 60), true, false,
3843 true);
3844 clip_parent->SetMasksToBounds(true);
3845 render_surface1->SetMasksToBounds(true);
3846
3847 ExecuteCalculateDrawProperties(root);
3848 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect());
3849 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect());
3850 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect());
3851}
3852
jaydasika1f5312d2015-10-21 21:34:323853TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) {
3854 LayerImpl* root = root_layer();
3855 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3856 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3857 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3858 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3859
3860 render_surface1->SetDrawsContent(true);
3861 render_surface2->SetDrawsContent(true);
3862 clip_child->SetDrawsContent(true);
3863 clip_child->SetClipParent(clip_parent);
3864 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3865 clip_children->insert(clip_child);
3866 clip_parent->SetClipChildren(clip_children.release());
3867
3868 gfx::Transform identity_matrix;
3869 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3870 gfx::PointF(), gfx::Size(100, 100), true, false,
3871 true);
3872 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3873 gfx::PointF(2.f, 2.f), gfx::Size(50, 50), true,
3874 false, false);
3875 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3876 gfx::PointF(), gfx::Size(20, 20), true, false,
3877 true);
3878 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3879 gfx::PointF(), gfx::Size(60, 60), true, false,
3880 false);
3881 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3882 gfx::PointF(), gfx::Size(60, 60), true, false,
3883 true);
3884 clip_parent->SetMasksToBounds(true);
3885 render_surface1->SetMasksToBounds(true);
3886
3887 ExecuteCalculateDrawProperties(root);
3888 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect());
3889}
3890
jaydasika77a4a072015-10-20 21:47:273891TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) {
3892 // Test that only drawn layers contribute to render surface content rect.
3893 LayerImpl* root = root_layer();
3894 LayerImpl* surface = AddChildToRoot<LayerImpl>();
3895 LayerImpl* test_layer = AddChild<LayerImpl>(surface);
3896
3897 test_layer->SetDrawsContent(false);
3898 surface->SetDrawsContent(true);
3899 gfx::Transform identity_matrix;
3900 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3901 gfx::PointF(), gfx::Size(200, 200), true, false,
3902 true);
3903 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
3904 gfx::PointF(), gfx::Size(100, 100), true, false,
3905 true);
3906 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
3907 gfx::PointF(), gfx::Size(150, 150), true, false,
3908 false);
3909
3910 ExecuteCalculateDrawProperties(root);
3911 EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect());
3912
3913 test_layer->SetDrawsContent(true);
3914 ExecuteCalculateDrawProperties(root);
3915 EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect());
3916}
3917
jaydasika27d0f2e2015-10-16 23:52:463918TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) {
3919 // Tests visible rects computation when we have unclipped_surface->
3920 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3921 // of surface_with_unclipped_descendants doesn't propagate to the
3922 // clipped_surface below it.
3923 LayerImpl* root = root_layer();
3924 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3925 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3926 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3927 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3928 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3929
3930 unclipped_surface->SetDrawsContent(true);
3931 unclipped_desc_surface->SetDrawsContent(true);
3932 clipped_surface->SetDrawsContent(true);
3933 clip_child->SetClipParent(clip_parent);
3934 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3935 clip_children->insert(clip_child);
3936 clip_parent->SetClipChildren(clip_children.release());
3937
3938 gfx::Transform identity_matrix;
3939 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3940 gfx::PointF(), gfx::Size(100, 100), true, false,
3941 true);
3942 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
3943 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
3944 true, false, true);
3945 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3946 gfx::PointF(), gfx::Size(50, 50), true, false,
3947 false);
3948 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
3949 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
3950 true, false, true);
3951 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3952 gfx::PointF(), gfx::Size(60, 60), true, false,
3953 false);
3954 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
3955 gfx::PointF(), gfx::Size(60, 60), true, false,
3956 true);
3957 clip_parent->SetMasksToBounds(true);
3958
3959 ExecuteCalculateDrawProperties(root);
3960 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect());
3961 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect());
3962 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect());
3963}
3964
3965TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) {
3966 // Tests visible rects computation when we have unclipped_surface->
3967 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3968 // of root propagate to the clipped_surface.
3969 LayerImpl* root = root_layer();
3970 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3971 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3972 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3973 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3974 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3975
3976 unclipped_surface->SetDrawsContent(true);
3977 unclipped_desc_surface->SetDrawsContent(true);
3978 clipped_surface->SetDrawsContent(true);
3979 clip_child->SetClipParent(clip_parent);
3980 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3981 clip_children->insert(clip_child);
3982 clip_parent->SetClipChildren(clip_children.release());
3983
3984 gfx::Transform identity_matrix;
3985 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3986 gfx::PointF(), gfx::Size(10, 10), true, false,
3987 true);
3988 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
3989 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
3990 true, false, true);
3991 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3992 gfx::PointF(), gfx::Size(50, 50), true, false,
3993 false);
3994 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
3995 gfx::Point3F(), gfx::PointF(),
3996 gfx::Size(100, 100), true, false, true);
3997 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3998 gfx::PointF(), gfx::Size(100, 100), true, false,
3999 false);
4000 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
4001 gfx::PointF(), gfx::Size(50, 50), true, false,
4002 true);
4003 clip_parent->SetMasksToBounds(true);
4004 unclipped_desc_surface->SetMasksToBounds(true);
4005
4006 ExecuteCalculateDrawProperties(root);
4007 EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect());
weiliangc0e13ba602016-03-12 04:53:564008 EXPECT_EQ(gfx::Rect(50, 50), unclipped_desc_surface->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:464009 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect());
4010}
4011
4012TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:234013 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:324014 // Layers that have non-axis aligned bounds (due to transforms) have an
4015 // expanded, axis-aligned DrawableContentRect and visible content rect.
weiliangc0dece732015-07-27 19:06:174016 LayerImpl* root = root_layer();
4017 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4018 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
4019 child1->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284020
[email protected]fb661802013-03-25 01:59:324021 gfx::Transform identity_matrix;
4022 gfx::Transform child_rotation;
4023 child_rotation.Rotate(45.0);
weiliangc0dece732015-07-27 19:06:174024 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4025 gfx::PointF(), gfx::Size(100, 100), true, false,
4026 true);
4027 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
4028 gfx::PointF(), gfx::Size(3, 4), true, false,
4029 true);
4030 SetLayerPropertiesForTesting(
4031 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
4032 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
[email protected]fb661802013-03-25 01:59:324033
weiliangc0dece732015-07-27 19:06:174034 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:324035
weiliangc0dece732015-07-27 19:06:174036 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324037
danakj5e6ff6d2015-09-05 04:43:444038 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:324039 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324040
4041 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:434042 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:174043 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324044
4045 // The unclipped surface grows its DrawableContentRect to include all drawable
4046 // regions of the subtree.
4047 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
4048 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:264049 gfx::Rect(50 - diagonal_radius,
4050 50 - diagonal_radius,
4051 diagonal_radius * 2,
4052 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444053 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content),
weiliangc0dece732015-07-27 19:06:174054 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324055
4056 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:434057 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
hush6b614212014-12-04 22:37:324058 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324059}
4060
[email protected]989386c2013-07-18 21:37:234061TEST_F(LayerTreeHostCommonTest,
4062 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:324063 // Layers that have non-axis aligned bounds (due to transforms) have an
4064 // expanded, axis-aligned DrawableContentRect and visible content rect.
weiliangc0dece732015-07-27 19:06:174065 LayerImpl* root = root_layer();
4066 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4067 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
4068 child1->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284069
[email protected]fb661802013-03-25 01:59:324070 gfx::Transform identity_matrix;
4071 gfx::Transform child_rotation;
4072 child_rotation.Rotate(45.0);
weiliangc0dece732015-07-27 19:06:174073 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4074 gfx::PointF(), gfx::Size(50, 50), true, false,
4075 true);
4076 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
4077 gfx::PointF(), gfx::Size(3, 4), true, false,
4078 true);
[email protected]a2566412014-06-05 03:14:204079
weiliangc0dece732015-07-27 19:06:174080 SetLayerPropertiesForTesting(
4081 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
4082 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
[email protected]fb661802013-03-25 01:59:324083
4084 root->SetMasksToBounds(true);
[email protected]fb661802013-03-25 01:59:324085
weiliangc0dece732015-07-27 19:06:174086 ExecuteCalculateDrawProperties(root);
4087
4088 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324089
4090 // The clipped surface clamps the DrawableContentRect that encloses the
4091 // rotated layer.
4092 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:264093 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
4094 50 - diagonal_radius,
4095 diagonal_radius * 2,
4096 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444097 gfx::RectF expected_surface_drawable_content(
4098 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
hush6b614212014-12-04 22:37:324099 EXPECT_EQ(expected_surface_drawable_content,
weiliangc0dece732015-07-27 19:06:174100 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324101
4102 // On the clipped surface, only a quarter of the child1 is visible, but when
4103 // rotating it back to child1's content space, the actual enclosing rect ends
4104 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:264105 //
4106 // Given the floating point math, this number is a little bit fuzzy.
danakj64767d902015-06-19 00:10:434107 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324108
4109 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:324110 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324111}
4112
[email protected]989386c2013-07-18 21:37:234113TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
weiliangc0dece732015-07-27 19:06:174114 LayerImpl* root = root_layer();
4115 FakePictureLayerImpl* render_surface1 =
4116 AddChildToRoot<FakePictureLayerImpl>();
4117 render_surface1->SetDrawsContent(true);
4118 FakePictureLayerImpl* render_surface2 =
4119 AddChild<FakePictureLayerImpl>(render_surface1);
4120 render_surface2->SetDrawsContent(true);
4121 FakePictureLayerImpl* child1 =
4122 AddChild<FakePictureLayerImpl>(render_surface2);
4123 child1->SetDrawsContent(true);
4124 FakePictureLayerImpl* child2 =
4125 AddChild<FakePictureLayerImpl>(render_surface2);
4126 child2->SetDrawsContent(true);
4127 FakePictureLayerImpl* child3 =
4128 AddChild<FakePictureLayerImpl>(render_surface2);
4129 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284130
[email protected]fb661802013-03-25 01:59:324131 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:174132 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4133 gfx::PointF(), gfx::Size(100, 100), true, false,
4134 true);
4135 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
4136 gfx::PointF(5.f, 5.f), gfx::Size(3, 4), true,
4137 false, true);
4138 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
4139 gfx::PointF(5.f, 5.f), gfx::Size(7, 13), true,
4140 false, true);
4141 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
4142 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
4143 false, false);
4144 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4145 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
4146 false, false);
4147 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
4148 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
4149 true, false, false);
[email protected]fb661802013-03-25 01:59:324150
4151 float device_scale_factor = 2.f;
4152
4153 root->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:174154
4155 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324156
4157 ASSERT_TRUE(render_surface1->render_surface());
4158 ASSERT_TRUE(render_surface2->render_surface());
4159
4160 // drawable_content_rects for all layers and surfaces are scaled by
4161 // device_scale_factor.
danakj5e6ff6d2015-09-05 04:43:444162 EXPECT_EQ(gfx::RectF(200.f, 200.f),
hush6b614212014-12-04 22:37:324163 root->render_surface()->DrawableContentRect());
danakj5e6ff6d2015-09-05 04:43:444164 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
hush6b614212014-12-04 22:37:324165 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324166
4167 // render_surface2 lives in the "unclipped universe" of render_surface1, and
4168 // is only implicitly clipped by render_surface1.
danakj5e6ff6d2015-09-05 04:43:444169 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f),
hush6b614212014-12-04 22:37:324170 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324171
hush6b614212014-12-04 22:37:324172 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
4173 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
4174 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324175
4176 // The root layer does not actually draw content of its own.
danakj64767d902015-06-19 00:10:434177 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324178
sohan.jyotie3bd6192014-10-13 07:13:594179 // All layer visible content rects are not expressed in content space of each
4180 // layer, so they are not scaled by the device_scale_factor.
danakj64767d902015-06-19 00:10:434181 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
4182 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
4183 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
4184 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
4185 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324186}
4187
[email protected]989386c2013-07-18 21:37:234188TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:324189 // Verify the behavior of back-face culling when there are no preserve-3d
4190 // layers. Note that 3d transforms still apply in this case, but they are
4191 // "flattened" to each parent layer according to current W3C spec.
4192
4193 const gfx::Transform identity_matrix;
loyso0940d412016-03-14 01:30:314194 scoped_refptr<Layer> parent = Layer::Create();
[email protected]fb661802013-03-25 01:59:324195 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
loyso0940d412016-03-14 01:30:314196 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324197 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
loyso0940d412016-03-14 01:30:314198 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324199 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
loyso0940d412016-03-14 01:30:314200 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324201 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
loyso0940d412016-03-14 01:30:314202 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324203 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:234204 front_facing_child_of_front_facing_surface =
loyso0940d412016-03-14 01:30:314205 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324206 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:234207 back_facing_child_of_front_facing_surface =
loyso0940d412016-03-14 01:30:314208 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324209 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:234210 front_facing_child_of_back_facing_surface =
loyso0940d412016-03-14 01:30:314211 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324212 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:234213 back_facing_child_of_back_facing_surface =
loyso0940d412016-03-14 01:30:314214 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324215
4216 parent->AddChild(front_facing_child);
4217 parent->AddChild(back_facing_child);
4218 parent->AddChild(front_facing_surface);
4219 parent->AddChild(back_facing_surface);
4220 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
4221 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
4222 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
4223 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
4224
ennea7b43c32015-06-18 20:01:334225 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:284226
[email protected]fb661802013-03-25 01:59:324227 // Nothing is double-sided
4228 front_facing_child->SetDoubleSided(false);
4229 back_facing_child->SetDoubleSided(false);
4230 front_facing_surface->SetDoubleSided(false);
4231 back_facing_surface->SetDoubleSided(false);
4232 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
4233 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
4234 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
4235 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
4236
4237 gfx::Transform backface_matrix;
4238 backface_matrix.Translate(50.0, 50.0);
4239 backface_matrix.RotateAboutYAxis(180.0);
4240 backface_matrix.Translate(-50.0, -50.0);
4241
4242 // Having a descendant and opacity will force these to have render surfaces.
4243 front_facing_surface->SetOpacity(0.5f);
4244 back_facing_surface->SetOpacity(0.5f);
4245
4246 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
4247 // these layers should blindly use their own local transforms to determine
4248 // back-face culling.
4249 SetLayerPropertiesForTesting(parent.get(),
4250 identity_matrix,
[email protected]a2566412014-06-05 03:14:204251 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324252 gfx::PointF(),
4253 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574254 true,
[email protected]fb661802013-03-25 01:59:324255 false);
4256 SetLayerPropertiesForTesting(front_facing_child.get(),
4257 identity_matrix,
[email protected]a2566412014-06-05 03:14:204258 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324259 gfx::PointF(),
4260 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574261 true,
[email protected]fb661802013-03-25 01:59:324262 false);
4263 SetLayerPropertiesForTesting(back_facing_child.get(),
4264 backface_matrix,
[email protected]a2566412014-06-05 03:14:204265 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324266 gfx::PointF(),
4267 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574268 true,
[email protected]fb661802013-03-25 01:59:324269 false);
4270 SetLayerPropertiesForTesting(front_facing_surface.get(),
4271 identity_matrix,
[email protected]a2566412014-06-05 03:14:204272 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324273 gfx::PointF(),
4274 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574275 true,
[email protected]fb661802013-03-25 01:59:324276 false);
4277 SetLayerPropertiesForTesting(back_facing_surface.get(),
4278 backface_matrix,
[email protected]a2566412014-06-05 03:14:204279 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324280 gfx::PointF(),
4281 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574282 true,
[email protected]fb661802013-03-25 01:59:324283 false);
4284 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
4285 identity_matrix,
[email protected]a2566412014-06-05 03:14:204286 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324287 gfx::PointF(),
4288 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574289 true,
[email protected]fb661802013-03-25 01:59:324290 false);
4291 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
4292 backface_matrix,
[email protected]a2566412014-06-05 03:14:204293 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324294 gfx::PointF(),
4295 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574296 true,
[email protected]fb661802013-03-25 01:59:324297 false);
4298 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
4299 identity_matrix,
[email protected]a2566412014-06-05 03:14:204300 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324301 gfx::PointF(),
4302 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574303 true,
[email protected]fb661802013-03-25 01:59:324304 false);
4305 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
4306 backface_matrix,
[email protected]a2566412014-06-05 03:14:204307 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324308 gfx::PointF(),
4309 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574310 true,
[email protected]fb661802013-03-25 01:59:324311 false);
4312
enne7b2a2172015-07-14 00:04:534313 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
[email protected]fb661802013-03-25 01:59:324314
4315 // Verify which render surfaces were created.
ennec1332992015-08-24 19:45:094316 EXPECT_FALSE(front_facing_child->has_render_surface());
4317 EXPECT_FALSE(back_facing_child->has_render_surface());
4318 EXPECT_TRUE(front_facing_surface->has_render_surface());
4319 EXPECT_TRUE(back_facing_surface->has_render_surface());
4320 EXPECT_FALSE(
4321 front_facing_child_of_front_facing_surface->has_render_surface());
4322 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4323 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4324 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324325
enne7b2a2172015-07-14 00:04:534326 EXPECT_EQ(4u, update_layer_list().size());
4327 EXPECT_TRUE(UpdateLayerListContains(front_facing_child->id()));
4328 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
4329 EXPECT_TRUE(UpdateLayerListContains(
4330 front_facing_child_of_front_facing_surface->id()));
4331 EXPECT_TRUE(
4332 UpdateLayerListContains(front_facing_child_of_back_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324333}
4334
[email protected]989386c2013-07-18 21:37:234335TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:324336 // Verify the behavior of back-face culling when preserves-3d transform style
4337 // is used.
4338
4339 const gfx::Transform identity_matrix;
weiliangcc154ce22015-12-09 03:39:264340 LayerImpl* parent = root_layer();
4341 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4342 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4343 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4344 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4345 LayerImpl* front_facing_child_of_front_facing_surface =
4346 AddChild<LayerImpl>(front_facing_surface);
4347 LayerImpl* back_facing_child_of_front_facing_surface =
4348 AddChild<LayerImpl>(front_facing_surface);
4349 LayerImpl* front_facing_child_of_back_facing_surface =
4350 AddChild<LayerImpl>(back_facing_surface);
4351 LayerImpl* back_facing_child_of_back_facing_surface =
4352 AddChild<LayerImpl>(back_facing_surface);
4353 // Opacity will not force creation of render surfaces in this case because of
4354 // the preserve-3d transform style. Instead, an example of when a surface
4355 // would be created with preserve-3d is when there is a replica layer.
4356 LayerImpl* dummy_replica_layer1 =
4357 AddReplicaLayer<LayerImpl>(front_facing_surface);
4358 LayerImpl* dummy_replica_layer2 =
4359 AddReplicaLayer<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284360
[email protected]fb661802013-03-25 01:59:324361 // Nothing is double-sided
4362 front_facing_child->SetDoubleSided(false);
4363 back_facing_child->SetDoubleSided(false);
4364 front_facing_surface->SetDoubleSided(false);
4365 back_facing_surface->SetDoubleSided(false);
4366 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
4367 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
4368 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
4369 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
4370
weiliangcc154ce22015-12-09 03:39:264371 // Everything draws content.
4372 front_facing_child->SetDrawsContent(true);
4373 back_facing_child->SetDrawsContent(true);
4374 front_facing_surface->SetDrawsContent(true);
4375 back_facing_surface->SetDrawsContent(true);
4376 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4377 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4378 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4379 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
4380 dummy_replica_layer1->SetDrawsContent(true);
4381 dummy_replica_layer2->SetDrawsContent(true);
4382
[email protected]fb661802013-03-25 01:59:324383 gfx::Transform backface_matrix;
4384 backface_matrix.Translate(50.0, 50.0);
4385 backface_matrix.RotateAboutYAxis(180.0);
4386 backface_matrix.Translate(-50.0, -50.0);
4387
[email protected]fb661802013-03-25 01:59:324388 // Each surface creates its own new 3d rendering context (as defined by W3C
4389 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
4390 // rendering context should use the transform with respect to that context.
4391 // This 3d rendering context occurs when (a) parent's transform style is flat
4392 // and (b) the layer's transform style is preserve-3d.
weiliangcc154ce22015-12-09 03:39:264393 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
weiliangc4374c2cc2015-12-07 19:26:014394 gfx::PointF(), gfx::Size(100, 100), true,
[email protected]fb661802013-03-25 01:59:324395 false); // parent transform style is flat.
weiliangcc154ce22015-12-09 03:39:264396 SetLayerPropertiesForTesting(front_facing_child, identity_matrix,
weiliangc4374c2cc2015-12-07 19:26:014397 gfx::Point3F(), gfx::PointF(),
4398 gfx::Size(100, 100), true, false);
weiliangcc154ce22015-12-09 03:39:264399 SetLayerPropertiesForTesting(back_facing_child, backface_matrix,
weiliangc4374c2cc2015-12-07 19:26:014400 gfx::Point3F(), gfx::PointF(),
4401 gfx::Size(100, 100), true, false);
[email protected]56fffdd2014-02-11 19:50:574402 // surface transform style is preserve-3d.
weiliangcc154ce22015-12-09 03:39:264403 SetLayerPropertiesForTesting(front_facing_surface, identity_matrix,
weiliangc4374c2cc2015-12-07 19:26:014404 gfx::Point3F(), gfx::PointF(),
4405 gfx::Size(100, 100), false, true);
[email protected]56fffdd2014-02-11 19:50:574406 // surface transform style is preserve-3d.
weiliangcc154ce22015-12-09 03:39:264407 SetLayerPropertiesForTesting(back_facing_surface, backface_matrix,
weiliangc4374c2cc2015-12-07 19:26:014408 gfx::Point3F(), gfx::PointF(),
4409 gfx::Size(100, 100), false, true);
weiliangcc154ce22015-12-09 03:39:264410 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014411 identity_matrix, gfx::Point3F(), gfx::PointF(),
4412 gfx::Size(100, 100), true, true);
weiliangcc154ce22015-12-09 03:39:264413 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014414 backface_matrix, gfx::Point3F(), gfx::PointF(),
4415 gfx::Size(100, 100), true, true);
weiliangcc154ce22015-12-09 03:39:264416 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014417 identity_matrix, gfx::Point3F(), gfx::PointF(),
4418 gfx::Size(100, 100), true, true);
weiliangcc154ce22015-12-09 03:39:264419 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014420 backface_matrix, gfx::Point3F(), gfx::PointF(),
4421 gfx::Size(100, 100), true, true);
[email protected]fb661802013-03-25 01:59:324422
weiliangcc154ce22015-12-09 03:39:264423 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:324424
awoloszyne83f28c2014-12-22 15:40:004425 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094426 EXPECT_FALSE(front_facing_child->has_render_surface());
4427 EXPECT_FALSE(back_facing_child->has_render_surface());
4428 EXPECT_TRUE(front_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094429 // We expect that a has_render_surface was created but not used.
4430 EXPECT_TRUE(back_facing_surface->has_render_surface());
4431 EXPECT_FALSE(
4432 front_facing_child_of_front_facing_surface->has_render_surface());
4433 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4434 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4435 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324436
weiliangcc154ce22015-12-09 03:39:264437 EXPECT_EQ(3u, update_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:324438
weiliangcc154ce22015-12-09 03:39:264439 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4440 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4441 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534442 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324443}
4444
[email protected]989386c2013-07-18 21:37:234445TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:324446 // Verify that layers are appropriately culled when their back face is showing
4447 // and they are not double sided, while animations are going on.
4448 //
4449 // Layers that are animating do not get culled on the main thread, as their
4450 // transforms should be treated as "unknown" so we can not be sure that their
4451 // back face is really showing.
4452 const gfx::Transform identity_matrix;
loyso0940d412016-03-14 01:30:314453 scoped_refptr<Layer> parent = Layer::Create();
[email protected]fb661802013-03-25 01:59:324454 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:314455 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324456 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
loyso0940d412016-03-14 01:30:314457 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324458 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
loyso0940d412016-03-14 01:30:314459 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324460 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
loyso0940d412016-03-14 01:30:314461 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324462 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loyso0940d412016-03-14 01:30:314463 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324464
4465 parent->AddChild(child);
4466 parent->AddChild(animating_surface);
4467 animating_surface->AddChild(child_of_animating_surface);
4468 parent->AddChild(animating_child);
4469 parent->AddChild(child2);
4470
ennea7b43c32015-06-18 20:01:334471 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:284472
[email protected]fb661802013-03-25 01:59:324473 // Nothing is double-sided
4474 child->SetDoubleSided(false);
4475 child2->SetDoubleSided(false);
4476 animating_surface->SetDoubleSided(false);
4477 child_of_animating_surface->SetDoubleSided(false);
4478 animating_child->SetDoubleSided(false);
4479
4480 gfx::Transform backface_matrix;
4481 backface_matrix.Translate(50.0, 50.0);
4482 backface_matrix.RotateAboutYAxis(180.0);
4483 backface_matrix.Translate(-50.0, -50.0);
4484
4485 // Make our render surface.
4486 animating_surface->SetForceRenderSurface(true);
4487
loyso9556c732016-03-11 07:54:584488 // Animate the transform on the render surface.
4489 AddAnimatedTransformToLayerWithPlayer(animating_surface->id(), timeline(),
4490 10.0, 30, 0);
4491 // This is just an animating layer, not a surface.
4492 AddAnimatedTransformToLayerWithPlayer(animating_child->id(), timeline(), 10.0,
4493 30, 0);
[email protected]fb661802013-03-25 01:59:324494
4495 SetLayerPropertiesForTesting(parent.get(),
4496 identity_matrix,
[email protected]a2566412014-06-05 03:14:204497 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324498 gfx::PointF(),
4499 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574500 true,
[email protected]fb661802013-03-25 01:59:324501 false);
4502 SetLayerPropertiesForTesting(child.get(),
4503 backface_matrix,
[email protected]a2566412014-06-05 03:14:204504 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324505 gfx::PointF(),
4506 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574507 true,
[email protected]fb661802013-03-25 01:59:324508 false);
4509 SetLayerPropertiesForTesting(animating_surface.get(),
4510 backface_matrix,
[email protected]a2566412014-06-05 03:14:204511 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324512 gfx::PointF(),
4513 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574514 true,
[email protected]fb661802013-03-25 01:59:324515 false);
4516 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
4517 backface_matrix,
[email protected]a2566412014-06-05 03:14:204518 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324519 gfx::PointF(),
4520 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574521 true,
[email protected]fb661802013-03-25 01:59:324522 false);
4523 SetLayerPropertiesForTesting(animating_child.get(),
4524 backface_matrix,
[email protected]a2566412014-06-05 03:14:204525 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324526 gfx::PointF(),
4527 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574528 true,
[email protected]fb661802013-03-25 01:59:324529 false);
4530 SetLayerPropertiesForTesting(child2.get(),
4531 identity_matrix,
[email protected]a2566412014-06-05 03:14:204532 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324533 gfx::PointF(),
4534 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574535 true,
[email protected]fb661802013-03-25 01:59:324536 false);
4537
jaydasika6b7c69d2016-04-01 00:54:434538 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4539 parent.get(), parent->bounds());
4540 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]fb661802013-03-25 01:59:324541
ennec1332992015-08-24 19:45:094542 EXPECT_FALSE(child->has_render_surface());
4543 EXPECT_TRUE(animating_surface->has_render_surface());
4544 EXPECT_FALSE(child_of_animating_surface->has_render_surface());
4545 EXPECT_FALSE(animating_child->has_render_surface());
4546 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324547
enne7b2a2172015-07-14 00:04:534548 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
4549
4550 EXPECT_EQ(4u, update_layer_list().size());
[email protected]fb661802013-03-25 01:59:324551
4552 // The non-animating child be culled from the layer list for the parent render
4553 // surface.
enne7b2a2172015-07-14 00:04:534554 EXPECT_TRUE(UpdateLayerListContains(animating_surface->id()));
4555 EXPECT_TRUE(UpdateLayerListContains(animating_child->id()));
4556 EXPECT_TRUE(UpdateLayerListContains(child2->id()));
4557 EXPECT_TRUE(UpdateLayerListContains(child_of_animating_surface->id()));
[email protected]fb661802013-03-25 01:59:324558
jaydasika74bf516f2016-04-01 19:48:154559 EXPECT_FALSE(child2->visible_layer_rect_for_testing().IsEmpty());
[email protected]fb661802013-03-25 01:59:324560
4561 // The animating layers should have a visible content rect that represents the
4562 // area of the front face that is within the viewport.
jaydasika74bf516f2016-04-01 19:48:154563 EXPECT_EQ(animating_child->visible_layer_rect_for_testing(),
Dana Jansensc46d3742015-06-18 01:33:144564 gfx::Rect(animating_child->bounds()));
jaydasika74bf516f2016-04-01 19:48:154565 EXPECT_EQ(animating_surface->visible_layer_rect_for_testing(),
Dana Jansensc46d3742015-06-18 01:33:144566 gfx::Rect(animating_surface->bounds()));
[email protected]fb661802013-03-25 01:59:324567 // And layers in the subtree of the animating layer should have valid visible
4568 // content rects also.
jaydasika74bf516f2016-04-01 19:48:154569 EXPECT_EQ(child_of_animating_surface->visible_layer_rect_for_testing(),
Dana Jansensc46d3742015-06-18 01:33:144570 gfx::Rect(child_of_animating_surface->bounds()));
[email protected]fb661802013-03-25 01:59:324571}
4572
[email protected]989386c2013-07-18 21:37:234573TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324574 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4575 // Verify the behavior of back-face culling for a render surface that is
4576 // created when it flattens its subtree, and its parent has preserves-3d.
4577
4578 const gfx::Transform identity_matrix;
loyso0940d412016-03-14 01:30:314579 scoped_refptr<Layer> parent = Layer::Create();
[email protected]fb661802013-03-25 01:59:324580 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
loyso0940d412016-03-14 01:30:314581 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324582 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
loyso0940d412016-03-14 01:30:314583 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324584 scoped_refptr<LayerWithForcedDrawsContent> child1 =
loyso0940d412016-03-14 01:30:314585 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324586 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loyso0940d412016-03-14 01:30:314587 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:324588
4589 parent->AddChild(front_facing_surface);
4590 parent->AddChild(back_facing_surface);
4591 front_facing_surface->AddChild(child1);
4592 back_facing_surface->AddChild(child2);
4593
ennea7b43c32015-06-18 20:01:334594 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:284595
[email protected]fb661802013-03-25 01:59:324596 // RenderSurfaces are not double-sided
4597 front_facing_surface->SetDoubleSided(false);
4598 back_facing_surface->SetDoubleSided(false);
4599
4600 gfx::Transform backface_matrix;
4601 backface_matrix.Translate(50.0, 50.0);
4602 backface_matrix.RotateAboutYAxis(180.0);
4603 backface_matrix.Translate(-50.0, -50.0);
4604
4605 SetLayerPropertiesForTesting(parent.get(),
4606 identity_matrix,
[email protected]a2566412014-06-05 03:14:204607 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324608 gfx::PointF(),
4609 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574610 false,
4611 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:324612 SetLayerPropertiesForTesting(front_facing_surface.get(),
4613 identity_matrix,
[email protected]a2566412014-06-05 03:14:204614 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324615 gfx::PointF(),
4616 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574617 true,
4618 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324619 SetLayerPropertiesForTesting(back_facing_surface.get(),
4620 backface_matrix,
[email protected]a2566412014-06-05 03:14:204621 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324622 gfx::PointF(),
4623 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574624 true,
4625 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324626 SetLayerPropertiesForTesting(child1.get(),
4627 identity_matrix,
[email protected]a2566412014-06-05 03:14:204628 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324629 gfx::PointF(),
4630 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574631 true,
[email protected]fb661802013-03-25 01:59:324632 false);
4633 SetLayerPropertiesForTesting(child2.get(),
4634 identity_matrix,
[email protected]a2566412014-06-05 03:14:204635 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324636 gfx::PointF(),
4637 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574638 true,
[email protected]fb661802013-03-25 01:59:324639 false);
4640
[email protected]a9d4d4f2014-06-19 06:49:284641 front_facing_surface->Set3dSortingContextId(1);
4642 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574643
enne7b2a2172015-07-14 00:04:534644 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
[email protected]fb661802013-03-25 01:59:324645
awoloszyne83f28c2014-12-22 15:40:004646 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094647 EXPECT_TRUE(front_facing_surface->has_render_surface());
awoloszyne83f28c2014-12-22 15:40:004648
4649 // We expect the render surface to have been created, but remain unused.
ennec1332992015-08-24 19:45:094650 EXPECT_TRUE(back_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094651 EXPECT_FALSE(child1->has_render_surface());
4652 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324653
enne7b2a2172015-07-14 00:04:534654 EXPECT_EQ(2u, update_layer_list().size());
4655 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
4656 EXPECT_TRUE(UpdateLayerListContains(child1->id()));
[email protected]fb661802013-03-25 01:59:324657}
4658
enne637715732015-07-07 02:05:264659TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324660 // Verify draw and screen space transforms of layers not in a surface.
[email protected]fb661802013-03-25 01:59:324661 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:144662
enne637715732015-07-07 02:05:264663 LayerImpl* parent = root_layer();
jaydasika8640f9f2015-11-10 01:34:364664 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264665 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4666 gfx::PointF(), gfx::Size(100, 100), false, true,
[email protected]fb661802013-03-25 01:59:324667 true);
[email protected]94f206c12012-08-25 00:09:144668
enne637715732015-07-07 02:05:264669 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364670 child->SetDrawsContent(true);
enne637715732015-07-07 02:05:264671 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4672 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4673 true, false);
[email protected]94f206c12012-08-25 00:09:144674
jaydasika8640f9f2015-11-10 01:34:364675 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
4676 child2->SetDrawsContent(true);
4677 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4678 gfx::PointF(2.f, 2.f), gfx::Size(5, 5), false,
4679 true, false);
[email protected]d600df7d2013-08-03 02:34:284680
[email protected]fb661802013-03-25 01:59:324681 float device_scale_factor = 2.5f;
enne637715732015-07-07 02:05:264682 gfx::Size viewport_size(100, 100);
4683 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144684
enne637715732015-07-07 02:05:264685 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent);
4686 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child);
jaydasika8640f9f2015-11-10 01:34:364687 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child2);
[email protected]518ee582012-10-24 18:29:444688
enne637715732015-07-07 02:05:264689 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144690
[email protected]fb661802013-03-25 01:59:324691 // Verify parent transforms
4692 gfx::Transform expected_parent_transform;
enne637715732015-07-07 02:05:264693 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324694 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104695 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324696 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444697 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144698
[email protected]fb661802013-03-25 01:59:324699 // Verify results of transformed parent rects
danakjddaec912015-09-25 19:38:404700 gfx::RectF parent_bounds(gfx::SizeF(parent->bounds()));
[email protected]94f206c12012-08-25 00:09:144701
[email protected]fb661802013-03-25 01:59:324702 gfx::RectF parent_draw_rect =
ajumad9432e32015-11-30 19:43:444703 MathUtil::MapClippedRect(parent->DrawTransform(), parent_bounds);
Dana Jansensc46d3742015-06-18 01:33:144704 gfx::RectF parent_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104705 MathUtil::MapClippedRect(parent->ScreenSpaceTransform(), parent_bounds);
[email protected]94f206c12012-08-25 00:09:144706
danakjddaec912015-09-25 19:38:404707 gfx::RectF expected_parent_draw_rect(gfx::SizeF(parent->bounds()));
[email protected]fb661802013-03-25 01:59:324708 expected_parent_draw_rect.Scale(device_scale_factor);
4709 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4710 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144711
jaydasika8640f9f2015-11-10 01:34:364712 // Verify child and child2 transforms. They should match.
[email protected]fb661802013-03-25 01:59:324713 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594714 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4715 expected_child_transform.Translate(child->position().x(),
4716 child->position().y());
[email protected]fb661802013-03-25 01:59:324717 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444718 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:324719 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104720 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324721 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444722 child2->DrawTransform());
[email protected]fb661802013-03-25 01:59:324723 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104724 child2->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144725
jaydasika8640f9f2015-11-10 01:34:364726 // Verify results of transformed child and child2 rects. They should
[email protected]fb661802013-03-25 01:59:324727 // match.
danakjddaec912015-09-25 19:38:404728 gfx::RectF child_bounds(gfx::SizeF(child->bounds()));
[email protected]94f206c12012-08-25 00:09:144729
[email protected]fb661802013-03-25 01:59:324730 gfx::RectF child_draw_rect =
ajumad9432e32015-11-30 19:43:444731 MathUtil::MapClippedRect(child->DrawTransform(), child_bounds);
Dana Jansensc46d3742015-06-18 01:33:144732 gfx::RectF child_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104733 MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds);
[email protected]94f206c12012-08-25 00:09:144734
jaydasika8640f9f2015-11-10 01:34:364735 gfx::RectF child2_draw_rect =
ajumad9432e32015-11-30 19:43:444736 MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds);
jaydasika8640f9f2015-11-10 01:34:364737 gfx::RectF child2_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104738 MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds);
[email protected]f89f5632012-11-14 23:34:454739
danakjddaec912015-09-25 19:38:404740 gfx::RectF expected_child_draw_rect(child->position(),
4741 gfx::SizeF(child->bounds()));
[email protected]fb661802013-03-25 01:59:324742 expected_child_draw_rect.Scale(device_scale_factor);
4743 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4744 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
jaydasika8640f9f2015-11-10 01:34:364745 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect);
4746 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144747}
4748
enne637715732015-07-07 02:05:264749TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324750 // Verify draw and screen space transforms of layers in a surface.
[email protected]fb661802013-03-25 01:59:324751 gfx::Transform identity_matrix;
[email protected]fb661802013-03-25 01:59:324752 gfx::Transform perspective_matrix;
4753 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094754
[email protected]fb661802013-03-25 01:59:324755 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054756 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094757
enne637715732015-07-07 02:05:264758 LayerImpl* root = root_layer();
4759 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4760 gfx::PointF(), gfx::Size(100, 100), false, true,
4761 false);
4762 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364763 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264764 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4765 gfx::PointF(), gfx::Size(100, 100), false, true,
4766 false);
[email protected]9781afa2013-07-17 23:15:324767
enne637715732015-07-07 02:05:264768 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
4769 SetLayerPropertiesForTesting(perspective_surface,
[email protected]fb661802013-03-25 01:59:324770 perspective_matrix * scale_small_matrix,
enne637715732015-07-07 02:05:264771 gfx::Point3F(), gfx::PointF(2.f, 2.f),
4772 gfx::Size(10, 10), false, true, true);
4773 perspective_surface->SetDrawsContent(true);
[email protected]1b30e8e2012-12-21 02:59:094774
enne637715732015-07-07 02:05:264775 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
4776 SetLayerPropertiesForTesting(scale_surface, scale_small_matrix,
4777 gfx::Point3F(), gfx::PointF(2.f, 2.f),
4778 gfx::Size(10, 10), false, true, true);
4779 scale_surface->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284780
[email protected]fb661802013-03-25 01:59:324781 float device_scale_factor = 2.5f;
4782 float page_scale_factor = 3.f;
enne637715732015-07-07 02:05:264783 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4784 root);
[email protected]1b30e8e2012-12-21 02:59:094785
sohan.jyotie3bd6192014-10-13 07:13:594786 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4787 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
4788 perspective_surface);
4789 // Ideal scale is the max 2d scale component of the combined transform up to
4790 // the nearest render target. Here this includes the layer transform as well
4791 // as the device and page scale factors.
4792 gfx::Transform transform = scale_small_matrix;
4793 transform.Scale(device_scale_factor * page_scale_factor,
4794 device_scale_factor * page_scale_factor);
4795 gfx::Vector2dF scales =
4796 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4797 float max_2d_scale = std::max(scales.x(), scales.y());
4798 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
4799
4800 // The ideal scale will draw 1:1 with its render target space along
4801 // the larger-scale axis.
4802 gfx::Vector2dF target_space_transform_scales =
4803 MathUtil::ComputeTransform2dScaleComponents(
4804 scale_surface->draw_properties().target_space_transform, 0.f);
4805 EXPECT_FLOAT_EQ(max_2d_scale,
4806 std::max(target_space_transform_scales.x(),
4807 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094808
enne637715732015-07-07 02:05:264809 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]1b30e8e2012-12-21 02:59:094810
[email protected]fb661802013-03-25 01:59:324811 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594812 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4813 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324814 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
ajumad9432e32015-11-30 19:43:444815 parent->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094816
[email protected]fb661802013-03-25 01:59:324817 // The scale for the perspective surface is not known, so it is rendered 1:1
4818 // with the screen, and then scaled during drawing.
4819 gfx::Transform expected_perspective_surface_draw_transform;
4820 expected_perspective_surface_draw_transform.Translate(
4821 device_scale_factor * page_scale_factor *
4822 perspective_surface->position().x(),
4823 device_scale_factor * page_scale_factor *
4824 perspective_surface->position().y());
4825 expected_perspective_surface_draw_transform.PreconcatTransform(
4826 perspective_matrix);
4827 expected_perspective_surface_draw_transform.PreconcatTransform(
4828 scale_small_matrix);
4829 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594830 expected_perspective_surface_layer_draw_transform.Scale(
4831 device_scale_factor * page_scale_factor,
4832 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324833 EXPECT_TRANSFORMATION_MATRIX_EQ(
4834 expected_perspective_surface_draw_transform,
4835 perspective_surface->render_surface()->draw_transform());
4836 EXPECT_TRANSFORMATION_MATRIX_EQ(
4837 expected_perspective_surface_layer_draw_transform,
ajumad9432e32015-11-30 19:43:444838 perspective_surface->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094839}
4840
enne637715732015-07-07 02:05:264841TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294842 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264843 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294844 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4845
4846 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264847 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294848 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4849
enne637715732015-07-07 02:05:264850 LayerImpl* root = root_layer();
[email protected]35a99a12013-05-09 23:52:294851 root->SetBounds(gfx::Size(100, 100));
4852
enne637715732015-07-07 02:05:264853 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364854 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264855 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4856 gfx::PointF(), gfx::Size(100, 100), false, true,
4857 false);
[email protected]35a99a12013-05-09 23:52:294858
enne637715732015-07-07 02:05:264859 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:364860 child_scale->SetDrawsContent(true);
enne637715732015-07-07 02:05:264861 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4862 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4863 true, false);
[email protected]d600df7d2013-08-03 02:34:284864
[email protected]fb661802013-03-25 01:59:324865 float device_scale_factor = 2.5f;
4866 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214867
[email protected]989386c2013-07-18 21:37:234868 {
enne637715732015-07-07 02:05:264869 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4870 root);
[email protected]11ec92972012-11-10 03:06:214871
sohan.jyotie3bd6192014-10-13 07:13:594872 // The ideal scale is able to go below 1.
4873 float expected_ideal_scale =
4874 device_scale_factor * page_scale_factor * initial_parent_scale;
4875 EXPECT_LT(expected_ideal_scale, 1.f);
4876 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
[email protected]11ec92972012-11-10 03:06:214877
sohan.jyotie3bd6192014-10-13 07:13:594878 expected_ideal_scale = device_scale_factor * page_scale_factor *
4879 initial_parent_scale * initial_child_scale;
4880 EXPECT_LT(expected_ideal_scale, 1.f);
4881 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
[email protected]989386c2013-07-18 21:37:234882 }
[email protected]11ec92972012-11-10 03:06:214883}
4884
enne637715732015-07-07 02:05:264885TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:324886 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264887 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324888 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:264889
[email protected]fb661802013-03-25 01:59:324890 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264891 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324892 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:264893
enne637715732015-07-07 02:05:264894 LayerImpl* root = root_layer();
[email protected]35a99a12013-05-09 23:52:294895 root->SetBounds(gfx::Size(100, 100));
4896
enne637715732015-07-07 02:05:264897 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364898 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264899 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4900 gfx::PointF(), gfx::Size(100, 100), false, true,
4901 false);
[email protected]6a9cff92012-11-08 11:53:264902
enne637715732015-07-07 02:05:264903 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:364904 child_scale->SetDrawsContent(true);
enne637715732015-07-07 02:05:264905 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4906 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4907 true, false);
[email protected]d600df7d2013-08-03 02:34:284908
[email protected]989386c2013-07-18 21:37:234909 {
enne637715732015-07-07 02:05:264910 ExecuteCalculateDrawProperties(root);
[email protected]6a9cff92012-11-08 11:53:264911
sohan.jyotie3bd6192014-10-13 07:13:594912 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
4913 // Animating layers compute ideal scale in the same way as when
4914 // they are static.
4915 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
4916 child_scale);
[email protected]989386c2013-07-18 21:37:234917 }
[email protected]6a9cff92012-11-08 11:53:264918}
4919
[email protected]989386c2013-07-18 21:37:234920TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324921 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:264922
enneea850232015-07-27 16:43:124923 LayerImpl* parent = root_layer();
4924 parent->SetDrawsContent(true);
4925 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4926 gfx::PointF(), gfx::Size(30, 30), false, true,
[email protected]fb661802013-03-25 01:59:324927 true);
[email protected]94f206c12012-08-25 00:09:144928
enneea850232015-07-27 16:43:124929 LayerImpl* child = AddChildToRoot<LayerImpl>();
4930 child->SetDrawsContent(true);
4931 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4932 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4933 true, true);
[email protected]94f206c12012-08-25 00:09:144934
[email protected]fb661802013-03-25 01:59:324935 gfx::Transform replica_transform;
4936 replica_transform.Scale(1.0, -1.0);
enneea850232015-07-27 16:43:124937
4938 scoped_ptr<LayerImpl> replica =
4939 LayerImpl::Create(host_impl()->active_tree(), 7);
4940 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
4941 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4942 true, false);
jaydasika5017a332016-03-31 01:06:224943 // We need to set parent on replica layer for property tree building.
4944 replica->SetParent(child);
danakja04855a2015-11-18 20:39:104945 child->SetReplicaLayer(std::move(replica));
[email protected]94f206c12012-08-25 00:09:144946
[email protected]fb661802013-03-25 01:59:324947 // This layer should end up in the same surface as child, with the same draw
4948 // and screen space transforms.
enneea850232015-07-27 16:43:124949 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
4950 duplicate_child_non_owner->SetDrawsContent(true);
4951 SetLayerPropertiesForTesting(duplicate_child_non_owner, identity_matrix,
4952 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4953 false, true, false);
[email protected]94f206c12012-08-25 00:09:144954
[email protected]fb661802013-03-25 01:59:324955 float device_scale_factor = 1.5f;
enneea850232015-07-27 16:43:124956 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144957
[email protected]fb661802013-03-25 01:59:324958 // We should have two render surfaces. The root's render surface and child's
4959 // render surface (it needs one because it has a replica layer).
enneea850232015-07-27 16:43:124960 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144961
[email protected]fb661802013-03-25 01:59:324962 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594963 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324964 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104965 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324966 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444967 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144968
[email protected]fb661802013-03-25 01:59:324969 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594970 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324971 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
ajumad9432e32015-11-30 19:43:444972 child->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144973
[email protected]fb661802013-03-25 01:59:324974 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:594975 expected_screen_space_transform.Scale(device_scale_factor,
4976 device_scale_factor);
4977 expected_screen_space_transform.Translate(child->position().x(),
4978 child->position().y());
[email protected]fb661802013-03-25 01:59:324979 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:104980 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144981
[email protected]fb661802013-03-25 01:59:324982 gfx::Transform expected_duplicate_child_draw_transform =
ajumad9432e32015-11-30 19:43:444983 child->DrawTransform();
4984 EXPECT_TRANSFORMATION_MATRIX_EQ(child->DrawTransform(),
4985 duplicate_child_non_owner->DrawTransform());
[email protected]fb661802013-03-25 01:59:324986 EXPECT_TRANSFORMATION_MATRIX_EQ(
ajumab6aa1c62015-12-01 21:01:104987 child->ScreenSpaceTransform(),
4988 duplicate_child_non_owner->ScreenSpaceTransform());
hush6b614212014-12-04 22:37:324989 EXPECT_EQ(child->drawable_content_rect(),
4990 duplicate_child_non_owner->drawable_content_rect());
Dana Jansensc46d3742015-06-18 01:33:144991 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
[email protected]94f206c12012-08-25 00:09:144992
[email protected]fb661802013-03-25 01:59:324993 gfx::Transform expected_render_surface_draw_transform;
4994 expected_render_surface_draw_transform.Translate(
4995 device_scale_factor * child->position().x(),
4996 device_scale_factor * child->position().y());
4997 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
4998 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144999
[email protected]fb661802013-03-25 01:59:325000 gfx::Transform expected_surface_draw_transform;
5001 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
5002 device_scale_factor * 2.f);
5003 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
5004 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145005
[email protected]fb661802013-03-25 01:59:325006 gfx::Transform expected_surface_screen_space_transform;
5007 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
5008 device_scale_factor * 2.f);
5009 EXPECT_TRANSFORMATION_MATRIX_EQ(
5010 expected_surface_screen_space_transform,
5011 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145012
[email protected]fb661802013-03-25 01:59:325013 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265014 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
5015 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
5016 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325017 EXPECT_TRANSFORMATION_MATRIX_EQ(
5018 expected_replica_draw_transform,
5019 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:145020
[email protected]fb661802013-03-25 01:59:325021 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265022 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
5023 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
5024 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325025 EXPECT_TRANSFORMATION_MATRIX_EQ(
5026 expected_replica_screen_space_transform,
5027 child->render_surface()->replica_screen_space_transform());
5028 EXPECT_TRANSFORMATION_MATRIX_EQ(
5029 expected_replica_screen_space_transform,
5030 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:475031}
5032
[email protected]989386c2013-07-18 21:37:235033TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325034 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
[email protected]fb661802013-03-25 01:59:325035 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:475036
enneea850232015-07-27 16:43:125037 LayerImpl* parent = root_layer();
5038 parent->SetDrawsContent(true);
5039 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
5040 gfx::PointF(), gfx::Size(33, 31), false, true,
[email protected]fb661802013-03-25 01:59:325041 true);
[email protected]904e9132012-11-01 00:12:475042
enneea850232015-07-27 16:43:125043 LayerImpl* child = AddChildToRoot<LayerImpl>();
5044 child->SetDrawsContent(true);
5045 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
5046 gfx::PointF(), gfx::Size(13, 11), false, true,
[email protected]fb661802013-03-25 01:59:325047 true);
[email protected]904e9132012-11-01 00:12:475048
[email protected]fb661802013-03-25 01:59:325049 gfx::Transform replica_transform;
5050 replica_transform.Scale(1.0, -1.0);
enneea850232015-07-27 16:43:125051 scoped_ptr<LayerImpl> replica =
5052 LayerImpl::Create(host_impl()->active_tree(), 7);
5053 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
5054 gfx::PointF(), gfx::Size(13, 11), false, true,
5055 false);
danakja04855a2015-11-18 20:39:105056 child->SetReplicaLayer(std::move(replica));
[email protected]d600df7d2013-08-03 02:34:285057
[email protected]873639e2013-07-24 19:56:315058 float device_scale_factor = 1.7f;
enneea850232015-07-27 16:43:125059 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]904e9132012-11-01 00:12:475060
[email protected]fb661802013-03-25 01:59:325061 // We should have two render surfaces. The root's render surface and child's
5062 // render surface (it needs one because it has a replica layer).
enneea850232015-07-27 16:43:125063 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]904e9132012-11-01 00:12:475064
[email protected]fb661802013-03-25 01:59:325065 gfx::Transform identity_transform;
[email protected]fb661802013-03-25 01:59:325066 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5067 child->render_surface()->draw_transform());
5068 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5069 child->render_surface()->draw_transform());
5070 EXPECT_TRANSFORMATION_MATRIX_EQ(
5071 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:475072
[email protected]fb661802013-03-25 01:59:325073 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265074 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325075 EXPECT_TRANSFORMATION_MATRIX_EQ(
5076 expected_replica_draw_transform,
5077 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:475078
[email protected]fb661802013-03-25 01:59:325079 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265080 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325081 EXPECT_TRANSFORMATION_MATRIX_EQ(
5082 expected_replica_screen_space_transform,
5083 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145084}
5085
jaydasikadb41a582016-03-28 20:48:215086TEST_F(LayerTreeHostCommonTest, LayerSearch) {
loyso0940d412016-03-14 01:30:315087 scoped_refptr<Layer> root = Layer::Create();
5088 scoped_refptr<Layer> child = Layer::Create();
5089 scoped_refptr<Layer> grand_child = Layer::Create();
5090 scoped_refptr<Layer> mask_layer = Layer::Create();
5091 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:145092
[email protected]fb661802013-03-25 01:59:325093 grand_child->SetReplicaLayer(replica_layer.get());
5094 child->AddChild(grand_child.get());
5095 child->SetMaskLayer(mask_layer.get());
5096 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:145097
ennea7b43c32015-06-18 20:01:335098 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:285099
[email protected]fb661802013-03-25 01:59:325100 int nonexistent_id = -1;
jaydasikadb41a582016-03-28 20:48:215101 EXPECT_EQ(root.get(), host()->LayerById(root->id()));
5102 EXPECT_EQ(child.get(), host()->LayerById(child->id()));
5103 EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id()));
5104 EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id()));
5105 EXPECT_EQ(replica_layer.get(), host()->LayerById(replica_layer->id()));
5106 EXPECT_FALSE(host()->LayerById(nonexistent_id));
[email protected]94f206c12012-08-25 00:09:145107}
5108
[email protected]989386c2013-07-18 21:37:235109TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
loyso0940d412016-03-14 01:30:315110 scoped_refptr<Layer> root = Layer::Create();
5111 scoped_refptr<Layer> child = Layer::Create();
[email protected]fb661802013-03-25 01:59:325112 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loyso0940d412016-03-14 01:30:315113 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:575114
[email protected]fb661802013-03-25 01:59:325115 const gfx::Transform identity_matrix;
5116 SetLayerPropertiesForTesting(root.get(),
5117 identity_matrix,
[email protected]a2566412014-06-05 03:14:205118 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325119 gfx::PointF(),
5120 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575121 true,
[email protected]fb661802013-03-25 01:59:325122 false);
5123 SetLayerPropertiesForTesting(child.get(),
5124 identity_matrix,
[email protected]a2566412014-06-05 03:14:205125 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325126 gfx::PointF(),
5127 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575128 true,
[email protected]fb661802013-03-25 01:59:325129 false);
5130 SetLayerPropertiesForTesting(grand_child.get(),
5131 identity_matrix,
[email protected]a2566412014-06-05 03:14:205132 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325133 gfx::PointF(),
5134 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575135 true,
[email protected]fb661802013-03-25 01:59:325136 false);
[email protected]498ec6e0e2012-11-30 18:24:575137
[email protected]fb661802013-03-25 01:59:325138 root->AddChild(child);
5139 child->AddChild(grand_child);
5140 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:575141
ennea7b43c32015-06-18 20:01:335142 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:285143
[email protected]fb661802013-03-25 01:59:325144 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:575145
ennec1332992015-08-24 19:45:095146 EXPECT_FALSE(child->has_render_surface());
[email protected]498ec6e0e2012-11-30 18:24:575147}
5148
[email protected]989386c2013-07-18 21:37:235149TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
khushalsagarb64b360d2015-10-21 19:25:165150 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455151 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565152 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:485153 FakeLayerTreeHostImpl host_impl(host()->settings(), &task_runner_provider,
5154 &shared_bitmap_manager, &task_graph_runner);
[email protected]f90fc412013-03-30 20:13:165155 host_impl.CreatePendingTree();
5156 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5157
5158 const gfx::Transform identity_matrix;
awoloszyne83f28c2014-12-22 15:40:005159 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5160 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]f90fc412013-03-30 20:13:165161 false);
5162 root->SetDrawsContent(true);
5163
5164 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005165 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5166 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]f90fc412013-03-30 20:13:165167 false);
5168 child->SetDrawsContent(true);
5169 child->SetOpacity(0.0f);
5170
5171 // Add opacity animation.
loyso9556c732016-03-11 07:54:585172 scoped_refptr<AnimationTimeline> timeline =
5173 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
5174 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:485175
loyso9556c732016-03-11 07:54:585176 AddOpacityTransitionToLayerWithPlayer(child->id(), timeline, 10.0, 0.0f, 1.0f,
5177 false);
[email protected]f90fc412013-03-30 20:13:165178
danakja04855a2015-11-18 20:39:105179 root->AddChild(std::move(child));
awoloszyne83f28c2014-12-22 15:40:005180 root->SetHasRenderSurface(true);
jaydasika0c2fd472016-03-24 01:26:055181 LayerImpl* root_layer = root.get();
5182 host_impl.pending_tree()->SetRootLayer(std::move(root));
[email protected]f90fc412013-03-30 20:13:165183
[email protected]c0ae06c12013-06-24 18:32:195184 LayerImplList render_surface_layer_list;
jaydasika0c2fd472016-03-24 01:26:055185 root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]7aad55f2013-07-26 11:25:535186 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
jaydasika0c2fd472016-03-24 01:26:055187 root_layer, root_layer->bounds(), &render_surface_layer_list,
5188 root_layer->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535189 inputs.can_adjust_raster_scales = true;
5190 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:165191
5192 // We should have one render surface and two layers. The child
5193 // layer should be included even though it is transparent.
5194 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:055195 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
jaydasika86654512016-01-27 17:05:075196
5197 // If the root itself is hidden, the child should not be drawn even if it has
5198 // an animating opacity.
jaydasika0c2fd472016-03-24 01:26:055199 root_layer->SetOpacity(0.0f);
5200 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika86654512016-01-27 17:05:075201 LayerImplList render_surface_layer_list2;
jaydasika0c2fd472016-03-24 01:26:055202 root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
jaydasika86654512016-01-27 17:05:075203 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2(
jaydasika0c2fd472016-03-24 01:26:055204 root_layer, root_layer->bounds(), &render_surface_layer_list2,
5205 root_layer->layer_tree_impl()->current_render_surface_list_id());
jaydasika86654512016-01-27 17:05:075206 inputs2.can_adjust_raster_scales = true;
5207 LayerTreeHostCommon::CalculateDrawProperties(&inputs2);
5208
jaydasika0c2fd472016-03-24 01:26:055209 LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2);
5210 EffectTree tree =
5211 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:075212 EffectNode* node = tree.Node(child_ptr->effect_tree_index());
5213 EXPECT_FALSE(node->data.is_drawn);
jaydasikae99e83e2016-01-29 19:35:405214
5215 // A layer should be drawn and it should contribute to drawn surface when
5216 // it has animating opacity even if it has opacity 0.
jaydasika0c2fd472016-03-24 01:26:055217 root_layer->SetOpacity(1.0f);
jaydasikae99e83e2016-01-29 19:35:405218 child_ptr->SetOpacity(0.0f);
jaydasika0c2fd472016-03-24 01:26:055219 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikae99e83e2016-01-29 19:35:405220 LayerImplList render_surface_layer_list3;
jaydasika0c2fd472016-03-24 01:26:055221 root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
jaydasikae99e83e2016-01-29 19:35:405222 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3(
jaydasika0c2fd472016-03-24 01:26:055223 root_layer, root_layer->bounds(), &render_surface_layer_list3,
5224 root_layer->layer_tree_impl()->current_render_surface_list_id());
jaydasikae99e83e2016-01-29 19:35:405225 inputs3.can_adjust_raster_scales = true;
5226 LayerTreeHostCommon::CalculateDrawProperties(&inputs3);
5227
jaydasika0c2fd472016-03-24 01:26:055228 child_ptr = root_layer->layer_tree_impl()->LayerById(2);
5229 tree = root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasikae99e83e2016-01-29 19:35:405230 node = tree.Node(child_ptr->effect_tree_index());
5231 EXPECT_TRUE(node->data.is_drawn);
5232 EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index()));
[email protected]f90fc412013-03-30 20:13:165233}
5234
danakj3f76ace2014-11-18 16:56:005235using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
enne637715732015-07-07 02:05:265236class LCDTextTest : public LayerTreeHostCommonTestBase,
5237 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:365238 public:
5239 LCDTextTest()
loyso0940d412016-03-14 01:30:315240 : LayerTreeHostCommonTestBase(LayerTreeSettings()),
5241 host_impl_(&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 {
loyso9556c732016-03-11 07:54:585252 timeline_ =
5253 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
5254 host_impl_.animation_host()->AddAnimationTimeline(timeline_);
loyso968163c92016-01-04 23:18:485255
[email protected]fb661802013-03-25 01:59:325256 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
danakj3f76ace2014-11-18 16:56:005257 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
[email protected]10aabcc32012-12-13 09:18:595258
enneaf5bda32015-02-19 01:27:365259 scoped_ptr<LayerImpl> root_ptr =
5260 LayerImpl::Create(host_impl_.active_tree(), 1);
5261 scoped_ptr<LayerImpl> child_ptr =
5262 LayerImpl::Create(host_impl_.active_tree(), 2);
5263 scoped_ptr<LayerImpl> grand_child_ptr =
5264 LayerImpl::Create(host_impl_.active_tree(), 3);
5265
5266 // Stash raw pointers to look at later.
5267 root_ = root_ptr.get();
5268 child_ = child_ptr.get();
5269 grand_child_ = grand_child_ptr.get();
5270
danakja04855a2015-11-18 20:39:105271 child_->AddChild(std::move(grand_child_ptr));
5272 root_->AddChild(std::move(child_ptr));
5273 host_impl_.active_tree()->SetRootLayer(std::move(root_ptr));
[email protected]10aabcc32012-12-13 09:18:595274
fmalita51b5e202014-11-18 20:11:505275 root_->SetContentsOpaque(true);
5276 child_->SetContentsOpaque(true);
5277 grand_child_->SetContentsOpaque(true);
5278
jaydasika3f930c12015-06-30 15:18:255279 root_->SetDrawsContent(true);
5280 child_->SetDrawsContent(true);
5281 grand_child_->SetDrawsContent(true);
5282
[email protected]fb661802013-03-25 01:59:325283 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365284 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
5285 gfx::PointF(), gfx::Size(1, 1), true, false,
5286 true);
5287 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
5288 gfx::PointF(), gfx::Size(1, 1), true, false,
5289 std::tr1::get<2>(GetParam()));
5290 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
5291 gfx::PointF(), gfx::Size(1, 1), true, false,
[email protected]fb661802013-03-25 01:59:325292 false);
[email protected]fb661802013-03-25 01:59:325293 }
[email protected]10aabcc32012-12-13 09:18:595294
[email protected]fb661802013-03-25 01:59:325295 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005296 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:365297
khushalsagarb64b360d2015-10-21 19:25:165298 FakeImplTaskRunnerProvider task_runner_provider_;
enneaf5bda32015-02-19 01:27:365299 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:475300 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:365301 FakeLayerTreeHostImpl host_impl_;
loyso968163c92016-01-04 23:18:485302 scoped_refptr<AnimationTimeline> timeline_;
enneaf5bda32015-02-19 01:27:365303
5304 LayerImpl* root_;
5305 LayerImpl* child_;
5306 LayerImpl* grand_child_;
[email protected]10aabcc32012-12-13 09:18:595307};
5308
[email protected]fb661802013-03-25 01:59:325309TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005310 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5311 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5312
[email protected]fb661802013-03-25 01:59:325313 // Case 1: Identity transform.
5314 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365315 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005316 layers_always_allowed_lcd_text_);
5317 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5318 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5319 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595320
[email protected]fb661802013-03-25 01:59:325321 // Case 2: Integral translation.
5322 gfx::Transform integral_translation;
5323 integral_translation.Translate(1.0, 2.0);
5324 child_->SetTransform(integral_translation);
jaydasika3f930c12015-06-30 15:18:255325 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365326 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005327 layers_always_allowed_lcd_text_);
5328 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5329 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5330 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595331
[email protected]fb661802013-03-25 01:59:325332 // Case 3: Non-integral translation.
5333 gfx::Transform non_integral_translation;
5334 non_integral_translation.Translate(1.5, 2.5);
5335 child_->SetTransform(non_integral_translation);
jaydasika3f930c12015-06-30 15:18:255336 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365337 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005338 layers_always_allowed_lcd_text_);
5339 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5340 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5341 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595342
[email protected]fb661802013-03-25 01:59:325343 // Case 4: Rotation.
5344 gfx::Transform rotation;
5345 rotation.Rotate(10.0);
5346 child_->SetTransform(rotation);
jaydasika3f930c12015-06-30 15:18:255347 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365348 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005349 layers_always_allowed_lcd_text_);
5350 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5351 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5352 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595353
[email protected]fb661802013-03-25 01:59:325354 // Case 5: Scale.
5355 gfx::Transform scale;
5356 scale.Scale(2.0, 2.0);
5357 child_->SetTransform(scale);
jaydasika3f930c12015-06-30 15:18:255358 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365359 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005360 layers_always_allowed_lcd_text_);
5361 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5362 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5363 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595364
[email protected]fb661802013-03-25 01:59:325365 // Case 6: Skew.
5366 gfx::Transform skew;
nainar8ca8ee62015-09-03 01:04:105367 skew.Skew(10.0, 0.0);
[email protected]fb661802013-03-25 01:59:325368 child_->SetTransform(skew);
jaydasika3f930c12015-06-30 15:18:255369 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365370 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005371 layers_always_allowed_lcd_text_);
5372 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5373 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5374 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595375
[email protected]fb661802013-03-25 01:59:325376 // Case 7: Translucent.
5377 child_->SetTransform(identity_matrix);
jaydasika3f930c12015-06-30 15:18:255378 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]fb661802013-03-25 01:59:325379 child_->SetOpacity(0.5f);
enneaf5bda32015-02-19 01:27:365380 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005381 layers_always_allowed_lcd_text_);
5382 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5383 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5384 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595385
[email protected]fb661802013-03-25 01:59:325386 // Case 8: Sanity check: restore transform and opacity.
5387 child_->SetTransform(identity_matrix);
jaydasika3f930c12015-06-30 15:18:255388 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]fb661802013-03-25 01:59:325389 child_->SetOpacity(1.f);
enneaf5bda32015-02-19 01:27:365390 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005391 layers_always_allowed_lcd_text_);
5392 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5393 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5394 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalita51b5e202014-11-18 20:11:505395
5396 // Case 9: Non-opaque content.
5397 child_->SetContentsOpaque(false);
enneaf5bda32015-02-19 01:27:365398 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505399 layers_always_allowed_lcd_text_);
5400 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5401 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5402 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5403
5404 // Case 10: Sanity check: restore content opaqueness.
5405 child_->SetContentsOpaque(true);
enneaf5bda32015-02-19 01:27:365406 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505407 layers_always_allowed_lcd_text_);
5408 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5409 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5410 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595411}
5412
[email protected]fd9a3b6d2013-08-03 00:46:175413TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005414 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
fmalitafcd926a2015-05-13 20:19:335415 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
danakj3f76ace2014-11-18 16:56:005416
[email protected]fb661802013-03-25 01:59:325417 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
enneaf5bda32015-02-19 01:27:365418 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005419 layers_always_allowed_lcd_text_);
5420 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5421 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5422 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595423
[email protected]fb661802013-03-25 01:59:325424 // Add opacity animation.
5425 child_->SetOpacity(0.9f);
jaydasika3f930c12015-06-30 15:18:255426 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso9556c732016-03-11 07:54:585427 AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f,
5428 0.1f, false);
enneaf5bda32015-02-19 01:27:365429 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005430 layers_always_allowed_lcd_text_);
fmalitafcd926a2015-05-13 20:19:335431 // Text LCD should be adjusted while animation is active.
5432 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5433 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5434 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5435}
5436
5437TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
5438 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5439 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5440
5441 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
5442 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5443 layers_always_allowed_lcd_text_);
danakj3f76ace2014-11-18 16:56:005444 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5445 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5446 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalitafcd926a2015-05-13 20:19:335447
5448 // Mark contents non-opaque within the first animation frame.
5449 child_->SetContentsOpaque(false);
loyso9556c732016-03-11 07:54:585450 AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f,
5451 0.1f, false);
fmalitafcd926a2015-05-13 20:19:335452 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5453 layers_always_allowed_lcd_text_);
5454 // LCD text should be disabled for non-opaque layers even during animations.
5455 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5456 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5457 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595458}
5459
5460INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5461 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005462 testing::Combine(testing::Bool(),
5463 testing::Bool(),
5464 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595465
[email protected]989386c2013-07-18 21:37:235466TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:165467 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455468 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565469 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165470 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565471 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195472 host_impl.CreatePendingTree();
5473 const gfx::Transform identity_matrix;
5474
5475 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
jaydasika0c2fd472016-03-24 01:26:055476 LayerImpl* root_layer = root.get();
awoloszyne83f28c2014-12-22 15:40:005477 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5478 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]c0ae06c12013-06-24 18:32:195479 false);
5480 root->SetDrawsContent(true);
5481
5482 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005483 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5484 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:195485 false);
5486 child->SetDrawsContent(true);
5487
5488 scoped_ptr<LayerImpl> grand_child =
5489 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:005490 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5491 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5492 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:195493 grand_child->SetDrawsContent(true);
5494 grand_child->SetHideLayerAndSubtree(true);
5495
danakja04855a2015-11-18 20:39:105496 child->AddChild(std::move(grand_child));
5497 root->AddChild(std::move(child));
awoloszyne83f28c2014-12-22 15:40:005498 root->SetHasRenderSurface(true);
jaydasika0c2fd472016-03-24 01:26:055499 host_impl.pending_tree()->SetRootLayer(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195500
5501 LayerImplList render_surface_layer_list;
jaydasika0c2fd472016-03-24 01:26:055502 root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]7aad55f2013-07-26 11:25:535503 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
jaydasika0c2fd472016-03-24 01:26:055504 root_layer, root_layer->bounds(), &render_surface_layer_list,
5505 root_layer->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535506 inputs.can_adjust_raster_scales = true;
5507 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195508
5509 // We should have one render surface and two layers. The grand child has
5510 // hidden itself.
5511 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:055512 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5513 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
5514 EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195515}
5516
[email protected]989386c2013-07-18 21:37:235517TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
khushalsagarb64b360d2015-10-21 19:25:165518 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455519 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565520 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165521 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565522 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195523 host_impl.CreatePendingTree();
5524 const gfx::Transform identity_matrix;
5525
5526 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:005527 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5528 gfx::PointF(), gfx::Size(50, 50), true, false,
5529 true);
[email protected]c0ae06c12013-06-24 18:32:195530 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095531 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195532
5533 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005534 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5535 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:195536 false);
5537 child->SetDrawsContent(true);
5538 child->SetHideLayerAndSubtree(true);
5539
5540 scoped_ptr<LayerImpl> grand_child =
5541 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:005542 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5543 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5544 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:195545 grand_child->SetDrawsContent(true);
5546
danakja04855a2015-11-18 20:39:105547 child->AddChild(std::move(grand_child));
5548 root->AddChild(std::move(child));
jaydasika2411692c2016-03-23 01:56:095549 host_impl.pending_tree()->SetRootLayer(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195550
5551 LayerImplList render_surface_layer_list;
jaydasika2411692c2016-03-23 01:56:095552 root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]7aad55f2013-07-26 11:25:535553 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
jaydasika2411692c2016-03-23 01:56:095554 root_layer, root_layer->bounds(), &render_surface_layer_list,
5555 root_layer->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535556 inputs.can_adjust_raster_scales = true;
5557 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195558
5559 // We should have one render surface and one layers. The child has
5560 // hidden itself and the grand child.
5561 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095562 ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size());
5563 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:195564}
5565
[email protected]30fe19ff2013-07-04 00:54:455566void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
5567
[email protected]989386c2013-07-18 21:37:235568TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165569 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455570 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565571 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165572 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565573 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455574 host_impl.CreatePendingTree();
5575 const gfx::Transform identity_matrix;
5576
weiliangc51fb255d2015-07-24 15:32:305577 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5578 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5579 gfx::PointF(), gfx::Size(50, 50), true, false,
5580 true);
5581 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095582 LayerImpl* root_layer = root.get();
[email protected]30fe19ff2013-07-04 00:54:455583
weiliangc51fb255d2015-07-24 15:32:305584 scoped_ptr<LayerImpl> copy_grand_parent =
5585 LayerImpl::Create(host_impl.pending_tree(), 2);
5586 SetLayerPropertiesForTesting(copy_grand_parent.get(), identity_matrix,
5587 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5588 true, false, false);
5589 copy_grand_parent->SetDrawsContent(true);
5590 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455591
weiliangc51fb255d2015-07-24 15:32:305592 scoped_ptr<LayerImpl> copy_parent =
5593 LayerImpl::Create(host_impl.pending_tree(), 3);
5594 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
5595 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5596 true, false, true);
5597 copy_parent->SetDrawsContent(true);
5598 LayerImpl* copy_parent_layer = copy_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455599
weiliangc51fb255d2015-07-24 15:32:305600 scoped_ptr<LayerImpl> copy_request =
5601 LayerImpl::Create(host_impl.pending_tree(), 4);
5602 SetLayerPropertiesForTesting(copy_request.get(), identity_matrix,
5603 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5604 true, false, true);
5605 copy_request->SetDrawsContent(true);
5606 LayerImpl* copy_layer = copy_request.get();
[email protected]30fe19ff2013-07-04 00:54:455607
weiliangc51fb255d2015-07-24 15:32:305608 scoped_ptr<LayerImpl> copy_child =
5609 LayerImpl::Create(host_impl.pending_tree(), 5);
5610 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
5611 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5612 true, false, false);
5613 copy_child->SetDrawsContent(true);
5614 LayerImpl* copy_child_layer = copy_child.get();
[email protected]30fe19ff2013-07-04 00:54:455615
jaydasika86654512016-01-27 17:05:075616 scoped_ptr<LayerImpl> copy_grand_child =
thakise53c5272016-01-24 01:20:405617 LayerImpl::Create(host_impl.pending_tree(), 6);
jaydasika86654512016-01-27 17:05:075618 SetLayerPropertiesForTesting(copy_grand_child.get(), identity_matrix,
5619 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5620 true, false, false);
5621 copy_child->SetDrawsContent(true);
5622 LayerImpl* copy_grand_child_layer = copy_grand_child.get();
5623
5624 scoped_ptr<LayerImpl> copy_grand_parent_sibling_before =
5625 LayerImpl::Create(host_impl.pending_tree(), 7);
[email protected]ac020122013-07-12 23:45:535626 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
weiliangc51fb255d2015-07-24 15:32:305627 identity_matrix, gfx::Point3F(), gfx::PointF(),
5628 gfx::Size(40, 40), true, false, false);
5629 copy_grand_parent_sibling_before->SetDrawsContent(true);
5630 LayerImpl* copy_grand_parent_sibling_before_layer =
5631 copy_grand_parent_sibling_before.get();
[email protected]ac020122013-07-12 23:45:535632
weiliangc51fb255d2015-07-24 15:32:305633 scoped_ptr<LayerImpl> copy_grand_parent_sibling_after =
jaydasika86654512016-01-27 17:05:075634 LayerImpl::Create(host_impl.pending_tree(), 8);
[email protected]ac020122013-07-12 23:45:535635 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
weiliangc51fb255d2015-07-24 15:32:305636 identity_matrix, gfx::Point3F(), gfx::PointF(),
5637 gfx::Size(40, 40), true, false, false);
5638 copy_grand_parent_sibling_after->SetDrawsContent(true);
5639 LayerImpl* copy_grand_parent_sibling_after_layer =
5640 copy_grand_parent_sibling_after.get();
[email protected]ac020122013-07-12 23:45:535641
jaydasika86654512016-01-27 17:05:075642 copy_child->AddChild(std::move(copy_grand_child));
danakja04855a2015-11-18 20:39:105643 copy_request->AddChild(std::move(copy_child));
5644 copy_parent->AddChild(std::move(copy_request));
5645 copy_grand_parent->AddChild(std::move(copy_parent));
5646 root->AddChild(std::move(copy_grand_parent_sibling_before));
5647 root->AddChild(std::move(copy_grand_parent));
5648 root->AddChild(std::move(copy_grand_parent_sibling_after));
jaydasika2411692c2016-03-23 01:56:095649 host_impl.pending_tree()->SetRootLayer(std::move(root));
[email protected]d600df7d2013-08-03 02:34:285650
[email protected]30fe19ff2013-07-04 00:54:455651 // Hide the copy_grand_parent and its subtree. But make a copy request in that
jaydasika86654512016-01-27 17:05:075652 // hidden subtree on copy_layer. Also hide the copy grand child and its
5653 // subtree.
weiliangc51fb255d2015-07-24 15:32:305654 copy_grand_parent_layer->SetHideLayerAndSubtree(true);
5655 copy_grand_parent_sibling_before_layer->SetHideLayerAndSubtree(true);
5656 copy_grand_parent_sibling_after_layer->SetHideLayerAndSubtree(true);
jaydasika86654512016-01-27 17:05:075657 copy_grand_child_layer->SetHideLayerAndSubtree(true);
weiliangc51fb255d2015-07-24 15:32:305658
vmpstra370ef52015-11-18 10:41:285659 std::vector<scoped_ptr<CopyOutputRequest>> copy_requests;
weiliangc51fb255d2015-07-24 15:32:305660 copy_requests.push_back(
5661 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5662 copy_layer->PassCopyRequests(&copy_requests);
[email protected]30fe19ff2013-07-04 00:54:455663 EXPECT_TRUE(copy_layer->HasCopyRequest());
5664
weiliangc51fb255d2015-07-24 15:32:305665 LayerImplList render_surface_layer_list;
jaydasika2411692c2016-03-23 01:56:095666 root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
weiliangc51fb255d2015-07-24 15:32:305667 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
jaydasika2411692c2016-03-23 01:56:095668 root_layer, root_layer->bounds(), &render_surface_layer_list,
5669 root_layer->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535670 inputs.can_adjust_raster_scales = true;
5671 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455672
jaydasika2411692c2016-03-23 01:56:095673 EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0);
sunxded58688e2016-01-11 21:01:025674 EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0);
5675 EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0);
5676 EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0);
[email protected]ac020122013-07-12 23:45:535677
jaydasika86654512016-01-27 17:05:075678 // We should have four render surfaces, one for the root, one for the grand
5679 // parent since it has opacity and two drawing descendants, one for the parent
[email protected]30fe19ff2013-07-04 00:54:455680 // since it owns a surface, and one for the copy_layer.
jaydasika86654512016-01-27 17:05:075681 ASSERT_EQ(4u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095682 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
jaydasika86654512016-01-27 17:05:075683 EXPECT_EQ(copy_grand_parent_layer->id(),
5684 render_surface_layer_list.at(1)->id());
5685 EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id());
5686 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id());
[email protected]30fe19ff2013-07-04 00:54:455687
jaydasika86654512016-01-27 17:05:075688 // The root render surface should have 2 contributing layers.
jaydasika2411692c2016-03-23 01:56:095689 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5690 EXPECT_EQ(root_layer->id(),
5691 root_layer->render_surface()->layer_list().at(0)->id());
jaydasika86654512016-01-27 17:05:075692 EXPECT_EQ(copy_grand_parent_layer->id(),
jaydasika2411692c2016-03-23 01:56:095693 root_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:455694
[email protected]7392c7b2014-02-07 08:28:285695 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:455696 // appear in its list, since it needs to be drawn for the copy request.
weiliangc51fb255d2015-07-24 15:32:305697 ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size());
[email protected]30fe19ff2013-07-04 00:54:455698 EXPECT_EQ(copy_layer->id(),
jaydasika86654512016-01-27 17:05:075699 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455700
5701 // The copy_layer's render surface should have two contributing layers.
5702 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
5703 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:235704 copy_layer->render_surface()->layer_list().at(0)->id());
weiliangc51fb255d2015-07-24 15:32:305705 EXPECT_EQ(copy_child_layer->id(),
[email protected]989386c2013-07-18 21:37:235706 copy_layer->render_surface()->layer_list().at(1)->id());
jaydasika86654512016-01-27 17:05:075707
5708 // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden,
5709 // but the copy_layer and copy_child should be drawn for the copy request.
5710 // copy grand child should not be drawn as its hidden even in the copy
5711 // request.
jaydasika2411692c2016-03-23 01:56:095712 EffectTree tree =
5713 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:075714 EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index());
5715 EXPECT_FALSE(node->data.is_drawn);
5716 node = tree.Node(copy_parent_layer->effect_tree_index());
5717 EXPECT_FALSE(node->data.is_drawn);
5718 node = tree.Node(copy_layer->effect_tree_index());
5719 EXPECT_TRUE(node->data.is_drawn);
5720 node = tree.Node(copy_child_layer->effect_tree_index());
5721 EXPECT_TRUE(node->data.is_drawn);
5722 node = tree.Node(copy_grand_child_layer->effect_tree_index());
5723 EXPECT_FALSE(node->data.is_drawn);
5724
5725 // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its
5726 // actually hidden.
5727 EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface());
[email protected]30fe19ff2013-07-04 00:54:455728}
5729
[email protected]989386c2013-07-18 21:37:235730TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165731 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455732 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565733 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165734 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565735 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455736 host_impl.CreatePendingTree();
5737 const gfx::Transform identity_matrix;
5738
weiliangc51fb255d2015-07-24 15:32:305739 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5740 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5741 gfx::PointF(), gfx::Size(50, 50), true, false,
5742 true);
5743 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455744
weiliangc51fb255d2015-07-24 15:32:305745 scoped_ptr<LayerImpl> copy_parent =
5746 LayerImpl::Create(host_impl.pending_tree(), 2);
5747 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
5748 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
5749 false, false);
5750 copy_parent->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455751 copy_parent->SetMasksToBounds(true);
5752
weiliangc51fb255d2015-07-24 15:32:305753 scoped_ptr<LayerImpl> copy_layer =
5754 LayerImpl::Create(host_impl.pending_tree(), 3);
5755 SetLayerPropertiesForTesting(copy_layer.get(), identity_matrix,
5756 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5757 true, false, true);
5758 copy_layer->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455759
weiliangc51fb255d2015-07-24 15:32:305760 scoped_ptr<LayerImpl> copy_child =
5761 LayerImpl::Create(host_impl.pending_tree(), 4);
5762 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
5763 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5764 true, false, false);
5765 copy_child->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455766
vmpstra370ef52015-11-18 10:41:285767 std::vector<scoped_ptr<CopyOutputRequest>> copy_requests;
weiliangc51fb255d2015-07-24 15:32:305768 copy_requests.push_back(
5769 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5770 copy_layer->PassCopyRequests(&copy_requests);
[email protected]30fe19ff2013-07-04 00:54:455771 EXPECT_TRUE(copy_layer->HasCopyRequest());
5772
danakja04855a2015-11-18 20:39:105773 copy_layer->AddChild(std::move(copy_child));
5774 copy_parent->AddChild(std::move(copy_layer));
5775 root->AddChild(std::move(copy_parent));
weiliangc51fb255d2015-07-24 15:32:305776
5777 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:055778 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
5779 LayerImpl* root_layer = root.get();
5780 root_layer->layer_tree_impl()->SetRootLayer(std::move(root));
weiliangc51fb255d2015-07-24 15:32:305781 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
sunxd71aea3e2016-04-01 23:48:055782 root_layer, root_layer->bounds(), &render_surface_layer_list,
5783 root_layer->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535784 inputs.can_adjust_raster_scales = true;
5785 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455786
xjze19f76402015-11-06 21:48:445787 // We should have two render surface, as the others are clipped out.
5788 ASSERT_EQ(2u, render_surface_layer_list.size());
sunxd71aea3e2016-04-01 23:48:055789 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455790
xjze19f76402015-11-06 21:48:445791 // The root render surface should only have 2 contributing layer, since the
[email protected]30fe19ff2013-07-04 00:54:455792 // other layers are empty/clipped away.
sunxd71aea3e2016-04-01 23:48:055793 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5794 EXPECT_EQ(root_layer->id(),
5795 root_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455796}
5797
[email protected]11a07b102013-07-24 17:33:195798TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
khushalsagarb64b360d2015-10-21 19:25:165799 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455800 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565801 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165802 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565803 &task_graph_runner);
[email protected]11a07b102013-07-24 17:33:195804 host_impl.CreatePendingTree();
5805 const gfx::Transform identity_matrix;
5806
loyso0940d412016-03-14 01:30:315807 scoped_refptr<Layer> root = Layer::Create();
[email protected]11a07b102013-07-24 17:33:195808 SetLayerPropertiesForTesting(root.get(),
5809 identity_matrix,
[email protected]a2566412014-06-05 03:14:205810 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:195811 gfx::PointF(),
5812 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575813 true,
[email protected]11a07b102013-07-24 17:33:195814 false);
5815 root->SetIsDrawable(true);
5816
5817 // The surface is moved slightly outside of the viewport.
loyso0940d412016-03-14 01:30:315818 scoped_refptr<Layer> surface = Layer::Create();
[email protected]11a07b102013-07-24 17:33:195819 SetLayerPropertiesForTesting(surface.get(),
5820 identity_matrix,
[email protected]a2566412014-06-05 03:14:205821 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:195822 gfx::PointF(-10, -20),
5823 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:575824 true,
[email protected]11a07b102013-07-24 17:33:195825 false);
5826 surface->SetForceRenderSurface(true);
5827
loyso0940d412016-03-14 01:30:315828 scoped_refptr<Layer> surface_child = Layer::Create();
[email protected]11a07b102013-07-24 17:33:195829 SetLayerPropertiesForTesting(surface_child.get(),
5830 identity_matrix,
[email protected]a2566412014-06-05 03:14:205831 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:195832 gfx::PointF(),
5833 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575834 true,
[email protected]11a07b102013-07-24 17:33:195835 false);
5836 surface_child->SetIsDrawable(true);
5837
5838 surface->AddChild(surface_child);
5839 root->AddChild(surface);
5840
ennea7b43c32015-06-18 20:01:335841 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:285842
jaydasika6b7c69d2016-04-01 00:54:435843 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(root.get(),
5844 root->bounds());
5845 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]11a07b102013-07-24 17:33:195846
danakj64767d902015-06-19 00:10:435847 // The visible_layer_rect for the |surface_child| should not be clipped by
[email protected]11a07b102013-07-24 17:33:195848 // the viewport.
5849 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
jaydasika74bf516f2016-04-01 19:48:155850 surface_child->visible_layer_rect_for_testing().ToString());
[email protected]11a07b102013-07-24 17:33:195851}
5852
[email protected]420fdf6e2013-08-26 20:36:385853TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5854 // Ensure that a transform between the layer and its render surface is not a
5855 // problem. Constructs the following layer tree.
5856 //
5857 // root (a render surface)
5858 // + render_surface
5859 // + clip_parent (scaled)
5860 // + intervening_clipping_layer
5861 // + clip_child
5862 //
5863 // The render surface should be resized correctly and the clip child should
5864 // inherit the right clip rect.
enne70aa712d2015-07-28 22:46:315865 LayerImpl* root = root_layer();
5866 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
5867 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
jaydasika0d98ba92015-11-17 05:17:285868 clip_parent->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315869 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285870 intervening->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315871 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5872 clip_child->SetDrawsContent(true);
5873 clip_child->SetClipParent(clip_parent);
5874 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
5875 clip_children->insert(clip_child);
5876 clip_parent->SetClipChildren(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385877
5878 intervening->SetMasksToBounds(true);
5879 clip_parent->SetMasksToBounds(true);
5880
[email protected]420fdf6e2013-08-26 20:36:385881 gfx::Transform scale_transform;
5882 scale_transform.Scale(2, 2);
5883
5884 gfx::Transform identity_transform;
5885
enne70aa712d2015-07-28 22:46:315886 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5887 gfx::PointF(), gfx::Size(50, 50), true, false,
5888 true);
5889 SetLayerPropertiesForTesting(render_surface, identity_transform,
5890 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5891 true, false, true);
5892 SetLayerPropertiesForTesting(clip_parent, scale_transform, gfx::Point3F(),
5893 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
5894 false, false);
5895 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5896 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5897 false, false);
5898 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5899 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
5900 false, false);
[email protected]420fdf6e2013-08-26 20:36:385901
enne70aa712d2015-07-28 22:46:315902 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385903
5904 ASSERT_TRUE(root->render_surface());
5905 ASSERT_TRUE(render_surface->render_surface());
5906
5907 // Ensure that we've inherited our clip parent's clip and weren't affected
5908 // by the intervening clip layer.
5909 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
5910 clip_parent->clip_rect().ToString());
5911 ASSERT_EQ(clip_parent->clip_rect().ToString(),
5912 clip_child->clip_rect().ToString());
5913 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
5914 intervening->clip_rect().ToString());
5915
5916 // Ensure that the render surface reports a content rect that has been grown
5917 // to accomodate for the clip child.
jaydasika0d98ba92015-11-17 05:17:285918 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
[email protected]420fdf6e2013-08-26 20:36:385919 render_surface->render_surface()->content_rect().ToString());
5920
5921 // The above check implies the two below, but they nicely demonstrate that
5922 // we've grown, despite the intervening layer's clip.
5923 ASSERT_TRUE(clip_parent->clip_rect().Contains(
5924 render_surface->render_surface()->content_rect()));
5925 ASSERT_FALSE(intervening->clip_rect().Contains(
5926 render_surface->render_surface()->content_rect()));
5927}
5928
5929TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5930 // Ensure that intervening render surfaces are not a problem in the basic
5931 // case. In the following tree, both render surfaces should be resized to
5932 // accomodate for the clip child, despite an intervening clip.
5933 //
5934 // root (a render surface)
5935 // + clip_parent (masks to bounds)
5936 // + render_surface1 (sets opacity)
5937 // + intervening (masks to bounds)
5938 // + render_surface2 (also sets opacity)
5939 // + clip_child
5940 //
weiliangcd6a836d2015-07-28 21:20:235941 LayerImpl* root = root_layer();
5942 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5943 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5944 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5945 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5946 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365947 render_surface1->SetDrawsContent(true);
5948 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235949 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385950
weiliangcd6a836d2015-07-28 21:20:235951 clip_child->SetClipParent(clip_parent);
[email protected]420fdf6e2013-08-26 20:36:385952
5953 intervening->SetMasksToBounds(true);
5954 clip_parent->SetMasksToBounds(true);
5955
[email protected]420fdf6e2013-08-26 20:36:385956 gfx::Transform translation_transform;
5957 translation_transform.Translate(2, 2);
5958
5959 gfx::Transform identity_transform;
weiliangcd6a836d2015-07-28 21:20:235960 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5961 gfx::PointF(), gfx::Size(50, 50), true, false,
5962 true);
5963 SetLayerPropertiesForTesting(clip_parent, translation_transform,
5964 gfx::Point3F(), gfx::PointF(1.f, 1.f),
5965 gfx::Size(40, 40), true, false, false);
5966 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5967 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5968 true, false, true);
5969 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5970 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5971 false, false);
5972 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5973 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5974 true, false, true);
5975 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5976 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
5977 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:385978
weiliangcd6a836d2015-07-28 21:20:235979 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385980
5981 EXPECT_TRUE(root->render_surface());
5982 EXPECT_TRUE(render_surface1->render_surface());
5983 EXPECT_TRUE(render_surface2->render_surface());
5984
5985 // Since the render surfaces could have expanded, they should not clip (their
5986 // bounds would no longer be reliable). We should resort to layer clipping
5987 // in this case.
5988 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5989 render_surface1->render_surface()->clip_rect().ToString());
5990 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5991 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5992 render_surface2->render_surface()->clip_rect().ToString());
5993 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5994
5995 // NB: clip rects are in target space.
5996 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5997 render_surface1->clip_rect().ToString());
5998 EXPECT_TRUE(render_surface1->is_clipped());
5999
6000 // This value is inherited from the clipping ancestor layer, 'intervening'.
6001 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6002 render_surface2->clip_rect().ToString());
6003 EXPECT_TRUE(render_surface2->is_clipped());
6004
6005 // The content rects of both render surfaces should both have expanded to
6006 // contain the clip child.
6007 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6008 render_surface1->render_surface()->content_rect().ToString());
6009 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6010 render_surface2->render_surface()->content_rect().ToString());
6011
6012 // The clip child should have inherited the clip parent's clip (projected to
6013 // the right space, of course), and should have the correctly sized visible
6014 // content rect.
6015 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6016 clip_child->clip_rect().ToString());
6017 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
danakj64767d902015-06-19 00:10:436018 clip_child->visible_layer_rect().ToString());
[email protected]420fdf6e2013-08-26 20:36:386019 EXPECT_TRUE(clip_child->is_clipped());
6020}
6021
6022TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
6023 // Ensure that intervening render surfaces are not a problem, even if there
6024 // is a scroll involved. Note, we do _not_ have to consider any other sort
6025 // of transform.
6026 //
6027 // root (a render surface)
6028 // + clip_parent (masks to bounds)
6029 // + render_surface1 (sets opacity)
6030 // + intervening (masks to bounds AND scrolls)
6031 // + render_surface2 (also sets opacity)
6032 // + clip_child
6033 //
weiliangcd6a836d2015-07-28 21:20:236034 LayerImpl* root = root_layer();
6035 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
6036 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
6037 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
6038 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
6039 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:366040 render_surface1->SetDrawsContent(true);
6041 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:236042 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:386043
weiliangcd6a836d2015-07-28 21:20:236044 clip_child->SetClipParent(clip_parent);
[email protected]420fdf6e2013-08-26 20:36:386045
6046 intervening->SetMasksToBounds(true);
6047 clip_parent->SetMasksToBounds(true);
weiliangcd6a836d2015-07-28 21:20:236048 intervening->SetScrollClipLayer(clip_parent->id());
6049 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:386050
6051 gfx::Transform translation_transform;
6052 translation_transform.Translate(2, 2);
6053
6054 gfx::Transform identity_transform;
weiliangcd6a836d2015-07-28 21:20:236055 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6056 gfx::PointF(), gfx::Size(50, 50), true, false,
6057 true);
6058 SetLayerPropertiesForTesting(clip_parent, translation_transform,
6059 gfx::Point3F(), gfx::PointF(1.f, 1.f),
6060 gfx::Size(40, 40), true, false, false);
6061 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6062 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
6063 true, false, true);
6064 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
6065 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
6066 false, false);
6067 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6068 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
6069 true, false, true);
6070 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
6071 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
6072 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:386073
weiliangcd6a836d2015-07-28 21:20:236074 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:386075
6076 EXPECT_TRUE(root->render_surface());
6077 EXPECT_TRUE(render_surface1->render_surface());
6078 EXPECT_TRUE(render_surface2->render_surface());
6079
6080 // Since the render surfaces could have expanded, they should not clip (their
6081 // bounds would no longer be reliable). We should resort to layer clipping
6082 // in this case.
6083 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6084 render_surface1->render_surface()->clip_rect().ToString());
6085 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6086 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6087 render_surface2->render_surface()->clip_rect().ToString());
6088 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6089
6090 // NB: clip rects are in target space.
6091 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6092 render_surface1->clip_rect().ToString());
6093 EXPECT_TRUE(render_surface1->is_clipped());
6094
6095 // This value is inherited from the clipping ancestor layer, 'intervening'.
6096 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6097 render_surface2->clip_rect().ToString());
6098 EXPECT_TRUE(render_surface2->is_clipped());
6099
6100 // The content rects of both render surfaces should both have expanded to
6101 // contain the clip child.
6102 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6103 render_surface1->render_surface()->content_rect().ToString());
6104 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6105 render_surface2->render_surface()->content_rect().ToString());
6106
6107 // The clip child should have inherited the clip parent's clip (projected to
6108 // the right space, of course), and should have the correctly sized visible
6109 // content rect.
6110 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6111 clip_child->clip_rect().ToString());
6112 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
danakj64767d902015-06-19 00:10:436113 clip_child->visible_layer_rect().ToString());
[email protected]420fdf6e2013-08-26 20:36:386114 EXPECT_TRUE(clip_child->is_clipped());
6115}
6116
6117TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
6118 // Ensures that descendants of the clip child inherit the correct clip.
6119 //
6120 // root (a render surface)
6121 // + clip_parent (masks to bounds)
6122 // + intervening (masks to bounds)
6123 // + clip_child
6124 // + child
6125 //
enne2d0d8e62015-08-18 18:29:176126 LayerImpl* root = root_layer();
6127 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
6128 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
6129 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
6130 LayerImpl* child = AddChild<LayerImpl>(clip_child);
jaydasika8640f9f2015-11-10 01:34:366131 clip_child->SetDrawsContent(true);
enne2d0d8e62015-08-18 18:29:176132 child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:386133
enne2d0d8e62015-08-18 18:29:176134 clip_child->SetClipParent(clip_parent);
6135 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
6136 clip_children->insert(clip_child);
6137 clip_parent->SetClipChildren(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:386138
6139 intervening->SetMasksToBounds(true);
6140 clip_parent->SetMasksToBounds(true);
6141
6142 gfx::Transform identity_transform;
enne2d0d8e62015-08-18 18:29:176143 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6144 gfx::PointF(), gfx::Size(50, 50), true, false,
6145 true);
6146 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
6147 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]420fdf6e2013-08-26 20:36:386148 false);
enne2d0d8e62015-08-18 18:29:176149 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
6150 gfx::PointF(), gfx::Size(5, 5), true, false,
[email protected]420fdf6e2013-08-26 20:36:386151 false);
enne2d0d8e62015-08-18 18:29:176152 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
6153 gfx::PointF(), gfx::Size(60, 60), true, false,
[email protected]420fdf6e2013-08-26 20:36:386154 false);
enne2d0d8e62015-08-18 18:29:176155 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6156 gfx::PointF(), gfx::Size(60, 60), true, false,
[email protected]420fdf6e2013-08-26 20:36:386157 false);
6158
enne2d0d8e62015-08-18 18:29:176159 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:386160
6161 EXPECT_TRUE(root->render_surface());
6162
6163 // Neither the clip child nor its descendant should have inherited the clip
6164 // from |intervening|.
6165 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6166 clip_child->clip_rect().ToString());
6167 EXPECT_TRUE(clip_child->is_clipped());
6168 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
danakj64767d902015-06-19 00:10:436169 child->visible_layer_rect().ToString());
[email protected]420fdf6e2013-08-26 20:36:386170 EXPECT_TRUE(child->is_clipped());
6171}
6172
6173TEST_F(LayerTreeHostCommonTest,
6174 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
6175 // Ensures that non-descendant clip children in the tree do not affect
6176 // render surfaces.
6177 //
6178 // root (a render surface)
6179 // + clip_parent (masks to bounds)
6180 // + render_surface1
6181 // + clip_child
6182 // + render_surface2
6183 // + non_clip_child
6184 //
6185 // In this example render_surface2 should be unaffected by clip_child.
enneb441cdd2015-07-28 22:47:506186 LayerImpl* root = root_layer();
6187 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
6188 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:286189 render_surface1->SetDrawsContent(true);
enneb441cdd2015-07-28 22:47:506190 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
6191 clip_child->SetDrawsContent(true);
6192 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:286193 render_surface2->SetDrawsContent(true);
enneb441cdd2015-07-28 22:47:506194 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
6195 non_clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:386196
enneb441cdd2015-07-28 22:47:506197 clip_child->SetClipParent(clip_parent);
6198 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
6199 clip_children->insert(clip_child);
6200 clip_parent->SetClipChildren(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:386201
6202 clip_parent->SetMasksToBounds(true);
6203 render_surface1->SetMasksToBounds(true);
6204
6205 gfx::Transform identity_transform;
enneb441cdd2015-07-28 22:47:506206 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6207 gfx::PointF(), gfx::Size(15, 15), true, false,
6208 true);
6209 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
6210 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]420fdf6e2013-08-26 20:36:386211 false);
enneb441cdd2015-07-28 22:47:506212 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6213 gfx::Point3F(), gfx::PointF(5, 5),
6214 gfx::Size(5, 5), true, false, true);
6215 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6216 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
6217 true, false, true);
6218 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
6219 gfx::PointF(-1, 1), gfx::Size(10, 10), true,
6220 false, false);
6221 SetLayerPropertiesForTesting(non_clip_child, identity_transform,
6222 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
6223 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:386224
enneb441cdd2015-07-28 22:47:506225 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:386226
6227 EXPECT_TRUE(root->render_surface());
6228 EXPECT_TRUE(render_surface1->render_surface());
6229 EXPECT_TRUE(render_surface2->render_surface());
6230
6231 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6232 render_surface1->clip_rect().ToString());
6233 EXPECT_TRUE(render_surface1->is_clipped());
6234
6235 // The render surface should not clip (it has unclipped descendants), instead
6236 // it should rely on layer clipping.
6237 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6238 render_surface1->render_surface()->clip_rect().ToString());
6239 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6240
jaydasika0d98ba92015-11-17 05:17:286241 // That said, it should have grown to accomodate the unclipped descendant and
6242 // its own size.
6243 EXPECT_EQ(gfx::Rect(-1, 0, 6, 5).ToString(),
[email protected]420fdf6e2013-08-26 20:36:386244 render_surface1->render_surface()->content_rect().ToString());
6245
6246 // This render surface should clip. It has no unclipped descendants.
weiliangcbb2e8642016-03-04 00:24:426247 EXPECT_EQ(gfx::Rect(0, 0, 10, 10).ToString(),
6248 render_surface2->render_surface()->clip_rect().ToString());
[email protected]420fdf6e2013-08-26 20:36:386249 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
weiliangcbb2e8642016-03-04 00:24:426250 EXPECT_FALSE(render_surface2->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:386251
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));
sunxd71aea3e2016-04-01 23:48:056342 LayerImpl* root_layer = root.get();
6343 root_layer->layer_tree_impl()->SetRootLayer(std::move(root));
[email protected]45948712013-09-27 02:46:486344
6345 {
6346 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:056347 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer);
6348 root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]45948712013-09-27 02:46:486349 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
sunxd71aea3e2016-04-01 23:48:056350 root_layer, root_layer->bounds(), &render_surface_layer_list,
6351 root_layer->layer_tree_impl()->current_render_surface_list_id());
[email protected]45948712013-09-27 02:46:486352 inputs.can_render_to_separate_surface = true;
6353 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6354
6355 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026356
6357 int count_represents_target_render_surface = 0;
6358 int count_represents_contributing_render_surface = 0;
6359 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516360 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6361 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026362 it != end; ++it) {
6363 if (it.represents_target_render_surface())
6364 count_represents_target_render_surface++;
6365 if (it.represents_contributing_render_surface())
6366 count_represents_contributing_render_surface++;
6367 if (it.represents_itself())
6368 count_represents_itself++;
6369 }
6370
6371 // Two render surfaces.
6372 EXPECT_EQ(2, count_represents_target_render_surface);
6373 // Second render surface contributes to root render surface.
6374 EXPECT_EQ(1, count_represents_contributing_render_surface);
6375 // All 4 layers represent itself.
6376 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486377 }
6378
6379 {
6380 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:056381 root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]45948712013-09-27 02:46:486382 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
sunxd71aea3e2016-04-01 23:48:056383 root_layer, root_layer->bounds(), &render_surface_layer_list,
6384 root_layer->layer_tree_impl()->current_render_surface_list_id());
[email protected]45948712013-09-27 02:46:486385 inputs.can_render_to_separate_surface = false;
6386 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6387
6388 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026389
6390 int count_represents_target_render_surface = 0;
6391 int count_represents_contributing_render_surface = 0;
6392 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516393 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6394 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026395 it != end; ++it) {
6396 if (it.represents_target_render_surface())
6397 count_represents_target_render_surface++;
6398 if (it.represents_contributing_render_surface())
6399 count_represents_contributing_render_surface++;
6400 if (it.represents_itself())
6401 count_represents_itself++;
6402 }
6403
6404 // Only root layer has a render surface.
6405 EXPECT_EQ(1, count_represents_target_render_surface);
6406 // No layer contributes a render surface to root render surface.
6407 EXPECT_EQ(0, count_represents_contributing_render_surface);
6408 // All 4 layers represent itself.
6409 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486410 }
6411}
6412
[email protected]a9aa60a82013-08-29 04:28:266413TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
enne03b0e9a2015-06-19 00:08:026414 LayerImpl* root = root_layer();
jaydasikae00c8a42016-01-28 20:18:336415 LayerImpl* back_facing = AddChild<LayerImpl>(root);
6416 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
6417 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
6418 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
6419 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
6420 child1->SetDrawsContent(true);
6421 child2->SetDrawsContent(true);
[email protected]a9aa60a82013-08-29 04:28:266422
6423 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026424 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6425 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]56fffdd2014-02-11 19:50:576426 true);
jaydasikae00c8a42016-01-28 20:18:336427 SetLayerPropertiesForTesting(back_facing, identity_transform, gfx::Point3F(),
6428 gfx::PointF(), gfx::Size(50, 50), true, false,
6429 false);
6430 SetLayerPropertiesForTesting(render_surface1, identity_transform,
enne03b0e9a2015-06-19 00:08:026431 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6432 false, true, true);
jaydasikae00c8a42016-01-28 20:18:336433 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6434 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6435 false, true, true);
6436 SetLayerPropertiesForTesting(child1, identity_transform, gfx::Point3F(),
6437 gfx::PointF(), gfx::Size(20, 20), true, false,
6438 false);
6439 SetLayerPropertiesForTesting(child2, identity_transform, gfx::Point3F(),
enne03b0e9a2015-06-19 00:08:026440 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]a9aa60a82013-08-29 04:28:266441 false);
6442
[email protected]56fffdd2014-02-11 19:50:576443 root->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:286444 root->Set3dSortingContextId(1);
jaydasikae00c8a42016-01-28 20:18:336445 back_facing->Set3dSortingContextId(1);
6446 back_facing->SetShouldFlattenTransform(false);
6447 render_surface1->SetDoubleSided(false);
6448 render_surface2->Set3dSortingContextId(2);
6449 render_surface2->SetDoubleSided(false);
[email protected]a9aa60a82013-08-29 04:28:266450
enne03b0e9a2015-06-19 00:08:026451 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266452
jaydasikae00c8a42016-01-28 20:18:336453 EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id());
6454 EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id());
6455 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6456 EXPECT_EQ(2u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026457 ->at(0)
6458 ->render_surface()
6459 ->layer_list()
6460 .size());
6461 EXPECT_EQ(1u, render_surface_layer_list_impl()
6462 ->at(1)
6463 ->render_surface()
6464 ->layer_list()
6465 .size());
[email protected]a9aa60a82013-08-29 04:28:266466
6467 gfx::Transform rotation_transform = identity_transform;
6468 rotation_transform.RotateAboutXAxis(180.0);
6469
jaydasikae00c8a42016-01-28 20:18:336470 back_facing->SetTransform(rotation_transform);
jaydasika5aa88b82015-11-10 01:48:036471 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]a9aa60a82013-08-29 04:28:266472
enne03b0e9a2015-06-19 00:08:026473 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266474
jaydasikae00c8a42016-01-28 20:18:336475 // render_surface1 is in the same 3d rendering context as back_facing and is
6476 // not double sided, so it should not be in RSLL. render_surface2 is also not
6477 // double-sided, but will still be in RSLL as it's in a different 3d rendering
6478 // context.
6479 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
6480 EXPECT_EQ(1u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026481 ->at(0)
6482 ->render_surface()
6483 ->layer_list()
6484 .size());
[email protected]a9aa60a82013-08-29 04:28:266485}
6486
ajumaaa0d3862015-11-09 22:24:466487TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) {
6488 LayerImpl* root = root_layer();
6489 LayerImpl* child = AddChild<LayerImpl>(root);
6490 LayerImpl* grand_child = AddChild<LayerImpl>(child);
6491 grand_child->SetDrawsContent(true);
6492
6493 child->SetDoubleSided(false);
6494 grand_child->SetUseParentBackfaceVisibility(true);
6495
6496 gfx::Transform identity_transform;
6497 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
jaydasika62bd3dd2016-02-04 18:52:556498 gfx::PointF(), gfx::Size(50, 50), false, false,
ajumaaa0d3862015-11-09 22:24:466499 true);
6500 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
jaydasika62bd3dd2016-02-04 18:52:556501 gfx::PointF(), gfx::Size(30, 30), false, false,
ajumaaa0d3862015-11-09 22:24:466502 false);
6503 SetLayerPropertiesForTesting(grand_child, identity_transform, gfx::Point3F(),
jaydasika62bd3dd2016-02-04 18:52:556504 gfx::PointF(), gfx::Size(20, 20), false, false,
ajumaaa0d3862015-11-09 22:24:466505 false);
6506
6507 ExecuteCalculateDrawProperties(root);
6508
6509 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6510 EXPECT_EQ(grand_child, render_surface_layer_list_impl()
6511 ->at(0)
6512 ->render_surface()
6513 ->layer_list()[0]);
jaydasika62bd3dd2016-02-04 18:52:556514
6515 // As all layers have identity transform, we shouldn't check for backface
6516 // visibility.
6517 EXPECT_FALSE(root->should_check_backface_visibility());
6518 EXPECT_FALSE(child->should_check_backface_visibility());
6519 EXPECT_FALSE(grand_child->should_check_backface_visibility());
6520 // As there are no 3d rendering contexts, all layers should use their local
6521 // transform for backface visibility.
6522 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6523 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6524 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6525
ajumaaa0d3862015-11-09 22:24:466526 gfx::Transform rotation_transform = identity_transform;
6527 rotation_transform.RotateAboutXAxis(180.0);
6528
6529 child->SetTransform(rotation_transform);
jaydasika62bd3dd2016-02-04 18:52:556530 child->Set3dSortingContextId(1);
6531 grand_child->Set3dSortingContextId(1);
ajumaaa0d3862015-11-09 22:24:466532 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6533
6534 ExecuteCalculateDrawProperties(root);
6535 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6536 EXPECT_EQ(0u, render_surface_layer_list_impl()
6537 ->at(0)
6538 ->render_surface()
6539 ->layer_list()
6540 .size());
jaydasika62bd3dd2016-02-04 18:52:556541
6542 // We should check for backface visibilty of child as it has a rotation
6543 // transform. We should also check for grand_child as it uses the backface
6544 // visibility of its parent.
6545 EXPECT_FALSE(root->should_check_backface_visibility());
6546 EXPECT_TRUE(child->should_check_backface_visibility());
6547 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6548 // child uses its local transform for backface visibility as it is the root of
6549 // a 3d rendering context. grand_child is in a 3d rendering context and is not
6550 // the root, but it derives its backface visibility from its parent which uses
6551 // its local transform.
6552 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6553 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6554 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6555
6556 grand_child->SetUseParentBackfaceVisibility(false);
6557 grand_child->SetDoubleSided(false);
6558 grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6559
6560 ExecuteCalculateDrawProperties(root);
6561 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6562 EXPECT_EQ(0u, render_surface_layer_list_impl()
6563 ->at(0)
6564 ->render_surface()
6565 ->layer_list()
6566 .size());
6567
6568 // We should check the backface visibility of child as it has a rotation
6569 // transform and for grand_child as it is in a 3d rendering context and not
6570 // the root of it.
6571 EXPECT_FALSE(root->should_check_backface_visibility());
6572 EXPECT_TRUE(child->should_check_backface_visibility());
6573 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6574 // grand_child is in an existing 3d rendering context, so it should not use
6575 // local transform for backface visibility.
6576 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6577 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6578 EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility());
ajumaaa0d3862015-11-09 22:24:466579}
6580
[email protected]995708c52013-10-17 20:52:596581TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
6582 // Checks that the simple case (being clipped by a scroll parent that would
6583 // have been processed before you anyhow) results in the right clips.
6584 //
6585 // + root
6586 // + scroll_parent_border
6587 // | + scroll_parent_clip
6588 // | + scroll_parent
6589 // + scroll_child
6590 //
enne085b48a2015-08-18 17:54:486591 LayerImpl* root = root_layer();
6592 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
6593 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6594 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6595 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596596
enne085b48a2015-08-18 17:54:486597 scroll_parent->SetDrawsContent(true);
6598 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596599 scroll_parent_clip->SetMasksToBounds(true);
6600
enne085b48a2015-08-18 17:54:486601 scroll_child->SetScrollParent(scroll_parent);
6602 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6603 scroll_children->insert(scroll_child);
6604 scroll_parent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596605
6606 gfx::Transform identity_transform;
enne085b48a2015-08-18 17:54:486607 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6608 gfx::PointF(), gfx::Size(50, 50), true, false,
6609 true);
6610 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6611 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6612 true, false, false);
6613 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6614 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6615 true, false, false);
6616 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6617 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6618 true, false, false);
6619 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6620 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596621 false);
6622
enne085b48a2015-08-18 17:54:486623 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596624
6625 EXPECT_TRUE(root->render_surface());
6626
6627 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6628 scroll_child->clip_rect().ToString());
6629 EXPECT_TRUE(scroll_child->is_clipped());
6630}
6631
jaydasika8ccff3d2016-01-20 19:51:306632TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) {
6633 // Tests the computation of draw transform for the scroll child when its
6634 // target is different from its scroll parent's target.
6635 LayerImpl* root = root_layer();
6636 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
6637 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
6638 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target);
6639 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
6640
6641 scroll_parent->SetDrawsContent(true);
6642 scroll_child->SetDrawsContent(true);
6643
6644 scroll_child->SetScrollParent(scroll_parent);
6645 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6646 scroll_children->insert(scroll_child);
6647 scroll_parent->SetScrollChildren(scroll_children.release());
6648
6649 gfx::Transform identity_transform;
6650 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6651 gfx::PointF(), gfx::Size(50, 50), true, false,
6652 true);
6653 SetLayerPropertiesForTesting(scroll_child_target, identity_transform,
6654 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6655 true, false, true);
6656 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6657 gfx::PointF(), gfx::Size(50, 50), true, false,
6658 false);
6659 SetLayerPropertiesForTesting(scroll_parent_target, identity_transform,
6660 gfx::Point3F(), gfx::PointF(10, 10),
6661 gfx::Size(50, 50), true, false, true);
6662 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6663 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
jaydasika2489a442016-01-29 02:26:006664 true, false, false);
6665 scroll_parent_target->SetMasksToBounds(true);
jaydasika8ccff3d2016-01-20 19:51:306666
jaydasika2489a442016-01-29 02:26:006667 float device_scale_factor = 1.5f;
6668 LayerImplList render_surface_layer_list_impl;
6669 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
6670 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
6671 root, root->bounds(), identity_transform, &render_surface_layer_list_impl,
6672 root->layer_tree_impl()->current_render_surface_list_id());
6673 inputs.device_scale_factor = device_scale_factor;
6674 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6675
weiliangc1da3fb892016-03-14 20:23:526676 EXPECT_EQ(scroll_child->effect_tree_index(),
6677 scroll_child_target->effect_tree_index());
jaydasika2489a442016-01-29 02:26:006678 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40));
6679 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75));
6680 gfx::Transform scale;
6681 scale.Scale(1.5f, 1.5f);
6682 EXPECT_EQ(scroll_child->DrawTransform(), scale);
jaydasika8ccff3d2016-01-20 19:51:306683}
6684
[email protected]08bdf1b2014-04-16 23:23:296685TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
enneca33fed2015-07-27 18:22:196686 LayerImpl* root = root_layer();
6687 root->SetDrawsContent(true);
6688 LayerImpl* parent = AddChildToRoot<LayerImpl>();
6689 parent->SetDrawsContent(true);
6690 LayerImpl* child = AddChild<LayerImpl>(parent);
6691 child->SetDrawsContent(true);
[email protected]08bdf1b2014-04-16 23:23:296692
6693 gfx::Transform identity_transform;
enneca33fed2015-07-27 18:22:196694 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6695 gfx::PointF(), gfx::Size(50, 50), true, true,
[email protected]08bdf1b2014-04-16 23:23:296696 true);
enneca33fed2015-07-27 18:22:196697 SetLayerPropertiesForTesting(parent, identity_transform, gfx::Point3F(),
6698 gfx::PointF(), gfx::Size(30, 30), true, true,
[email protected]08bdf1b2014-04-16 23:23:296699 true);
enneca33fed2015-07-27 18:22:196700 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6701 gfx::PointF(), gfx::Size(20, 20), true, true,
[email protected]08bdf1b2014-04-16 23:23:296702 true);
[email protected]08bdf1b2014-04-16 23:23:296703
enneca33fed2015-07-27 18:22:196704 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296705
enneca33fed2015-07-27 18:22:196706 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296707
6708 gfx::Transform singular_transform;
6709 singular_transform.Scale3d(
6710 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6711
6712 child->SetTransform(singular_transform);
6713
sunxd71aea3e2016-04-01 23:48:056714 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196715 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296716
enneca33fed2015-07-27 18:22:196717 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296718
6719 // Ensure that the entire subtree under a layer with singular transform does
6720 // not get rendered.
6721 parent->SetTransform(singular_transform);
6722 child->SetTransform(identity_transform);
6723
sunxd71aea3e2016-04-01 23:48:056724 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196725 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296726
enneca33fed2015-07-27 18:22:196727 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296728}
6729
[email protected]995708c52013-10-17 20:52:596730TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
6731 // Checks that clipping by a scroll parent that follows you in paint order
6732 // still results in correct clipping.
6733 //
6734 // + root
[email protected]995708c52013-10-17 20:52:596735 // + scroll_parent_border
6736 // + scroll_parent_clip
6737 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026738 // + scroll_child
[email protected]995708c52013-10-17 20:52:596739 //
enne03b0e9a2015-06-19 00:08:026740 LayerImpl* root = root_layer();
6741 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6742 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6743 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6744 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596745
enne03b0e9a2015-06-19 00:08:026746 scroll_parent->SetDrawsContent(true);
6747 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596748
6749 scroll_parent_clip->SetMasksToBounds(true);
6750
enne03b0e9a2015-06-19 00:08:026751 scroll_child->SetScrollParent(scroll_parent);
ajuma9af2e92b2015-06-29 22:26:386752 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6753 scroll_children->insert(scroll_child);
6754 scroll_parent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596755
6756 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026757 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6758 gfx::PointF(), gfx::Size(50, 50), true, false,
6759 true);
6760 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6761 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6762 true, false, false);
6763 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6764 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6765 true, false, false);
6766 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6767 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6768 true, false, false);
6769 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6770 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596771 false);
6772
enne03b0e9a2015-06-19 00:08:026773 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596774
6775 EXPECT_TRUE(root->render_surface());
6776
6777 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6778 scroll_child->clip_rect().ToString());
6779 EXPECT_TRUE(scroll_child->is_clipped());
6780}
6781
6782TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
6783 // Checks that clipping by a scroll parent and scroll grandparent that follow
6784 // you in paint order still results in correct clipping.
6785 //
6786 // + root
6787 // + scroll_child
6788 // + scroll_parent_border
6789 // | + scroll_parent_clip
6790 // | + scroll_parent
6791 // + scroll_grandparent_border
6792 // + scroll_grandparent_clip
6793 // + scroll_grandparent
6794 //
enne03b0e9a2015-06-19 00:08:026795 LayerImpl* root = root_layer();
6796 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6797 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6798 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6799 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6800 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6801 LayerImpl* scroll_grandparent_clip =
6802 AddChild<LayerImpl>(scroll_grandparent_border);
6803 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:596804
enne03b0e9a2015-06-19 00:08:026805 scroll_parent->SetDrawsContent(true);
6806 scroll_grandparent->SetDrawsContent(true);
6807 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596808
6809 scroll_parent_clip->SetMasksToBounds(true);
6810 scroll_grandparent_clip->SetMasksToBounds(true);
6811
enne03b0e9a2015-06-19 00:08:026812 scroll_child->SetScrollParent(scroll_parent);
ajuma9af2e92b2015-06-29 22:26:386813 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6814 scroll_children->insert(scroll_child);
6815 scroll_parent->SetScrollChildren(scroll_children.release());
6816
enne03b0e9a2015-06-19 00:08:026817 scroll_parent_border->SetScrollParent(scroll_grandparent);
ajuma9af2e92b2015-06-29 22:26:386818 scroll_children.reset(new std::set<LayerImpl*>);
6819 scroll_children->insert(scroll_parent_border);
6820 scroll_grandparent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596821
6822 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026823 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6824 gfx::PointF(), gfx::Size(50, 50), true, false,
6825 true);
6826 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6827 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6828 true, false, false);
6829 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6830 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6831 true, false, false);
6832 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6833 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6834 true, false, false);
6835 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6836 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6837 true, false, false);
6838 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6839 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6840 true, false, false);
6841 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6842 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6843 true, false, false);
6844 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6845 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596846 false);
6847
enne03b0e9a2015-06-19 00:08:026848 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596849
6850 EXPECT_TRUE(root->render_surface());
6851
6852 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
6853 scroll_child->clip_rect().ToString());
6854 EXPECT_TRUE(scroll_child->is_clipped());
6855
6856 // Despite the fact that we visited the above layers out of order to get the
6857 // correct clip, the layer lists should be unaffected.
6858 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
enne03b0e9a2015-06-19 00:08:026859 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
6860 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
6861 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
[email protected]995708c52013-10-17 20:52:596862}
6863
6864TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
6865 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:226866 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:596867 // + root
6868 // + scroll_child
6869 // + scroll_parent_border
6870 // + scroll_parent_clip
6871 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026872 // + render_surface2
[email protected]995708c52013-10-17 20:52:596873 // + scroll_grandparent_border
6874 // + scroll_grandparent_clip
6875 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:026876 // + render_surface1
[email protected]995708c52013-10-17 20:52:596877 //
enne03b0e9a2015-06-19 00:08:026878 LayerImpl* root = root_layer();
6879 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596880
enne03b0e9a2015-06-19 00:08:026881 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6882 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596883
enne03b0e9a2015-06-19 00:08:026884 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6885 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6886 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6887 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
6888 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6889 LayerImpl* scroll_grandparent_clip =
6890 AddChild<LayerImpl>(scroll_grandparent_border);
6891 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6892 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:596893
enne03b0e9a2015-06-19 00:08:026894 scroll_parent->SetDrawsContent(true);
6895 render_surface1->SetDrawsContent(true);
6896 scroll_grandparent->SetDrawsContent(true);
6897 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596898
6899 scroll_parent_clip->SetMasksToBounds(true);
6900 scroll_grandparent_clip->SetMasksToBounds(true);
6901
enne03b0e9a2015-06-19 00:08:026902 scroll_child->SetScrollParent(scroll_parent);
ajuma9af2e92b2015-06-29 22:26:386903 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6904 scroll_children->insert(scroll_child);
6905 scroll_parent->SetScrollChildren(scroll_children.release());
6906
enne03b0e9a2015-06-19 00:08:026907 scroll_parent_border->SetScrollParent(scroll_grandparent);
ajuma9af2e92b2015-06-29 22:26:386908 scroll_children.reset(new std::set<LayerImpl*>);
6909 scroll_children->insert(scroll_parent_border);
6910 scroll_grandparent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596911
6912 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026913 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6914 gfx::PointF(), gfx::Size(50, 50), true, false,
6915 true);
6916 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6917 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6918 true, false, false);
6919 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6920 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6921 true, false, false);
6922 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6923 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6924 true, false, false);
6925 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6926 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6927 true, false, true);
6928 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6929 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6930 true, false, false);
6931 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6932 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6933 true, false, false);
6934 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6935 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6936 true, false, false);
6937 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6938 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6939 true, false, true);
6940 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6941 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596942 false);
6943
enne03b0e9a2015-06-19 00:08:026944 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596945
6946 EXPECT_TRUE(root->render_surface());
6947
6948 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
6949 scroll_child->clip_rect().ToString());
6950 EXPECT_TRUE(scroll_child->is_clipped());
6951
6952 // Despite the fact that we had to process the layers out of order to get the
6953 // right clip, our render_surface_layer_list's order should be unaffected.
enne03b0e9a2015-06-19 00:08:026954 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6955 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
6956 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
6957 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
6958 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6959 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6960 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:596961}
6962
ajuma0b10f942015-03-21 07:45:536963TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
6964 // Ensures that when we have a render surface between a fixed position layer
6965 // and its container, we compute the fixed position layer's draw transform
6966 // with respect to that intervening render surface, not with respect to its
6967 // container's render target.
6968 //
6969 // + root
6970 // + render_surface
6971 // + fixed
ajuma737b2702015-05-06 01:18:376972 // + child
ajuma0b10f942015-03-21 07:45:536973 //
sunxdfd920f3f2016-04-05 16:17:516974 LayerImpl* root = root_layer();
6975 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6976 LayerImpl* fixed = AddChild<LayerImpl>(render_surface);
6977 LayerImpl* child = AddChild<LayerImpl>(fixed);
ajuma0b10f942015-03-21 07:45:536978
sunxdfd920f3f2016-04-05 16:17:516979 render_surface->SetDrawsContent(true);
6980 fixed->SetDrawsContent(true);
6981 child->SetDrawsContent(true);
ajuma0b10f942015-03-21 07:45:536982
6983 root->SetIsContainerForFixedPositionLayers(true);
6984 render_surface->SetForceRenderSurface(true);
6985
6986 LayerPositionConstraint constraint;
6987 constraint.set_is_fixed_position(true);
6988 fixed->SetPositionConstraint(constraint);
6989
sunxdfd920f3f2016-04-05 16:17:516990 SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(),
ajuma0b10f942015-03-21 07:45:536991 gfx::PointF(), gfx::Size(50, 50), true, false);
sunxdfd920f3f2016-04-05 16:17:516992 SetLayerPropertiesForTesting(render_surface, gfx::Transform(), gfx::Point3F(),
6993 gfx::PointF(7.f, 9.f), gfx::Size(50, 50), true,
6994 false);
6995 SetLayerPropertiesForTesting(fixed, gfx::Transform(), gfx::Point3F(),
ajuma0b10f942015-03-21 07:45:536996 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true,
6997 false);
sunxdfd920f3f2016-04-05 16:17:516998 SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(),
ajuma737b2702015-05-06 01:18:376999 gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true,
7000 false);
ajuma0b10f942015-03-21 07:45:537001
sunxdfd920f3f2016-04-05 16:17:517002 ExecuteCalculateDrawProperties(root);
ajuma0b10f942015-03-21 07:45:537003
sunxdfd920f3f2016-04-05 16:17:517004 TransformTree& tree =
7005 host_impl()->active_tree()->property_trees()->transform_tree;
ennef6903532015-08-18 05:10:157006
ajuma737b2702015-05-06 01:18:377007 gfx::Transform expected_fixed_draw_transform;
7008 expected_fixed_draw_transform.Translate(10.f, 15.f);
ennef6903532015-08-18 05:10:157009 EXPECT_EQ(expected_fixed_draw_transform,
sunxdfd920f3f2016-04-05 16:17:517010 draw_property_utils::DrawTransform(fixed, tree));
ajuma0b10f942015-03-21 07:45:537011
ajuma737b2702015-05-06 01:18:377012 gfx::Transform expected_fixed_screen_space_transform;
7013 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
7014 EXPECT_EQ(expected_fixed_screen_space_transform,
sunxdfd920f3f2016-04-05 16:17:517015 draw_property_utils::ScreenSpaceTransform(fixed, tree));
ajuma737b2702015-05-06 01:18:377016
7017 gfx::Transform expected_child_draw_transform;
7018 expected_child_draw_transform.Translate(11.f, 17.f);
ennef6903532015-08-18 05:10:157019 EXPECT_EQ(expected_child_draw_transform,
sunxdfd920f3f2016-04-05 16:17:517020 draw_property_utils::DrawTransform(child, tree));
ajuma737b2702015-05-06 01:18:377021
7022 gfx::Transform expected_child_screen_space_transform;
7023 expected_child_screen_space_transform.Translate(18.f, 26.f);
7024 EXPECT_EQ(expected_child_screen_space_transform,
sunxdfd920f3f2016-04-05 16:17:517025 draw_property_utils::ScreenSpaceTransform(child, tree));
ajuma0b10f942015-03-21 07:45:537026}
7027
[email protected]d81752b2013-10-25 08:32:237028TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
7029 // This test verifies that a scrolling layer that gets snapped to
7030 // integer coordinates doesn't move a fixed position child.
7031 //
7032 // + root
7033 // + container
7034 // + scroller
7035 // + fixed
7036 //
khushalsagarb64b360d2015-10-21 19:25:167037 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:457038 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567039 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167040 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567041 &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:237042 host_impl.CreatePendingTree();
sunxdb7e79432016-03-09 21:13:427043 scoped_ptr<LayerImpl> root_ptr =
7044 LayerImpl::Create(host_impl.active_tree(), 1);
7045 LayerImpl* root = root_ptr.get();
[email protected]d81752b2013-10-25 08:32:237046 scoped_ptr<LayerImpl> container =
7047 LayerImpl::Create(host_impl.active_tree(), 2);
7048 LayerImpl* container_layer = container.get();
7049 scoped_ptr<LayerImpl> scroller =
7050 LayerImpl::Create(host_impl.active_tree(), 3);
7051 LayerImpl* scroll_layer = scroller.get();
7052 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7053 LayerImpl* fixed_layer = fixed.get();
7054
7055 container->SetIsContainerForFixedPositionLayers(true);
7056
7057 LayerPositionConstraint constraint;
7058 constraint.set_is_fixed_position(true);
7059 fixed->SetPositionConstraint(constraint);
7060
[email protected]adeda572014-01-31 00:49:477061 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:237062
7063 gfx::Transform identity_transform;
7064 gfx::Transform container_transform;
7065 container_transform.Translate3d(10.0, 20.0, 0.0);
7066 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7067
sunxdb7e79432016-03-09 21:13:427068 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
awoloszyne83f28c2014-12-22 15:40:007069 gfx::PointF(), gfx::Size(50, 50), true, false,
7070 true);
7071 SetLayerPropertiesForTesting(container.get(), container_transform,
7072 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7073 true, false, false);
7074 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7075 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7076 true, false, false);
7077 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7078 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]d81752b2013-10-25 08:32:237079 false);
7080
jaydasika0d98ba92015-11-17 05:17:287081 root->SetDrawsContent(true);
7082 container->SetDrawsContent(true);
7083 scroller->SetDrawsContent(true);
7084 fixed->SetDrawsContent(true);
danakja04855a2015-11-18 20:39:107085 scroller->AddChild(std::move(fixed));
7086 container->AddChild(std::move(scroller));
7087 root->AddChild(std::move(container));
[email protected]d81752b2013-10-25 08:32:237088
7089 // Rounded to integers already.
7090 {
sunxdb7e79432016-03-09 21:13:427091 root->layer_tree_impl()->SetRootLayer(std::move(root_ptr));
7092 root->layer_tree_impl()->BuildPropertyTreesForTesting();
7093
[email protected]d81752b2013-10-25 08:32:237094 gfx::Vector2dF scroll_delta(3.0, 5.0);
sunxdb7e79432016-03-09 21:13:427095 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:237096
7097 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:447098 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]d81752b2013-10-25 08:32:237099 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
sunxdb7e79432016-03-09 21:13:427100 root, root->bounds(), &render_surface_layer_list,
ajumad9432e32015-11-30 19:43:447101 root->layer_tree_impl()->current_render_surface_list_id());
sunxdb7e79432016-03-09 21:13:427102 root->layer_tree_impl()
7103 ->property_trees()
7104 ->transform_tree.set_source_to_parent_updates_allowed(false);
[email protected]d81752b2013-10-25 08:32:237105 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7106
7107 EXPECT_TRANSFORMATION_MATRIX_EQ(
7108 container_layer->draw_properties().screen_space_transform,
7109 fixed_layer->draw_properties().screen_space_transform);
7110 EXPECT_VECTOR_EQ(
7111 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7112 container_offset);
7113 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7114 .screen_space_transform.To2dTranslation(),
7115 container_offset - scroll_delta);
7116 }
7117
7118 // Scroll delta requiring rounding.
7119 {
sunxdb7e79432016-03-09 21:13:427120 root->layer_tree_impl()->BuildPropertyTreesForTesting();
7121
[email protected]d81752b2013-10-25 08:32:237122 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
sunxdb7e79432016-03-09 21:13:427123 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:237124
7125 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
7126
7127 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:447128 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]d81752b2013-10-25 08:32:237129 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
sunxdb7e79432016-03-09 21:13:427130 root, root->bounds(), &render_surface_layer_list,
ajumad9432e32015-11-30 19:43:447131 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]d81752b2013-10-25 08:32:237132 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7133
7134 EXPECT_TRANSFORMATION_MATRIX_EQ(
7135 container_layer->draw_properties().screen_space_transform,
7136 fixed_layer->draw_properties().screen_space_transform);
7137 EXPECT_VECTOR_EQ(
7138 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7139 container_offset);
7140 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7141 .screen_space_transform.To2dTranslation(),
7142 container_offset - rounded_scroll_delta);
7143 }
[email protected]cf15ad7b2014-04-02 03:59:267144
7145 // Scale is applied earlier in the tree.
7146 {
sunxdb7e79432016-03-09 21:13:427147 SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF());
[email protected]cf15ad7b2014-04-02 03:59:267148 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:287149 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
[email protected]cf15ad7b2014-04-02 03:59:267150 container_layer->SetTransform(scaled_container_transform);
jaydasika0d98ba92015-11-17 05:17:287151 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxdb7e79432016-03-09 21:13:427152 root->layer_tree_impl()->BuildPropertyTreesForTesting();
[email protected]cf15ad7b2014-04-02 03:59:267153
7154 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
sunxdb7e79432016-03-09 21:13:427155 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]cf15ad7b2014-04-02 03:59:267156
7157 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:447158 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]cf15ad7b2014-04-02 03:59:267159 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
sunxdb7e79432016-03-09 21:13:427160 root, root->bounds(), &render_surface_layer_list,
ajumad9432e32015-11-30 19:43:447161 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]cf15ad7b2014-04-02 03:59:267162 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7163
7164 EXPECT_TRANSFORMATION_MATRIX_EQ(
7165 container_layer->draw_properties().screen_space_transform,
7166 fixed_layer->draw_properties().screen_space_transform);
7167 EXPECT_VECTOR_EQ(
7168 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7169 container_offset);
7170
7171 container_layer->SetTransform(container_transform);
7172 }
[email protected]d81752b2013-10-25 08:32:237173}
7174
miletus2c78036b2015-01-29 20:52:377175TEST_F(LayerTreeHostCommonTest,
ajuma5e8e40d2015-07-31 01:50:507176 ScrollSnappingWithAnimatedScreenSpaceTransform) {
7177 // This test verifies that a scrolling layer whose screen space transform is
7178 // animating doesn't get snapped to integer coordinates.
7179 //
7180 // + root
7181 // + animated layer
7182 // + surface
7183 // + container
7184 // + scroller
7185 //
7186 LayerImpl* root = root_layer();
7187 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
7188 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
7189 LayerImpl* container = AddChild<LayerImpl>(surface);
7190 LayerImpl* scroller = AddChild<LayerImpl>(container);
7191 scroller->SetScrollClipLayer(container->id());
7192 scroller->SetDrawsContent(true);
7193
7194 gfx::Transform identity_transform;
7195 gfx::Transform start_scale;
7196 start_scale.Scale(1.5f, 1.5f);
7197 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
7198 gfx::PointF(), gfx::Size(50, 50), true, false,
7199 true);
7200 SetLayerPropertiesForTesting(animated_layer, start_scale, gfx::Point3F(),
7201 gfx::PointF(), gfx::Size(50, 50), true, false,
7202 false);
7203 SetLayerPropertiesForTesting(surface, identity_transform, gfx::Point3F(),
7204 gfx::PointF(), gfx::Size(50, 50), true, false,
7205 true);
7206 SetLayerPropertiesForTesting(container, identity_transform, gfx::Point3F(),
7207 gfx::PointF(), gfx::Size(50, 50), true, false,
7208 false);
7209 SetLayerPropertiesForTesting(scroller, identity_transform, gfx::Point3F(),
7210 gfx::PointF(), gfx::Size(100, 100), true, false,
7211 false);
7212
7213 gfx::Transform end_scale;
7214 end_scale.Scale(2.f, 2.f);
7215 TransformOperations start_operations;
7216 start_operations.AppendMatrix(start_scale);
7217 TransformOperations end_operations;
7218 end_operations.AppendMatrix(end_scale);
loyso9556c732016-03-11 07:54:587219 AddAnimatedTransformToLayerWithPlayer(animated_layer->id(), timeline_impl(),
7220 1.0, start_operations, end_operations);
ajuma5e8e40d2015-07-31 01:50:507221 gfx::Vector2dF scroll_delta(5.f, 9.f);
sunxdb7e79432016-03-09 21:13:427222 SetScrollOffsetDelta(scroller, scroll_delta);
ajuma5e8e40d2015-07-31 01:50:507223
7224 ExecuteCalculateDrawProperties(root);
7225
7226 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
7227 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:447228 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:507229}
7230
[email protected]1c3626e2014-04-09 17:49:227231class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7232 public:
7233 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
7234 LayerTreeImpl* tree_impl,
7235 int id) {
7236 return make_scoped_ptr(
7237 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7238 }
7239
dcheng716bedf2014-10-21 09:51:087240 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227241
[email protected]1c3626e2014-04-09 17:49:227242 private:
7243 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7244 int id)
[email protected]a57cb8b12014-06-13 18:15:377245 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227246 SetDrawsContent(true);
7247 }
[email protected]1c3626e2014-04-09 17:49:227248};
7249
7250TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:167251 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]1c3626e2014-04-09 17:49:227252 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567253 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:487254 LayerTreeSettings settings = host()->settings();
ajumab4a846f22015-08-24 19:13:447255 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167256 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7257 &shared_bitmap_manager, &task_graph_runner);
[email protected]1c3626e2014-04-09 17:49:227258 gfx::Transform identity_matrix;
7259 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
7260 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
7261 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
7262 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
7263 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
7264 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
7265 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
7266 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7267
7268 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7269 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7270 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
jaydasika2411692c2016-03-23 01:56:097271 AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get();
[email protected]1c3626e2014-04-09 17:49:227272
danakja04855a2015-11-18 20:39:107273 child->AddChild(std::move(grand_child));
7274 parent->AddChild(std::move(child));
7275 grand_parent->AddChild(std::move(parent));
[email protected]1c3626e2014-04-09 17:49:227276
jaydasika2411692c2016-03-23 01:56:097277 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
awoloszyne83f28c2014-12-22 15:40:007278 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7279 true, false, true);
7280 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7281 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227282 false);
awoloszyne83f28c2014-12-22 15:40:007283 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7284 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227285 false);
awoloszyne83f28c2014-12-22 15:40:007286
7287 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
7288 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227289 false);
7290
sunxd71aea3e2016-04-01 23:48:057291 host_impl.active_tree()->SetRootLayer(std::move(grand_parent));
7292
jaydasika2411692c2016-03-23 01:56:097293 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227294
7295 // No layers have animations.
jaydasika2411692c2016-03-23 01:56:097296 EXPECT_EQ(
7297 0.f,
7298 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377299 EXPECT_EQ(0.f,
7300 parent_raw->draw_properties().maximum_animation_contents_scale);
7301 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7302 EXPECT_EQ(
7303 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227304
jaydasika2411692c2016-03-23 01:56:097305 EXPECT_EQ(
7306 0.f,
7307 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037308 EXPECT_EQ(0.f,
7309 parent_raw->draw_properties().starting_animation_contents_scale);
7310 EXPECT_EQ(0.f,
7311 child_raw->draw_properties().starting_animation_contents_scale);
7312 EXPECT_EQ(
7313 0.f,
7314 grand_child_raw->draw_properties().starting_animation_contents_scale);
7315
[email protected]1c3626e2014-04-09 17:49:227316 TransformOperations translation;
7317 translation.AppendTranslate(1.f, 2.f, 3.f);
7318
loyso968163c92016-01-04 23:18:487319 scoped_refptr<AnimationTimeline> timeline;
loyso9556c732016-03-11 07:54:587320 timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7321 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487322
loyso9556c732016-03-11 07:54:587323 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7324 TransformOperations(), translation);
[email protected]1c3626e2014-04-09 17:49:227325
7326 // No layers have scale-affecting animations.
jaydasika2411692c2016-03-23 01:56:097327 EXPECT_EQ(
7328 0.f,
7329 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377330 EXPECT_EQ(0.f,
7331 parent_raw->draw_properties().maximum_animation_contents_scale);
7332 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7333 EXPECT_EQ(
7334 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227335
jaydasika2411692c2016-03-23 01:56:097336 EXPECT_EQ(
7337 0.f,
7338 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037339 EXPECT_EQ(0.f,
7340 parent_raw->draw_properties().starting_animation_contents_scale);
7341 EXPECT_EQ(0.f,
7342 child_raw->draw_properties().starting_animation_contents_scale);
7343 EXPECT_EQ(
7344 0.f,
7345 grand_child_raw->draw_properties().starting_animation_contents_scale);
7346
[email protected]1c3626e2014-04-09 17:49:227347 TransformOperations scale;
7348 scale.AppendScale(5.f, 4.f, 3.f);
7349
loyso9556c732016-03-11 07:54:587350 AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0,
7351 TransformOperations(), scale);
ajumacaaa9b32015-08-04 15:55:297352 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097353 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227354
7355 // Only |child| has a scale-affecting animation.
jaydasika2411692c2016-03-23 01:56:097356 EXPECT_EQ(
7357 0.f,
7358 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377359 EXPECT_EQ(0.f,
7360 parent_raw->draw_properties().maximum_animation_contents_scale);
7361 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
7362 EXPECT_EQ(
7363 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227364
jaydasika2411692c2016-03-23 01:56:097365 EXPECT_EQ(
7366 0.f,
7367 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037368 EXPECT_EQ(0.f,
7369 parent_raw->draw_properties().starting_animation_contents_scale);
7370 EXPECT_EQ(1.f,
7371 child_raw->draw_properties().starting_animation_contents_scale);
7372 EXPECT_EQ(
7373 1.f,
7374 grand_child_raw->draw_properties().starting_animation_contents_scale);
7375
jaydasika2411692c2016-03-23 01:56:097376 AddAnimatedTransformToLayerWithPlayer(grand_parent_raw->id(), timeline, 1.0,
loyso9556c732016-03-11 07:54:587377 TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:097378 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7379 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227380
7381 // |grand_parent| and |child| have scale-affecting animations.
jaydasika2411692c2016-03-23 01:56:097382 EXPECT_EQ(
7383 5.f,
7384 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377385 EXPECT_EQ(5.f,
7386 parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227387 // We don't support combining animated scales from two nodes; 0.f means
7388 // that the maximum scale could not be computed.
[email protected]a57cb8b12014-06-13 18:15:377389 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7390 EXPECT_EQ(
7391 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227392
jaydasika2411692c2016-03-23 01:56:097393 EXPECT_EQ(
7394 1.f,
7395 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037396 EXPECT_EQ(1.f,
7397 parent_raw->draw_properties().starting_animation_contents_scale);
7398 EXPECT_EQ(0.f,
7399 child_raw->draw_properties().starting_animation_contents_scale);
7400 EXPECT_EQ(
7401 0.f,
7402 grand_child_raw->draw_properties().starting_animation_contents_scale);
7403
loyso9556c732016-03-11 07:54:587404 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7405 TransformOperations(), scale);
ajumacaaa9b32015-08-04 15:55:297406 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097407 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227408
7409 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
jaydasika2411692c2016-03-23 01:56:097410 EXPECT_EQ(
7411 5.f,
7412 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377413 EXPECT_EQ(0.f,
7414 parent_raw->draw_properties().maximum_animation_contents_scale);
7415 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7416 EXPECT_EQ(
7417 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227418
jaydasika2411692c2016-03-23 01:56:097419 EXPECT_EQ(
7420 1.f,
7421 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037422 EXPECT_EQ(0.f,
7423 parent_raw->draw_properties().starting_animation_contents_scale);
7424 EXPECT_EQ(0.f,
7425 child_raw->draw_properties().starting_animation_contents_scale);
7426 EXPECT_EQ(
7427 0.f,
7428 grand_child_raw->draw_properties().starting_animation_contents_scale);
7429
jaydasika2411692c2016-03-23 01:56:097430 AbortAnimationsOnLayerWithPlayer(grand_parent_raw->id(), timeline,
loyso9556c732016-03-11 07:54:587431 TargetProperty::TRANSFORM);
7432 AbortAnimationsOnLayerWithPlayer(parent_raw->id(), timeline,
7433 TargetProperty::TRANSFORM);
7434 AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline,
7435 TargetProperty::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227436
7437 TransformOperations perspective;
7438 perspective.AppendPerspective(10.f);
7439
loyso9556c732016-03-11 07:54:587440 AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0,
7441 TransformOperations(), perspective);
ajumab4a846f22015-08-24 19:13:447442 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097443 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227444
7445 // |child| has a scale-affecting animation but computing the maximum of this
7446 // animation is not supported.
jaydasika2411692c2016-03-23 01:56:097447 EXPECT_EQ(
7448 0.f,
7449 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377450 EXPECT_EQ(0.f,
7451 parent_raw->draw_properties().maximum_animation_contents_scale);
7452 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7453 EXPECT_EQ(
7454 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227455
jaydasika2411692c2016-03-23 01:56:097456 EXPECT_EQ(
7457 0.f,
7458 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037459 EXPECT_EQ(0.f,
7460 parent_raw->draw_properties().starting_animation_contents_scale);
7461 EXPECT_EQ(0.f,
7462 child_raw->draw_properties().starting_animation_contents_scale);
7463 EXPECT_EQ(
7464 0.f,
7465 grand_child_raw->draw_properties().starting_animation_contents_scale);
7466
loyso9556c732016-03-11 07:54:587467 AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline,
7468 TargetProperty::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227469 gfx::Transform scale_matrix;
7470 scale_matrix.Scale(1.f, 2.f);
jaydasika2411692c2016-03-23 01:56:097471 grand_parent_raw->SetTransform(scale_matrix);
[email protected]1c3626e2014-04-09 17:49:227472 parent_raw->SetTransform(scale_matrix);
jaydasika2411692c2016-03-23 01:56:097473 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:487474
loyso9556c732016-03-11 07:54:587475 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7476 TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:097477 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227478
7479 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7480 // animation with maximum scale 5.f.
jaydasika2411692c2016-03-23 01:56:097481 EXPECT_EQ(
7482 0.f,
7483 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377484 EXPECT_EQ(10.f,
7485 parent_raw->draw_properties().maximum_animation_contents_scale);
7486 EXPECT_EQ(10.f,
7487 child_raw->draw_properties().maximum_animation_contents_scale);
7488 EXPECT_EQ(
7489 10.f,
7490 grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227491
jaydasika2411692c2016-03-23 01:56:097492 EXPECT_EQ(
7493 0.f,
7494 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037495 EXPECT_EQ(2.f,
7496 parent_raw->draw_properties().starting_animation_contents_scale);
7497 EXPECT_EQ(2.f,
7498 child_raw->draw_properties().starting_animation_contents_scale);
7499 EXPECT_EQ(
7500 2.f,
7501 grand_child_raw->draw_properties().starting_animation_contents_scale);
7502
[email protected]1c3626e2014-04-09 17:49:227503 gfx::Transform perspective_matrix;
7504 perspective_matrix.ApplyPerspectiveDepth(2.f);
7505 child_raw->SetTransform(perspective_matrix);
jaydasika2411692c2016-03-23 01:56:097506 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7507 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227508
7509 // |child| has a transform that's neither a translation nor a scale.
jaydasika2411692c2016-03-23 01:56:097510 EXPECT_EQ(
7511 0.f,
7512 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377513 EXPECT_EQ(10.f,
7514 parent_raw->draw_properties().maximum_animation_contents_scale);
7515 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7516 EXPECT_EQ(
7517 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227518
jaydasika2411692c2016-03-23 01:56:097519 EXPECT_EQ(
7520 0.f,
7521 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037522 EXPECT_EQ(2.f,
7523 parent_raw->draw_properties().starting_animation_contents_scale);
7524 EXPECT_EQ(0.f,
7525 child_raw->draw_properties().starting_animation_contents_scale);
7526 EXPECT_EQ(
7527 0.f,
7528 grand_child_raw->draw_properties().starting_animation_contents_scale);
7529
[email protected]1c3626e2014-04-09 17:49:227530 parent_raw->SetTransform(perspective_matrix);
jaydasika2411692c2016-03-23 01:56:097531 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7532 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227533
7534 // |parent| and |child| have transforms that are neither translations nor
7535 // scales.
jaydasika2411692c2016-03-23 01:56:097536 EXPECT_EQ(
7537 0.f,
7538 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377539 EXPECT_EQ(0.f,
7540 parent_raw->draw_properties().maximum_animation_contents_scale);
7541 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7542 EXPECT_EQ(
7543 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227544
jaydasika2411692c2016-03-23 01:56:097545 EXPECT_EQ(
7546 0.f,
7547 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037548 EXPECT_EQ(0.f,
7549 parent_raw->draw_properties().starting_animation_contents_scale);
7550 EXPECT_EQ(0.f,
7551 child_raw->draw_properties().starting_animation_contents_scale);
7552 EXPECT_EQ(
7553 0.f,
7554 grand_child_raw->draw_properties().starting_animation_contents_scale);
7555
[email protected]1c3626e2014-04-09 17:49:227556 parent_raw->SetTransform(identity_matrix);
7557 child_raw->SetTransform(identity_matrix);
jaydasika2411692c2016-03-23 01:56:097558 grand_parent_raw->SetTransform(perspective_matrix);
7559 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227560
jaydasika2411692c2016-03-23 01:56:097561 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227562
7563 // |grand_parent| has a transform that's neither a translation nor a scale.
jaydasika2411692c2016-03-23 01:56:097564 EXPECT_EQ(
7565 0.f,
7566 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377567 EXPECT_EQ(0.f,
7568 parent_raw->draw_properties().maximum_animation_contents_scale);
7569 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7570 EXPECT_EQ(
7571 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037572
jaydasika2411692c2016-03-23 01:56:097573 EXPECT_EQ(
7574 0.f,
7575 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037576 EXPECT_EQ(0.f,
7577 parent_raw->draw_properties().starting_animation_contents_scale);
7578 EXPECT_EQ(0.f,
7579 child_raw->draw_properties().starting_animation_contents_scale);
7580 EXPECT_EQ(
7581 0.f,
7582 grand_child_raw->draw_properties().starting_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227583}
7584
[email protected]390bb1ff2014-05-09 17:14:407585static int membership_id(LayerImpl* layer) {
7586 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
7587}
7588
7589static void GatherDrawnLayers(LayerImplList* rsll,
7590 std::set<LayerImpl*>* drawn_layers) {
enne389d1a12015-06-18 20:40:517591 for (LayerIterator it = LayerIterator::Begin(rsll),
7592 end = LayerIterator::End(rsll);
7593 it != end; ++it) {
[email protected]390bb1ff2014-05-09 17:14:407594 LayerImpl* layer = *it;
7595 if (it.represents_itself())
7596 drawn_layers->insert(layer);
7597
7598 if (!it.represents_contributing_render_surface())
7599 continue;
7600
7601 if (layer->mask_layer())
7602 drawn_layers->insert(layer->mask_layer());
7603 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
7604 drawn_layers->insert(layer->replica_layer()->mask_layer());
7605 }
7606}
7607
7608TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:167609 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]390bb1ff2014-05-09 17:14:407610 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567611 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167612 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567613 &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:407614 gfx::Transform identity_matrix;
7615
7616 scoped_ptr<LayerImpl> grand_parent =
7617 LayerImpl::Create(host_impl.active_tree(), 1);
7618 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
7619 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
7620 scoped_ptr<LayerImpl> grand_child1 =
7621 LayerImpl::Create(host_impl.active_tree(), 7);
7622 scoped_ptr<LayerImpl> grand_child2 =
7623 LayerImpl::Create(host_impl.active_tree(), 9);
7624
7625 LayerImpl* grand_parent_raw = grand_parent.get();
7626 LayerImpl* parent_raw = parent.get();
7627 LayerImpl* child_raw = child.get();
7628 LayerImpl* grand_child1_raw = grand_child1.get();
7629 LayerImpl* grand_child2_raw = grand_child2.get();
7630
danakja04855a2015-11-18 20:39:107631 child->AddChild(std::move(grand_child1));
7632 child->AddChild(std::move(grand_child2));
7633 parent->AddChild(std::move(child));
7634 grand_parent->AddChild(std::move(parent));
jaydasika2411692c2016-03-23 01:56:097635 host_impl.active_tree()->SetRootLayer(std::move(grand_parent));
[email protected]390bb1ff2014-05-09 17:14:407636
awoloszyne83f28c2014-12-22 15:40:007637 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
7638 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7639 true, false, true);
7640 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7641 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:407642 false);
awoloszyne83f28c2014-12-22 15:40:007643
7644 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7645 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:407646 false);
awoloszyne83f28c2014-12-22 15:40:007647
7648 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
7649 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7650 true, false, false);
7651
7652 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
7653 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7654 true, false, false);
[email protected]390bb1ff2014-05-09 17:14:407655
7656 // Start with nothing being drawn.
7657 ExecuteCalculateDrawProperties(grand_parent_raw);
7658 int member_id = render_surface_layer_list_count();
7659
7660 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7661 EXPECT_NE(member_id, membership_id(parent_raw));
7662 EXPECT_NE(member_id, membership_id(child_raw));
7663 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7664 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7665
7666 std::set<LayerImpl*> expected;
7667 std::set<LayerImpl*> actual;
7668 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7669 EXPECT_EQ(expected, actual);
7670
7671 // If we force render surface, but none of the layers are in the layer list,
7672 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:007673 grand_child1_raw->SetHasRenderSurface(true);
jaydasikaebf9e4ea2015-08-14 21:29:127674 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407675
7676 ExecuteCalculateDrawProperties(grand_parent_raw);
7677 member_id = render_surface_layer_list_count();
7678
7679 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7680 EXPECT_NE(member_id, membership_id(parent_raw));
7681 EXPECT_NE(member_id, membership_id(child_raw));
7682 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7683 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7684
7685 expected.clear();
7686 actual.clear();
7687 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7688 EXPECT_EQ(expected, actual);
7689
7690 // However, if we say that this layer also draws content, it will appear in
7691 // RSLL.
7692 grand_child1_raw->SetDrawsContent(true);
7693
7694 ExecuteCalculateDrawProperties(grand_parent_raw);
7695 member_id = render_surface_layer_list_count();
7696
7697 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7698 EXPECT_NE(member_id, membership_id(parent_raw));
7699 EXPECT_NE(member_id, membership_id(child_raw));
7700 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
7701 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7702
7703 expected.clear();
7704 expected.insert(grand_child1_raw);
7705
7706 actual.clear();
7707 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7708 EXPECT_EQ(expected, actual);
7709
7710 // Now child is forced to have a render surface, and one if its children draws
7711 // content.
7712 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:007713 grand_child1_raw->SetHasRenderSurface(false);
jaydasikaebf9e4ea2015-08-14 21:29:127714 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
awoloszyne83f28c2014-12-22 15:40:007715 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:407716 grand_child2_raw->SetDrawsContent(true);
7717
7718 ExecuteCalculateDrawProperties(grand_parent_raw);
7719 member_id = render_surface_layer_list_count();
7720
7721 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7722 EXPECT_NE(member_id, membership_id(parent_raw));
7723 EXPECT_NE(member_id, membership_id(child_raw));
7724 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7725 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7726
7727 expected.clear();
7728 expected.insert(grand_child2_raw);
7729
7730 actual.clear();
7731 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7732 EXPECT_EQ(expected, actual);
7733
7734 // Add a mask layer to child.
danakja5a05ba02015-11-20 20:14:217735 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:047736 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407737
7738 ExecuteCalculateDrawProperties(grand_parent_raw);
7739 member_id = render_surface_layer_list_count();
7740
7741 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7742 EXPECT_NE(member_id, membership_id(parent_raw));
7743 EXPECT_NE(member_id, membership_id(child_raw));
7744 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7745 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7746 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7747
7748 expected.clear();
7749 expected.insert(grand_child2_raw);
7750 expected.insert(child_raw->mask_layer());
7751
7752 expected.clear();
7753 expected.insert(grand_child2_raw);
7754 expected.insert(child_raw->mask_layer());
7755
7756 actual.clear();
7757 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7758 EXPECT_EQ(expected, actual);
7759
7760 // Add replica mask layer.
7761 scoped_ptr<LayerImpl> replica_layer =
7762 LayerImpl::Create(host_impl.active_tree(), 20);
7763 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
danakja04855a2015-11-18 20:39:107764 child_raw->SetReplicaLayer(std::move(replica_layer));
jaydasika23fb3822015-08-25 03:22:597765 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407766
7767 ExecuteCalculateDrawProperties(grand_parent_raw);
7768 member_id = render_surface_layer_list_count();
7769
7770 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7771 EXPECT_NE(member_id, membership_id(parent_raw));
7772 EXPECT_NE(member_id, membership_id(child_raw));
7773 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7774 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
7775 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7776 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7777
7778 expected.clear();
7779 expected.insert(grand_child2_raw);
7780 expected.insert(child_raw->mask_layer());
7781 expected.insert(child_raw->replica_layer()->mask_layer());
7782
7783 actual.clear();
7784 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7785 EXPECT_EQ(expected, actual);
7786
7787 child_raw->TakeReplicaLayer();
7788
7789 // With nothing drawing, we should have no layers.
7790 grand_child2_raw->SetDrawsContent(false);
7791
7792 ExecuteCalculateDrawProperties(grand_parent_raw);
7793 member_id = render_surface_layer_list_count();
7794
7795 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7796 EXPECT_NE(member_id, membership_id(parent_raw));
7797 EXPECT_NE(member_id, membership_id(child_raw));
7798 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
7799 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7800 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7801
7802 expected.clear();
7803 actual.clear();
7804 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7805 EXPECT_EQ(expected, actual);
7806
7807 // Child itself draws means that we should have the child and the mask in the
7808 // list.
7809 child_raw->SetDrawsContent(true);
7810
7811 ExecuteCalculateDrawProperties(grand_parent_raw);
7812 member_id = render_surface_layer_list_count();
7813
7814 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7815 EXPECT_NE(member_id, membership_id(parent_raw));
7816 EXPECT_EQ(member_id, membership_id(child_raw));
7817 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7818 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7819 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7820
7821 expected.clear();
7822 expected.insert(child_raw);
7823 expected.insert(child_raw->mask_layer());
7824 actual.clear();
7825 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7826 EXPECT_EQ(expected, actual);
7827
7828 child_raw->TakeMaskLayer();
jaydasikad36e7fa2015-07-14 15:15:047829 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407830
7831 // Now everyone's a member!
7832 grand_parent_raw->SetDrawsContent(true);
7833 parent_raw->SetDrawsContent(true);
7834 child_raw->SetDrawsContent(true);
7835 grand_child1_raw->SetDrawsContent(true);
7836 grand_child2_raw->SetDrawsContent(true);
7837
7838 ExecuteCalculateDrawProperties(grand_parent_raw);
7839 member_id = render_surface_layer_list_count();
7840
7841 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
7842 EXPECT_EQ(member_id, membership_id(parent_raw));
7843 EXPECT_EQ(member_id, membership_id(child_raw));
7844 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
7845 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7846
7847 expected.clear();
7848 expected.insert(grand_parent_raw);
7849 expected.insert(parent_raw);
7850 expected.insert(child_raw);
7851 expected.insert(grand_child1_raw);
7852 expected.insert(grand_child2_raw);
7853
7854 actual.clear();
7855 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7856 EXPECT_EQ(expected, actual);
7857}
[email protected]18e69652014-06-13 12:50:587858
7859TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:167860 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]18e69652014-06-13 12:50:587861 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567862 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:487863 LayerTreeSettings settings = host()->settings();
enne637715732015-07-07 02:05:267864 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167865 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7866 &shared_bitmap_manager, &task_graph_runner);
[email protected]18e69652014-06-13 12:50:587867
7868 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7869 LayerImpl* root_layer = root.get();
7870 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
7871 LayerImpl* child1_layer = child1.get();
7872 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
7873 LayerImpl* child2_layer = child2.get();
7874
danakja04855a2015-11-18 20:39:107875 root->AddChild(std::move(child1));
7876 root->AddChild(std::move(child2));
weiliangcc154ce22015-12-09 03:39:267877 root->SetForceRenderSurface(true);
jaydasika0d98ba92015-11-17 05:17:287878 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:097879 host_impl.active_tree()->SetRootLayer(std::move(root));
[email protected]18e69652014-06-13 12:50:587880
7881 gfx::Transform identity_matrix, scale_transform_child1,
7882 scale_transform_child2;
7883 scale_transform_child1.Scale(2, 3);
7884 scale_transform_child2.Scale(4, 5);
7885
awoloszyne83f28c2014-12-22 15:40:007886 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
7887 gfx::PointF(), gfx::Size(1, 1), true, false,
7888 true);
7889 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
jaydasika0d98ba92015-11-17 05:17:287890 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1),
7891 true, false, false);
[email protected]18e69652014-06-13 12:50:587892
danakja5a05ba02015-11-20 20:14:217893 child1_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4));
jaydasika0d98ba92015-11-17 05:17:287894 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587895
7896 scoped_ptr<LayerImpl> replica_layer =
7897 LayerImpl::Create(host_impl.active_tree(), 5);
7898 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
danakja04855a2015-11-18 20:39:107899 child1_layer->SetReplicaLayer(std::move(replica_layer));
awoloszyne83f28c2014-12-22 15:40:007900 child1_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:587901
7902 ExecuteCalculateDrawProperties(root_layer);
7903
7904 TransformOperations scale;
7905 scale.AppendScale(5.f, 8.f, 3.f);
7906
loyso9556c732016-03-11 07:54:587907 scoped_refptr<AnimationTimeline> timeline =
7908 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7909 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487910
loyso9556c732016-03-11 07:54:587911 AddAnimatedTransformToLayerWithPlayer(child2_layer->id(), timeline, 1.0,
7912 TransformOperations(), scale);
loyso968163c92016-01-04 23:18:487913
awoloszyne83f28c2014-12-22 15:40:007914 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
jaydasika0d98ba92015-11-17 05:17:287915 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1),
7916 true, false, false);
7917 child2_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587918
jaydasika2411692c2016-03-23 01:56:097919 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:587920 ExecuteCalculateDrawProperties(root_layer);
7921
enne637715732015-07-07 02:05:267922 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
7923 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
7924 EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale());
7925 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587926
7927 EXPECT_FLOAT_EQ(
7928 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7929 EXPECT_FLOAT_EQ(
7930 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7931 EXPECT_FLOAT_EQ(0.f,
7932 child1_layer->mask_layer()
7933 ->draw_properties()
7934 .maximum_animation_contents_scale);
7935 EXPECT_FLOAT_EQ(0.f,
7936 child1_layer->replica_layer()
7937 ->mask_layer()
7938 ->draw_properties()
7939 .maximum_animation_contents_scale);
7940 EXPECT_FLOAT_EQ(
7941 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
7942
[email protected]18e69652014-06-13 12:50:587943 // Changing page-scale would affect ideal_contents_scale and
7944 // maximum_animation_contents_scale.
7945
7946 float page_scale_factor = 3.f;
7947 float device_scale_factor = 1.0f;
7948 std::vector<LayerImpl*> render_surface_layer_list;
7949 gfx::Size device_viewport_size =
7950 gfx::Size(root_layer->bounds().width() * device_scale_factor,
7951 root_layer->bounds().height() * device_scale_factor);
ajumad9432e32015-11-30 19:43:447952 root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]18e69652014-06-13 12:50:587953 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:447954 root_layer, device_viewport_size, &render_surface_layer_list,
7955 root_layer->layer_tree_impl()->current_render_surface_list_id());
[email protected]18e69652014-06-13 12:50:587956
7957 inputs.page_scale_factor = page_scale_factor;
7958 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:117959 inputs.page_scale_layer = root_layer;
[email protected]18e69652014-06-13 12:50:587960 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7961
enne637715732015-07-07 02:05:267962 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
7963 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
7964 EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587965 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267966 9.f,
7967 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
7968 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587969
7970 EXPECT_FLOAT_EQ(
7971 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7972 EXPECT_FLOAT_EQ(
7973 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7974 EXPECT_FLOAT_EQ(0.f,
7975 child1_layer->mask_layer()
7976 ->draw_properties()
7977 .maximum_animation_contents_scale);
7978 EXPECT_FLOAT_EQ(0.f,
7979 child1_layer->replica_layer()
7980 ->mask_layer()
7981 ->draw_properties()
7982 .maximum_animation_contents_scale);
7983 EXPECT_FLOAT_EQ(
7984 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
7985
[email protected]18e69652014-06-13 12:50:587986 // Changing device-scale would affect ideal_contents_scale and
7987 // maximum_animation_contents_scale.
7988
7989 device_scale_factor = 4.0f;
7990 inputs.device_scale_factor = device_scale_factor;
7991 inputs.can_adjust_raster_scales = true;
jaydasika2411692c2016-03-23 01:56:097992 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:587993 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7994
enne637715732015-07-07 02:05:267995 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
7996 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
7997 EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587998 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267999 36.f,
8000 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
8001 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:588002
8003 EXPECT_FLOAT_EQ(
8004 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8005 EXPECT_FLOAT_EQ(
8006 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8007 EXPECT_FLOAT_EQ(0.f,
8008 child1_layer->mask_layer()
8009 ->draw_properties()
8010 .maximum_animation_contents_scale);
8011 EXPECT_FLOAT_EQ(0.f,
8012 child1_layer->replica_layer()
8013 ->mask_layer()
8014 ->draw_properties()
8015 .maximum_animation_contents_scale);
8016 EXPECT_FLOAT_EQ(
8017 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
[email protected]18e69652014-06-13 12:50:588018}
8019
danakjf6069db2014-09-13 00:46:478020TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
loyso0940d412016-03-14 01:30:318021 scoped_refptr<Layer> root = Layer::Create();
danakjf6069db2014-09-13 00:46:478022 SetLayerPropertiesForTesting(root.get(),
8023 gfx::Transform(),
8024 gfx::Point3F(),
8025 gfx::PointF(),
8026 gfx::Size(768 / 2, 3000),
8027 true,
8028 false);
8029 root->SetIsDrawable(true);
8030
loyso0940d412016-03-14 01:30:318031 scoped_refptr<Layer> clip = Layer::Create();
danakjf6069db2014-09-13 00:46:478032 SetLayerPropertiesForTesting(clip.get(),
8033 gfx::Transform(),
8034 gfx::Point3F(),
8035 gfx::PointF(),
8036 gfx::Size(768 / 2, 10000),
8037 true,
8038 false);
8039 clip->SetMasksToBounds(true);
8040
loyso0940d412016-03-14 01:30:318041 scoped_refptr<Layer> content = Layer::Create();
danakjf6069db2014-09-13 00:46:478042 SetLayerPropertiesForTesting(content.get(),
8043 gfx::Transform(),
8044 gfx::Point3F(),
8045 gfx::PointF(),
8046 gfx::Size(768 / 2, 10000),
8047 true,
8048 false);
8049 content->SetIsDrawable(true);
8050 content->SetForceRenderSurface(true);
8051
8052 root->AddChild(clip);
8053 clip->AddChild(content);
8054
ennea7b43c32015-06-18 20:01:338055 host()->SetRootLayer(root);
danakjf6069db2014-09-13 00:46:478056
8057 gfx::Size device_viewport_size(768, 582);
jaydasika6b7c69d2016-04-01 00:54:438058 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8059 host()->root_layer(), device_viewport_size);
danakjf6069db2014-09-13 00:46:478060 inputs.device_scale_factor = 2.f;
8061 inputs.page_scale_factor = 1.f;
enne6394d5b42015-05-26 22:23:118062 inputs.page_scale_layer = NULL;
jaydasika6b7c69d2016-04-01 00:54:438063 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakjf6069db2014-09-13 00:46:478064
8065 // Layers in the root render surface have their visible content rect clipped
8066 // by the viewport.
jaydasika74bf516f2016-04-01 19:48:158067 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
8068 root->visible_layer_rect_for_testing());
danakjf6069db2014-09-13 00:46:478069
8070 // Layers drawing to a child render surface should still have their visible
8071 // content rect clipped by the viewport.
jaydasika74bf516f2016-04-01 19:48:158072 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
8073 content->visible_layer_rect_for_testing());
danakjf6069db2014-09-13 00:46:478074}
8075
timav599f4359d2014-12-05 00:12:228076TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:168077 FakeImplTaskRunnerProvider task_runner_provider;
timav599f4359d2014-12-05 00:12:228078 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:568079 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:168080 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:568081 &task_graph_runner);
timav599f4359d2014-12-05 00:12:228082
8083 // Set two layers: the root layer clips it's child,
8084 // the child draws its content.
8085
8086 gfx::Size root_size = gfx::Size(300, 500);
8087
8088 // Sublayer should be bigger than the root enlarged by bounds_delta.
8089 gfx::Size sublayer_size = gfx::Size(300, 1000);
8090
8091 // Device viewport accomidated the root and the top controls.
8092 gfx::Size device_viewport_size = gfx::Size(300, 600);
8093 gfx::Transform identity_matrix;
8094
miletus8bd08a622015-06-16 18:44:528095 host_impl.SetViewportSize(device_viewport_size);
timav599f4359d2014-12-05 00:12:228096 host_impl.active_tree()->SetRootLayer(
8097 LayerImpl::Create(host_impl.active_tree(), 1));
8098
8099 LayerImpl* root = host_impl.active_tree()->root_layer();
8100 SetLayerPropertiesForTesting(root,
8101 identity_matrix,
8102 gfx::Point3F(),
8103 gfx::PointF(),
8104 root_size,
8105 false,
awoloszyne83f28c2014-12-22 15:40:008106 false,
8107 true);
timav599f4359d2014-12-05 00:12:228108 root->SetMasksToBounds(true);
8109
8110 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
8111
8112 LayerImpl* sublayer = root->child_at(0);
8113 SetLayerPropertiesForTesting(sublayer,
8114 identity_matrix,
8115 gfx::Point3F(),
8116 gfx::PointF(),
8117 sublayer_size,
8118 false,
awoloszyne83f28c2014-12-22 15:40:008119 false,
timav599f4359d2014-12-05 00:12:228120 false);
timav599f4359d2014-12-05 00:12:228121 sublayer->SetDrawsContent(true);
8122
8123 LayerImplList layer_impl_list;
ajumad9432e32015-11-30 19:43:448124 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
timav599f4359d2014-12-05 00:12:228125 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:448126 root, device_viewport_size, &layer_impl_list,
8127 root->layer_tree_impl()->current_render_surface_list_id());
timav599f4359d2014-12-05 00:12:228128
8129 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
danakj64767d902015-06-19 00:10:438130 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228131
8132 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
timav599f4359d2014-12-05 00:12:228133 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8134
8135 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8136 root_size.height() + 50);
danakj64767d902015-06-19 00:10:438137 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228138}
8139
ajumadd2802e72015-06-30 20:28:298140TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
loyso0940d412016-03-14 01:30:318141 scoped_refptr<Layer> root = Layer::Create();
8142 scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create();
8143 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create();
8144 scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create();
8145 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298146
8147 root->AddChild(inner_viewport_container_layer);
8148 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
8149 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
8150 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
8151
8152 inner_viewport_scroll_layer->SetScrollClipLayerId(
8153 inner_viewport_container_layer->id());
8154 outer_viewport_scroll_layer->SetScrollClipLayerId(
8155 outer_viewport_container_layer->id());
8156
8157 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8158 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8159
8160 host()->SetRootLayer(root);
8161 host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer,
8162 outer_viewport_scroll_layer);
8163
loyso0940d412016-03-14 01:30:318164 scoped_refptr<Layer> fixed_to_inner = Layer::Create();
8165 scoped_refptr<Layer> fixed_to_outer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298166
8167 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
8168 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
8169
8170 LayerPositionConstraint fixed_to_right;
8171 fixed_to_right.set_is_fixed_position(true);
8172 fixed_to_right.set_is_fixed_to_right_edge(true);
8173
8174 fixed_to_inner->SetPositionConstraint(fixed_to_right);
8175 fixed_to_outer->SetPositionConstraint(fixed_to_right);
8176
8177 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8178
8179 TransformTree& transform_tree = host()->property_trees()->transform_tree;
8180 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8181 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8182
8183 LayerPositionConstraint fixed_to_left;
8184 fixed_to_left.set_is_fixed_position(true);
8185 fixed_to_inner->SetPositionConstraint(fixed_to_left);
8186
8187 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8188 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8189 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8190
8191 fixed_to_outer->SetPositionConstraint(fixed_to_left);
8192
8193 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8194 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8195 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8196}
8197
vollick7d83b452015-02-24 20:18:068198TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
8199 const gfx::Transform identity_matrix;
loyso0940d412016-03-14 01:30:318200 scoped_refptr<Layer> root = Layer::Create();
vollick7d83b452015-02-24 20:18:068201 scoped_refptr<LayerWithForcedDrawsContent> animated =
loyso0940d412016-03-14 01:30:318202 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick7d83b452015-02-24 20:18:068203
8204 root->AddChild(animated);
8205
ennea7b43c32015-06-18 20:01:338206 host()->SetRootLayer(root);
vollick7d83b452015-02-24 20:18:068207
8208 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8209 gfx::PointF(), gfx::Size(100, 100), true, false);
8210 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
8211 gfx::PointF(), gfx::Size(20, 20), true, false);
8212
8213 root->SetMasksToBounds(true);
8214 root->SetForceRenderSurface(true);
8215 animated->SetOpacity(0.f);
8216
loyso9556c732016-03-11 07:54:588217 AddOpacityTransitionToLayerWithPlayer(animated->id(), timeline(), 10.0, 0.f,
8218 1.f, false);
enne601f2ef12015-05-19 18:20:178219 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick7d83b452015-02-24 20:18:068220
jaydasika74bf516f2016-04-01 19:48:158221 EXPECT_FALSE(animated->visible_layer_rect_for_testing().IsEmpty());
vollick7d83b452015-02-24 20:18:068222}
8223
ajumaa92fdc12015-03-31 22:47:418224TEST_F(LayerTreeHostCommonTest,
8225 VisibleContentRectForAnimatedLayerWithSingularTransform) {
8226 const gfx::Transform identity_matrix;
loyso0940d412016-03-14 01:30:318227 scoped_refptr<Layer> root = Layer::Create();
8228 scoped_refptr<Layer> clip = Layer::Create();
ajumaa92fdc12015-03-31 22:47:418229 scoped_refptr<LayerWithForcedDrawsContent> animated =
loyso0940d412016-03-14 01:30:318230 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaa92fdc12015-03-31 22:47:418231 scoped_refptr<LayerWithForcedDrawsContent> surface =
loyso0940d412016-03-14 01:30:318232 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaa92fdc12015-03-31 22:47:418233 scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation =
loyso0940d412016-03-14 01:30:318234 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaa92fdc12015-03-31 22:47:418235
8236 root->AddChild(clip);
8237 clip->AddChild(animated);
8238 animated->AddChild(surface);
8239 surface->AddChild(descendant_of_animation);
8240
8241 clip->SetMasksToBounds(true);
8242 surface->SetForceRenderSurface(true);
8243
ennea7b43c32015-06-18 20:01:338244 host()->SetRootLayer(root);
ajumaa92fdc12015-03-31 22:47:418245
8246 gfx::Transform uninvertible_matrix;
8247 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
8248
8249 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8250 gfx::PointF(), gfx::Size(100, 100), true, false);
8251 SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(),
8252 gfx::PointF(), gfx::Size(10, 10), true, false);
8253 SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix,
8254 gfx::Point3F(), gfx::PointF(),
8255 gfx::Size(120, 120), true, false);
8256 SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(),
8257 gfx::PointF(), gfx::Size(100, 100), true, false);
8258 SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix,
8259 gfx::Point3F(), gfx::PointF(),
8260 gfx::Size(200, 200), true, false);
8261
8262 TransformOperations start_transform_operations;
8263 start_transform_operations.AppendMatrix(uninvertible_matrix);
8264 TransformOperations end_transform_operations;
8265
loyso9556c732016-03-11 07:54:588266 AddAnimatedTransformToLayerWithPlayer(animated->id(), timeline(), 10.0,
8267 start_transform_operations,
8268 end_transform_operations);
enne601f2ef12015-05-19 18:20:178269 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:418270
8271 // The animated layer has a singular transform and maps to a non-empty rect in
8272 // clipped target space, so is treated as fully visible.
jaydasika74bf516f2016-04-01 19:48:158273 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:418274
8275 // The singular transform on |animated| is flattened when inherited by
8276 // |surface|, and this happens to make it invertible.
jaydasika74bf516f2016-04-01 19:48:158277 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect_for_testing());
8278 EXPECT_EQ(gfx::Rect(2, 2),
8279 descendant_of_animation->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:418280
8281 gfx::Transform zero_matrix;
8282 zero_matrix.Scale3d(0.f, 0.f, 0.f);
8283 SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(),
8284 gfx::PointF(), gfx::Size(120, 120), true, false);
8285
enne601f2ef12015-05-19 18:20:178286 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:418287
8288 // The animated layer maps to the empty rect in clipped target space, so is
8289 // treated as having an empty visible rect.
jaydasika74bf516f2016-04-01 19:48:158290 EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:418291
8292 // This time, flattening does not make |animated|'s transform invertible. This
8293 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:348294 // |surface| and layers that draw into it as having empty visible rect.
jaydasika74bf516f2016-04-01 19:48:158295 EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect_for_testing());
8296 EXPECT_EQ(gfx::Rect(),
8297 descendant_of_animation->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:418298}
8299
enne92f2f6d92015-02-25 23:13:318300// Verify that having an animated filter (but no current filter, as these
8301// are mutually exclusive) correctly creates a render surface.
8302TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
loyso0940d412016-03-14 01:30:318303 scoped_refptr<Layer> root = Layer::Create();
8304 scoped_refptr<Layer> child = Layer::Create();
8305 scoped_refptr<Layer> grandchild = Layer::Create();
enne92f2f6d92015-02-25 23:13:318306 root->AddChild(child);
8307 child->AddChild(grandchild);
8308
8309 gfx::Transform identity_transform;
8310 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8311 gfx::PointF(), gfx::Size(50, 50), true, false);
8312 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8313 gfx::PointF(), gfx::Size(50, 50), true, false);
8314 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8315 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
8316 true, false);
ennea7b43c32015-06-18 20:01:338317 host()->SetRootLayer(root);
enne92f2f6d92015-02-25 23:13:318318
loyso9556c732016-03-11 07:54:588319 AddAnimatedFilterToLayerWithPlayer(child->id(), timeline(), 10.0, 0.1f, 0.2f);
enne92f2f6d92015-02-25 23:13:318320 ExecuteCalculateDrawProperties(root.get());
8321
ennec1332992015-08-24 19:45:098322 EXPECT_TRUE(root->has_render_surface());
8323 EXPECT_TRUE(child->has_render_surface());
8324 EXPECT_FALSE(grandchild->has_render_surface());
enne92f2f6d92015-02-25 23:13:318325
8326 EXPECT_TRUE(root->filters().IsEmpty());
8327 EXPECT_TRUE(child->filters().IsEmpty());
8328 EXPECT_TRUE(grandchild->filters().IsEmpty());
8329
8330 EXPECT_FALSE(root->FilterIsAnimating());
8331 EXPECT_TRUE(child->FilterIsAnimating());
8332 EXPECT_FALSE(grandchild->FilterIsAnimating());
8333}
8334
ajuma315a4782015-07-24 21:16:348335// Verify that having a filter animation with a delayed start time creates a
8336// render surface.
8337TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
loyso0940d412016-03-14 01:30:318338 scoped_refptr<Layer> root = Layer::Create();
8339 scoped_refptr<Layer> child = Layer::Create();
8340 scoped_refptr<Layer> grandchild = Layer::Create();
ajuma315a4782015-07-24 21:16:348341 root->AddChild(child);
8342 child->AddChild(grandchild);
8343
8344 gfx::Transform identity_transform;
8345 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8346 gfx::PointF(), gfx::Size(50, 50), true, false);
8347 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8348 gfx::PointF(), gfx::Size(50, 50), true, false);
8349 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8350 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
8351 true, false);
8352 host()->SetRootLayer(root);
8353
8354 scoped_ptr<KeyframedFilterAnimationCurve> curve(
8355 KeyframedFilterAnimationCurve::Create());
8356 FilterOperations start_filters;
8357 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
8358 FilterOperations end_filters;
8359 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
8360 curve->AddKeyframe(
8361 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
8362 curve->AddKeyframe(FilterKeyframe::Create(
8363 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
8364 scoped_ptr<Animation> animation =
loyso0c8e4402016-02-25 04:12:308365 Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER);
ajuma315a4782015-07-24 21:16:348366 animation->set_fill_mode(Animation::FILL_MODE_NONE);
8367 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
ajuma315a4782015-07-24 21:16:348368
loyso9556c732016-03-11 07:54:588369 AddAnimationToLayerWithPlayer(child->id(), timeline(), std::move(animation));
ajuma315a4782015-07-24 21:16:348370 ExecuteCalculateDrawProperties(root.get());
8371
ennec1332992015-08-24 19:45:098372 EXPECT_TRUE(root->has_render_surface());
8373 EXPECT_TRUE(child->has_render_surface());
8374 EXPECT_FALSE(grandchild->has_render_surface());
ajuma315a4782015-07-24 21:16:348375
8376 EXPECT_TRUE(root->filters().IsEmpty());
8377 EXPECT_TRUE(child->filters().IsEmpty());
8378 EXPECT_TRUE(grandchild->filters().IsEmpty());
8379
8380 EXPECT_FALSE(root->FilterIsAnimating());
8381 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
8382 EXPECT_FALSE(child->FilterIsAnimating());
8383 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
8384 EXPECT_FALSE(grandchild->FilterIsAnimating());
8385 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
8386}
8387
vollick0120eb22015-03-02 03:07:348388// Ensures that the property tree code accounts for offsets between fixed
8389// position layers and their respective containers.
8390TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
loyso0940d412016-03-14 01:30:318391 scoped_refptr<Layer> root = Layer::Create();
8392 scoped_refptr<Layer> child = Layer::Create();
vollick0120eb22015-03-02 03:07:348393 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loyso0940d412016-03-14 01:30:318394 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick0120eb22015-03-02 03:07:348395
8396 root->AddChild(child);
8397 child->AddChild(grandchild);
8398
8399 gfx::Transform identity_transform;
8400 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8401 gfx::PointF(), gfx::Size(50, 50), true, false);
8402 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8403 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
8404 false);
8405 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8406 gfx::Point3F(), gfx::PointF(-1000, -1000),
8407 gfx::Size(50, 50), true, false);
8408
8409 root->SetMasksToBounds(true);
8410 root->SetIsContainerForFixedPositionLayers(true);
8411 LayerPositionConstraint constraint;
8412 constraint.set_is_fixed_position(true);
8413 grandchild->SetPositionConstraint(constraint);
8414
8415 root->SetIsContainerForFixedPositionLayers(true);
8416
ennea7b43c32015-06-18 20:01:338417 host()->SetRootLayer(root);
vollick0120eb22015-03-02 03:07:348418
enne601f2ef12015-05-19 18:20:178419 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick0120eb22015-03-02 03:07:348420
jaydasika74bf516f2016-04-01 19:48:158421 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
8422 grandchild->visible_layer_rect_for_testing());
vollick0120eb22015-03-02 03:07:348423}
8424
ajuma0178b522015-07-02 21:08:418425// Ensures that the property tree code accounts for offsets between fixed
8426// position containers and their transform tree parents, when a fixed position
8427// layer's container is its layer tree parent, but this parent doesn't have its
8428// own transform tree node.
8429TEST_F(LayerTreeHostCommonTest,
8430 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
loyso0940d412016-03-14 01:30:318431 scoped_refptr<Layer> root = Layer::Create();
8432 scoped_refptr<Layer> child = Layer::Create();
ajuma0178b522015-07-02 21:08:418433 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loyso0940d412016-03-14 01:30:318434 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajuma0178b522015-07-02 21:08:418435
8436 root->AddChild(child);
8437 child->AddChild(grandchild);
8438
8439 gfx::Transform identity_transform;
8440 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8441 gfx::PointF(), gfx::Size(50, 50), true, false);
8442 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8443 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
8444 false);
8445 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8446 gfx::Point3F(), gfx::PointF(-1000, -1000),
8447 gfx::Size(50, 50), true, false);
8448
8449 root->SetMasksToBounds(true);
8450 child->SetIsContainerForFixedPositionLayers(true);
8451 LayerPositionConstraint constraint;
8452 constraint.set_is_fixed_position(true);
8453 grandchild->SetPositionConstraint(constraint);
8454
8455 root->SetIsContainerForFixedPositionLayers(true);
8456
8457 host()->SetRootLayer(root);
8458
8459 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8460
jaydasika74bf516f2016-04-01 19:48:158461 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
8462 grandchild->visible_layer_rect_for_testing());
ajuma0178b522015-07-02 21:08:418463}
8464
vollick67394b42015-03-10 00:22:308465TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) {
8466 // In the following layer tree, the layer |box|'s render target is |surface|.
8467 // |surface| also creates a transform node. We want to combine clips for |box|
8468 // in the space of its target (i.e., |surface|), not its target's target. This
8469 // test ensures that happens.
8470
8471 gfx::Transform rotate;
8472 rotate.Rotate(5);
8473 gfx::Transform identity;
8474
loyso0940d412016-03-14 01:30:318475 scoped_refptr<Layer> root = Layer::Create();
vollick67394b42015-03-10 00:22:308476 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8477 gfx::PointF(), gfx::Size(2500, 1500), true,
8478 false);
8479
loyso0940d412016-03-14 01:30:318480 scoped_refptr<Layer> frame_clip = Layer::Create();
vollick67394b42015-03-10 00:22:308481 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8482 gfx::PointF(), gfx::Size(2500, 1500), true,
8483 false);
8484 frame_clip->SetMasksToBounds(true);
8485
loyso0940d412016-03-14 01:30:318486 scoped_refptr<Layer> rotated = Layer::Create();
vollick67394b42015-03-10 00:22:308487 SetLayerPropertiesForTesting(rotated.get(), rotate,
8488 gfx::Point3F(1250, 250, 0), gfx::PointF(),
8489 gfx::Size(2500, 500), true, false);
8490
loyso0940d412016-03-14 01:30:318491 scoped_refptr<Layer> surface = Layer::Create();
vollick67394b42015-03-10 00:22:308492 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(),
8493 gfx::PointF(), gfx::Size(2500, 500), true,
8494 false);
8495 surface->SetOpacity(0.5);
8496
8497 scoped_refptr<LayerWithForcedDrawsContent> container =
loyso0940d412016-03-14 01:30:318498 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick67394b42015-03-10 00:22:308499 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(),
8500 gfx::PointF(), gfx::Size(300, 300), true, false);
8501
8502 scoped_refptr<LayerWithForcedDrawsContent> box =
loyso0940d412016-03-14 01:30:318503 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick67394b42015-03-10 00:22:308504 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(),
8505 gfx::PointF(), gfx::Size(100, 100), true, false);
8506
8507 root->AddChild(frame_clip);
8508 frame_clip->AddChild(rotated);
8509 rotated->AddChild(surface);
8510 surface->AddChild(container);
8511 surface->AddChild(box);
8512
ennea7b43c32015-06-18 20:01:338513 host()->SetRootLayer(root);
vollick67394b42015-03-10 00:22:308514
8515 ExecuteCalculateDrawProperties(root.get());
8516}
8517
vollick8c824742015-03-20 22:21:088518TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
8519 gfx::Transform identity;
8520 gfx::Transform translate_z;
8521 translate_z.Translate3d(0, 0, 10);
8522
loyso0940d412016-03-14 01:30:318523 scoped_refptr<Layer> root = Layer::Create();
vollick8c824742015-03-20 22:21:088524 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8525 gfx::PointF(), gfx::Size(800, 800), true, false);
8526 root->SetIsContainerForFixedPositionLayers(true);
8527
loyso0940d412016-03-14 01:30:318528 scoped_refptr<Layer> frame_clip = Layer::Create();
vollick8c824742015-03-20 22:21:088529 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
8530 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8531 false);
8532 frame_clip->SetMasksToBounds(true);
8533
8534 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loyso0940d412016-03-14 01:30:318535 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick8c824742015-03-20 22:21:088536 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8537 gfx::PointF(), gfx::Size(1000, 1000), true,
8538 false);
8539
8540 LayerPositionConstraint constraint;
8541 constraint.set_is_fixed_position(true);
8542 fixed->SetPositionConstraint(constraint);
8543
8544 root->AddChild(frame_clip);
8545 frame_clip->AddChild(fixed);
8546
ennea7b43c32015-06-18 20:01:338547 host()->SetRootLayer(root);
vollick8c824742015-03-20 22:21:088548
enne601f2ef12015-05-19 18:20:178549 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick8c824742015-03-20 22:21:088550
8551 gfx::Rect expected(0, 0, 100, 100);
jaydasika74bf516f2016-04-01 19:48:158552 EXPECT_EQ(expected, fixed->visible_layer_rect_for_testing());
vollick8c824742015-03-20 22:21:088553}
8554
vollick06ca3e832015-03-31 19:37:128555TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
8556 gfx::Transform identity;
8557
loyso0940d412016-03-14 01:30:318558 scoped_refptr<Layer> root = Layer::Create();
vollick06ca3e832015-03-31 19:37:128559 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8560 gfx::PointF(), gfx::Size(800, 800), true, false);
8561 root->SetIsContainerForFixedPositionLayers(true);
8562
loyso0940d412016-03-14 01:30:318563 scoped_refptr<Layer> frame_clip = Layer::Create();
vollick06ca3e832015-03-31 19:37:128564 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8565 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8566 false);
8567 frame_clip->SetMasksToBounds(true);
8568
8569 scoped_refptr<LayerWithForcedDrawsContent> scroller =
loyso0940d412016-03-14 01:30:318570 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick06ca3e832015-03-31 19:37:128571 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
8572 gfx::PointF(), gfx::Size(1000, 1000), true,
8573 false);
8574
8575 scroller->SetScrollOffset(gfx::ScrollOffset(100, 100));
8576 scroller->SetScrollClipLayerId(frame_clip->id());
8577
8578 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loyso0940d412016-03-14 01:30:318579 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick06ca3e832015-03-31 19:37:128580 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8581 gfx::PointF(100, 100), gfx::Size(50, 50), true,
8582 false);
8583
8584 LayerPositionConstraint constraint;
8585 constraint.set_is_fixed_position(true);
8586 fixed->SetPositionConstraint(constraint);
8587 fixed->SetForceRenderSurface(true);
8588 fixed->SetMasksToBounds(true);
8589
8590 root->AddChild(frame_clip);
8591 frame_clip->AddChild(scroller);
8592 scroller->AddChild(fixed);
8593
ennea7b43c32015-06-18 20:01:338594 host()->SetRootLayer(root);
vollick06ca3e832015-03-31 19:37:128595
enne601f2ef12015-05-19 18:20:178596 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick06ca3e832015-03-31 19:37:128597
8598 gfx::Rect expected(0, 0, 50, 50);
jaydasika74bf516f2016-04-01 19:48:158599 EXPECT_EQ(expected, fixed->visible_layer_rect_for_testing());
vollick06ca3e832015-03-31 19:37:128600}
8601
vollick5057e1e2015-04-17 19:12:328602TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
8603 gfx::Transform identity;
8604 gfx::Transform translate;
8605 gfx::Transform rotate;
8606
8607 translate.Translate(10, 10);
8608 rotate.Rotate(45);
8609
loyso0940d412016-03-14 01:30:318610 scoped_refptr<Layer> root = Layer::Create();
vollick5057e1e2015-04-17 19:12:328611 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8612 gfx::PointF(), gfx::Size(800, 800), true, false);
8613 root->SetIsContainerForFixedPositionLayers(true);
8614
ennea7b43c32015-06-18 20:01:338615 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:328616
enne601f2ef12015-05-19 18:20:178617 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ennea7b43c32015-06-18 20:01:338618 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328619
8620 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:338621 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328622
8623 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:338624 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328625}
8626
ajumab0e0c1c2015-04-23 00:29:238627TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
loyso0940d412016-03-14 01:30:318628 scoped_refptr<Layer> root = Layer::Create();
ajumab0e0c1c2015-04-23 00:29:238629 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:318630 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumab0e0c1c2015-04-23 00:29:238631 root->AddChild(child);
8632
ennea7b43c32015-06-18 20:01:338633 host()->SetRootLayer(root);
ajumab0e0c1c2015-04-23 00:29:238634
8635 gfx::Transform identity_matrix;
8636 gfx::Transform scale_matrix;
8637 scale_matrix.Scale(2.f, 2.f);
8638 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8639 gfx::PointF(), gfx::Size(100, 100), true, false);
8640 SetLayerPropertiesForTesting(child.get(), scale_matrix, gfx::Point3F(),
8641 gfx::PointF(), gfx::Size(10, 10), true, false);
8642
enne601f2ef12015-05-19 18:20:178643 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158644 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect_for_testing());
ajumab0e0c1c2015-04-23 00:29:238645
8646 child->SetTransformOrigin(gfx::Point3F(10.f, 10.f, 10.f));
8647
enne601f2ef12015-05-19 18:20:178648 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158649 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect_for_testing());
ajumab0e0c1c2015-04-23 00:29:238650}
8651
ajumaf09db8962015-04-24 21:55:348652TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
loyso0940d412016-03-14 01:30:318653 scoped_refptr<Layer> root = Layer::Create();
ajumaf09db8962015-04-24 21:55:348654 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
loyso0940d412016-03-14 01:30:318655 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaf09db8962015-04-24 21:55:348656 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
loyso0940d412016-03-14 01:30:318657 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaf09db8962015-04-24 21:55:348658
8659 root->AddChild(scroll_child);
8660 root->AddChild(scroll_parent);
8661 scroll_child->SetScrollParent(scroll_parent.get());
8662 scroll_parent->SetScrollClipLayerId(root->id());
8663
ennea7b43c32015-06-18 20:01:338664 host()->SetRootLayer(root);
ajumaf09db8962015-04-24 21:55:348665
8666 gfx::Transform identity_transform;
8667 gfx::Transform scale;
8668 scale.Scale(2.f, 2.f);
8669 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8670 gfx::PointF(), gfx::Size(50, 50), true, false);
8671 SetLayerPropertiesForTesting(scroll_child.get(), scale, gfx::Point3F(),
8672 gfx::PointF(), gfx::Size(40, 40), true, false);
8673 SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform,
8674 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
8675 true, false);
8676
enne601f2ef12015-05-19 18:20:178677 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158678 EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect_for_testing());
ajumaf09db8962015-04-24 21:55:348679
8680 scroll_child->SetPosition(gfx::PointF(0, -10.f));
8681 scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f));
enne601f2ef12015-05-19 18:20:178682 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158683 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
8684 scroll_child->visible_layer_rect_for_testing());
ajumaf09db8962015-04-24 21:55:348685}
8686
vollick2175fae82015-04-27 21:18:128687static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
8688}
8689
sunxded58688e2016-01-11 21:01:028690TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) {
8691 // If the layer has a node in effect_tree, the return value of
8692 // num_copy_requests_in_target_subtree() must be equal to the actual number
8693 // of copy requests in the sub-layer_tree; Otherwise, the number is expected
8694 // to be the value of its nearest ancestor that owns an effect node and
8695 // greater than or equal to the actual number of copy requests in the
8696 // sub-layer_tree.
8697
loyso0940d412016-03-14 01:30:318698 scoped_refptr<Layer> root = Layer::Create();
8699 scoped_refptr<Layer> child1 = Layer::Create();
8700 scoped_refptr<Layer> child2 = Layer::Create();
8701 scoped_refptr<Layer> grandchild = Layer::Create();
8702 scoped_refptr<Layer> greatgrandchild = Layer::Create();
sunxded58688e2016-01-11 21:01:028703
8704 root->AddChild(child1);
8705 root->AddChild(child2);
8706 child1->AddChild(grandchild);
8707 grandchild->AddChild(greatgrandchild);
8708 host()->SetRootLayer(root);
8709
8710 child1->RequestCopyOfOutput(
8711 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8712 greatgrandchild->RequestCopyOfOutput(
8713 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8714 child2->SetOpacity(0.f);
8715 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8716
8717 EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2);
8718 EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2);
8719 EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0);
8720 EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2);
8721 EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1);
8722}
8723
vollick2175fae82015-04-27 21:18:128724TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
8725 gfx::Transform identity;
loyso0940d412016-03-14 01:30:318726 scoped_refptr<Layer> root = Layer::Create();
chrishtr01539b802015-11-24 08:11:328727 FakeContentLayerClient client;
8728 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:128729 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:318730 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick2175fae82015-04-27 21:18:128731 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loyso0940d412016-03-14 01:30:318732 make_scoped_refptr(new LayerWithForcedDrawsContent());
danakj4e95f7632015-06-05 19:46:258733 scoped_refptr<FakePictureLayer> greatgrandchild(
loyso0940d412016-03-14 01:30:318734 FakePictureLayer::Create(&client));
vollick2175fae82015-04-27 21:18:128735 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8736 gfx::PointF(), gfx::Size(100, 100), true, false);
8737 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8738 gfx::PointF(), gfx::Size(10, 10), true, false);
8739 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8740 gfx::PointF(), gfx::Size(10, 10), true, false);
8741 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
8742 gfx::PointF(), gfx::Size(10, 10), true, false);
8743
8744 root->AddChild(child);
8745 child->AddChild(grandchild);
8746 grandchild->AddChild(greatgrandchild);
8747
ennea7b43c32015-06-18 20:01:338748 host()->SetRootLayer(root);
vollick2175fae82015-04-27 21:18:128749
8750 // Check the non-skipped case.
enne601f2ef12015-05-19 18:20:178751 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158752 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128753
8754 // Now we will reset the visible rect from property trees for the grandchild,
8755 // and we will configure |child| in several ways that should force the subtree
8756 // to be skipped. The visible content rect for |grandchild| should, therefore,
8757 // remain empty.
weiliangcc97575c2016-03-03 18:34:278758 grandchild->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:128759 gfx::Transform singular;
8760 singular.matrix().set(0, 0, 0);
8761
8762 child->SetTransform(singular);
enne601f2ef12015-05-19 18:20:178763 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158764 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128765 child->SetTransform(identity);
8766
8767 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:178768 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158769 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128770 child->SetHideLayerAndSubtree(false);
8771
ajuma315a4782015-07-24 21:16:348772 gfx::Transform zero_z_scale;
8773 zero_z_scale.Scale3d(1, 1, 0);
8774 child->SetTransform(zero_z_scale);
8775
8776 // Add a transform animation with a start delay. Now, even though |child| has
8777 // a singular transform, the subtree should still get processed.
8778 int animation_id = 0;
8779 scoped_ptr<Animation> animation = Animation::Create(
danakja5a05ba02015-11-20 20:14:218780 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
loyso0c8e4402016-02-25 04:12:308781 animation_id, 1, TargetProperty::TRANSFORM);
ajuma315a4782015-07-24 21:16:348782 animation->set_fill_mode(Animation::FILL_MODE_NONE);
8783 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso9556c732016-03-11 07:54:588784 AddAnimationToLayerWithPlayer(child->id(), timeline(), std::move(animation));
ajuma315a4782015-07-24 21:16:348785 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158786 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
weiliangcc97575c2016-03-03 18:34:278787 grandchild->set_visible_layer_rect(gfx::Rect());
ajuma315a4782015-07-24 21:16:348788
loyso9556c732016-03-11 07:54:588789 RemoveAnimationFromLayerWithExistingPlayer(child->id(), timeline(),
8790 animation_id);
ajuma315a4782015-07-24 21:16:348791 child->SetTransform(identity);
vollick2175fae82015-04-27 21:18:128792 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:178793 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158794 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128795
8796 // Now, even though child has zero opacity, we will configure |grandchild| and
8797 // |greatgrandchild| in several ways that should force the subtree to be
8798 // processed anyhow.
jaydasika86654512016-01-27 17:05:078799 grandchild->RequestCopyOfOutput(
vollick2175fae82015-04-27 21:18:128800 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
enne601f2ef12015-05-19 18:20:178801 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158802 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
weiliangcc97575c2016-03-03 18:34:278803 greatgrandchild->set_visible_layer_rect(gfx::Rect());
ajuma315a4782015-07-24 21:16:348804
8805 // Add an opacity animation with a start delay.
8806 animation_id = 1;
8807 animation = Animation::Create(
danakja5a05ba02015-11-20 20:14:218808 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
loyso0c8e4402016-02-25 04:12:308809 animation_id, 1, TargetProperty::OPACITY);
ajuma315a4782015-07-24 21:16:348810 animation->set_fill_mode(Animation::FILL_MODE_NONE);
8811 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso9556c732016-03-11 07:54:588812 AddAnimationToLayerWithExistingPlayer(child->id(), timeline(),
8813 std::move(animation));
ajuma315a4782015-07-24 21:16:348814 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158815 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128816}
8817
sunxd71aea3e2016-04-01 23:48:058818TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:168819 FakeImplTaskRunnerProvider task_runner_provider;
vollick2175fae82015-04-27 21:18:128820 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:568821 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:168822 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:568823 &task_graph_runner);
vollick2175fae82015-04-27 21:18:128824
8825 gfx::Transform identity;
8826 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
8827 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
8828 scoped_ptr<LayerImpl> grandchild =
8829 LayerImpl::Create(host_impl.active_tree(), 3);
8830
danakj4e95f7632015-06-05 19:46:258831 scoped_ptr<FakePictureLayerImpl> greatgrandchild(
8832 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:128833
8834 child->SetDrawsContent(true);
8835 grandchild->SetDrawsContent(true);
8836 greatgrandchild->SetDrawsContent(true);
8837
8838 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8839 gfx::PointF(), gfx::Size(100, 100), true, false,
8840 true);
8841 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8842 gfx::PointF(), gfx::Size(10, 10), true, false,
8843 false);
8844 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8845 gfx::PointF(), gfx::Size(10, 10), true, false,
8846 false);
vollick2175fae82015-04-27 21:18:128847
jaydasika2411692c2016-03-23 01:56:098848 LayerImpl* root_ptr = root.get();
vollick2175fae82015-04-27 21:18:128849 LayerImpl* child_ptr = child.get();
8850 LayerImpl* grandchild_ptr = grandchild.get();
vollick2175fae82015-04-27 21:18:128851
danakja04855a2015-11-18 20:39:108852 child->AddChild(std::move(grandchild));
8853 root->AddChild(std::move(child));
jaydasika2411692c2016-03-23 01:56:098854 host_impl.active_tree()->SetRootLayer(std::move(root));
vollick2175fae82015-04-27 21:18:128855
8856 // Check the non-skipped case.
sunxd71aea3e2016-04-01 23:48:058857 // ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8858 // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128859
8860 // Now we will reset the visible rect from property trees for the grandchild,
8861 // and we will configure |child| in several ways that should force the subtree
8862 // to be skipped. The visible content rect for |grandchild| should, therefore,
8863 // remain empty.
weiliangcc97575c2016-03-03 18:34:278864 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
sunxd71aea3e2016-04-01 23:48:058865
vollick2175fae82015-04-27 21:18:128866 gfx::Transform singular;
8867 singular.matrix().set(0, 0, 0);
sunxd71aea3e2016-04-01 23:48:058868 // This line is used to make the results of skipping and not skipping layers
8869 // different.
8870 singular.matrix().set(0, 1, 1);
8871
8872 gfx::Transform rotate;
8873 rotate.Rotate(90);
8874
8875 gfx::Transform rotate_back_and_translate;
8876 rotate_back_and_translate.RotateAboutYAxis(180);
8877 rotate_back_and_translate.Translate(-10, 0);
vollick2175fae82015-04-27 21:18:128878
8879 child_ptr->SetTransform(singular);
sunxd71aea3e2016-04-01 23:48:058880 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:098881 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278882 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128883 child_ptr->SetTransform(identity);
8884
8885 child_ptr->SetHideLayerAndSubtree(true);
jaydasika2411692c2016-03-23 01:56:098886 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278887 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128888 child_ptr->SetHideLayerAndSubtree(false);
8889
8890 child_ptr->SetOpacity(0.f);
jaydasika2411692c2016-03-23 01:56:098891 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278892 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:058893 child_ptr->SetOpacity(1.f);
vollick2175fae82015-04-27 21:18:128894
sunxd71aea3e2016-04-01 23:48:058895 root_ptr->SetTransform(singular);
8896 // Force transform tree to have a node for child, so that ancestor's
8897 // invertible transform can be tested.
8898 child_ptr->SetTransform(rotate);
8899 host_impl.active_tree()->property_trees()->needs_rebuild = true;
8900 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8901 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
8902 root_ptr->SetTransform(identity);
8903 child_ptr->SetTransform(identity);
8904
8905 root_ptr->SetOpacity(0.f);
8906 child_ptr->SetOpacity(0.7f);
8907 host_impl.active_tree()->property_trees()->needs_rebuild = true;
8908 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8909 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
8910 root_ptr->SetOpacity(1.f);
8911
8912 child_ptr->SetOpacity(0.f);
vollick2175fae82015-04-27 21:18:128913 // Now, even though child has zero opacity, we will configure |grandchild| and
8914 // |greatgrandchild| in several ways that should force the subtree to be
8915 // processed anyhow.
vmpstra370ef52015-11-18 10:41:288916 std::vector<scoped_ptr<CopyOutputRequest>> requests;
vollick2175fae82015-04-27 21:18:128917 requests.push_back(CopyOutputRequest::CreateEmptyRequest());
8918
jaydasika86654512016-01-27 17:05:078919 grandchild_ptr->PassCopyRequests(&requests);
jaydasika2411692c2016-03-23 01:56:098920 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8921 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278922 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:058923 requests.clear();
8924 grandchild_ptr->PassCopyRequests(&requests);
8925 child_ptr->SetOpacity(1.f);
8926
8927 // A double sided render surface with backface visible should not be skipped
8928 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
8929 child_ptr->SetHasRenderSurface(true);
8930 child_ptr->SetDoubleSided(true);
8931 child_ptr->SetTransform(rotate_back_and_translate);
8932 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8933 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8934 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
8935 child_ptr->SetTransform(identity);
8936
8937 scoped_ptr<KeyframedTransformAnimationCurve> curve(
8938 KeyframedTransformAnimationCurve::Create());
8939 TransformOperations start;
8940 start.AppendTranslate(1.f, 2.f, 3.f);
8941 gfx::Transform transform;
8942 transform.Scale3d(1.0, 2.0, 3.0);
8943 TransformOperations operation;
8944 operation.AppendMatrix(transform);
8945 curve->AddKeyframe(
8946 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8947 curve->AddKeyframe(TransformKeyframe::Create(
8948 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
8949 scoped_ptr<Animation> transform_animation(
8950 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8951 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
8952 host_impl.active_tree()->animation_host()->RegisterPlayerForLayer(
8953 root_ptr->id(), player.get());
8954 host_impl.active_tree()
8955 ->animation_host()
8956 ->GetControllerForLayerId(root_ptr->id())
8957 ->AddAnimation(std::move(transform_animation));
8958 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
8959 child_ptr->SetScrollClipLayer(root_ptr->id());
8960 root_ptr->SetTransform(singular);
8961 child_ptr->SetTransform(singular);
8962 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8963 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8964 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
8965
8966 host_impl.active_tree()->animation_host()->UnregisterPlayerForLayer(
8967 root_ptr->id(), player.get());
8968}
8969
8970TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
8971 FakeImplTaskRunnerProvider task_runner_provider;
8972 TestSharedBitmapManager shared_bitmap_manager;
8973 TestTaskGraphRunner task_graph_runner;
8974 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
8975 &task_graph_runner);
8976
8977 gfx::Transform identity;
8978 host_impl.CreatePendingTree();
8979 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
8980 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
8981 scoped_ptr<LayerImpl> grandchild =
8982 LayerImpl::Create(host_impl.pending_tree(), 3);
8983
8984 scoped_ptr<FakePictureLayerImpl> greatgrandchild(
8985 FakePictureLayerImpl::Create(host_impl.pending_tree(), 4));
8986
8987 child->SetDrawsContent(true);
8988 grandchild->SetDrawsContent(true);
8989 greatgrandchild->SetDrawsContent(true);
8990
8991 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8992 gfx::PointF(), gfx::Size(100, 100), true, false,
8993 true);
8994 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8995 gfx::PointF(), gfx::Size(10, 10), true, false,
8996 false);
8997 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8998 gfx::PointF(), gfx::Size(10, 10), true, false,
8999 false);
9000
9001 LayerImpl* root_ptr = root.get();
9002 LayerImpl* grandchild_ptr = grandchild.get();
9003
9004 child->AddChild(std::move(grandchild));
9005 root->AddChild(std::move(child));
9006
9007 host_impl.pending_tree()->SetRootLayer(std::move(root));
9008
9009 // Check the non-skipped case.
9010 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
9011 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9012
9013 scoped_ptr<KeyframedFloatAnimationCurve> curve(
9014 KeyframedFloatAnimationCurve::Create());
9015 scoped_ptr<TimingFunction> func = EaseTimingFunction::Create();
9016 curve->AddKeyframe(
9017 FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func)));
9018 curve->AddKeyframe(
9019 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr));
9020 scoped_ptr<Animation> animation(
9021 Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY));
9022 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
9023 host_impl.active_tree()->animation_host()->RegisterPlayerForLayer(
9024 root_ptr->id(), player.get());
9025 host_impl.active_tree()
9026 ->animation_host()
9027 ->GetControllerForLayerId(root_ptr->id())
9028 ->AddAnimation(std::move(animation));
9029 root_ptr->SetOpacity(0);
9030 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9031 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
9032 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
9033 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9034
9035 host_impl.active_tree()->animation_host()->UnregisterPlayerForLayer(
9036 root_ptr->id(), player.get());
vollick2175fae82015-04-27 21:18:129037}
9038
9039TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
9040 gfx::Transform identity;
loyso0940d412016-03-14 01:30:319041 scoped_refptr<Layer> root = Layer::Create();
chrishtr01539b802015-11-24 08:11:329042 FakeContentLayerClient client;
9043 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:129044 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:319045 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick2175fae82015-04-27 21:18:129046 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9047 gfx::PointF(), gfx::Size(100, 100), true, false);
9048 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9049 gfx::PointF(), gfx::Size(10, 10), true, false);
9050 root->AddChild(child);
9051
ennea7b43c32015-06-18 20:01:339052 host()->SetRootLayer(root);
vollick2175fae82015-04-27 21:18:129053
enne601f2ef12015-05-19 18:20:179054 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:159055 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect_for_testing());
weiliangcc97575c2016-03-03 18:34:279056 child->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:129057
9058 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:179059 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:159060 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:129061 child->SetHideLayerAndSubtree(false);
9062
9063 child->SetBounds(gfx::Size());
enne601f2ef12015-05-19 18:20:179064 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:159065 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:129066 child->SetBounds(gfx::Size(10, 10));
9067
9068 gfx::Transform rotate;
9069 child->SetDoubleSided(false);
9070 rotate.RotateAboutXAxis(180.f);
9071 child->SetTransform(rotate);
enne601f2ef12015-05-19 18:20:179072 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:159073 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:129074 child->SetDoubleSided(true);
9075 child->SetTransform(identity);
9076
9077 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:179078 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:159079 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:129080}
9081
jaydasika3d10aa62015-05-06 17:50:449082TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
9083 // Ensure that the treewalk in LayerTreeHostCommom::
9084 // PreCalculateMetaInformation happens when its required.
loyso0940d412016-03-14 01:30:319085 scoped_refptr<Layer> root = Layer::Create();
9086 scoped_refptr<Layer> parent = Layer::Create();
9087 scoped_refptr<Layer> child = Layer::Create();
jaydasika3d10aa62015-05-06 17:50:449088
9089 root->AddChild(parent);
9090 parent->AddChild(child);
9091
9092 child->SetClipParent(root.get());
9093
9094 gfx::Transform identity;
9095
9096 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9097 gfx::PointF(), gfx::Size(100, 100), true, false);
9098 SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(),
9099 gfx::PointF(), gfx::Size(100, 100), true, false);
9100 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9101 gfx::PointF(), gfx::Size(100, 100), true, false);
9102
ennea7b43c32015-06-18 20:01:339103 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:449104
jaydasika3d10aa62015-05-06 17:50:449105 child->RequestCopyOfOutput(
9106 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
sunxded58688e2016-01-11 21:01:029107
9108 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9109 EXPECT_EQ(parent->num_unclipped_descendants(), 1u);
9110
9111 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
9112 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9113 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika3d10aa62015-05-06 17:50:449114}
9115
9116TEST_F(LayerTreeHostCommonTest, InputHandlersRecursiveUpdateTest) {
9117 // Ensure that the treewalk in LayertreeHostCommon::
9118 // PreCalculateMetaInformation updates input handlers correctly.
ennecf94ff0c2015-08-18 22:58:059119 LayerImpl* root = root_layer();
9120 LayerImpl* child = AddChild<LayerImpl>(root);
jaydasika3d10aa62015-05-06 17:50:449121
9122 gfx::Transform identity;
9123
ennecf94ff0c2015-08-18 22:58:059124 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
9125 gfx::Size(100, 100), true, false, true);
9126 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
9127 gfx::Size(100, 100), true, false, false);
jaydasika3d10aa62015-05-06 17:50:449128
dtapuskaee0b6982016-01-29 15:14:489129 EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), false);
jaydasika3d10aa62015-05-06 17:50:449130
dtapuskaee0b6982016-01-29 15:14:489131 child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
ennecf94ff0c2015-08-18 22:58:059132 ExecuteCalculateDrawProperties(root);
dtapuskaee0b6982016-01-29 15:14:489133 EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), true);
ennecf94ff0c2015-08-18 22:58:059134
dtapuskaee0b6982016-01-29 15:14:489135 child->SetTouchEventHandlerRegion(gfx::Rect());
ennecf94ff0c2015-08-18 22:58:059136 ExecuteCalculateDrawProperties(root);
dtapuskaee0b6982016-01-29 15:14:489137 EXPECT_EQ(root->layer_or_descendant_has_touch_handler(), false);
jaydasika3d10aa62015-05-06 17:50:449138}
9139
vollick692444f2015-05-20 15:39:149140TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
9141 gfx::Transform identity;
9142 gfx::Transform translate_z;
9143 translate_z.Translate3d(0, 0, 10);
9144
loyso0940d412016-03-14 01:30:319145 scoped_refptr<Layer> root = Layer::Create();
vollick692444f2015-05-20 15:39:149146 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9147 gfx::PointF(), gfx::Size(800, 800), true, false);
9148
loyso0940d412016-03-14 01:30:319149 scoped_refptr<Layer> child = Layer::Create();
vollick692444f2015-05-20 15:39:149150 SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(),
9151 gfx::PointF(), gfx::Size(100, 100), true, false);
9152
9153 root->AddChild(child);
9154
ennea7b43c32015-06-18 20:01:339155 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:149156
9157 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9158 EXPECT_NE(-1, child->transform_tree_index());
9159
9160 child->RemoveFromParent();
9161
9162 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9163 EXPECT_EQ(-1, child->transform_tree_index());
9164}
9165
jaydasika67d7989e2015-08-06 21:55:349166TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
9167 // Ensure that a Clip Node is added when a render surface applies clip.
9168 LayerImpl* root = root_layer();
9169 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
9170 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
9171 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
9172 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9173
9174 const gfx::Transform identity_matrix;
9175 // This transform should be a significant one so that a transform node is
9176 // formed for it.
9177 gfx::Transform transform1;
9178 transform1.RotateAboutYAxis(45);
9179 transform1.RotateAboutXAxis(30);
9180 // This transform should be a 3d transform as we want the render surface
9181 // to flatten the transform
9182 gfx::Transform transform2;
9183 transform2.Translate3d(10, 10, 10);
9184
9185 layer_clips_subtree->SetMasksToBounds(true);
9186 test_layer->SetDrawsContent(true);
9187
9188 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269189 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349190 SetLayerPropertiesForTesting(significant_transform, transform1,
9191 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
weiliangcc154ce22015-12-09 03:39:269192 true, false);
jaydasika67d7989e2015-08-06 21:55:349193 SetLayerPropertiesForTesting(layer_clips_subtree, identity_matrix,
9194 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
weiliangcc154ce22015-12-09 03:39:269195 true, false);
jaydasika67d7989e2015-08-06 21:55:349196 SetLayerPropertiesForTesting(render_surface, transform2, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269197 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349198 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269199 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349200
weiliangcc154ce22015-12-09 03:39:269201 root->SetForceRenderSurface(true);
9202 significant_transform->SetForceRenderSurface(false);
9203 layer_clips_subtree->SetForceRenderSurface(true);
9204 render_surface->SetForceRenderSurface(true);
9205 test_layer->SetForceRenderSurface(false);
jaydasika67d7989e2015-08-06 21:55:349206 ExecuteCalculateDrawProperties(root);
9207
9208 TransformTree transform_tree =
9209 root->layer_tree_impl()->property_trees()->transform_tree;
9210 TransformNode* transform_node =
9211 transform_tree.Node(significant_transform->transform_tree_index());
9212 EXPECT_EQ(transform_node->owner_id, significant_transform->id());
9213
weiliangcc154ce22015-12-09 03:39:269214 EXPECT_TRUE(root->has_render_surface());
9215 EXPECT_FALSE(significant_transform->has_render_surface());
9216 EXPECT_TRUE(layer_clips_subtree->has_render_surface());
9217 EXPECT_TRUE(render_surface->has_render_surface());
9218 EXPECT_FALSE(test_layer->has_render_surface());
9219
jaydasika67d7989e2015-08-06 21:55:349220 ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
9221 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
ajuma01734dd02015-10-07 01:22:089222 EXPECT_FALSE(clip_node->data.applies_local_clip);
weiliangcc97575c2016-03-03 18:34:279223 EXPECT_EQ(gfx::Rect(22, 21), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349224}
9225
9226TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
9227 // Ensure that when parent clip node's transform is an ancestor of current
9228 // clip node's target, clip is 'projected' from parent space to current
9229 // target space and visible rects are calculated correctly.
9230 LayerImpl* root = root_layer();
9231 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9232 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
9233 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
9234
9235 const gfx::Transform identity_matrix;
9236 gfx::Transform transform;
9237 transform.RotateAboutYAxis(45);
9238 clip_layer->SetMasksToBounds(true);
9239 target_layer->SetMasksToBounds(true);
9240 test_layer->SetDrawsContent(true);
9241
9242 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9243 gfx::PointF(), gfx::Size(30, 30), true, false,
9244 true);
9245 SetLayerPropertiesForTesting(clip_layer, transform, gfx::Point3F(),
9246 gfx::PointF(), gfx::Size(30, 30), true, false,
9247 false);
9248 SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(),
9249 gfx::PointF(), gfx::Size(30, 30), true, false,
9250 true);
9251 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9252 gfx::PointF(), gfx::Size(30, 30), true, false,
9253 false);
9254 ExecuteCalculateDrawProperties(root);
9255
weiliangcc97575c2016-03-03 18:34:279256 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349257}
9258
jaydasika7d5c1ed2015-08-14 14:27:029259TEST_F(LayerTreeHostCommonTest,
9260 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
9261 // Ensure clip rect is calculated correctly when render surface has unclipped
9262 // descendants.
9263 LayerImpl* root = root_layer();
9264 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9265 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
9266 LayerImpl* render_surface =
9267 AddChild<LayerImpl>(between_clip_parent_and_child);
9268 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9269
9270 const gfx::Transform identity_matrix;
weiliangcbb2e8642016-03-04 00:24:429271 gfx::Transform translate;
9272 translate.Translate(2.0, 2.0);
jaydasika7d5c1ed2015-08-14 14:27:029273
weiliangcbb2e8642016-03-04 00:24:429274 clip_parent->SetMasksToBounds(true);
jaydasika7d5c1ed2015-08-14 14:27:029275 test_layer->SetDrawsContent(true);
9276 render_surface->SetClipParent(clip_parent);
jaydasikae9d09702015-09-15 01:26:419277 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9278 clip_children->insert(render_surface);
9279 clip_parent->SetClipChildren(clip_children.release());
jaydasika7d5c1ed2015-08-14 14:27:029280 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9281 gfx::PointF(), gfx::Size(30, 30), true, false,
9282 true);
weiliangcbb2e8642016-03-04 00:24:429283 SetLayerPropertiesForTesting(clip_parent, translate, gfx::Point3F(),
jaydasika7d5c1ed2015-08-14 14:27:029284 gfx::PointF(), gfx::Size(30, 30), true, false,
9285 false);
weiliangcbb2e8642016-03-04 00:24:429286 SetLayerPropertiesForTesting(between_clip_parent_and_child, translate,
jaydasika7d5c1ed2015-08-14 14:27:029287 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
9288 true, false, false);
9289 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9290 gfx::PointF(), gfx::Size(30, 30), true, false,
9291 true);
9292 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9293 gfx::PointF(), gfx::Size(30, 30), true, false,
9294 false);
9295
9296 ExecuteCalculateDrawProperties(root);
9297
weiliangcbb2e8642016-03-04 00:24:429298 EXPECT_TRUE(test_layer->is_clipped());
9299 EXPECT_FALSE(test_layer->render_target()->render_surface()->is_clipped());
weiliangc0b41eaf2016-03-14 21:35:569300 EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect());
9301 EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect());
jaydasika7d5c1ed2015-08-14 14:27:029302}
9303
jaydasika571dd2cf2015-09-25 20:55:429304TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:089305 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
9306 // Ensure that the visible layer rect of a descendant of a surface with
9307 // unclipped descendants is computed correctly, when the surface doesn't apply
9308 // a clip.
9309 LayerImpl* root = root_layer();
9310 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9311 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9312 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9313 LayerImpl* child = AddChild<LayerImpl>(render_surface);
9314
9315 const gfx::Transform identity_matrix;
9316
9317 clip_child->SetDrawsContent(true);
9318 child->SetDrawsContent(true);
9319 clip_child->SetClipParent(clip_parent);
9320 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9321 clip_children->insert(clip_child);
9322 clip_parent->SetClipChildren(clip_children.release());
9323 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9324 gfx::PointF(), gfx::Size(30, 10), true, false,
9325 true);
9326 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9327 gfx::PointF(), gfx::Size(30, 30), true, false,
9328 false);
9329 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9330 gfx::PointF(), gfx::Size(10, 15), true, false,
9331 true);
9332 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9333 gfx::PointF(), gfx::Size(10, 10), true, false,
9334 false);
9335 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
9336 gfx::PointF(), gfx::Size(40, 40), true, false,
9337 false);
9338
9339 ExecuteCalculateDrawProperties(root);
9340 EXPECT_EQ(gfx::Rect(40, 40), child->visible_layer_rect());
9341}
9342
9343TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:429344 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
9345 LayerImpl* root = root_layer();
9346 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9347 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9348 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
9349 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
9350 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
9351
9352 const gfx::Transform identity_matrix;
9353 root->SetMasksToBounds(true);
9354 render_surface->SetMasksToBounds(true);
9355 render_surface->SetDrawsContent(true);
9356 clip_child->SetDrawsContent(true);
9357 test_layer1->SetDrawsContent(true);
9358 test_layer2->SetDrawsContent(true);
9359 clip_child->SetClipParent(clip_parent);
9360 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9361 clip_children->insert(clip_child);
9362 clip_parent->SetClipChildren(clip_children.release());
9363
9364 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9365 gfx::PointF(), gfx::Size(30, 30), true, false,
9366 true);
9367 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9368 gfx::PointF(), gfx::Size(30, 30), true, false,
9369 false);
9370 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9371 gfx::PointF(), gfx::Size(50, 50), true, false,
9372 true);
9373 SetLayerPropertiesForTesting(test_layer1, identity_matrix, gfx::Point3F(),
9374 gfx::PointF(), gfx::Size(50, 50), true, false,
9375 false);
9376 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9377 gfx::PointF(), gfx::Size(50, 50), true, false,
9378 false);
9379 SetLayerPropertiesForTesting(test_layer2, identity_matrix, gfx::Point3F(),
9380 gfx::PointF(), gfx::Size(50, 50), true, false,
9381 false);
9382
9383 ExecuteCalculateDrawProperties(root);
weiliangc0e13ba602016-03-12 04:53:569384 EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect());
9385 EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect());
jaydasika571dd2cf2015-09-25 20:55:429386 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
9387 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
9388}
9389
ajumae2b7a5c2015-09-30 21:41:429390TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
9391 LayerImpl* root = root_layer();
9392 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9393 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9394 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9395
9396 const gfx::Transform identity_matrix;
9397 clip_parent->SetDrawsContent(true);
9398 render_surface->SetMasksToBounds(true);
9399 render_surface->SetDrawsContent(true);
9400 clip_child->SetDrawsContent(true);
9401
9402 clip_child->SetClipParent(clip_parent);
9403 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9404 clip_children->insert(clip_child);
9405 clip_parent->SetClipChildren(clip_children.release());
9406
9407 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9408 gfx::PointF(), gfx::Size(50, 50), true, false,
9409 true);
9410 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9411 gfx::PointF(), gfx::Size(50, 50), true, false,
9412 false);
9413 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9414 gfx::PointF(), gfx::Size(30, 30), true, false,
9415 true);
9416 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9417 gfx::PointF(), gfx::Size(50, 50), true, false,
9418 false);
9419
9420 ExecuteCalculateDrawProperties(root);
9421
9422 // The clip child should inherit its clip parent's clipping state, not its
9423 // tree parent's clipping state.
9424 EXPECT_FALSE(clip_parent->is_clipped());
9425 EXPECT_TRUE(render_surface->is_clipped());
9426 EXPECT_FALSE(clip_child->is_clipped());
9427}
9428
jaydasika77a4a072015-10-20 21:47:279429TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
9430 // Tests the value of render surface content rect when we have multiple types
9431 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
9432 // clipped surfaces.
9433 LayerImpl* root = root_layer();
9434 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
9435 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
9436 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9437 LayerImpl* unclipped_desc_surface2 =
9438 AddChild<LayerImpl>(unclipped_desc_surface);
9439 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
9440 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
9441
9442 unclipped_surface->SetDrawsContent(true);
9443 unclipped_desc_surface->SetDrawsContent(true);
9444 unclipped_desc_surface2->SetDrawsContent(true);
9445 clipped_surface->SetDrawsContent(true);
9446 clip_child->SetClipParent(clip_parent);
9447 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9448 clip_children->insert(clip_child);
9449 clip_parent->SetClipChildren(clip_children.release());
9450
9451 gfx::Transform identity_matrix;
9452 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9453 gfx::PointF(), gfx::Size(80, 80), true, false,
9454 true);
9455 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
9456 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
9457 true, false, true);
9458 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9459 gfx::PointF(), gfx::Size(50, 50), true, false,
9460 false);
9461 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
9462 gfx::Point3F(), gfx::PointF(),
9463 gfx::Size(100, 100), true, false, true);
9464 SetLayerPropertiesForTesting(unclipped_desc_surface2, identity_matrix,
9465 gfx::Point3F(), gfx::PointF(), gfx::Size(60, 60),
9466 true, false, true);
9467 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9468 gfx::PointF(), gfx::Size(100, 100), true, false,
9469 false);
9470 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
9471 gfx::PointF(), gfx::Size(70, 70), true, false,
9472 true);
9473 clip_parent->SetMasksToBounds(true);
9474 unclipped_surface->SetMasksToBounds(true);
9475 unclipped_desc_surface->SetMasksToBounds(true);
9476
9477 ExecuteCalculateDrawProperties(root);
9478 EXPECT_EQ(gfx::Rect(50, 50),
9479 unclipped_surface->render_surface()->content_rect());
weiliangc0e13ba602016-03-12 04:53:569480 EXPECT_EQ(gfx::Rect(50, 50),
jaydasika77a4a072015-10-20 21:47:279481 unclipped_desc_surface->render_surface()->content_rect());
9482 EXPECT_EQ(gfx::Rect(50, 50),
9483 unclipped_desc_surface2->render_surface()->content_rect());
9484 EXPECT_EQ(gfx::Rect(50, 50),
9485 clipped_surface->render_surface()->content_rect());
9486}
9487
9488TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
9489 // Tests the value of render surface content rect when we have a layer that
9490 // clips between the clip parent's target and clip child's target.
9491 LayerImpl* root = root_layer();
9492 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9493 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9494 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9495 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9496 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9497
9498 clip_child->SetDrawsContent(true);
9499 unclipped_desc_surface->SetDrawsContent(true);
9500 clip_child->SetClipParent(clip_parent);
9501 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9502 clip_children->insert(clip_child);
9503 clip_parent->SetClipChildren(clip_children.release());
9504
9505 gfx::Transform identity_matrix;
9506 gfx::Transform translate;
9507 translate.Translate(10, 10);
9508 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9509 gfx::PointF(), gfx::Size(100, 100), true, false,
9510 true);
9511 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
9512 gfx::PointF(), gfx::Size(100, 100), true, false,
9513 true);
9514 SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(),
9515 gfx::PointF(), gfx::Size(20, 20), true, false,
9516 false);
9517 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9518 gfx::PointF(), gfx::Size(50, 50), true, false,
9519 false);
9520 SetLayerPropertiesForTesting(unclipped_desc_surface, translate,
9521 gfx::Point3F(), gfx::PointF(),
9522 gfx::Size(100, 100), true, false, true);
9523 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9524 gfx::PointF(), gfx::Size(100, 100), true, false,
9525 false);
9526 surface->SetMasksToBounds(true);
9527 clip_layer->SetMasksToBounds(true);
9528
9529 ExecuteCalculateDrawProperties(root);
9530
9531 EXPECT_EQ(gfx::Rect(10, 10),
9532 unclipped_desc_surface->render_surface()->content_rect());
9533}
9534
jaydasika2c8c2872015-10-21 23:28:219535TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
9536 LayerImpl* root = root_layer();
9537 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9538 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9539 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9540 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9541 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9542
9543 clip_child->SetDrawsContent(true);
9544 unclipped_desc_surface->SetDrawsContent(true);
9545 clip_child->SetClipParent(clip_parent);
9546 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9547 clip_children->insert(clip_child);
9548 clip_parent->SetClipChildren(clip_children.release());
9549
9550 gfx::Transform identity_matrix;
9551 gfx::Transform scale;
9552 scale.Scale(2, 2);
9553 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9554 gfx::PointF(), gfx::Size(100, 100), true, false,
9555 true);
9556 SetLayerPropertiesForTesting(surface, scale, gfx::Point3F(), gfx::PointF(),
9557 gfx::Size(100, 100), true, false, true);
9558 SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(),
9559 gfx::PointF(), gfx::Size(20, 20), true, false,
9560 false);
9561 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9562 gfx::PointF(), gfx::Size(50, 50), true, false,
9563 false);
9564 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
9565 gfx::Point3F(), gfx::PointF(),
9566 gfx::Size(100, 100), true, false, true);
9567 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9568 gfx::PointF(), gfx::Size(100, 100), true, false,
9569 false);
9570 surface->SetMasksToBounds(true);
9571 clip_layer->SetMasksToBounds(true);
9572
9573 ExecuteCalculateDrawProperties(root);
9574
9575 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9576}
9577
jaydasika60f85862015-10-01 20:36:149578TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
9579 LayerImpl* root = root_layer();
9580 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9581 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9582
9583 const gfx::Transform identity_matrix;
9584 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9585 gfx::PointF(), gfx::Size(30, 30), true, false,
9586 true);
9587 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9588 gfx::PointF(), gfx::Size(30, 30), true, false,
9589 true);
jaydasika86654512016-01-27 17:05:079590 gfx::Transform translation;
9591 translation.Translate(10, 10);
9592 SetLayerPropertiesForTesting(test_layer, translation, gfx::Point3F(),
jaydasika60f85862015-10-01 20:36:149593 gfx::PointF(), gfx::Size(20, 20), true, false,
9594 false);
9595
9596 render_surface->SetMasksToBounds(true);
9597 test_layer->SetDrawsContent(true);
9598 test_layer->SetOpacity(0);
dtapuskaee0b6982016-01-29 15:14:489599 test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20));
jaydasika60f85862015-10-01 20:36:149600
9601 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079602 EXPECT_EQ(translation, test_layer->ScreenSpaceTransform());
jaydasika60f85862015-10-01 20:36:149603}
9604
jaydasikae4910fa22015-10-09 00:52:099605TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
9606 LayerImpl* root = root_layer();
9607 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9608 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9609 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9610
9611 const gfx::Transform identity_matrix;
9612 clip_parent->SetMasksToBounds(true);
9613 render_surface->SetMasksToBounds(true);
9614 render_surface->SetDrawsContent(true);
9615 clip_child->SetDrawsContent(true);
9616 clip_child->SetClipParent(clip_parent);
9617 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9618 clip_children->insert(clip_child);
9619 clip_parent->SetClipChildren(clip_children.release());
9620
9621 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9622 gfx::PointF(), gfx::Size(30, 30), true, false,
9623 true);
9624 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9625 gfx::PointF(10.f, 10.f), gfx::Size(40, 40), true,
9626 false, false);
9627 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9628 gfx::PointF(), gfx::Size(50, 50), true, false,
9629 true);
9630 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9631 gfx::PointF(), gfx::Size(50, 50), true, false,
9632 false);
9633
9634 ExecuteCalculateDrawProperties(root);
9635 EXPECT_EQ(gfx::Rect(40, 40), clip_child->visible_layer_rect());
9636}
9637
jaydasika571dd2cf2015-09-25 20:55:429638TEST_F(LayerTreeHostCommonTest,
9639 LayerClipRectLargerThanClippingRenderSurfaceRect) {
9640 LayerImpl* root = root_layer();
9641 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9642 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9643 const gfx::Transform identity_matrix;
9644 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9645 gfx::PointF(), gfx::Size(30, 30), true, false,
9646 true);
9647 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9648 gfx::PointF(), gfx::Size(50, 50), true, false,
9649 true);
9650 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9651 gfx::PointF(), gfx::Size(50, 50), true, false,
9652 false);
9653 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369654 root->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429655 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369656 render_surface->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429657 test_layer->SetMasksToBounds(true);
9658 test_layer->SetDrawsContent(true);
9659 ExecuteCalculateDrawProperties(root);
9660
9661 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
9662 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
9663 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
9664}
9665
jaydasikab5504ca2015-12-18 23:41:559666TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) {
9667 // Tests that subtree is hidden is updated.
9668 LayerImpl* root = root_layer();
9669 LayerImpl* hidden = AddChild<LayerImpl>(root);
9670 LayerImpl* test = AddChild<LayerImpl>(hidden);
9671
9672 const gfx::Transform identity_matrix;
9673 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9674 gfx::PointF(), gfx::Size(30, 30), true, false,
9675 true);
9676 SetLayerPropertiesForTesting(hidden, identity_matrix, gfx::Point3F(),
9677 gfx::PointF(10, 10), gfx::Size(30, 30), true,
9678 false, true);
9679 SetLayerPropertiesForTesting(test, identity_matrix, gfx::Point3F(),
9680 gfx::PointF(), gfx::Size(30, 30), true, false,
9681 true);
9682
9683 hidden->SetHideLayerAndSubtree(true);
9684 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079685 EXPECT_TRUE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559686
9687 hidden->SetHideLayerAndSubtree(false);
9688 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9689 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079690 EXPECT_FALSE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559691}
9692
jaydasikac0137282015-10-01 15:50:309693TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
9694 LayerImpl* root = root_layer();
9695 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9696 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9697 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
9698
9699 const gfx::Transform identity_matrix;
9700 clip_child->SetClipParent(root);
9701 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9702 clip_children->insert(clip_child);
9703 root->SetClipChildren(clip_children.release());
9704 root->SetMasksToBounds(true);
9705 render_surface1->SetDrawsContent(true);
9706 render_surface2->SetDrawsContent(true);
9707
9708 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9709 gfx::PointF(), gfx::Size(30, 30), true, false,
9710 true);
9711 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
9712 gfx::PointF(10, 10), gfx::Size(30, 30), true,
9713 false, true);
9714 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
9715 gfx::PointF(), gfx::Size(30, 30), true, false,
9716 true);
9717 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9718 gfx::PointF(), gfx::Size(30, 30), true, false,
9719 false);
9720 ExecuteCalculateDrawProperties(root);
9721
9722 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
jaydasikadaf0af02016-01-06 15:33:379723 // A clip node is created for every render surface and for layers that have
9724 // local clip. So, here it should be craeted for every layer.
9725 EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u);
jaydasikac0137282015-10-01 15:50:309726}
9727
jaydasika224bca02015-12-18 02:37:099728TEST_F(LayerTreeHostCommonTest, MaskLayerScreenSpaceTransform) {
9729 // Tests that the mask layer gets its owning layer's screen space transform.
9730 LayerImpl* root = root_layer();
9731 LayerImpl* child = AddChild<LayerImpl>(root);
9732
9733 const gfx::Transform identity_matrix;
9734 gfx::Transform transform;
9735 transform.Translate(10, 10);
9736
9737 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9738 gfx::PointF(), gfx::Size(30, 30), true, false,
9739 true);
9740 SetLayerPropertiesForTesting(child, transform, gfx::Point3F(), gfx::PointF(),
9741 gfx::Size(30, 30), true, false, false);
9742 root->SetDrawsContent(true);
9743 child->SetDrawsContent(false);
9744 child->SetMaskLayer(LayerImpl::Create(root->layer_tree_impl(), 100));
9745 ExecuteCalculateDrawProperties(root);
9746
9747 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
9748 child->mask_layer()->ScreenSpaceTransform());
9749 transform.Translate(10, 10);
9750 child->SetTransform(transform);
9751 child->SetDrawsContent(true);
9752 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9753 ExecuteCalculateDrawProperties(root);
9754 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
9755 child->mask_layer()->ScreenSpaceTransform());
9756}
9757
jaydasika5160e672015-10-15 15:25:149758TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
9759 LayerImpl* root = root_layer();
9760 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
sunxd71aea3e2016-04-01 23:48:059761 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
jaydasika5160e672015-10-15 15:25:149762
9763 const gfx::Transform identity_matrix;
sunxd71aea3e2016-04-01 23:48:059764 child->SetDrawsContent(true);
9765 child->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:149766
9767 gfx::Transform large_transform;
9768 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
9769 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
9770 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
9771 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
9772
9773 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9774 gfx::PointF(), gfx::Size(30, 30), true, false,
9775 true);
sunxd71aea3e2016-04-01 23:48:059776 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
jaydasika5160e672015-10-15 15:25:149777 gfx::PointF(), gfx::Size(30, 30), true, false,
9778 true);
sunxd71aea3e2016-04-01 23:48:059779 // TODO(sunxd): we make child have no render surface, because if the
9780 // child has one, the large transform applied to child will result in NaNs in
9781 // the draw_transform of the render_surface, thus make draw property updates
9782 // skip the child layer. We need further investigation into this to know
9783 // what exactly happens here.
9784 SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(),
jaydasika5160e672015-10-15 15:25:149785 gfx::PointF(), gfx::Size(30, 30), true, false,
sunxd71aea3e2016-04-01 23:48:059786 false);
jaydasika5160e672015-10-15 15:25:149787
9788 ExecuteCalculateDrawProperties(root);
9789
jaydasika5160e672015-10-15 15:25:149790 EXPECT_EQ(gfx::RectF(),
sunxd71aea3e2016-04-01 23:48:059791 render_surface1->render_surface()->DrawableContentRect());
9792
9793 bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) ||
9794 std::isnan(child->DrawTransform().matrix().get(0, 0));
9795 EXPECT_TRUE(is_inf_or_nan);
9796
9797 is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) ||
9798 std::isnan(child->DrawTransform().matrix().get(1, 1));
9799 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:149800
9801 std::vector<LayerImpl*>* rsll = render_surface_layer_list_impl();
9802 bool root_in_rsll =
9803 std::find(rsll->begin(), rsll->end(), root) != rsll->end();
9804 EXPECT_TRUE(root_in_rsll);
jaydasika5160e672015-10-15 15:25:149805}
9806
khushalsagar37694212016-01-15 20:46:489807TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) {
9808 LayerTreeHostCommon::ScrollUpdateInfo scroll;
9809 scroll.layer_id = 2;
9810 scroll.scroll_delta = gfx::Vector2d(5, 10);
9811
9812 proto::ScrollUpdateInfo proto;
9813 scroll.ToProtobuf(&proto);
9814 LayerTreeHostCommon::ScrollUpdateInfo new_scroll;
9815 new_scroll.FromProtobuf(proto);
9816
9817 EXPECT_EQ(scroll, new_scroll);
9818}
9819
9820TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) {
9821 ScrollAndScaleSet scroll_and_scale_set;
9822
9823 LayerTreeHostCommon::ScrollUpdateInfo scroll1;
9824 scroll1.layer_id = 1;
9825 scroll1.scroll_delta = gfx::Vector2d(5, 10);
9826 LayerTreeHostCommon::ScrollUpdateInfo scroll2;
9827 scroll2.layer_id = 2;
9828 scroll2.scroll_delta = gfx::Vector2d(1, 5);
9829 scroll_and_scale_set.scrolls.push_back(scroll1);
9830 scroll_and_scale_set.scrolls.push_back(scroll2);
9831
9832 scroll_and_scale_set.page_scale_delta = 0.3f;
9833 scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f);
9834 scroll_and_scale_set.top_controls_delta = 0.9f;
9835
9836 proto::ScrollAndScaleSet proto;
9837 scroll_and_scale_set.ToProtobuf(&proto);
9838 ScrollAndScaleSet new_scroll_and_scale_set;
9839 new_scroll_and_scale_set.FromProtobuf(proto);
9840
9841 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set));
9842}
9843
sunxdea1df782016-01-28 00:12:339844TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) {
9845 // Test the behavior of scroll tree builder
9846 // Topology:
sunxdcfccd1b32016-02-11 00:54:209847 // +root1(1)[inner_viewport_container_layer]
9848 // +-page_scale_layer
9849 // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling &
9850 // scrollable, inner_viewport_scroll_layer]
9851 // +------child6(6)[kScrollbarScrolling]
9852 // +--------grand_child10(10)[kScrollbarScrolling]
9853 // +----parent3(3)
9854 // +------child7(7)[scrollable]
9855 // +------child8(8)[scroll_parent=7]
9856 // +--------grand_child11(11)[scrollable]
9857 // +----parent4(4)
9858 // +------child9(9)
9859 // +--------grand_child12(12)
9860 // +----parent5(5)[contains_non_fast_scrollable_region]
sunxdea1df782016-01-28 00:12:339861 //
9862 // Expected scroll tree topology:
9863 // +property_tree_root---owner:-1
9864 // +--root---owner:1, id:1
9865 // +----node---owner:2, id:2
9866 // +------node---owner:6, id:3
9867 // +----node---owner:7, id:4
9868 // +------node---owner:11, id:5
9869 // +----node---owner:5, id:6
9870 //
9871 // Extra check:
9872 // scroll_tree_index() of:
9873 // grand_child10:3
9874 // parent3:1
9875 // child8:4
9876 // parent4:1
9877 // child9:1
9878 // grand_child12:1
loyso0940d412016-03-14 01:30:319879 scoped_refptr<Layer> root1 = Layer::Create();
9880 scoped_refptr<Layer> page_scale_layer = Layer::Create();
9881 scoped_refptr<Layer> parent2 = Layer::Create();
9882 scoped_refptr<Layer> parent3 = Layer::Create();
9883 scoped_refptr<Layer> parent4 = Layer::Create();
9884 scoped_refptr<Layer> parent5 = Layer::Create();
9885 scoped_refptr<Layer> child6 = Layer::Create();
9886 scoped_refptr<Layer> child7 = Layer::Create();
9887 scoped_refptr<Layer> child8 = Layer::Create();
9888 scoped_refptr<Layer> child9 = Layer::Create();
9889 scoped_refptr<Layer> grand_child10 = Layer::Create();
9890 scoped_refptr<Layer> grand_child11 = Layer::Create();
9891 scoped_refptr<Layer> grand_child12 = Layer::Create();
sunxdea1df782016-01-28 00:12:339892
sunxdcfccd1b32016-02-11 00:54:209893 root1->AddChild(page_scale_layer);
9894 page_scale_layer->AddChild(parent2);
9895 page_scale_layer->AddChild(parent3);
9896 page_scale_layer->AddChild(parent4);
9897 page_scale_layer->AddChild(parent5);
sunxdea1df782016-01-28 00:12:339898 parent2->AddChild(child6);
9899 parent3->AddChild(child7);
9900 parent3->AddChild(child8);
9901 parent4->AddChild(child9);
9902 child6->AddChild(grand_child10);
9903 child8->AddChild(grand_child11);
9904 child9->AddChild(grand_child12);
9905 host()->SetRootLayer(root1);
9906
9907 parent2->AddMainThreadScrollingReasons(
9908 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
sunxd29f17bf422016-02-03 02:47:489909 parent2->AddMainThreadScrollingReasons(
9910 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:339911 parent2->SetScrollClipLayerId(root1->id());
9912 child6->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:489913 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:339914 grand_child10->AddMainThreadScrollingReasons(
sunxd29f17bf422016-02-03 02:47:489915 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:339916
sunxdcfccd1b32016-02-11 00:54:209917 child7->SetScrollClipLayerId(parent3->id());
9918
sunxdea1df782016-01-28 00:12:339919 child8->SetScrollParent(child7.get());
sunxdcfccd1b32016-02-11 00:54:209920 grand_child11->SetScrollClipLayerId(parent3->id());
sunxdea1df782016-01-28 00:12:339921
9922 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
sunxdcfccd1b32016-02-11 00:54:209923 parent5->SetBounds(gfx::Size(10, 10));
sunxdea1df782016-01-28 00:12:339924
sunxdcfccd1b32016-02-11 00:54:209925 host()->RegisterViewportLayers(NULL, page_scale_layer, parent2, NULL);
sunxdea1df782016-01-28 00:12:339926 ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get());
9927
9928 const int kInvalidPropertyTreeNodeId = -1;
9929 const int kRootPropertyTreeNodeId = 0;
9930
9931 // Property tree root
9932 ScrollTree scroll_tree = host()->property_trees()->scroll_tree;
sunxdc36713a2016-03-03 22:31:109933 PropertyTrees property_trees;
sunxdc044b11a2016-03-16 16:23:209934 property_trees.is_main_thread = true;
9935 property_trees.is_active = false;
sunxdc36713a2016-03-03 22:31:109936 ScrollTree expected_scroll_tree = property_trees.scroll_tree;
sunxdea1df782016-01-28 00:12:339937 ScrollNode* property_tree_root = expected_scroll_tree.Node(0);
9938 property_tree_root->id = kRootPropertyTreeNodeId;
9939 property_tree_root->parent_id = kInvalidPropertyTreeNodeId;
9940 property_tree_root->owner_id = kInvalidPropertyTreeNodeId;
9941 property_tree_root->data.scrollable = false;
sunxd29f17bf422016-02-03 02:47:489942 property_tree_root->data.main_thread_scrolling_reasons =
9943 MainThreadScrollingReason::kNotScrollingOnMain;
sunxdea1df782016-01-28 00:12:339944 property_tree_root->data.contains_non_fast_scrollable_region = false;
sunxdd1abacf2016-02-16 22:08:309945 property_tree_root->data.transform_id = kRootPropertyTreeNodeId;
sunxdea1df782016-01-28 00:12:339946
9947 // The node owned by root1
9948 ScrollNode scroll_root1;
9949 scroll_root1.id = 1;
9950 scroll_root1.owner_id = root1->id();
sunxd54e08e9d2016-02-22 23:01:289951 scroll_root1.data.user_scrollable_horizontal = true;
9952 scroll_root1.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:309953 scroll_root1.data.transform_id = root1->transform_tree_index();
sunxdea1df782016-01-28 00:12:339954 expected_scroll_tree.Insert(scroll_root1, 0);
9955
9956 // The node owned by parent2
9957 ScrollNode scroll_parent2;
9958 scroll_parent2.id = 2;
9959 scroll_parent2.owner_id = parent2->id();
9960 scroll_parent2.data.scrollable = true;
sunxd29f17bf422016-02-03 02:47:489961 scroll_parent2.data.main_thread_scrolling_reasons =
9962 parent2->main_thread_scrolling_reasons();
sunxdcfccd1b32016-02-11 00:54:209963 scroll_parent2.data.scroll_clip_layer_bounds = root1->bounds();
9964 scroll_parent2.data.bounds = parent2->bounds();
9965 scroll_parent2.data.max_scroll_offset_affected_by_page_scale = true;
9966 scroll_parent2.data.is_inner_viewport_scroll_layer = true;
sunxd54e08e9d2016-02-22 23:01:289967 scroll_parent2.data.user_scrollable_horizontal = true;
9968 scroll_parent2.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:309969 scroll_parent2.data.transform_id = parent2->transform_tree_index();
sunxdea1df782016-01-28 00:12:339970 expected_scroll_tree.Insert(scroll_parent2, 1);
9971
9972 // The node owned by child6
9973 ScrollNode scroll_child6;
9974 scroll_child6.id = 3;
9975 scroll_child6.owner_id = child6->id();
sunxd29f17bf422016-02-03 02:47:489976 scroll_child6.data.main_thread_scrolling_reasons =
9977 child6->main_thread_scrolling_reasons();
sunxdd1abacf2016-02-16 22:08:309978 scroll_child6.data.should_flatten = true;
sunxd54e08e9d2016-02-22 23:01:289979 scroll_child6.data.user_scrollable_horizontal = true;
9980 scroll_child6.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:309981 scroll_child6.data.transform_id = child6->transform_tree_index();
sunxdea1df782016-01-28 00:12:339982 expected_scroll_tree.Insert(scroll_child6, 2);
9983
9984 // The node owned by child7, child7 also owns a transform node
9985 ScrollNode scroll_child7;
9986 scroll_child7.id = 4;
9987 scroll_child7.owner_id = child7->id();
9988 scroll_child7.data.scrollable = true;
sunxdd1abacf2016-02-16 22:08:309989 scroll_child7.data.scroll_clip_layer_bounds = parent3->bounds();
9990 scroll_child7.data.bounds = child7->bounds();
sunxd54e08e9d2016-02-22 23:01:289991 scroll_child7.data.user_scrollable_horizontal = true;
9992 scroll_child7.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:309993 scroll_child7.data.transform_id = child7->transform_tree_index();
sunxdea1df782016-01-28 00:12:339994 expected_scroll_tree.Insert(scroll_child7, 1);
9995
9996 // The node owned by grand_child11, grand_child11 also owns a transform node
9997 ScrollNode scroll_grand_child11;
9998 scroll_grand_child11.id = 5;
9999 scroll_grand_child11.owner_id = grand_child11->id();
10000 scroll_grand_child11.data.scrollable = true;
sunxd54e08e9d2016-02-22 23:01:2810001 scroll_grand_child11.data.user_scrollable_horizontal = true;
10002 scroll_grand_child11.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010003 scroll_grand_child11.data.transform_id =
10004 grand_child11->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310005 expected_scroll_tree.Insert(scroll_grand_child11, 4);
10006
10007 // The node owned by parent5
10008 ScrollNode scroll_parent5;
10009 scroll_parent5.id = 8;
10010 scroll_parent5.owner_id = parent5->id();
10011 scroll_parent5.data.contains_non_fast_scrollable_region = true;
sunxdcfccd1b32016-02-11 00:54:2010012 scroll_parent5.data.bounds = gfx::Size(10, 10);
sunxdd1abacf2016-02-16 22:08:3010013 scroll_parent5.data.should_flatten = true;
sunxd54e08e9d2016-02-22 23:01:2810014 scroll_parent5.data.user_scrollable_horizontal = true;
10015 scroll_parent5.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010016 scroll_parent5.data.transform_id = parent5->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310017 expected_scroll_tree.Insert(scroll_parent5, 1);
10018
sunxdc044b11a2016-03-16 16:23:2010019 expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0));
10020 expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0));
10021 expected_scroll_tree.SetScrollOffset(grand_child11->id(),
10022 gfx::ScrollOffset(0, 0));
sunxdea1df782016-01-28 00:12:3310023 expected_scroll_tree.set_needs_update(false);
10024
10025 EXPECT_EQ(expected_scroll_tree, scroll_tree);
10026
10027 // Check other layers' scroll_tree_index
sunxdcfccd1b32016-02-11 00:54:2010028 EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index());
sunxdea1df782016-01-28 00:12:3310029 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10030 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10031 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10032 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10033 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10034 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10035}
10036
[email protected]ba565742012-11-10 09:29:4810037} // namespace
10038} // namespace cc