blob: 4dab20808e9345b879e8d1122d9928b71e898fac [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>
danakj25c52c32016-04-12 21:51:0810#include <memory>
[email protected]995708c52013-10-17 20:52:5911#include <set>
vmpstra370ef52015-11-18 10:41:2812#include <vector>
[email protected]995708c52013-10-17 20:52:5913
danakj60bc3bc2016-04-09 00:24:4814#include "base/memory/ptr_util.h"
loyso968163c92016-01-04 23:18:4815#include "cc/animation/animation_host.h"
16#include "cc/animation/animation_id_provider.h"
sunxd71aea3e2016-04-01 23:48:0517#include "cc/animation/animation_player.h"
ajuma315a4782015-07-24 21:16:3418#include "cc/animation/keyframed_animation_curve.h"
[email protected]1c3626e2014-04-09 17:49:2219#include "cc/animation/transform_operations.h"
[email protected]681ccff2013-03-18 06:13:5220#include "cc/base/math_util.h"
sunxd29f17bf2016-02-03 02:47:4821#include "cc/input/main_thread_scrolling_reason.h"
[email protected]cc3cfaa2013-03-18 09:05:5222#include "cc/layers/content_layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5223#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5924#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5225#include "cc/layers/layer_impl.h"
[email protected]390bb1ff2014-05-09 17:14:4026#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2827#include "cc/layers/render_surface_impl.h"
[email protected]30fe19ff2013-07-04 00:54:4528#include "cc/output/copy_output_request.h"
29#include "cc/output/copy_output_result.h"
khushalsagar37694212016-01-15 20:46:4830#include "cc/proto/begin_main_frame_and_commit_state.pb.h"
31#include "cc/proto/gfx_conversions.h"
[email protected]101441ce2012-10-16 01:45:0332#include "cc/test/animation_test_common.h"
vollick2175fae82015-04-27 21:18:1233#include "cc/test/fake_content_layer_client.h"
khushalsagarb64b360d2015-10-21 19:25:1634#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]d600df7d2013-08-03 02:34:2835#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4536#include "cc/test/fake_layer_tree_host_impl.h"
ajumaae0dc2d2015-08-05 21:55:5637#include "cc/test/fake_output_surface.h"
sohan.jyotie3bd6192014-10-13 07:13:5938#include "cc/test/fake_picture_layer.h"
39#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0340#include "cc/test/geometry_test_utils.h"
[email protected]28336d52014-05-12 19:07:2841#include "cc/test/layer_tree_host_common_test.h"
reveman34b7a1522015-03-23 20:27:4742#include "cc/test/test_task_graph_runner.h"
ennef6903532015-08-18 05:10:1543#include "cc/trees/draw_property_utils.h"
[email protected]556fd292013-03-18 08:03:0444#include "cc/trees/layer_tree_impl.h"
[email protected]556fd292013-03-18 08:03:0445#include "cc/trees/single_thread_proxy.h"
khushalsagarb64b360d2015-10-21 19:25:1646#include "cc/trees/task_runner_provider.h"
[email protected]7f0c53db2012-10-02 00:23:1847#include "testing/gmock/include/gmock/gmock.h"
48#include "testing/gtest/include/gtest/gtest.h"
jbroman1c44d5b52016-06-06 21:19:3049#include "third_party/skia/include/effects/SkOffsetImageFilter.h"
heejin.r.chungd28506ba2014-10-23 16:36:2050#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3751#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0052#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1453
[email protected]ba565742012-11-10 09:29:4854namespace cc {
[email protected]94f206c12012-08-25 00:09:1455namespace {
56
[email protected]96baf3e2012-10-22 23:09:5557class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:3258 public:
loyso0940d412016-03-14 01:30:3159 LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:1460
dcheng716bedf2014-10-21 09:51:0861 bool DrawsContent() const override;
[email protected]d58499a2012-10-09 22:27:4762
[email protected]fb661802013-03-25 01:59:3263 private:
dcheng716bedf2014-10-21 09:51:0864 ~LayerWithForcedDrawsContent() override {}
[email protected]94f206c12012-08-25 00:09:1465};
66
[email protected]fb661802013-03-25 01:59:3267bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:4468
[email protected]96baf3e2012-10-22 23:09:5569class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:3270 public:
71 MockContentLayerClient() {}
dcheng716bedf2014-10-21 09:51:0872 ~MockContentLayerClient() override {}
chrishtr01539b802015-11-24 08:11:3273 gfx::Rect PaintableRegion() override { return gfx::Rect(); }
jbroman16d628c2015-05-29 20:11:5974 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
schenney0154bfa2015-02-05 19:46:4975 PaintingControlSetting picture_control) override {
ajuma5e77f7d42014-11-27 14:19:1476 NOTIMPLEMENTED();
jbroman16d628c2015-05-29 20:11:5977 return nullptr;
ajuma5e77f7d42014-11-27 14:19:1478 }
dcheng716bedf2014-10-21 09:51:0879 bool FillsBoundsCompletely() const override { return false; }
jbroman9f60f1a2015-07-16 21:40:3280 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
[email protected]f34a24232012-09-20 22:59:5581};
82
[email protected]989386c2013-07-18 21:37:2383#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
84 do { \
85 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
86 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:4787 } while (false)
88
enne637715732015-07-07 02:05:2689#define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
90 do { \
91 EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \
sohan.jyotie3bd6192014-10-13 07:13:5992 } while (false)
93
enne637715732015-07-07 02:05:2694class LayerTreeSettingsScaleContent : public LayerTreeSettings {
95 public:
96 LayerTreeSettingsScaleContent() {
97 layer_transforms_should_scale_layer_contents = true;
98 }
99};
100
101class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTest {
102 public:
103 LayerTreeHostCommonScalingTest()
104 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
105};
106
weiliangc6da32862016-04-20 16:40:11107class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest {
108 public:
109 LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {}
110
111 LayerImpl* TestVisibleRectAndDrawableContentRect(
112 const gfx::Rect& target_rect,
113 const gfx::Transform& layer_transform,
114 const gfx::Rect& layer_rect) {
115 LayerImpl* root = root_layer();
116 LayerImpl* target = AddChild<LayerImpl>(root);
117 LayerImpl* drawing_layer = AddChild<LayerImpl>(target);
118
119 root->SetDrawsContent(true);
120 target->SetDrawsContent(true);
121 target->SetMasksToBounds(true);
122 drawing_layer->SetDrawsContent(true);
123
124 gfx::Transform identity;
125
126 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
127 gfx::Size(500, 500), true, false, true);
128 SetLayerPropertiesForTesting(target, identity, gfx::Point3F(),
129 gfx::PointF(target_rect.origin()),
130 target_rect.size(), true, false, true);
131 SetLayerPropertiesForTesting(drawing_layer, layer_transform, gfx::Point3F(),
132 gfx::PointF(layer_rect.origin()),
133 layer_rect.size(), true, false, false);
134
135 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
136 ExecuteCalculateDrawProperties(root);
137
138 return drawing_layer;
139 }
140};
141
[email protected]989386c2013-07-18 21:37:23142TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32143 // Sanity check: For layers positioned at zero, with zero size,
144 // and with identity transforms, then the draw transform,
145 // screen space transform, and the hierarchy passed on to children
146 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14147
sunxdfd920f3f2016-04-05 16:17:51148 LayerImpl* parent = root_layer();
149 LayerImpl* child = AddChild<LayerImpl>(parent);
150 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28151
[email protected]fb661802013-03-25 01:59:32152 gfx::Transform identity_matrix;
sunxdfd920f3f2016-04-05 16:17:51153 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
154 gfx::PointF(), gfx::Size(100, 100), true, false);
155 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
156 gfx::PointF(), gfx::Size(), true, false);
157 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
158 gfx::PointF(), gfx::Size(), true, false);
[email protected]94f206c12012-08-25 00:09:14159
sunxdfd920f3f2016-04-05 16:17:51160 ExecuteCalculateDrawProperties(parent);
[email protected]94f206c12012-08-25 00:09:14161
sunxdfd920f3f2016-04-05 16:17:51162 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32163 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
sunxdfd920f3f2016-04-05 16:17:51164 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32165 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
sunxdfd920f3f2016-04-05 16:17:51166 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32167 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
sunxdfd920f3f2016-04-05 16:17:51168 grand_child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14169}
170
jaydasika322436372015-12-16 23:42:38171TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) {
172 // Tests that effect tree node gets a valid transform id when a layer
173 // has opacity but doesn't create a render surface.
174 LayerImpl* parent = root_layer();
175 LayerImpl* child = AddChild<LayerImpl>(parent);
176 child->SetDrawsContent(true);
177
178 gfx::Transform identity_matrix;
179 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
180 gfx::PointF(), gfx::Size(100, 100), true, false);
181 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
182 gfx::PointF(10, 10), gfx::Size(100, 100), true,
183 false);
jaydasikaab317e02016-06-01 00:53:18184 child->test_properties()->opacity = 0.f;
jaydasika322436372015-12-16 23:42:38185 ExecuteCalculateDrawProperties(parent);
ajumae4af47062016-05-24 23:59:04186 EffectTree& effect_tree =
jaydasika322436372015-12-16 23:42:38187 parent->layer_tree_impl()->property_trees()->effect_tree;
188 EffectNode* node = effect_tree.Node(child->effect_tree_index());
189 const int transform_tree_size = parent->layer_tree_impl()
190 ->property_trees()
191 ->transform_tree.next_available_id();
192 EXPECT_LT(node->data.transform_id, transform_tree_size);
193}
194
[email protected]989386c2013-07-18 21:37:23195TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32196 gfx::Transform identity_matrix;
sunxdfd920f3f2016-04-05 16:17:51197 LayerImpl* root = root_layer();
198 LayerImpl* layer = AddChild<LayerImpl>(root);
[email protected]94f206c12012-08-25 00:09:14199
sunxdfd920f3f2016-04-05 16:17:51200 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31201 gfx::PointF(), gfx::Size(1, 2), true, false);
[email protected]ecc12622012-10-30 20:45:42202
sunxdfd920f3f2016-04-05 16:17:51203 TransformTree& tree =
204 host_impl()->active_tree()->property_trees()->transform_tree;
enne826452722015-08-18 22:22:31205
[email protected]fb661802013-03-25 01:59:32206 // Case 2: Setting the bounds of the layer should not affect either the draw
207 // transform or the screenspace transform.
208 gfx::Transform translation_to_center;
209 translation_to_center.Translate(5.0, 6.0);
sunxdfd920f3f2016-04-05 16:17:51210 SetLayerPropertiesForTesting(layer, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31211 gfx::PointF(), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51212 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31213 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51214 identity_matrix, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31215 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51216 identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14217
[email protected]fb661802013-03-25 01:59:32218 // Case 3: The anchor point by itself (without a layer transform) should have
219 // no effect on the transforms.
sunxdfd920f3f2016-04-05 16:17:51220 SetLayerPropertiesForTesting(layer, identity_matrix,
enne826452722015-08-18 22:22:31221 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
222 gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51223 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
224 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31225 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51226 identity_matrix, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31227 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51228 identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14229
[email protected]fb661802013-03-25 01:59:32230 // Case 4: A change in actual position affects both the draw transform and
231 // screen space transform.
232 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05233 position_transform.Translate(0.f, 1.2f);
enne826452722015-08-18 22:22:31234 SetLayerPropertiesForTesting(
sunxdfd920f3f2016-04-05 16:17:51235 layer, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
enne826452722015-08-18 22:22:31236 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51237 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
238 ExecuteCalculateDrawProperties(root);
239 EXPECT_TRANSFORMATION_MATRIX_EQ(
240 position_transform, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31241 EXPECT_TRANSFORMATION_MATRIX_EQ(
weiliangcc97575c2016-03-03 18:34:27242 position_transform,
sunxdfd920f3f2016-04-05 16:17:51243 draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14244
[email protected]fb661802013-03-25 01:59:32245 // Case 5: In the correct sequence of transforms, the layer transform should
246 // pre-multiply the translation_to_center. This is easily tested by using a
247 // scale transform, because scale and translation are not commutative.
248 gfx::Transform layer_transform;
249 layer_transform.Scale3d(2.0, 2.0, 1.0);
sunxdfd920f3f2016-04-05 16:17:51250 SetLayerPropertiesForTesting(layer, layer_transform, gfx::Point3F(),
enne826452722015-08-18 22:22:31251 gfx::PointF(), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51252 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
253 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31254 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51255 layer_transform, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31256 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51257 layer_transform, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14258
[email protected]fb661802013-03-25 01:59:32259 // Case 6: The layer transform should occur with respect to the anchor point.
260 gfx::Transform translation_to_anchor;
261 translation_to_anchor.Translate(5.0, 0.0);
262 gfx::Transform expected_result =
263 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
sunxdfd920f3f2016-04-05 16:17:51264 SetLayerPropertiesForTesting(layer, layer_transform,
enne826452722015-08-18 22:22:31265 gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(),
266 gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51267 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
268 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31269 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51270 expected_result, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31271 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51272 expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14273
[email protected]fb661802013-03-25 01:59:32274 // Case 7: Verify that position pre-multiplies the layer transform. The
275 // current implementation of CalculateDrawProperties does this implicitly, but
276 // it is still worth testing to detect accidental regressions.
277 expected_result = position_transform * translation_to_anchor *
278 layer_transform * Inverse(translation_to_anchor);
enne826452722015-08-18 22:22:31279 SetLayerPropertiesForTesting(
sunxdfd920f3f2016-04-05 16:17:51280 layer, layer_transform, gfx::Point3F(5.0f, 0.f, 0.f),
enne826452722015-08-18 22:22:31281 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51282 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
283 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31284 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51285 expected_result, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31286 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51287 expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14288}
289
[email protected]989386c2013-07-18 21:37:23290TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13291 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32292 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01293 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32294 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
295 -kScrollOffset.y());
jaydasikaa534a472016-03-31 01:12:16296 float page_scale = 0.888f;
[email protected]fb661802013-03-25 01:59:32297 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20298
khushalsagarb64b360d2015-10-21 19:25:16299 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:45300 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:56301 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:16302 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:56303 &task_graph_runner);
[email protected]657b24c2013-03-06 09:01:20304
[email protected]fb661802013-03-25 01:59:32305 gfx::Transform identity_matrix;
danakj60bc3bc2016-04-09 00:24:48306 std::unique_ptr<LayerImpl> sublayer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32307 LayerImpl::Create(host_impl.active_tree(), 1));
308 LayerImpl* sublayer = sublayer_scoped_ptr.get();
jaydasika0d98ba92015-11-17 05:17:28309 sublayer->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:00310 SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(),
311 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:32312 false);
[email protected]657b24c2013-03-06 09:01:20313
danakj60bc3bc2016-04-09 00:24:48314 std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32315 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47316 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
awoloszyne83f28c2014-12-22 15:40:00317 SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(),
318 gfx::PointF(), gfx::Size(10, 20), true, false,
[email protected]fb661802013-03-25 01:59:32319 false);
danakj60bc3bc2016-04-09 00:24:48320 std::unique_ptr<LayerImpl> clip_layer_scoped_ptr(
[email protected]adeda572014-01-31 00:49:47321 LayerImpl::Create(host_impl.active_tree(), 4));
322 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
323
324 scroll_layer->SetScrollClipLayer(clip_layer->id());
325 clip_layer->SetBounds(
326 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
327 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
328 scroll_layer->SetScrollClipLayer(clip_layer->id());
sunxdb7e79432016-03-09 21:13:42329 SetScrollOffsetDelta(scroll_layer, kScrollDelta);
[email protected]fb661802013-03-25 01:59:32330 gfx::Transform impl_transform;
danakja04855a2015-11-18 20:39:10331 scroll_layer->AddChild(std::move(sublayer_scoped_ptr));
[email protected]adeda572014-01-31 00:49:47332 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
danakja04855a2015-11-18 20:39:10333 clip_layer->AddChild(std::move(scroll_layer_scoped_ptr));
sunxdb7e79432016-03-09 21:13:42334 scroll_layer_raw_ptr->layer_tree_impl()
335 ->property_trees()
336 ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(),
337 kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20338
danakj60bc3bc2016-04-09 00:24:48339 std::unique_ptr<LayerImpl> root(
340 LayerImpl::Create(host_impl.active_tree(), 3));
awoloszyne83f28c2014-12-22 15:40:00341 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
342 gfx::PointF(), gfx::Size(3, 4), true, false,
[email protected]fb661802013-03-25 01:59:32343 false);
danakja04855a2015-11-18 20:39:10344 root->AddChild(std::move(clip_layer_scoped_ptr));
awoloszyne83f28c2014-12-22 15:40:00345 root->SetHasRenderSurface(true);
jaydasika2411692c2016-03-23 01:56:09346 LayerImpl* root_layer = root.get();
347 host_impl.active_tree()->SetRootLayer(std::move(root));
[email protected]657b24c2013-03-06 09:01:20348
jaydasikaa534a472016-03-31 01:12:16349 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
jaydasika2411692c2016-03-23 01:56:09350 scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32351 gfx::Transform expected_transform = identity_matrix;
352 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
danakj2c8d12c2015-06-18 06:15:33353 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
jaydasikaa534a472016-03-31 01:12:16354 page_scale * kDeviceScale),
danakj2c8d12c2015-06-18 06:15:33355 MathUtil::Round(sub_layer_screen_position.y() *
jaydasikaa534a472016-03-31 01:12:16356 page_scale * kDeviceScale));
357 expected_transform.Scale(page_scale * kDeviceScale,
358 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32359 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44360 sublayer->DrawTransform());
[email protected]fb661802013-03-25 01:59:32361 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumab6aa1c62015-12-01 21:01:10362 sublayer->ScreenSpaceTransform());
[email protected]657b24c2013-03-06 09:01:20363
[email protected]fb661802013-03-25 01:59:32364 gfx::Transform arbitrary_translate;
365 const float kTranslateX = 10.6f;
366 const float kTranslateY = 20.6f;
367 arbitrary_translate.Translate(kTranslateX, kTranslateY);
awoloszyne83f28c2014-12-22 15:40:00368 SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate,
369 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
370 true, false, false);
jaydasika2411692c2016-03-23 01:56:09371 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaa534a472016-03-31 01:12:16372 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
jaydasika2411692c2016-03-23 01:56:09373 scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32374 expected_transform.MakeIdentity();
375 expected_transform.Translate(
jaydasikaa534a472016-03-31 01:12:16376 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
377 sub_layer_screen_position.x() * page_scale *
danakj2c8d12c2015-06-18 06:15:33378 kDeviceScale),
jaydasikaa534a472016-03-31 01:12:16379 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
380 sub_layer_screen_position.y() * page_scale *
danakj2c8d12c2015-06-18 06:15:33381 kDeviceScale));
jaydasikaa534a472016-03-31 01:12:16382 expected_transform.Scale(page_scale * kDeviceScale,
383 page_scale * kDeviceScale);
384 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
385 sublayer->DrawTransform());
386
387 // Test that page scale is updated even when we don't rebuild property trees.
388 page_scale = 1.888f;
389 root_layer->layer_tree_impl()->SetViewportLayersFromIds(
390 Layer::INVALID_ID, scroll_layer->parent()->id(), Layer::INVALID_ID,
391 Layer::INVALID_ID);
392 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale);
393 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild);
394 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
395 scroll_layer->parent());
396
397 expected_transform.MakeIdentity();
398 expected_transform.Translate(
399 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
400 sub_layer_screen_position.x() * page_scale *
401 kDeviceScale),
402 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
403 sub_layer_screen_position.y() * page_scale *
404 kDeviceScale));
405 expected_transform.Scale(page_scale * kDeviceScale,
406 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32407 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44408 sublayer->DrawTransform());
[email protected]657b24c2013-03-06 09:01:20409}
410
[email protected]989386c2013-07-18 21:37:23411TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32412 gfx::Transform identity_matrix;
sunxdfd920f3f2016-04-05 16:17:51413 LayerImpl* root = root_layer();
414 LayerImpl* parent = AddChild<LayerImpl>(root);
415 LayerImpl* child = AddChild<LayerImpl>(parent);
416 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28417
[email protected]fb661802013-03-25 01:59:32418 // One-time setup of root layer
sunxdfd920f3f2016-04-05 16:17:51419 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31420 gfx::PointF(), gfx::Size(1, 2), true, false);
421
sunxdfd920f3f2016-04-05 16:17:51422 TransformTree& tree =
423 host_impl()->active_tree()->property_trees()->transform_tree;
[email protected]ecc12622012-10-30 20:45:42424
[email protected]fb661802013-03-25 01:59:32425 // Case 1: parent's anchor point should not affect child or grand_child.
sunxdfd920f3f2016-04-05 16:17:51426 SetLayerPropertiesForTesting(parent, identity_matrix,
enne826452722015-08-18 22:22:31427 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
428 gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51429 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31430 gfx::PointF(), gfx::Size(16, 18), true, false);
sunxdfd920f3f2016-04-05 16:17:51431 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
432 gfx::PointF(), gfx::Size(76, 78), true, false);
433 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31434
435 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51436 identity_matrix, draw_property_utils::DrawTransform(child, tree));
437 EXPECT_TRANSFORMATION_MATRIX_EQ(
438 identity_matrix, draw_property_utils::ScreenSpaceTransform(child, tree));
439 EXPECT_TRANSFORMATION_MATRIX_EQ(
440 identity_matrix, draw_property_utils::DrawTransform(grand_child, tree));
enne826452722015-08-18 22:22:31441 EXPECT_TRANSFORMATION_MATRIX_EQ(
442 identity_matrix,
sunxdfd920f3f2016-04-05 16:17:51443 draw_property_utils::ScreenSpaceTransform(grand_child, tree));
[email protected]94f206c12012-08-25 00:09:14444
[email protected]fb661802013-03-25 01:59:32445 // Case 2: parent's position affects child and grand_child.
446 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05447 parent_position_transform.Translate(0.f, 1.2f);
enne826452722015-08-18 22:22:31448 SetLayerPropertiesForTesting(
sunxdfd920f3f2016-04-05 16:17:51449 parent, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
enne826452722015-08-18 22:22:31450 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51451 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31452 gfx::PointF(), gfx::Size(16, 18), true, false);
sunxdfd920f3f2016-04-05 16:17:51453 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
454 gfx::PointF(), gfx::Size(76, 78), true, false);
455 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
456 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31457 EXPECT_TRANSFORMATION_MATRIX_EQ(
458 parent_position_transform,
sunxdfd920f3f2016-04-05 16:17:51459 draw_property_utils::DrawTransform(child, tree));
enne826452722015-08-18 22:22:31460 EXPECT_TRANSFORMATION_MATRIX_EQ(
461 parent_position_transform,
sunxdfd920f3f2016-04-05 16:17:51462 draw_property_utils::ScreenSpaceTransform(child, tree));
enne826452722015-08-18 22:22:31463 EXPECT_TRANSFORMATION_MATRIX_EQ(
464 parent_position_transform,
sunxdfd920f3f2016-04-05 16:17:51465 draw_property_utils::DrawTransform(grand_child, tree));
enne826452722015-08-18 22:22:31466 EXPECT_TRANSFORMATION_MATRIX_EQ(
467 parent_position_transform,
sunxdfd920f3f2016-04-05 16:17:51468 draw_property_utils::ScreenSpaceTransform(grand_child, tree));
[email protected]94f206c12012-08-25 00:09:14469
[email protected]fb661802013-03-25 01:59:32470 // Case 3: parent's local transform affects child and grandchild
471 gfx::Transform parent_layer_transform;
472 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
473 gfx::Transform parent_translation_to_anchor;
474 parent_translation_to_anchor.Translate(2.5, 3.0);
475 gfx::Transform parent_composite_transform =
476 parent_translation_to_anchor * parent_layer_transform *
477 Inverse(parent_translation_to_anchor);
sunxdfd920f3f2016-04-05 16:17:51478 SetLayerPropertiesForTesting(parent, parent_layer_transform,
enne826452722015-08-18 22:22:31479 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
480 gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51481 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31482 gfx::PointF(), gfx::Size(16, 18), true, false);
sunxdfd920f3f2016-04-05 16:17:51483 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
484 gfx::PointF(), gfx::Size(76, 78), true, false);
485 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
486 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31487 EXPECT_TRANSFORMATION_MATRIX_EQ(
488 parent_composite_transform,
sunxdfd920f3f2016-04-05 16:17:51489 draw_property_utils::DrawTransform(child, tree));
enne826452722015-08-18 22:22:31490 EXPECT_TRANSFORMATION_MATRIX_EQ(
491 parent_composite_transform,
sunxdfd920f3f2016-04-05 16:17:51492 draw_property_utils::ScreenSpaceTransform(child, tree));
enne826452722015-08-18 22:22:31493 EXPECT_TRANSFORMATION_MATRIX_EQ(
494 parent_composite_transform,
sunxdfd920f3f2016-04-05 16:17:51495 draw_property_utils::DrawTransform(grand_child, tree));
enne826452722015-08-18 22:22:31496 EXPECT_TRANSFORMATION_MATRIX_EQ(
497 parent_composite_transform,
sunxdfd920f3f2016-04-05 16:17:51498 draw_property_utils::ScreenSpaceTransform(grand_child, tree));
[email protected]94f206c12012-08-25 00:09:14499}
500
[email protected]989386c2013-07-18 21:37:23501TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
enne25dea3f2015-07-27 16:44:28502 LayerImpl* root = root_layer();
503 LayerImpl* parent = AddChildToRoot<LayerImpl>();
504 LayerImpl* child = AddChild<LayerImpl>(parent);
505 LayerImpl* grand_child = AddChild<LayerImpl>(child);
506 grand_child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:14507
[email protected]fb661802013-03-25 01:59:32508 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28509 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
510 gfx::PointF(), gfx::Size(1, 2), true, false,
511 true);
[email protected]ecc12622012-10-30 20:45:42512
[email protected]fb661802013-03-25 01:59:32513 // Child is set up so that a new render surface should be created.
jaydasikaab317e02016-06-01 00:53:18514 child->test_properties()->opacity = 0.5f;
jaydasika8640f9f2015-11-10 01:34:36515 child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:14516
[email protected]fb661802013-03-25 01:59:32517 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05518 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32519 gfx::Transform parent_translation_to_anchor;
520 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44521
[email protected]fb661802013-03-25 01:59:32522 gfx::Transform parent_composite_transform =
523 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39524 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32525 gfx::Vector2dF parent_composite_scale =
526 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
527 1.f);
528 gfx::Transform surface_sublayer_transform;
529 surface_sublayer_transform.Scale(parent_composite_scale.x(),
530 parent_composite_scale.y());
531 gfx::Transform surface_sublayer_composite_transform =
532 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14533
enne25dea3f2015-07-27 16:44:28534 SetLayerPropertiesForTesting(parent, parent_layer_transform,
535 gfx::Point3F(25.0f, 30.0f, 0.f), gfx::PointF(),
536 gfx::Size(100, 120), true, false, false);
537 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
538 gfx::PointF(), gfx::Size(16, 18), true, false,
539 true);
540 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
541 gfx::PointF(), gfx::Size(8, 10), true, false,
[email protected]fb661802013-03-25 01:59:32542 false);
enne25dea3f2015-07-27 16:44:28543 ExecuteCalculateDrawProperties(root);
[email protected]94f206c12012-08-25 00:09:14544
[email protected]fb661802013-03-25 01:59:32545 // Render surface should have been created now.
546 ASSERT_TRUE(child->render_surface());
weiliangc189c1a12016-04-11 16:16:25547 ASSERT_EQ(child->render_surface(), child->render_target());
[email protected]94f206c12012-08-25 00:09:14548
[email protected]fb661802013-03-25 01:59:32549 // The child layer's draw transform should refer to its new render surface.
550 // The screen-space transform, however, should still refer to the root.
551 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
ajumad9432e32015-11-30 19:43:44552 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32553 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
ajumab6aa1c62015-12-01 21:01:10554 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14555
[email protected]fb661802013-03-25 01:59:32556 // Because the grand_child is the only drawable content, the child's render
557 // surface will tighten its bounds to the grand_child. The scale at which the
558 // surface's subtree is drawn must be removed from the composite transform.
weiliangc189c1a12016-04-11 16:16:25559 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform,
560 child->render_target()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14561
[email protected]fb661802013-03-25 01:59:32562 // The screen space is the same as the target since the child surface draws
563 // into the root.
564 EXPECT_TRANSFORMATION_MATRIX_EQ(
565 surface_sublayer_composite_transform,
weiliangc189c1a12016-04-11 16:16:25566 child->render_target()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14567}
568
ajuma51d73f72015-10-19 19:43:58569TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) {
570 LayerImpl* root = root_layer();
571 LayerImpl* parent = AddChildToRoot<LayerImpl>();
572 LayerImpl* child = AddChild<LayerImpl>(parent);
573 LayerImpl* grand_child = AddChild<LayerImpl>(child);
574 grand_child->SetDrawsContent(true);
575
576 gfx::Transform identity_matrix;
577 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
578 gfx::PointF(), gfx::Size(100, 100), true, false,
579 true);
580
581 gfx::Transform parent_transform;
582 parent_transform.Translate(10.0, 10.0);
583
584 gfx::Transform child_transform;
585 child_transform.Rotate(45.0);
586
587 // child gets a render surface when surfaces are enabled.
588 SetLayerPropertiesForTesting(parent, parent_transform, gfx::Point3F(),
589 gfx::PointF(), gfx::Size(10, 10), true, false,
590 false);
591 SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(),
592 gfx::PointF(), gfx::Size(10, 10), true, false,
593 true);
594 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
595 gfx::PointF(2.0, 2.0), gfx::Size(20, 20), true,
596 false, false);
597
598 gfx::Transform expected_grand_child_screen_space_transform;
599 expected_grand_child_screen_space_transform.Translate(10.0, 10.0);
600 expected_grand_child_screen_space_transform.Rotate(45.0);
601 expected_grand_child_screen_space_transform.Translate(2.0, 2.0);
602
603 // First compute draw properties with separate surfaces enabled.
604 ExecuteCalculateDrawProperties(root);
605
606 // The grand child's draw transform should be its offset wrt the child.
607 gfx::Transform expected_grand_child_draw_transform;
608 expected_grand_child_draw_transform.Translate(2.0, 2.0);
609 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44610 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58611 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10612 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58613
614 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
615
616 // With separate surfaces disabled, the grand child's draw transform should be
617 // the same as its screen space transform.
618 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumad9432e32015-11-30 19:43:44619 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58620 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10621 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58622}
623
[email protected]989386c2013-07-18 21:37:23624TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
enne25dea3f2015-07-27 16:44:28625 LayerImpl* root = root_layer();
626 LayerImpl* parent = AddChildToRoot<LayerImpl>();
627 LayerImpl* child = AddChild<LayerImpl>(parent);
628 LayerImpl* grand_child = AddChild<LayerImpl>(child);
629 grand_child->SetDrawsContent(true);
danakj60bc3bc2016-04-09 00:24:48630 std::unique_ptr<LayerImpl> child_replica =
enne25dea3f2015-07-27 16:44:28631 LayerImpl::Create(host_impl()->active_tree(), 100);
[email protected]d600df7d2013-08-03 02:34:28632
[email protected]fb661802013-03-25 01:59:32633 // One-time setup of root layer
634 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28635 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
636 gfx::PointF(), gfx::Size(1, 2), true, false,
637 true);
[email protected]fb661802013-03-25 01:59:32638
639 // Child is set up so that a new render surface should be created.
jaydasikaab317e02016-06-01 00:53:18640 child->test_properties()->opacity = 0.5f;
[email protected]fb661802013-03-25 01:59:32641
642 gfx::Transform parent_layer_transform;
643 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
644 gfx::Transform parent_translation_to_anchor;
645 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32646 gfx::Transform parent_composite_transform =
647 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39648 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32649 gfx::Transform replica_layer_transform;
650 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
651 gfx::Vector2dF parent_composite_scale =
652 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
653 1.f);
654 gfx::Transform surface_sublayer_transform;
655 surface_sublayer_transform.Scale(parent_composite_scale.x(),
656 parent_composite_scale.y());
657 gfx::Transform replica_composite_transform =
658 parent_composite_transform * replica_layer_transform *
659 Inverse(surface_sublayer_transform);
enne25dea3f2015-07-27 16:44:28660 child_replica->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32661 // Child's render surface should not exist yet.
662 ASSERT_FALSE(child->render_surface());
663
enne25dea3f2015-07-27 16:44:28664 SetLayerPropertiesForTesting(parent, parent_layer_transform,
665 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
666 gfx::Size(10, 12), true, false, false);
667 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
668 gfx::PointF(), gfx::Size(16, 18), true, false,
669 true);
670 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
671 gfx::PointF(-0.5f, -0.5f), gfx::Size(1, 1), true,
672 false, false);
673 SetLayerPropertiesForTesting(child_replica.get(), replica_layer_transform,
674 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
675 false, false);
danakja04855a2015-11-18 20:39:10676 child->SetReplicaLayer(std::move(child_replica));
enne25dea3f2015-07-27 16:44:28677
678 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32679
680 // Render surface should have been created now.
681 ASSERT_TRUE(child->render_surface());
weiliangc189c1a12016-04-11 16:16:25682 ASSERT_EQ(child->render_surface(), child->render_target());
[email protected]fb661802013-03-25 01:59:32683
684 EXPECT_TRANSFORMATION_MATRIX_EQ(
685 replica_composite_transform,
weiliangc189c1a12016-04-11 16:16:25686 child->render_target()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:32687 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57688 child->render_target()
[email protected]fb661802013-03-25 01:59:32689 ->replica_screen_space_transform());
690}
691
[email protected]989386c2013-07-18 21:37:23692TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32693 // This test creates a more complex tree and verifies it all at once. This
694 // covers the following cases:
695 // - layers that are described w.r.t. a render surface: should have draw
696 // transforms described w.r.t. that surface
697 // - A render surface described w.r.t. an ancestor render surface: should
698 // have a draw transform described w.r.t. that ancestor surface
699 // - Replicas of a render surface are described w.r.t. the replica's
700 // transform around its anchor, along with the surface itself.
701 // - Sanity check on recursion: verify transforms of layers described w.r.t.
702 // a render surface that is described w.r.t. an ancestor render surface.
703 // - verifying that each layer has a reference to the correct render surface
704 // and render target values.
705
enne25dea3f2015-07-27 16:44:28706 LayerImpl* root = root_layer();
707 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36708 parent->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28709 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36710 render_surface1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28711 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36712 render_surface2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28713 LayerImpl* child_of_root = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36714 child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28715 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36716 child_of_rs1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28717 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:36718 child_of_rs2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28719 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
jaydasika8640f9f2015-11-10 01:34:36720 grand_child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28721 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
722 grand_child_of_rs1->SetDrawsContent(true);
723 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
724 grand_child_of_rs2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32725
danakj60bc3bc2016-04-09 00:24:48726 std::unique_ptr<LayerImpl> replica_of_rs1 =
enne25dea3f2015-07-27 16:44:28727 LayerImpl::Create(host_impl()->active_tree(), 101);
danakj60bc3bc2016-04-09 00:24:48728 std::unique_ptr<LayerImpl> replica_of_rs2 =
enne25dea3f2015-07-27 16:44:28729 LayerImpl::Create(host_impl()->active_tree(), 102);
[email protected]d600df7d2013-08-03 02:34:28730
[email protected]fb661802013-03-25 01:59:32731 // In combination with descendant draws content, opacity != 1 forces the layer
732 // to have a new render surface.
jaydasikaab317e02016-06-01 00:53:18733 render_surface1->test_properties()->opacity = 0.5f;
734 render_surface2->test_properties()->opacity = 0.33f;
[email protected]fb661802013-03-25 01:59:32735
736 // One-time setup of root layer
737 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28738 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
739 gfx::PointF(), gfx::Size(1, 2), true, false,
740 true);
[email protected]fb661802013-03-25 01:59:32741
742 // All layers in the tree are initialized with an anchor at .25 and a size of
743 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39744 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32745 gfx::Transform translation_to_anchor;
746 translation_to_anchor.Translate(2.5, 0.0);
747 gfx::Transform layer_transform;
748 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32749 gfx::Transform replica_layer_transform;
750 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
751
752 gfx::Transform A =
753 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32754 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
755 Inverse(translation_to_anchor);
756
757 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39758 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32759 gfx::Transform surface1_sublayer_transform;
760 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
761 surface1_parent_transform_scale.y());
762
763 // SS1 = transform given to the subtree of render_surface1
764 gfx::Transform SS1 = surface1_sublayer_transform;
765 // S1 = transform to move from render_surface1 pixels to the layer space of
766 // the owning layer
767 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
768
769 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39770 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32771 gfx::Transform surface2_sublayer_transform;
772 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
773 surface2_parent_transform_scale.y());
774
775 // SS2 = transform given to the subtree of render_surface2
776 gfx::Transform SS2 = surface2_sublayer_transform;
777 // S2 = transform to move from render_surface2 pixels to the layer space of
778 // the owning layer
779 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
780
enne25dea3f2015-07-27 16:44:28781 SetLayerPropertiesForTesting(parent, layer_transform,
782 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
783 gfx::Size(10, 10), true, false, false);
784 SetLayerPropertiesForTesting(render_surface1, layer_transform,
785 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
786 gfx::Size(10, 10), true, false, true);
787 SetLayerPropertiesForTesting(render_surface2, layer_transform,
788 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
789 gfx::Size(10, 10), true, false, true);
790 SetLayerPropertiesForTesting(child_of_root, layer_transform,
791 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
792 gfx::Size(10, 10), true, false, false);
793 SetLayerPropertiesForTesting(child_of_rs1, layer_transform,
794 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
795 gfx::Size(10, 10), true, false, false);
796 SetLayerPropertiesForTesting(child_of_rs2, layer_transform,
797 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
798 gfx::Size(10, 10), true, false, false);
799 SetLayerPropertiesForTesting(grand_child_of_root, layer_transform,
800 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
801 gfx::Size(10, 10), true, false, false);
802 SetLayerPropertiesForTesting(grand_child_of_rs1, layer_transform,
803 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
804 gfx::Size(10, 10), true, false, false);
805 SetLayerPropertiesForTesting(grand_child_of_rs2, layer_transform,
806 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
807 gfx::Size(10, 10), true, false, false);
808 SetLayerPropertiesForTesting(replica_of_rs1.get(), replica_layer_transform,
809 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
810 gfx::Size(), true, false, false);
811 SetLayerPropertiesForTesting(replica_of_rs2.get(), replica_layer_transform,
812 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
813 gfx::Size(), true, false, false);
[email protected]fb661802013-03-25 01:59:32814
jaydasika5017a332016-03-31 01:06:22815 // We need to set parent on replica layers for property tree building.
816 replica_of_rs1->SetParent(render_surface1);
817 replica_of_rs2->SetParent(render_surface2);
danakja04855a2015-11-18 20:39:10818 render_surface1->SetReplicaLayer(std::move(replica_of_rs1));
819 render_surface2->SetReplicaLayer(std::move(replica_of_rs2));
enne25dea3f2015-07-27 16:44:28820 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32821
822 // Only layers that are associated with render surfaces should have an actual
823 // RenderSurface() value.
824 ASSERT_TRUE(root->render_surface());
825 ASSERT_FALSE(child_of_root->render_surface());
826 ASSERT_FALSE(grand_child_of_root->render_surface());
827
828 ASSERT_TRUE(render_surface1->render_surface());
829 ASSERT_FALSE(child_of_rs1->render_surface());
830 ASSERT_FALSE(grand_child_of_rs1->render_surface());
831
832 ASSERT_TRUE(render_surface2->render_surface());
833 ASSERT_FALSE(child_of_rs2->render_surface());
834 ASSERT_FALSE(grand_child_of_rs2->render_surface());
835
836 // Verify all render target accessors
weiliangc189c1a12016-04-11 16:16:25837 EXPECT_EQ(root->render_surface(), parent->render_target());
838 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
839 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32840
weiliangc189c1a12016-04-11 16:16:25841 EXPECT_EQ(render_surface1->render_surface(),
842 render_surface1->render_target());
843 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
844 EXPECT_EQ(render_surface1->render_surface(),
845 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32846
weiliangc189c1a12016-04-11 16:16:25847 EXPECT_EQ(render_surface2->render_surface(),
848 render_surface2->render_target());
849 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
850 EXPECT_EQ(render_surface2->render_surface(),
851 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32852
853 // Verify layer draw transforms note that draw transforms are described with
854 // respect to the nearest ancestor render surface but screen space transforms
855 // are described with respect to the root.
ajumad9432e32015-11-30 19:43:44856 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform());
857 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39858 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumad9432e32015-11-30 19:43:44859 grand_child_of_root->DrawTransform());
[email protected]fb661802013-03-25 01:59:32860
ajumad9432e32015-11-30 19:43:44861 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform());
862 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39863 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
ajumad9432e32015-11-30 19:43:44864 grand_child_of_rs1->DrawTransform());
[email protected]fb661802013-03-25 01:59:32865
ajumad9432e32015-11-30 19:43:44866 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform());
867 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39868 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
ajumad9432e32015-11-30 19:43:44869 grand_child_of_rs2->DrawTransform());
[email protected]fb661802013-03-25 01:59:32870
871 // Verify layer screen-space transforms
872 //
ajumab6aa1c62015-12-01 21:01:10873 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform());
874 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform());
875 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
876 grand_child_of_root->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32877
[email protected]baf64d062014-02-16 22:10:39878 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
ajumab6aa1c62015-12-01 21:01:10879 render_surface1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39880 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10881 child_of_rs1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39882 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10883 grand_child_of_rs1->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32884
[email protected]baf64d062014-02-16 22:10:39885 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10886 render_surface2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39887 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10888 child_of_rs2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39889 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10890 grand_child_of_rs2->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32891
892 // Verify render surface transforms.
893 //
894 // Draw transform of render surface 1 is described with respect to root.
895 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39896 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32897 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39898 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:32899 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39900 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32901 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39902 A * R * S1,
[email protected]fb661802013-03-25 01:59:32903 render_surface1->render_surface()->replica_screen_space_transform());
904 // Draw transform of render surface 2 is described with respect to render
905 // surface 1.
906 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39907 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32908 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39909 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:32910 render_surface2->render_surface()->replica_draw_transform());
911 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39912 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:32913 render_surface2->render_surface()->screen_space_transform());
914 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39915 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:32916 render_surface2->render_surface()->replica_screen_space_transform());
917
918 // Sanity check. If these fail there is probably a bug in the test itself. It
919 // is expected that we correctly set up transforms so that the y-component of
920 // the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:10921 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:26922 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:10923 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32924 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10925 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32926
[email protected]803f6b52013-09-12 00:51:26927 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:10928 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
929 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32930 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10931 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32932
[email protected]803f6b52013-09-12 00:51:26933 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:10934 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
935 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32936 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10937 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32938}
939
[email protected]989386c2013-07-18 21:37:23940TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:32941 // For layers that flatten their subtree, there should be an orthographic
942 // projection (for x and y values) in the middle of the transform sequence.
943 // Note that the way the code is currently implemented, it is not expected to
944 // use a canonical orthographic projection.
945
enne25dea3f2015-07-27 16:44:28946 LayerImpl* root = root_layer();
947 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36948 child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28949 LayerImpl* grand_child = AddChild<LayerImpl>(child);
950 grand_child->SetDrawsContent(true);
951 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
952 great_grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32953
954 gfx::Transform rotation_about_y_axis;
955 rotation_about_y_axis.RotateAboutYAxis(30.0);
956
957 const gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28958 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
959 gfx::PointF(), gfx::Size(100, 100), true, false,
960 true);
961 SetLayerPropertiesForTesting(child, rotation_about_y_axis, gfx::Point3F(),
962 gfx::PointF(), gfx::Size(10, 10), true, false,
963 true);
964 SetLayerPropertiesForTesting(grand_child, rotation_about_y_axis,
ajumad0d64422015-03-14 04:20:08965 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
enne25dea3f2015-07-27 16:44:28966 true, false, false);
967 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
968 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
969 true, false, false);
[email protected]d600df7d2013-08-03 02:34:28970
[email protected]fb661802013-03-25 01:59:32971 // No layers in this test should preserve 3d.
jaydasikaca2605e2016-04-23 02:52:52972 ASSERT_TRUE(root->test_properties()->should_flatten_transform);
973 ASSERT_TRUE(child->test_properties()->should_flatten_transform);
974 ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform);
975 ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform);
[email protected]fb661802013-03-25 01:59:32976
977 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
978 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
979 gfx::Transform expected_grand_child_draw_transform =
980 rotation_about_y_axis; // draws onto child's render surface
981 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
982 flattened_rotation_about_y.FlattenTo2d();
983 gfx::Transform expected_grand_child_screen_space_transform =
984 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:08985 gfx::Transform expected_great_grand_child_draw_transform =
986 flattened_rotation_about_y;
987 gfx::Transform expected_great_grand_child_screen_space_transform =
988 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:32989
enne25dea3f2015-07-27 16:44:28990 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32991
992 // The child's draw transform should have been taken by its surface.
993 ASSERT_TRUE(child->render_surface());
994 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
995 child->render_surface()->draw_transform());
996 EXPECT_TRANSFORMATION_MATRIX_EQ(
997 expected_child_screen_space_transform,
998 child->render_surface()->screen_space_transform());
ajumad9432e32015-11-30 19:43:44999 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321000 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101001 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321002 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441003 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321004 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101005 grand_child->ScreenSpaceTransform());
ajumad0d64422015-03-14 04:20:081006 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441007 great_grand_child->DrawTransform());
ajumad0d64422015-03-14 04:20:081008 EXPECT_TRANSFORMATION_MATRIX_EQ(
1009 expected_great_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101010 great_grand_child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321011}
1012
ajumadbd92cb2015-07-16 13:47:061013TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
jaydasika6f972de2016-04-07 16:16:141014 LayerImpl* root = root_layer();
1015 LayerImpl* child = AddChild<LayerImpl>(root);
1016 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumadbd92cb2015-07-16 13:47:061017
1018 gfx::Transform child_transform;
1019 child_transform.Translate(50.0, 50.0);
1020 child_transform.RotateAboutZAxis(30.0);
1021
1022 gfx::Transform grand_child_transform;
1023 grand_child_transform.RotateAboutYAxis(90.0);
1024
1025 const gfx::Transform identity_matrix;
jaydasika6f972de2016-04-07 16:16:141026 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1027 gfx::PointF(), gfx::Size(200, 200), true, false,
1028 true);
1029 SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(),
1030 gfx::PointF(), gfx::Size(10, 10), true, false,
1031 false);
1032 SetLayerPropertiesForTesting(grand_child, grand_child_transform,
ajumadbd92cb2015-07-16 13:47:061033 gfx::Point3F(), gfx::PointF(),
jaydasika6f972de2016-04-07 16:16:141034 gfx::Size(100, 100), true, false, false);
ajumadbd92cb2015-07-16 13:47:061035
jaydasikaca2605e2016-04-23 02:52:521036 grand_child->test_properties()->should_flatten_transform = false;
jaydasika6f972de2016-04-07 16:16:141037 grand_child->SetDrawsContent(true);
ajumadbd92cb2015-07-16 13:47:061038
jaydasika6f972de2016-04-07 16:16:141039 ExecuteCalculateDrawProperties(root);
ajumadbd92cb2015-07-16 13:47:061040
1041 // Mapping grand_child's bounds to target space produces a non-empty rect
1042 // that is fully contained within the target's bounds, so grand_child should
1043 // be considered fully visible.
1044 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
jaydasika6f972de2016-04-07 16:16:141045 grand_child->visible_layer_rect());
ajumadbd92cb2015-07-16 13:47:061046}
1047
[email protected]989386c2013-07-18 21:37:231048TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321049 // A layer that is empty in one axis, but not the other, was accidentally
1050 // skipping a necessary translation. Without that translation, the coordinate
1051 // space of the layer's draw transform is incorrect.
1052 //
1053 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1054 // but if that layer becomes a render surface, then its draw transform is
1055 // implicitly inherited by the rest of the subtree, which then is positioned
1056 // incorrectly as a result.
1057
ennec1332992015-08-24 19:45:091058 LayerImpl* root = root_layer();
1059 LayerImpl* child = AddChild<LayerImpl>(root);
1060 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1061 grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321062
1063 // The child height is zero, but has non-zero width that should be accounted
1064 // for while computing draw transforms.
1065 const gfx::Transform identity_matrix;
ennec1332992015-08-24 19:45:091066 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1067 gfx::PointF(), gfx::Size(100, 100), true, false,
1068 true);
1069 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1070 gfx::PointF(), gfx::Size(10, 0), true, false,
1071 true);
1072 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1073 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321074 false);
1075
ennec1332992015-08-24 19:45:091076 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321077
ennec1332992015-08-24 19:45:091078 ASSERT_TRUE(child->has_render_surface());
[email protected]fb661802013-03-25 01:59:321079 // This is the real test, the rest are sanity checks.
1080 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1081 child->render_surface()->draw_transform());
ajumad9432e32015-11-30 19:43:441082 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321083 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
ajumad9432e32015-11-30 19:43:441084 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321085}
1086
jaydasika9bbee9b2016-01-13 00:36:481087TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) {
1088 const gfx::Transform identity_matrix;
1089 LayerImpl* root = root_layer();
1090 LayerImpl* render_surface = AddChild<LayerImpl>(root);
1091 LayerImpl* child = AddChild<LayerImpl>(render_surface);
1092 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1093
1094 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1095 gfx::PointF(), gfx::Size(100, 100), true, false,
1096 true);
1097 gfx::Transform translate;
1098 translate.Translate3d(5, 5, 5);
1099 SetLayerPropertiesForTesting(render_surface, translate, gfx::Point3F(),
1100 gfx::PointF(), gfx::Size(100, 100), true, false,
1101 true);
1102 SetLayerPropertiesForTesting(child, translate, gfx::Point3F(), gfx::PointF(),
1103 gfx::Size(100, 100), true, false, false);
1104 SetLayerPropertiesForTesting(grand_child, translate, gfx::Point3F(),
1105 gfx::PointF(), gfx::Size(100, 100), true, false,
1106 false);
1107 grand_child->SetDrawsContent(true);
1108
1109 // render_surface will have a sublayer scale because of device scale factor.
1110 float device_scale_factor = 2.0f;
1111 LayerImplList render_surface_layer_list_impl;
jaydasika9bbee9b2016-01-13 00:36:481112 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381113 root, root->bounds(), translate, &render_surface_layer_list_impl);
jaydasika9bbee9b2016-01-13 00:36:481114 inputs.device_scale_factor = device_scale_factor;
1115 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571116 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika9bbee9b2016-01-13 00:36:481117
1118 // Between grand_child and render_surface, we translate by (10, 10) and scale
1119 // by a factor of 2.
1120 gfx::Vector2dF expected_translation(20.0f, 20.0f);
1121 EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(),
1122 expected_translation);
1123}
1124
[email protected]989386c2013-07-18 21:37:231125TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321126 // Transformations applied at the root of the tree should be forwarded
1127 // to child layers instead of applied to the root RenderSurface.
1128 const gfx::Transform identity_matrix;
enned3f61fb02015-08-18 22:54:391129 LayerImpl* root = root_layer();
1130 root->SetDrawsContent(true);
1131 LayerImpl* child = AddChild<LayerImpl>(root);
1132 child->SetDrawsContent(true);
[email protected]f224cc92013-06-06 23:23:321133
enned3f61fb02015-08-18 22:54:391134 child->SetScrollClipLayer(root->id());
[email protected]d600df7d2013-08-03 02:34:281135
enned3f61fb02015-08-18 22:54:391136 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1137 gfx::PointF(), gfx::Size(20, 20), true, false,
1138 true);
1139 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1140 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]f224cc92013-06-06 23:23:321141 false);
1142
[email protected]f224cc92013-06-06 23:23:321143 gfx::Transform translate;
1144 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231145 {
enned3f61fb02015-08-18 22:54:391146 LayerImplList render_surface_layer_list_impl;
1147 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381148 root, root->bounds(), translate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321149 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571150 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231151 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1152 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1153 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1154 }
[email protected]f224cc92013-06-06 23:23:321155
1156 gfx::Transform scale;
1157 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231158 {
enned3f61fb02015-08-18 22:54:391159 LayerImplList render_surface_layer_list_impl;
1160 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381161 root, root->bounds(), scale, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321162 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571163 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231164 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1165 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1166 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1167 }
[email protected]f224cc92013-06-06 23:23:321168
1169 gfx::Transform rotate;
1170 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231171 {
enned3f61fb02015-08-18 22:54:391172 LayerImplList render_surface_layer_list_impl;
1173 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381174 root, root->bounds(), rotate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321175 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571176 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231177 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1178 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1179 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1180 }
[email protected]f224cc92013-06-06 23:23:321181
1182 gfx::Transform composite;
1183 composite.ConcatTransform(translate);
1184 composite.ConcatTransform(scale);
1185 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231186 {
enned3f61fb02015-08-18 22:54:391187 LayerImplList render_surface_layer_list_impl;
1188 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381189 root, root->bounds(), composite, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321190 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571191 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231192 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1193 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1194 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1195 }
[email protected]f224cc92013-06-06 23:23:321196
[email protected]9781afa2013-07-17 23:15:321197 // Verify it composes correctly with device scale.
1198 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231199
1200 {
enned3f61fb02015-08-18 22:54:391201 LayerImplList render_surface_layer_list_impl;
1202 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381203 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531204 inputs.device_scale_factor = device_scale_factor;
vollick5057e1e2015-04-17 19:12:321205 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571206 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231207 gfx::Transform device_scaled_translate = translate;
1208 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1209 EXPECT_EQ(device_scaled_translate,
1210 root->draw_properties().target_space_transform);
1211 EXPECT_EQ(device_scaled_translate,
1212 child->draw_properties().target_space_transform);
1213 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1214 }
[email protected]9781afa2013-07-17 23:15:321215
1216 // Verify it composes correctly with page scale.
1217 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231218
1219 {
enned3f61fb02015-08-18 22:54:391220 LayerImplList render_surface_layer_list_impl;
1221 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381222 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531223 inputs.page_scale_factor = page_scale_factor;
enned3f61fb02015-08-18 22:54:391224 inputs.page_scale_layer = root;
vollick5057e1e2015-04-17 19:12:321225 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571226 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231227 gfx::Transform page_scaled_translate = translate;
1228 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
enne6394d5b42015-05-26 22:23:111229 EXPECT_EQ(page_scaled_translate,
1230 root->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231231 EXPECT_EQ(page_scaled_translate,
1232 child->draw_properties().target_space_transform);
1233 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1234 }
[email protected]9781afa2013-07-17 23:15:321235
[email protected]f224cc92013-06-06 23:23:321236 // Verify that it composes correctly with transforms directly on root layer.
1237 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231238
1239 {
enned3f61fb02015-08-18 22:54:391240 LayerImplList render_surface_layer_list_impl;
1241 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381242 root, root->bounds(), composite, &render_surface_layer_list_impl);
enned3f61fb02015-08-18 22:54:391243 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571244 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231245 gfx::Transform compositeSquared = composite;
1246 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261247 EXPECT_TRANSFORMATION_MATRIX_EQ(
1248 compositeSquared, root->draw_properties().target_space_transform);
1249 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391250 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231251 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1252 }
[email protected]f224cc92013-06-06 23:23:321253}
1254
[email protected]989386c2013-07-18 21:37:231255TEST_F(LayerTreeHostCommonTest,
1256 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
enneea850232015-07-27 16:43:121257 LayerImpl* parent = root_layer();
1258 parent->SetMasksToBounds(true);
1259 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1260 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1261 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:281262
[email protected]fb661802013-03-25 01:59:321263 const gfx::Transform identity_matrix;
enneea850232015-07-27 16:43:121264 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1265 gfx::PointF(), gfx::Size(10, 10), true, false,
1266 true);
1267 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1268 gfx::PointF(), gfx::Size(10, 10), true, false,
1269 true);
1270 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1271 gfx::PointF(30.f, 30.f), gfx::Size(10, 10), true,
1272 false, false);
[email protected]fb661802013-03-25 01:59:321273
enneea850232015-07-27 16:43:121274 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321275
1276 // The child layer's content is entirely outside the parent's clip rect, so
1277 // the intermediate render surface should not be listed here, even if it was
1278 // forced to be created. Render surfaces without children or visible content
1279 // are unexpected at draw time (e.g. we might try to create a content texture
1280 // of size 0).
1281 ASSERT_TRUE(parent->render_surface());
enneea850232015-07-27 16:43:121282 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:321283}
1284
[email protected]989386c2013-07-18 21:37:231285TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
enne03b0e9a2015-06-19 00:08:021286 LayerImpl* parent = root_layer();
1287 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
1288 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1289 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:281290
[email protected]fb661802013-03-25 01:59:321291 const gfx::Transform identity_matrix;
enne03b0e9a2015-06-19 00:08:021292 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1293 gfx::PointF(), gfx::Size(10, 10), true, false,
1294 true);
1295 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1296 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321297 false);
jaydasikaab317e02016-06-01 00:53:181298 render_surface1->test_properties()->opacity = 0.f;
[email protected]fb661802013-03-25 01:59:321299
enne03b0e9a2015-06-19 00:08:021300 LayerImplList render_surface_layer_list;
1301 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381302 parent, parent->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531303 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571304 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]fb661802013-03-25 01:59:321305
1306 // Since the layer is transparent, render_surface1->render_surface() should
1307 // not have gotten added anywhere. Also, the drawable content rect should not
1308 // have been extended by the children.
1309 ASSERT_TRUE(parent->render_surface());
1310 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1311 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231312 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321313 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1314}
1315
hendrikwc266f7b2015-08-21 23:41:341316TEST_F(LayerTreeHostCommonTest,
1317 RenderSurfaceListForTransparentChildWithBackgroundFilter) {
1318 LayerImpl* parent = root_layer();
1319 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
1320 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1321 child->SetDrawsContent(true);
1322
1323 const gfx::Transform identity_matrix;
1324 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1325 gfx::PointF(), gfx::Size(10, 10), true, false,
1326 true);
1327 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1328 gfx::PointF(), gfx::Size(10, 10), true, false,
1329 true);
1330 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1331 gfx::PointF(), gfx::Size(10, 10), true, false,
1332 false);
jaydasikaab317e02016-06-01 00:53:181333 render_surface1->test_properties()->opacity = 0.f;
jaydasika86654512016-01-27 17:05:071334 render_surface1->SetDrawsContent(true);
1335 child->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341336 FilterOperations filters;
1337 filters.Append(FilterOperation::CreateBlurFilter(1.5f));
1338 render_surface1->SetBackgroundFilters(filters);
1339
jaydasika369c24b2016-04-06 23:44:161340 {
1341 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161342 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381343 parent, parent->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161344 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571345 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161346 EXPECT_EQ(2U, render_surface_layer_list.size());
1347 }
hendrikwc266f7b2015-08-21 23:41:341348 // The layer is fully transparent, but has a background filter, so it
jaydasika369c24b2016-04-06 23:44:161349 // shouldn't be skipped and should be drawn.
hendrikwc266f7b2015-08-21 23:41:341350 ASSERT_TRUE(parent->render_surface());
1351 EXPECT_EQ(1U, parent->render_surface()->layer_list().size());
jaydasika8640f9f2015-11-10 01:34:361352 EXPECT_EQ(gfx::RectF(0, 0, 10, 10),
1353 parent->render_surface()->DrawableContentRect());
jaydasika369c24b2016-04-06 23:44:161354 EffectTree& effect_tree =
1355 parent->layer_tree_impl()->property_trees()->effect_tree;
1356 EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index());
1357 EXPECT_TRUE(node->data.is_drawn);
1358
1359 // When parent is transparent, the layer should not be drawn.
1360 parent->OnOpacityAnimated(0.f);
1361 render_surface1->OnOpacityAnimated(1.f);
jaydasika8185d302016-04-14 15:20:061362 render_surface1->set_visible_layer_rect(gfx::Rect());
jaydasika369c24b2016-04-06 23:44:161363 {
1364 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161365 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381366 parent, parent->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161367 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571368 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161369 }
1370
1371 node = effect_tree.Node(render_surface1->effect_tree_index());
1372 EXPECT_FALSE(node->data.is_drawn);
jaydasika8185d302016-04-14 15:20:061373 EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect());
hendrikwc266f7b2015-08-21 23:41:341374}
1375
senorblanco38858c52016-01-20 23:15:001376TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) {
1377 LayerImpl* root = root_layer();
1378 LayerImpl* parent = AddChild<LayerImpl>(root);
1379 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1380 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1381 child1->SetDrawsContent(true);
1382 child2->SetDrawsContent(true);
1383
1384 const gfx::Transform identity_matrix;
1385 gfx::Transform scale_matrix;
1386 scale_matrix.Scale(2.0f, 2.0f);
1387 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1388 gfx::PointF(), gfx::Size(100, 100), true, false,
1389 true);
1390 SetLayerPropertiesForTesting(parent, scale_matrix, gfx::Point3F(),
1391 gfx::PointF(), gfx::Size(), true, false, true);
1392 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1393 gfx::PointF(0, 0), gfx::Size(25, 25), true,
1394 false, true);
1395 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1396 gfx::PointF(25, 25), gfx::Size(25, 25), true,
1397 false, true);
1398 FilterOperations filters;
1399 filters.Append(FilterOperation::CreateBlurFilter(10.0f));
1400 parent->SetFilters(filters);
1401
1402 LayerImplList render_surface_layer_list;
senorblanco38858c52016-01-20 23:15:001403 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381404 root, root->bounds(), &render_surface_layer_list);
senorblanco38858c52016-01-20 23:15:001405 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571406 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
senorblanco38858c52016-01-20 23:15:001407
1408 ASSERT_TRUE(parent->render_surface());
1409 EXPECT_EQ(2U, parent->render_surface()->layer_list().size());
1410 EXPECT_EQ(4U, render_surface_layer_list.size());
jbroman1c44d5b52016-06-06 21:19:301411
1412 // The rectangle enclosing child1 and child2 (0,0 50x50), expanded for the
1413 // blur (-30,-30 110x110), and then scaled by the scale matrix
1414 // (-60,-60 220x220).
1415 EXPECT_EQ(gfx::RectF(-60, -60, 220, 220),
senorblanco38858c52016-01-20 23:15:001416 parent->render_surface()->DrawableContentRect());
1417}
1418
jbroman1c44d5b52016-06-06 21:19:301419TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilter) {
1420 LayerImpl* root = root_layer();
1421 LayerImpl* child = AddChild<LayerImpl>(root);
1422 child->SetDrawsContent(true);
1423
1424 SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(),
1425 gfx::PointF(), gfx::Size(100, 100), true, false,
1426 true);
1427 SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(),
1428 gfx::PointF(), gfx::Size(25, 25), true, false,
1429 true);
1430
1431 FilterOperations filters;
1432 filters.Append(FilterOperation::CreateReferenceFilter(
1433 SkOffsetImageFilter::Make(50, 50, nullptr)));
1434 child->SetFilters(filters);
1435
1436 ExecuteCalculateDrawProperties(root);
1437
1438 // The render surface's size should be unaffected by the offset image filter;
1439 // it need only have a drawable content rect large enough to contain the
1440 // contents (at the new offset).
1441 ASSERT_TRUE(child->render_surface());
1442 EXPECT_EQ(gfx::RectF(50, 50, 25, 25),
1443 child->render_surface()->DrawableContentRect());
1444}
1445
1446TEST_F(LayerTreeHostCommonTest, DrawableContentRectForReferenceFilterHighDpi) {
1447 const float device_scale_factor = 2.0f;
1448
1449 LayerImpl* root = root_layer();
1450 root->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor);
1451 LayerImpl* child = AddChild<LayerImpl>(root);
1452 child->SetDrawsContent(true);
1453
1454 SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(),
1455 gfx::PointF(), gfx::Size(100, 100), true, false,
1456 true);
1457 SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(),
1458 gfx::PointF(), gfx::Size(25, 25), true, false,
1459 true);
1460
1461 FilterOperations filters;
1462 filters.Append(FilterOperation::CreateReferenceFilter(
1463 SkOffsetImageFilter::Make(50, 50, nullptr)));
1464 child->SetFilters(filters);
1465
1466 ExecuteCalculateDrawProperties(root, device_scale_factor);
1467
1468 // The render surface's size should be unaffected by the offset image filter;
1469 // it need only have a drawable content rect large enough to contain the
1470 // contents (at the new offset). All coordinates should be scaled by 2,
1471 // corresponding to the device scale factor.
1472 ASSERT_TRUE(child->render_surface());
1473 EXPECT_EQ(gfx::RectF(100, 100, 50, 50),
1474 child->render_surface()->DrawableContentRect());
1475}
1476
rosca948d29d2014-11-09 10:25:131477TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
enned5f4ddd2015-08-18 16:50:061478 LayerImpl* parent = root_layer();
1479 LayerImpl* child = AddChild<LayerImpl>(parent);
1480 child->SetDrawsContent(true);
rosca948d29d2014-11-09 10:25:131481
1482 const gfx::Transform identity_matrix;
1483 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
enned5f4ddd2015-08-18 16:50:061484 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1485 gfx::PointF(), gfx::Size(10, 10), true, false,
1486 true);
1487 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1488 gfx::PointF(), gfx::Size(10, 10), true, false,
1489 true);
rosca948d29d2014-11-09 10:25:131490
rosca948d29d2014-11-09 10:25:131491 child->SetBlendMode(blend_mode);
jaydasikaab317e02016-06-01 00:53:181492 child->test_properties()->opacity = 0.5f;
rosca948d29d2014-11-09 10:25:131493
enned5f4ddd2015-08-18 16:50:061494 ExecuteCalculateDrawProperties(parent);
rosca948d29d2014-11-09 10:25:131495
1496 // Since the child layer has a blend mode other than normal, it should get
1497 // its own render surface. Also, layer's draw_properties should contain the
1498 // default blend mode, since the render surface becomes responsible for
1499 // applying the blend mode.
1500 ASSERT_TRUE(child->render_surface());
weiliangc451b818f2015-07-24 17:52:291501 EXPECT_EQ(1.0f, child->draw_opacity());
1502 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
jaydasika92239dc2015-08-15 02:59:261503 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode());
rosca948d29d2014-11-09 10:25:131504}
1505
jaydasikafbdb86e2016-01-21 18:57:511506TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) {
1507 LayerImpl* root = root_layer();
1508 LayerImpl* surface1 = AddChildToRoot<LayerImpl>();
1509 LayerImpl* not_surface = AddChild<LayerImpl>(surface1);
1510 LayerImpl* surface2 = AddChild<LayerImpl>(not_surface);
1511
1512 const gfx::Transform identity_matrix;
1513 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1514 gfx::PointF(), gfx::Size(10, 10), true, false,
1515 true);
1516 SetLayerPropertiesForTesting(surface1, identity_matrix, gfx::Point3F(),
1517 gfx::PointF(), gfx::Size(10, 10), true, false,
1518 true);
1519 SetLayerPropertiesForTesting(not_surface, identity_matrix, gfx::Point3F(),
1520 gfx::PointF(), gfx::Size(10, 10), true, false,
1521 false);
1522 SetLayerPropertiesForTesting(surface2, identity_matrix, gfx::Point3F(),
1523 gfx::PointF(), gfx::Size(10, 10), true, false,
1524 true);
1525 surface1->SetDrawsContent(true);
1526 surface2->SetDrawsContent(true);
1527
jaydasikaab317e02016-06-01 00:53:181528 surface1->test_properties()->opacity = 0.5f;
1529 not_surface->test_properties()->opacity = 0.5f;
1530 surface2->test_properties()->opacity = 0.5f;
jaydasikafbdb86e2016-01-21 18:57:511531
1532 ExecuteCalculateDrawProperties(root);
1533
1534 ASSERT_TRUE(surface1->render_surface());
1535 ASSERT_FALSE(not_surface->render_surface());
1536 ASSERT_TRUE(surface2->render_surface());
1537 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity());
1538 // surface2's draw opacity should include the opacity of not-surface and
1539 // itself, but not the opacity of surface1.
1540 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity());
1541}
1542
ajuma51d73f72015-10-19 19:43:581543TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) {
1544 // Tests that when separate surfaces are disabled, a layer's draw opacity is
1545 // the product of all ancestor layer opacties and the layer's own opacity.
1546 // (Rendering will still be incorrect in situations where we really do need
1547 // surfaces to apply opacity, such as when we have overlapping layers with an
1548 // ancestor whose opacity is <1.)
1549 LayerImpl* root = root_layer();
1550 LayerImpl* parent = AddChild<LayerImpl>(root);
1551 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1552 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1553 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1554 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1555 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1556
1557 root->SetDrawsContent(true);
1558 parent->SetDrawsContent(true);
1559 child1->SetDrawsContent(true);
1560 child2->SetDrawsContent(true);
1561 grand_child->SetDrawsContent(true);
1562 leaf_node1->SetDrawsContent(true);
1563 leaf_node2->SetDrawsContent(true);
1564
1565 const gfx::Transform identity_matrix;
1566
1567 // child1 and grand_child get render surfaces when surfaces are enabled.
1568 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1569 gfx::PointF(), gfx::Size(100, 100), true, false,
1570 true);
1571 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1572 gfx::PointF(), gfx::Size(100, 100), true, false,
1573 false);
1574 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1575 gfx::PointF(), gfx::Size(100, 100), true, false,
1576 true);
1577 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1578 gfx::PointF(), gfx::Size(100, 100), true, false,
1579 false);
1580 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1581 gfx::PointF(), gfx::Size(100, 100), true, false,
1582 true);
1583 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1584 gfx::PointF(), gfx::Size(100, 100), true, false,
1585 false);
1586 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1587 gfx::PointF(), gfx::Size(100, 100), true, false,
1588 false);
1589
jaydasikaab317e02016-06-01 00:53:181590 child1->test_properties()->opacity = 0.5f;
1591 grand_child->test_properties()->opacity = 0.5f;
1592 leaf_node1->test_properties()->opacity = 0.5f;
1593 leaf_node2->test_properties()->opacity = 0.5f;
ajuma51d73f72015-10-19 19:43:581594
1595 // With surfaces enabled, each layer's draw opacity is the product of layer
1596 // opacities on the path from the layer to its render target, not including
1597 // the opacity of the layer that owns the target surface (since that opacity
1598 // is applied by the surface).
1599 ExecuteCalculateDrawProperties(root);
1600 EXPECT_EQ(1.f, root->draw_opacity());
1601 EXPECT_EQ(1.f, parent->draw_opacity());
1602 EXPECT_EQ(1.f, child1->draw_opacity());
1603 EXPECT_EQ(1.f, child2->draw_opacity());
1604 EXPECT_EQ(1.f, grand_child->draw_opacity());
1605 EXPECT_EQ(0.5f, leaf_node1->draw_opacity());
1606 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1607
1608 // With surfaces disabled, each layer's draw opacity is the product of layer
1609 // opacities on the path from the layer to the root.
1610 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1611 EXPECT_EQ(1.f, root->draw_opacity());
1612 EXPECT_EQ(1.f, parent->draw_opacity());
1613 EXPECT_EQ(0.5f, child1->draw_opacity());
1614 EXPECT_EQ(1.f, child2->draw_opacity());
1615 EXPECT_EQ(0.25f, grand_child->draw_opacity());
1616 EXPECT_EQ(0.125f, leaf_node1->draw_opacity());
1617 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1618}
1619
[email protected]989386c2013-07-18 21:37:231620TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
weiliangcc154ce22015-12-09 03:39:261621 LayerImpl* parent = root_layer();
1622 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1623 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
weiliangceffae0462015-12-08 23:17:261624
1625 const gfx::Transform identity_matrix;
weiliangcc154ce22015-12-09 03:39:261626 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
weiliangceffae0462015-12-08 23:17:261627 gfx::PointF(), gfx::Size(10, 10), true, false);
weiliangcc154ce22015-12-09 03:39:261628 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1629 gfx::PointF(), gfx::Size(10, 10), true, false);
1630 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
weiliangceffae0462015-12-08 23:17:261631 gfx::PointF(), gfx::Size(10, 10), true, false);
1632
weiliangcc154ce22015-12-09 03:39:261633 child->SetDrawsContent(true);
jaydasika6b5a32bf2016-04-22 21:56:361634 render_surface1->test_properties()->force_render_surface = true;
weiliangceffae0462015-12-08 23:17:261635
[email protected]989386c2013-07-18 21:37:231636 {
weiliangcc154ce22015-12-09 03:39:261637 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:321638
[email protected]989386c2013-07-18 21:37:231639 // The root layer always creates a render surface
ennec1332992015-08-24 19:45:091640 EXPECT_TRUE(parent->has_render_surface());
1641 EXPECT_TRUE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231642 }
[email protected]fb661802013-03-25 01:59:321643
[email protected]989386c2013-07-18 21:37:231644 {
jaydasika6b5a32bf2016-04-22 21:56:361645 render_surface1->test_properties()->force_render_surface = false;
weiliangcc154ce22015-12-09 03:39:261646 render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true;
1647 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
ennec1332992015-08-24 19:45:091648 EXPECT_TRUE(parent->has_render_surface());
1649 EXPECT_FALSE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231650 }
[email protected]fb661802013-03-25 01:59:321651}
1652
ajuma246190a2015-03-11 20:56:031653TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1654 // Render surfaces act as a flattening point for their subtree, so should
1655 // always flatten the target-to-screen space transform seen by descendants.
1656
enne1a79c5542015-08-18 19:43:571657 LayerImpl* root = root_layer();
1658 LayerImpl* parent = AddChild<LayerImpl>(root);
1659 LayerImpl* child = AddChild<LayerImpl>(parent);
1660 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1661
1662 child->SetDrawsContent(true);
1663 grand_child->SetDrawsContent(true);
ajuma246190a2015-03-11 20:56:031664
1665 gfx::Transform rotation_about_y_axis;
1666 rotation_about_y_axis.RotateAboutYAxis(30.0);
1667 // Make |parent| have a render surface.
jaydasikaab317e02016-06-01 00:53:181668 parent->test_properties()->opacity = 0.9f;
ajuma246190a2015-03-11 20:56:031669
1670 const gfx::Transform identity_matrix;
enne1a79c5542015-08-18 19:43:571671 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1672 gfx::PointF(), gfx::Size(100, 100), true, false,
1673 true);
1674 SetLayerPropertiesForTesting(parent, rotation_about_y_axis, gfx::Point3F(),
1675 gfx::PointF(), gfx::Size(10, 10), true, false,
1676 true);
1677 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1678 gfx::PointF(), gfx::Size(10, 10), true, false,
1679 false);
1680 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1681 gfx::PointF(), gfx::Size(10, 10), true, false,
1682 false);
ajuma246190a2015-03-11 20:56:031683
jaydasikaca2605e2016-04-23 02:52:521684 grand_child->test_properties()->should_flatten_transform = false;
ajuma246190a2015-03-11 20:56:031685
ajuma246190a2015-03-11 20:56:031686 // Only grand_child should preserve 3d.
jaydasikaca2605e2016-04-23 02:52:521687 EXPECT_TRUE(root->test_properties()->should_flatten_transform);
1688 EXPECT_TRUE(parent->test_properties()->should_flatten_transform);
1689 EXPECT_TRUE(child->test_properties()->should_flatten_transform);
1690 EXPECT_FALSE(grand_child->test_properties()->should_flatten_transform);
ajuma246190a2015-03-11 20:56:031691
1692 gfx::Transform expected_child_draw_transform = identity_matrix;
1693 gfx::Transform expected_grand_child_draw_transform = identity_matrix;
1694
1695 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1696 flattened_rotation_about_y.FlattenTo2d();
1697
enne1a79c5542015-08-18 19:43:571698 ExecuteCalculateDrawProperties(root);
ajuma246190a2015-03-11 20:56:031699
1700 EXPECT_TRUE(parent->render_surface());
1701 EXPECT_FALSE(child->render_surface());
1702 EXPECT_FALSE(grand_child->render_surface());
1703
ajumad9432e32015-11-30 19:43:441704 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
ajuma246190a2015-03-11 20:56:031705 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
ajumad9432e32015-11-30 19:43:441706 grand_child->DrawTransform());
ajuma246190a2015-03-11 20:56:031707
1708 // The screen-space transform inherited by |child| and |grand_child| should
1709 // have been flattened at their render target. In particular, the fact that
1710 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1711 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101712 child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031713 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101714 grand_child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031715}
1716
[email protected]989386c2013-07-18 21:37:231717TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321718 // The entire subtree of layers that are outside the clip rect should be
1719 // culled away, and should not affect the render_surface_layer_list.
1720 //
1721 // The test tree is set up as follows:
1722 // - all layers except the leaf_nodes are forced to be a new render surface
1723 // that have something to draw.
1724 // - parent is a large container layer.
1725 // - child has masksToBounds=true to cause clipping.
1726 // - grand_child is positioned outside of the child's bounds
1727 // - great_grand_child is also kept outside child's bounds.
1728 //
1729 // In this configuration, grand_child and great_grand_child are completely
1730 // outside the clip rect, and they should never get scheduled on the list of
1731 // render surfaces.
[email protected]fb661802013-03-25 01:59:321732
weiliangcfb3d5eaa2015-07-28 23:54:571733 LayerImpl* parent = root_layer();
1734 LayerImpl* child = AddChildToRoot<LayerImpl>();
1735 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1736 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
[email protected]d600df7d2013-08-03 02:34:281737
[email protected]fb661802013-03-25 01:59:321738 // leaf_node1 ensures that parent and child are kept on the
1739 // render_surface_layer_list, even though grand_child and great_grand_child
1740 // should be clipped.
weiliangcfb3d5eaa2015-07-28 23:54:571741 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
1742 leaf_node1->SetDrawsContent(true);
1743 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
1744 leaf_node2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321745
weiliangcfb3d5eaa2015-07-28 23:54:571746 const gfx::Transform identity_matrix;
1747
1748 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1749 gfx::PointF(), gfx::Size(500, 500), true, false,
1750 true);
1751 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1752 gfx::PointF(), gfx::Size(20, 20), true, false,
1753 true);
1754 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1755 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1756 false, false);
1757 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
1758 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1759 true, false, false);
1760 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1761 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:321762 false);
weiliangcfb3d5eaa2015-07-28 23:54:571763 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1764 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]fb661802013-03-25 01:59:321765 false);
1766
1767 child->SetMasksToBounds(true);
jaydasikaab317e02016-06-01 00:53:181768 child->test_properties()->opacity = 0.4f;
1769 grand_child->test_properties()->opacity = 0.5f;
1770 great_grand_child->test_properties()->opacity = 0.4f;
[email protected]fb661802013-03-25 01:59:321771
weiliangcfb3d5eaa2015-07-28 23:54:571772 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321773
weiliangcfb3d5eaa2015-07-28 23:54:571774 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
1775 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id());
1776 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id());
[email protected]fb661802013-03-25 01:59:321777}
1778
[email protected]989386c2013-07-18 21:37:231779TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321780 // When a render surface has a clip rect, it is used to clip the content rect
weiliangcfb3d5eaa2015-07-28 23:54:571781 // of the surface.
[email protected]fb661802013-03-25 01:59:321782
1783 // The test tree is set up as follows:
1784 // - parent is a container layer that masksToBounds=true to cause clipping.
1785 // - child is a render surface, which has a clip rect set to the bounds of
1786 // the parent.
1787 // - grand_child is a render surface, and the only visible content in child.
1788 // It is positioned outside of the clip rect from parent.
1789
1790 // In this configuration, grand_child should be outside the clipped
1791 // content rect of the child, making grand_child not appear in the
weiliangcfb3d5eaa2015-07-28 23:54:571792 // render_surface_layer_list.
1793
1794 LayerImpl* parent = root_layer();
1795 LayerImpl* child = AddChildToRoot<LayerImpl>();
1796 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1797 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
1798 leaf_node->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321799
1800 const gfx::Transform identity_matrix;
[email protected]fb661802013-03-25 01:59:321801
weiliangcfb3d5eaa2015-07-28 23:54:571802 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1803 gfx::PointF(), gfx::Size(100, 100), true, false,
1804 true);
1805 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1806 gfx::PointF(), gfx::Size(20, 20), true, false,
1807 true);
1808 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1809 gfx::PointF(200.f, 200.f), gfx::Size(10, 10),
1810 true, false, true);
1811 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
1812 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321813 false);
1814
1815 parent->SetMasksToBounds(true);
jaydasikaab317e02016-06-01 00:53:181816 child->test_properties()->opacity = 0.4f;
1817 grand_child->test_properties()->opacity = 0.4f;
[email protected]fb661802013-03-25 01:59:321818
weiliangcfb3d5eaa2015-07-28 23:54:571819 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321820
weiliangcfb3d5eaa2015-07-28 23:54:571821 // We should cull child and grand_child from the
1822 // render_surface_layer_list.
1823 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
1824 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id());
[email protected]fb661802013-03-25 01:59:321825}
1826
ajumae2b7a5c2015-09-30 21:41:421827TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1828 // Tests that LayerImpl's IsClipped() property is set to true when:
[email protected]fb661802013-03-25 01:59:321829 // - the layer clips its subtree, e.g. masks to bounds,
1830 // - the layer is clipped by an ancestor that contributes to the same
1831 // render target,
1832 // - a surface is clipped by an ancestor that contributes to the same
1833 // render target.
1834 //
1835 // In particular, for a layer that owns a render surface:
1836 // - the render surface inherits any clip from ancestors, and does NOT
1837 // pass that clipped status to the layer itself.
1838 // - but if the layer itself masks to bounds, it is considered clipped
1839 // and propagates the clip to the subtree.
1840
1841 const gfx::Transform identity_matrix;
enne76bf8982015-08-18 17:55:331842 LayerImpl* root = root_layer();
1843 LayerImpl* parent = AddChild<LayerImpl>(root);
jaydasika8640f9f2015-11-10 01:34:361844 parent->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331845 LayerImpl* child1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:361846 child1->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331847 LayerImpl* child2 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:361848 child2->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331849 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
jaydasika8640f9f2015-11-10 01:34:361850 grand_child->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331851 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1852 leaf_node1->SetDrawsContent(true);
1853 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1854 leaf_node2->SetDrawsContent(true);
1855
1856 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1857 gfx::PointF(), gfx::Size(100, 100), true, false,
1858 true);
1859 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1860 gfx::PointF(), gfx::Size(100, 100), true, false,
1861 false);
1862 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1863 gfx::PointF(), gfx::Size(100, 100), true, false,
1864 false);
1865 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1866 gfx::PointF(), gfx::Size(100, 100), true, false,
1867 true);
1868 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1869 gfx::PointF(), gfx::Size(100, 100), true, false,
1870 false);
1871 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1872 gfx::PointF(), gfx::Size(100, 100), true, false,
1873 false);
1874 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1875 gfx::PointF(), gfx::Size(100, 100), true, false,
1876 false);
1877
1878 // Case 1: nothing is clipped except the root render surface.
weiliangce3f09a612016-03-16 17:02:521879 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331880
weiliangce3f09a612016-03-16 17:02:521881 ASSERT_TRUE(root->render_surface());
1882 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331883
weiliangce3f09a612016-03-16 17:02:521884 EXPECT_FALSE(root->is_clipped());
1885 EXPECT_TRUE(root->render_surface()->is_clipped());
1886 EXPECT_FALSE(parent->is_clipped());
1887 EXPECT_FALSE(child1->is_clipped());
1888 EXPECT_FALSE(child2->is_clipped());
1889 EXPECT_FALSE(child2->render_surface()->is_clipped());
1890 EXPECT_FALSE(grand_child->is_clipped());
1891 EXPECT_FALSE(leaf_node1->is_clipped());
1892 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331893
1894 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1895 // surface are clipped. But layers that contribute to child2's surface are
1896 // not clipped explicitly because child2's surface already accounts for
1897 // that clip.
weiliangce3f09a612016-03-16 17:02:521898 parent->SetMasksToBounds(true);
1899 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331900
weiliangce3f09a612016-03-16 17:02:521901 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331902
weiliangce3f09a612016-03-16 17:02:521903 ASSERT_TRUE(root->render_surface());
1904 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331905
weiliangce3f09a612016-03-16 17:02:521906 EXPECT_FALSE(root->is_clipped());
1907 EXPECT_TRUE(root->render_surface()->is_clipped());
1908 EXPECT_TRUE(parent->is_clipped());
1909 EXPECT_TRUE(child1->is_clipped());
1910 EXPECT_FALSE(child2->is_clipped());
1911 EXPECT_TRUE(child2->render_surface()->is_clipped());
1912 EXPECT_TRUE(grand_child->is_clipped());
1913 EXPECT_TRUE(leaf_node1->is_clipped());
1914 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331915
weiliangce3f09a612016-03-16 17:02:521916 parent->SetMasksToBounds(false);
enne76bf8982015-08-18 17:55:331917
1918 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1919 // child2's render surface is not clipped.
weiliangce3f09a612016-03-16 17:02:521920 child2->SetMasksToBounds(true);
1921 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331922
weiliangce3f09a612016-03-16 17:02:521923 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331924
weiliangce3f09a612016-03-16 17:02:521925 ASSERT_TRUE(root->render_surface());
1926 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331927
weiliangce3f09a612016-03-16 17:02:521928 EXPECT_FALSE(root->is_clipped());
1929 EXPECT_TRUE(root->render_surface()->is_clipped());
1930 EXPECT_FALSE(parent->is_clipped());
1931 EXPECT_FALSE(child1->is_clipped());
1932 EXPECT_TRUE(child2->is_clipped());
1933 EXPECT_FALSE(child2->render_surface()->is_clipped());
1934 EXPECT_FALSE(grand_child->is_clipped());
1935 EXPECT_FALSE(leaf_node1->is_clipped());
1936 EXPECT_TRUE(leaf_node2->is_clipped());
1937}
1938
1939TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) {
1940 // Tests that when as long as layer is clipped, it's clip rect is set to
1941 // correct value.
1942 LayerImpl* root = root_layer();
1943 LayerImpl* parent = AddChild<LayerImpl>(root);
1944 LayerImpl* child = AddChild<LayerImpl>(parent);
1945
1946 root->SetDrawsContent(true);
1947 parent->SetDrawsContent(true);
1948 child->SetDrawsContent(true);
1949
1950 const gfx::Transform identity_matrix;
1951
1952 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1953 gfx::PointF(), gfx::Size(100, 100), true, false,
1954 true);
1955 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1956 gfx::PointF(), gfx::Size(100, 100), true, false,
1957 false);
1958 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1959 gfx::PointF(), gfx::Size(100, 100), true, false,
1960 false);
1961 child->SetMasksToBounds(true);
1962
1963 ExecuteCalculateDrawProperties(root);
1964
1965 EXPECT_FALSE(root->is_clipped());
1966 EXPECT_FALSE(parent->is_clipped());
1967 EXPECT_TRUE(child->is_clipped());
1968 EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect());
1969
1970 parent->SetMasksToBounds(true);
1971 child->SetPosition(gfx::PointF(100, 100));
1972 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1973
1974 ExecuteCalculateDrawProperties(root);
1975
1976 EXPECT_FALSE(root->is_clipped());
1977 EXPECT_TRUE(parent->is_clipped());
1978 EXPECT_TRUE(child->is_clipped());
1979 EXPECT_EQ(gfx::Rect(), child->clip_rect());
[email protected]fb661802013-03-25 01:59:321980}
1981
ajuma51d73f72015-10-19 19:43:581982TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) {
1983 // Tests that when separate surfaces are disabled, is_clipped is true exactly
1984 // when a layer or its ancestor has a clip; in particular, if a layer
1985 // is_clipped, so is its entire subtree (since there are no render surfaces
1986 // that can reset is_clipped).
1987 LayerImpl* root = root_layer();
1988 LayerImpl* parent = AddChild<LayerImpl>(root);
1989 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1990 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1991 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1992 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1993 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1994
1995 root->SetDrawsContent(true);
1996 parent->SetDrawsContent(true);
1997 child1->SetDrawsContent(true);
1998 child2->SetDrawsContent(true);
1999 grand_child->SetDrawsContent(true);
2000 leaf_node1->SetDrawsContent(true);
2001 leaf_node2->SetDrawsContent(true);
2002
2003 const gfx::Transform identity_matrix;
2004
2005 // child1 and grand_child get render surfaces when surfaces are enabled.
2006 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2007 gfx::PointF(), gfx::Size(100, 100), true, false,
2008 true);
2009 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2010 gfx::PointF(), gfx::Size(100, 100), true, false,
2011 false);
2012 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2013 gfx::PointF(), gfx::Size(100, 100), true, false,
2014 true);
2015 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2016 gfx::PointF(), gfx::Size(100, 100), true, false,
2017 false);
2018 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2019 gfx::PointF(), gfx::Size(100, 100), true, false,
2020 true);
2021 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2022 gfx::PointF(), gfx::Size(100, 100), true, false,
2023 false);
2024 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2025 gfx::PointF(), gfx::Size(100, 100), true, false,
2026 false);
2027
2028 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with
2029 // or without surfaces.
weiliangcc154ce22015-12-09 03:39:262030 root->SetHasRenderSurface(true);
2031 child1->SetHasRenderSurface(true);
2032 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582033 ExecuteCalculateDrawProperties(root);
2034 EXPECT_FALSE(root->is_clipped());
2035 EXPECT_FALSE(parent->is_clipped());
2036 EXPECT_FALSE(child1->is_clipped());
2037 EXPECT_FALSE(child2->is_clipped());
2038 EXPECT_FALSE(grand_child->is_clipped());
2039 EXPECT_FALSE(leaf_node1->is_clipped());
2040 EXPECT_FALSE(leaf_node2->is_clipped());
2041
2042 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2043 EXPECT_FALSE(root->is_clipped());
2044 EXPECT_FALSE(parent->is_clipped());
2045 EXPECT_FALSE(child1->is_clipped());
2046 EXPECT_FALSE(child2->is_clipped());
2047 EXPECT_FALSE(grand_child->is_clipped());
2048 EXPECT_FALSE(leaf_node1->is_clipped());
2049 EXPECT_FALSE(leaf_node2->is_clipped());
2050
2051 // Case 2: The root is clipped. With surfaces, this only persists until the
2052 // next render surface. Without surfaces, the entire tree is clipped.
2053 root->SetMasksToBounds(true);
2054 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262055 root->SetHasRenderSurface(true);
2056 child1->SetHasRenderSurface(true);
2057 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582058 ExecuteCalculateDrawProperties(root);
2059 EXPECT_TRUE(root->is_clipped());
2060 EXPECT_TRUE(parent->is_clipped());
2061 EXPECT_FALSE(child1->is_clipped());
2062 EXPECT_TRUE(child2->is_clipped());
2063 EXPECT_FALSE(grand_child->is_clipped());
2064 EXPECT_FALSE(leaf_node1->is_clipped());
2065 EXPECT_TRUE(leaf_node2->is_clipped());
2066
2067 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2068 EXPECT_TRUE(root->is_clipped());
2069 EXPECT_TRUE(parent->is_clipped());
2070 EXPECT_TRUE(child1->is_clipped());
2071 EXPECT_TRUE(child2->is_clipped());
2072 EXPECT_TRUE(grand_child->is_clipped());
2073 EXPECT_TRUE(leaf_node1->is_clipped());
2074 EXPECT_TRUE(leaf_node2->is_clipped());
2075
2076 root->SetMasksToBounds(false);
2077
2078 // Case 3: The parent is clipped. Again, with surfaces, this only persists
2079 // until the next render surface. Without surfaces, parent's entire subtree is
2080 // clipped.
2081 parent->SetMasksToBounds(true);
2082 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262083 root->SetHasRenderSurface(true);
2084 child1->SetHasRenderSurface(true);
2085 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582086 ExecuteCalculateDrawProperties(root);
2087 EXPECT_FALSE(root->is_clipped());
2088 EXPECT_TRUE(parent->is_clipped());
2089 EXPECT_FALSE(child1->is_clipped());
2090 EXPECT_TRUE(child2->is_clipped());
2091 EXPECT_FALSE(grand_child->is_clipped());
2092 EXPECT_FALSE(leaf_node1->is_clipped());
2093 EXPECT_TRUE(leaf_node2->is_clipped());
2094
2095 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2096 EXPECT_FALSE(root->is_clipped());
2097 EXPECT_TRUE(parent->is_clipped());
2098 EXPECT_TRUE(child1->is_clipped());
2099 EXPECT_TRUE(child2->is_clipped());
2100 EXPECT_TRUE(grand_child->is_clipped());
2101 EXPECT_TRUE(leaf_node1->is_clipped());
2102 EXPECT_TRUE(leaf_node2->is_clipped());
2103
2104 parent->SetMasksToBounds(false);
2105
2106 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it
2107 // has no non-surface children. Without surfaces, child1's entire subtree is
2108 // clipped.
2109 child1->SetMasksToBounds(true);
2110 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262111 root->SetHasRenderSurface(true);
2112 child1->SetHasRenderSurface(true);
2113 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582114 ExecuteCalculateDrawProperties(root);
2115 EXPECT_FALSE(root->is_clipped());
2116 EXPECT_FALSE(parent->is_clipped());
2117 EXPECT_TRUE(child1->is_clipped());
2118 EXPECT_FALSE(child2->is_clipped());
2119 EXPECT_FALSE(grand_child->is_clipped());
2120 EXPECT_FALSE(leaf_node1->is_clipped());
2121 EXPECT_FALSE(leaf_node2->is_clipped());
2122
2123 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2124 EXPECT_FALSE(root->is_clipped());
2125 EXPECT_FALSE(parent->is_clipped());
2126 EXPECT_TRUE(child1->is_clipped());
2127 EXPECT_FALSE(child2->is_clipped());
2128 EXPECT_TRUE(grand_child->is_clipped());
2129 EXPECT_TRUE(leaf_node1->is_clipped());
2130 EXPECT_FALSE(leaf_node2->is_clipped());
2131
2132 child1->SetMasksToBounds(false);
2133
2134 // Case 5: Only the leaf nodes are clipped. The behavior with and without
2135 // surfaces is the same.
2136 leaf_node1->SetMasksToBounds(true);
2137 leaf_node2->SetMasksToBounds(true);
2138 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262139 root->SetHasRenderSurface(true);
2140 child1->SetHasRenderSurface(true);
2141 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582142 ExecuteCalculateDrawProperties(root);
2143 EXPECT_FALSE(root->is_clipped());
2144 EXPECT_FALSE(parent->is_clipped());
2145 EXPECT_FALSE(child1->is_clipped());
2146 EXPECT_FALSE(child2->is_clipped());
2147 EXPECT_FALSE(grand_child->is_clipped());
2148 EXPECT_TRUE(leaf_node1->is_clipped());
2149 EXPECT_TRUE(leaf_node2->is_clipped());
2150
2151 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2152 EXPECT_FALSE(root->is_clipped());
2153 EXPECT_FALSE(parent->is_clipped());
2154 EXPECT_FALSE(child1->is_clipped());
2155 EXPECT_FALSE(child2->is_clipped());
2156 EXPECT_FALSE(grand_child->is_clipped());
2157 EXPECT_TRUE(leaf_node1->is_clipped());
2158 EXPECT_TRUE(leaf_node2->is_clipped());
2159}
2160
[email protected]fd9a3b6d2013-08-03 00:46:172161TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:322162 // Verify that layers get the appropriate DrawableContentRect when their
2163 // parent masksToBounds is true.
2164 //
2165 // grand_child1 - completely inside the region; DrawableContentRect should
2166 // be the layer rect expressed in target space.
2167 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
2168 // will be the intersection of layer bounds and the mask region.
2169 // grand_child3 - partially clipped and masksToBounds; the
2170 // DrawableContentRect will still be the intersection of layer bounds and
2171 // the mask region.
2172 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2173 // be empty.
[email protected]fb661802013-03-25 01:59:322174
2175 const gfx::Transform identity_matrix;
enne07405c772015-08-18 17:56:452176 LayerImpl* parent = root_layer();
2177 LayerImpl* child = AddChild<LayerImpl>(parent);
2178 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362179 grand_child1->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452180 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362181 grand_child2->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452182 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362183 grand_child3->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452184 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362185 grand_child4->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322186
enne07405c772015-08-18 17:56:452187 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2188 gfx::PointF(), gfx::Size(500, 500), true, false,
2189 true);
2190 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2191 gfx::PointF(), gfx::Size(20, 20), true, false,
2192 true);
2193 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2194 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
2195 false, false);
2196 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2197 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2198 false, false);
2199 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2200 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2201 false, false);
2202 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
2203 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
2204 false, false);
[email protected]fb661802013-03-25 01:59:322205
2206 child->SetMasksToBounds(true);
2207 grand_child3->SetMasksToBounds(true);
2208
enne07405c772015-08-18 17:56:452209 // Force child to be a render surface.
jaydasikaab317e02016-06-01 00:53:182210 child->test_properties()->opacity = 0.4f;
[email protected]fb661802013-03-25 01:59:322211
enne07405c772015-08-18 17:56:452212 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322213
hush6b614212014-12-04 22:37:322214 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2215 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2216 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322217 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2218}
2219
[email protected]989386c2013-07-18 21:37:232220TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322221 // Verify that render surfaces (and their layers) get the appropriate
2222 // clip rects when their parent masksToBounds is true.
2223 //
2224 // Layers that own render surfaces (at least for now) do not inherit any
2225 // clipping; instead the surface will enforce the clip for the entire subtree.
2226 // They may still have a clip rect of their own layer bounds, however, if
2227 // masksToBounds was true.
weiliangcfb3d5eaa2015-07-28 23:54:572228 LayerImpl* parent = root_layer();
2229 LayerImpl* child = AddChildToRoot<LayerImpl>();
2230 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2231 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2232 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2233 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
[email protected]fb661802013-03-25 01:59:322234 // the leaf nodes ensure that these grand_children become render surfaces for
2235 // this test.
weiliangcfb3d5eaa2015-07-28 23:54:572236 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
2237 leaf_node1->SetDrawsContent(true);
2238 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
2239 leaf_node2->SetDrawsContent(true);
2240 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
2241 leaf_node3->SetDrawsContent(true);
2242 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
2243 leaf_node4->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322244
weiliangcfb3d5eaa2015-07-28 23:54:572245 const gfx::Transform identity_matrix;
2246
2247 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2248 gfx::PointF(), gfx::Size(500, 500), true, false,
2249 true);
2250 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2251 gfx::PointF(), gfx::Size(20, 20), true, false,
2252 true);
2253 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2254 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
2255 false, true);
2256 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2257 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2258 false, true);
2259 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2260 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2261 false, true);
2262 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
2263 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
2264 false, true);
2265 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2266 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322267 false);
weiliangcfb3d5eaa2015-07-28 23:54:572268 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2269 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322270 false);
weiliangcfb3d5eaa2015-07-28 23:54:572271 SetLayerPropertiesForTesting(leaf_node3, identity_matrix, gfx::Point3F(),
2272 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322273 false);
weiliangcfb3d5eaa2015-07-28 23:54:572274 SetLayerPropertiesForTesting(leaf_node4, identity_matrix, gfx::Point3F(),
2275 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322276 false);
2277
2278 child->SetMasksToBounds(true);
2279 grand_child3->SetMasksToBounds(true);
2280 grand_child4->SetMasksToBounds(true);
2281
2282 // Force everyone to be a render surface.
jaydasikaab317e02016-06-01 00:53:182283 child->test_properties()->opacity = 0.4f;
2284 grand_child1->test_properties()->opacity = 0.5f;
2285 grand_child2->test_properties()->opacity = 0.5f;
2286 grand_child3->test_properties()->opacity = 0.5f;
2287 grand_child4->test_properties()->opacity = 0.5f;
[email protected]fb661802013-03-25 01:59:322288
weiliangcfb3d5eaa2015-07-28 23:54:572289 ExecuteCalculateDrawProperties(parent);
2290
[email protected]fb661802013-03-25 01:59:322291 ASSERT_TRUE(grand_child1->render_surface());
2292 ASSERT_TRUE(grand_child2->render_surface());
2293 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322294
2295 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2296 // masksToBounds.
hush6b614212014-12-04 22:37:322297 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2298 grand_child1->render_surface()->clip_rect());
2299 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2300 grand_child2->render_surface()->clip_rect());
2301 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2302 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322303}
2304
ajuma51d73f72015-10-19 19:43:582305TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) {
2306 // Tests that when separate surfaces are disabled, a layer's clip_rect is the
2307 // intersection of all ancestor clips in screen space; in particular, if a
2308 // layer masks to bounds, it contributes to the clip_rect of all layers in its
2309 // subtree (since there are no render surfaces that can reset the clip_rect).
2310 LayerImpl* root = root_layer();
2311 LayerImpl* parent = AddChild<LayerImpl>(root);
2312 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2313 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2314 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2315 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2316 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2317
2318 root->SetDrawsContent(true);
2319 parent->SetDrawsContent(true);
2320 child1->SetDrawsContent(true);
2321 child2->SetDrawsContent(true);
2322 grand_child->SetDrawsContent(true);
2323 leaf_node1->SetDrawsContent(true);
2324 leaf_node2->SetDrawsContent(true);
2325
2326 const gfx::Transform identity_matrix;
2327
2328 // child1 and grand_child get render surfaces when surfaces are enabled.
2329 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:262330 gfx::PointF(), gfx::Size(100, 100), true, false);
ajuma51d73f72015-10-19 19:43:582331 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2332 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
weiliangcc154ce22015-12-09 03:39:262333 false);
ajuma51d73f72015-10-19 19:43:582334 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2335 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
weiliangcc154ce22015-12-09 03:39:262336 false);
ajuma51d73f72015-10-19 19:43:582337 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2338 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
weiliangcc154ce22015-12-09 03:39:262339 false);
ajuma51d73f72015-10-19 19:43:582340 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2341 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
weiliangcc154ce22015-12-09 03:39:262342 true, false);
ajuma51d73f72015-10-19 19:43:582343 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2344 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
weiliangcc154ce22015-12-09 03:39:262345 true, false);
ajuma51d73f72015-10-19 19:43:582346 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2347 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
weiliangcc154ce22015-12-09 03:39:262348 true, false);
ajuma51d73f72015-10-19 19:43:582349
2350 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its
2351 // bounds in target space. The only thing that changes when surfaces are
2352 // disabled is that target space is always screen space.
jaydasika6b5a32bf2016-04-22 21:56:362353 root->test_properties()->force_render_surface = true;
2354 child1->test_properties()->force_render_surface = true;
2355 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582356 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262357 EXPECT_TRUE(root->has_render_surface());
2358 EXPECT_FALSE(parent->has_render_surface());
2359 EXPECT_TRUE(child1->has_render_surface());
2360 EXPECT_FALSE(child2->has_render_surface());
2361 EXPECT_TRUE(grand_child->has_render_surface());
2362 EXPECT_FALSE(leaf_node1->has_render_surface());
2363 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422364 EXPECT_FALSE(root->is_clipped());
2365 EXPECT_FALSE(parent->is_clipped());
2366 EXPECT_FALSE(child1->is_clipped());
2367 EXPECT_FALSE(child2->is_clipped());
2368 EXPECT_FALSE(grand_child->is_clipped());
2369 EXPECT_FALSE(leaf_node1->is_clipped());
2370 EXPECT_FALSE(leaf_node2->is_clipped());
2371 EXPECT_TRUE(root->render_surface()->is_clipped());
2372 EXPECT_FALSE(child1->render_surface()->is_clipped());
2373 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2374 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582375
2376 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422377 EXPECT_FALSE(root->is_clipped());
2378 EXPECT_FALSE(parent->is_clipped());
2379 EXPECT_FALSE(child1->is_clipped());
2380 EXPECT_FALSE(child2->is_clipped());
2381 EXPECT_FALSE(grand_child->is_clipped());
2382 EXPECT_FALSE(leaf_node1->is_clipped());
2383 EXPECT_FALSE(leaf_node2->is_clipped());
2384 EXPECT_TRUE(root->render_surface()->is_clipped());
2385 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582386
2387 // Case 2: The root is clipped. In this case, layers that draw into the root
2388 // render surface are clipped by the root's bounds.
2389 root->SetMasksToBounds(true);
2390 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362391 root->test_properties()->force_render_surface = true;
2392 child1->test_properties()->force_render_surface = true;
2393 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582394 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262395 EXPECT_TRUE(root->has_render_surface());
2396 EXPECT_FALSE(parent->has_render_surface());
2397 EXPECT_TRUE(child1->has_render_surface());
2398 EXPECT_FALSE(child2->has_render_surface());
2399 EXPECT_TRUE(grand_child->has_render_surface());
2400 EXPECT_FALSE(leaf_node1->has_render_surface());
2401 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422402 EXPECT_TRUE(root->is_clipped());
2403 EXPECT_TRUE(parent->is_clipped());
2404 EXPECT_FALSE(child1->is_clipped());
2405 EXPECT_TRUE(child1->render_surface()->is_clipped());
2406 EXPECT_TRUE(child2->is_clipped());
2407 EXPECT_FALSE(grand_child->is_clipped());
2408 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2409 EXPECT_FALSE(leaf_node1->is_clipped());
2410 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582411 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2412 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422413 EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582414 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
ajuma51d73f72015-10-19 19:43:582415 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2416
2417 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422418 EXPECT_TRUE(root->is_clipped());
2419 EXPECT_TRUE(parent->is_clipped());
2420 EXPECT_TRUE(child1->is_clipped());
2421 EXPECT_TRUE(child2->is_clipped());
2422 EXPECT_TRUE(grand_child->is_clipped());
2423 EXPECT_TRUE(leaf_node1->is_clipped());
2424 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582425 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2426 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2427 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect());
2428 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2429 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect());
2430 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect());
2431 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2432
2433 root->SetMasksToBounds(false);
2434
2435 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the
2436 // parent clip rect only contributes to the subtree rooted at child2, since
2437 // the subtree rooted at child1 renders into a separate surface. Similarly,
2438 // child1's clip rect doesn't contribute to its descendants, since its only
2439 // child is a render surface. However, without surfaces, these clip rects
2440 // contribute to all descendants.
2441 parent->SetMasksToBounds(true);
2442 child1->SetMasksToBounds(true);
2443 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362444 root->test_properties()->force_render_surface = true;
2445 child1->test_properties()->force_render_surface = true;
2446 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582447 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262448 EXPECT_TRUE(root->has_render_surface());
2449 EXPECT_FALSE(parent->has_render_surface());
2450 EXPECT_TRUE(child1->has_render_surface());
2451 EXPECT_FALSE(child2->has_render_surface());
2452 EXPECT_TRUE(grand_child->has_render_surface());
2453 EXPECT_FALSE(leaf_node1->has_render_surface());
2454 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422455 EXPECT_FALSE(root->is_clipped());
2456 EXPECT_TRUE(root->render_surface()->is_clipped());
2457 EXPECT_TRUE(parent->is_clipped());
2458 EXPECT_TRUE(child1->is_clipped());
2459 EXPECT_TRUE(child2->is_clipped());
2460 EXPECT_FALSE(grand_child->is_clipped());
2461 EXPECT_TRUE(grand_child->render_surface()->is_clipped());
2462 EXPECT_FALSE(leaf_node1->is_clipped());
2463 EXPECT_TRUE(leaf_node2->is_clipped());
2464 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582465 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2466 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2467 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422468 EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582469 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2470
2471 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422472 EXPECT_FALSE(root->is_clipped());
2473 EXPECT_TRUE(root->render_surface()->is_clipped());
2474 EXPECT_TRUE(parent->is_clipped());
2475 EXPECT_TRUE(child1->is_clipped());
2476 EXPECT_TRUE(child2->is_clipped());
2477 EXPECT_TRUE(grand_child->is_clipped());
2478 EXPECT_TRUE(leaf_node1->is_clipped());
2479 EXPECT_TRUE(leaf_node2->is_clipped());
2480 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582481 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2482 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect());
2483 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2484 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect());
2485 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect());
2486 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2487}
2488
jaydasika8d0064f2016-06-02 23:34:542489TEST_F(LayerTreeHostCommonTest, HitTestingWhenSurfacesDisabled) {
2490 LayerImpl* root = root_layer();
2491 LayerImpl* parent = AddChild<LayerImpl>(root);
2492 LayerImpl* child = AddChild<LayerImpl>(parent);
2493 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2494 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2495
2496 root->SetDrawsContent(true);
2497 parent->SetDrawsContent(true);
2498 child->SetDrawsContent(true);
2499 grand_child->SetDrawsContent(true);
2500 leaf_node->SetDrawsContent(true);
2501
2502 const gfx::Transform identity_matrix;
2503
2504 // child and grand_child will get render surfaces if surfaces are enabled.
2505 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2506 gfx::PointF(), gfx::Size(100, 100), true, false,
2507 true);
2508 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2509 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2510 false, false);
2511 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2512 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2513 false, true);
2514 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2515 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2516 true, false, true);
2517 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
2518 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2519 true, false, false);
2520
2521 parent->SetMasksToBounds(true);
2522 child->SetMasksToBounds(true);
2523
2524 root->SetHasRenderSurface(true);
2525 child->SetHasRenderSurface(true);
2526 grand_child->SetHasRenderSurface(true);
2527
2528 host_impl()->set_resourceless_software_draw_for_testing();
2529 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2530 gfx::PointF test_point(90.f, 90.f);
2531 LayerImpl* result_layer =
2532 root->layer_tree_impl()->FindLayerThatIsHitByPoint(test_point);
2533 ASSERT_TRUE(result_layer);
2534 EXPECT_EQ(leaf_node, result_layer);
2535}
2536
ajuma51d73f72015-10-19 19:43:582537TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) {
2538 // Tests that draw properties are computed correctly when we disable and then
2539 // re-enable separate surfaces.
2540 LayerImpl* root = root_layer();
2541 LayerImpl* parent = AddChild<LayerImpl>(root);
2542 LayerImpl* child = AddChild<LayerImpl>(parent);
2543 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2544 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2545
2546 root->SetDrawsContent(true);
2547 parent->SetDrawsContent(true);
2548 child->SetDrawsContent(true);
2549 grand_child->SetDrawsContent(true);
2550 leaf_node->SetDrawsContent(true);
2551
2552 const gfx::Transform identity_matrix;
2553
2554 // child and grand_child get render surfaces when surfaces are enabled.
2555 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2556 gfx::PointF(), gfx::Size(100, 100), true, false,
2557 true);
2558 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2559 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2560 false, false);
2561 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2562 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2563 false, true);
2564 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2565 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2566 true, false, true);
2567 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
2568 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2569 true, false, false);
2570
2571 parent->SetMasksToBounds(true);
2572 child->SetMasksToBounds(true);
2573
weiliangcc154ce22015-12-09 03:39:262574 root->SetHasRenderSurface(true);
2575 child->SetHasRenderSurface(true);
2576 grand_child->SetHasRenderSurface(true);
2577
ajuma51d73f72015-10-19 19:43:582578 gfx::Transform expected_leaf_draw_transform_with_surfaces;
2579 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0);
2580
2581 gfx::Transform expected_leaf_draw_transform_without_surfaces;
2582 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0);
2583
2584 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422585 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252586 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582587 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2588 EXPECT_EQ(expected_leaf_draw_transform_with_surfaces,
ajumad9432e32015-11-30 19:43:442589 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582590
weiliangcc154ce22015-12-09 03:39:262591 root->SetHasRenderSurface(true);
2592 child->SetHasRenderSurface(true);
2593 grand_child->SetHasRenderSurface(true);
2594
ajuma51d73f72015-10-19 19:43:582595 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422596 EXPECT_TRUE(leaf_node->is_clipped());
ajuma51d73f72015-10-19 19:43:582597 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect());
2598 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect());
2599 EXPECT_EQ(expected_leaf_draw_transform_without_surfaces,
ajumad9432e32015-11-30 19:43:442600 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582601
weiliangcc154ce22015-12-09 03:39:262602 root->SetHasRenderSurface(true);
2603 child->SetHasRenderSurface(true);
2604 grand_child->SetHasRenderSurface(true);
2605
ajuma51d73f72015-10-19 19:43:582606 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422607 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252608 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582609 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2610 EXPECT_EQ(expected_leaf_draw_transform_with_surfaces,
ajumad9432e32015-11-30 19:43:442611 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582612}
2613
[email protected]989386c2013-07-18 21:37:232614TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
enneab0fee42015-07-07 17:36:422615 LayerImpl* parent = root_layer();
2616 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2617 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
2618 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
2619 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2620 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2621 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2622 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2623 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
[email protected]fb661802013-03-25 01:59:322624
jaydasika8640f9f2015-11-10 01:34:362625 parent->SetDrawsContent(true);
2626 render_surface1->SetDrawsContent(true);
2627 child_of_rs1->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422628 grand_child_of_rs1->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362629 render_surface2->SetDrawsContent(true);
2630 child_of_rs2->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422631 grand_child_of_rs2->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362632 child_of_root->SetDrawsContent(true);
2633 grand_child_of_root->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322634
2635 gfx::Transform layer_transform;
2636 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322637
enneab0fee42015-07-07 17:36:422638 SetLayerPropertiesForTesting(
2639 parent, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2640 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2641 SetLayerPropertiesForTesting(
2642 render_surface1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2643 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2644 SetLayerPropertiesForTesting(
2645 render_surface2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2646 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2647 SetLayerPropertiesForTesting(
2648 child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2649 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2650 SetLayerPropertiesForTesting(
2651 child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2652 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2653 SetLayerPropertiesForTesting(
2654 child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2655 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2656 SetLayerPropertiesForTesting(
2657 grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2658 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2659 SetLayerPropertiesForTesting(
2660 grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2661 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2662 SetLayerPropertiesForTesting(
2663 grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2664 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
[email protected]fb661802013-03-25 01:59:322665
jaydasika4340ea02016-06-06 19:44:262666 parent->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
jaydasika9cb21c772016-05-10 22:37:082667
loyso9556c732016-03-11 07:54:582668 // Put an animated opacity on the render surface.
2669 AddOpacityTransitionToLayerWithPlayer(render_surface1->id(), timeline_impl(),
2670 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322671
loyso9556c732016-03-11 07:54:582672 // Also put an animated opacity on a layer without descendants.
2673 AddOpacityTransitionToLayerWithPlayer(grand_child_of_root->id(),
2674 timeline_impl(), 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322675
loyso9556c732016-03-11 07:54:582676 // Put a transform animation on the render surface.
2677 AddAnimatedTransformToLayerWithPlayer(render_surface2->id(), timeline_impl(),
2678 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322679
loyso9556c732016-03-11 07:54:582680 // Also put transform animations on grand_child_of_root, and
2681 // grand_child_of_rs2
2682 AddAnimatedTransformToLayerWithPlayer(grand_child_of_root->id(),
2683 timeline_impl(), 10.0, 30, 0);
2684 AddAnimatedTransformToLayerWithPlayer(grand_child_of_rs2->id(),
2685 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322686
jaydasika9cb21c772016-05-10 22:37:082687 parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneab0fee42015-07-07 17:36:422688 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322689
2690 // Only layers that are associated with render surfaces should have an actual
2691 // RenderSurface() value.
2692 ASSERT_TRUE(parent->render_surface());
2693 ASSERT_FALSE(child_of_root->render_surface());
2694 ASSERT_FALSE(grand_child_of_root->render_surface());
2695
2696 ASSERT_TRUE(render_surface1->render_surface());
2697 ASSERT_FALSE(child_of_rs1->render_surface());
2698 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2699
2700 ASSERT_TRUE(render_surface2->render_surface());
2701 ASSERT_FALSE(child_of_rs2->render_surface());
2702 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2703
2704 // Verify all render target accessors
weiliangc189c1a12016-04-11 16:16:252705 EXPECT_EQ(parent->render_surface(), parent->render_target());
2706 EXPECT_EQ(parent->render_surface(), child_of_root->render_target());
2707 EXPECT_EQ(parent->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322708
weiliangc189c1a12016-04-11 16:16:252709 EXPECT_EQ(render_surface1->render_surface(),
2710 render_surface1->render_target());
2711 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
2712 EXPECT_EQ(render_surface1->render_surface(),
2713 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322714
weiliangc189c1a12016-04-11 16:16:252715 EXPECT_EQ(render_surface2->render_surface(),
2716 render_surface2->render_target());
2717 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
2718 EXPECT_EQ(render_surface2->render_surface(),
2719 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322720
[email protected]fb661802013-03-25 01:59:322721 // Verify screen_space_transform_is_animating values
2722 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2723 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2724 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2725 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322726 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2727 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2728 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322729 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2730 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2731
2732 // Sanity check. If these fail there is probably a bug in the test itself.
2733 // It is expected that we correctly set up transforms so that the y-component
2734 // of the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:102735 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:262736 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102737 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322738 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102739 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322740
[email protected]803f6b52013-09-12 00:51:262741 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102742 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
2743 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322744 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102745 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322746
[email protected]803f6b52013-09-12 00:51:262747 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:102748 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
2749 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322750 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102751 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322752}
2753
ajuma9384b9c22015-09-17 20:35:032754TEST_F(LayerTreeHostCommonTest, LargeTransforms) {
2755 LayerImpl* parent = root_layer();
2756 LayerImpl* child = AddChildToRoot<LayerImpl>();
2757 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2758
2759 grand_child->SetDrawsContent(true);
2760
2761 gfx::Transform large_transform;
2762 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2763
2764 gfx::Transform identity;
2765
2766 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(),
2767 gfx::Size(10, 10), true, false, true);
2768 SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(),
2769 gfx::PointF(), gfx::Size(10, 10), true, false,
2770 false);
2771 SetLayerPropertiesForTesting(grand_child, large_transform, gfx::Point3F(),
2772 gfx::PointF(), gfx::Size(10, 10), true, false,
2773 false);
2774 ExecuteCalculateDrawProperties(parent);
2775
2776 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
2777}
2778
ajuma315a4782015-07-24 21:16:342779TEST_F(LayerTreeHostCommonTest,
2780 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
2781 LayerImpl* parent = root_layer();
2782 LayerImpl* child = AddChild<LayerImpl>(parent);
2783 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2784 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2785
2786 parent->SetDrawsContent(true);
2787 child->SetDrawsContent(true);
2788 grand_child->SetDrawsContent(true);
2789 great_grand_child->SetDrawsContent(true);
2790
2791 gfx::Transform identity;
2792
2793 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(),
2794 gfx::Size(10, 10), true, false, true);
2795 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
2796 gfx::Size(10, 10), true, false, false);
2797 SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(),
2798 gfx::PointF(), gfx::Size(10, 10), true, false,
2799 false);
2800 SetLayerPropertiesForTesting(great_grand_child, identity, gfx::Point3F(),
2801 gfx::PointF(), gfx::Size(10, 10), true, false,
2802 false);
2803
2804 // Add a transform animation with a start delay to |grand_child|.
danakj60bc3bc2016-04-09 00:24:482805 std::unique_ptr<Animation> animation = Animation::Create(
2806 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1,
loyso0c8e4402016-02-25 04:12:302807 TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:552808 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:342809 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso9556c732016-03-11 07:54:582810 AddAnimationToLayerWithPlayer(grand_child->id(), timeline_impl(),
2811 std::move(animation));
ajuma315a4782015-07-24 21:16:342812 ExecuteCalculateDrawProperties(parent);
2813
2814 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2815 EXPECT_FALSE(child->screen_space_transform_is_animating());
2816
2817 EXPECT_FALSE(grand_child->TransformIsAnimating());
2818 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2819 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2820 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2821}
2822
weiliangc6da32862016-04-20 16:40:112823TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) {
2824 // Test visible layer rect and drawable content rect are calculated correctly
2825 // correctly for identity transforms.
[email protected]fb661802013-03-25 01:59:322826
[email protected]2c7c6702013-03-26 03:14:052827 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322828 gfx::Transform layer_to_surface_transform;
2829
2830 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232831 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
weiliangc6da32862016-04-20 16:40:112832 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2833 gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30);
2834 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2835 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2836 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2837 EXPECT_EQ(expected_drawable_content_rect,
2838 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322839
2840 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052841 layer_content_rect = gfx::Rect(120, 120, 30, 30);
weiliangc6da32862016-04-20 16:40:112842 expected_visible_layer_rect = gfx::Rect();
2843 expected_drawable_content_rect = gfx::Rect();
2844 drawing_layer = TestVisibleRectAndDrawableContentRect(
2845 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2846 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2847 EXPECT_EQ(expected_drawable_content_rect,
2848 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322849
2850 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052851 layer_content_rect = gfx::Rect(80, 80, 30, 30);
weiliangc6da32862016-04-20 16:40:112852 expected_visible_layer_rect = gfx::Rect(20, 20);
2853 expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20);
2854 drawing_layer = TestVisibleRectAndDrawableContentRect(
2855 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2856 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2857 EXPECT_EQ(expected_drawable_content_rect,
2858 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322859}
2860
weiliangc6da32862016-04-20 16:40:112861TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) {
2862 // Test visible layer rect and drawable content rect are calculated correctly
2863 // for rotations about z-axis (i.e. 2D rotations).
[email protected]fb661802013-03-25 01:59:322864
[email protected]2c7c6702013-03-26 03:14:052865 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2866 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322867 gfx::Transform layer_to_surface_transform;
2868
2869 // Case 1: Layer is contained within the surface.
2870 layer_to_surface_transform.MakeIdentity();
2871 layer_to_surface_transform.Translate(50.0, 50.0);
2872 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112873 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2874 gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43);
2875 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2876 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2877 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2878 EXPECT_EQ(expected_drawable_content_rect,
2879 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322880
2881 // Case 2: Layer is outside the surface rect.
2882 layer_to_surface_transform.MakeIdentity();
2883 layer_to_surface_transform.Translate(-50.0, 0.0);
2884 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112885 expected_visible_layer_rect = gfx::Rect();
2886 expected_drawable_content_rect = gfx::Rect();
2887 drawing_layer = TestVisibleRectAndDrawableContentRect(
2888 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2889 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2890 EXPECT_EQ(expected_drawable_content_rect,
2891 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322892
2893 // Case 3: The layer is rotated about its top-left corner. In surface space,
2894 // the layer is oriented diagonally, with the left half outside of the render
2895 // surface. In this case, the g should still be the entire layer
2896 // (remember the g is computed in layer space); both the top-left
2897 // and bottom-right corners of the layer are still visible.
2898 layer_to_surface_transform.MakeIdentity();
2899 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112900 expected_visible_layer_rect = gfx::Rect(30, 30);
2901 expected_drawable_content_rect = gfx::Rect(22, 43);
2902 drawing_layer = TestVisibleRectAndDrawableContentRect(
2903 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2904 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2905 EXPECT_EQ(expected_drawable_content_rect,
2906 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322907
2908 // Case 4: The layer is rotated about its top-left corner, and translated
2909 // upwards. In surface space, the layer is oriented diagonally, with only the
2910 // top corner of the surface overlapping the layer. In layer space, the render
2911 // surface overlaps the right side of the layer. The g should be
2912 // the layer's right half.
2913 layer_to_surface_transform.MakeIdentity();
2914 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2915 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112916 // Right half of layer bounds.
2917 expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30);
2918 expected_drawable_content_rect = gfx::Rect(22, 22);
2919 drawing_layer = TestVisibleRectAndDrawableContentRect(
2920 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2921 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2922 EXPECT_EQ(expected_drawable_content_rect,
2923 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322924}
2925
weiliangc6da32862016-04-20 16:40:112926TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) {
2927 // Test visible layer rect and drawable content rect are calculated correctly
2928 // for 3d transforms.
[email protected]fb661802013-03-25 01:59:322929
[email protected]2c7c6702013-03-26 03:14:052930 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2931 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322932 gfx::Transform layer_to_surface_transform;
2933
2934 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2935 // degrees, should be fully contained in the render surface.
weiliangc6da32862016-04-20 16:40:112936 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]fb661802013-03-25 01:59:322937 layer_to_surface_transform.MakeIdentity();
2938 layer_to_surface_transform.RotateAboutYAxis(45.0);
weiliangc6da32862016-04-20 16:40:112939 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2940 gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100);
2941 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2942 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2943 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2944 EXPECT_EQ(expected_drawable_content_rect,
2945 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322946
2947 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2948 // degrees, but shifted to the side so only the right-half the layer would be
2949 // visible on the surface.
weiliangc6da32862016-04-20 16:40:112950 // 50 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262951 SkMScalar half_width_of_rotated_layer =
2952 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322953 layer_to_surface_transform.MakeIdentity();
2954 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232955 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2956 // edge of the layer.
weiliangc6da32862016-04-20 16:40:112957 // Tight half of the layer.
2958 expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100);
2959 expected_drawable_content_rect = gfx::Rect(36, 100);
2960 drawing_layer = TestVisibleRectAndDrawableContentRect(
2961 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2962 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2963 EXPECT_EQ(expected_drawable_content_rect,
2964 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322965}
2966
weiliangc6da32862016-04-20 16:40:112967TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) {
2968 // Test visible layer rect and drawable content rect are calculated correctly
2969 // when the layer has a perspective projection onto the target surface.
[email protected]fb661802013-03-25 01:59:322970
[email protected]2c7c6702013-03-26 03:14:052971 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2972 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322973 gfx::Transform layer_to_surface_transform;
2974
2975 // Case 1: Even though the layer is twice as large as the surface, due to
2976 // perspective foreshortening, the layer will fit fully in the surface when
2977 // its translated more than the perspective amount.
2978 layer_to_surface_transform.MakeIdentity();
2979
2980 // The following sequence of transforms applies the perspective about the
2981 // center of the surface.
2982 layer_to_surface_transform.Translate(50.0, 50.0);
2983 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2984 layer_to_surface_transform.Translate(-50.0, -50.0);
2985
2986 // This translate places the layer in front of the surface's projection plane.
2987 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2988
weiliangc6da32862016-04-20 16:40:112989 // Layer position is (-50, -50), visible rect in layer space is layer bounds
2990 // offset by layer position.
2991 gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150);
2992 gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38);
2993 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2994 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2995 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2996 EXPECT_EQ(expected_drawable_content_rect,
2997 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322998
2999 // Case 2: same projection as before, except that the layer is also translated
3000 // to the side, so that only the right half of the layer should be visible.
3001 //
3002 // Explanation of expected result: The perspective ratio is (z distance
3003 // between layer and camera origin) / (z distance between projection plane and
3004 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
weiliangc6da32862016-04-20 16:40:113005 // move a layer by translating -25 units in projected surface units (so that
[email protected]fb661802013-03-25 01:59:323006 // only half of it is visible), then we would need to translate by (-36 / 9) *
weiliangc6da32862016-04-20 16:40:113007 // -25 == -100 in the layer's units.
3008 layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0);
3009 // Visible layer rect is moved by 100, and drawable content rect is in target
3010 // space and is moved by 25.
3011 expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150);
3012 expected_drawable_content_rect = gfx::Rect(13, 38);
3013 drawing_layer = TestVisibleRectAndDrawableContentRect(
3014 target_surface_rect, layer_to_surface_transform, layer_content_rect);
3015 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
3016 EXPECT_EQ(expected_drawable_content_rect,
3017 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323018}
3019
weiliangc6da32862016-04-20 16:40:113020TEST_F(LayerTreeHostCommonDrawRectsTest,
3021 DrawRectsFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:323022 // There is currently no explicit concept of an orthographic projection plane
3023 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
3024 // are technically behind the surface in an orthographic world should not be
3025 // clipped when they are flattened to the surface.
3026
[email protected]2c7c6702013-03-26 03:14:053027 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
3028 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:323029 gfx::Transform layer_to_surface_transform;
3030
3031 // This sequence of transforms effectively rotates the layer about the y-axis
3032 // at the center of the layer.
3033 layer_to_surface_transform.MakeIdentity();
3034 layer_to_surface_transform.Translate(50.0, 0.0);
3035 layer_to_surface_transform.RotateAboutYAxis(45.0);
3036 layer_to_surface_transform.Translate(-50.0, 0.0);
3037
weiliangc6da32862016-04-20 16:40:113038 // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface
3039 // space.
3040 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
3041 gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100);
3042 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
3043 target_surface_rect, layer_to_surface_transform, layer_content_rect);
3044 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
3045 EXPECT_EQ(expected_drawable_content_rect,
3046 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323047}
3048
weiliangc6da32862016-04-20 16:40:113049TEST_F(LayerTreeHostCommonDrawRectsTest,
3050 DrawRectsFor3dPerspectiveWhenClippedByW) {
3051 // Test visible layer rect and drawable content rect are calculated correctly
3052 // when projecting a surface onto a layer, but the layer is partially behind
3053 // the camera (not just behind the projection plane). In this case, the
3054 // cartesian coordinates may seem to be valid, but actually they are not. The
3055 // visible rect needs to be properly clipped by the w = 0 plane in homogeneous
3056 // coordinates before converting to cartesian coordinates. The drawable
3057 // content rect would be entire surface rect because layer is rotated at the
3058 // camera position.
[email protected]fb661802013-03-25 01:59:323059
weiliangc6da32862016-04-20 16:40:113060 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200);
3061 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2);
[email protected]fb661802013-03-25 01:59:323062 gfx::Transform layer_to_surface_transform;
3063
3064 // The layer is positioned so that the right half of the layer should be in
3065 // front of the camera, while the other half is behind the surface's
3066 // projection plane. The following sequence of transforms applies the
3067 // perspective and rotation about the center of the layer.
3068 layer_to_surface_transform.MakeIdentity();
3069 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
weiliangc6da32862016-04-20 16:40:113070 layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0);
3071 layer_to_surface_transform.RotateAboutYAxis(-45.0);
3072 layer_to_surface_transform.Translate(-10, -1);
[email protected]fb661802013-03-25 01:59:323073
3074 // Sanity check that this transform does indeed cause w < 0 when applying the
3075 // transform, otherwise this code is not testing the intended scenario.
3076 bool clipped;
3077 MathUtil::MapQuad(layer_to_surface_transform,
3078 gfx::QuadF(gfx::RectF(layer_content_rect)),
3079 &clipped);
3080 ASSERT_TRUE(clipped);
3081
weiliangc6da32862016-04-20 16:40:113082 gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1);
3083 gfx::Rect expected_drawable_content_rect = target_surface_rect;
3084 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
3085 target_surface_rect, layer_to_surface_transform, layer_content_rect);
3086 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
3087 EXPECT_EQ(expected_drawable_content_rect,
3088 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323089}
3090
weiliangc6da32862016-04-20 16:40:113091TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:323092 // To determine visible rect in layer space, there needs to be an
3093 // un-projection from surface space to layer space. When the original
3094 // transform was a perspective projection that was clipped, it returns a rect
3095 // that encloses the clipped bounds. Un-projecting this new rect may require
3096 // clipping again.
3097
3098 // This sequence of transforms causes one corner of the layer to protrude
3099 // across the w = 0 plane, and should be clipped.
weiliangc6da32862016-04-20 16:40:113100 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150);
3101 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:323102 gfx::Transform layer_to_surface_transform;
3103 layer_to_surface_transform.MakeIdentity();
weiliangc6da32862016-04-20 16:40:113104 layer_to_surface_transform.Translate(10, 10);
[email protected]fb661802013-03-25 01:59:323105 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
3106 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
3107 layer_to_surface_transform.RotateAboutYAxis(45.0);
3108 layer_to_surface_transform.RotateAboutXAxis(80.0);
weiliangc6da32862016-04-20 16:40:113109 layer_to_surface_transform.Translate(-10, -10);
[email protected]fb661802013-03-25 01:59:323110
3111 // Sanity check that un-projection does indeed cause w < 0, otherwise this
3112 // code is not testing the intended scenario.
3113 bool clipped;
danakj5e6ff6d2015-09-05 04:43:443114 gfx::RectF clipped_rect = MathUtil::MapClippedRect(
3115 layer_to_surface_transform, gfx::RectF(layer_content_rect));
[email protected]fb661802013-03-25 01:59:323116 MathUtil::ProjectQuad(
3117 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
3118 ASSERT_TRUE(clipped);
3119
3120 // Only the corner of the layer is not visible on the surface because of being
3121 // clipped. But, the net result of rounding visible region to an axis-aligned
3122 // rect is that the entire layer should still be considered visible.
weiliangc6da32862016-04-20 16:40:113123 gfx::Rect expected_visible_layer_rect = layer_content_rect;
3124 gfx::Rect expected_drawable_content_rect = target_surface_rect;
3125 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
3126 target_surface_rect, layer_to_surface_transform, layer_content_rect);
3127 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
3128 EXPECT_EQ(expected_drawable_content_rect,
3129 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323130}
3131
miletus9d3da522015-06-05 19:45:073132TEST_F(LayerTreeHostCommonTest,
3133 VisibleRectsForPositionedRootLayerClippedByViewport) {
enne6c281f6e2015-08-18 23:23:003134 LayerImpl* root = root_layer();
3135 root->SetDrawsContent(true);
miletus9d3da522015-06-05 19:45:073136
3137 gfx::Transform identity_matrix;
3138 // Root layer is positioned at (60, 70). The default device viewport size
3139 // is (0, 0, 100x100) in target space. So the root layer's visible rect
3140 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
enne6c281f6e2015-08-18 23:23:003141 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
miletus9d3da522015-06-05 19:45:073142 gfx::PointF(60, 70), gfx::Size(100, 100), true,
enne6c281f6e2015-08-18 23:23:003143 false, true);
3144 ExecuteCalculateDrawProperties(root);
miletus9d3da522015-06-05 19:45:073145
danakj5e6ff6d2015-09-05 04:43:443146 EXPECT_EQ(gfx::RectF(100.f, 100.f),
miletus9d3da522015-06-05 19:45:073147 root->render_surface()->DrawableContentRect());
3148 // In target space, not clipped.
3149 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
3150 // In layer space, clipped.
danakj5e6ff6d2015-09-05 04:43:443151 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
miletus9d3da522015-06-05 19:45:073152}
3153
[email protected]989386c2013-07-18 21:37:233154TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
weiliangc0dece732015-07-27 19:06:173155 LayerImpl* root = root_layer();
3156 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
3157 child1_layer->SetDrawsContent(true);
3158 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
3159 child2_layer->SetDrawsContent(true);
3160 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
3161 child3_layer->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283162
[email protected]fb661802013-03-25 01:59:323163 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173164 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3165 gfx::PointF(), gfx::Size(100, 100), true, false,
3166 true);
3167 SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(),
3168 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]fb661802013-03-25 01:59:323169 false);
weiliangc0dece732015-07-27 19:06:173170 SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(),
3171 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3172 false, false);
3173 SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(),
3174 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3175 true, false, false);
[email protected]fb661802013-03-25 01:59:323176
weiliangc0dece732015-07-27 19:06:173177 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323178
danakj5e6ff6d2015-09-05 04:43:443179 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323180 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323181
danakj64767d902015-06-19 00:10:433182 // Layers that do not draw content should have empty visible_layer_rects.
3183 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323184
danakj64767d902015-06-19 00:10:433185 // layer visible_layer_rects are clipped by their target surface.
weiliangc0dece732015-07-27 19:06:173186 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
3187 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
3188 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323189
3190 // layer drawable_content_rects are not clipped.
weiliangc0dece732015-07-27 19:06:173191 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
3192 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
3193 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323194}
3195
[email protected]989386c2013-07-18 21:37:233196TEST_F(LayerTreeHostCommonTest,
3197 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
weiliangc0dece732015-07-27 19:06:173198 LayerImpl* root = root_layer();
3199 LayerImpl* child = AddChildToRoot<LayerImpl>();
3200 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
3201 grand_child1->SetDrawsContent(true);
3202 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
3203 grand_child2->SetDrawsContent(true);
3204 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
3205 grand_child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283206
[email protected]fb661802013-03-25 01:59:323207 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173208 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3209 gfx::PointF(), gfx::Size(100, 100), true, false,
3210 true);
3211 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
3212 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]fb661802013-03-25 01:59:323213 false);
weiliangc0dece732015-07-27 19:06:173214 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
3215 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3216 false, false);
3217 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
3218 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3219 false, false);
3220 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
3221 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3222 true, false, false);
[email protected]fb661802013-03-25 01:59:323223
3224 child->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:173225 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323226
danakj5e6ff6d2015-09-05 04:43:443227 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323228 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323229
3230 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433231 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3232 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323233
3234 // All grandchild visible content rects should be clipped by child.
danakj64767d902015-06-19 00:10:433235 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
3236 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
3237 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323238
3239 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:323240 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
3241 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323242 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
3243}
3244
ajuma27442dd2015-03-30 19:19:483245TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
jaydasika6f972de2016-04-07 16:16:143246 LayerImpl* root = root_layer();
3247 LayerImpl* child = AddChild<LayerImpl>(root);
3248 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma27442dd2015-03-30 19:19:483249
3250 gfx::Transform identity_matrix;
3251 gfx::Transform child_scale_matrix;
3252 child_scale_matrix.Scale(0.25f, 0.25f);
3253 gfx::Transform grand_child_scale_matrix;
3254 grand_child_scale_matrix.Scale(0.246f, 0.246f);
jaydasika6f972de2016-04-07 16:16:143255 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3256 gfx::PointF(), gfx::Size(100, 100), true, false,
3257 true);
3258 SetLayerPropertiesForTesting(child, child_scale_matrix, gfx::Point3F(),
3259 gfx::PointF(), gfx::Size(10, 10), true, false,
3260 false);
3261 SetLayerPropertiesForTesting(grand_child, grand_child_scale_matrix,
ajuma27442dd2015-03-30 19:19:483262 gfx::Point3F(), gfx::PointF(),
jaydasika6f972de2016-04-07 16:16:143263 gfx::Size(100, 100), true, false, false);
ajuma27442dd2015-03-30 19:19:483264
3265 child->SetMasksToBounds(true);
jaydasika6f972de2016-04-07 16:16:143266 grand_child->SetDrawsContent(true);
3267 ExecuteCalculateDrawProperties(root);
ajuma27442dd2015-03-30 19:19:483268
weiliangcd15784432016-06-07 17:57:333269 // The visible rect is expanded to integer coordinates.
3270 EXPECT_EQ(gfx::Rect(41, 41), grand_child->visible_layer_rect());
ajuma27442dd2015-03-30 19:19:483271}
3272
[email protected]989386c2013-07-18 21:37:233273TEST_F(LayerTreeHostCommonTest,
3274 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
weiliangc0dece732015-07-27 19:06:173275 LayerImpl* root = root_layer();
3276 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3277 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3278 child1->SetDrawsContent(true);
3279 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
3280 child2->SetDrawsContent(true);
3281 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
3282 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283283
[email protected]fb661802013-03-25 01:59:323284 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173285 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3286 gfx::PointF(), gfx::Size(100, 100), true, false,
3287 true);
3288 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3289 gfx::PointF(), gfx::Size(3, 4), true, false,
3290 true);
3291 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3292 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3293 false, false);
3294 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3295 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3296 false, false);
3297 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3298 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3299 true, false, false);
[email protected]fb661802013-03-25 01:59:323300
weiliangc0dece732015-07-27 19:06:173301 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323302
weiliangc0dece732015-07-27 19:06:173303 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323304
danakj5e6ff6d2015-09-05 04:43:443305 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323306 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323307
3308 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433309 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173310 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323311
3312 // An unclipped surface grows its DrawableContentRect to include all drawable
3313 // regions of the subtree.
danakj5e6ff6d2015-09-05 04:43:443314 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
weiliangc0dece732015-07-27 19:06:173315 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323316
3317 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:433318 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3319 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3320 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323321
hush6b614212014-12-04 22:37:323322 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3323 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3324 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323325}
3326
[email protected]989386c2013-07-18 21:37:233327TEST_F(LayerTreeHostCommonTest,
ajuma51d73f72015-10-19 19:43:583328 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) {
3329 LayerImpl* root = root_layer();
3330 LayerImpl* parent = AddChild<LayerImpl>(root);
3331 LayerImpl* child1 = AddChild<LayerImpl>(parent);
3332 LayerImpl* child2 = AddChild<LayerImpl>(parent);
3333 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1);
3334 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2);
3335 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
3336 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
3337
3338 root->SetDrawsContent(true);
3339 parent->SetDrawsContent(true);
3340 child1->SetDrawsContent(true);
3341 child2->SetDrawsContent(true);
3342 grand_child1->SetDrawsContent(true);
3343 grand_child2->SetDrawsContent(true);
3344 leaf_node1->SetDrawsContent(true);
3345 leaf_node2->SetDrawsContent(true);
3346
3347 const gfx::Transform identity_matrix;
3348
3349 // child1 and child2 get render surfaces when surfaces are enabled.
3350 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3351 gfx::PointF(), gfx::Size(100, 100), true, false,
3352 true);
3353 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3354 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
3355 false, false);
3356 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3357 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
3358 false, true);
3359 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3360 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
3361 false, true);
3362 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
3363 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
3364 true, false, false);
3365 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
3366 gfx::PointF(7.f, 7.f), gfx::Size(1500, 1500),
3367 true, false, false);
3368 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
3369 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
3370 true, false, false);
3371 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
3372 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
3373 true, false, false);
3374
3375 // Case 1: No layers clip. Visible rects are clipped by the viewport, but the
3376 // viewport clip doesn't apply to layers that draw into unclipped surfaces.
3377 // Each layer's drawable content rect is its bounds in target space; the only
3378 // thing that changes with surfaces disabled is that target space is always
3379 // screen space.
weiliangcc154ce22015-12-09 03:39:263380 root->SetHasRenderSurface(true);
3381 child1->SetHasRenderSurface(true);
3382 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583383 ExecuteCalculateDrawProperties(root);
3384 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3385 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect());
3386 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3387 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3388 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child1->visible_layer_rect());
3389 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3390 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node1->visible_layer_rect());
3391 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node2->visible_layer_rect());
3392
3393 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3394 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3395 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3396 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3397 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3398 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3399 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3400 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3401
3402 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3403 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3404 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3405 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3406 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3407 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3408 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3409 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3410 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3411
3412 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3413 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3414 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3415 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3416 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500),
3417 grand_child1->drawable_content_rect());
3418 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3419 grand_child2->drawable_content_rect());
3420 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect());
3421 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect());
3422
3423 // Case 2: The parent clips. In this case, neither surface is unclipped, so
3424 // all visible layer rects are clipped by the intersection of all ancestor
3425 // clips, whether or not surfaces are disabled. However, drawable content
3426 // rects are clipped only until the next render surface is reached, so
3427 // descendants of parent have their drawable content rects clipped only when
3428 // surfaces are disabled.
3429 parent->SetMasksToBounds(true);
3430 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:263431 root->SetHasRenderSurface(true);
3432 child1->SetHasRenderSurface(true);
3433 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583434 ExecuteCalculateDrawProperties(root);
3435 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3436 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3437 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3438 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3439 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3440 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3441 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3442 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3443
3444 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3445 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3446 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3447 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3448 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3449 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3450 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3451 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3452
3453 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3454 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3455 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3456 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3457 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3458 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3459 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3460 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3461 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3462
3463 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3464 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3465 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect());
3466 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect());
3467 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect());
3468 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect());
3469 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect());
3470 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect());
3471
3472 parent->SetMasksToBounds(false);
3473
3474 // Case 3: child1 and grand_child2 clip. In this case, descendants of these
3475 // layers have their visible rects clipped by them; without surfaces, these
3476 // rects are also clipped by the viewport. Similarly, descendants of these
3477 // layers have their drawable content rects clipped by them.
3478 child1->SetMasksToBounds(true);
3479 grand_child2->SetMasksToBounds(true);
3480 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:263481 root->SetHasRenderSurface(true);
3482 child1->SetHasRenderSurface(true);
3483 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583484 ExecuteCalculateDrawProperties(root);
3485 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3486 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3487 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3488 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3489 EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect());
3490 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3491 EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect());
3492 EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect());
3493
3494 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3495 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3496 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3497 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3498 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect());
3499 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3500 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect());
3501 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect());
3502
3503 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3504 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3505 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3506 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3507 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3508 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3509 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3510 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3511 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3512
3513 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3514 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3515 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3516 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3517 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect());
3518 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3519 grand_child2->drawable_content_rect());
3520 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect());
3521 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect());
3522}
3523
3524TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:023525 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
enne6c281f6e2015-08-18 23:23:003526 LayerImpl* root = root_layer();
3527 LayerImpl* child1 = AddChild<LayerImpl>(root);
3528 LayerImpl* child2 = AddChild<LayerImpl>(root);
3529 LayerImpl* child3 = AddChild<LayerImpl>(root);
3530 child1->SetDrawsContent(true);
3531 child2->SetDrawsContent(true);
3532 child3->SetDrawsContent(true);
hush887bb542014-12-02 22:49:023533
3534 gfx::Transform identity_matrix;
enne6c281f6e2015-08-18 23:23:003535 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3536 gfx::PointF(), gfx::Size(100, 100), true, false,
3537 true);
3538 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023539 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
enne6c281f6e2015-08-18 23:23:003540 false, false);
3541 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023542 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
enne6c281f6e2015-08-18 23:23:003543 false, false);
3544 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023545 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
enne6c281f6e2015-08-18 23:23:003546 true, false, false);
hush887bb542014-12-02 22:49:023547
enne6c281f6e2015-08-18 23:23:003548 LayerImplList render_surface_layer_list_impl;
hush887bb542014-12-02 22:49:023549 // Now set the root render surface an empty clip.
enne6c281f6e2015-08-18 23:23:003550 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:383551 root, gfx::Size(), &render_surface_layer_list_impl);
hush887bb542014-12-02 22:49:023552
sunxdb365de02016-04-28 20:32:573553 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
hush887bb542014-12-02 22:49:023554 ASSERT_TRUE(root->render_surface());
3555 EXPECT_FALSE(root->is_clipped());
3556
3557 gfx::Rect empty;
3558 EXPECT_EQ(empty, root->render_surface()->clip_rect());
3559 EXPECT_TRUE(root->render_surface()->is_clipped());
3560
3561 // Visible content rect calculation will check if the target surface is
3562 // clipped or not. An empty clip rect does not indicate the render surface
3563 // is unclipped.
danakj64767d902015-06-19 00:10:433564 EXPECT_EQ(empty, child1->visible_layer_rect());
3565 EXPECT_EQ(empty, child2->visible_layer_rect());
3566 EXPECT_EQ(empty, child3->visible_layer_rect());
hush887bb542014-12-02 22:49:023567}
3568
3569TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233570 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
weiliangc0dece732015-07-27 19:06:173571 LayerImpl* root = root_layer();
3572 LayerImpl* child = AddChildToRoot<LayerImpl>();
3573 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283574
[email protected]630ddad2013-08-16 03:01:323575 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473576 gfx::Transform identity_matrix;
3577 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323578 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473579
weiliangc0dece732015-07-27 19:06:173580 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3581 gfx::PointF(), gfx::Size(100, 100), true, false,
3582 true);
3583 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3584 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3585 false, false);
[email protected]451107a32013-04-10 05:12:473586
weiliangc0dece732015-07-27 19:06:173587 ExecuteCalculateDrawProperties(root);
[email protected]451107a32013-04-10 05:12:473588
danakj64767d902015-06-19 00:10:433589 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473590 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323591
[email protected]08bdf1b2014-04-16 23:23:293592 // Case 2: a matrix with flattened z, uninvertible and not visible according
3593 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:323594 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263595 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323596 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3597
weiliangc0dece732015-07-27 19:06:173598 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3599 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3600 false, false);
[email protected]630ddad2013-08-16 03:01:323601
weiliangc0dece732015-07-27 19:06:173602 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323603
danakj64767d902015-06-19 00:10:433604 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293605 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323606
[email protected]08bdf1b2014-04-16 23:23:293607 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:323608 uninvertible_matrix.MakeIdentity();
3609 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263610 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323611 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3612
weiliangc0dece732015-07-27 19:06:173613 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3614 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3615 false, false);
[email protected]630ddad2013-08-16 03:01:323616
weiliangc0dece732015-07-27 19:06:173617 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323618
danakj64767d902015-06-19 00:10:433619 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293620 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473621}
3622
[email protected]989386c2013-07-18 21:37:233623TEST_F(LayerTreeHostCommonTest,
ajumaae0dc2d2015-08-05 21:55:563624 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
3625 LayerImpl* root = root_layer();
3626 LayerImpl* child = AddChildToRoot<LayerImpl>();
3627 LayerImpl* grand_child = AddChild<LayerImpl>(child);
3628 child->SetDrawsContent(true);
3629 grand_child->SetDrawsContent(true);
3630
3631 gfx::Transform identity_matrix;
3632
3633 gfx::Transform perspective;
3634 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3635
3636 gfx::Transform rotation;
3637 rotation.RotateAboutYAxis(45.0);
3638
3639 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3640 gfx::PointF(), gfx::Size(100, 100), true, false,
3641 true);
3642 SetLayerPropertiesForTesting(child, perspective, gfx::Point3F(),
3643 gfx::PointF(10.f, 10.f), gfx::Size(100, 100),
3644 false, true, false);
3645 SetLayerPropertiesForTesting(grand_child, rotation, gfx::Point3F(),
3646 gfx::PointF(), gfx::Size(100, 100), false, true,
3647 false);
3648
3649 ExecuteCalculateDrawProperties(root);
3650
3651 // Though all layers have invertible transforms, matrix multiplication using
3652 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053653 EXPECT_FALSE(root->layer_tree_impl()
3654 ->property_trees()
3655 ->transform_tree.Node(grand_child->transform_tree_index())
3656 ->data.ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563657
sunxd71aea3e2016-04-01 23:48:053658 // CalcDrawProps skips a subtree when a layer's screen space transform is
3659 // uninvertible
3660 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
ajumaae0dc2d2015-08-05 21:55:563661}
3662
3663TEST_F(LayerTreeHostCommonTest,
3664 OcclusionForLayerWithUninvertibleDrawTransform) {
khushalsagarb64b360d2015-10-21 19:25:163665 FakeImplTaskRunnerProvider task_runner_provider;
ajumaae0dc2d2015-08-05 21:55:563666 TestSharedBitmapManager shared_bitmap_manager;
3667 TestTaskGraphRunner task_graph_runner;
danakj60bc3bc2016-04-09 00:24:483668 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
khushalsagarb64b360d2015-10-21 19:25:163669 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
ajumaae0dc2d2015-08-05 21:55:563670 &task_graph_runner);
danakj60bc3bc2016-04-09 00:24:483671 std::unique_ptr<LayerImpl> root =
3672 LayerImpl::Create(host_impl.active_tree(), 1);
3673 std::unique_ptr<LayerImpl> child =
3674 LayerImpl::Create(host_impl.active_tree(), 2);
3675 std::unique_ptr<LayerImpl> grand_child =
ajumaae0dc2d2015-08-05 21:55:563676 LayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:483677 std::unique_ptr<LayerImpl> occluding_child =
ajumaae0dc2d2015-08-05 21:55:563678 LayerImpl::Create(host_impl.active_tree(), 4);
3679 child->SetDrawsContent(true);
3680 grand_child->SetDrawsContent(true);
3681 occluding_child->SetDrawsContent(true);
3682 occluding_child->SetContentsOpaque(true);
3683
3684 gfx::Transform identity_matrix;
3685 gfx::Transform perspective;
3686 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3687
3688 gfx::Transform rotation;
3689 rotation.RotateAboutYAxis(45.0);
3690
3691 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
3692 gfx::PointF(), gfx::Size(1000, 1000), true,
3693 false, true);
3694 SetLayerPropertiesForTesting(child.get(), perspective, gfx::Point3F(),
3695 gfx::PointF(10.f, 10.f), gfx::Size(300, 300),
3696 false, true, false);
3697 SetLayerPropertiesForTesting(grand_child.get(), rotation, gfx::Point3F(),
3698 gfx::PointF(), gfx::Size(200, 200), false, true,
3699 false);
3700 SetLayerPropertiesForTesting(occluding_child.get(), identity_matrix,
3701 gfx::Point3F(), gfx::PointF(),
3702 gfx::Size(200, 200), false, false, false);
3703
3704 host_impl.SetViewportSize(root->bounds());
3705
danakja04855a2015-11-18 20:39:103706 child->AddChild(std::move(grand_child));
3707 root->AddChild(std::move(child));
3708 root->AddChild(std::move(occluding_child));
3709 host_impl.active_tree()->SetRootLayer(std::move(root));
sievers71c62dd52015-10-07 01:44:393710 host_impl.SetVisible(true);
revemand180dfc32015-09-24 00:19:433711 host_impl.InitializeRenderer(output_surface.get());
jaydasika4340ea02016-06-06 19:44:263712 host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting();
ajumaae0dc2d2015-08-05 21:55:563713 bool update_lcd_text = false;
3714 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3715
3716 LayerImpl* grand_child_ptr =
vollick83fbfc82016-03-22 18:33:273717 host_impl.active_tree()->root_layer()->children()[0]->children()[0];
ajumaae0dc2d2015-08-05 21:55:563718
3719 // Though all layers have invertible transforms, matrix multiplication using
3720 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053721 EXPECT_FALSE(
3722 host_impl.active_tree()
3723 ->property_trees()
3724 ->transform_tree.Node(grand_child_ptr->transform_tree_index())
3725 ->data.ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563726
sunxd71aea3e2016-04-01 23:48:053727 // Since |grand_child| has an uninvertible screen space transform, it is
3728 // skipped so
3729 // that we are not computing its occlusion_in_content_space.
3730 gfx::Rect layer_bounds = gfx::Rect();
ajumaae0dc2d2015-08-05 21:55:563731 EXPECT_EQ(
3732 layer_bounds,
3733 grand_child_ptr->draw_properties()
3734 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
3735}
3736
3737TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233738 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
weiliangc0dece732015-07-27 19:06:173739 LayerImpl* root = root_layer();
3740 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3741 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3742 child1->SetDrawsContent(true);
3743 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
3744 child2->SetDrawsContent(true);
3745 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
3746 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283747
[email protected]fb661802013-03-25 01:59:323748 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173749 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3750 gfx::PointF(), gfx::Size(100, 100), true, false,
3751 true);
3752 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3753 gfx::PointF(), gfx::Size(3, 4), true, false,
3754 true);
3755 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3756 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3757 false, false);
3758 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3759 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3760 false, false);
3761 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3762 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3763 true, false, false);
[email protected]fb661802013-03-25 01:59:323764
3765 root->SetMasksToBounds(true);
[email protected]fb661802013-03-25 01:59:323766
weiliangc0dece732015-07-27 19:06:173767 ExecuteCalculateDrawProperties(root);
3768
3769 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323770
danakj5e6ff6d2015-09-05 04:43:443771 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323772 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323773
3774 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433775 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173776 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323777
3778 // A clipped surface grows its DrawableContentRect to include all drawable
3779 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443780 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
weiliangc0dece732015-07-27 19:06:173781 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323782
3783 // All layers that draw content into the surface have their visible content
3784 // rect clipped by the surface clip rect.
danakj64767d902015-06-19 00:10:433785 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3786 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3787 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323788
3789 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323790 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3791 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3792 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323793}
3794
[email protected]989386c2013-07-18 21:37:233795TEST_F(LayerTreeHostCommonTest,
3796 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323797 // Check that clipping does not propagate down surfaces.
weiliangc0dece732015-07-27 19:06:173798 LayerImpl* root = root_layer();
3799 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3800 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
3801 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
3802 child1->SetDrawsContent(true);
3803 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
3804 child2->SetDrawsContent(true);
3805 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
3806 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283807
[email protected]fb661802013-03-25 01:59:323808 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173809 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3810 gfx::PointF(), gfx::Size(100, 100), true, false,
3811 true);
3812 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3813 gfx::PointF(), gfx::Size(3, 4), true, false,
3814 true);
3815 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3816 gfx::PointF(), gfx::Size(7, 13), true, false,
3817 true);
3818 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3819 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3820 false, false);
3821 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3822 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3823 false, false);
3824 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3825 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3826 true, false, false);
[email protected]fb661802013-03-25 01:59:323827
3828 root->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:173829
3830 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323831
3832 ASSERT_TRUE(render_surface1->render_surface());
3833 ASSERT_TRUE(render_surface2->render_surface());
3834
danakj5e6ff6d2015-09-05 04:43:443835 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323836 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323837
3838 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433839 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3840 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3841 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323842
3843 // A clipped surface grows its DrawableContentRect to include all drawable
3844 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443845 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
hush6b614212014-12-04 22:37:323846 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323847
3848 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3849 // is only implicitly clipped by render_surface1's content rect. So,
3850 // render_surface2 grows to enclose all drawable content of its subtree.
danakj5e6ff6d2015-09-05 04:43:443851 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
hush6b614212014-12-04 22:37:323852 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323853
3854 // All layers that draw content into render_surface2 think they are unclipped.
danakj64767d902015-06-19 00:10:433855 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3856 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3857 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323858
3859 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323860 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3861 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3862 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323863}
3864
[email protected]989386c2013-07-18 21:37:233865TEST_F(LayerTreeHostCommonTest,
jaydasika27d0f2e2015-10-16 23:52:463866 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) {
3867 LayerImpl* root = root_layer();
3868 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3869 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
3870 LayerImpl* child2 = AddChild<LayerImpl>(child1);
3871 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2);
3872 child1->SetDrawsContent(true);
3873 child2->SetDrawsContent(true);
3874 render_surface2->SetDrawsContent(true);
3875
3876 gfx::Transform identity_matrix;
3877 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3878 gfx::PointF(), gfx::Size(100, 100), true, false,
3879 true);
3880 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3881 gfx::PointF(), gfx::Size(100, 100), true, false,
3882 true);
3883 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3884 gfx::PointF(), gfx::Size(500, 500), true, false,
3885 false);
3886 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3887 gfx::PointF(), gfx::Size(700, 700), true, false,
3888 false);
3889 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3890 gfx::PointF(), gfx::Size(1000, 1000), true,
3891 false, true);
3892
3893 child1->SetMasksToBounds(true);
3894 child2->SetMasksToBounds(true);
3895
3896 ExecuteCalculateDrawProperties(root);
3897 EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect());
3898 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect());
3899}
3900
3901TEST_F(LayerTreeHostCommonTest,
3902 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) {
3903 LayerImpl* root = root_layer();
3904 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3905 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3906 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3907 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3908
3909 render_surface1->SetDrawsContent(true);
3910 render_surface2->SetDrawsContent(true);
3911 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563912 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:483913 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika27d0f2e2015-10-16 23:52:463914 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:563915 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika27d0f2e2015-10-16 23:52:463916
3917 gfx::Transform identity_matrix;
3918 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3919 gfx::PointF(), gfx::Size(100, 100), true, false,
3920 true);
3921 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3922 gfx::PointF(), gfx::Size(50, 50), true, false,
3923 false);
3924 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3925 gfx::PointF(), gfx::Size(20, 20), true, false,
3926 true);
3927 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3928 gfx::PointF(), gfx::Size(60, 60), true, false,
3929 false);
3930 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3931 gfx::PointF(), gfx::Size(60, 60), true, false,
3932 true);
3933 clip_parent->SetMasksToBounds(true);
3934 render_surface1->SetMasksToBounds(true);
3935
3936 ExecuteCalculateDrawProperties(root);
3937 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect());
3938 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect());
3939 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect());
3940}
3941
jaydasika1f5312d2015-10-21 21:34:323942TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) {
3943 LayerImpl* root = root_layer();
3944 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3945 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3946 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3947 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3948
3949 render_surface1->SetDrawsContent(true);
3950 render_surface2->SetDrawsContent(true);
3951 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563952 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:483953 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika1f5312d2015-10-21 21:34:323954 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:563955 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika1f5312d2015-10-21 21:34:323956
3957 gfx::Transform identity_matrix;
3958 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3959 gfx::PointF(), gfx::Size(100, 100), true, false,
3960 true);
3961 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3962 gfx::PointF(2.f, 2.f), gfx::Size(50, 50), true,
3963 false, false);
3964 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3965 gfx::PointF(), gfx::Size(20, 20), true, false,
3966 true);
3967 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3968 gfx::PointF(), gfx::Size(60, 60), true, false,
3969 false);
3970 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3971 gfx::PointF(), gfx::Size(60, 60), true, false,
3972 true);
3973 clip_parent->SetMasksToBounds(true);
3974 render_surface1->SetMasksToBounds(true);
3975
3976 ExecuteCalculateDrawProperties(root);
3977 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect());
3978}
3979
jaydasika77a4a072015-10-20 21:47:273980TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) {
3981 // Test that only drawn layers contribute to render surface content rect.
3982 LayerImpl* root = root_layer();
3983 LayerImpl* surface = AddChildToRoot<LayerImpl>();
3984 LayerImpl* test_layer = AddChild<LayerImpl>(surface);
3985
3986 test_layer->SetDrawsContent(false);
3987 surface->SetDrawsContent(true);
3988 gfx::Transform identity_matrix;
3989 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3990 gfx::PointF(), gfx::Size(200, 200), true, false,
3991 true);
3992 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
3993 gfx::PointF(), gfx::Size(100, 100), true, false,
3994 true);
3995 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
3996 gfx::PointF(), gfx::Size(150, 150), true, false,
3997 false);
3998
3999 ExecuteCalculateDrawProperties(root);
4000 EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect());
4001
4002 test_layer->SetDrawsContent(true);
4003 ExecuteCalculateDrawProperties(root);
4004 EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect());
4005}
4006
jaydasika27d0f2e2015-10-16 23:52:464007TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) {
4008 // Tests visible rects computation when we have unclipped_surface->
4009 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
4010 // of surface_with_unclipped_descendants doesn't propagate to the
4011 // clipped_surface below it.
4012 LayerImpl* root = root_layer();
4013 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
4014 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
4015 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
4016 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
4017 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
4018
4019 unclipped_surface->SetDrawsContent(true);
4020 unclipped_desc_surface->SetDrawsContent(true);
4021 clipped_surface->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:564022 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:484023 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika27d0f2e2015-10-16 23:52:464024 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:564025 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika27d0f2e2015-10-16 23:52:464026
4027 gfx::Transform identity_matrix;
4028 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4029 gfx::PointF(), gfx::Size(100, 100), true, false,
4030 true);
4031 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
4032 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4033 true, false, true);
4034 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
4035 gfx::PointF(), gfx::Size(50, 50), true, false,
4036 false);
4037 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
4038 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4039 true, false, true);
4040 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
4041 gfx::PointF(), gfx::Size(60, 60), true, false,
4042 false);
4043 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
4044 gfx::PointF(), gfx::Size(60, 60), true, false,
4045 true);
4046 clip_parent->SetMasksToBounds(true);
4047
4048 ExecuteCalculateDrawProperties(root);
4049 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect());
4050 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect());
4051 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect());
4052}
4053
4054TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) {
4055 // Tests visible rects computation when we have unclipped_surface->
4056 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
4057 // of root propagate to the clipped_surface.
4058 LayerImpl* root = root_layer();
4059 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
4060 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
4061 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
4062 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
4063 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
4064
4065 unclipped_surface->SetDrawsContent(true);
4066 unclipped_desc_surface->SetDrawsContent(true);
4067 clipped_surface->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:564068 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:484069 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika27d0f2e2015-10-16 23:52:464070 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:564071 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika27d0f2e2015-10-16 23:52:464072
4073 gfx::Transform identity_matrix;
4074 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4075 gfx::PointF(), gfx::Size(10, 10), true, false,
4076 true);
4077 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
4078 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
4079 true, false, true);
4080 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
4081 gfx::PointF(), gfx::Size(50, 50), true, false,
4082 false);
4083 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
4084 gfx::Point3F(), gfx::PointF(),
4085 gfx::Size(100, 100), true, false, true);
4086 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
4087 gfx::PointF(), gfx::Size(100, 100), true, false,
4088 false);
4089 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
4090 gfx::PointF(), gfx::Size(50, 50), true, false,
4091 true);
4092 clip_parent->SetMasksToBounds(true);
4093 unclipped_desc_surface->SetMasksToBounds(true);
4094
4095 ExecuteCalculateDrawProperties(root);
4096 EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect());
weiliangc0e13ba602016-03-12 04:53:564097 EXPECT_EQ(gfx::Rect(50, 50), unclipped_desc_surface->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:464098 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect());
4099}
4100
4101TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:234102 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:324103 // Layers that have non-axis aligned bounds (due to transforms) have an
4104 // expanded, axis-aligned DrawableContentRect and visible content rect.
weiliangc0dece732015-07-27 19:06:174105 LayerImpl* root = root_layer();
4106 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4107 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
4108 child1->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284109
[email protected]fb661802013-03-25 01:59:324110 gfx::Transform identity_matrix;
4111 gfx::Transform child_rotation;
4112 child_rotation.Rotate(45.0);
weiliangc0dece732015-07-27 19:06:174113 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4114 gfx::PointF(), gfx::Size(100, 100), true, false,
4115 true);
4116 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
4117 gfx::PointF(), gfx::Size(3, 4), true, false,
4118 true);
4119 SetLayerPropertiesForTesting(
4120 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
4121 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
[email protected]fb661802013-03-25 01:59:324122
weiliangc0dece732015-07-27 19:06:174123 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:324124
weiliangc0dece732015-07-27 19:06:174125 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324126
danakj5e6ff6d2015-09-05 04:43:444127 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:324128 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324129
4130 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:434131 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:174132 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324133
4134 // The unclipped surface grows its DrawableContentRect to include all drawable
4135 // regions of the subtree.
4136 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
4137 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:264138 gfx::Rect(50 - diagonal_radius,
4139 50 - diagonal_radius,
4140 diagonal_radius * 2,
4141 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444142 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content),
weiliangc0dece732015-07-27 19:06:174143 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324144
4145 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:434146 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
hush6b614212014-12-04 22:37:324147 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324148}
4149
[email protected]989386c2013-07-18 21:37:234150TEST_F(LayerTreeHostCommonTest,
4151 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:324152 // Layers that have non-axis aligned bounds (due to transforms) have an
4153 // expanded, axis-aligned DrawableContentRect and visible content rect.
weiliangc0dece732015-07-27 19:06:174154 LayerImpl* root = root_layer();
4155 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4156 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
4157 child1->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284158
[email protected]fb661802013-03-25 01:59:324159 gfx::Transform identity_matrix;
4160 gfx::Transform child_rotation;
4161 child_rotation.Rotate(45.0);
weiliangc0dece732015-07-27 19:06:174162 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4163 gfx::PointF(), gfx::Size(50, 50), true, false,
4164 true);
4165 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
4166 gfx::PointF(), gfx::Size(3, 4), true, false,
4167 true);
[email protected]a2566412014-06-05 03:14:204168
weiliangc0dece732015-07-27 19:06:174169 SetLayerPropertiesForTesting(
4170 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
4171 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
[email protected]fb661802013-03-25 01:59:324172
4173 root->SetMasksToBounds(true);
[email protected]fb661802013-03-25 01:59:324174
weiliangc0dece732015-07-27 19:06:174175 ExecuteCalculateDrawProperties(root);
4176
4177 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324178
4179 // The clipped surface clamps the DrawableContentRect that encloses the
4180 // rotated layer.
4181 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:264182 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
4183 50 - diagonal_radius,
4184 diagonal_radius * 2,
4185 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444186 gfx::RectF expected_surface_drawable_content(
4187 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
hush6b614212014-12-04 22:37:324188 EXPECT_EQ(expected_surface_drawable_content,
weiliangc0dece732015-07-27 19:06:174189 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324190
4191 // On the clipped surface, only a quarter of the child1 is visible, but when
4192 // rotating it back to child1's content space, the actual enclosing rect ends
4193 // up covering the full left half of child1.
weiliangcd15784432016-06-07 17:57:334194 EXPECT_EQ(gfx::Rect(0, 0, 25, 50), child1->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324195
4196 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:324197 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324198}
4199
[email protected]989386c2013-07-18 21:37:234200TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
weiliangc0dece732015-07-27 19:06:174201 LayerImpl* root = root_layer();
4202 FakePictureLayerImpl* render_surface1 =
4203 AddChildToRoot<FakePictureLayerImpl>();
4204 render_surface1->SetDrawsContent(true);
4205 FakePictureLayerImpl* render_surface2 =
4206 AddChild<FakePictureLayerImpl>(render_surface1);
4207 render_surface2->SetDrawsContent(true);
4208 FakePictureLayerImpl* child1 =
4209 AddChild<FakePictureLayerImpl>(render_surface2);
4210 child1->SetDrawsContent(true);
4211 FakePictureLayerImpl* child2 =
4212 AddChild<FakePictureLayerImpl>(render_surface2);
4213 child2->SetDrawsContent(true);
4214 FakePictureLayerImpl* child3 =
4215 AddChild<FakePictureLayerImpl>(render_surface2);
4216 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284217
[email protected]fb661802013-03-25 01:59:324218 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:174219 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4220 gfx::PointF(), gfx::Size(100, 100), true, false,
4221 true);
4222 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
4223 gfx::PointF(5.f, 5.f), gfx::Size(3, 4), true,
4224 false, true);
4225 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
4226 gfx::PointF(5.f, 5.f), gfx::Size(7, 13), true,
4227 false, true);
4228 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
4229 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
4230 false, false);
4231 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4232 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
4233 false, false);
4234 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
4235 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
4236 true, false, false);
[email protected]fb661802013-03-25 01:59:324237
4238 float device_scale_factor = 2.f;
4239
4240 root->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:174241
4242 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324243
4244 ASSERT_TRUE(render_surface1->render_surface());
4245 ASSERT_TRUE(render_surface2->render_surface());
4246
4247 // drawable_content_rects for all layers and surfaces are scaled by
4248 // device_scale_factor.
danakj5e6ff6d2015-09-05 04:43:444249 EXPECT_EQ(gfx::RectF(200.f, 200.f),
hush6b614212014-12-04 22:37:324250 root->render_surface()->DrawableContentRect());
danakj5e6ff6d2015-09-05 04:43:444251 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
hush6b614212014-12-04 22:37:324252 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324253
4254 // render_surface2 lives in the "unclipped universe" of render_surface1, and
4255 // is only implicitly clipped by render_surface1.
danakj5e6ff6d2015-09-05 04:43:444256 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f),
hush6b614212014-12-04 22:37:324257 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324258
hush6b614212014-12-04 22:37:324259 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
4260 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
4261 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324262
4263 // The root layer does not actually draw content of its own.
danakj64767d902015-06-19 00:10:434264 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324265
sohan.jyotie3bd6192014-10-13 07:13:594266 // All layer visible content rects are not expressed in content space of each
4267 // layer, so they are not scaled by the device_scale_factor.
danakj64767d902015-06-19 00:10:434268 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
4269 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
4270 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
4271 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
4272 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324273}
4274
[email protected]989386c2013-07-18 21:37:234275TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:324276 // Verify the behavior of back-face culling when there are no preserve-3d
4277 // layers. Note that 3d transforms still apply in this case, but they are
4278 // "flattened" to each parent layer according to current W3C spec.
4279
4280 const gfx::Transform identity_matrix;
ajuma4711f4b12016-05-16 18:48:324281 LayerImpl* parent = root_layer();
4282 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4283 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4284 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4285 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4286 LayerImpl* front_facing_child_of_front_facing_surface =
4287 AddChild<LayerImpl>(front_facing_surface);
4288 LayerImpl* back_facing_child_of_front_facing_surface =
4289 AddChild<LayerImpl>(front_facing_surface);
4290 LayerImpl* front_facing_child_of_back_facing_surface =
4291 AddChild<LayerImpl>(back_facing_surface);
4292 LayerImpl* back_facing_child_of_back_facing_surface =
4293 AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284294
[email protected]fb661802013-03-25 01:59:324295 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324296 front_facing_child->test_properties()->double_sided = false;
4297 back_facing_child->test_properties()->double_sided = false;
4298 front_facing_surface->test_properties()->double_sided = false;
4299 back_facing_surface->test_properties()->double_sided = false;
4300 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4301 false;
4302 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4303 false;
4304 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4305 false;
4306 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4307 false;
4308
4309 // Everything draws content.
4310 front_facing_child->SetDrawsContent(true);
4311 back_facing_child->SetDrawsContent(true);
4312 front_facing_surface->SetDrawsContent(true);
4313 back_facing_surface->SetDrawsContent(true);
4314 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4315 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4316 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4317 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324318
4319 gfx::Transform backface_matrix;
4320 backface_matrix.Translate(50.0, 50.0);
4321 backface_matrix.RotateAboutYAxis(180.0);
4322 backface_matrix.Translate(-50.0, -50.0);
4323
4324 // Having a descendant and opacity will force these to have render surfaces.
jaydasikaab317e02016-06-01 00:53:184325 front_facing_surface->test_properties()->opacity = 0.5f;
4326 back_facing_surface->test_properties()->opacity = 0.5f;
[email protected]fb661802013-03-25 01:59:324327
4328 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
4329 // these layers should blindly use their own local transforms to determine
4330 // back-face culling.
ajuma4711f4b12016-05-16 18:48:324331 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4332 gfx::PointF(), gfx::Size(100, 100), true, false);
4333 SetLayerPropertiesForTesting(front_facing_child, identity_matrix,
4334 gfx::Point3F(), gfx::PointF(),
4335 gfx::Size(100, 100), true, false);
4336 SetLayerPropertiesForTesting(back_facing_child, backface_matrix,
4337 gfx::Point3F(), gfx::PointF(),
4338 gfx::Size(100, 100), true, false);
4339 SetLayerPropertiesForTesting(front_facing_surface, identity_matrix,
4340 gfx::Point3F(), gfx::PointF(),
4341 gfx::Size(100, 100), true, false);
4342 SetLayerPropertiesForTesting(back_facing_surface, backface_matrix,
4343 gfx::Point3F(), gfx::PointF(),
4344 gfx::Size(100, 100), true, false);
4345 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface,
4346 identity_matrix, gfx::Point3F(), gfx::PointF(),
4347 gfx::Size(100, 100), true, false);
4348 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface,
4349 backface_matrix, gfx::Point3F(), gfx::PointF(),
4350 gfx::Size(100, 100), true, false);
4351 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface,
4352 identity_matrix, gfx::Point3F(), gfx::PointF(),
4353 gfx::Size(100, 100), true, false);
4354 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface,
4355 backface_matrix, gfx::Point3F(), gfx::PointF(),
4356 gfx::Size(100, 100), true, false);
[email protected]fb661802013-03-25 01:59:324357
ajuma4711f4b12016-05-16 18:48:324358 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:324359
4360 // Verify which render surfaces were created.
ennec1332992015-08-24 19:45:094361 EXPECT_FALSE(front_facing_child->has_render_surface());
4362 EXPECT_FALSE(back_facing_child->has_render_surface());
4363 EXPECT_TRUE(front_facing_surface->has_render_surface());
4364 EXPECT_TRUE(back_facing_surface->has_render_surface());
4365 EXPECT_FALSE(
4366 front_facing_child_of_front_facing_surface->has_render_surface());
4367 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4368 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4369 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324370
ajuma4711f4b12016-05-16 18:48:324371 EXPECT_EQ(4u, update_layer_list_impl()->size());
4372 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4373 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4374 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534375 front_facing_child_of_front_facing_surface->id()));
ajuma4711f4b12016-05-16 18:48:324376 EXPECT_TRUE(UpdateLayerListImplContains(
4377 front_facing_child_of_back_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324378}
4379
[email protected]989386c2013-07-18 21:37:234380TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:324381 // Verify the behavior of back-face culling when preserves-3d transform style
4382 // is used.
4383
4384 const gfx::Transform identity_matrix;
weiliangcc154ce22015-12-09 03:39:264385 LayerImpl* parent = root_layer();
4386 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4387 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4388 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4389 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4390 LayerImpl* front_facing_child_of_front_facing_surface =
4391 AddChild<LayerImpl>(front_facing_surface);
4392 LayerImpl* back_facing_child_of_front_facing_surface =
4393 AddChild<LayerImpl>(front_facing_surface);
4394 LayerImpl* front_facing_child_of_back_facing_surface =
4395 AddChild<LayerImpl>(back_facing_surface);
4396 LayerImpl* back_facing_child_of_back_facing_surface =
4397 AddChild<LayerImpl>(back_facing_surface);
4398 // Opacity will not force creation of render surfaces in this case because of
4399 // the preserve-3d transform style. Instead, an example of when a surface
4400 // would be created with preserve-3d is when there is a replica layer.
4401 LayerImpl* dummy_replica_layer1 =
4402 AddReplicaLayer<LayerImpl>(front_facing_surface);
4403 LayerImpl* dummy_replica_layer2 =
4404 AddReplicaLayer<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284405
[email protected]fb661802013-03-25 01:59:324406 // Nothing is double-sided
jaydasika6b5a32bf2016-04-22 21:56:364407 front_facing_child->test_properties()->double_sided = false;
4408 back_facing_child->test_properties()->double_sided = false;
4409 front_facing_surface->test_properties()->double_sided = false;
4410 back_facing_surface->test_properties()->double_sided = false;
4411 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4412 false;
4413 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4414 false;
4415 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4416 false;
4417 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4418 false;
[email protected]fb661802013-03-25 01:59:324419
weiliangcc154ce22015-12-09 03:39:264420 // Everything draws content.
4421 front_facing_child->SetDrawsContent(true);
4422 back_facing_child->SetDrawsContent(true);
4423 front_facing_surface->SetDrawsContent(true);
4424 back_facing_surface->SetDrawsContent(true);
4425 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4426 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4427 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4428 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
4429 dummy_replica_layer1->SetDrawsContent(true);
4430 dummy_replica_layer2->SetDrawsContent(true);
4431
[email protected]fb661802013-03-25 01:59:324432 gfx::Transform backface_matrix;
4433 backface_matrix.Translate(50.0, 50.0);
4434 backface_matrix.RotateAboutYAxis(180.0);
4435 backface_matrix.Translate(-50.0, -50.0);
4436
[email protected]fb661802013-03-25 01:59:324437 // Each surface creates its own new 3d rendering context (as defined by W3C
4438 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
4439 // rendering context should use the transform with respect to that context.
4440 // This 3d rendering context occurs when (a) parent's transform style is flat
4441 // and (b) the layer's transform style is preserve-3d.
weiliangcc154ce22015-12-09 03:39:264442 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
weiliangc4374c2cc2015-12-07 19:26:014443 gfx::PointF(), gfx::Size(100, 100), true,
[email protected]fb661802013-03-25 01:59:324444 false); // parent transform style is flat.
weiliangcc154ce22015-12-09 03:39:264445 SetLayerPropertiesForTesting(front_facing_child, identity_matrix,
weiliangc4374c2cc2015-12-07 19:26:014446 gfx::Point3F(), gfx::PointF(),
4447 gfx::Size(100, 100), true, false);
weiliangcc154ce22015-12-09 03:39:264448 SetLayerPropertiesForTesting(back_facing_child, backface_matrix,
weiliangc4374c2cc2015-12-07 19:26:014449 gfx::Point3F(), gfx::PointF(),
4450 gfx::Size(100, 100), true, false);
[email protected]56fffdd2014-02-11 19:50:574451 // surface transform style is preserve-3d.
weiliangcc154ce22015-12-09 03:39:264452 SetLayerPropertiesForTesting(front_facing_surface, identity_matrix,
weiliangc4374c2cc2015-12-07 19:26:014453 gfx::Point3F(), gfx::PointF(),
4454 gfx::Size(100, 100), false, true);
[email protected]56fffdd2014-02-11 19:50:574455 // surface transform style is preserve-3d.
weiliangcc154ce22015-12-09 03:39:264456 SetLayerPropertiesForTesting(back_facing_surface, backface_matrix,
weiliangc4374c2cc2015-12-07 19:26:014457 gfx::Point3F(), gfx::PointF(),
4458 gfx::Size(100, 100), false, true);
weiliangcc154ce22015-12-09 03:39:264459 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014460 identity_matrix, gfx::Point3F(), gfx::PointF(),
4461 gfx::Size(100, 100), true, true);
weiliangcc154ce22015-12-09 03:39:264462 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014463 backface_matrix, gfx::Point3F(), gfx::PointF(),
4464 gfx::Size(100, 100), true, true);
weiliangcc154ce22015-12-09 03:39:264465 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014466 identity_matrix, gfx::Point3F(), gfx::PointF(),
4467 gfx::Size(100, 100), true, true);
weiliangcc154ce22015-12-09 03:39:264468 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014469 backface_matrix, gfx::Point3F(), gfx::PointF(),
4470 gfx::Size(100, 100), true, true);
[email protected]fb661802013-03-25 01:59:324471
weiliangcc154ce22015-12-09 03:39:264472 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:324473
awoloszyne83f28c2014-12-22 15:40:004474 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094475 EXPECT_FALSE(front_facing_child->has_render_surface());
4476 EXPECT_FALSE(back_facing_child->has_render_surface());
4477 EXPECT_TRUE(front_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094478 // We expect that a has_render_surface was created but not used.
4479 EXPECT_TRUE(back_facing_surface->has_render_surface());
4480 EXPECT_FALSE(
4481 front_facing_child_of_front_facing_surface->has_render_surface());
4482 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4483 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4484 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324485
weiliangcc154ce22015-12-09 03:39:264486 EXPECT_EQ(3u, update_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:324487
weiliangcc154ce22015-12-09 03:39:264488 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4489 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4490 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534491 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324492}
4493
[email protected]989386c2013-07-18 21:37:234494TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:324495 // Verify that layers are appropriately culled when their back face is showing
4496 // and they are not double sided, while animations are going on.
4497 //
ajuma4711f4b12016-05-16 18:48:324498 // Even layers that are animating get culled if their back face is showing and
4499 // they are not double sided.
[email protected]fb661802013-03-25 01:59:324500 const gfx::Transform identity_matrix;
ajuma4711f4b12016-05-16 18:48:324501 LayerImpl* parent = root_layer();
4502 LayerImpl* child = AddChildToRoot<LayerImpl>();
4503 LayerImpl* animating_surface = AddChildToRoot<LayerImpl>();
4504 LayerImpl* child_of_animating_surface =
4505 AddChild<LayerImpl>(animating_surface);
4506 LayerImpl* animating_child = AddChildToRoot<LayerImpl>();
4507 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
[email protected]d600df7d2013-08-03 02:34:284508
[email protected]fb661802013-03-25 01:59:324509 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324510 child->test_properties()->double_sided = false;
4511 child2->test_properties()->double_sided = false;
4512 animating_surface->test_properties()->double_sided = false;
4513 child_of_animating_surface->test_properties()->double_sided = false;
4514 animating_child->test_properties()->double_sided = false;
4515
4516 // Everything draws content.
4517 child->SetDrawsContent(true);
4518 child2->SetDrawsContent(true);
4519 animating_surface->SetDrawsContent(true);
4520 child_of_animating_surface->SetDrawsContent(true);
4521 animating_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324522
4523 gfx::Transform backface_matrix;
4524 backface_matrix.Translate(50.0, 50.0);
4525 backface_matrix.RotateAboutYAxis(180.0);
4526 backface_matrix.Translate(-50.0, -50.0);
4527
loyso9556c732016-03-11 07:54:584528 // Animate the transform on the render surface.
ajuma4711f4b12016-05-16 18:48:324529 AddAnimatedTransformToLayerWithPlayer(animating_surface->id(),
4530 timeline_impl(), 10.0, 30, 0);
loyso9556c732016-03-11 07:54:584531 // This is just an animating layer, not a surface.
ajuma4711f4b12016-05-16 18:48:324532 AddAnimatedTransformToLayerWithPlayer(animating_child->id(), timeline_impl(),
4533 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:324534
ajuma4711f4b12016-05-16 18:48:324535 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4536 gfx::PointF(), gfx::Size(100, 100), true, false);
4537 SetLayerPropertiesForTesting(child, backface_matrix, gfx::Point3F(),
4538 gfx::PointF(), gfx::Size(100, 100), true, false);
4539 SetLayerPropertiesForTesting(animating_surface, backface_matrix,
4540 gfx::Point3F(), gfx::PointF(),
4541 gfx::Size(100, 100), true, false, true);
4542 SetLayerPropertiesForTesting(child_of_animating_surface, backface_matrix,
4543 gfx::Point3F(), gfx::PointF(),
4544 gfx::Size(100, 100), true, false);
4545 SetLayerPropertiesForTesting(animating_child, backface_matrix, gfx::Point3F(),
4546 gfx::PointF(), gfx::Size(100, 100), true, false);
4547 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4548 gfx::PointF(), gfx::Size(100, 100), true, false);
[email protected]fb661802013-03-25 01:59:324549
ajuma4711f4b12016-05-16 18:48:324550 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:324551
ennec1332992015-08-24 19:45:094552 EXPECT_FALSE(child->has_render_surface());
4553 EXPECT_TRUE(animating_surface->has_render_surface());
4554 EXPECT_FALSE(child_of_animating_surface->has_render_surface());
4555 EXPECT_FALSE(animating_child->has_render_surface());
4556 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324557
ajuma4711f4b12016-05-16 18:48:324558 EXPECT_EQ(1u, update_layer_list_impl()->size());
enne7b2a2172015-07-14 00:04:534559
ajuma4711f4b12016-05-16 18:48:324560 // The back facing layers are culled from the layer list, and have an empty
4561 // visible rect.
4562 EXPECT_TRUE(UpdateLayerListImplContains(child2->id()));
4563 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
4564 EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty());
4565 EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty());
4566 EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:324567
ajuma4711f4b12016-05-16 18:48:324568 EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324569}
4570
[email protected]989386c2013-07-18 21:37:234571TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324572 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4573 // Verify the behavior of back-face culling for a render surface that is
4574 // created when it flattens its subtree, and its parent has preserves-3d.
4575
4576 const gfx::Transform identity_matrix;
ajuma4711f4b12016-05-16 18:48:324577 LayerImpl* parent = root_layer();
4578 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4579 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4580 LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface);
4581 LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284582
[email protected]fb661802013-03-25 01:59:324583 // RenderSurfaces are not double-sided
ajuma4711f4b12016-05-16 18:48:324584 front_facing_surface->test_properties()->double_sided = false;
4585 back_facing_surface->test_properties()->double_sided = false;
4586
4587 // Everything draws content.
4588 front_facing_surface->SetDrawsContent(true);
4589 back_facing_surface->SetDrawsContent(true);
4590 child1->SetDrawsContent(true);
4591 child2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324592
4593 gfx::Transform backface_matrix;
4594 backface_matrix.Translate(50.0, 50.0);
4595 backface_matrix.RotateAboutYAxis(180.0);
4596 backface_matrix.Translate(-50.0, -50.0);
4597
ajuma4711f4b12016-05-16 18:48:324598 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4599 gfx::PointF(), gfx::Size(100, 100), false,
[email protected]56fffdd2014-02-11 19:50:574600 true); // parent transform style is preserve3d.
ajuma4711f4b12016-05-16 18:48:324601 SetLayerPropertiesForTesting(front_facing_surface, identity_matrix,
4602 gfx::Point3F(), gfx::PointF(),
4603 gfx::Size(100, 100), true,
[email protected]56fffdd2014-02-11 19:50:574604 true); // surface transform style is flat.
ajuma4711f4b12016-05-16 18:48:324605 SetLayerPropertiesForTesting(back_facing_surface, backface_matrix,
4606 gfx::Point3F(), gfx::PointF(),
4607 gfx::Size(100, 100), true,
[email protected]56fffdd2014-02-11 19:50:574608 true); // surface transform style is flat.
ajuma4711f4b12016-05-16 18:48:324609 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
4610 gfx::PointF(), gfx::Size(100, 100), true, false);
4611 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4612 gfx::PointF(), gfx::Size(100, 100), true, false);
[email protected]fb661802013-03-25 01:59:324613
[email protected]a9d4d4f2014-06-19 06:49:284614 front_facing_surface->Set3dSortingContextId(1);
4615 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574616
ajuma4711f4b12016-05-16 18:48:324617 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:324618
awoloszyne83f28c2014-12-22 15:40:004619 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094620 EXPECT_TRUE(front_facing_surface->has_render_surface());
awoloszyne83f28c2014-12-22 15:40:004621
4622 // We expect the render surface to have been created, but remain unused.
ennec1332992015-08-24 19:45:094623 EXPECT_TRUE(back_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094624 EXPECT_FALSE(child1->has_render_surface());
4625 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324626
ajuma4711f4b12016-05-16 18:48:324627 EXPECT_EQ(2u, update_layer_list_impl()->size());
4628 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4629 EXPECT_TRUE(UpdateLayerListImplContains(child1->id()));
[email protected]fb661802013-03-25 01:59:324630}
4631
enne637715732015-07-07 02:05:264632TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324633 // Verify draw and screen space transforms of layers not in a surface.
[email protected]fb661802013-03-25 01:59:324634 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:144635
enne637715732015-07-07 02:05:264636 LayerImpl* parent = root_layer();
jaydasika8640f9f2015-11-10 01:34:364637 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264638 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4639 gfx::PointF(), gfx::Size(100, 100), false, true,
[email protected]fb661802013-03-25 01:59:324640 true);
[email protected]94f206c12012-08-25 00:09:144641
enne637715732015-07-07 02:05:264642 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364643 child->SetDrawsContent(true);
enne637715732015-07-07 02:05:264644 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4645 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4646 true, false);
[email protected]94f206c12012-08-25 00:09:144647
jaydasika8640f9f2015-11-10 01:34:364648 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
4649 child2->SetDrawsContent(true);
4650 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4651 gfx::PointF(2.f, 2.f), gfx::Size(5, 5), false,
4652 true, false);
[email protected]d600df7d2013-08-03 02:34:284653
[email protected]fb661802013-03-25 01:59:324654 float device_scale_factor = 2.5f;
enne637715732015-07-07 02:05:264655 gfx::Size viewport_size(100, 100);
4656 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144657
enne637715732015-07-07 02:05:264658 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent);
4659 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child);
jaydasika8640f9f2015-11-10 01:34:364660 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child2);
[email protected]518ee582012-10-24 18:29:444661
enne637715732015-07-07 02:05:264662 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144663
[email protected]fb661802013-03-25 01:59:324664 // Verify parent transforms
4665 gfx::Transform expected_parent_transform;
enne637715732015-07-07 02:05:264666 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324667 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104668 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324669 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444670 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144671
[email protected]fb661802013-03-25 01:59:324672 // Verify results of transformed parent rects
danakjddaec912015-09-25 19:38:404673 gfx::RectF parent_bounds(gfx::SizeF(parent->bounds()));
[email protected]94f206c12012-08-25 00:09:144674
[email protected]fb661802013-03-25 01:59:324675 gfx::RectF parent_draw_rect =
ajumad9432e32015-11-30 19:43:444676 MathUtil::MapClippedRect(parent->DrawTransform(), parent_bounds);
Dana Jansensc46d3742015-06-18 01:33:144677 gfx::RectF parent_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104678 MathUtil::MapClippedRect(parent->ScreenSpaceTransform(), parent_bounds);
[email protected]94f206c12012-08-25 00:09:144679
danakjddaec912015-09-25 19:38:404680 gfx::RectF expected_parent_draw_rect(gfx::SizeF(parent->bounds()));
[email protected]fb661802013-03-25 01:59:324681 expected_parent_draw_rect.Scale(device_scale_factor);
4682 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4683 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144684
jaydasika8640f9f2015-11-10 01:34:364685 // Verify child and child2 transforms. They should match.
[email protected]fb661802013-03-25 01:59:324686 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594687 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4688 expected_child_transform.Translate(child->position().x(),
4689 child->position().y());
[email protected]fb661802013-03-25 01:59:324690 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444691 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:324692 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104693 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324694 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444695 child2->DrawTransform());
[email protected]fb661802013-03-25 01:59:324696 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104697 child2->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144698
jaydasika8640f9f2015-11-10 01:34:364699 // Verify results of transformed child and child2 rects. They should
[email protected]fb661802013-03-25 01:59:324700 // match.
danakjddaec912015-09-25 19:38:404701 gfx::RectF child_bounds(gfx::SizeF(child->bounds()));
[email protected]94f206c12012-08-25 00:09:144702
[email protected]fb661802013-03-25 01:59:324703 gfx::RectF child_draw_rect =
ajumad9432e32015-11-30 19:43:444704 MathUtil::MapClippedRect(child->DrawTransform(), child_bounds);
Dana Jansensc46d3742015-06-18 01:33:144705 gfx::RectF child_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104706 MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds);
[email protected]94f206c12012-08-25 00:09:144707
jaydasika8640f9f2015-11-10 01:34:364708 gfx::RectF child2_draw_rect =
ajumad9432e32015-11-30 19:43:444709 MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds);
jaydasika8640f9f2015-11-10 01:34:364710 gfx::RectF child2_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104711 MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds);
[email protected]f89f5632012-11-14 23:34:454712
danakjddaec912015-09-25 19:38:404713 gfx::RectF expected_child_draw_rect(child->position(),
4714 gfx::SizeF(child->bounds()));
[email protected]fb661802013-03-25 01:59:324715 expected_child_draw_rect.Scale(device_scale_factor);
4716 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4717 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
jaydasika8640f9f2015-11-10 01:34:364718 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect);
4719 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144720}
4721
enne637715732015-07-07 02:05:264722TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324723 // Verify draw and screen space transforms of layers in a surface.
[email protected]fb661802013-03-25 01:59:324724 gfx::Transform identity_matrix;
[email protected]fb661802013-03-25 01:59:324725 gfx::Transform perspective_matrix;
4726 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094727
[email protected]fb661802013-03-25 01:59:324728 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054729 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094730
enne637715732015-07-07 02:05:264731 LayerImpl* root = root_layer();
4732 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4733 gfx::PointF(), gfx::Size(100, 100), false, true,
4734 false);
sunxdc5d4fb42016-05-27 04:40:094735
4736 LayerImpl* page_scale = AddChildToRoot<LayerImpl>();
4737 SetLayerPropertiesForTesting(page_scale, identity_matrix, gfx::Point3F(),
4738 gfx::PointF(), gfx::Size(100, 100), false, true,
4739 false);
4740
4741 LayerImpl* parent = AddChild<LayerImpl>(page_scale);
jaydasika8640f9f2015-11-10 01:34:364742 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264743 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4744 gfx::PointF(), gfx::Size(100, 100), false, true,
4745 false);
[email protected]9781afa2013-07-17 23:15:324746
enne637715732015-07-07 02:05:264747 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
4748 SetLayerPropertiesForTesting(perspective_surface,
[email protected]fb661802013-03-25 01:59:324749 perspective_matrix * scale_small_matrix,
enne637715732015-07-07 02:05:264750 gfx::Point3F(), gfx::PointF(2.f, 2.f),
4751 gfx::Size(10, 10), false, true, true);
4752 perspective_surface->SetDrawsContent(true);
[email protected]1b30e8e2012-12-21 02:59:094753
enne637715732015-07-07 02:05:264754 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
4755 SetLayerPropertiesForTesting(scale_surface, scale_small_matrix,
4756 gfx::Point3F(), gfx::PointF(2.f, 2.f),
4757 gfx::Size(10, 10), false, true, true);
4758 scale_surface->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284759
[email protected]fb661802013-03-25 01:59:324760 float device_scale_factor = 2.5f;
4761 float page_scale_factor = 3.f;
sunxdc5d4fb42016-05-27 04:40:094762 root->layer_tree_impl()->SetViewportLayersFromIds(
4763 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID,
4764 Layer::INVALID_ID);
4765 root->layer_tree_impl()->SetDeviceScaleFactor(device_scale_factor);
jaydasika4340ea02016-06-06 19:44:264766 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
sunxdc5d4fb42016-05-27 04:40:094767 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor);
enne637715732015-07-07 02:05:264768 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4769 root);
[email protected]1b30e8e2012-12-21 02:59:094770
sohan.jyotie3bd6192014-10-13 07:13:594771 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4772 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
4773 perspective_surface);
4774 // Ideal scale is the max 2d scale component of the combined transform up to
4775 // the nearest render target. Here this includes the layer transform as well
4776 // as the device and page scale factors.
4777 gfx::Transform transform = scale_small_matrix;
4778 transform.Scale(device_scale_factor * page_scale_factor,
4779 device_scale_factor * page_scale_factor);
4780 gfx::Vector2dF scales =
4781 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4782 float max_2d_scale = std::max(scales.x(), scales.y());
4783 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
4784
4785 // The ideal scale will draw 1:1 with its render target space along
4786 // the larger-scale axis.
4787 gfx::Vector2dF target_space_transform_scales =
4788 MathUtil::ComputeTransform2dScaleComponents(
4789 scale_surface->draw_properties().target_space_transform, 0.f);
4790 EXPECT_FLOAT_EQ(max_2d_scale,
4791 std::max(target_space_transform_scales.x(),
4792 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094793
enne637715732015-07-07 02:05:264794 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]1b30e8e2012-12-21 02:59:094795
[email protected]fb661802013-03-25 01:59:324796 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594797 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4798 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324799 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
ajumad9432e32015-11-30 19:43:444800 parent->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094801
[email protected]fb661802013-03-25 01:59:324802 // The scale for the perspective surface is not known, so it is rendered 1:1
4803 // with the screen, and then scaled during drawing.
4804 gfx::Transform expected_perspective_surface_draw_transform;
4805 expected_perspective_surface_draw_transform.Translate(
4806 device_scale_factor * page_scale_factor *
4807 perspective_surface->position().x(),
4808 device_scale_factor * page_scale_factor *
4809 perspective_surface->position().y());
4810 expected_perspective_surface_draw_transform.PreconcatTransform(
4811 perspective_matrix);
4812 expected_perspective_surface_draw_transform.PreconcatTransform(
4813 scale_small_matrix);
4814 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594815 expected_perspective_surface_layer_draw_transform.Scale(
4816 device_scale_factor * page_scale_factor,
4817 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324818 EXPECT_TRANSFORMATION_MATRIX_EQ(
4819 expected_perspective_surface_draw_transform,
4820 perspective_surface->render_surface()->draw_transform());
4821 EXPECT_TRANSFORMATION_MATRIX_EQ(
4822 expected_perspective_surface_layer_draw_transform,
ajumad9432e32015-11-30 19:43:444823 perspective_surface->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094824}
4825
enne637715732015-07-07 02:05:264826TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294827 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264828 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294829 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4830
4831 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264832 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294833 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4834
enne637715732015-07-07 02:05:264835 LayerImpl* root = root_layer();
[email protected]35a99a12013-05-09 23:52:294836 root->SetBounds(gfx::Size(100, 100));
4837
enne637715732015-07-07 02:05:264838 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364839 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264840 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4841 gfx::PointF(), gfx::Size(100, 100), false, true,
4842 false);
[email protected]35a99a12013-05-09 23:52:294843
enne637715732015-07-07 02:05:264844 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:364845 child_scale->SetDrawsContent(true);
enne637715732015-07-07 02:05:264846 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4847 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4848 true, false);
[email protected]d600df7d2013-08-03 02:34:284849
[email protected]fb661802013-03-25 01:59:324850 float device_scale_factor = 2.5f;
4851 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214852
[email protected]989386c2013-07-18 21:37:234853 {
enne637715732015-07-07 02:05:264854 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4855 root);
[email protected]11ec92972012-11-10 03:06:214856
sohan.jyotie3bd6192014-10-13 07:13:594857 // The ideal scale is able to go below 1.
4858 float expected_ideal_scale =
4859 device_scale_factor * page_scale_factor * initial_parent_scale;
4860 EXPECT_LT(expected_ideal_scale, 1.f);
4861 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
[email protected]11ec92972012-11-10 03:06:214862
sohan.jyotie3bd6192014-10-13 07:13:594863 expected_ideal_scale = device_scale_factor * page_scale_factor *
4864 initial_parent_scale * initial_child_scale;
4865 EXPECT_LT(expected_ideal_scale, 1.f);
4866 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
[email protected]989386c2013-07-18 21:37:234867 }
[email protected]11ec92972012-11-10 03:06:214868}
4869
enne637715732015-07-07 02:05:264870TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:324871 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264872 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324873 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:264874
[email protected]fb661802013-03-25 01:59:324875 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264876 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324877 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:264878
enne637715732015-07-07 02:05:264879 LayerImpl* root = root_layer();
[email protected]35a99a12013-05-09 23:52:294880 root->SetBounds(gfx::Size(100, 100));
4881
enne637715732015-07-07 02:05:264882 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364883 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264884 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4885 gfx::PointF(), gfx::Size(100, 100), false, true,
4886 false);
[email protected]6a9cff92012-11-08 11:53:264887
enne637715732015-07-07 02:05:264888 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:364889 child_scale->SetDrawsContent(true);
enne637715732015-07-07 02:05:264890 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4891 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4892 true, false);
[email protected]d600df7d2013-08-03 02:34:284893
[email protected]989386c2013-07-18 21:37:234894 {
enne637715732015-07-07 02:05:264895 ExecuteCalculateDrawProperties(root);
[email protected]6a9cff92012-11-08 11:53:264896
sohan.jyotie3bd6192014-10-13 07:13:594897 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
4898 // Animating layers compute ideal scale in the same way as when
4899 // they are static.
4900 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
4901 child_scale);
[email protected]989386c2013-07-18 21:37:234902 }
[email protected]6a9cff92012-11-08 11:53:264903}
4904
[email protected]989386c2013-07-18 21:37:234905TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324906 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:264907
enneea850232015-07-27 16:43:124908 LayerImpl* parent = root_layer();
4909 parent->SetDrawsContent(true);
4910 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4911 gfx::PointF(), gfx::Size(30, 30), false, true,
[email protected]fb661802013-03-25 01:59:324912 true);
[email protected]94f206c12012-08-25 00:09:144913
enneea850232015-07-27 16:43:124914 LayerImpl* child = AddChildToRoot<LayerImpl>();
4915 child->SetDrawsContent(true);
4916 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4917 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4918 true, true);
[email protected]94f206c12012-08-25 00:09:144919
[email protected]fb661802013-03-25 01:59:324920 gfx::Transform replica_transform;
4921 replica_transform.Scale(1.0, -1.0);
enneea850232015-07-27 16:43:124922
danakj60bc3bc2016-04-09 00:24:484923 std::unique_ptr<LayerImpl> replica =
enneea850232015-07-27 16:43:124924 LayerImpl::Create(host_impl()->active_tree(), 7);
4925 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
4926 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4927 true, false);
jaydasika5017a332016-03-31 01:06:224928 // We need to set parent on replica layer for property tree building.
4929 replica->SetParent(child);
danakja04855a2015-11-18 20:39:104930 child->SetReplicaLayer(std::move(replica));
[email protected]94f206c12012-08-25 00:09:144931
[email protected]fb661802013-03-25 01:59:324932 // This layer should end up in the same surface as child, with the same draw
4933 // and screen space transforms.
enneea850232015-07-27 16:43:124934 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
4935 duplicate_child_non_owner->SetDrawsContent(true);
4936 SetLayerPropertiesForTesting(duplicate_child_non_owner, identity_matrix,
4937 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4938 false, true, false);
[email protected]94f206c12012-08-25 00:09:144939
[email protected]fb661802013-03-25 01:59:324940 float device_scale_factor = 1.5f;
enneea850232015-07-27 16:43:124941 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144942
[email protected]fb661802013-03-25 01:59:324943 // We should have two render surfaces. The root's render surface and child's
4944 // render surface (it needs one because it has a replica layer).
enneea850232015-07-27 16:43:124945 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144946
[email protected]fb661802013-03-25 01:59:324947 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594948 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324949 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104950 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324951 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444952 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144953
[email protected]fb661802013-03-25 01:59:324954 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594955 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324956 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
ajumad9432e32015-11-30 19:43:444957 child->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144958
[email protected]fb661802013-03-25 01:59:324959 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:594960 expected_screen_space_transform.Scale(device_scale_factor,
4961 device_scale_factor);
4962 expected_screen_space_transform.Translate(child->position().x(),
4963 child->position().y());
[email protected]fb661802013-03-25 01:59:324964 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:104965 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144966
[email protected]fb661802013-03-25 01:59:324967 gfx::Transform expected_duplicate_child_draw_transform =
ajumad9432e32015-11-30 19:43:444968 child->DrawTransform();
4969 EXPECT_TRANSFORMATION_MATRIX_EQ(child->DrawTransform(),
4970 duplicate_child_non_owner->DrawTransform());
[email protected]fb661802013-03-25 01:59:324971 EXPECT_TRANSFORMATION_MATRIX_EQ(
ajumab6aa1c62015-12-01 21:01:104972 child->ScreenSpaceTransform(),
4973 duplicate_child_non_owner->ScreenSpaceTransform());
hush6b614212014-12-04 22:37:324974 EXPECT_EQ(child->drawable_content_rect(),
4975 duplicate_child_non_owner->drawable_content_rect());
Dana Jansensc46d3742015-06-18 01:33:144976 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
[email protected]94f206c12012-08-25 00:09:144977
[email protected]fb661802013-03-25 01:59:324978 gfx::Transform expected_render_surface_draw_transform;
4979 expected_render_surface_draw_transform.Translate(
4980 device_scale_factor * child->position().x(),
4981 device_scale_factor * child->position().y());
4982 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
4983 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144984
[email protected]fb661802013-03-25 01:59:324985 gfx::Transform expected_surface_draw_transform;
4986 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
4987 device_scale_factor * 2.f);
4988 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
4989 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144990
[email protected]fb661802013-03-25 01:59:324991 gfx::Transform expected_surface_screen_space_transform;
4992 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
4993 device_scale_factor * 2.f);
4994 EXPECT_TRANSFORMATION_MATRIX_EQ(
4995 expected_surface_screen_space_transform,
4996 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144997
[email protected]fb661802013-03-25 01:59:324998 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:264999 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
5000 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
5001 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325002 EXPECT_TRANSFORMATION_MATRIX_EQ(
5003 expected_replica_draw_transform,
5004 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:145005
[email protected]fb661802013-03-25 01:59:325006 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265007 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
5008 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
5009 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325010 EXPECT_TRANSFORMATION_MATRIX_EQ(
5011 expected_replica_screen_space_transform,
5012 child->render_surface()->replica_screen_space_transform());
5013 EXPECT_TRANSFORMATION_MATRIX_EQ(
5014 expected_replica_screen_space_transform,
5015 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:475016}
5017
[email protected]989386c2013-07-18 21:37:235018TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325019 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
[email protected]fb661802013-03-25 01:59:325020 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:475021
enneea850232015-07-27 16:43:125022 LayerImpl* parent = root_layer();
5023 parent->SetDrawsContent(true);
5024 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
5025 gfx::PointF(), gfx::Size(33, 31), false, true,
[email protected]fb661802013-03-25 01:59:325026 true);
[email protected]904e9132012-11-01 00:12:475027
enneea850232015-07-27 16:43:125028 LayerImpl* child = AddChildToRoot<LayerImpl>();
5029 child->SetDrawsContent(true);
5030 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
5031 gfx::PointF(), gfx::Size(13, 11), false, true,
[email protected]fb661802013-03-25 01:59:325032 true);
[email protected]904e9132012-11-01 00:12:475033
[email protected]fb661802013-03-25 01:59:325034 gfx::Transform replica_transform;
5035 replica_transform.Scale(1.0, -1.0);
danakj60bc3bc2016-04-09 00:24:485036 std::unique_ptr<LayerImpl> replica =
enneea850232015-07-27 16:43:125037 LayerImpl::Create(host_impl()->active_tree(), 7);
5038 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
5039 gfx::PointF(), gfx::Size(13, 11), false, true,
5040 false);
danakja04855a2015-11-18 20:39:105041 child->SetReplicaLayer(std::move(replica));
[email protected]d600df7d2013-08-03 02:34:285042
[email protected]873639e2013-07-24 19:56:315043 float device_scale_factor = 1.7f;
enneea850232015-07-27 16:43:125044 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]904e9132012-11-01 00:12:475045
[email protected]fb661802013-03-25 01:59:325046 // We should have two render surfaces. The root's render surface and child's
5047 // render surface (it needs one because it has a replica layer).
enneea850232015-07-27 16:43:125048 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]904e9132012-11-01 00:12:475049
[email protected]fb661802013-03-25 01:59:325050 gfx::Transform identity_transform;
[email protected]fb661802013-03-25 01:59:325051 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5052 child->render_surface()->draw_transform());
5053 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5054 child->render_surface()->draw_transform());
5055 EXPECT_TRANSFORMATION_MATRIX_EQ(
5056 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:475057
[email protected]fb661802013-03-25 01:59:325058 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265059 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325060 EXPECT_TRANSFORMATION_MATRIX_EQ(
5061 expected_replica_draw_transform,
5062 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:475063
[email protected]fb661802013-03-25 01:59:325064 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265065 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325066 EXPECT_TRANSFORMATION_MATRIX_EQ(
5067 expected_replica_screen_space_transform,
5068 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145069}
5070
jaydasikadb41a582016-03-28 20:48:215071TEST_F(LayerTreeHostCommonTest, LayerSearch) {
loyso0940d412016-03-14 01:30:315072 scoped_refptr<Layer> root = Layer::Create();
5073 scoped_refptr<Layer> child = Layer::Create();
5074 scoped_refptr<Layer> grand_child = Layer::Create();
5075 scoped_refptr<Layer> mask_layer = Layer::Create();
5076 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:145077
[email protected]fb661802013-03-25 01:59:325078 grand_child->SetReplicaLayer(replica_layer.get());
5079 child->AddChild(grand_child.get());
5080 child->SetMaskLayer(mask_layer.get());
5081 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:145082
ennea7b43c32015-06-18 20:01:335083 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:285084
[email protected]fb661802013-03-25 01:59:325085 int nonexistent_id = -1;
jaydasikadb41a582016-03-28 20:48:215086 EXPECT_EQ(root.get(), host()->LayerById(root->id()));
5087 EXPECT_EQ(child.get(), host()->LayerById(child->id()));
5088 EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id()));
5089 EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id()));
5090 EXPECT_EQ(replica_layer.get(), host()->LayerById(replica_layer->id()));
5091 EXPECT_FALSE(host()->LayerById(nonexistent_id));
[email protected]94f206c12012-08-25 00:09:145092}
5093
[email protected]989386c2013-07-18 21:37:235094TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
ajuma4711f4b12016-05-16 18:48:325095 LayerImpl* root = root_layer();
5096 LayerImpl* child = AddChild<LayerImpl>(root);
5097 LayerImpl* grand_child = AddChild<LayerImpl>(child);
5098 grand_child->SetDrawsContent(true);
[email protected]498ec6e0e2012-11-30 18:24:575099
[email protected]fb661802013-03-25 01:59:325100 const gfx::Transform identity_matrix;
ajuma4711f4b12016-05-16 18:48:325101 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
5102 gfx::PointF(), gfx::Size(100, 100), true, false);
5103 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
5104 gfx::PointF(), gfx::Size(10, 10), true, false);
5105 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
5106 gfx::PointF(), gfx::Size(10, 10), true, false);
[email protected]498ec6e0e2012-11-30 18:24:575107
jaydasikaab317e02016-06-01 00:53:185108 child->test_properties()->opacity = 0.5f;
[email protected]498ec6e0e2012-11-30 18:24:575109
ajuma4711f4b12016-05-16 18:48:325110 ExecuteCalculateDrawProperties(root);
[email protected]498ec6e0e2012-11-30 18:24:575111
ennec1332992015-08-24 19:45:095112 EXPECT_FALSE(child->has_render_surface());
[email protected]498ec6e0e2012-11-30 18:24:575113}
5114
[email protected]989386c2013-07-18 21:37:235115TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
khushalsagarb64b360d2015-10-21 19:25:165116 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455117 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565118 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:485119 FakeLayerTreeHostImpl host_impl(host()->settings(), &task_runner_provider,
5120 &shared_bitmap_manager, &task_graph_runner);
[email protected]f90fc412013-03-30 20:13:165121 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:485122 std::unique_ptr<LayerImpl> root =
5123 LayerImpl::Create(host_impl.pending_tree(), 1);
[email protected]f90fc412013-03-30 20:13:165124
5125 const gfx::Transform identity_matrix;
awoloszyne83f28c2014-12-22 15:40:005126 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5127 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]f90fc412013-03-30 20:13:165128 false);
5129 root->SetDrawsContent(true);
5130
danakj60bc3bc2016-04-09 00:24:485131 std::unique_ptr<LayerImpl> child =
5132 LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005133 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5134 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]f90fc412013-03-30 20:13:165135 false);
5136 child->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:185137 child->test_properties()->opacity = 0.0f;
[email protected]f90fc412013-03-30 20:13:165138
jaydasika9cb21c772016-05-10 22:37:085139 const int child_id = child->id();
5140 root->AddChild(std::move(child));
5141 root->SetHasRenderSurface(true);
5142 LayerImpl* root_layer = root.get();
5143 host_impl.pending_tree()->SetRootLayer(std::move(root));
jaydasika4340ea02016-06-06 19:44:265144 host_impl.pending_tree()->BuildLayerListAndPropertyTreesForTesting();
[email protected]f90fc412013-03-30 20:13:165145 // Add opacity animation.
loyso9556c732016-03-11 07:54:585146 scoped_refptr<AnimationTimeline> timeline =
5147 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
5148 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:485149
jaydasika9cb21c772016-05-10 22:37:085150 AddOpacityTransitionToLayerWithPlayer(child_id, timeline, 10.0, 0.0f, 1.0f,
loyso9556c732016-03-11 07:54:585151 false);
[email protected]f90fc412013-03-30 20:13:165152
[email protected]c0ae06c12013-06-24 18:32:195153 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535154 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385155 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535156 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575157 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]f90fc412013-03-30 20:13:165158
5159 // We should have one render surface and two layers. The child
5160 // layer should be included even though it is transparent.
5161 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:055162 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
jaydasika86654512016-01-27 17:05:075163
5164 // If the root itself is hidden, the child should not be drawn even if it has
5165 // an animating opacity.
jaydasikaab317e02016-06-01 00:53:185166 root_layer->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:055167 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika86654512016-01-27 17:05:075168 LayerImplList render_surface_layer_list2;
jaydasika86654512016-01-27 17:05:075169 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2(
ajuma0adb5902016-04-28 16:32:385170 root_layer, root_layer->bounds(), &render_surface_layer_list2);
jaydasika86654512016-01-27 17:05:075171 inputs2.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575172 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2);
jaydasika86654512016-01-27 17:05:075173
jaydasika0c2fd472016-03-24 01:26:055174 LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2);
jaydasika8185d302016-04-14 15:20:065175 EffectTree& tree =
jaydasika0c2fd472016-03-24 01:26:055176 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:075177 EffectNode* node = tree.Node(child_ptr->effect_tree_index());
5178 EXPECT_FALSE(node->data.is_drawn);
jaydasikae99e83e2016-01-29 19:35:405179
5180 // A layer should be drawn and it should contribute to drawn surface when
5181 // it has animating opacity even if it has opacity 0.
jaydasikaab317e02016-06-01 00:53:185182 root_layer->test_properties()->opacity = 1.0f;
5183 child_ptr->test_properties()->opacity = 0.0f;
jaydasika0c2fd472016-03-24 01:26:055184 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikae99e83e2016-01-29 19:35:405185 LayerImplList render_surface_layer_list3;
jaydasikae99e83e2016-01-29 19:35:405186 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3(
ajuma0adb5902016-04-28 16:32:385187 root_layer, root_layer->bounds(), &render_surface_layer_list3);
jaydasikae99e83e2016-01-29 19:35:405188 inputs3.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575189 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3);
jaydasikae99e83e2016-01-29 19:35:405190
jaydasika0c2fd472016-03-24 01:26:055191 child_ptr = root_layer->layer_tree_impl()->LayerById(2);
5192 tree = root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasikae99e83e2016-01-29 19:35:405193 node = tree.Node(child_ptr->effect_tree_index());
5194 EXPECT_TRUE(node->data.is_drawn);
5195 EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index()));
jaydasika8185d302016-04-14 15:20:065196
5197 // But if the opacity of the layer remains 0 after activation, it should not
5198 // be drawn.
5199 host_impl.ActivateSyncTree();
5200 LayerImpl* active_root = host_impl.active_tree()->root_layer();
5201 LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id());
5202
5203 EffectTree& active_effect_tree =
5204 host_impl.active_tree()->property_trees()->effect_tree;
5205 EXPECT_TRUE(active_effect_tree.needs_update());
5206
5207 ExecuteCalculateDrawProperties(active_root);
5208
5209 node = active_effect_tree.Node(active_child->effect_tree_index());
5210 EXPECT_FALSE(node->data.is_drawn);
5211 EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface(
5212 active_child->effect_tree_index()));
[email protected]f90fc412013-03-30 20:13:165213}
5214
danakj3f76ace2014-11-18 16:56:005215using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
enne637715732015-07-07 02:05:265216class LCDTextTest : public LayerTreeHostCommonTestBase,
5217 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:365218 public:
5219 LCDTextTest()
sunxd5a7a4032016-06-01 18:49:225220 : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()),
5221 host_impl_(LCDTextTestLayerTreeSettings(),
5222 &task_runner_provider_,
khushalsagarb64b360d2015-10-21 19:25:165223 &shared_bitmap_manager_,
5224 &task_graph_runner_),
enneaf5bda32015-02-19 01:27:365225 root_(nullptr),
5226 child_(nullptr),
5227 grand_child_(nullptr) {}
5228
loyso968163c92016-01-04 23:18:485229 scoped_refptr<AnimationTimeline> timeline() { return timeline_; }
5230
[email protected]fb661802013-03-25 01:59:325231 protected:
sunxd5a7a4032016-06-01 18:49:225232 LayerTreeSettings LCDTextTestLayerTreeSettings() {
5233 LayerTreeSettings settings = LayerTreeSettings();
5234
5235 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
5236 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
5237 settings.can_use_lcd_text = can_use_lcd_text_;
5238 settings.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text_;
5239 return settings;
5240 }
5241
dcheng93a52eb2014-12-23 02:14:235242 void SetUp() override {
loyso9556c732016-03-11 07:54:585243 timeline_ =
5244 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
5245 host_impl_.animation_host()->AddAnimationTimeline(timeline_);
loyso968163c92016-01-04 23:18:485246
danakj60bc3bc2016-04-09 00:24:485247 std::unique_ptr<LayerImpl> root_ptr =
enneaf5bda32015-02-19 01:27:365248 LayerImpl::Create(host_impl_.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:485249 std::unique_ptr<LayerImpl> child_ptr =
enneaf5bda32015-02-19 01:27:365250 LayerImpl::Create(host_impl_.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:485251 std::unique_ptr<LayerImpl> grand_child_ptr =
enneaf5bda32015-02-19 01:27:365252 LayerImpl::Create(host_impl_.active_tree(), 3);
5253
5254 // Stash raw pointers to look at later.
5255 root_ = root_ptr.get();
5256 child_ = child_ptr.get();
5257 grand_child_ = grand_child_ptr.get();
5258
danakja04855a2015-11-18 20:39:105259 child_->AddChild(std::move(grand_child_ptr));
5260 root_->AddChild(std::move(child_ptr));
5261 host_impl_.active_tree()->SetRootLayer(std::move(root_ptr));
[email protected]10aabcc32012-12-13 09:18:595262
fmalita51b5e202014-11-18 20:11:505263 root_->SetContentsOpaque(true);
5264 child_->SetContentsOpaque(true);
5265 grand_child_->SetContentsOpaque(true);
5266
jaydasika3f930c12015-06-30 15:18:255267 root_->SetDrawsContent(true);
5268 child_->SetDrawsContent(true);
5269 grand_child_->SetDrawsContent(true);
5270
[email protected]fb661802013-03-25 01:59:325271 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365272 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
5273 gfx::PointF(), gfx::Size(1, 1), true, false,
5274 true);
5275 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
5276 gfx::PointF(), gfx::Size(1, 1), true, false,
5277 std::tr1::get<2>(GetParam()));
5278 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
5279 gfx::PointF(), gfx::Size(1, 1), true, false,
[email protected]fb661802013-03-25 01:59:325280 false);
[email protected]fb661802013-03-25 01:59:325281 }
[email protected]10aabcc32012-12-13 09:18:595282
[email protected]fb661802013-03-25 01:59:325283 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005284 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:365285
khushalsagarb64b360d2015-10-21 19:25:165286 FakeImplTaskRunnerProvider task_runner_provider_;
enneaf5bda32015-02-19 01:27:365287 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:475288 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:365289 FakeLayerTreeHostImpl host_impl_;
loyso968163c92016-01-04 23:18:485290 scoped_refptr<AnimationTimeline> timeline_;
enneaf5bda32015-02-19 01:27:365291
5292 LayerImpl* root_;
5293 LayerImpl* child_;
5294 LayerImpl* grand_child_;
[email protected]10aabcc32012-12-13 09:18:595295};
5296
[email protected]fb661802013-03-25 01:59:325297TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005298 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5299 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5300
[email protected]fb661802013-03-25 01:59:325301 // Case 1: Identity transform.
5302 gfx::Transform identity_matrix;
sunxd5a7a4032016-06-01 18:49:225303 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
5304 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5305 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5306 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595307
[email protected]fb661802013-03-25 01:59:325308 // Case 2: Integral translation.
5309 gfx::Transform integral_translation;
5310 integral_translation.Translate(1.0, 2.0);
5311 child_->SetTransform(integral_translation);
jaydasika3f930c12015-06-30 15:18:255312 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxd5a7a4032016-06-01 18:49:225313 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
5314 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5315 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5316 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595317
[email protected]fb661802013-03-25 01:59:325318 // Case 3: Non-integral translation.
5319 gfx::Transform non_integral_translation;
5320 non_integral_translation.Translate(1.5, 2.5);
5321 child_->SetTransform(non_integral_translation);
jaydasika3f930c12015-06-30 15:18:255322 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxd5a7a4032016-06-01 18:49:225323 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
5324 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5325 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5326 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595327
[email protected]fb661802013-03-25 01:59:325328 // Case 4: Rotation.
5329 gfx::Transform rotation;
5330 rotation.Rotate(10.0);
5331 child_->SetTransform(rotation);
jaydasika3f930c12015-06-30 15:18:255332 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxd5a7a4032016-06-01 18:49:225333 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
5334 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5335 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5336 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595337
[email protected]fb661802013-03-25 01:59:325338 // Case 5: Scale.
5339 gfx::Transform scale;
5340 scale.Scale(2.0, 2.0);
5341 child_->SetTransform(scale);
jaydasika3f930c12015-06-30 15:18:255342 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxd5a7a4032016-06-01 18:49:225343 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
5344 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5345 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5346 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595347
[email protected]fb661802013-03-25 01:59:325348 // Case 6: Skew.
5349 gfx::Transform skew;
nainar8ca8ee62015-09-03 01:04:105350 skew.Skew(10.0, 0.0);
[email protected]fb661802013-03-25 01:59:325351 child_->SetTransform(skew);
jaydasika3f930c12015-06-30 15:18:255352 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxd5a7a4032016-06-01 18:49:225353 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
5354 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5355 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5356 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595357
[email protected]fb661802013-03-25 01:59:325358 // Case 7: Translucent.
5359 child_->SetTransform(identity_matrix);
jaydasika3f930c12015-06-30 15:18:255360 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:185361 child_->test_properties()->opacity = 0.5f;
sunxd5a7a4032016-06-01 18:49:225362 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
5363 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5364 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5365 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595366
[email protected]fb661802013-03-25 01:59:325367 // Case 8: Sanity check: restore transform and opacity.
5368 child_->SetTransform(identity_matrix);
jaydasika3f930c12015-06-30 15:18:255369 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaab317e02016-06-01 00:53:185370 child_->test_properties()->opacity = 1.f;
sunxd5a7a4032016-06-01 18:49:225371 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
5372 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5373 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5374 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:505375
5376 // Case 9: Non-opaque content.
5377 child_->SetContentsOpaque(false);
sunxd5a7a4032016-06-01 18:49:225378 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
5379 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5380 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5381 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalita51b5e202014-11-18 20:11:505382
5383 // Case 10: Sanity check: restore content opaqueness.
5384 child_->SetContentsOpaque(true);
sunxd5a7a4032016-06-01 18:49:225385 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
5386 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5387 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5388 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595389}
5390
[email protected]fd9a3b6d2013-08-03 00:46:175391TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005392 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
fmalitafcd926a2015-05-13 20:19:335393 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
danakj3f76ace2014-11-18 16:56:005394
[email protected]fb661802013-03-25 01:59:325395 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
sunxd5a7a4032016-06-01 18:49:225396 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
5397 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5398 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5399 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595400
[email protected]fb661802013-03-25 01:59:325401 // Add opacity animation.
jaydasikaab317e02016-06-01 00:53:185402 child_->test_properties()->opacity = 0.9f;
jaydasika3f930c12015-06-30 15:18:255403 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso9556c732016-03-11 07:54:585404 AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f,
5405 0.1f, false);
sunxd5a7a4032016-06-01 18:49:225406 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
fmalitafcd926a2015-05-13 20:19:335407 // Text LCD should be adjusted while animation is active.
sunxd5a7a4032016-06-01 18:49:225408 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5409 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5410 EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText());
fmalitafcd926a2015-05-13 20:19:335411}
5412
5413TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
5414 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5415 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5416
5417 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
sunxd5a7a4032016-06-01 18:49:225418 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
5419 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5420 EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText());
5421 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
fmalitafcd926a2015-05-13 20:19:335422
5423 // Mark contents non-opaque within the first animation frame.
5424 child_->SetContentsOpaque(false);
loyso9556c732016-03-11 07:54:585425 AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f,
5426 0.1f, false);
sunxd5a7a4032016-06-01 18:49:225427 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL);
fmalitafcd926a2015-05-13 20:19:335428 // LCD text should be disabled for non-opaque layers even during animations.
sunxd5a7a4032016-06-01 18:49:225429 EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText());
5430 EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText());
5431 EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText());
[email protected]10aabcc32012-12-13 09:18:595432}
5433
5434INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5435 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005436 testing::Combine(testing::Bool(),
5437 testing::Bool(),
5438 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595439
[email protected]989386c2013-07-18 21:37:235440TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:165441 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455442 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565443 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165444 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565445 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195446 host_impl.CreatePendingTree();
5447 const gfx::Transform identity_matrix;
5448
danakj60bc3bc2016-04-09 00:24:485449 std::unique_ptr<LayerImpl> root =
5450 LayerImpl::Create(host_impl.pending_tree(), 1);
jaydasika0c2fd472016-03-24 01:26:055451 LayerImpl* root_layer = root.get();
awoloszyne83f28c2014-12-22 15:40:005452 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5453 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]c0ae06c12013-06-24 18:32:195454 false);
5455 root->SetDrawsContent(true);
5456
danakj60bc3bc2016-04-09 00:24:485457 std::unique_ptr<LayerImpl> child =
5458 LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005459 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5460 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:195461 false);
5462 child->SetDrawsContent(true);
5463
danakj60bc3bc2016-04-09 00:24:485464 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195465 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:005466 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5467 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5468 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:195469 grand_child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355470 grand_child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195471
danakja04855a2015-11-18 20:39:105472 child->AddChild(std::move(grand_child));
5473 root->AddChild(std::move(child));
awoloszyne83f28c2014-12-22 15:40:005474 root->SetHasRenderSurface(true);
jaydasika0c2fd472016-03-24 01:26:055475 host_impl.pending_tree()->SetRootLayer(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195476
5477 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535478 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385479 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535480 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575481 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195482
5483 // We should have one render surface and two layers. The grand child has
5484 // hidden itself.
5485 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:055486 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5487 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
5488 EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195489}
5490
[email protected]989386c2013-07-18 21:37:235491TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
khushalsagarb64b360d2015-10-21 19:25:165492 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455493 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565494 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165495 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565496 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195497 host_impl.CreatePendingTree();
5498 const gfx::Transform identity_matrix;
5499
danakj60bc3bc2016-04-09 00:24:485500 std::unique_ptr<LayerImpl> root =
5501 LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:005502 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5503 gfx::PointF(), gfx::Size(50, 50), true, false,
5504 true);
[email protected]c0ae06c12013-06-24 18:32:195505 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095506 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195507
danakj60bc3bc2016-04-09 00:24:485508 std::unique_ptr<LayerImpl> child =
5509 LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005510 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5511 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:195512 false);
5513 child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355514 child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195515
danakj60bc3bc2016-04-09 00:24:485516 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195517 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:005518 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5519 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5520 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:195521 grand_child->SetDrawsContent(true);
5522
danakja04855a2015-11-18 20:39:105523 child->AddChild(std::move(grand_child));
5524 root->AddChild(std::move(child));
jaydasika2411692c2016-03-23 01:56:095525 host_impl.pending_tree()->SetRootLayer(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195526
5527 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535528 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385529 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535530 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575531 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195532
5533 // We should have one render surface and one layers. The child has
5534 // hidden itself and the grand child.
5535 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095536 ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size());
5537 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:195538}
5539
danakj60bc3bc2016-04-09 00:24:485540void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
[email protected]30fe19ff2013-07-04 00:54:455541
[email protected]989386c2013-07-18 21:37:235542TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165543 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455544 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565545 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165546 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565547 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455548 host_impl.CreatePendingTree();
5549 const gfx::Transform identity_matrix;
5550
danakj60bc3bc2016-04-09 00:24:485551 std::unique_ptr<LayerImpl> root =
5552 LayerImpl::Create(host_impl.pending_tree(), 1);
weiliangc51fb255d2015-07-24 15:32:305553 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5554 gfx::PointF(), gfx::Size(50, 50), true, false,
5555 true);
5556 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095557 LayerImpl* root_layer = root.get();
[email protected]30fe19ff2013-07-04 00:54:455558
danakj60bc3bc2016-04-09 00:24:485559 std::unique_ptr<LayerImpl> copy_grand_parent =
weiliangc51fb255d2015-07-24 15:32:305560 LayerImpl::Create(host_impl.pending_tree(), 2);
5561 SetLayerPropertiesForTesting(copy_grand_parent.get(), identity_matrix,
5562 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5563 true, false, false);
5564 copy_grand_parent->SetDrawsContent(true);
5565 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455566
danakj60bc3bc2016-04-09 00:24:485567 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305568 LayerImpl::Create(host_impl.pending_tree(), 3);
5569 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
5570 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5571 true, false, true);
5572 copy_parent->SetDrawsContent(true);
5573 LayerImpl* copy_parent_layer = copy_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455574
danakj60bc3bc2016-04-09 00:24:485575 std::unique_ptr<LayerImpl> copy_request =
weiliangc51fb255d2015-07-24 15:32:305576 LayerImpl::Create(host_impl.pending_tree(), 4);
5577 SetLayerPropertiesForTesting(copy_request.get(), identity_matrix,
5578 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5579 true, false, true);
5580 copy_request->SetDrawsContent(true);
5581 LayerImpl* copy_layer = copy_request.get();
[email protected]30fe19ff2013-07-04 00:54:455582
danakj60bc3bc2016-04-09 00:24:485583 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305584 LayerImpl::Create(host_impl.pending_tree(), 5);
5585 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
5586 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5587 true, false, false);
5588 copy_child->SetDrawsContent(true);
5589 LayerImpl* copy_child_layer = copy_child.get();
[email protected]30fe19ff2013-07-04 00:54:455590
danakj60bc3bc2016-04-09 00:24:485591 std::unique_ptr<LayerImpl> copy_grand_child =
thakise53c5272016-01-24 01:20:405592 LayerImpl::Create(host_impl.pending_tree(), 6);
jaydasika86654512016-01-27 17:05:075593 SetLayerPropertiesForTesting(copy_grand_child.get(), identity_matrix,
5594 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5595 true, false, false);
5596 copy_child->SetDrawsContent(true);
5597 LayerImpl* copy_grand_child_layer = copy_grand_child.get();
5598
danakj60bc3bc2016-04-09 00:24:485599 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before =
jaydasika86654512016-01-27 17:05:075600 LayerImpl::Create(host_impl.pending_tree(), 7);
[email protected]ac020122013-07-12 23:45:535601 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
weiliangc51fb255d2015-07-24 15:32:305602 identity_matrix, gfx::Point3F(), gfx::PointF(),
5603 gfx::Size(40, 40), true, false, false);
5604 copy_grand_parent_sibling_before->SetDrawsContent(true);
5605 LayerImpl* copy_grand_parent_sibling_before_layer =
5606 copy_grand_parent_sibling_before.get();
[email protected]ac020122013-07-12 23:45:535607
danakj60bc3bc2016-04-09 00:24:485608 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after =
jaydasika86654512016-01-27 17:05:075609 LayerImpl::Create(host_impl.pending_tree(), 8);
[email protected]ac020122013-07-12 23:45:535610 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
weiliangc51fb255d2015-07-24 15:32:305611 identity_matrix, gfx::Point3F(), gfx::PointF(),
5612 gfx::Size(40, 40), true, false, false);
5613 copy_grand_parent_sibling_after->SetDrawsContent(true);
5614 LayerImpl* copy_grand_parent_sibling_after_layer =
5615 copy_grand_parent_sibling_after.get();
[email protected]ac020122013-07-12 23:45:535616
jaydasika86654512016-01-27 17:05:075617 copy_child->AddChild(std::move(copy_grand_child));
danakja04855a2015-11-18 20:39:105618 copy_request->AddChild(std::move(copy_child));
5619 copy_parent->AddChild(std::move(copy_request));
5620 copy_grand_parent->AddChild(std::move(copy_parent));
5621 root->AddChild(std::move(copy_grand_parent_sibling_before));
5622 root->AddChild(std::move(copy_grand_parent));
5623 root->AddChild(std::move(copy_grand_parent_sibling_after));
jaydasika2411692c2016-03-23 01:56:095624 host_impl.pending_tree()->SetRootLayer(std::move(root));
[email protected]d600df7d2013-08-03 02:34:285625
[email protected]30fe19ff2013-07-04 00:54:455626 // Hide the copy_grand_parent and its subtree. But make a copy request in that
jaydasika86654512016-01-27 17:05:075627 // hidden subtree on copy_layer. Also hide the copy grand child and its
5628 // subtree.
jaydasika5121caa82016-05-05 15:43:355629 copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true;
5630 copy_grand_parent_sibling_before_layer->test_properties()
5631 ->hide_layer_and_subtree = true;
5632 copy_grand_parent_sibling_after_layer->test_properties()
5633 ->hide_layer_and_subtree = true;
5634 copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true;
weiliangc51fb255d2015-07-24 15:32:305635
ajumae6f541b2016-05-31 16:50:505636 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:305637 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:455638
weiliangc51fb255d2015-07-24 15:32:305639 LayerImplList render_surface_layer_list;
5640 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385641 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535642 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575643 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455644
jaydasika2411692c2016-03-23 01:56:095645 EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0);
sunxded58688e2016-01-11 21:01:025646 EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0);
5647 EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0);
5648 EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0);
[email protected]ac020122013-07-12 23:45:535649
jaydasika86654512016-01-27 17:05:075650 // We should have four render surfaces, one for the root, one for the grand
5651 // parent since it has opacity and two drawing descendants, one for the parent
[email protected]30fe19ff2013-07-04 00:54:455652 // since it owns a surface, and one for the copy_layer.
jaydasika86654512016-01-27 17:05:075653 ASSERT_EQ(4u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095654 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
jaydasika86654512016-01-27 17:05:075655 EXPECT_EQ(copy_grand_parent_layer->id(),
5656 render_surface_layer_list.at(1)->id());
5657 EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id());
5658 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id());
[email protected]30fe19ff2013-07-04 00:54:455659
jaydasika86654512016-01-27 17:05:075660 // The root render surface should have 2 contributing layers.
jaydasika2411692c2016-03-23 01:56:095661 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5662 EXPECT_EQ(root_layer->id(),
5663 root_layer->render_surface()->layer_list().at(0)->id());
jaydasika86654512016-01-27 17:05:075664 EXPECT_EQ(copy_grand_parent_layer->id(),
jaydasika2411692c2016-03-23 01:56:095665 root_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:455666
[email protected]7392c7b2014-02-07 08:28:285667 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:455668 // appear in its list, since it needs to be drawn for the copy request.
weiliangc51fb255d2015-07-24 15:32:305669 ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size());
[email protected]30fe19ff2013-07-04 00:54:455670 EXPECT_EQ(copy_layer->id(),
jaydasika8185d302016-04-14 15:20:065671 copy_parent_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455672
5673 // The copy_layer's render surface should have two contributing layers.
5674 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
5675 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:235676 copy_layer->render_surface()->layer_list().at(0)->id());
weiliangc51fb255d2015-07-24 15:32:305677 EXPECT_EQ(copy_child_layer->id(),
[email protected]989386c2013-07-18 21:37:235678 copy_layer->render_surface()->layer_list().at(1)->id());
jaydasika86654512016-01-27 17:05:075679
5680 // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden,
5681 // but the copy_layer and copy_child should be drawn for the copy request.
5682 // copy grand child should not be drawn as its hidden even in the copy
5683 // request.
ajumae4af47062016-05-24 23:59:045684 EffectTree& tree =
jaydasika2411692c2016-03-23 01:56:095685 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:075686 EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index());
5687 EXPECT_FALSE(node->data.is_drawn);
5688 node = tree.Node(copy_parent_layer->effect_tree_index());
5689 EXPECT_FALSE(node->data.is_drawn);
5690 node = tree.Node(copy_layer->effect_tree_index());
5691 EXPECT_TRUE(node->data.is_drawn);
5692 node = tree.Node(copy_child_layer->effect_tree_index());
5693 EXPECT_TRUE(node->data.is_drawn);
5694 node = tree.Node(copy_grand_child_layer->effect_tree_index());
5695 EXPECT_FALSE(node->data.is_drawn);
5696
5697 // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its
5698 // actually hidden.
5699 EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface());
[email protected]30fe19ff2013-07-04 00:54:455700}
5701
[email protected]989386c2013-07-18 21:37:235702TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165703 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455704 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565705 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165706 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565707 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455708 host_impl.CreatePendingTree();
5709 const gfx::Transform identity_matrix;
5710
danakj60bc3bc2016-04-09 00:24:485711 std::unique_ptr<LayerImpl> root =
5712 LayerImpl::Create(host_impl.pending_tree(), 1);
weiliangc51fb255d2015-07-24 15:32:305713 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5714 gfx::PointF(), gfx::Size(50, 50), true, false,
5715 true);
5716 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455717
danakj60bc3bc2016-04-09 00:24:485718 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305719 LayerImpl::Create(host_impl.pending_tree(), 2);
5720 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
5721 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
5722 false, false);
5723 copy_parent->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455724 copy_parent->SetMasksToBounds(true);
5725
danakj60bc3bc2016-04-09 00:24:485726 std::unique_ptr<LayerImpl> copy_layer =
weiliangc51fb255d2015-07-24 15:32:305727 LayerImpl::Create(host_impl.pending_tree(), 3);
5728 SetLayerPropertiesForTesting(copy_layer.get(), identity_matrix,
5729 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5730 true, false, true);
5731 copy_layer->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455732
danakj60bc3bc2016-04-09 00:24:485733 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305734 LayerImpl::Create(host_impl.pending_tree(), 4);
5735 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
5736 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5737 true, false, false);
5738 copy_child->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455739
ajumae6f541b2016-05-31 16:50:505740 copy_layer->test_properties()->copy_requests.push_back(
weiliangc51fb255d2015-07-24 15:32:305741 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
[email protected]30fe19ff2013-07-04 00:54:455742
danakja04855a2015-11-18 20:39:105743 copy_layer->AddChild(std::move(copy_child));
5744 copy_parent->AddChild(std::move(copy_layer));
5745 root->AddChild(std::move(copy_parent));
weiliangc51fb255d2015-07-24 15:32:305746
5747 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:055748 LayerImpl* root_layer = root.get();
5749 root_layer->layer_tree_impl()->SetRootLayer(std::move(root));
weiliangc51fb255d2015-07-24 15:32:305750 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385751 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535752 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575753 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455754
xjze19f76402015-11-06 21:48:445755 // We should have two render surface, as the others are clipped out.
5756 ASSERT_EQ(2u, render_surface_layer_list.size());
sunxd71aea3e2016-04-01 23:48:055757 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455758
xjze19f76402015-11-06 21:48:445759 // The root render surface should only have 2 contributing layer, since the
[email protected]30fe19ff2013-07-04 00:54:455760 // other layers are empty/clipped away.
sunxd71aea3e2016-04-01 23:48:055761 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5762 EXPECT_EQ(root_layer->id(),
5763 root_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455764}
5765
[email protected]11a07b102013-07-24 17:33:195766TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
jaydasika6f972de2016-04-07 16:16:145767 LayerImpl* root = root_layer();
5768 LayerImpl* surface = AddChild<LayerImpl>(root);
5769 LayerImpl* surface_child = AddChild<LayerImpl>(surface);
5770
[email protected]11a07b102013-07-24 17:33:195771 const gfx::Transform identity_matrix;
jaydasika6f972de2016-04-07 16:16:145772 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
5773 gfx::PointF(), gfx::Size(50, 50), true, false,
5774 true);
5775 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
5776 gfx::PointF(-10, 20), gfx::Size(), true, false,
5777 true);
5778 SetLayerPropertiesForTesting(surface_child, identity_matrix, gfx::Point3F(),
5779 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]11a07b102013-07-24 17:33:195780 false);
jaydasika6f972de2016-04-07 16:16:145781 root->SetDrawsContent(true);
5782 surface_child->SetDrawsContent(true);
[email protected]11a07b102013-07-24 17:33:195783
jaydasika6f972de2016-04-07 16:16:145784 ExecuteCalculateDrawProperties(root);
[email protected]11a07b102013-07-24 17:33:195785
danakj64767d902015-06-19 00:10:435786 // The visible_layer_rect for the |surface_child| should not be clipped by
[email protected]11a07b102013-07-24 17:33:195787 // the viewport.
jaydasika6f972de2016-04-07 16:16:145788 EXPECT_EQ(gfx::Rect(50, 50), surface_child->visible_layer_rect());
[email protected]11a07b102013-07-24 17:33:195789}
5790
[email protected]420fdf6e2013-08-26 20:36:385791TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5792 // Ensure that a transform between the layer and its render surface is not a
5793 // problem. Constructs the following layer tree.
5794 //
5795 // root (a render surface)
5796 // + render_surface
5797 // + clip_parent (scaled)
5798 // + intervening_clipping_layer
5799 // + clip_child
5800 //
5801 // The render surface should be resized correctly and the clip child should
5802 // inherit the right clip rect.
enne70aa712d2015-07-28 22:46:315803 LayerImpl* root = root_layer();
5804 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
5805 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
jaydasika0d98ba92015-11-17 05:17:285806 clip_parent->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315807 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285808 intervening->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315809 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5810 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:565811 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:485812 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enne70aa712d2015-07-28 22:46:315813 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:565814 clip_parent->test_properties()->clip_children.reset(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385815
5816 intervening->SetMasksToBounds(true);
5817 clip_parent->SetMasksToBounds(true);
5818
[email protected]420fdf6e2013-08-26 20:36:385819 gfx::Transform scale_transform;
5820 scale_transform.Scale(2, 2);
5821
5822 gfx::Transform identity_transform;
5823
enne70aa712d2015-07-28 22:46:315824 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5825 gfx::PointF(), gfx::Size(50, 50), true, false,
5826 true);
5827 SetLayerPropertiesForTesting(render_surface, identity_transform,
5828 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5829 true, false, true);
5830 SetLayerPropertiesForTesting(clip_parent, scale_transform, gfx::Point3F(),
5831 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
5832 false, false);
5833 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5834 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5835 false, false);
5836 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5837 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
5838 false, false);
[email protected]420fdf6e2013-08-26 20:36:385839
enne70aa712d2015-07-28 22:46:315840 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385841
5842 ASSERT_TRUE(root->render_surface());
5843 ASSERT_TRUE(render_surface->render_surface());
5844
5845 // Ensure that we've inherited our clip parent's clip and weren't affected
5846 // by the intervening clip layer.
jaydasika6f972de2016-04-07 16:16:145847 ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect());
5848 ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect());
5849 ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385850
5851 // Ensure that the render surface reports a content rect that has been grown
5852 // to accomodate for the clip child.
jaydasika6f972de2016-04-07 16:16:145853 ASSERT_EQ(gfx::Rect(1, 1, 20, 20),
5854 render_surface->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385855
5856 // The above check implies the two below, but they nicely demonstrate that
5857 // we've grown, despite the intervening layer's clip.
5858 ASSERT_TRUE(clip_parent->clip_rect().Contains(
5859 render_surface->render_surface()->content_rect()));
5860 ASSERT_FALSE(intervening->clip_rect().Contains(
5861 render_surface->render_surface()->content_rect()));
5862}
5863
5864TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5865 // Ensure that intervening render surfaces are not a problem in the basic
5866 // case. In the following tree, both render surfaces should be resized to
5867 // accomodate for the clip child, despite an intervening clip.
5868 //
5869 // root (a render surface)
5870 // + clip_parent (masks to bounds)
5871 // + render_surface1 (sets opacity)
5872 // + intervening (masks to bounds)
5873 // + render_surface2 (also sets opacity)
5874 // + clip_child
5875 //
weiliangcd6a836d2015-07-28 21:20:235876 LayerImpl* root = root_layer();
5877 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5878 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5879 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5880 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5881 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365882 render_surface1->SetDrawsContent(true);
5883 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235884 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385885
jaydasika1c0a27d42016-04-28 01:54:565886 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385887
5888 intervening->SetMasksToBounds(true);
5889 clip_parent->SetMasksToBounds(true);
5890
[email protected]420fdf6e2013-08-26 20:36:385891 gfx::Transform translation_transform;
5892 translation_transform.Translate(2, 2);
5893
5894 gfx::Transform identity_transform;
weiliangcd6a836d2015-07-28 21:20:235895 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5896 gfx::PointF(), gfx::Size(50, 50), true, false,
5897 true);
5898 SetLayerPropertiesForTesting(clip_parent, translation_transform,
5899 gfx::Point3F(), gfx::PointF(1.f, 1.f),
5900 gfx::Size(40, 40), true, false, false);
5901 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5902 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5903 true, false, true);
5904 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5905 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5906 false, false);
5907 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5908 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5909 true, false, true);
5910 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5911 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
5912 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:385913
weiliangcd6a836d2015-07-28 21:20:235914 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385915
5916 EXPECT_TRUE(root->render_surface());
5917 EXPECT_TRUE(render_surface1->render_surface());
5918 EXPECT_TRUE(render_surface2->render_surface());
5919
5920 // Since the render surfaces could have expanded, they should not clip (their
5921 // bounds would no longer be reliable). We should resort to layer clipping
5922 // in this case.
jaydasika6f972de2016-04-07 16:16:145923 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5924 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385925 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145926 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5927 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385928 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5929
5930 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145931 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385932 EXPECT_TRUE(render_surface1->is_clipped());
5933
5934 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145935 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385936 EXPECT_TRUE(render_surface2->is_clipped());
5937
5938 // The content rects of both render surfaces should both have expanded to
5939 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145940 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5941 render_surface1->render_surface()->content_rect());
5942 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40),
5943 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385944
5945 // The clip child should have inherited the clip parent's clip (projected to
5946 // the right space, of course), and should have the correctly sized visible
5947 // content rect.
jaydasika6f972de2016-04-07 16:16:145948 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect());
5949 EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385950 EXPECT_TRUE(clip_child->is_clipped());
5951}
5952
5953TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
5954 // Ensure that intervening render surfaces are not a problem, even if there
5955 // is a scroll involved. Note, we do _not_ have to consider any other sort
5956 // of transform.
5957 //
5958 // root (a render surface)
5959 // + clip_parent (masks to bounds)
5960 // + render_surface1 (sets opacity)
5961 // + intervening (masks to bounds AND scrolls)
5962 // + render_surface2 (also sets opacity)
5963 // + clip_child
5964 //
weiliangcd6a836d2015-07-28 21:20:235965 LayerImpl* root = root_layer();
5966 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5967 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5968 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5969 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5970 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365971 render_surface1->SetDrawsContent(true);
5972 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235973 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385974
jaydasika1c0a27d42016-04-28 01:54:565975 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385976
5977 intervening->SetMasksToBounds(true);
5978 clip_parent->SetMasksToBounds(true);
weiliangcd6a836d2015-07-28 21:20:235979 intervening->SetScrollClipLayer(clip_parent->id());
5980 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:385981
5982 gfx::Transform translation_transform;
5983 translation_transform.Translate(2, 2);
5984
5985 gfx::Transform identity_transform;
weiliangcd6a836d2015-07-28 21:20:235986 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5987 gfx::PointF(), gfx::Size(50, 50), true, false,
5988 true);
5989 SetLayerPropertiesForTesting(clip_parent, translation_transform,
5990 gfx::Point3F(), gfx::PointF(1.f, 1.f),
5991 gfx::Size(40, 40), true, false, false);
5992 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5993 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5994 true, false, true);
5995 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5996 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5997 false, false);
5998 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5999 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
6000 true, false, true);
6001 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
6002 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
6003 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:386004
weiliangcd6a836d2015-07-28 21:20:236005 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:386006
6007 EXPECT_TRUE(root->render_surface());
6008 EXPECT_TRUE(render_surface1->render_surface());
6009 EXPECT_TRUE(render_surface2->render_surface());
6010
6011 // Since the render surfaces could have expanded, they should not clip (their
6012 // bounds would no longer be reliable). We should resort to layer clipping
6013 // in this case.
jaydasika6f972de2016-04-07 16:16:146014 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
6015 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386016 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:146017 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
6018 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386019 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6020
6021 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:146022 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386023 EXPECT_TRUE(render_surface1->is_clipped());
6024
6025 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:146026 EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386027 EXPECT_TRUE(render_surface2->is_clipped());
6028
6029 // The content rects of both render surfaces should both have expanded to
6030 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:146031 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
6032 render_surface1->render_surface()->content_rect());
6033 EXPECT_EQ(gfx::Rect(2, 2, 40, 40),
6034 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:386035
6036 // The clip child should have inherited the clip parent's clip (projected to
6037 // the right space, of course), and should have the correctly sized visible
6038 // content rect.
jaydasika6f972de2016-04-07 16:16:146039 EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect());
6040 EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:386041 EXPECT_TRUE(clip_child->is_clipped());
6042}
6043
6044TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
6045 // Ensures that descendants of the clip child inherit the correct clip.
6046 //
6047 // root (a render surface)
6048 // + clip_parent (masks to bounds)
6049 // + intervening (masks to bounds)
6050 // + clip_child
6051 // + child
6052 //
enne2d0d8e62015-08-18 18:29:176053 LayerImpl* root = root_layer();
6054 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
6055 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
6056 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
6057 LayerImpl* child = AddChild<LayerImpl>(clip_child);
jaydasika8640f9f2015-11-10 01:34:366058 clip_child->SetDrawsContent(true);
enne2d0d8e62015-08-18 18:29:176059 child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:386060
jaydasika1c0a27d42016-04-28 01:54:566061 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:486062 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enne2d0d8e62015-08-18 18:29:176063 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:566064 clip_parent->test_properties()->clip_children.reset(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:386065
6066 intervening->SetMasksToBounds(true);
6067 clip_parent->SetMasksToBounds(true);
6068
6069 gfx::Transform identity_transform;
enne2d0d8e62015-08-18 18:29:176070 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6071 gfx::PointF(), gfx::Size(50, 50), true, false,
6072 true);
6073 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
6074 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]420fdf6e2013-08-26 20:36:386075 false);
enne2d0d8e62015-08-18 18:29:176076 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
6077 gfx::PointF(), gfx::Size(5, 5), true, false,
[email protected]420fdf6e2013-08-26 20:36:386078 false);
enne2d0d8e62015-08-18 18:29:176079 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
6080 gfx::PointF(), gfx::Size(60, 60), true, false,
[email protected]420fdf6e2013-08-26 20:36:386081 false);
enne2d0d8e62015-08-18 18:29:176082 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6083 gfx::PointF(), gfx::Size(60, 60), true, false,
[email protected]420fdf6e2013-08-26 20:36:386084 false);
6085
enne2d0d8e62015-08-18 18:29:176086 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:386087
6088 EXPECT_TRUE(root->render_surface());
6089
6090 // Neither the clip child nor its descendant should have inherited the clip
6091 // from |intervening|.
jaydasika6f972de2016-04-07 16:16:146092 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386093 EXPECT_TRUE(clip_child->is_clipped());
jaydasika6f972de2016-04-07 16:16:146094 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:386095 EXPECT_TRUE(child->is_clipped());
6096}
6097
6098TEST_F(LayerTreeHostCommonTest,
6099 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
6100 // Ensures that non-descendant clip children in the tree do not affect
6101 // render surfaces.
6102 //
6103 // root (a render surface)
6104 // + clip_parent (masks to bounds)
6105 // + render_surface1
6106 // + clip_child
6107 // + render_surface2
6108 // + non_clip_child
6109 //
6110 // In this example render_surface2 should be unaffected by clip_child.
enneb441cdd2015-07-28 22:47:506111 LayerImpl* root = root_layer();
6112 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
6113 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:286114 render_surface1->SetDrawsContent(true);
enneb441cdd2015-07-28 22:47:506115 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
6116 clip_child->SetDrawsContent(true);
6117 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:286118 render_surface2->SetDrawsContent(true);
enneb441cdd2015-07-28 22:47:506119 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
6120 non_clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:386121
jaydasika1c0a27d42016-04-28 01:54:566122 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:486123 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enneb441cdd2015-07-28 22:47:506124 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:566125 clip_parent->test_properties()->clip_children.reset(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:386126
6127 clip_parent->SetMasksToBounds(true);
6128 render_surface1->SetMasksToBounds(true);
6129
6130 gfx::Transform identity_transform;
enneb441cdd2015-07-28 22:47:506131 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6132 gfx::PointF(), gfx::Size(15, 15), true, false,
6133 true);
6134 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
6135 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]420fdf6e2013-08-26 20:36:386136 false);
enneb441cdd2015-07-28 22:47:506137 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6138 gfx::Point3F(), gfx::PointF(5, 5),
6139 gfx::Size(5, 5), true, false, true);
6140 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6141 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
6142 true, false, true);
6143 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
6144 gfx::PointF(-1, 1), gfx::Size(10, 10), true,
6145 false, false);
6146 SetLayerPropertiesForTesting(non_clip_child, identity_transform,
6147 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
6148 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:386149
enneb441cdd2015-07-28 22:47:506150 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:386151
6152 EXPECT_TRUE(root->render_surface());
6153 EXPECT_TRUE(render_surface1->render_surface());
6154 EXPECT_TRUE(render_surface2->render_surface());
6155
jaydasika6f972de2016-04-07 16:16:146156 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386157 EXPECT_TRUE(render_surface1->is_clipped());
6158
6159 // The render surface should not clip (it has unclipped descendants), instead
6160 // it should rely on layer clipping.
jaydasika6f972de2016-04-07 16:16:146161 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
6162 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386163 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6164
jaydasika0d98ba92015-11-17 05:17:286165 // That said, it should have grown to accomodate the unclipped descendant and
6166 // its own size.
jaydasika6f972de2016-04-07 16:16:146167 EXPECT_EQ(gfx::Rect(-1, 0, 6, 5),
6168 render_surface1->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:386169
6170 // This render surface should clip. It has no unclipped descendants.
jaydasika6f972de2016-04-07 16:16:146171 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
6172 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386173 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
weiliangcbb2e8642016-03-04 00:24:426174 EXPECT_FALSE(render_surface2->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:386175
6176 // It also shouldn't have grown to accomodate the clip child.
jaydasika6f972de2016-04-07 16:16:146177 EXPECT_EQ(gfx::Rect(0, 0, 5, 5),
6178 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:386179
6180 // Sanity check our num_unclipped_descendants values.
ajuma0641ded2016-05-05 21:28:216181 EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants);
6182 EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants);
[email protected]420fdf6e2013-08-26 20:36:386183}
6184
weiliangc9ced1592015-11-17 19:04:376185TEST_F(LayerTreeHostCommonTest,
6186 CreateRenderSurfaceWhenFlattenInsideRenderingContext) {
6187 // Verifies that Render Surfaces are created at the edge of rendering context.
6188
weiliangcc154ce22015-12-09 03:39:266189 LayerImpl* root = root_layer();
6190 LayerImpl* child1 = AddChildToRoot<LayerImpl>();
6191 LayerImpl* child2 = AddChild<LayerImpl>(child1);
6192 LayerImpl* child3 = AddChild<LayerImpl>(child2);
6193 root->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376194
6195 const gfx::Transform identity_matrix;
6196 gfx::Point3F transform_origin;
6197 gfx::PointF position;
6198 gfx::Size bounds(100, 100);
6199
6200 SetLayerPropertiesForTesting(root, identity_matrix, transform_origin,
6201 position, bounds, true, false);
6202 SetLayerPropertiesForTesting(child1, identity_matrix, transform_origin,
6203 position, bounds, false, true);
weiliangcc154ce22015-12-09 03:39:266204 child1->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376205 SetLayerPropertiesForTesting(child2, identity_matrix, transform_origin,
6206 position, bounds, true, false);
weiliangcc154ce22015-12-09 03:39:266207 child2->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376208 SetLayerPropertiesForTesting(child3, identity_matrix, transform_origin,
6209 position, bounds, true, false);
weiliangcc154ce22015-12-09 03:39:266210 child3->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376211
6212 child2->Set3dSortingContextId(1);
6213 child3->Set3dSortingContextId(1);
6214
weiliangcc154ce22015-12-09 03:39:266215 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
weiliangc9ced1592015-11-17 19:04:376216
6217 // Verify which render surfaces were created.
6218 EXPECT_TRUE(root->has_render_surface());
6219 EXPECT_FALSE(child1->has_render_surface());
6220 EXPECT_TRUE(child2->has_render_surface());
6221 EXPECT_FALSE(child3->has_render_surface());
6222}
6223
[email protected]45948712013-09-27 02:46:486224TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
khushalsagarb64b360d2015-10-21 19:25:166225 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:456226 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:566227 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:166228 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:566229 &task_graph_runner);
weiliangcc154ce22015-12-09 03:39:266230
danakj60bc3bc2016-04-09 00:24:486231 std::unique_ptr<LayerImpl> root =
[email protected]45948712013-09-27 02:46:486232 LayerImpl::Create(host_impl.active_tree(), 12345);
danakj60bc3bc2016-04-09 00:24:486233 std::unique_ptr<LayerImpl> child1 =
[email protected]45948712013-09-27 02:46:486234 LayerImpl::Create(host_impl.active_tree(), 123456);
danakj60bc3bc2016-04-09 00:24:486235 std::unique_ptr<LayerImpl> child2 =
[email protected]45948712013-09-27 02:46:486236 LayerImpl::Create(host_impl.active_tree(), 1234567);
danakj60bc3bc2016-04-09 00:24:486237 std::unique_ptr<LayerImpl> child3 =
[email protected]45948712013-09-27 02:46:486238 LayerImpl::Create(host_impl.active_tree(), 12345678);
6239
6240 gfx::Transform identity_matrix;
[email protected]a2566412014-06-05 03:14:206241 gfx::Point3F transform_origin;
[email protected]45948712013-09-27 02:46:486242 gfx::PointF position;
6243 gfx::Size bounds(100, 100);
awoloszyne83f28c2014-12-22 15:40:006244 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
6245 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:486246 root->SetDrawsContent(true);
6247
6248 // This layer structure normally forces render surface due to preserves3d
6249 // behavior.
awoloszyne83f28c2014-12-22 15:40:006250 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin,
weiliangc9ced1592015-11-17 19:04:376251 position, bounds, false, true, false);
[email protected]45948712013-09-27 02:46:486252 child1->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:006253 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin,
weiliangc9ced1592015-11-17 19:04:376254 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:486255 child2->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:006256 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin,
6257 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:486258 child3->SetDrawsContent(true);
6259
[email protected]a9d4d4f2014-06-19 06:49:286260 child2->Set3dSortingContextId(1);
6261 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:576262
danakja04855a2015-11-18 20:39:106263 child2->AddChild(std::move(child3));
6264 child1->AddChild(std::move(child2));
6265 root->AddChild(std::move(child1));
sunxd71aea3e2016-04-01 23:48:056266 LayerImpl* root_layer = root.get();
6267 root_layer->layer_tree_impl()->SetRootLayer(std::move(root));
[email protected]45948712013-09-27 02:46:486268
6269 {
6270 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:056271 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer);
[email protected]45948712013-09-27 02:46:486272 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386273 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:486274 inputs.can_render_to_separate_surface = true;
sunxdb365de02016-04-28 20:32:576275 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:486276
6277 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026278
6279 int count_represents_target_render_surface = 0;
6280 int count_represents_contributing_render_surface = 0;
6281 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516282 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6283 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026284 it != end; ++it) {
6285 if (it.represents_target_render_surface())
6286 count_represents_target_render_surface++;
6287 if (it.represents_contributing_render_surface())
6288 count_represents_contributing_render_surface++;
6289 if (it.represents_itself())
6290 count_represents_itself++;
6291 }
6292
6293 // Two render surfaces.
6294 EXPECT_EQ(2, count_represents_target_render_surface);
6295 // Second render surface contributes to root render surface.
6296 EXPECT_EQ(1, count_represents_contributing_render_surface);
6297 // All 4 layers represent itself.
6298 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486299 }
6300
6301 {
6302 LayerImplList render_surface_layer_list;
6303 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386304 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:486305 inputs.can_render_to_separate_surface = false;
sunxdb365de02016-04-28 20:32:576306 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:486307
6308 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026309
6310 int count_represents_target_render_surface = 0;
6311 int count_represents_contributing_render_surface = 0;
6312 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516313 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6314 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026315 it != end; ++it) {
6316 if (it.represents_target_render_surface())
6317 count_represents_target_render_surface++;
6318 if (it.represents_contributing_render_surface())
6319 count_represents_contributing_render_surface++;
6320 if (it.represents_itself())
6321 count_represents_itself++;
6322 }
6323
6324 // Only root layer has a render surface.
6325 EXPECT_EQ(1, count_represents_target_render_surface);
6326 // No layer contributes a render surface to root render surface.
6327 EXPECT_EQ(0, count_represents_contributing_render_surface);
6328 // All 4 layers represent itself.
6329 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486330 }
6331}
6332
[email protected]a9aa60a82013-08-29 04:28:266333TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
enne03b0e9a2015-06-19 00:08:026334 LayerImpl* root = root_layer();
jaydasikae00c8a42016-01-28 20:18:336335 LayerImpl* back_facing = AddChild<LayerImpl>(root);
6336 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
6337 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
6338 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
6339 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
6340 child1->SetDrawsContent(true);
6341 child2->SetDrawsContent(true);
[email protected]a9aa60a82013-08-29 04:28:266342
6343 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026344 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6345 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]56fffdd2014-02-11 19:50:576346 true);
jaydasikae00c8a42016-01-28 20:18:336347 SetLayerPropertiesForTesting(back_facing, identity_transform, gfx::Point3F(),
6348 gfx::PointF(), gfx::Size(50, 50), true, false,
6349 false);
6350 SetLayerPropertiesForTesting(render_surface1, identity_transform,
enne03b0e9a2015-06-19 00:08:026351 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6352 false, true, true);
jaydasikae00c8a42016-01-28 20:18:336353 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6354 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6355 false, true, true);
6356 SetLayerPropertiesForTesting(child1, identity_transform, gfx::Point3F(),
6357 gfx::PointF(), gfx::Size(20, 20), true, false,
6358 false);
6359 SetLayerPropertiesForTesting(child2, identity_transform, gfx::Point3F(),
enne03b0e9a2015-06-19 00:08:026360 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]a9aa60a82013-08-29 04:28:266361 false);
6362
jaydasikaca2605e2016-04-23 02:52:526363 root->test_properties()->should_flatten_transform = false;
[email protected]a9d4d4f2014-06-19 06:49:286364 root->Set3dSortingContextId(1);
jaydasikae00c8a42016-01-28 20:18:336365 back_facing->Set3dSortingContextId(1);
jaydasikaca2605e2016-04-23 02:52:526366 back_facing->test_properties()->should_flatten_transform = false;
jaydasika6b5a32bf2016-04-22 21:56:366367 render_surface1->test_properties()->double_sided = false;
jaydasikae00c8a42016-01-28 20:18:336368 render_surface2->Set3dSortingContextId(2);
jaydasika6b5a32bf2016-04-22 21:56:366369 render_surface2->test_properties()->double_sided = false;
[email protected]a9aa60a82013-08-29 04:28:266370
enne03b0e9a2015-06-19 00:08:026371 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266372
jaydasikae00c8a42016-01-28 20:18:336373 EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id());
6374 EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id());
6375 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6376 EXPECT_EQ(2u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026377 ->at(0)
6378 ->render_surface()
6379 ->layer_list()
6380 .size());
6381 EXPECT_EQ(1u, render_surface_layer_list_impl()
6382 ->at(1)
6383 ->render_surface()
6384 ->layer_list()
6385 .size());
[email protected]a9aa60a82013-08-29 04:28:266386
6387 gfx::Transform rotation_transform = identity_transform;
6388 rotation_transform.RotateAboutXAxis(180.0);
6389
jaydasikae00c8a42016-01-28 20:18:336390 back_facing->SetTransform(rotation_transform);
jaydasika5aa88b82015-11-10 01:48:036391 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]a9aa60a82013-08-29 04:28:266392
enne03b0e9a2015-06-19 00:08:026393 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266394
jaydasikae00c8a42016-01-28 20:18:336395 // render_surface1 is in the same 3d rendering context as back_facing and is
6396 // not double sided, so it should not be in RSLL. render_surface2 is also not
6397 // double-sided, but will still be in RSLL as it's in a different 3d rendering
6398 // context.
6399 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
6400 EXPECT_EQ(1u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026401 ->at(0)
6402 ->render_surface()
6403 ->layer_list()
6404 .size());
[email protected]a9aa60a82013-08-29 04:28:266405}
6406
ajumaaa0d3862015-11-09 22:24:466407TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) {
6408 LayerImpl* root = root_layer();
6409 LayerImpl* child = AddChild<LayerImpl>(root);
6410 LayerImpl* grand_child = AddChild<LayerImpl>(child);
6411 grand_child->SetDrawsContent(true);
6412
jaydasika6b5a32bf2016-04-22 21:56:366413 child->test_properties()->double_sided = false;
ajumaaa0d3862015-11-09 22:24:466414 grand_child->SetUseParentBackfaceVisibility(true);
6415
6416 gfx::Transform identity_transform;
6417 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
jaydasika62bd3dd2016-02-04 18:52:556418 gfx::PointF(), gfx::Size(50, 50), false, false,
ajumaaa0d3862015-11-09 22:24:466419 true);
6420 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
jaydasika62bd3dd2016-02-04 18:52:556421 gfx::PointF(), gfx::Size(30, 30), false, false,
ajumaaa0d3862015-11-09 22:24:466422 false);
6423 SetLayerPropertiesForTesting(grand_child, identity_transform, gfx::Point3F(),
jaydasika62bd3dd2016-02-04 18:52:556424 gfx::PointF(), gfx::Size(20, 20), false, false,
ajumaaa0d3862015-11-09 22:24:466425 false);
6426
6427 ExecuteCalculateDrawProperties(root);
6428
6429 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6430 EXPECT_EQ(grand_child, render_surface_layer_list_impl()
6431 ->at(0)
6432 ->render_surface()
6433 ->layer_list()[0]);
jaydasika62bd3dd2016-02-04 18:52:556434
6435 // As all layers have identity transform, we shouldn't check for backface
6436 // visibility.
6437 EXPECT_FALSE(root->should_check_backface_visibility());
6438 EXPECT_FALSE(child->should_check_backface_visibility());
6439 EXPECT_FALSE(grand_child->should_check_backface_visibility());
6440 // As there are no 3d rendering contexts, all layers should use their local
6441 // transform for backface visibility.
6442 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6443 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6444 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6445
ajumaaa0d3862015-11-09 22:24:466446 gfx::Transform rotation_transform = identity_transform;
6447 rotation_transform.RotateAboutXAxis(180.0);
6448
6449 child->SetTransform(rotation_transform);
jaydasika62bd3dd2016-02-04 18:52:556450 child->Set3dSortingContextId(1);
6451 grand_child->Set3dSortingContextId(1);
ajumaaa0d3862015-11-09 22:24:466452 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6453
6454 ExecuteCalculateDrawProperties(root);
6455 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6456 EXPECT_EQ(0u, render_surface_layer_list_impl()
6457 ->at(0)
6458 ->render_surface()
6459 ->layer_list()
6460 .size());
jaydasika62bd3dd2016-02-04 18:52:556461
6462 // We should check for backface visibilty of child as it has a rotation
6463 // transform. We should also check for grand_child as it uses the backface
6464 // visibility of its parent.
6465 EXPECT_FALSE(root->should_check_backface_visibility());
6466 EXPECT_TRUE(child->should_check_backface_visibility());
6467 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6468 // child uses its local transform for backface visibility as it is the root of
6469 // a 3d rendering context. grand_child is in a 3d rendering context and is not
6470 // the root, but it derives its backface visibility from its parent which uses
6471 // its local transform.
6472 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6473 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6474 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6475
6476 grand_child->SetUseParentBackfaceVisibility(false);
jaydasika6b5a32bf2016-04-22 21:56:366477 grand_child->test_properties()->double_sided = false;
jaydasika62bd3dd2016-02-04 18:52:556478 grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6479
6480 ExecuteCalculateDrawProperties(root);
6481 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6482 EXPECT_EQ(0u, render_surface_layer_list_impl()
6483 ->at(0)
6484 ->render_surface()
6485 ->layer_list()
6486 .size());
6487
6488 // We should check the backface visibility of child as it has a rotation
6489 // transform and for grand_child as it is in a 3d rendering context and not
6490 // the root of it.
6491 EXPECT_FALSE(root->should_check_backface_visibility());
6492 EXPECT_TRUE(child->should_check_backface_visibility());
6493 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6494 // grand_child is in an existing 3d rendering context, so it should not use
6495 // local transform for backface visibility.
6496 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6497 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6498 EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility());
ajumaaa0d3862015-11-09 22:24:466499}
6500
sunxd59dd7da2016-05-19 20:07:476501TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) {
6502 LayerImpl* root = root_layer();
6503 LayerImpl* back_facing = AddChild<LayerImpl>(root);
6504 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
6505 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
6506
6507 gfx::Transform identity_transform;
6508 gfx::Transform rotate_about_y;
6509 rotate_about_y.RotateAboutYAxis(180.0);
6510 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6511 gfx::PointF(), gfx::Size(50, 50), false, true,
6512 true);
6513 SetLayerPropertiesForTesting(back_facing, rotate_about_y, gfx::Point3F(),
6514 gfx::PointF(), gfx::Size(50, 50), false, true,
6515 false);
6516 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6517 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6518 false, true, true);
6519 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6520 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6521 false, true, true);
6522
6523 render_surface1->test_properties()->double_sided = false;
6524 render_surface2->test_properties()->double_sided = false;
6525
6526 ExecuteCalculateDrawProperties(root);
6527
6528 const EffectTree& tree =
6529 root->layer_tree_impl()->property_trees()->effect_tree;
6530 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
6531 ->data.hidden_by_backface_visibility);
6532 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
6533 ->data.hidden_by_backface_visibility);
6534
6535 back_facing->OnTransformAnimated(identity_transform);
6536 render_surface2->OnTransformAnimated(rotate_about_y);
6537 ExecuteCalculateDrawProperties(root);
6538 EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index())
6539 ->data.hidden_by_backface_visibility);
6540 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
6541 ->data.hidden_by_backface_visibility);
6542
6543 render_surface1->OnTransformAnimated(rotate_about_y);
6544 ExecuteCalculateDrawProperties(root);
6545 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
6546 ->data.hidden_by_backface_visibility);
6547 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
6548 ->data.hidden_by_backface_visibility);
6549}
6550
[email protected]995708c52013-10-17 20:52:596551TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
6552 // Checks that the simple case (being clipped by a scroll parent that would
6553 // have been processed before you anyhow) results in the right clips.
6554 //
6555 // + root
6556 // + scroll_parent_border
6557 // | + scroll_parent_clip
6558 // | + scroll_parent
6559 // + scroll_child
6560 //
enne085b48a2015-08-18 17:54:486561 LayerImpl* root = root_layer();
6562 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
6563 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6564 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6565 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596566
enne085b48a2015-08-18 17:54:486567 scroll_parent->SetDrawsContent(true);
6568 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596569 scroll_parent_clip->SetMasksToBounds(true);
6570
jaydasika1c0a27d42016-04-28 01:54:566571 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakj60bc3bc2016-04-09 00:24:486572 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
6573 new std::set<LayerImpl*>);
enne085b48a2015-08-18 17:54:486574 scroll_children->insert(scroll_child);
jaydasika1c0a27d42016-04-28 01:54:566575 scroll_parent->test_properties()->scroll_children.reset(
6576 scroll_children.release());
[email protected]995708c52013-10-17 20:52:596577
6578 gfx::Transform identity_transform;
enne085b48a2015-08-18 17:54:486579 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6580 gfx::PointF(), gfx::Size(50, 50), true, false,
6581 true);
6582 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6583 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6584 true, false, false);
6585 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6586 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6587 true, false, false);
6588 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6589 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6590 true, false, false);
6591 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6592 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596593 false);
6594
enne085b48a2015-08-18 17:54:486595 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596596
6597 EXPECT_TRUE(root->render_surface());
6598
jaydasika6f972de2016-04-07 16:16:146599 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596600 EXPECT_TRUE(scroll_child->is_clipped());
6601}
6602
jaydasika8ccff3d2016-01-20 19:51:306603TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) {
6604 // Tests the computation of draw transform for the scroll child when its
6605 // target is different from its scroll parent's target.
6606 LayerImpl* root = root_layer();
6607 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
6608 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
6609 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target);
6610 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
6611
6612 scroll_parent->SetDrawsContent(true);
6613 scroll_child->SetDrawsContent(true);
6614
jaydasika1c0a27d42016-04-28 01:54:566615 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakj60bc3bc2016-04-09 00:24:486616 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
6617 new std::set<LayerImpl*>);
jaydasika8ccff3d2016-01-20 19:51:306618 scroll_children->insert(scroll_child);
jaydasika1c0a27d42016-04-28 01:54:566619 scroll_parent->test_properties()->scroll_children.reset(
6620 scroll_children.release());
jaydasika8ccff3d2016-01-20 19:51:306621
6622 gfx::Transform identity_transform;
6623 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6624 gfx::PointF(), gfx::Size(50, 50), true, false,
6625 true);
6626 SetLayerPropertiesForTesting(scroll_child_target, identity_transform,
6627 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6628 true, false, true);
6629 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6630 gfx::PointF(), gfx::Size(50, 50), true, false,
6631 false);
6632 SetLayerPropertiesForTesting(scroll_parent_target, identity_transform,
6633 gfx::Point3F(), gfx::PointF(10, 10),
6634 gfx::Size(50, 50), true, false, true);
6635 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6636 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
jaydasika2489a442016-01-29 02:26:006637 true, false, false);
6638 scroll_parent_target->SetMasksToBounds(true);
jaydasika8ccff3d2016-01-20 19:51:306639
jaydasika2489a442016-01-29 02:26:006640 float device_scale_factor = 1.5f;
6641 LayerImplList render_surface_layer_list_impl;
jaydasika2489a442016-01-29 02:26:006642 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386643 root, root->bounds(), identity_transform,
6644 &render_surface_layer_list_impl);
jaydasika2489a442016-01-29 02:26:006645 inputs.device_scale_factor = device_scale_factor;
sunxdb365de02016-04-28 20:32:576646 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika2489a442016-01-29 02:26:006647
weiliangc1da3fb892016-03-14 20:23:526648 EXPECT_EQ(scroll_child->effect_tree_index(),
6649 scroll_child_target->effect_tree_index());
jaydasika2489a442016-01-29 02:26:006650 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40));
6651 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75));
6652 gfx::Transform scale;
6653 scale.Scale(1.5f, 1.5f);
6654 EXPECT_EQ(scroll_child->DrawTransform(), scale);
jaydasika8ccff3d2016-01-20 19:51:306655}
6656
[email protected]08bdf1b2014-04-16 23:23:296657TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
enneca33fed2015-07-27 18:22:196658 LayerImpl* root = root_layer();
6659 root->SetDrawsContent(true);
6660 LayerImpl* parent = AddChildToRoot<LayerImpl>();
6661 parent->SetDrawsContent(true);
6662 LayerImpl* child = AddChild<LayerImpl>(parent);
6663 child->SetDrawsContent(true);
[email protected]08bdf1b2014-04-16 23:23:296664
6665 gfx::Transform identity_transform;
enneca33fed2015-07-27 18:22:196666 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6667 gfx::PointF(), gfx::Size(50, 50), true, true,
[email protected]08bdf1b2014-04-16 23:23:296668 true);
enneca33fed2015-07-27 18:22:196669 SetLayerPropertiesForTesting(parent, identity_transform, gfx::Point3F(),
6670 gfx::PointF(), gfx::Size(30, 30), true, true,
[email protected]08bdf1b2014-04-16 23:23:296671 true);
enneca33fed2015-07-27 18:22:196672 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6673 gfx::PointF(), gfx::Size(20, 20), true, true,
[email protected]08bdf1b2014-04-16 23:23:296674 true);
[email protected]08bdf1b2014-04-16 23:23:296675
enneca33fed2015-07-27 18:22:196676 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296677
enneca33fed2015-07-27 18:22:196678 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296679
6680 gfx::Transform singular_transform;
6681 singular_transform.Scale3d(
6682 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6683
6684 child->SetTransform(singular_transform);
6685
sunxd71aea3e2016-04-01 23:48:056686 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196687 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296688
enneca33fed2015-07-27 18:22:196689 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296690
6691 // Ensure that the entire subtree under a layer with singular transform does
6692 // not get rendered.
6693 parent->SetTransform(singular_transform);
6694 child->SetTransform(identity_transform);
6695
sunxd71aea3e2016-04-01 23:48:056696 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196697 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296698
enneca33fed2015-07-27 18:22:196699 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296700}
6701
[email protected]995708c52013-10-17 20:52:596702TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
6703 // Checks that clipping by a scroll parent that follows you in paint order
6704 // still results in correct clipping.
6705 //
6706 // + root
[email protected]995708c52013-10-17 20:52:596707 // + scroll_parent_border
6708 // + scroll_parent_clip
6709 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026710 // + scroll_child
[email protected]995708c52013-10-17 20:52:596711 //
enne03b0e9a2015-06-19 00:08:026712 LayerImpl* root = root_layer();
6713 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6714 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6715 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6716 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596717
enne03b0e9a2015-06-19 00:08:026718 scroll_parent->SetDrawsContent(true);
6719 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596720
6721 scroll_parent_clip->SetMasksToBounds(true);
6722
jaydasika1c0a27d42016-04-28 01:54:566723 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakj60bc3bc2016-04-09 00:24:486724 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
6725 new std::set<LayerImpl*>);
ajuma9af2e92b2015-06-29 22:26:386726 scroll_children->insert(scroll_child);
jaydasika1c0a27d42016-04-28 01:54:566727 scroll_parent->test_properties()->scroll_children.reset(
6728 scroll_children.release());
[email protected]995708c52013-10-17 20:52:596729
6730 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026731 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6732 gfx::PointF(), gfx::Size(50, 50), true, false,
6733 true);
6734 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6735 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6736 true, false, false);
6737 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6738 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6739 true, false, false);
6740 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6741 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6742 true, false, false);
6743 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6744 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596745 false);
6746
enne03b0e9a2015-06-19 00:08:026747 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596748
6749 EXPECT_TRUE(root->render_surface());
6750
jaydasika6f972de2016-04-07 16:16:146751 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596752 EXPECT_TRUE(scroll_child->is_clipped());
6753}
6754
6755TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
6756 // Checks that clipping by a scroll parent and scroll grandparent that follow
6757 // you in paint order still results in correct clipping.
6758 //
6759 // + root
6760 // + scroll_child
6761 // + scroll_parent_border
6762 // | + scroll_parent_clip
6763 // | + scroll_parent
6764 // + scroll_grandparent_border
6765 // + scroll_grandparent_clip
6766 // + scroll_grandparent
6767 //
enne03b0e9a2015-06-19 00:08:026768 LayerImpl* root = root_layer();
6769 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6770 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6771 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6772 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6773 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6774 LayerImpl* scroll_grandparent_clip =
6775 AddChild<LayerImpl>(scroll_grandparent_border);
6776 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:596777
enne03b0e9a2015-06-19 00:08:026778 scroll_parent->SetDrawsContent(true);
6779 scroll_grandparent->SetDrawsContent(true);
6780 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596781
6782 scroll_parent_clip->SetMasksToBounds(true);
6783 scroll_grandparent_clip->SetMasksToBounds(true);
6784
jaydasika1c0a27d42016-04-28 01:54:566785 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakj60bc3bc2016-04-09 00:24:486786 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
6787 new std::set<LayerImpl*>);
ajuma9af2e92b2015-06-29 22:26:386788 scroll_children->insert(scroll_child);
jaydasika1c0a27d42016-04-28 01:54:566789 scroll_parent->test_properties()->scroll_children.reset(
6790 scroll_children.release());
ajuma9af2e92b2015-06-29 22:26:386791
jaydasika1c0a27d42016-04-28 01:54:566792 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
ajuma9af2e92b2015-06-29 22:26:386793 scroll_children.reset(new std::set<LayerImpl*>);
6794 scroll_children->insert(scroll_parent_border);
jaydasika1c0a27d42016-04-28 01:54:566795 scroll_grandparent->test_properties()->scroll_children.reset(
6796 scroll_children.release());
[email protected]995708c52013-10-17 20:52:596797
6798 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026799 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6800 gfx::PointF(), gfx::Size(50, 50), true, false,
6801 true);
6802 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6803 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6804 true, false, false);
6805 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6806 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6807 true, false, false);
6808 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6809 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6810 true, false, false);
6811 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6812 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6813 true, false, false);
6814 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6815 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6816 true, false, false);
6817 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6818 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6819 true, false, false);
6820 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6821 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596822 false);
6823
enne03b0e9a2015-06-19 00:08:026824 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596825
6826 EXPECT_TRUE(root->render_surface());
6827
jaydasika6f972de2016-04-07 16:16:146828 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596829 EXPECT_TRUE(scroll_child->is_clipped());
6830
6831 // Despite the fact that we visited the above layers out of order to get the
6832 // correct clip, the layer lists should be unaffected.
6833 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
enne03b0e9a2015-06-19 00:08:026834 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
6835 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
6836 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
[email protected]995708c52013-10-17 20:52:596837}
6838
6839TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
6840 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:226841 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:596842 // + root
6843 // + scroll_child
6844 // + scroll_parent_border
6845 // + scroll_parent_clip
6846 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026847 // + render_surface2
[email protected]995708c52013-10-17 20:52:596848 // + scroll_grandparent_border
6849 // + scroll_grandparent_clip
6850 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:026851 // + render_surface1
[email protected]995708c52013-10-17 20:52:596852 //
enne03b0e9a2015-06-19 00:08:026853 LayerImpl* root = root_layer();
6854 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596855
enne03b0e9a2015-06-19 00:08:026856 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6857 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596858
enne03b0e9a2015-06-19 00:08:026859 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6860 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6861 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6862 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
6863 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6864 LayerImpl* scroll_grandparent_clip =
6865 AddChild<LayerImpl>(scroll_grandparent_border);
6866 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6867 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:596868
enne03b0e9a2015-06-19 00:08:026869 scroll_parent->SetDrawsContent(true);
6870 render_surface1->SetDrawsContent(true);
6871 scroll_grandparent->SetDrawsContent(true);
6872 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596873
6874 scroll_parent_clip->SetMasksToBounds(true);
6875 scroll_grandparent_clip->SetMasksToBounds(true);
6876
jaydasika1c0a27d42016-04-28 01:54:566877 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakj60bc3bc2016-04-09 00:24:486878 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
6879 new std::set<LayerImpl*>);
ajuma9af2e92b2015-06-29 22:26:386880 scroll_children->insert(scroll_child);
jaydasika1c0a27d42016-04-28 01:54:566881 scroll_parent->test_properties()->scroll_children.reset(
6882 scroll_children.release());
ajuma9af2e92b2015-06-29 22:26:386883
jaydasika1c0a27d42016-04-28 01:54:566884 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
ajuma9af2e92b2015-06-29 22:26:386885 scroll_children.reset(new std::set<LayerImpl*>);
6886 scroll_children->insert(scroll_parent_border);
jaydasika1c0a27d42016-04-28 01:54:566887 scroll_grandparent->test_properties()->scroll_children.reset(
6888 scroll_children.release());
[email protected]995708c52013-10-17 20:52:596889
6890 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026891 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6892 gfx::PointF(), gfx::Size(50, 50), true, false,
6893 true);
6894 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6895 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6896 true, false, false);
6897 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6898 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6899 true, false, false);
6900 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6901 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6902 true, false, false);
6903 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6904 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6905 true, false, true);
6906 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6907 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6908 true, false, false);
6909 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6910 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6911 true, false, false);
6912 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6913 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6914 true, false, false);
6915 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6916 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6917 true, false, true);
6918 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6919 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596920 false);
6921
enne03b0e9a2015-06-19 00:08:026922 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596923
6924 EXPECT_TRUE(root->render_surface());
6925
jaydasika6f972de2016-04-07 16:16:146926 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596927 EXPECT_TRUE(scroll_child->is_clipped());
6928
6929 // Despite the fact that we had to process the layers out of order to get the
6930 // right clip, our render_surface_layer_list's order should be unaffected.
enne03b0e9a2015-06-19 00:08:026931 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6932 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
6933 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
6934 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
6935 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6936 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6937 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:596938}
6939
ajuma0b10f942015-03-21 07:45:536940TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
6941 // Ensures that when we have a render surface between a fixed position layer
6942 // and its container, we compute the fixed position layer's draw transform
6943 // with respect to that intervening render surface, not with respect to its
6944 // container's render target.
6945 //
6946 // + root
6947 // + render_surface
6948 // + fixed
ajuma737b2702015-05-06 01:18:376949 // + child
ajuma0b10f942015-03-21 07:45:536950 //
sunxdfd920f3f2016-04-05 16:17:516951 LayerImpl* root = root_layer();
6952 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6953 LayerImpl* fixed = AddChild<LayerImpl>(render_surface);
6954 LayerImpl* child = AddChild<LayerImpl>(fixed);
ajuma0b10f942015-03-21 07:45:536955
sunxdfd920f3f2016-04-05 16:17:516956 render_surface->SetDrawsContent(true);
6957 fixed->SetDrawsContent(true);
6958 child->SetDrawsContent(true);
ajuma0b10f942015-03-21 07:45:536959
jaydasika6b5a32bf2016-04-22 21:56:366960 render_surface->test_properties()->force_render_surface = true;
jaydasikaca2605e2016-04-23 02:52:526961 root->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0b10f942015-03-21 07:45:536962
6963 LayerPositionConstraint constraint;
6964 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526965 fixed->test_properties()->position_constraint = constraint;
ajuma0b10f942015-03-21 07:45:536966
sunxdfd920f3f2016-04-05 16:17:516967 SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(),
ajuma0b10f942015-03-21 07:45:536968 gfx::PointF(), gfx::Size(50, 50), true, false);
sunxdfd920f3f2016-04-05 16:17:516969 SetLayerPropertiesForTesting(render_surface, gfx::Transform(), gfx::Point3F(),
6970 gfx::PointF(7.f, 9.f), gfx::Size(50, 50), true,
6971 false);
6972 SetLayerPropertiesForTesting(fixed, gfx::Transform(), gfx::Point3F(),
ajuma0b10f942015-03-21 07:45:536973 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true,
6974 false);
sunxdfd920f3f2016-04-05 16:17:516975 SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(),
ajuma737b2702015-05-06 01:18:376976 gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true,
6977 false);
ajuma0b10f942015-03-21 07:45:536978
sunxdfd920f3f2016-04-05 16:17:516979 ExecuteCalculateDrawProperties(root);
ajuma0b10f942015-03-21 07:45:536980
sunxdfd920f3f2016-04-05 16:17:516981 TransformTree& tree =
6982 host_impl()->active_tree()->property_trees()->transform_tree;
ennef6903532015-08-18 05:10:156983
ajuma737b2702015-05-06 01:18:376984 gfx::Transform expected_fixed_draw_transform;
6985 expected_fixed_draw_transform.Translate(10.f, 15.f);
ennef6903532015-08-18 05:10:156986 EXPECT_EQ(expected_fixed_draw_transform,
sunxdfd920f3f2016-04-05 16:17:516987 draw_property_utils::DrawTransform(fixed, tree));
ajuma0b10f942015-03-21 07:45:536988
ajuma737b2702015-05-06 01:18:376989 gfx::Transform expected_fixed_screen_space_transform;
6990 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
6991 EXPECT_EQ(expected_fixed_screen_space_transform,
sunxdfd920f3f2016-04-05 16:17:516992 draw_property_utils::ScreenSpaceTransform(fixed, tree));
ajuma737b2702015-05-06 01:18:376993
6994 gfx::Transform expected_child_draw_transform;
6995 expected_child_draw_transform.Translate(11.f, 17.f);
ennef6903532015-08-18 05:10:156996 EXPECT_EQ(expected_child_draw_transform,
sunxdfd920f3f2016-04-05 16:17:516997 draw_property_utils::DrawTransform(child, tree));
ajuma737b2702015-05-06 01:18:376998
6999 gfx::Transform expected_child_screen_space_transform;
7000 expected_child_screen_space_transform.Translate(18.f, 26.f);
7001 EXPECT_EQ(expected_child_screen_space_transform,
sunxdfd920f3f2016-04-05 16:17:517002 draw_property_utils::ScreenSpaceTransform(child, tree));
ajuma0b10f942015-03-21 07:45:537003}
7004
[email protected]d81752b2013-10-25 08:32:237005TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
7006 // This test verifies that a scrolling layer that gets snapped to
7007 // integer coordinates doesn't move a fixed position child.
7008 //
7009 // + root
7010 // + container
7011 // + scroller
7012 // + fixed
7013 //
khushalsagarb64b360d2015-10-21 19:25:167014 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:457015 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567016 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167017 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567018 &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:237019 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:487020 std::unique_ptr<LayerImpl> root_ptr =
sunxdb7e79432016-03-09 21:13:427021 LayerImpl::Create(host_impl.active_tree(), 1);
7022 LayerImpl* root = root_ptr.get();
danakj60bc3bc2016-04-09 00:24:487023 std::unique_ptr<LayerImpl> container =
[email protected]d81752b2013-10-25 08:32:237024 LayerImpl::Create(host_impl.active_tree(), 2);
7025 LayerImpl* container_layer = container.get();
danakj60bc3bc2016-04-09 00:24:487026 std::unique_ptr<LayerImpl> scroller =
[email protected]d81752b2013-10-25 08:32:237027 LayerImpl::Create(host_impl.active_tree(), 3);
7028 LayerImpl* scroll_layer = scroller.get();
danakj60bc3bc2016-04-09 00:24:487029 std::unique_ptr<LayerImpl> fixed =
7030 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]d81752b2013-10-25 08:32:237031 LayerImpl* fixed_layer = fixed.get();
7032
jaydasikaca2605e2016-04-23 02:52:527033 container->test_properties()->is_container_for_fixed_position_layers = true;
[email protected]d81752b2013-10-25 08:32:237034
7035 LayerPositionConstraint constraint;
7036 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:527037 fixed->test_properties()->position_constraint = constraint;
[email protected]d81752b2013-10-25 08:32:237038
[email protected]adeda572014-01-31 00:49:477039 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:237040
7041 gfx::Transform identity_transform;
7042 gfx::Transform container_transform;
7043 container_transform.Translate3d(10.0, 20.0, 0.0);
7044 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7045
sunxdb7e79432016-03-09 21:13:427046 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
awoloszyne83f28c2014-12-22 15:40:007047 gfx::PointF(), gfx::Size(50, 50), true, false,
7048 true);
7049 SetLayerPropertiesForTesting(container.get(), container_transform,
7050 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7051 true, false, false);
7052 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7053 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7054 true, false, false);
7055 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7056 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]d81752b2013-10-25 08:32:237057 false);
7058
jaydasika0d98ba92015-11-17 05:17:287059 root->SetDrawsContent(true);
7060 container->SetDrawsContent(true);
7061 scroller->SetDrawsContent(true);
7062 fixed->SetDrawsContent(true);
danakja04855a2015-11-18 20:39:107063 scroller->AddChild(std::move(fixed));
7064 container->AddChild(std::move(scroller));
7065 root->AddChild(std::move(container));
[email protected]d81752b2013-10-25 08:32:237066
7067 // Rounded to integers already.
7068 {
sunxdb7e79432016-03-09 21:13:427069 root->layer_tree_impl()->SetRootLayer(std::move(root_ptr));
jaydasika4340ea02016-06-06 19:44:267070 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
sunxdb7e79432016-03-09 21:13:427071
[email protected]d81752b2013-10-25 08:32:237072 gfx::Vector2dF scroll_delta(3.0, 5.0);
sunxdb7e79432016-03-09 21:13:427073 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:237074
7075 LayerImplList render_surface_layer_list;
7076 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:387077 root, root->bounds(), &render_surface_layer_list);
sunxdb7e79432016-03-09 21:13:427078 root->layer_tree_impl()
7079 ->property_trees()
7080 ->transform_tree.set_source_to_parent_updates_allowed(false);
sunxdb365de02016-04-28 20:32:577081 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:237082
7083 EXPECT_TRANSFORMATION_MATRIX_EQ(
7084 container_layer->draw_properties().screen_space_transform,
7085 fixed_layer->draw_properties().screen_space_transform);
7086 EXPECT_VECTOR_EQ(
7087 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7088 container_offset);
7089 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7090 .screen_space_transform.To2dTranslation(),
7091 container_offset - scroll_delta);
7092 }
7093
7094 // Scroll delta requiring rounding.
7095 {
jaydasika4340ea02016-06-06 19:44:267096 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
sunxdb7e79432016-03-09 21:13:427097
[email protected]d81752b2013-10-25 08:32:237098 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
sunxdb7e79432016-03-09 21:13:427099 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:237100
7101 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
7102
7103 LayerImplList render_surface_layer_list;
7104 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:387105 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:577106 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:237107
7108 EXPECT_TRANSFORMATION_MATRIX_EQ(
7109 container_layer->draw_properties().screen_space_transform,
7110 fixed_layer->draw_properties().screen_space_transform);
7111 EXPECT_VECTOR_EQ(
7112 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7113 container_offset);
7114 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7115 .screen_space_transform.To2dTranslation(),
7116 container_offset - rounded_scroll_delta);
7117 }
[email protected]cf15ad7b2014-04-02 03:59:267118
7119 // Scale is applied earlier in the tree.
7120 {
sunxdb7e79432016-03-09 21:13:427121 SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF());
[email protected]cf15ad7b2014-04-02 03:59:267122 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:287123 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
[email protected]cf15ad7b2014-04-02 03:59:267124 container_layer->SetTransform(scaled_container_transform);
jaydasika0d98ba92015-11-17 05:17:287125 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika4340ea02016-06-06 19:44:267126 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting();
[email protected]cf15ad7b2014-04-02 03:59:267127
7128 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
sunxdb7e79432016-03-09 21:13:427129 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]cf15ad7b2014-04-02 03:59:267130
7131 LayerImplList render_surface_layer_list;
7132 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:387133 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:577134 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]cf15ad7b2014-04-02 03:59:267135
7136 EXPECT_TRANSFORMATION_MATRIX_EQ(
7137 container_layer->draw_properties().screen_space_transform,
7138 fixed_layer->draw_properties().screen_space_transform);
7139 EXPECT_VECTOR_EQ(
7140 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7141 container_offset);
7142
7143 container_layer->SetTransform(container_transform);
7144 }
[email protected]d81752b2013-10-25 08:32:237145}
7146
miletus2c78036b2015-01-29 20:52:377147TEST_F(LayerTreeHostCommonTest,
ajuma5e8e40d2015-07-31 01:50:507148 ScrollSnappingWithAnimatedScreenSpaceTransform) {
7149 // This test verifies that a scrolling layer whose screen space transform is
7150 // animating doesn't get snapped to integer coordinates.
7151 //
7152 // + root
7153 // + animated layer
7154 // + surface
7155 // + container
7156 // + scroller
7157 //
7158 LayerImpl* root = root_layer();
7159 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
7160 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
7161 LayerImpl* container = AddChild<LayerImpl>(surface);
7162 LayerImpl* scroller = AddChild<LayerImpl>(container);
7163 scroller->SetScrollClipLayer(container->id());
7164 scroller->SetDrawsContent(true);
7165
7166 gfx::Transform identity_transform;
7167 gfx::Transform start_scale;
7168 start_scale.Scale(1.5f, 1.5f);
7169 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
7170 gfx::PointF(), gfx::Size(50, 50), true, false,
7171 true);
7172 SetLayerPropertiesForTesting(animated_layer, start_scale, gfx::Point3F(),
7173 gfx::PointF(), gfx::Size(50, 50), true, false,
7174 false);
7175 SetLayerPropertiesForTesting(surface, identity_transform, gfx::Point3F(),
7176 gfx::PointF(), gfx::Size(50, 50), true, false,
7177 true);
7178 SetLayerPropertiesForTesting(container, identity_transform, gfx::Point3F(),
7179 gfx::PointF(), gfx::Size(50, 50), true, false,
7180 false);
7181 SetLayerPropertiesForTesting(scroller, identity_transform, gfx::Point3F(),
7182 gfx::PointF(), gfx::Size(100, 100), true, false,
7183 false);
7184
7185 gfx::Transform end_scale;
7186 end_scale.Scale(2.f, 2.f);
7187 TransformOperations start_operations;
7188 start_operations.AppendMatrix(start_scale);
7189 TransformOperations end_operations;
7190 end_operations.AppendMatrix(end_scale);
loyso9556c732016-03-11 07:54:587191 AddAnimatedTransformToLayerWithPlayer(animated_layer->id(), timeline_impl(),
7192 1.0, start_operations, end_operations);
ajuma5e8e40d2015-07-31 01:50:507193 gfx::Vector2dF scroll_delta(5.f, 9.f);
sunxdb7e79432016-03-09 21:13:427194 SetScrollOffsetDelta(scroller, scroll_delta);
ajuma5e8e40d2015-07-31 01:50:507195
7196 ExecuteCalculateDrawProperties(root);
7197
7198 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
7199 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:447200 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:507201}
7202
[email protected]1c3626e2014-04-09 17:49:227203class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7204 public:
danakj60bc3bc2016-04-09 00:24:487205 static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
[email protected]1c3626e2014-04-09 17:49:227206 LayerTreeImpl* tree_impl,
7207 int id) {
danakj60bc3bc2016-04-09 00:24:487208 return base::WrapUnique(
[email protected]1c3626e2014-04-09 17:49:227209 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7210 }
7211
dcheng716bedf2014-10-21 09:51:087212 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227213
[email protected]1c3626e2014-04-09 17:49:227214 private:
7215 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7216 int id)
[email protected]a57cb8b12014-06-13 18:15:377217 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227218 SetDrawsContent(true);
7219 }
[email protected]1c3626e2014-04-09 17:49:227220};
7221
7222TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:167223 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]1c3626e2014-04-09 17:49:227224 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567225 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:487226 LayerTreeSettings settings = host()->settings();
ajumab4a846f22015-08-24 19:13:447227 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167228 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7229 &shared_bitmap_manager, &task_graph_runner);
[email protected]1c3626e2014-04-09 17:49:227230 gfx::Transform identity_matrix;
danakj60bc3bc2016-04-09 00:24:487231 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
[email protected]1c3626e2014-04-09 17:49:227232 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487233 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
[email protected]1c3626e2014-04-09 17:49:227234 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:487235 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child =
[email protected]1c3626e2014-04-09 17:49:227236 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:487237 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
[email protected]1c3626e2014-04-09 17:49:227238 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7239
7240 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7241 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7242 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
jaydasika2411692c2016-03-23 01:56:097243 AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get();
[email protected]1c3626e2014-04-09 17:49:227244
danakja04855a2015-11-18 20:39:107245 child->AddChild(std::move(grand_child));
7246 parent->AddChild(std::move(child));
7247 grand_parent->AddChild(std::move(parent));
[email protected]1c3626e2014-04-09 17:49:227248
jaydasika2411692c2016-03-23 01:56:097249 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
awoloszyne83f28c2014-12-22 15:40:007250 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7251 true, false, true);
7252 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7253 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227254 false);
awoloszyne83f28c2014-12-22 15:40:007255 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7256 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227257 false);
awoloszyne83f28c2014-12-22 15:40:007258
7259 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
7260 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227261 false);
7262
sunxd71aea3e2016-04-01 23:48:057263 host_impl.active_tree()->SetRootLayer(std::move(grand_parent));
7264
jaydasika2411692c2016-03-23 01:56:097265 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227266
7267 // No layers have animations.
jaydasika2411692c2016-03-23 01:56:097268 EXPECT_EQ(
7269 0.f,
7270 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377271 EXPECT_EQ(0.f,
7272 parent_raw->draw_properties().maximum_animation_contents_scale);
7273 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7274 EXPECT_EQ(
7275 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227276
jaydasika2411692c2016-03-23 01:56:097277 EXPECT_EQ(
7278 0.f,
7279 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037280 EXPECT_EQ(0.f,
7281 parent_raw->draw_properties().starting_animation_contents_scale);
7282 EXPECT_EQ(0.f,
7283 child_raw->draw_properties().starting_animation_contents_scale);
7284 EXPECT_EQ(
7285 0.f,
7286 grand_child_raw->draw_properties().starting_animation_contents_scale);
7287
[email protected]1c3626e2014-04-09 17:49:227288 TransformOperations translation;
7289 translation.AppendTranslate(1.f, 2.f, 3.f);
7290
loyso968163c92016-01-04 23:18:487291 scoped_refptr<AnimationTimeline> timeline;
loyso9556c732016-03-11 07:54:587292 timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7293 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487294
loyso9556c732016-03-11 07:54:587295 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7296 TransformOperations(), translation);
[email protected]1c3626e2014-04-09 17:49:227297
7298 // No layers have scale-affecting animations.
jaydasika2411692c2016-03-23 01:56:097299 EXPECT_EQ(
7300 0.f,
7301 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377302 EXPECT_EQ(0.f,
7303 parent_raw->draw_properties().maximum_animation_contents_scale);
7304 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7305 EXPECT_EQ(
7306 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227307
jaydasika2411692c2016-03-23 01:56:097308 EXPECT_EQ(
7309 0.f,
7310 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037311 EXPECT_EQ(0.f,
7312 parent_raw->draw_properties().starting_animation_contents_scale);
7313 EXPECT_EQ(0.f,
7314 child_raw->draw_properties().starting_animation_contents_scale);
7315 EXPECT_EQ(
7316 0.f,
7317 grand_child_raw->draw_properties().starting_animation_contents_scale);
7318
[email protected]1c3626e2014-04-09 17:49:227319 TransformOperations scale;
7320 scale.AppendScale(5.f, 4.f, 3.f);
7321
loyso9556c732016-03-11 07:54:587322 AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0,
7323 TransformOperations(), scale);
ajumacaaa9b32015-08-04 15:55:297324 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097325 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227326
7327 // Only |child| has a scale-affecting animation.
jaydasika2411692c2016-03-23 01:56:097328 EXPECT_EQ(
7329 0.f,
7330 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377331 EXPECT_EQ(0.f,
7332 parent_raw->draw_properties().maximum_animation_contents_scale);
7333 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
7334 EXPECT_EQ(
7335 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227336
jaydasika2411692c2016-03-23 01:56:097337 EXPECT_EQ(
7338 0.f,
7339 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037340 EXPECT_EQ(0.f,
7341 parent_raw->draw_properties().starting_animation_contents_scale);
7342 EXPECT_EQ(1.f,
7343 child_raw->draw_properties().starting_animation_contents_scale);
7344 EXPECT_EQ(
7345 1.f,
7346 grand_child_raw->draw_properties().starting_animation_contents_scale);
7347
jaydasika2411692c2016-03-23 01:56:097348 AddAnimatedTransformToLayerWithPlayer(grand_parent_raw->id(), timeline, 1.0,
loyso9556c732016-03-11 07:54:587349 TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:097350 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7351 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227352
7353 // |grand_parent| and |child| have scale-affecting animations.
jaydasika2411692c2016-03-23 01:56:097354 EXPECT_EQ(
7355 5.f,
7356 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377357 EXPECT_EQ(5.f,
7358 parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227359 // We don't support combining animated scales from two nodes; 0.f means
7360 // that the maximum scale could not be computed.
[email protected]a57cb8b12014-06-13 18:15:377361 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7362 EXPECT_EQ(
7363 0.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 1.f,
7367 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037368 EXPECT_EQ(1.f,
7369 parent_raw->draw_properties().starting_animation_contents_scale);
7370 EXPECT_EQ(0.f,
7371 child_raw->draw_properties().starting_animation_contents_scale);
7372 EXPECT_EQ(
7373 0.f,
7374 grand_child_raw->draw_properties().starting_animation_contents_scale);
7375
loyso9556c732016-03-11 07:54:587376 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7377 TransformOperations(), scale);
ajumacaaa9b32015-08-04 15:55:297378 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097379 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227380
7381 // |grand_parent|, |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(0.f,
7386 parent_raw->draw_properties().maximum_animation_contents_scale);
7387 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7388 EXPECT_EQ(
7389 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227390
jaydasika2411692c2016-03-23 01:56:097391 EXPECT_EQ(
7392 1.f,
7393 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037394 EXPECT_EQ(0.f,
7395 parent_raw->draw_properties().starting_animation_contents_scale);
7396 EXPECT_EQ(0.f,
7397 child_raw->draw_properties().starting_animation_contents_scale);
7398 EXPECT_EQ(
7399 0.f,
7400 grand_child_raw->draw_properties().starting_animation_contents_scale);
7401
jaydasika2411692c2016-03-23 01:56:097402 AbortAnimationsOnLayerWithPlayer(grand_parent_raw->id(), timeline,
loyso9556c732016-03-11 07:54:587403 TargetProperty::TRANSFORM);
7404 AbortAnimationsOnLayerWithPlayer(parent_raw->id(), timeline,
7405 TargetProperty::TRANSFORM);
7406 AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline,
7407 TargetProperty::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227408
7409 TransformOperations perspective;
7410 perspective.AppendPerspective(10.f);
7411
loyso9556c732016-03-11 07:54:587412 AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0,
7413 TransformOperations(), perspective);
ajumab4a846f22015-08-24 19:13:447414 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097415 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227416
7417 // |child| has a scale-affecting animation but computing the maximum of this
7418 // animation is not supported.
jaydasika2411692c2016-03-23 01:56:097419 EXPECT_EQ(
7420 0.f,
7421 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377422 EXPECT_EQ(0.f,
7423 parent_raw->draw_properties().maximum_animation_contents_scale);
7424 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7425 EXPECT_EQ(
7426 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227427
jaydasika2411692c2016-03-23 01:56:097428 EXPECT_EQ(
7429 0.f,
7430 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037431 EXPECT_EQ(0.f,
7432 parent_raw->draw_properties().starting_animation_contents_scale);
7433 EXPECT_EQ(0.f,
7434 child_raw->draw_properties().starting_animation_contents_scale);
7435 EXPECT_EQ(
7436 0.f,
7437 grand_child_raw->draw_properties().starting_animation_contents_scale);
7438
loyso9556c732016-03-11 07:54:587439 AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline,
7440 TargetProperty::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227441 gfx::Transform scale_matrix;
7442 scale_matrix.Scale(1.f, 2.f);
jaydasika2411692c2016-03-23 01:56:097443 grand_parent_raw->SetTransform(scale_matrix);
[email protected]1c3626e2014-04-09 17:49:227444 parent_raw->SetTransform(scale_matrix);
jaydasika2411692c2016-03-23 01:56:097445 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:487446
loyso9556c732016-03-11 07:54:587447 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7448 TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:097449 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227450
7451 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7452 // animation with maximum scale 5.f.
jaydasika2411692c2016-03-23 01:56:097453 EXPECT_EQ(
7454 0.f,
7455 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377456 EXPECT_EQ(10.f,
7457 parent_raw->draw_properties().maximum_animation_contents_scale);
7458 EXPECT_EQ(10.f,
7459 child_raw->draw_properties().maximum_animation_contents_scale);
7460 EXPECT_EQ(
7461 10.f,
7462 grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227463
jaydasika2411692c2016-03-23 01:56:097464 EXPECT_EQ(
7465 0.f,
7466 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037467 EXPECT_EQ(2.f,
7468 parent_raw->draw_properties().starting_animation_contents_scale);
7469 EXPECT_EQ(2.f,
7470 child_raw->draw_properties().starting_animation_contents_scale);
7471 EXPECT_EQ(
7472 2.f,
7473 grand_child_raw->draw_properties().starting_animation_contents_scale);
7474
[email protected]1c3626e2014-04-09 17:49:227475 gfx::Transform perspective_matrix;
7476 perspective_matrix.ApplyPerspectiveDepth(2.f);
7477 child_raw->SetTransform(perspective_matrix);
jaydasika2411692c2016-03-23 01:56:097478 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7479 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227480
7481 // |child| has a transform that's neither a translation nor a scale.
jaydasika2411692c2016-03-23 01:56:097482 EXPECT_EQ(
7483 0.f,
7484 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377485 EXPECT_EQ(10.f,
7486 parent_raw->draw_properties().maximum_animation_contents_scale);
7487 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7488 EXPECT_EQ(
7489 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227490
jaydasika2411692c2016-03-23 01:56:097491 EXPECT_EQ(
7492 0.f,
7493 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037494 EXPECT_EQ(2.f,
7495 parent_raw->draw_properties().starting_animation_contents_scale);
7496 EXPECT_EQ(0.f,
7497 child_raw->draw_properties().starting_animation_contents_scale);
7498 EXPECT_EQ(
7499 0.f,
7500 grand_child_raw->draw_properties().starting_animation_contents_scale);
7501
[email protected]1c3626e2014-04-09 17:49:227502 parent_raw->SetTransform(perspective_matrix);
jaydasika2411692c2016-03-23 01:56:097503 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7504 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227505
7506 // |parent| and |child| have transforms that are neither translations nor
7507 // scales.
jaydasika2411692c2016-03-23 01:56:097508 EXPECT_EQ(
7509 0.f,
7510 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377511 EXPECT_EQ(0.f,
7512 parent_raw->draw_properties().maximum_animation_contents_scale);
7513 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7514 EXPECT_EQ(
7515 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227516
jaydasika2411692c2016-03-23 01:56:097517 EXPECT_EQ(
7518 0.f,
7519 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037520 EXPECT_EQ(0.f,
7521 parent_raw->draw_properties().starting_animation_contents_scale);
7522 EXPECT_EQ(0.f,
7523 child_raw->draw_properties().starting_animation_contents_scale);
7524 EXPECT_EQ(
7525 0.f,
7526 grand_child_raw->draw_properties().starting_animation_contents_scale);
7527
[email protected]1c3626e2014-04-09 17:49:227528 parent_raw->SetTransform(identity_matrix);
7529 child_raw->SetTransform(identity_matrix);
jaydasika2411692c2016-03-23 01:56:097530 grand_parent_raw->SetTransform(perspective_matrix);
7531 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227532
jaydasika2411692c2016-03-23 01:56:097533 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227534
7535 // |grand_parent| has a transform that's neither a translation nor a scale.
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);
ajuma052892e2015-08-21 14:39:037544
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);
[email protected]1c3626e2014-04-09 17:49:227555}
7556
[email protected]390bb1ff2014-05-09 17:14:407557static void GatherDrawnLayers(LayerImplList* rsll,
7558 std::set<LayerImpl*>* drawn_layers) {
enne389d1a12015-06-18 20:40:517559 for (LayerIterator it = LayerIterator::Begin(rsll),
7560 end = LayerIterator::End(rsll);
7561 it != end; ++it) {
[email protected]390bb1ff2014-05-09 17:14:407562 LayerImpl* layer = *it;
7563 if (it.represents_itself())
7564 drawn_layers->insert(layer);
7565
7566 if (!it.represents_contributing_render_surface())
7567 continue;
7568
7569 if (layer->mask_layer())
7570 drawn_layers->insert(layer->mask_layer());
7571 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
7572 drawn_layers->insert(layer->replica_layer()->mask_layer());
7573 }
7574}
7575
7576TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:167577 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]390bb1ff2014-05-09 17:14:407578 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567579 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167580 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567581 &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:407582 gfx::Transform identity_matrix;
7583
danakj60bc3bc2016-04-09 00:24:487584 std::unique_ptr<LayerImpl> grand_parent =
[email protected]390bb1ff2014-05-09 17:14:407585 LayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487586 std::unique_ptr<LayerImpl> parent =
7587 LayerImpl::Create(host_impl.active_tree(), 3);
7588 std::unique_ptr<LayerImpl> child =
7589 LayerImpl::Create(host_impl.active_tree(), 5);
7590 std::unique_ptr<LayerImpl> grand_child1 =
[email protected]390bb1ff2014-05-09 17:14:407591 LayerImpl::Create(host_impl.active_tree(), 7);
danakj60bc3bc2016-04-09 00:24:487592 std::unique_ptr<LayerImpl> grand_child2 =
[email protected]390bb1ff2014-05-09 17:14:407593 LayerImpl::Create(host_impl.active_tree(), 9);
7594
7595 LayerImpl* grand_parent_raw = grand_parent.get();
7596 LayerImpl* parent_raw = parent.get();
7597 LayerImpl* child_raw = child.get();
7598 LayerImpl* grand_child1_raw = grand_child1.get();
7599 LayerImpl* grand_child2_raw = grand_child2.get();
7600
danakja04855a2015-11-18 20:39:107601 child->AddChild(std::move(grand_child1));
7602 child->AddChild(std::move(grand_child2));
7603 parent->AddChild(std::move(child));
7604 grand_parent->AddChild(std::move(parent));
jaydasika2411692c2016-03-23 01:56:097605 host_impl.active_tree()->SetRootLayer(std::move(grand_parent));
[email protected]390bb1ff2014-05-09 17:14:407606
awoloszyne83f28c2014-12-22 15:40:007607 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
7608 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7609 true, false, true);
7610 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7611 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:407612 false);
awoloszyne83f28c2014-12-22 15:40:007613
7614 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7615 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:407616 false);
awoloszyne83f28c2014-12-22 15:40:007617
7618 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
7619 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7620 true, false, false);
7621
7622 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
7623 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7624 true, false, false);
[email protected]390bb1ff2014-05-09 17:14:407625
7626 // Start with nothing being drawn.
7627 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407628
ajuma0adb5902016-04-28 16:32:387629 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7630 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7631 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7632 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7633 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407634
7635 std::set<LayerImpl*> expected;
7636 std::set<LayerImpl*> actual;
7637 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7638 EXPECT_EQ(expected, actual);
7639
7640 // If we force render surface, but none of the layers are in the layer list,
7641 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:007642 grand_child1_raw->SetHasRenderSurface(true);
jaydasikaebf9e4ea2015-08-14 21:29:127643 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407644
7645 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407646
ajuma0adb5902016-04-28 16:32:387647 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7648 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7649 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7650 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7651 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407652
7653 expected.clear();
7654 actual.clear();
7655 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7656 EXPECT_EQ(expected, actual);
7657
7658 // However, if we say that this layer also draws content, it will appear in
7659 // RSLL.
7660 grand_child1_raw->SetDrawsContent(true);
7661
7662 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407663
ajuma0adb5902016-04-28 16:32:387664 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7665 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7666 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7667 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7668 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407669
7670 expected.clear();
7671 expected.insert(grand_child1_raw);
7672
7673 actual.clear();
7674 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7675 EXPECT_EQ(expected, actual);
7676
7677 // Now child is forced to have a render surface, and one if its children draws
7678 // content.
7679 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:007680 grand_child1_raw->SetHasRenderSurface(false);
jaydasikaebf9e4ea2015-08-14 21:29:127681 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
awoloszyne83f28c2014-12-22 15:40:007682 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:407683 grand_child2_raw->SetDrawsContent(true);
7684
7685 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407686
ajuma0adb5902016-04-28 16:32:387687 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7688 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7689 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7690 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7691 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407692
7693 expected.clear();
7694 expected.insert(grand_child2_raw);
7695
7696 actual.clear();
7697 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7698 EXPECT_EQ(expected, actual);
7699
7700 // Add a mask layer to child.
danakja5a05ba02015-11-20 20:14:217701 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:047702 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407703
7704 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407705
ajuma0adb5902016-04-28 16:32:387706 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7707 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7708 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7709 EXPECT_TRUE(
7710 child_raw->mask_layer()->is_drawn_render_surface_layer_list_member());
7711 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7712 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407713
7714 expected.clear();
7715 expected.insert(grand_child2_raw);
7716 expected.insert(child_raw->mask_layer());
7717
7718 expected.clear();
7719 expected.insert(grand_child2_raw);
7720 expected.insert(child_raw->mask_layer());
7721
7722 actual.clear();
7723 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7724 EXPECT_EQ(expected, actual);
7725
7726 // Add replica mask layer.
danakj60bc3bc2016-04-09 00:24:487727 std::unique_ptr<LayerImpl> replica_layer =
[email protected]390bb1ff2014-05-09 17:14:407728 LayerImpl::Create(host_impl.active_tree(), 20);
7729 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
danakja04855a2015-11-18 20:39:107730 child_raw->SetReplicaLayer(std::move(replica_layer));
jaydasika23fb3822015-08-25 03:22:597731 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407732
7733 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407734
ajuma0adb5902016-04-28 16:32:387735 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7736 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7737 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7738 EXPECT_TRUE(
7739 child_raw->mask_layer()->is_drawn_render_surface_layer_list_member());
7740 EXPECT_TRUE(child_raw->replica_layer()
7741 ->mask_layer()
7742 ->is_drawn_render_surface_layer_list_member());
7743 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7744 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407745
7746 expected.clear();
7747 expected.insert(grand_child2_raw);
7748 expected.insert(child_raw->mask_layer());
7749 expected.insert(child_raw->replica_layer()->mask_layer());
7750
7751 actual.clear();
7752 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7753 EXPECT_EQ(expected, actual);
7754
7755 child_raw->TakeReplicaLayer();
7756
7757 // With nothing drawing, we should have no layers.
7758 grand_child2_raw->SetDrawsContent(false);
7759
7760 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407761
ajuma0adb5902016-04-28 16:32:387762 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7763 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7764 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7765 EXPECT_FALSE(
7766 child_raw->mask_layer()->is_drawn_render_surface_layer_list_member());
7767 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7768 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407769
7770 expected.clear();
7771 actual.clear();
7772 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7773 EXPECT_EQ(expected, actual);
7774
7775 // Child itself draws means that we should have the child and the mask in the
7776 // list.
7777 child_raw->SetDrawsContent(true);
7778
7779 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407780
ajuma0adb5902016-04-28 16:32:387781 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7782 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7783 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
7784 EXPECT_TRUE(
7785 child_raw->mask_layer()->is_drawn_render_surface_layer_list_member());
7786 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7787 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407788
7789 expected.clear();
7790 expected.insert(child_raw);
7791 expected.insert(child_raw->mask_layer());
7792 actual.clear();
7793 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7794 EXPECT_EQ(expected, actual);
7795
7796 child_raw->TakeMaskLayer();
jaydasikad36e7fa2015-07-14 15:15:047797 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407798
7799 // Now everyone's a member!
7800 grand_parent_raw->SetDrawsContent(true);
7801 parent_raw->SetDrawsContent(true);
7802 child_raw->SetDrawsContent(true);
7803 grand_child1_raw->SetDrawsContent(true);
7804 grand_child2_raw->SetDrawsContent(true);
7805
7806 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407807
ajuma0adb5902016-04-28 16:32:387808 EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7809 EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member());
7810 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
7811 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7812 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407813
7814 expected.clear();
7815 expected.insert(grand_parent_raw);
7816 expected.insert(parent_raw);
7817 expected.insert(child_raw);
7818 expected.insert(grand_child1_raw);
7819 expected.insert(grand_child2_raw);
7820
7821 actual.clear();
7822 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7823 EXPECT_EQ(expected, actual);
7824}
[email protected]18e69652014-06-13 12:50:587825
7826TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:167827 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]18e69652014-06-13 12:50:587828 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567829 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:487830 LayerTreeSettings settings = host()->settings();
enne637715732015-07-07 02:05:267831 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167832 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7833 &shared_bitmap_manager, &task_graph_runner);
[email protected]18e69652014-06-13 12:50:587834
danakj60bc3bc2016-04-09 00:24:487835 std::unique_ptr<LayerImpl> root =
7836 LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]18e69652014-06-13 12:50:587837 LayerImpl* root_layer = root.get();
danakj60bc3bc2016-04-09 00:24:487838 std::unique_ptr<LayerImpl> child1 =
7839 LayerImpl::Create(host_impl.active_tree(), 2);
[email protected]18e69652014-06-13 12:50:587840 LayerImpl* child1_layer = child1.get();
danakj60bc3bc2016-04-09 00:24:487841 std::unique_ptr<LayerImpl> child2 =
7842 LayerImpl::Create(host_impl.active_tree(), 3);
[email protected]18e69652014-06-13 12:50:587843 LayerImpl* child2_layer = child2.get();
7844
danakja04855a2015-11-18 20:39:107845 root->AddChild(std::move(child1));
7846 root->AddChild(std::move(child2));
jaydasika6b5a32bf2016-04-22 21:56:367847 root->test_properties()->force_render_surface = true;
jaydasika0d98ba92015-11-17 05:17:287848 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:097849 host_impl.active_tree()->SetRootLayer(std::move(root));
[email protected]18e69652014-06-13 12:50:587850
7851 gfx::Transform identity_matrix, scale_transform_child1,
7852 scale_transform_child2;
7853 scale_transform_child1.Scale(2, 3);
7854 scale_transform_child2.Scale(4, 5);
7855
awoloszyne83f28c2014-12-22 15:40:007856 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
7857 gfx::PointF(), gfx::Size(1, 1), true, false,
7858 true);
7859 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
jaydasika0d98ba92015-11-17 05:17:287860 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1),
7861 true, false, false);
[email protected]18e69652014-06-13 12:50:587862
danakja5a05ba02015-11-20 20:14:217863 child1_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4));
jaydasika0d98ba92015-11-17 05:17:287864 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587865
danakj60bc3bc2016-04-09 00:24:487866 std::unique_ptr<LayerImpl> replica_layer =
[email protected]18e69652014-06-13 12:50:587867 LayerImpl::Create(host_impl.active_tree(), 5);
7868 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
danakja04855a2015-11-18 20:39:107869 child1_layer->SetReplicaLayer(std::move(replica_layer));
awoloszyne83f28c2014-12-22 15:40:007870 child1_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:587871
7872 ExecuteCalculateDrawProperties(root_layer);
7873
7874 TransformOperations scale;
7875 scale.AppendScale(5.f, 8.f, 3.f);
7876
loyso9556c732016-03-11 07:54:587877 scoped_refptr<AnimationTimeline> timeline =
7878 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7879 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487880
loyso9556c732016-03-11 07:54:587881 AddAnimatedTransformToLayerWithPlayer(child2_layer->id(), timeline, 1.0,
7882 TransformOperations(), scale);
loyso968163c92016-01-04 23:18:487883
awoloszyne83f28c2014-12-22 15:40:007884 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
jaydasika0d98ba92015-11-17 05:17:287885 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1),
7886 true, false, false);
7887 child2_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587888
jaydasika2411692c2016-03-23 01:56:097889 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:587890 ExecuteCalculateDrawProperties(root_layer);
7891
enne637715732015-07-07 02:05:267892 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
7893 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
7894 EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale());
7895 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587896
7897 EXPECT_FLOAT_EQ(
7898 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7899 EXPECT_FLOAT_EQ(
7900 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7901 EXPECT_FLOAT_EQ(0.f,
7902 child1_layer->mask_layer()
7903 ->draw_properties()
7904 .maximum_animation_contents_scale);
7905 EXPECT_FLOAT_EQ(0.f,
7906 child1_layer->replica_layer()
7907 ->mask_layer()
7908 ->draw_properties()
7909 .maximum_animation_contents_scale);
7910 EXPECT_FLOAT_EQ(
7911 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
7912
[email protected]18e69652014-06-13 12:50:587913 // Changing page-scale would affect ideal_contents_scale and
7914 // maximum_animation_contents_scale.
7915
7916 float page_scale_factor = 3.f;
7917 float device_scale_factor = 1.0f;
7918 std::vector<LayerImpl*> render_surface_layer_list;
7919 gfx::Size device_viewport_size =
7920 gfx::Size(root_layer->bounds().width() * device_scale_factor,
7921 root_layer->bounds().height() * device_scale_factor);
7922 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:387923 root_layer, device_viewport_size, &render_surface_layer_list);
[email protected]18e69652014-06-13 12:50:587924
7925 inputs.page_scale_factor = page_scale_factor;
7926 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:117927 inputs.page_scale_layer = root_layer;
sunxdb365de02016-04-28 20:32:577928 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:587929
enne637715732015-07-07 02:05:267930 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
7931 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
7932 EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587933 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267934 9.f,
7935 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
7936 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587937
7938 EXPECT_FLOAT_EQ(
7939 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7940 EXPECT_FLOAT_EQ(
7941 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7942 EXPECT_FLOAT_EQ(0.f,
7943 child1_layer->mask_layer()
7944 ->draw_properties()
7945 .maximum_animation_contents_scale);
7946 EXPECT_FLOAT_EQ(0.f,
7947 child1_layer->replica_layer()
7948 ->mask_layer()
7949 ->draw_properties()
7950 .maximum_animation_contents_scale);
7951 EXPECT_FLOAT_EQ(
7952 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
7953
[email protected]18e69652014-06-13 12:50:587954 // Changing device-scale would affect ideal_contents_scale and
7955 // maximum_animation_contents_scale.
7956
7957 device_scale_factor = 4.0f;
7958 inputs.device_scale_factor = device_scale_factor;
7959 inputs.can_adjust_raster_scales = true;
jaydasika2411692c2016-03-23 01:56:097960 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:577961 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:587962
enne637715732015-07-07 02:05:267963 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
7964 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
7965 EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587966 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267967 36.f,
7968 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
7969 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587970
7971 EXPECT_FLOAT_EQ(
7972 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7973 EXPECT_FLOAT_EQ(
7974 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7975 EXPECT_FLOAT_EQ(0.f,
7976 child1_layer->mask_layer()
7977 ->draw_properties()
7978 .maximum_animation_contents_scale);
7979 EXPECT_FLOAT_EQ(0.f,
7980 child1_layer->replica_layer()
7981 ->mask_layer()
7982 ->draw_properties()
7983 .maximum_animation_contents_scale);
7984 EXPECT_FLOAT_EQ(
7985 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
[email protected]18e69652014-06-13 12:50:587986}
7987
danakjf6069db2014-09-13 00:46:477988TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
jaydasika6f972de2016-04-07 16:16:147989 LayerImpl* root = root_layer();
7990 LayerImpl* clip = AddChild<LayerImpl>(root);
7991 LayerImpl* content = AddChild<LayerImpl>(clip);
danakjf6069db2014-09-13 00:46:477992
jaydasika6f972de2016-04-07 16:16:147993 const gfx::Transform identity_matrix;
7994 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
7995 gfx::PointF(), gfx::Size(768 / 2, 3000), true,
7996 false, true);
7997 SetLayerPropertiesForTesting(clip, identity_matrix, gfx::Point3F(),
7998 gfx::PointF(), gfx::Size(768 / 2, 10000), true,
7999 false, false);
8000 SetLayerPropertiesForTesting(content, identity_matrix, gfx::Point3F(),
8001 gfx::PointF(), gfx::Size(768 / 2, 10000), true,
8002 false, true);
8003 root->SetDrawsContent(true);
danakjf6069db2014-09-13 00:46:478004 clip->SetMasksToBounds(true);
jaydasika6f972de2016-04-07 16:16:148005 content->SetDrawsContent(true);
danakjf6069db2014-09-13 00:46:478006
8007 gfx::Size device_viewport_size(768, 582);
jaydasika6f972de2016-04-07 16:16:148008 LayerImplList render_surface_layer_list_impl;
jaydasika6f972de2016-04-07 16:16:148009 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8010 root, device_viewport_size, identity_matrix,
ajuma0adb5902016-04-28 16:32:388011 &render_surface_layer_list_impl);
danakjf6069db2014-09-13 00:46:478012 inputs.device_scale_factor = 2.f;
8013 inputs.page_scale_factor = 1.f;
enne6394d5b42015-05-26 22:23:118014 inputs.page_scale_layer = NULL;
sunxdb365de02016-04-28 20:32:578015 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakjf6069db2014-09-13 00:46:478016
8017 // Layers in the root render surface have their visible content rect clipped
8018 // by the viewport.
jaydasika6f972de2016-04-07 16:16:148019 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478020
8021 // Layers drawing to a child render surface should still have their visible
8022 // content rect clipped by the viewport.
jaydasika6f972de2016-04-07 16:16:148023 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect());
danakjf6069db2014-09-13 00:46:478024}
8025
timav599f4359d2014-12-05 00:12:228026TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:168027 FakeImplTaskRunnerProvider task_runner_provider;
timav599f4359d2014-12-05 00:12:228028 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:568029 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:168030 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:568031 &task_graph_runner);
timav599f4359d2014-12-05 00:12:228032
8033 // Set two layers: the root layer clips it's child,
8034 // the child draws its content.
8035
8036 gfx::Size root_size = gfx::Size(300, 500);
8037
8038 // Sublayer should be bigger than the root enlarged by bounds_delta.
8039 gfx::Size sublayer_size = gfx::Size(300, 1000);
8040
8041 // Device viewport accomidated the root and the top controls.
8042 gfx::Size device_viewport_size = gfx::Size(300, 600);
8043 gfx::Transform identity_matrix;
8044
miletus8bd08a622015-06-16 18:44:528045 host_impl.SetViewportSize(device_viewport_size);
timav599f4359d2014-12-05 00:12:228046 host_impl.active_tree()->SetRootLayer(
8047 LayerImpl::Create(host_impl.active_tree(), 1));
8048
8049 LayerImpl* root = host_impl.active_tree()->root_layer();
8050 SetLayerPropertiesForTesting(root,
8051 identity_matrix,
8052 gfx::Point3F(),
8053 gfx::PointF(),
8054 root_size,
8055 false,
awoloszyne83f28c2014-12-22 15:40:008056 false,
8057 true);
timav599f4359d2014-12-05 00:12:228058 root->SetMasksToBounds(true);
8059
8060 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
8061
8062 LayerImpl* sublayer = root->child_at(0);
8063 SetLayerPropertiesForTesting(sublayer,
8064 identity_matrix,
8065 gfx::Point3F(),
8066 gfx::PointF(),
8067 sublayer_size,
8068 false,
awoloszyne83f28c2014-12-22 15:40:008069 false,
timav599f4359d2014-12-05 00:12:228070 false);
timav599f4359d2014-12-05 00:12:228071 sublayer->SetDrawsContent(true);
8072
8073 LayerImplList layer_impl_list;
8074 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:388075 root, device_viewport_size, &layer_impl_list);
timav599f4359d2014-12-05 00:12:228076
sunxdb365de02016-04-28 20:32:578077 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakj64767d902015-06-19 00:10:438078 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228079
8080 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
sunxdb365de02016-04-28 20:32:578081 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
timav599f4359d2014-12-05 00:12:228082
8083 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8084 root_size.height() + 50);
danakj64767d902015-06-19 00:10:438085 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:228086}
8087
ajumadd2802e72015-06-30 20:28:298088TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
loyso0940d412016-03-14 01:30:318089 scoped_refptr<Layer> root = Layer::Create();
8090 scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create();
8091 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create();
8092 scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create();
8093 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298094
8095 root->AddChild(inner_viewport_container_layer);
8096 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
8097 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
8098 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
8099
8100 inner_viewport_scroll_layer->SetScrollClipLayerId(
8101 inner_viewport_container_layer->id());
8102 outer_viewport_scroll_layer->SetScrollClipLayerId(
8103 outer_viewport_container_layer->id());
8104
8105 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8106 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8107
8108 host()->SetRootLayer(root);
8109 host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer,
8110 outer_viewport_scroll_layer);
8111
loyso0940d412016-03-14 01:30:318112 scoped_refptr<Layer> fixed_to_inner = Layer::Create();
8113 scoped_refptr<Layer> fixed_to_outer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298114
8115 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
8116 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
8117
8118 LayerPositionConstraint fixed_to_right;
8119 fixed_to_right.set_is_fixed_position(true);
8120 fixed_to_right.set_is_fixed_to_right_edge(true);
8121
8122 fixed_to_inner->SetPositionConstraint(fixed_to_right);
8123 fixed_to_outer->SetPositionConstraint(fixed_to_right);
8124
8125 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8126
8127 TransformTree& transform_tree = host()->property_trees()->transform_tree;
8128 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8129 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8130
8131 LayerPositionConstraint fixed_to_left;
8132 fixed_to_left.set_is_fixed_position(true);
8133 fixed_to_inner->SetPositionConstraint(fixed_to_left);
8134
8135 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8136 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8137 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8138
8139 fixed_to_outer->SetPositionConstraint(fixed_to_left);
8140
8141 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8142 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8143 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8144}
8145
vollick7d83b452015-02-24 20:18:068146TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
8147 const gfx::Transform identity_matrix;
loyso0940d412016-03-14 01:30:318148 scoped_refptr<Layer> root = Layer::Create();
vollick7d83b452015-02-24 20:18:068149 scoped_refptr<LayerWithForcedDrawsContent> animated =
loyso0940d412016-03-14 01:30:318150 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick7d83b452015-02-24 20:18:068151
8152 root->AddChild(animated);
8153
ennea7b43c32015-06-18 20:01:338154 host()->SetRootLayer(root);
vollick7d83b452015-02-24 20:18:068155
8156 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8157 gfx::PointF(), gfx::Size(100, 100), true, false);
8158 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
8159 gfx::PointF(), gfx::Size(20, 20), true, false);
8160
8161 root->SetMasksToBounds(true);
jaydasika6b5a32bf2016-04-22 21:56:368162 root->SetForceRenderSurfaceForTesting(true);
vollick7d83b452015-02-24 20:18:068163 animated->SetOpacity(0.f);
8164
loyso9556c732016-03-11 07:54:588165 AddOpacityTransitionToLayerWithPlayer(animated->id(), timeline(), 10.0, 0.f,
8166 1.f, false);
enne601f2ef12015-05-19 18:20:178167 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick7d83b452015-02-24 20:18:068168
jaydasika74bf516f2016-04-01 19:48:158169 EXPECT_FALSE(animated->visible_layer_rect_for_testing().IsEmpty());
vollick7d83b452015-02-24 20:18:068170}
8171
ajumaa92fdc12015-03-31 22:47:418172TEST_F(LayerTreeHostCommonTest,
8173 VisibleContentRectForAnimatedLayerWithSingularTransform) {
8174 const gfx::Transform identity_matrix;
loyso0940d412016-03-14 01:30:318175 scoped_refptr<Layer> root = Layer::Create();
8176 scoped_refptr<Layer> clip = Layer::Create();
ajumaa92fdc12015-03-31 22:47:418177 scoped_refptr<LayerWithForcedDrawsContent> animated =
loyso0940d412016-03-14 01:30:318178 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaa92fdc12015-03-31 22:47:418179 scoped_refptr<LayerWithForcedDrawsContent> surface =
loyso0940d412016-03-14 01:30:318180 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaa92fdc12015-03-31 22:47:418181 scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation =
loyso0940d412016-03-14 01:30:318182 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaa92fdc12015-03-31 22:47:418183
8184 root->AddChild(clip);
8185 clip->AddChild(animated);
8186 animated->AddChild(surface);
8187 surface->AddChild(descendant_of_animation);
8188
8189 clip->SetMasksToBounds(true);
jaydasika6b5a32bf2016-04-22 21:56:368190 surface->SetForceRenderSurfaceForTesting(true);
ajumaa92fdc12015-03-31 22:47:418191
ennea7b43c32015-06-18 20:01:338192 host()->SetRootLayer(root);
ajumaa92fdc12015-03-31 22:47:418193
8194 gfx::Transform uninvertible_matrix;
8195 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
8196
8197 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8198 gfx::PointF(), gfx::Size(100, 100), true, false);
8199 SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(),
8200 gfx::PointF(), gfx::Size(10, 10), true, false);
8201 SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix,
8202 gfx::Point3F(), gfx::PointF(),
8203 gfx::Size(120, 120), true, false);
8204 SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(),
8205 gfx::PointF(), gfx::Size(100, 100), true, false);
8206 SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix,
8207 gfx::Point3F(), gfx::PointF(),
8208 gfx::Size(200, 200), true, false);
8209
8210 TransformOperations start_transform_operations;
8211 start_transform_operations.AppendMatrix(uninvertible_matrix);
8212 TransformOperations end_transform_operations;
8213
loyso9556c732016-03-11 07:54:588214 AddAnimatedTransformToLayerWithPlayer(animated->id(), timeline(), 10.0,
8215 start_transform_operations,
8216 end_transform_operations);
enne601f2ef12015-05-19 18:20:178217 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:418218
8219 // The animated layer has a singular transform and maps to a non-empty rect in
8220 // clipped target space, so is treated as fully visible.
jaydasika74bf516f2016-04-01 19:48:158221 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:418222
8223 // The singular transform on |animated| is flattened when inherited by
8224 // |surface|, and this happens to make it invertible.
jaydasika74bf516f2016-04-01 19:48:158225 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect_for_testing());
8226 EXPECT_EQ(gfx::Rect(2, 2),
8227 descendant_of_animation->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:418228
8229 gfx::Transform zero_matrix;
8230 zero_matrix.Scale3d(0.f, 0.f, 0.f);
8231 SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(),
8232 gfx::PointF(), gfx::Size(120, 120), true, false);
8233
enne601f2ef12015-05-19 18:20:178234 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:418235
8236 // The animated layer maps to the empty rect in clipped target space, so is
8237 // treated as having an empty visible rect.
jaydasika74bf516f2016-04-01 19:48:158238 EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:418239
8240 // This time, flattening does not make |animated|'s transform invertible. This
8241 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:348242 // |surface| and layers that draw into it as having empty visible rect.
jaydasika74bf516f2016-04-01 19:48:158243 EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect_for_testing());
8244 EXPECT_EQ(gfx::Rect(),
8245 descendant_of_animation->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:418246}
8247
enne92f2f6d92015-02-25 23:13:318248// Verify that having an animated filter (but no current filter, as these
8249// are mutually exclusive) correctly creates a render surface.
8250TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
ajuma4711f4b12016-05-16 18:48:328251 LayerImpl* root = root_layer();
8252 LayerImpl* child = AddChild<LayerImpl>(root);
8253 LayerImpl* grandchild = AddChild<LayerImpl>(child);
enne92f2f6d92015-02-25 23:13:318254
8255 gfx::Transform identity_transform;
ajuma4711f4b12016-05-16 18:48:328256 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
enne92f2f6d92015-02-25 23:13:318257 gfx::PointF(), gfx::Size(50, 50), true, false);
ajuma4711f4b12016-05-16 18:48:328258 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
enne92f2f6d92015-02-25 23:13:318259 gfx::PointF(), gfx::Size(50, 50), true, false);
ajuma4711f4b12016-05-16 18:48:328260 SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(),
8261 gfx::PointF(), gfx::Size(50, 50), true, false);
enne92f2f6d92015-02-25 23:13:318262
ajuma4711f4b12016-05-16 18:48:328263 AddAnimatedFilterToLayerWithPlayer(child->id(), timeline_impl(), 10.0, 0.1f,
8264 0.2f);
8265 ExecuteCalculateDrawProperties(root);
enne92f2f6d92015-02-25 23:13:318266
ennec1332992015-08-24 19:45:098267 EXPECT_TRUE(root->has_render_surface());
8268 EXPECT_TRUE(child->has_render_surface());
8269 EXPECT_FALSE(grandchild->has_render_surface());
enne92f2f6d92015-02-25 23:13:318270
8271 EXPECT_TRUE(root->filters().IsEmpty());
8272 EXPECT_TRUE(child->filters().IsEmpty());
8273 EXPECT_TRUE(grandchild->filters().IsEmpty());
8274
8275 EXPECT_FALSE(root->FilterIsAnimating());
8276 EXPECT_TRUE(child->FilterIsAnimating());
8277 EXPECT_FALSE(grandchild->FilterIsAnimating());
8278}
8279
ajuma315a4782015-07-24 21:16:348280// Verify that having a filter animation with a delayed start time creates a
8281// render surface.
8282TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
ajuma4711f4b12016-05-16 18:48:328283 LayerImpl* root = root_layer();
8284 LayerImpl* child = AddChild<LayerImpl>(root);
8285 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma315a4782015-07-24 21:16:348286
8287 gfx::Transform identity_transform;
ajuma4711f4b12016-05-16 18:48:328288 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
ajuma315a4782015-07-24 21:16:348289 gfx::PointF(), gfx::Size(50, 50), true, false);
ajuma4711f4b12016-05-16 18:48:328290 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
ajuma315a4782015-07-24 21:16:348291 gfx::PointF(), gfx::Size(50, 50), true, false);
ajuma4711f4b12016-05-16 18:48:328292 SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(),
8293 gfx::PointF(), gfx::Size(50, 50), true, false);
ajuma315a4782015-07-24 21:16:348294
danakj60bc3bc2016-04-09 00:24:488295 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
ajuma315a4782015-07-24 21:16:348296 KeyframedFilterAnimationCurve::Create());
8297 FilterOperations start_filters;
8298 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
8299 FilterOperations end_filters;
8300 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
8301 curve->AddKeyframe(
8302 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
8303 curve->AddKeyframe(FilterKeyframe::Create(
8304 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
danakj60bc3bc2016-04-09 00:24:488305 std::unique_ptr<Animation> animation =
loyso0c8e4402016-02-25 04:12:308306 Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER);
loysoc255f272016-05-18 02:53:558307 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348308 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
ajuma315a4782015-07-24 21:16:348309
ajuma4711f4b12016-05-16 18:48:328310 AddAnimationToLayerWithPlayer(child->id(), timeline_impl(),
8311 std::move(animation));
8312 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:348313
ennec1332992015-08-24 19:45:098314 EXPECT_TRUE(root->has_render_surface());
8315 EXPECT_TRUE(child->has_render_surface());
8316 EXPECT_FALSE(grandchild->has_render_surface());
ajuma315a4782015-07-24 21:16:348317
8318 EXPECT_TRUE(root->filters().IsEmpty());
8319 EXPECT_TRUE(child->filters().IsEmpty());
8320 EXPECT_TRUE(grandchild->filters().IsEmpty());
8321
8322 EXPECT_FALSE(root->FilterIsAnimating());
8323 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
8324 EXPECT_FALSE(child->FilterIsAnimating());
8325 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
8326 EXPECT_FALSE(grandchild->FilterIsAnimating());
8327 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
8328}
8329
vollick0120eb22015-03-02 03:07:348330// Ensures that the property tree code accounts for offsets between fixed
8331// position layers and their respective containers.
8332TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
jaydasika6f972de2016-04-07 16:16:148333 LayerImpl* root = root_layer();
8334 LayerImpl* child = AddChild<LayerImpl>(root);
8335 LayerImpl* grandchild = AddChild<LayerImpl>(child);
vollick0120eb22015-03-02 03:07:348336
8337 gfx::Transform identity_transform;
jaydasika6f972de2016-04-07 16:16:148338 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
8339 gfx::PointF(), gfx::Size(50, 50), true, false,
8340 true);
8341 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
vollick0120eb22015-03-02 03:07:348342 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
jaydasika6f972de2016-04-07 16:16:148343 false, false);
8344 SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(),
8345 gfx::PointF(-1000, -1000), gfx::Size(50, 50),
8346 true, false, false);
vollick0120eb22015-03-02 03:07:348347
8348 root->SetMasksToBounds(true);
jaydasikaca2605e2016-04-23 02:52:528349 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick0120eb22015-03-02 03:07:348350 LayerPositionConstraint constraint;
8351 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528352 grandchild->test_properties()->position_constraint = constraint;
jaydasika6f972de2016-04-07 16:16:148353 grandchild->SetDrawsContent(true);
vollick0120eb22015-03-02 03:07:348354
jaydasikaca2605e2016-04-23 02:52:528355 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick0120eb22015-03-02 03:07:348356
jaydasika6f972de2016-04-07 16:16:148357 ExecuteCalculateDrawProperties(root);
vollick0120eb22015-03-02 03:07:348358
jaydasika6f972de2016-04-07 16:16:148359 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
vollick0120eb22015-03-02 03:07:348360}
8361
ajuma0178b522015-07-02 21:08:418362// Ensures that the property tree code accounts for offsets between fixed
8363// position containers and their transform tree parents, when a fixed position
8364// layer's container is its layer tree parent, but this parent doesn't have its
8365// own transform tree node.
8366TEST_F(LayerTreeHostCommonTest,
8367 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
jaydasika6f972de2016-04-07 16:16:148368 LayerImpl* root = root_layer();
8369 LayerImpl* child = AddChild<LayerImpl>(root);
8370 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma0178b522015-07-02 21:08:418371
8372 gfx::Transform identity_transform;
jaydasika6f972de2016-04-07 16:16:148373 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
8374 gfx::PointF(), gfx::Size(50, 50), true, false,
8375 true);
8376 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
ajuma0178b522015-07-02 21:08:418377 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
jaydasika6f972de2016-04-07 16:16:148378 false, false);
8379 SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(),
8380 gfx::PointF(-1000, -1000), gfx::Size(50, 50),
8381 true, false, false);
ajuma0178b522015-07-02 21:08:418382
8383 root->SetMasksToBounds(true);
jaydasikaca2605e2016-04-23 02:52:528384 child->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0178b522015-07-02 21:08:418385 LayerPositionConstraint constraint;
8386 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528387 grandchild->test_properties()->position_constraint = constraint;
jaydasika6f972de2016-04-07 16:16:148388 grandchild->SetDrawsContent(true);
ajuma0178b522015-07-02 21:08:418389
jaydasikaca2605e2016-04-23 02:52:528390 root->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0178b522015-07-02 21:08:418391
jaydasika6f972de2016-04-07 16:16:148392 ExecuteCalculateDrawProperties(root);
ajuma0178b522015-07-02 21:08:418393
jaydasika6f972de2016-04-07 16:16:148394 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
ajuma0178b522015-07-02 21:08:418395}
8396
vollick67394b42015-03-10 00:22:308397TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) {
8398 // In the following layer tree, the layer |box|'s render target is |surface|.
8399 // |surface| also creates a transform node. We want to combine clips for |box|
8400 // in the space of its target (i.e., |surface|), not its target's target. This
8401 // test ensures that happens.
8402
8403 gfx::Transform rotate;
8404 rotate.Rotate(5);
8405 gfx::Transform identity;
8406
loyso0940d412016-03-14 01:30:318407 scoped_refptr<Layer> root = Layer::Create();
vollick67394b42015-03-10 00:22:308408 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8409 gfx::PointF(), gfx::Size(2500, 1500), true,
8410 false);
8411
loyso0940d412016-03-14 01:30:318412 scoped_refptr<Layer> frame_clip = Layer::Create();
vollick67394b42015-03-10 00:22:308413 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8414 gfx::PointF(), gfx::Size(2500, 1500), true,
8415 false);
8416 frame_clip->SetMasksToBounds(true);
8417
loyso0940d412016-03-14 01:30:318418 scoped_refptr<Layer> rotated = Layer::Create();
vollick67394b42015-03-10 00:22:308419 SetLayerPropertiesForTesting(rotated.get(), rotate,
8420 gfx::Point3F(1250, 250, 0), gfx::PointF(),
8421 gfx::Size(2500, 500), true, false);
8422
loyso0940d412016-03-14 01:30:318423 scoped_refptr<Layer> surface = Layer::Create();
vollick67394b42015-03-10 00:22:308424 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(),
8425 gfx::PointF(), gfx::Size(2500, 500), true,
8426 false);
8427 surface->SetOpacity(0.5);
8428
8429 scoped_refptr<LayerWithForcedDrawsContent> container =
loyso0940d412016-03-14 01:30:318430 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick67394b42015-03-10 00:22:308431 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(),
8432 gfx::PointF(), gfx::Size(300, 300), true, false);
8433
8434 scoped_refptr<LayerWithForcedDrawsContent> box =
loyso0940d412016-03-14 01:30:318435 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick67394b42015-03-10 00:22:308436 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(),
8437 gfx::PointF(), gfx::Size(100, 100), true, false);
8438
8439 root->AddChild(frame_clip);
8440 frame_clip->AddChild(rotated);
8441 rotated->AddChild(surface);
8442 surface->AddChild(container);
8443 surface->AddChild(box);
8444
ennea7b43c32015-06-18 20:01:338445 host()->SetRootLayer(root);
vollick67394b42015-03-10 00:22:308446
8447 ExecuteCalculateDrawProperties(root.get());
8448}
8449
vollick8c824742015-03-20 22:21:088450TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
jaydasika6f972de2016-04-07 16:16:148451 LayerImpl* root = root_layer();
8452 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8453 LayerImpl* fixed = AddChild<LayerImpl>(frame_clip);
vollick8c824742015-03-20 22:21:088454 gfx::Transform identity;
8455 gfx::Transform translate_z;
8456 translate_z.Translate3d(0, 0, 10);
8457
jaydasika6f972de2016-04-07 16:16:148458 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
8459 gfx::Size(800, 800), true, false, true);
jaydasikaca2605e2016-04-23 02:52:528460 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick8c824742015-03-20 22:21:088461
jaydasika6f972de2016-04-07 16:16:148462 SetLayerPropertiesForTesting(frame_clip, translate_z, gfx::Point3F(),
vollick8c824742015-03-20 22:21:088463 gfx::PointF(500, 100), gfx::Size(100, 100), true,
jaydasika6f972de2016-04-07 16:16:148464 false, false);
vollick8c824742015-03-20 22:21:088465 frame_clip->SetMasksToBounds(true);
8466
jaydasika6f972de2016-04-07 16:16:148467 SetLayerPropertiesForTesting(fixed, identity, gfx::Point3F(), gfx::PointF(),
8468 gfx::Size(1000, 1000), true, false, false);
vollick8c824742015-03-20 22:21:088469
8470 LayerPositionConstraint constraint;
8471 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528472 fixed->test_properties()->position_constraint = constraint;
jaydasika6f972de2016-04-07 16:16:148473 fixed->SetDrawsContent(true);
vollick8c824742015-03-20 22:21:088474
jaydasika6f972de2016-04-07 16:16:148475 ExecuteCalculateDrawProperties(root);
vollick8c824742015-03-20 22:21:088476
8477 gfx::Rect expected(0, 0, 100, 100);
jaydasika6f972de2016-04-07 16:16:148478 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick8c824742015-03-20 22:21:088479}
8480
vollick06ca3e832015-03-31 19:37:128481TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
jaydasika6f972de2016-04-07 16:16:148482 LayerImpl* root = root_layer();
8483 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8484 LayerImpl* scroller = AddChild<LayerImpl>(frame_clip);
8485 LayerImpl* fixed = AddChild<LayerImpl>(scroller);
8486
vollick06ca3e832015-03-31 19:37:128487 gfx::Transform identity;
jaydasika6f972de2016-04-07 16:16:148488 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
8489 gfx::Size(800, 800), true, false, true);
8490 SetLayerPropertiesForTesting(frame_clip, identity, gfx::Point3F(),
vollick06ca3e832015-03-31 19:37:128491 gfx::PointF(500, 100), gfx::Size(100, 100), true,
jaydasika6f972de2016-04-07 16:16:148492 false, false);
8493 SetLayerPropertiesForTesting(scroller, identity, gfx::Point3F(),
vollick06ca3e832015-03-31 19:37:128494 gfx::PointF(), gfx::Size(1000, 1000), true,
jaydasika6f972de2016-04-07 16:16:148495 false, false);
8496 SetLayerPropertiesForTesting(fixed, identity, gfx::Point3F(),
vollick06ca3e832015-03-31 19:37:128497 gfx::PointF(100, 100), gfx::Size(50, 50), true,
jaydasika6f972de2016-04-07 16:16:148498 false, true);
8499
jaydasikaca2605e2016-04-23 02:52:528500 root->test_properties()->is_container_for_fixed_position_layers = true;
jaydasika6f972de2016-04-07 16:16:148501 root->SetDrawsContent(true);
8502
8503 frame_clip->SetMasksToBounds(true);
8504 frame_clip->SetDrawsContent(true);
8505
8506 scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100));
8507 scroller->SetScrollClipLayer(frame_clip->id());
8508 scroller->SetDrawsContent(true);
vollick06ca3e832015-03-31 19:37:128509
8510 LayerPositionConstraint constraint;
8511 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528512 fixed->test_properties()->position_constraint = constraint;
vollick06ca3e832015-03-31 19:37:128513 fixed->SetMasksToBounds(true);
jaydasika6f972de2016-04-07 16:16:148514 fixed->SetDrawsContent(true);
vollick06ca3e832015-03-31 19:37:128515
jaydasika6f972de2016-04-07 16:16:148516 ExecuteCalculateDrawProperties(root);
vollick06ca3e832015-03-31 19:37:128517
8518 gfx::Rect expected(0, 0, 50, 50);
jaydasika6f972de2016-04-07 16:16:148519 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick06ca3e832015-03-31 19:37:128520}
8521
vollick5057e1e2015-04-17 19:12:328522TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
8523 gfx::Transform identity;
8524 gfx::Transform translate;
8525 gfx::Transform rotate;
8526
8527 translate.Translate(10, 10);
8528 rotate.Rotate(45);
8529
loyso0940d412016-03-14 01:30:318530 scoped_refptr<Layer> root = Layer::Create();
vollick5057e1e2015-04-17 19:12:328531 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8532 gfx::PointF(), gfx::Size(800, 800), true, false);
8533 root->SetIsContainerForFixedPositionLayers(true);
8534
ennea7b43c32015-06-18 20:01:338535 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:328536
enne601f2ef12015-05-19 18:20:178537 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ennea7b43c32015-06-18 20:01:338538 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328539
8540 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:338541 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328542
8543 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:338544 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328545}
8546
ajumab0e0c1c2015-04-23 00:29:238547TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
jaydasika6f972de2016-04-07 16:16:148548 LayerImpl* root = root_layer();
8549 LayerImpl* child = AddChild<LayerImpl>(root);
ajumab0e0c1c2015-04-23 00:29:238550
8551 gfx::Transform identity_matrix;
8552 gfx::Transform scale_matrix;
8553 scale_matrix.Scale(2.f, 2.f);
jaydasika6f972de2016-04-07 16:16:148554 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
8555 gfx::PointF(), gfx::Size(100, 100), true, false,
8556 true);
8557 SetLayerPropertiesForTesting(child, scale_matrix, gfx::Point3F(),
8558 gfx::PointF(), gfx::Size(10, 10), true, false,
8559 false);
ajumab0e0c1c2015-04-23 00:29:238560
jaydasika6f972de2016-04-07 16:16:148561 root->SetDrawsContent(true);
8562 child->SetDrawsContent(true);
8563
8564 ExecuteCalculateDrawProperties(root);
8565 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238566
jaydasika38be7a822016-04-21 16:07:068567 child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f);
ajumab0e0c1c2015-04-23 00:29:238568
jaydasika6f972de2016-04-07 16:16:148569 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8570 ExecuteCalculateDrawProperties(root);
8571 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238572}
8573
ajumaf09db8962015-04-24 21:55:348574TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
jaydasika6f972de2016-04-07 16:16:148575 LayerImpl* root = root_layer();
8576 LayerImpl* scroll_parent = AddChild<LayerImpl>(root);
8577 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent);
ajumaf09db8962015-04-24 21:55:348578
jaydasika6f972de2016-04-07 16:16:148579 scroll_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:568580 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakj60bc3bc2016-04-09 00:24:488581 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
8582 new std::set<LayerImpl*>);
jaydasika6f972de2016-04-07 16:16:148583 scroll_children->insert(scroll_child);
jaydasika1c0a27d42016-04-28 01:54:568584 scroll_parent->test_properties()->scroll_children.reset(
8585 scroll_children.release());
jaydasika6f972de2016-04-07 16:16:148586 scroll_parent->SetDrawsContent(true);
ajumaf09db8962015-04-24 21:55:348587
8588 gfx::Transform identity_transform;
8589 gfx::Transform scale;
8590 scale.Scale(2.f, 2.f);
jaydasika6f972de2016-04-07 16:16:148591 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
8592 gfx::PointF(), gfx::Size(50, 50), true, false,
8593 true);
8594 SetLayerPropertiesForTesting(scroll_child, scale, gfx::Point3F(),
8595 gfx::PointF(), gfx::Size(40, 40), true, false,
8596 false);
8597 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
ajumaf09db8962015-04-24 21:55:348598 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
jaydasika6f972de2016-04-07 16:16:148599 true, false, false);
ajumaf09db8962015-04-24 21:55:348600
jaydasika6f972de2016-04-07 16:16:148601 ExecuteCalculateDrawProperties(root);
8602 EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348603
8604 scroll_child->SetPosition(gfx::PointF(0, -10.f));
jaydasika6f972de2016-04-07 16:16:148605 scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f));
8606 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8607 ExecuteCalculateDrawProperties(root);
8608 EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348609}
8610
danakj60bc3bc2016-04-09 00:24:488611static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
vollick2175fae82015-04-27 21:18:128612
sunxded58688e2016-01-11 21:01:028613TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) {
8614 // If the layer has a node in effect_tree, the return value of
8615 // num_copy_requests_in_target_subtree() must be equal to the actual number
8616 // of copy requests in the sub-layer_tree; Otherwise, the number is expected
8617 // to be the value of its nearest ancestor that owns an effect node and
8618 // greater than or equal to the actual number of copy requests in the
8619 // sub-layer_tree.
8620
loyso0940d412016-03-14 01:30:318621 scoped_refptr<Layer> root = Layer::Create();
8622 scoped_refptr<Layer> child1 = Layer::Create();
8623 scoped_refptr<Layer> child2 = Layer::Create();
8624 scoped_refptr<Layer> grandchild = Layer::Create();
8625 scoped_refptr<Layer> greatgrandchild = Layer::Create();
sunxded58688e2016-01-11 21:01:028626
8627 root->AddChild(child1);
8628 root->AddChild(child2);
8629 child1->AddChild(grandchild);
8630 grandchild->AddChild(greatgrandchild);
8631 host()->SetRootLayer(root);
8632
8633 child1->RequestCopyOfOutput(
8634 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8635 greatgrandchild->RequestCopyOfOutput(
8636 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8637 child2->SetOpacity(0.f);
8638 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8639
8640 EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2);
8641 EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2);
8642 EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0);
8643 EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2);
8644 EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1);
8645}
8646
vollick2175fae82015-04-27 21:18:128647TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
8648 gfx::Transform identity;
loyso0940d412016-03-14 01:30:318649 scoped_refptr<Layer> root = Layer::Create();
chrishtr01539b802015-11-24 08:11:328650 FakeContentLayerClient client;
8651 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:128652 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:318653 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick2175fae82015-04-27 21:18:128654 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loyso0940d412016-03-14 01:30:318655 make_scoped_refptr(new LayerWithForcedDrawsContent());
danakj4e95f7632015-06-05 19:46:258656 scoped_refptr<FakePictureLayer> greatgrandchild(
loyso0940d412016-03-14 01:30:318657 FakePictureLayer::Create(&client));
vollick2175fae82015-04-27 21:18:128658 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8659 gfx::PointF(), gfx::Size(100, 100), true, false);
8660 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8661 gfx::PointF(), gfx::Size(10, 10), true, false);
8662 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8663 gfx::PointF(), gfx::Size(10, 10), true, false);
8664 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
8665 gfx::PointF(), gfx::Size(10, 10), true, false);
8666
8667 root->AddChild(child);
8668 child->AddChild(grandchild);
8669 grandchild->AddChild(greatgrandchild);
8670
ennea7b43c32015-06-18 20:01:338671 host()->SetRootLayer(root);
vollick2175fae82015-04-27 21:18:128672
8673 // Check the non-skipped case.
enne601f2ef12015-05-19 18:20:178674 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158675 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128676
8677 // Now we will reset the visible rect from property trees for the grandchild,
8678 // and we will configure |child| in several ways that should force the subtree
8679 // to be skipped. The visible content rect for |grandchild| should, therefore,
8680 // remain empty.
weiliangcc97575c2016-03-03 18:34:278681 grandchild->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:128682 gfx::Transform singular;
8683 singular.matrix().set(0, 0, 0);
8684
8685 child->SetTransform(singular);
enne601f2ef12015-05-19 18:20:178686 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158687 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128688 child->SetTransform(identity);
8689
8690 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:178691 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158692 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128693 child->SetHideLayerAndSubtree(false);
8694
ajuma315a4782015-07-24 21:16:348695 gfx::Transform zero_z_scale;
8696 zero_z_scale.Scale3d(1, 1, 0);
8697 child->SetTransform(zero_z_scale);
8698
8699 // Add a transform animation with a start delay. Now, even though |child| has
8700 // a singular transform, the subtree should still get processed.
8701 int animation_id = 0;
danakj60bc3bc2016-04-09 00:24:488702 std::unique_ptr<Animation> animation = Animation::Create(
8703 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
loyso0c8e4402016-02-25 04:12:308704 animation_id, 1, TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:558705 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348706 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso9556c732016-03-11 07:54:588707 AddAnimationToLayerWithPlayer(child->id(), timeline(), std::move(animation));
ajuma315a4782015-07-24 21:16:348708 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158709 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
weiliangcc97575c2016-03-03 18:34:278710 grandchild->set_visible_layer_rect(gfx::Rect());
ajuma315a4782015-07-24 21:16:348711
loyso9556c732016-03-11 07:54:588712 RemoveAnimationFromLayerWithExistingPlayer(child->id(), timeline(),
8713 animation_id);
ajuma315a4782015-07-24 21:16:348714 child->SetTransform(identity);
vollick2175fae82015-04-27 21:18:128715 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:178716 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158717 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128718
8719 // Now, even though child has zero opacity, we will configure |grandchild| and
8720 // |greatgrandchild| in several ways that should force the subtree to be
8721 // processed anyhow.
jaydasika86654512016-01-27 17:05:078722 grandchild->RequestCopyOfOutput(
vollick2175fae82015-04-27 21:18:128723 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
enne601f2ef12015-05-19 18:20:178724 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158725 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
weiliangcc97575c2016-03-03 18:34:278726 greatgrandchild->set_visible_layer_rect(gfx::Rect());
ajuma315a4782015-07-24 21:16:348727
8728 // Add an opacity animation with a start delay.
8729 animation_id = 1;
8730 animation = Animation::Create(
danakj60bc3bc2016-04-09 00:24:488731 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
loyso0c8e4402016-02-25 04:12:308732 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:558733 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348734 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso9556c732016-03-11 07:54:588735 AddAnimationToLayerWithExistingPlayer(child->id(), timeline(),
8736 std::move(animation));
ajuma315a4782015-07-24 21:16:348737 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158738 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128739}
8740
sunxd71aea3e2016-04-01 23:48:058741TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:168742 FakeImplTaskRunnerProvider task_runner_provider;
vollick2175fae82015-04-27 21:18:128743 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:568744 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:168745 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:568746 &task_graph_runner);
vollick2175fae82015-04-27 21:18:128747
8748 gfx::Transform identity;
danakj60bc3bc2016-04-09 00:24:488749 std::unique_ptr<LayerImpl> root =
8750 LayerImpl::Create(host_impl.active_tree(), 1);
8751 std::unique_ptr<LayerImpl> child =
8752 LayerImpl::Create(host_impl.active_tree(), 2);
8753 std::unique_ptr<LayerImpl> grandchild =
vollick2175fae82015-04-27 21:18:128754 LayerImpl::Create(host_impl.active_tree(), 3);
8755
danakj60bc3bc2016-04-09 00:24:488756 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
danakj4e95f7632015-06-05 19:46:258757 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:128758
8759 child->SetDrawsContent(true);
8760 grandchild->SetDrawsContent(true);
8761 greatgrandchild->SetDrawsContent(true);
8762
8763 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8764 gfx::PointF(), gfx::Size(100, 100), true, false,
8765 true);
8766 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8767 gfx::PointF(), gfx::Size(10, 10), true, false,
8768 false);
8769 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8770 gfx::PointF(), gfx::Size(10, 10), true, false,
8771 false);
vollick2175fae82015-04-27 21:18:128772
jaydasika2411692c2016-03-23 01:56:098773 LayerImpl* root_ptr = root.get();
vollick2175fae82015-04-27 21:18:128774 LayerImpl* child_ptr = child.get();
8775 LayerImpl* grandchild_ptr = grandchild.get();
vollick2175fae82015-04-27 21:18:128776
danakja04855a2015-11-18 20:39:108777 child->AddChild(std::move(grandchild));
8778 root->AddChild(std::move(child));
jaydasika2411692c2016-03-23 01:56:098779 host_impl.active_tree()->SetRootLayer(std::move(root));
vollick2175fae82015-04-27 21:18:128780
8781 // Check the non-skipped case.
sunxd71aea3e2016-04-01 23:48:058782 // ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8783 // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128784
8785 // Now we will reset the visible rect from property trees for the grandchild,
8786 // and we will configure |child| in several ways that should force the subtree
8787 // to be skipped. The visible content rect for |grandchild| should, therefore,
8788 // remain empty.
weiliangcc97575c2016-03-03 18:34:278789 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
sunxd71aea3e2016-04-01 23:48:058790
vollick2175fae82015-04-27 21:18:128791 gfx::Transform singular;
8792 singular.matrix().set(0, 0, 0);
sunxd71aea3e2016-04-01 23:48:058793 // This line is used to make the results of skipping and not skipping layers
8794 // different.
8795 singular.matrix().set(0, 1, 1);
8796
8797 gfx::Transform rotate;
8798 rotate.Rotate(90);
8799
8800 gfx::Transform rotate_back_and_translate;
8801 rotate_back_and_translate.RotateAboutYAxis(180);
8802 rotate_back_and_translate.Translate(-10, 0);
vollick2175fae82015-04-27 21:18:128803
8804 child_ptr->SetTransform(singular);
sunxd71aea3e2016-04-01 23:48:058805 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:098806 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278807 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128808 child_ptr->SetTransform(identity);
8809
jaydasika5121caa82016-05-05 15:43:358810 child_ptr->test_properties()->hide_layer_and_subtree = true;
jaydasika2411692c2016-03-23 01:56:098811 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278812 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:358813 child_ptr->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:128814
jaydasikaab317e02016-06-01 00:53:188815 child_ptr->OnOpacityAnimated(0.f);
jaydasika2411692c2016-03-23 01:56:098816 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278817 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:188818 child_ptr->test_properties()->opacity = 1.f;
vollick2175fae82015-04-27 21:18:128819
sunxd71aea3e2016-04-01 23:48:058820 root_ptr->SetTransform(singular);
8821 // Force transform tree to have a node for child, so that ancestor's
8822 // invertible transform can be tested.
8823 child_ptr->SetTransform(rotate);
8824 host_impl.active_tree()->property_trees()->needs_rebuild = true;
8825 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8826 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
8827 root_ptr->SetTransform(identity);
8828 child_ptr->SetTransform(identity);
8829
jaydasikaab317e02016-06-01 00:53:188830 root_ptr->test_properties()->opacity = 0.f;
8831 child_ptr->test_properties()->opacity = 0.7f;
sunxd71aea3e2016-04-01 23:48:058832 host_impl.active_tree()->property_trees()->needs_rebuild = true;
8833 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8834 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasikaab317e02016-06-01 00:53:188835 root_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:058836
jaydasikaab317e02016-06-01 00:53:188837 child_ptr->test_properties()->opacity = 0.f;
vollick2175fae82015-04-27 21:18:128838 // Now, even though child has zero opacity, we will configure |grandchild| and
8839 // |greatgrandchild| in several ways that should force the subtree to be
8840 // processed anyhow.
ajumae6f541b2016-05-31 16:50:508841 grandchild_ptr->test_properties()->copy_requests.push_back(
8842 CopyOutputRequest::CreateEmptyRequest());
jaydasika2411692c2016-03-23 01:56:098843 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8844 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278845 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
ajumae6f541b2016-05-31 16:50:508846
8847 host_impl.active_tree()->property_trees()->effect_tree.ClearCopyRequests();
jaydasikaab317e02016-06-01 00:53:188848 child_ptr->test_properties()->opacity = 1.f;
sunxd71aea3e2016-04-01 23:48:058849
8850 // A double sided render surface with backface visible should not be skipped
8851 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
8852 child_ptr->SetHasRenderSurface(true);
jaydasika6b5a32bf2016-04-22 21:56:368853 child_ptr->test_properties()->double_sided = true;
sunxd71aea3e2016-04-01 23:48:058854 child_ptr->SetTransform(rotate_back_and_translate);
8855 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8856 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8857 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
8858 child_ptr->SetTransform(identity);
8859
danakj60bc3bc2016-04-09 00:24:488860 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:058861 KeyframedTransformAnimationCurve::Create());
8862 TransformOperations start;
8863 start.AppendTranslate(1.f, 2.f, 3.f);
8864 gfx::Transform transform;
8865 transform.Scale3d(1.0, 2.0, 3.0);
8866 TransformOperations operation;
8867 operation.AppendMatrix(transform);
8868 curve->AddKeyframe(
8869 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8870 curve->AddKeyframe(TransformKeyframe::Create(
8871 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj60bc3bc2016-04-09 00:24:488872 std::unique_ptr<Animation> transform_animation(
sunxd71aea3e2016-04-01 23:48:058873 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8874 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:588875 host_impl.active_tree()->animation_host()->RegisterPlayerForElement(
sunxd71aea3e2016-04-01 23:48:058876 root_ptr->id(), player.get());
8877 host_impl.active_tree()
8878 ->animation_host()
loysofb69174e2016-04-27 00:58:588879 ->GetElementAnimationsForElementId(root_ptr->id())
sunxd71aea3e2016-04-01 23:48:058880 ->AddAnimation(std::move(transform_animation));
8881 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
8882 child_ptr->SetScrollClipLayer(root_ptr->id());
8883 root_ptr->SetTransform(singular);
8884 child_ptr->SetTransform(singular);
8885 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8886 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
jaydasikaf187b06b2016-04-11 23:30:278887 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:058888
loysofb69174e2016-04-27 00:58:588889 host_impl.active_tree()->animation_host()->UnregisterPlayerForElement(
sunxd71aea3e2016-04-01 23:48:058890 root_ptr->id(), player.get());
8891}
8892
jaydasikaf187b06b2016-04-11 23:30:278893TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) {
8894 LayerImpl* root = root_layer();
8895 LayerImpl* child = AddChild<LayerImpl>(root);
8896 LayerImpl* grand_child = AddChild<LayerImpl>(child);
8897
8898 gfx::Transform identity;
8899 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
8900 gfx::Size(10, 10), true, false, true);
8901 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
8902 gfx::Size(10, 10), true, false, false);
8903 SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(),
8904 gfx::PointF(), gfx::Size(10, 10), true, false,
8905 false);
8906
8907 gfx::Transform singular;
8908 singular.matrix().set(0, 0, 0);
8909 singular.matrix().set(0, 1, 1);
8910
8911 child->SetTransform(singular);
8912 child->SetDrawsContent(true);
8913 grand_child->SetDrawsContent(true);
8914
danakj25c52c32016-04-12 21:51:088915 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
jaydasikaf187b06b2016-04-11 23:30:278916 KeyframedTransformAnimationCurve::Create());
8917 TransformOperations start;
8918 start.AppendTranslate(1.f, 2.f, 3.f);
8919 gfx::Transform transform;
8920 transform.Scale3d(1.0, 2.0, 3.0);
8921 TransformOperations operation;
8922 operation.AppendMatrix(transform);
8923 curve->AddKeyframe(
8924 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8925 curve->AddKeyframe(TransformKeyframe::Create(
8926 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj25c52c32016-04-12 21:51:088927 std::unique_ptr<Animation> transform_animation(
jaydasikaf187b06b2016-04-11 23:30:278928 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8929 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:588930 host_impl()->active_tree()->animation_host()->RegisterPlayerForElement(
jaydasikaf187b06b2016-04-11 23:30:278931 grand_child->id(), player.get());
8932 host_impl()
8933 ->active_tree()
8934 ->animation_host()
loysofb69174e2016-04-27 00:58:588935 ->GetElementAnimationsForElementId(grand_child->id())
jaydasikaf187b06b2016-04-11 23:30:278936 ->AddAnimation(std::move(transform_animation));
8937
8938 ExecuteCalculateDrawProperties(root);
8939 EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect());
8940 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
8941
loysofb69174e2016-04-27 00:58:588942 host_impl()->active_tree()->animation_host()->UnregisterPlayerForElement(
jaydasikaf187b06b2016-04-11 23:30:278943 grand_child->id(), player.get());
8944}
8945
sunxd71aea3e2016-04-01 23:48:058946TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
8947 FakeImplTaskRunnerProvider task_runner_provider;
8948 TestSharedBitmapManager shared_bitmap_manager;
8949 TestTaskGraphRunner task_graph_runner;
8950 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
8951 &task_graph_runner);
8952
8953 gfx::Transform identity;
8954 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:488955 std::unique_ptr<LayerImpl> root =
8956 LayerImpl::Create(host_impl.pending_tree(), 1);
8957 std::unique_ptr<LayerImpl> child =
8958 LayerImpl::Create(host_impl.pending_tree(), 2);
8959 std::unique_ptr<LayerImpl> grandchild =
sunxd71aea3e2016-04-01 23:48:058960 LayerImpl::Create(host_impl.pending_tree(), 3);
8961
danakj60bc3bc2016-04-09 00:24:488962 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
sunxd71aea3e2016-04-01 23:48:058963 FakePictureLayerImpl::Create(host_impl.pending_tree(), 4));
8964
8965 child->SetDrawsContent(true);
8966 grandchild->SetDrawsContent(true);
8967 greatgrandchild->SetDrawsContent(true);
8968
8969 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8970 gfx::PointF(), gfx::Size(100, 100), true, false,
8971 true);
8972 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8973 gfx::PointF(), gfx::Size(10, 10), true, false,
8974 false);
8975 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8976 gfx::PointF(), gfx::Size(10, 10), true, false,
8977 false);
8978
8979 LayerImpl* root_ptr = root.get();
8980 LayerImpl* grandchild_ptr = grandchild.get();
8981
8982 child->AddChild(std::move(grandchild));
8983 root->AddChild(std::move(child));
8984
8985 host_impl.pending_tree()->SetRootLayer(std::move(root));
8986
8987 // Check the non-skipped case.
8988 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8989 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
8990
danakj60bc3bc2016-04-09 00:24:488991 std::unique_ptr<KeyframedFloatAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:058992 KeyframedFloatAnimationCurve::Create());
loyso1e4e7ee2016-06-03 03:04:498993 std::unique_ptr<TimingFunction> func =
8994 CubicBezierTimingFunction::CreatePreset(
8995 CubicBezierTimingFunction::EaseType::EASE);
sunxd71aea3e2016-04-01 23:48:058996 curve->AddKeyframe(
8997 FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func)));
8998 curve->AddKeyframe(
8999 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr));
danakj60bc3bc2016-04-09 00:24:489000 std::unique_ptr<Animation> animation(
sunxd71aea3e2016-04-01 23:48:059001 Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY));
9002 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:589003 host_impl.active_tree()->animation_host()->RegisterPlayerForElement(
sunxd71aea3e2016-04-01 23:48:059004 root_ptr->id(), player.get());
9005 host_impl.active_tree()
9006 ->animation_host()
loysofb69174e2016-04-27 00:58:589007 ->GetElementAnimationsForElementId(root_ptr->id())
sunxd71aea3e2016-04-01 23:48:059008 ->AddAnimation(std::move(animation));
jaydasikaab317e02016-06-01 00:53:189009 root_ptr->test_properties()->opacity = 0.f;
sunxd71aea3e2016-04-01 23:48:059010 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
9011 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
9012 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
9013 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
9014
loysofb69174e2016-04-27 00:58:589015 host_impl.active_tree()->animation_host()->UnregisterPlayerForElement(
sunxd71aea3e2016-04-01 23:48:059016 root_ptr->id(), player.get());
vollick2175fae82015-04-27 21:18:129017}
9018
9019TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
9020 gfx::Transform identity;
jaydasika6f972de2016-04-07 16:16:149021 LayerImpl* root = root_layer();
9022 LayerImpl* child = AddChild<LayerImpl>(root);
vollick2175fae82015-04-27 21:18:129023
jaydasika6f972de2016-04-07 16:16:149024 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
9025 gfx::Size(100, 100), true, false, true);
9026 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
9027 gfx::Size(10, 10), true, false, false);
9028 child->SetDrawsContent(true);
vollick2175fae82015-04-27 21:18:129029
jaydasika6f972de2016-04-07 16:16:149030 ExecuteCalculateDrawProperties(root);
9031 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
weiliangcc97575c2016-03-03 18:34:279032 child->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:129033
jaydasika5121caa82016-05-05 15:43:359034 child->test_properties()->hide_layer_and_subtree = true;
jaydasika6f972de2016-04-07 16:16:149035 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9036 ExecuteCalculateDrawProperties(root);
9037 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:359038 child->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:129039
9040 child->SetBounds(gfx::Size());
jaydasika6f972de2016-04-07 16:16:149041 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9042 ExecuteCalculateDrawProperties(root);
9043 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129044 child->SetBounds(gfx::Size(10, 10));
9045
9046 gfx::Transform rotate;
jaydasika6b5a32bf2016-04-22 21:56:369047 child->test_properties()->double_sided = false;
vollick2175fae82015-04-27 21:18:129048 rotate.RotateAboutXAxis(180.f);
9049 child->SetTransform(rotate);
jaydasika6f972de2016-04-07 16:16:149050 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9051 ExecuteCalculateDrawProperties(root);
9052 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika6b5a32bf2016-04-22 21:56:369053 child->test_properties()->double_sided = true;
vollick2175fae82015-04-27 21:18:129054 child->SetTransform(identity);
9055
jaydasikaab317e02016-06-01 00:53:189056 child->test_properties()->opacity = 0.f;
jaydasika6f972de2016-04-07 16:16:149057 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9058 ExecuteCalculateDrawProperties(root);
9059 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:129060}
9061
jaydasika3d10aa62015-05-06 17:50:449062TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
9063 // Ensure that the treewalk in LayerTreeHostCommom::
9064 // PreCalculateMetaInformation happens when its required.
loyso0940d412016-03-14 01:30:319065 scoped_refptr<Layer> root = Layer::Create();
9066 scoped_refptr<Layer> parent = Layer::Create();
9067 scoped_refptr<Layer> child = Layer::Create();
jaydasika3d10aa62015-05-06 17:50:449068
9069 root->AddChild(parent);
9070 parent->AddChild(child);
9071
9072 child->SetClipParent(root.get());
9073
9074 gfx::Transform identity;
9075
9076 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9077 gfx::PointF(), gfx::Size(100, 100), true, false);
9078 SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(),
9079 gfx::PointF(), gfx::Size(100, 100), true, false);
9080 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9081 gfx::PointF(), gfx::Size(100, 100), true, false);
9082
ennea7b43c32015-06-18 20:01:339083 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:449084
jaydasika3d10aa62015-05-06 17:50:449085 child->RequestCopyOfOutput(
9086 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
sunxded58688e2016-01-11 21:01:029087
9088 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9089 EXPECT_EQ(parent->num_unclipped_descendants(), 1u);
9090
9091 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
9092 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9093 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika3d10aa62015-05-06 17:50:449094}
9095
vollick692444f2015-05-20 15:39:149096TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
9097 gfx::Transform identity;
9098 gfx::Transform translate_z;
9099 translate_z.Translate3d(0, 0, 10);
9100
loyso0940d412016-03-14 01:30:319101 scoped_refptr<Layer> root = Layer::Create();
vollick692444f2015-05-20 15:39:149102 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9103 gfx::PointF(), gfx::Size(800, 800), true, false);
9104
loyso0940d412016-03-14 01:30:319105 scoped_refptr<Layer> child = Layer::Create();
vollick692444f2015-05-20 15:39:149106 SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(),
9107 gfx::PointF(), gfx::Size(100, 100), true, false);
9108
9109 root->AddChild(child);
9110
ennea7b43c32015-06-18 20:01:339111 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:149112
9113 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9114 EXPECT_NE(-1, child->transform_tree_index());
9115
9116 child->RemoveFromParent();
9117
9118 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9119 EXPECT_EQ(-1, child->transform_tree_index());
9120}
9121
jaydasika67d7989e2015-08-06 21:55:349122TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
9123 // Ensure that a Clip Node is added when a render surface applies clip.
9124 LayerImpl* root = root_layer();
9125 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
9126 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
9127 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
9128 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9129
9130 const gfx::Transform identity_matrix;
9131 // This transform should be a significant one so that a transform node is
9132 // formed for it.
9133 gfx::Transform transform1;
9134 transform1.RotateAboutYAxis(45);
9135 transform1.RotateAboutXAxis(30);
9136 // This transform should be a 3d transform as we want the render surface
9137 // to flatten the transform
9138 gfx::Transform transform2;
9139 transform2.Translate3d(10, 10, 10);
9140
9141 layer_clips_subtree->SetMasksToBounds(true);
9142 test_layer->SetDrawsContent(true);
9143
9144 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269145 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349146 SetLayerPropertiesForTesting(significant_transform, transform1,
9147 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
weiliangcc154ce22015-12-09 03:39:269148 true, false);
jaydasika67d7989e2015-08-06 21:55:349149 SetLayerPropertiesForTesting(layer_clips_subtree, identity_matrix,
9150 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
weiliangcc154ce22015-12-09 03:39:269151 true, false);
jaydasika67d7989e2015-08-06 21:55:349152 SetLayerPropertiesForTesting(render_surface, transform2, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269153 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349154 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269155 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349156
jaydasika6b5a32bf2016-04-22 21:56:369157 root->test_properties()->force_render_surface = true;
9158 significant_transform->test_properties()->force_render_surface = false;
9159 layer_clips_subtree->test_properties()->force_render_surface = true;
9160 render_surface->test_properties()->force_render_surface = true;
9161 test_layer->test_properties()->force_render_surface = false;
jaydasika67d7989e2015-08-06 21:55:349162 ExecuteCalculateDrawProperties(root);
9163
ajumae4af47062016-05-24 23:59:049164 TransformTree& transform_tree =
jaydasika67d7989e2015-08-06 21:55:349165 root->layer_tree_impl()->property_trees()->transform_tree;
9166 TransformNode* transform_node =
9167 transform_tree.Node(significant_transform->transform_tree_index());
9168 EXPECT_EQ(transform_node->owner_id, significant_transform->id());
9169
weiliangcc154ce22015-12-09 03:39:269170 EXPECT_TRUE(root->has_render_surface());
9171 EXPECT_FALSE(significant_transform->has_render_surface());
9172 EXPECT_TRUE(layer_clips_subtree->has_render_surface());
9173 EXPECT_TRUE(render_surface->has_render_surface());
9174 EXPECT_FALSE(test_layer->has_render_surface());
9175
ajumae4af47062016-05-24 23:59:049176 ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
jaydasika67d7989e2015-08-06 21:55:349177 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
ajuma01734dd02015-10-07 01:22:089178 EXPECT_FALSE(clip_node->data.applies_local_clip);
weiliangcd15784432016-06-07 17:57:339179 EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349180}
9181
9182TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
9183 // Ensure that when parent clip node's transform is an ancestor of current
9184 // clip node's target, clip is 'projected' from parent space to current
9185 // target space and visible rects are calculated correctly.
9186 LayerImpl* root = root_layer();
9187 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9188 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
9189 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
9190
9191 const gfx::Transform identity_matrix;
9192 gfx::Transform transform;
9193 transform.RotateAboutYAxis(45);
9194 clip_layer->SetMasksToBounds(true);
9195 target_layer->SetMasksToBounds(true);
9196 test_layer->SetDrawsContent(true);
9197
9198 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9199 gfx::PointF(), gfx::Size(30, 30), true, false,
9200 true);
9201 SetLayerPropertiesForTesting(clip_layer, transform, gfx::Point3F(),
9202 gfx::PointF(), gfx::Size(30, 30), true, false,
9203 false);
9204 SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(),
9205 gfx::PointF(), gfx::Size(30, 30), true, false,
9206 true);
9207 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9208 gfx::PointF(), gfx::Size(30, 30), true, false,
9209 false);
9210 ExecuteCalculateDrawProperties(root);
9211
weiliangcc97575c2016-03-03 18:34:279212 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349213}
9214
jaydasika7d5c1ed2015-08-14 14:27:029215TEST_F(LayerTreeHostCommonTest,
9216 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
9217 // Ensure clip rect is calculated correctly when render surface has unclipped
9218 // descendants.
9219 LayerImpl* root = root_layer();
9220 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9221 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
9222 LayerImpl* render_surface =
9223 AddChild<LayerImpl>(between_clip_parent_and_child);
9224 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9225
9226 const gfx::Transform identity_matrix;
weiliangcbb2e8642016-03-04 00:24:429227 gfx::Transform translate;
9228 translate.Translate(2.0, 2.0);
jaydasika7d5c1ed2015-08-14 14:27:029229
weiliangcbb2e8642016-03-04 00:24:429230 clip_parent->SetMasksToBounds(true);
jaydasika7d5c1ed2015-08-14 14:27:029231 test_layer->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569232 render_surface->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489233 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasikae9d09702015-09-15 01:26:419234 clip_children->insert(render_surface);
jaydasika1c0a27d42016-04-28 01:54:569235 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika7d5c1ed2015-08-14 14:27:029236 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9237 gfx::PointF(), gfx::Size(30, 30), true, false,
9238 true);
weiliangcbb2e8642016-03-04 00:24:429239 SetLayerPropertiesForTesting(clip_parent, translate, gfx::Point3F(),
jaydasika7d5c1ed2015-08-14 14:27:029240 gfx::PointF(), gfx::Size(30, 30), true, false,
9241 false);
weiliangcbb2e8642016-03-04 00:24:429242 SetLayerPropertiesForTesting(between_clip_parent_and_child, translate,
jaydasika7d5c1ed2015-08-14 14:27:029243 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
9244 true, false, false);
9245 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9246 gfx::PointF(), gfx::Size(30, 30), true, false,
9247 true);
9248 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9249 gfx::PointF(), gfx::Size(30, 30), true, false,
9250 false);
9251
9252 ExecuteCalculateDrawProperties(root);
9253
weiliangcbb2e8642016-03-04 00:24:429254 EXPECT_TRUE(test_layer->is_clipped());
weiliangc189c1a12016-04-11 16:16:259255 EXPECT_FALSE(test_layer->render_target()->is_clipped());
weiliangc0b41eaf2016-03-14 21:35:569256 EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect());
9257 EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect());
jaydasika7d5c1ed2015-08-14 14:27:029258}
9259
jaydasika571dd2cf2015-09-25 20:55:429260TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:089261 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
9262 // Ensure that the visible layer rect of a descendant of a surface with
9263 // unclipped descendants is computed correctly, when the surface doesn't apply
9264 // a clip.
9265 LayerImpl* root = root_layer();
9266 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9267 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9268 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9269 LayerImpl* child = AddChild<LayerImpl>(render_surface);
9270
9271 const gfx::Transform identity_matrix;
9272
9273 clip_child->SetDrawsContent(true);
9274 child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569275 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489276 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
ajuma01734dd02015-10-07 01:22:089277 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569278 clip_parent->test_properties()->clip_children.reset(clip_children.release());
ajuma01734dd02015-10-07 01:22:089279 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9280 gfx::PointF(), gfx::Size(30, 10), true, false,
9281 true);
9282 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9283 gfx::PointF(), gfx::Size(30, 30), true, false,
9284 false);
9285 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9286 gfx::PointF(), gfx::Size(10, 15), true, false,
9287 true);
9288 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9289 gfx::PointF(), gfx::Size(10, 10), true, false,
9290 false);
9291 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
9292 gfx::PointF(), gfx::Size(40, 40), true, false,
9293 false);
9294
9295 ExecuteCalculateDrawProperties(root);
9296 EXPECT_EQ(gfx::Rect(40, 40), child->visible_layer_rect());
9297}
9298
9299TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:429300 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
9301 LayerImpl* root = root_layer();
9302 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9303 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9304 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
9305 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
9306 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
9307
9308 const gfx::Transform identity_matrix;
9309 root->SetMasksToBounds(true);
9310 render_surface->SetMasksToBounds(true);
9311 render_surface->SetDrawsContent(true);
9312 clip_child->SetDrawsContent(true);
9313 test_layer1->SetDrawsContent(true);
9314 test_layer2->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569315 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489316 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika571dd2cf2015-09-25 20:55:429317 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569318 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika571dd2cf2015-09-25 20:55:429319
9320 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9321 gfx::PointF(), gfx::Size(30, 30), true, false,
9322 true);
9323 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9324 gfx::PointF(), gfx::Size(30, 30), true, false,
9325 false);
9326 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9327 gfx::PointF(), gfx::Size(50, 50), true, false,
9328 true);
9329 SetLayerPropertiesForTesting(test_layer1, identity_matrix, gfx::Point3F(),
9330 gfx::PointF(), gfx::Size(50, 50), true, false,
9331 false);
9332 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9333 gfx::PointF(), gfx::Size(50, 50), true, false,
9334 false);
9335 SetLayerPropertiesForTesting(test_layer2, identity_matrix, gfx::Point3F(),
9336 gfx::PointF(), gfx::Size(50, 50), true, false,
9337 false);
9338
9339 ExecuteCalculateDrawProperties(root);
weiliangc0e13ba602016-03-12 04:53:569340 EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect());
9341 EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect());
jaydasika571dd2cf2015-09-25 20:55:429342 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
9343 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
9344}
9345
ajumae2b7a5c2015-09-30 21:41:429346TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
9347 LayerImpl* root = root_layer();
9348 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9349 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9350 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9351
9352 const gfx::Transform identity_matrix;
9353 clip_parent->SetDrawsContent(true);
9354 render_surface->SetMasksToBounds(true);
9355 render_surface->SetDrawsContent(true);
9356 clip_child->SetDrawsContent(true);
9357
jaydasika1c0a27d42016-04-28 01:54:569358 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489359 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
ajumae2b7a5c2015-09-30 21:41:429360 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569361 clip_parent->test_properties()->clip_children.reset(clip_children.release());
ajumae2b7a5c2015-09-30 21:41:429362
9363 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9364 gfx::PointF(), gfx::Size(50, 50), true, false,
9365 true);
9366 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9367 gfx::PointF(), gfx::Size(50, 50), true, false,
9368 false);
9369 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9370 gfx::PointF(), gfx::Size(30, 30), true, false,
9371 true);
9372 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9373 gfx::PointF(), gfx::Size(50, 50), true, false,
9374 false);
9375
9376 ExecuteCalculateDrawProperties(root);
9377
9378 // The clip child should inherit its clip parent's clipping state, not its
9379 // tree parent's clipping state.
9380 EXPECT_FALSE(clip_parent->is_clipped());
9381 EXPECT_TRUE(render_surface->is_clipped());
9382 EXPECT_FALSE(clip_child->is_clipped());
9383}
9384
jaydasika77a4a072015-10-20 21:47:279385TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
9386 // Tests the value of render surface content rect when we have multiple types
9387 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
9388 // clipped surfaces.
9389 LayerImpl* root = root_layer();
9390 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
9391 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
9392 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9393 LayerImpl* unclipped_desc_surface2 =
9394 AddChild<LayerImpl>(unclipped_desc_surface);
9395 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
9396 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
9397
9398 unclipped_surface->SetDrawsContent(true);
9399 unclipped_desc_surface->SetDrawsContent(true);
9400 unclipped_desc_surface2->SetDrawsContent(true);
9401 clipped_surface->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569402 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489403 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika77a4a072015-10-20 21:47:279404 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569405 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika77a4a072015-10-20 21:47:279406
9407 gfx::Transform identity_matrix;
9408 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9409 gfx::PointF(), gfx::Size(80, 80), true, false,
9410 true);
9411 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
9412 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
9413 true, false, true);
9414 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9415 gfx::PointF(), gfx::Size(50, 50), true, false,
9416 false);
9417 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
9418 gfx::Point3F(), gfx::PointF(),
9419 gfx::Size(100, 100), true, false, true);
9420 SetLayerPropertiesForTesting(unclipped_desc_surface2, identity_matrix,
9421 gfx::Point3F(), gfx::PointF(), gfx::Size(60, 60),
9422 true, false, true);
9423 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9424 gfx::PointF(), gfx::Size(100, 100), true, false,
9425 false);
9426 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
9427 gfx::PointF(), gfx::Size(70, 70), true, false,
9428 true);
9429 clip_parent->SetMasksToBounds(true);
9430 unclipped_surface->SetMasksToBounds(true);
9431 unclipped_desc_surface->SetMasksToBounds(true);
9432
9433 ExecuteCalculateDrawProperties(root);
9434 EXPECT_EQ(gfx::Rect(50, 50),
9435 unclipped_surface->render_surface()->content_rect());
weiliangc0e13ba602016-03-12 04:53:569436 EXPECT_EQ(gfx::Rect(50, 50),
jaydasika77a4a072015-10-20 21:47:279437 unclipped_desc_surface->render_surface()->content_rect());
9438 EXPECT_EQ(gfx::Rect(50, 50),
9439 unclipped_desc_surface2->render_surface()->content_rect());
9440 EXPECT_EQ(gfx::Rect(50, 50),
9441 clipped_surface->render_surface()->content_rect());
9442}
9443
9444TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
9445 // Tests the value of render surface content rect when we have a layer that
9446 // clips between the clip parent's target and clip child's target.
9447 LayerImpl* root = root_layer();
9448 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9449 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9450 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9451 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9452 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9453
9454 clip_child->SetDrawsContent(true);
9455 unclipped_desc_surface->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569456 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489457 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika77a4a072015-10-20 21:47:279458 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569459 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika77a4a072015-10-20 21:47:279460
9461 gfx::Transform identity_matrix;
9462 gfx::Transform translate;
9463 translate.Translate(10, 10);
9464 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9465 gfx::PointF(), gfx::Size(100, 100), true, false,
9466 true);
9467 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
9468 gfx::PointF(), gfx::Size(100, 100), true, false,
9469 true);
9470 SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(),
9471 gfx::PointF(), gfx::Size(20, 20), true, false,
9472 false);
9473 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9474 gfx::PointF(), gfx::Size(50, 50), true, false,
9475 false);
9476 SetLayerPropertiesForTesting(unclipped_desc_surface, translate,
9477 gfx::Point3F(), gfx::PointF(),
9478 gfx::Size(100, 100), true, false, true);
9479 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9480 gfx::PointF(), gfx::Size(100, 100), true, false,
9481 false);
9482 surface->SetMasksToBounds(true);
9483 clip_layer->SetMasksToBounds(true);
9484
9485 ExecuteCalculateDrawProperties(root);
9486
9487 EXPECT_EQ(gfx::Rect(10, 10),
9488 unclipped_desc_surface->render_surface()->content_rect());
9489}
9490
jaydasika2c8c2872015-10-21 23:28:219491TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
9492 LayerImpl* root = root_layer();
9493 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9494 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9495 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9496 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9497 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9498
9499 clip_child->SetDrawsContent(true);
9500 unclipped_desc_surface->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569501 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489502 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika2c8c2872015-10-21 23:28:219503 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569504 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika2c8c2872015-10-21 23:28:219505
9506 gfx::Transform identity_matrix;
9507 gfx::Transform scale;
9508 scale.Scale(2, 2);
9509 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9510 gfx::PointF(), gfx::Size(100, 100), true, false,
9511 true);
9512 SetLayerPropertiesForTesting(surface, scale, gfx::Point3F(), gfx::PointF(),
9513 gfx::Size(100, 100), true, false, 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, identity_matrix,
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(20, 20), clip_child->visible_layer_rect());
9532}
9533
jaydasika60f85862015-10-01 20:36:149534TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
9535 LayerImpl* root = root_layer();
9536 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9537 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9538
9539 const gfx::Transform identity_matrix;
9540 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9541 gfx::PointF(), gfx::Size(30, 30), true, false,
9542 true);
9543 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9544 gfx::PointF(), gfx::Size(30, 30), true, false,
9545 true);
jaydasika86654512016-01-27 17:05:079546 gfx::Transform translation;
9547 translation.Translate(10, 10);
9548 SetLayerPropertiesForTesting(test_layer, translation, gfx::Point3F(),
jaydasika60f85862015-10-01 20:36:149549 gfx::PointF(), gfx::Size(20, 20), true, false,
9550 false);
9551
9552 render_surface->SetMasksToBounds(true);
9553 test_layer->SetDrawsContent(true);
jaydasikaab317e02016-06-01 00:53:189554 test_layer->test_properties()->opacity = 0.f;
dtapuskaee0b6982016-01-29 15:14:489555 test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20));
jaydasika60f85862015-10-01 20:36:149556
9557 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079558 EXPECT_EQ(translation, test_layer->ScreenSpaceTransform());
jaydasika60f85862015-10-01 20:36:149559}
9560
jaydasikae4910fa22015-10-09 00:52:099561TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
9562 LayerImpl* root = root_layer();
9563 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9564 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9565 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9566
9567 const gfx::Transform identity_matrix;
9568 clip_parent->SetMasksToBounds(true);
9569 render_surface->SetMasksToBounds(true);
9570 render_surface->SetDrawsContent(true);
9571 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569572 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489573 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasikae4910fa22015-10-09 00:52:099574 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569575 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasikae4910fa22015-10-09 00:52:099576
9577 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9578 gfx::PointF(), gfx::Size(30, 30), true, false,
9579 true);
9580 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9581 gfx::PointF(10.f, 10.f), gfx::Size(40, 40), true,
9582 false, false);
9583 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9584 gfx::PointF(), gfx::Size(50, 50), true, false,
9585 true);
9586 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9587 gfx::PointF(), gfx::Size(50, 50), true, false,
9588 false);
9589
9590 ExecuteCalculateDrawProperties(root);
9591 EXPECT_EQ(gfx::Rect(40, 40), clip_child->visible_layer_rect());
9592}
9593
jaydasika571dd2cf2015-09-25 20:55:429594TEST_F(LayerTreeHostCommonTest,
9595 LayerClipRectLargerThanClippingRenderSurfaceRect) {
9596 LayerImpl* root = root_layer();
9597 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9598 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9599 const gfx::Transform identity_matrix;
9600 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9601 gfx::PointF(), gfx::Size(30, 30), true, false,
9602 true);
9603 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9604 gfx::PointF(), gfx::Size(50, 50), true, false,
9605 true);
9606 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9607 gfx::PointF(), gfx::Size(50, 50), true, false,
9608 false);
9609 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369610 root->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429611 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369612 render_surface->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429613 test_layer->SetMasksToBounds(true);
9614 test_layer->SetDrawsContent(true);
9615 ExecuteCalculateDrawProperties(root);
9616
9617 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
9618 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
9619 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
9620}
9621
jaydasikab5504ca2015-12-18 23:41:559622TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) {
9623 // Tests that subtree is hidden is updated.
9624 LayerImpl* root = root_layer();
9625 LayerImpl* hidden = AddChild<LayerImpl>(root);
9626 LayerImpl* test = AddChild<LayerImpl>(hidden);
9627
9628 const gfx::Transform identity_matrix;
9629 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9630 gfx::PointF(), gfx::Size(30, 30), true, false,
9631 true);
9632 SetLayerPropertiesForTesting(hidden, identity_matrix, gfx::Point3F(),
9633 gfx::PointF(10, 10), gfx::Size(30, 30), true,
9634 false, true);
9635 SetLayerPropertiesForTesting(test, identity_matrix, gfx::Point3F(),
9636 gfx::PointF(), gfx::Size(30, 30), true, false,
9637 true);
9638
jaydasika5121caa82016-05-05 15:43:359639 hidden->test_properties()->hide_layer_and_subtree = true;
jaydasikab5504ca2015-12-18 23:41:559640 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079641 EXPECT_TRUE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559642
jaydasika5121caa82016-05-05 15:43:359643 hidden->test_properties()->hide_layer_and_subtree = false;
jaydasikab5504ca2015-12-18 23:41:559644 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9645 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079646 EXPECT_FALSE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559647}
9648
jaydasikac0137282015-10-01 15:50:309649TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
9650 LayerImpl* root = root_layer();
9651 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9652 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9653 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
9654
9655 const gfx::Transform identity_matrix;
jaydasika1c0a27d42016-04-28 01:54:569656 clip_child->test_properties()->clip_parent = root;
danakj60bc3bc2016-04-09 00:24:489657 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasikac0137282015-10-01 15:50:309658 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569659 root->test_properties()->clip_children.reset(clip_children.release());
jaydasikac0137282015-10-01 15:50:309660 root->SetMasksToBounds(true);
9661 render_surface1->SetDrawsContent(true);
9662 render_surface2->SetDrawsContent(true);
9663
9664 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9665 gfx::PointF(), gfx::Size(30, 30), true, false,
9666 true);
9667 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
9668 gfx::PointF(10, 10), gfx::Size(30, 30), true,
9669 false, true);
9670 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
9671 gfx::PointF(), gfx::Size(30, 30), true, false,
9672 true);
9673 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9674 gfx::PointF(), gfx::Size(30, 30), true, false,
9675 false);
9676 ExecuteCalculateDrawProperties(root);
9677
9678 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
jaydasikadaf0af02016-01-06 15:33:379679 // A clip node is created for every render surface and for layers that have
9680 // local clip. So, here it should be craeted for every layer.
9681 EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u);
jaydasikac0137282015-10-01 15:50:309682}
9683
jaydasika224bca02015-12-18 02:37:099684TEST_F(LayerTreeHostCommonTest, MaskLayerScreenSpaceTransform) {
9685 // Tests that the mask layer gets its owning layer's screen space transform.
9686 LayerImpl* root = root_layer();
9687 LayerImpl* child = AddChild<LayerImpl>(root);
9688
9689 const gfx::Transform identity_matrix;
9690 gfx::Transform transform;
9691 transform.Translate(10, 10);
9692
9693 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9694 gfx::PointF(), gfx::Size(30, 30), true, false,
9695 true);
9696 SetLayerPropertiesForTesting(child, transform, gfx::Point3F(), gfx::PointF(),
9697 gfx::Size(30, 30), true, false, false);
9698 root->SetDrawsContent(true);
9699 child->SetDrawsContent(false);
9700 child->SetMaskLayer(LayerImpl::Create(root->layer_tree_impl(), 100));
9701 ExecuteCalculateDrawProperties(root);
9702
9703 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
9704 child->mask_layer()->ScreenSpaceTransform());
9705 transform.Translate(10, 10);
9706 child->SetTransform(transform);
9707 child->SetDrawsContent(true);
9708 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9709 ExecuteCalculateDrawProperties(root);
9710 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
9711 child->mask_layer()->ScreenSpaceTransform());
9712}
9713
jaydasikaf62311f2016-04-20 14:38:459714TEST_F(LayerTreeHostCommonTest,
9715 SublayerScaleWithTransformNodeBetweenTwoTargets) {
9716 LayerImpl* root = root_layer();
9717 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9718 LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1);
9719 LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets);
9720 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2);
9721 const gfx::Transform identity_matrix;
9722 test_layer->SetDrawsContent(true);
9723
9724 gfx::Transform scale;
9725 scale.Scale(2.f, 2.f);
9726 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9727 gfx::PointF(), gfx::Size(30, 30), true, false,
9728 true);
9729 SetLayerPropertiesForTesting(render_surface1, scale, gfx::Point3F(),
9730 gfx::PointF(), gfx::Size(30, 30), true, false,
9731 true);
9732 SetLayerPropertiesForTesting(between_targets, identity_matrix, gfx::Point3F(),
9733 gfx::PointF(), gfx::Size(30, 30), true, false,
9734 false);
9735 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
9736 gfx::PointF(), gfx::Size(30, 30), true, false,
9737 true);
9738 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9739 gfx::PointF(), gfx::Size(30, 30), true, false,
9740 false);
9741 // We want layer between the two targets to create a clip node and transform
9742 // node but it shouldn't create a render surface.
9743 between_targets->SetMasksToBounds(true);
9744 between_targets->Set3dSortingContextId(2);
9745
9746 ExecuteCalculateDrawProperties(root);
9747
9748 TransformTree& tree =
9749 root->layer_tree_impl()->property_trees()->transform_tree;
9750 TransformNode* node = tree.Node(render_surface1->transform_tree_index());
9751 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(2.f, 2.f));
9752
9753 node = tree.Node(between_targets->transform_tree_index());
9754 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(1.f, 1.f));
9755
9756 node = tree.Node(render_surface2->transform_tree_index());
9757 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(2.f, 2.f));
9758
9759 EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect());
9760}
9761
jaydasika5160e672015-10-15 15:25:149762TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
9763 LayerImpl* root = root_layer();
9764 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
sunxd71aea3e2016-04-01 23:48:059765 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
jaydasika5160e672015-10-15 15:25:149766
9767 const gfx::Transform identity_matrix;
sunxd71aea3e2016-04-01 23:48:059768 child->SetDrawsContent(true);
9769 child->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:149770
9771 gfx::Transform large_transform;
9772 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
9773 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
9774 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
9775 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
9776
9777 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9778 gfx::PointF(), gfx::Size(30, 30), true, false,
9779 true);
sunxd71aea3e2016-04-01 23:48:059780 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
jaydasika5160e672015-10-15 15:25:149781 gfx::PointF(), gfx::Size(30, 30), true, false,
9782 true);
sunxd71aea3e2016-04-01 23:48:059783 // TODO(sunxd): we make child have no render surface, because if the
9784 // child has one, the large transform applied to child will result in NaNs in
9785 // the draw_transform of the render_surface, thus make draw property updates
9786 // skip the child layer. We need further investigation into this to know
9787 // what exactly happens here.
9788 SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(),
jaydasika5160e672015-10-15 15:25:149789 gfx::PointF(), gfx::Size(30, 30), true, false,
sunxd71aea3e2016-04-01 23:48:059790 false);
jaydasika5160e672015-10-15 15:25:149791
9792 ExecuteCalculateDrawProperties(root);
9793
jaydasika5160e672015-10-15 15:25:149794 EXPECT_EQ(gfx::RectF(),
sunxd71aea3e2016-04-01 23:48:059795 render_surface1->render_surface()->DrawableContentRect());
9796
9797 bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) ||
9798 std::isnan(child->DrawTransform().matrix().get(0, 0));
9799 EXPECT_TRUE(is_inf_or_nan);
9800
9801 is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) ||
9802 std::isnan(child->DrawTransform().matrix().get(1, 1));
9803 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:149804
9805 std::vector<LayerImpl*>* rsll = render_surface_layer_list_impl();
9806 bool root_in_rsll =
9807 std::find(rsll->begin(), rsll->end(), root) != rsll->end();
9808 EXPECT_TRUE(root_in_rsll);
jaydasika5160e672015-10-15 15:25:149809}
9810
jaydasika8d6efe2e2016-05-17 15:37:219811TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) {
9812 const gfx::Transform identity_matrix;
9813 scoped_refptr<Layer> root = Layer::Create();
9814 scoped_refptr<LayerWithForcedDrawsContent> child =
9815 make_scoped_refptr(new LayerWithForcedDrawsContent());
9816 root->AddChild(child);
9817
9818 host()->SetRootLayer(root);
9819
9820 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
9821 gfx::PointF(), gfx::Size(100, 100), true, false);
9822 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
9823 gfx::PointF(), gfx::Size(20, 20), true, false);
9824
9825 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9826
9827 // Changing the opacity from 1 to non-1 value should trigger rebuild of
9828 // property trees as a new effect node will be created.
9829 child->SetOpacity(0.5f);
9830 PropertyTrees* property_trees = host()->property_trees();
9831 EXPECT_TRUE(property_trees->needs_rebuild);
9832
9833 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9834 EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()),
9835 property_trees->effect_id_to_index_map.end());
9836
9837 // child already has an effect node. Changing its opacity shouldn't trigger
9838 // a property trees rebuild.
9839 child->SetOpacity(0.8f);
9840 property_trees = host()->property_trees();
9841 EXPECT_FALSE(property_trees->needs_rebuild);
9842
9843 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9844 EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()),
9845 property_trees->effect_id_to_index_map.end());
9846
9847 // Changing the opacity from non-1 value to 1 should trigger a rebuild of
9848 // property trees as the effect node may no longer be needed.
9849 child->SetOpacity(1.f);
9850 property_trees = host()->property_trees();
9851 EXPECT_TRUE(property_trees->needs_rebuild);
9852
9853 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9854 EXPECT_EQ(property_trees->effect_id_to_index_map.find(child->id()),
9855 property_trees->effect_id_to_index_map.end());
9856}
9857
jaydasika9cb21c772016-05-10 22:37:089858TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) {
9859 const gfx::Transform identity_matrix;
9860 scoped_refptr<Layer> root = Layer::Create();
9861 scoped_refptr<LayerWithForcedDrawsContent> animated =
9862 make_scoped_refptr(new LayerWithForcedDrawsContent());
9863 root->AddChild(animated);
9864
9865 host()->SetRootLayer(root);
9866
9867 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
9868 gfx::PointF(), gfx::Size(100, 100), true, false);
9869 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
9870 gfx::PointF(), gfx::Size(20, 20), true, false);
9871
9872 root->SetForceRenderSurfaceForTesting(true);
9873 animated->SetOpacity(0.f);
9874
9875 scoped_refptr<AnimationPlayer> player =
9876 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
9877 timeline()->AttachPlayer(player);
9878 player->AttachElement(animated->id());
9879
9880 int animation_id = 0;
9881 std::unique_ptr<Animation> animation = Animation::Create(
9882 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
9883 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:559884 animation->set_fill_mode(Animation::FillMode::NONE);
jaydasika9cb21c772016-05-10 22:37:089885 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
9886 Animation* animation_ptr = animation.get();
9887 AddAnimationToLayerWithExistingPlayer(animated->id(), timeline(),
9888 std::move(animation));
9889
9890 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9891
9892 EffectTree& tree = root->layer_tree_host()->property_trees()->effect_tree;
9893 EffectNode* node = tree.Node(animated->effect_tree_index());
9894 EXPECT_FALSE(node->data.is_currently_animating_opacity);
9895 EXPECT_TRUE(node->data.has_potential_opacity_animation);
9896
9897 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
9898 root->layer_tree_host()->AnimateLayers(
9899 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
9900 node = tree.Node(animated->effect_tree_index());
9901 EXPECT_TRUE(node->data.is_currently_animating_opacity);
9902 EXPECT_TRUE(node->data.has_potential_opacity_animation);
9903
9904 player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/);
9905 node = tree.Node(animated->effect_tree_index());
9906 EXPECT_FALSE(node->data.is_currently_animating_opacity);
9907 EXPECT_FALSE(node->data.has_potential_opacity_animation);
9908}
9909
jaydasika6c3404e92016-05-19 02:40:369910TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) {
9911 const gfx::Transform identity_matrix;
9912 scoped_refptr<Layer> root = Layer::Create();
9913 scoped_refptr<LayerWithForcedDrawsContent> animated =
9914 make_scoped_refptr(new LayerWithForcedDrawsContent());
9915 root->AddChild(animated);
9916
9917 host()->SetRootLayer(root);
9918
9919 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
9920 gfx::PointF(), gfx::Size(100, 100), true, false);
9921 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
9922 gfx::PointF(), gfx::Size(20, 20), true, false);
9923
9924 root->SetForceRenderSurfaceForTesting(true);
9925
9926 scoped_refptr<AnimationPlayer> player =
9927 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
9928 timeline()->AttachPlayer(player);
9929 player->AttachElement(animated->id());
9930
9931 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
9932 KeyframedTransformAnimationCurve::Create());
9933 TransformOperations start;
9934 start.AppendTranslate(1.f, 2.f, 3.f);
9935 gfx::Transform transform;
9936 transform.Scale3d(1.0, 2.0, 3.0);
9937 TransformOperations operation;
9938 operation.AppendMatrix(transform);
9939 curve->AddKeyframe(
9940 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
9941 curve->AddKeyframe(TransformKeyframe::Create(
9942 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
9943 std::unique_ptr<Animation> animation(
9944 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
9945 animation->set_fill_mode(Animation::FillMode::NONE);
9946 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
9947 Animation* animation_ptr = animation.get();
9948 AddAnimationToLayerWithExistingPlayer(animated->id(), timeline(),
9949 std::move(animation));
9950
9951 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9952
9953 TransformTree& tree =
9954 root->layer_tree_host()->property_trees()->transform_tree;
9955 TransformNode* node = tree.Node(animated->transform_tree_index());
9956 EXPECT_FALSE(node->data.is_currently_animating);
9957 EXPECT_TRUE(node->data.has_potential_animation);
9958
9959 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
9960 root->layer_tree_host()->AnimateLayers(
9961 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
9962 node = tree.Node(animated->transform_tree_index());
9963 EXPECT_TRUE(node->data.is_currently_animating);
9964 EXPECT_TRUE(node->data.has_potential_animation);
9965
9966 player->AbortAnimations(TargetProperty::TRANSFORM,
9967 false /*needs_completion*/);
9968 node = tree.Node(animated->transform_tree_index());
9969 EXPECT_FALSE(node->data.is_currently_animating);
9970 EXPECT_FALSE(node->data.has_potential_animation);
9971}
9972
khushalsagar37694212016-01-15 20:46:489973TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) {
9974 LayerTreeHostCommon::ScrollUpdateInfo scroll;
9975 scroll.layer_id = 2;
9976 scroll.scroll_delta = gfx::Vector2d(5, 10);
9977
9978 proto::ScrollUpdateInfo proto;
9979 scroll.ToProtobuf(&proto);
9980 LayerTreeHostCommon::ScrollUpdateInfo new_scroll;
9981 new_scroll.FromProtobuf(proto);
9982
9983 EXPECT_EQ(scroll, new_scroll);
9984}
9985
9986TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) {
9987 ScrollAndScaleSet scroll_and_scale_set;
9988
9989 LayerTreeHostCommon::ScrollUpdateInfo scroll1;
9990 scroll1.layer_id = 1;
9991 scroll1.scroll_delta = gfx::Vector2d(5, 10);
9992 LayerTreeHostCommon::ScrollUpdateInfo scroll2;
9993 scroll2.layer_id = 2;
9994 scroll2.scroll_delta = gfx::Vector2d(1, 5);
9995 scroll_and_scale_set.scrolls.push_back(scroll1);
9996 scroll_and_scale_set.scrolls.push_back(scroll2);
9997
9998 scroll_and_scale_set.page_scale_delta = 0.3f;
9999 scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f);
10000 scroll_and_scale_set.top_controls_delta = 0.9f;
10001
10002 proto::ScrollAndScaleSet proto;
10003 scroll_and_scale_set.ToProtobuf(&proto);
10004 ScrollAndScaleSet new_scroll_and_scale_set;
10005 new_scroll_and_scale_set.FromProtobuf(proto);
10006
10007 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set));
10008}
10009
sunxdea1df782016-01-28 00:12:3310010TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) {
10011 // Test the behavior of scroll tree builder
10012 // Topology:
sunxdcfccd1b32016-02-11 00:54:2010013 // +root1(1)[inner_viewport_container_layer]
10014 // +-page_scale_layer
10015 // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling &
10016 // scrollable, inner_viewport_scroll_layer]
10017 // +------child6(6)[kScrollbarScrolling]
10018 // +--------grand_child10(10)[kScrollbarScrolling]
10019 // +----parent3(3)
10020 // +------child7(7)[scrollable]
10021 // +------child8(8)[scroll_parent=7]
10022 // +--------grand_child11(11)[scrollable]
10023 // +----parent4(4)
10024 // +------child9(9)
10025 // +--------grand_child12(12)
10026 // +----parent5(5)[contains_non_fast_scrollable_region]
sunxdea1df782016-01-28 00:12:3310027 //
10028 // Expected scroll tree topology:
10029 // +property_tree_root---owner:-1
10030 // +--root---owner:1, id:1
10031 // +----node---owner:2, id:2
10032 // +------node---owner:6, id:3
10033 // +----node---owner:7, id:4
10034 // +------node---owner:11, id:5
10035 // +----node---owner:5, id:6
10036 //
10037 // Extra check:
10038 // scroll_tree_index() of:
10039 // grand_child10:3
10040 // parent3:1
10041 // child8:4
10042 // parent4:1
10043 // child9:1
10044 // grand_child12:1
loyso0940d412016-03-14 01:30:3110045 scoped_refptr<Layer> root1 = Layer::Create();
10046 scoped_refptr<Layer> page_scale_layer = Layer::Create();
10047 scoped_refptr<Layer> parent2 = Layer::Create();
10048 scoped_refptr<Layer> parent3 = Layer::Create();
10049 scoped_refptr<Layer> parent4 = Layer::Create();
10050 scoped_refptr<Layer> parent5 = Layer::Create();
10051 scoped_refptr<Layer> child6 = Layer::Create();
10052 scoped_refptr<Layer> child7 = Layer::Create();
10053 scoped_refptr<Layer> child8 = Layer::Create();
10054 scoped_refptr<Layer> child9 = Layer::Create();
10055 scoped_refptr<Layer> grand_child10 = Layer::Create();
10056 scoped_refptr<Layer> grand_child11 = Layer::Create();
10057 scoped_refptr<Layer> grand_child12 = Layer::Create();
sunxdea1df782016-01-28 00:12:3310058
sunxdcfccd1b32016-02-11 00:54:2010059 root1->AddChild(page_scale_layer);
10060 page_scale_layer->AddChild(parent2);
10061 page_scale_layer->AddChild(parent3);
10062 page_scale_layer->AddChild(parent4);
10063 page_scale_layer->AddChild(parent5);
sunxdea1df782016-01-28 00:12:3310064 parent2->AddChild(child6);
10065 parent3->AddChild(child7);
10066 parent3->AddChild(child8);
10067 parent4->AddChild(child9);
10068 child6->AddChild(grand_child10);
10069 child8->AddChild(grand_child11);
10070 child9->AddChild(grand_child12);
10071 host()->SetRootLayer(root1);
10072
10073 parent2->AddMainThreadScrollingReasons(
10074 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
sunxd29f17bf2016-02-03 02:47:4810075 parent2->AddMainThreadScrollingReasons(
10076 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310077 parent2->SetScrollClipLayerId(root1->id());
10078 child6->AddMainThreadScrollingReasons(
sunxd29f17bf2016-02-03 02:47:4810079 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310080 grand_child10->AddMainThreadScrollingReasons(
sunxd29f17bf2016-02-03 02:47:4810081 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:3310082
sunxdcfccd1b32016-02-11 00:54:2010083 child7->SetScrollClipLayerId(parent3->id());
10084
sunxdea1df782016-01-28 00:12:3310085 child8->SetScrollParent(child7.get());
sunxdcfccd1b32016-02-11 00:54:2010086 grand_child11->SetScrollClipLayerId(parent3->id());
sunxdea1df782016-01-28 00:12:3310087
10088 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
sunxdcfccd1b32016-02-11 00:54:2010089 parent5->SetBounds(gfx::Size(10, 10));
sunxdea1df782016-01-28 00:12:3310090
sunxdcfccd1b32016-02-11 00:54:2010091 host()->RegisterViewportLayers(NULL, page_scale_layer, parent2, NULL);
sunxdea1df782016-01-28 00:12:3310092 ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get());
10093
10094 const int kInvalidPropertyTreeNodeId = -1;
10095 const int kRootPropertyTreeNodeId = 0;
10096
10097 // Property tree root
ajumae4af47062016-05-24 23:59:0410098 ScrollTree& scroll_tree = host()->property_trees()->scroll_tree;
sunxdc36713a2016-03-03 22:31:1010099 PropertyTrees property_trees;
sunxdc044b11a2016-03-16 16:23:2010100 property_trees.is_main_thread = true;
10101 property_trees.is_active = false;
ajumae4af47062016-05-24 23:59:0410102 ScrollTree& expected_scroll_tree = property_trees.scroll_tree;
sunxdea1df782016-01-28 00:12:3310103 ScrollNode* property_tree_root = expected_scroll_tree.Node(0);
10104 property_tree_root->id = kRootPropertyTreeNodeId;
10105 property_tree_root->parent_id = kInvalidPropertyTreeNodeId;
10106 property_tree_root->owner_id = kInvalidPropertyTreeNodeId;
10107 property_tree_root->data.scrollable = false;
sunxd29f17bf2016-02-03 02:47:4810108 property_tree_root->data.main_thread_scrolling_reasons =
10109 MainThreadScrollingReason::kNotScrollingOnMain;
sunxdea1df782016-01-28 00:12:3310110 property_tree_root->data.contains_non_fast_scrollable_region = false;
sunxdd1abacf2016-02-16 22:08:3010111 property_tree_root->data.transform_id = kRootPropertyTreeNodeId;
sunxdea1df782016-01-28 00:12:3310112
10113 // The node owned by root1
10114 ScrollNode scroll_root1;
10115 scroll_root1.id = 1;
10116 scroll_root1.owner_id = root1->id();
sunxd54e08e9d2016-02-22 23:01:2810117 scroll_root1.data.user_scrollable_horizontal = true;
10118 scroll_root1.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010119 scroll_root1.data.transform_id = root1->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310120 expected_scroll_tree.Insert(scroll_root1, 0);
10121
10122 // The node owned by parent2
10123 ScrollNode scroll_parent2;
10124 scroll_parent2.id = 2;
10125 scroll_parent2.owner_id = parent2->id();
10126 scroll_parent2.data.scrollable = true;
sunxd29f17bf2016-02-03 02:47:4810127 scroll_parent2.data.main_thread_scrolling_reasons =
10128 parent2->main_thread_scrolling_reasons();
sunxdcfccd1b32016-02-11 00:54:2010129 scroll_parent2.data.scroll_clip_layer_bounds = root1->bounds();
10130 scroll_parent2.data.bounds = parent2->bounds();
10131 scroll_parent2.data.max_scroll_offset_affected_by_page_scale = true;
10132 scroll_parent2.data.is_inner_viewport_scroll_layer = true;
sunxd54e08e9d2016-02-22 23:01:2810133 scroll_parent2.data.user_scrollable_horizontal = true;
10134 scroll_parent2.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010135 scroll_parent2.data.transform_id = parent2->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310136 expected_scroll_tree.Insert(scroll_parent2, 1);
10137
10138 // The node owned by child6
10139 ScrollNode scroll_child6;
10140 scroll_child6.id = 3;
10141 scroll_child6.owner_id = child6->id();
sunxd29f17bf2016-02-03 02:47:4810142 scroll_child6.data.main_thread_scrolling_reasons =
10143 child6->main_thread_scrolling_reasons();
sunxdd1abacf2016-02-16 22:08:3010144 scroll_child6.data.should_flatten = true;
sunxd54e08e9d2016-02-22 23:01:2810145 scroll_child6.data.user_scrollable_horizontal = true;
10146 scroll_child6.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010147 scroll_child6.data.transform_id = child6->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310148 expected_scroll_tree.Insert(scroll_child6, 2);
10149
10150 // The node owned by child7, child7 also owns a transform node
10151 ScrollNode scroll_child7;
10152 scroll_child7.id = 4;
10153 scroll_child7.owner_id = child7->id();
10154 scroll_child7.data.scrollable = true;
sunxdd1abacf2016-02-16 22:08:3010155 scroll_child7.data.scroll_clip_layer_bounds = parent3->bounds();
10156 scroll_child7.data.bounds = child7->bounds();
sunxd54e08e9d2016-02-22 23:01:2810157 scroll_child7.data.user_scrollable_horizontal = true;
10158 scroll_child7.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010159 scroll_child7.data.transform_id = child7->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310160 expected_scroll_tree.Insert(scroll_child7, 1);
10161
10162 // The node owned by grand_child11, grand_child11 also owns a transform node
10163 ScrollNode scroll_grand_child11;
10164 scroll_grand_child11.id = 5;
10165 scroll_grand_child11.owner_id = grand_child11->id();
10166 scroll_grand_child11.data.scrollable = true;
sunxd54e08e9d2016-02-22 23:01:2810167 scroll_grand_child11.data.user_scrollable_horizontal = true;
10168 scroll_grand_child11.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010169 scroll_grand_child11.data.transform_id =
10170 grand_child11->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310171 expected_scroll_tree.Insert(scroll_grand_child11, 4);
10172
10173 // The node owned by parent5
10174 ScrollNode scroll_parent5;
10175 scroll_parent5.id = 8;
10176 scroll_parent5.owner_id = parent5->id();
10177 scroll_parent5.data.contains_non_fast_scrollable_region = true;
sunxdcfccd1b32016-02-11 00:54:2010178 scroll_parent5.data.bounds = gfx::Size(10, 10);
sunxdd1abacf2016-02-16 22:08:3010179 scroll_parent5.data.should_flatten = true;
sunxd54e08e9d2016-02-22 23:01:2810180 scroll_parent5.data.user_scrollable_horizontal = true;
10181 scroll_parent5.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010182 scroll_parent5.data.transform_id = parent5->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310183 expected_scroll_tree.Insert(scroll_parent5, 1);
10184
sunxdc044b11a2016-03-16 16:23:2010185 expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0));
10186 expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0));
10187 expected_scroll_tree.SetScrollOffset(grand_child11->id(),
10188 gfx::ScrollOffset(0, 0));
sunxdea1df782016-01-28 00:12:3310189 expected_scroll_tree.set_needs_update(false);
10190
10191 EXPECT_EQ(expected_scroll_tree, scroll_tree);
10192
10193 // Check other layers' scroll_tree_index
sunxdcfccd1b32016-02-11 00:54:2010194 EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index());
sunxdea1df782016-01-28 00:12:3310195 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10196 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10197 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10198 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10199 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10200 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10201}
10202
[email protected]ba565742012-11-10 09:29:4810203} // namespace
10204} // namespace cc