blob: e9724dc9e64085f4d2427fe15cca823fc5ad57da [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"
heejin.r.chungd28506ba2014-10-23 16:36:2049#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3750#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0051#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1452
[email protected]ba565742012-11-10 09:29:4853namespace cc {
[email protected]94f206c12012-08-25 00:09:1454namespace {
55
[email protected]96baf3e2012-10-22 23:09:5556class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:3257 public:
loyso0940d412016-03-14 01:30:3158 LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:1459
dcheng716bedf2014-10-21 09:51:0860 bool DrawsContent() const override;
[email protected]d58499a2012-10-09 22:27:4761
[email protected]fb661802013-03-25 01:59:3262 private:
dcheng716bedf2014-10-21 09:51:0863 ~LayerWithForcedDrawsContent() override {}
[email protected]94f206c12012-08-25 00:09:1464};
65
[email protected]fb661802013-03-25 01:59:3266bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:4467
[email protected]96baf3e2012-10-22 23:09:5568class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:3269 public:
70 MockContentLayerClient() {}
dcheng716bedf2014-10-21 09:51:0871 ~MockContentLayerClient() override {}
chrishtr01539b802015-11-24 08:11:3272 gfx::Rect PaintableRegion() override { return gfx::Rect(); }
jbroman16d628c2015-05-29 20:11:5973 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
schenney0154bfa2015-02-05 19:46:4974 PaintingControlSetting picture_control) override {
ajuma5e77f7d42014-11-27 14:19:1475 NOTIMPLEMENTED();
jbroman16d628c2015-05-29 20:11:5976 return nullptr;
ajuma5e77f7d42014-11-27 14:19:1477 }
dcheng716bedf2014-10-21 09:51:0878 bool FillsBoundsCompletely() const override { return false; }
jbroman9f60f1a2015-07-16 21:40:3279 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
[email protected]f34a24232012-09-20 22:59:5580};
81
[email protected]989386c2013-07-18 21:37:2382#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
83 do { \
84 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
85 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:4786 } while (false)
87
enne637715732015-07-07 02:05:2688#define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
89 do { \
90 EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \
sohan.jyotie3bd6192014-10-13 07:13:5991 } while (false)
92
enne637715732015-07-07 02:05:2693class LayerTreeSettingsScaleContent : public LayerTreeSettings {
94 public:
95 LayerTreeSettingsScaleContent() {
96 layer_transforms_should_scale_layer_contents = true;
97 }
98};
99
100class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTest {
101 public:
102 LayerTreeHostCommonScalingTest()
103 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
104};
105
weiliangc6da32862016-04-20 16:40:11106class LayerTreeHostCommonDrawRectsTest : public LayerTreeHostCommonTest {
107 public:
108 LayerTreeHostCommonDrawRectsTest() : LayerTreeHostCommonTest() {}
109
110 LayerImpl* TestVisibleRectAndDrawableContentRect(
111 const gfx::Rect& target_rect,
112 const gfx::Transform& layer_transform,
113 const gfx::Rect& layer_rect) {
114 LayerImpl* root = root_layer();
115 LayerImpl* target = AddChild<LayerImpl>(root);
116 LayerImpl* drawing_layer = AddChild<LayerImpl>(target);
117
118 root->SetDrawsContent(true);
119 target->SetDrawsContent(true);
120 target->SetMasksToBounds(true);
121 drawing_layer->SetDrawsContent(true);
122
123 gfx::Transform identity;
124
125 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
126 gfx::Size(500, 500), true, false, true);
127 SetLayerPropertiesForTesting(target, identity, gfx::Point3F(),
128 gfx::PointF(target_rect.origin()),
129 target_rect.size(), true, false, true);
130 SetLayerPropertiesForTesting(drawing_layer, layer_transform, gfx::Point3F(),
131 gfx::PointF(layer_rect.origin()),
132 layer_rect.size(), true, false, false);
133
134 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
135 ExecuteCalculateDrawProperties(root);
136
137 return drawing_layer;
138 }
139};
140
[email protected]989386c2013-07-18 21:37:23141TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32142 // Sanity check: For layers positioned at zero, with zero size,
143 // and with identity transforms, then the draw transform,
144 // screen space transform, and the hierarchy passed on to children
145 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14146
sunxdfd920f3f2016-04-05 16:17:51147 LayerImpl* parent = root_layer();
148 LayerImpl* child = AddChild<LayerImpl>(parent);
149 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28150
[email protected]fb661802013-03-25 01:59:32151 gfx::Transform identity_matrix;
sunxdfd920f3f2016-04-05 16:17:51152 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
153 gfx::PointF(), gfx::Size(100, 100), true, false);
154 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
155 gfx::PointF(), gfx::Size(), true, false);
156 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
157 gfx::PointF(), gfx::Size(), true, false);
[email protected]94f206c12012-08-25 00:09:14158
sunxdfd920f3f2016-04-05 16:17:51159 ExecuteCalculateDrawProperties(parent);
[email protected]94f206c12012-08-25 00:09:14160
sunxdfd920f3f2016-04-05 16:17:51161 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32162 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
sunxdfd920f3f2016-04-05 16:17:51163 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32164 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
sunxdfd920f3f2016-04-05 16:17:51165 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32166 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
sunxdfd920f3f2016-04-05 16:17:51167 grand_child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14168}
169
jaydasika322436372015-12-16 23:42:38170TEST_F(LayerTreeHostCommonTest, EffectTreeTransformIdTest) {
171 // Tests that effect tree node gets a valid transform id when a layer
172 // has opacity but doesn't create a render surface.
173 LayerImpl* parent = root_layer();
174 LayerImpl* child = AddChild<LayerImpl>(parent);
175 child->SetDrawsContent(true);
176
177 gfx::Transform identity_matrix;
178 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
179 gfx::PointF(), gfx::Size(100, 100), true, false);
180 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
181 gfx::PointF(10, 10), gfx::Size(100, 100), true,
182 false);
183 child->SetOpacity(0.f);
184 ExecuteCalculateDrawProperties(parent);
ajumae4af47062016-05-24 23:59:04185 EffectTree& effect_tree =
jaydasika322436372015-12-16 23:42:38186 parent->layer_tree_impl()->property_trees()->effect_tree;
187 EffectNode* node = effect_tree.Node(child->effect_tree_index());
188 const int transform_tree_size = parent->layer_tree_impl()
189 ->property_trees()
190 ->transform_tree.next_available_id();
191 EXPECT_LT(node->data.transform_id, transform_tree_size);
192}
193
[email protected]989386c2013-07-18 21:37:23194TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32195 gfx::Transform identity_matrix;
sunxdfd920f3f2016-04-05 16:17:51196 LayerImpl* root = root_layer();
197 LayerImpl* layer = AddChild<LayerImpl>(root);
[email protected]94f206c12012-08-25 00:09:14198
sunxdfd920f3f2016-04-05 16:17:51199 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31200 gfx::PointF(), gfx::Size(1, 2), true, false);
[email protected]ecc12622012-10-30 20:45:42201
sunxdfd920f3f2016-04-05 16:17:51202 TransformTree& tree =
203 host_impl()->active_tree()->property_trees()->transform_tree;
enne826452722015-08-18 22:22:31204
[email protected]fb661802013-03-25 01:59:32205 // Case 2: Setting the bounds of the layer should not affect either the draw
206 // transform or the screenspace transform.
207 gfx::Transform translation_to_center;
208 translation_to_center.Translate(5.0, 6.0);
sunxdfd920f3f2016-04-05 16:17:51209 SetLayerPropertiesForTesting(layer, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31210 gfx::PointF(), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51211 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31212 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51213 identity_matrix, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31214 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51215 identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14216
[email protected]fb661802013-03-25 01:59:32217 // Case 3: The anchor point by itself (without a layer transform) should have
218 // no effect on the transforms.
sunxdfd920f3f2016-04-05 16:17:51219 SetLayerPropertiesForTesting(layer, identity_matrix,
enne826452722015-08-18 22:22:31220 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
221 gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51222 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
223 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31224 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51225 identity_matrix, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31226 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51227 identity_matrix, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14228
[email protected]fb661802013-03-25 01:59:32229 // Case 4: A change in actual position affects both the draw transform and
230 // screen space transform.
231 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05232 position_transform.Translate(0.f, 1.2f);
enne826452722015-08-18 22:22:31233 SetLayerPropertiesForTesting(
sunxdfd920f3f2016-04-05 16:17:51234 layer, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
enne826452722015-08-18 22:22:31235 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51236 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
237 ExecuteCalculateDrawProperties(root);
238 EXPECT_TRANSFORMATION_MATRIX_EQ(
239 position_transform, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31240 EXPECT_TRANSFORMATION_MATRIX_EQ(
weiliangcc97575c2016-03-03 18:34:27241 position_transform,
sunxdfd920f3f2016-04-05 16:17:51242 draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14243
[email protected]fb661802013-03-25 01:59:32244 // Case 5: In the correct sequence of transforms, the layer transform should
245 // pre-multiply the translation_to_center. This is easily tested by using a
246 // scale transform, because scale and translation are not commutative.
247 gfx::Transform layer_transform;
248 layer_transform.Scale3d(2.0, 2.0, 1.0);
sunxdfd920f3f2016-04-05 16:17:51249 SetLayerPropertiesForTesting(layer, layer_transform, gfx::Point3F(),
enne826452722015-08-18 22:22:31250 gfx::PointF(), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51251 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
252 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31253 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51254 layer_transform, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31255 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51256 layer_transform, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14257
[email protected]fb661802013-03-25 01:59:32258 // Case 6: The layer transform should occur with respect to the anchor point.
259 gfx::Transform translation_to_anchor;
260 translation_to_anchor.Translate(5.0, 0.0);
261 gfx::Transform expected_result =
262 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
sunxdfd920f3f2016-04-05 16:17:51263 SetLayerPropertiesForTesting(layer, layer_transform,
enne826452722015-08-18 22:22:31264 gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(),
265 gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51266 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
267 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31268 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51269 expected_result, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31270 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51271 expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14272
[email protected]fb661802013-03-25 01:59:32273 // Case 7: Verify that position pre-multiplies the layer transform. The
274 // current implementation of CalculateDrawProperties does this implicitly, but
275 // it is still worth testing to detect accidental regressions.
276 expected_result = position_transform * translation_to_anchor *
277 layer_transform * Inverse(translation_to_anchor);
enne826452722015-08-18 22:22:31278 SetLayerPropertiesForTesting(
sunxdfd920f3f2016-04-05 16:17:51279 layer, layer_transform, gfx::Point3F(5.0f, 0.f, 0.f),
enne826452722015-08-18 22:22:31280 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51281 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
282 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31283 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51284 expected_result, draw_property_utils::DrawTransform(layer, tree));
enne826452722015-08-18 22:22:31285 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51286 expected_result, draw_property_utils::ScreenSpaceTransform(layer, tree));
[email protected]94f206c12012-08-25 00:09:14287}
288
[email protected]989386c2013-07-18 21:37:23289TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13290 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32291 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01292 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32293 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
294 -kScrollOffset.y());
jaydasikaa534a472016-03-31 01:12:16295 float page_scale = 0.888f;
[email protected]fb661802013-03-25 01:59:32296 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20297
khushalsagarb64b360d2015-10-21 19:25:16298 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:45299 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:56300 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:16301 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:56302 &task_graph_runner);
[email protected]657b24c2013-03-06 09:01:20303
[email protected]fb661802013-03-25 01:59:32304 gfx::Transform identity_matrix;
danakj60bc3bc2016-04-09 00:24:48305 std::unique_ptr<LayerImpl> sublayer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32306 LayerImpl::Create(host_impl.active_tree(), 1));
307 LayerImpl* sublayer = sublayer_scoped_ptr.get();
jaydasika0d98ba92015-11-17 05:17:28308 sublayer->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:00309 SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(),
310 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:32311 false);
[email protected]657b24c2013-03-06 09:01:20312
danakj60bc3bc2016-04-09 00:24:48313 std::unique_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32314 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47315 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
awoloszyne83f28c2014-12-22 15:40:00316 SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(),
317 gfx::PointF(), gfx::Size(10, 20), true, false,
[email protected]fb661802013-03-25 01:59:32318 false);
danakj60bc3bc2016-04-09 00:24:48319 std::unique_ptr<LayerImpl> clip_layer_scoped_ptr(
[email protected]adeda572014-01-31 00:49:47320 LayerImpl::Create(host_impl.active_tree(), 4));
321 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
322
323 scroll_layer->SetScrollClipLayer(clip_layer->id());
324 clip_layer->SetBounds(
325 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
326 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
327 scroll_layer->SetScrollClipLayer(clip_layer->id());
sunxdb7e79432016-03-09 21:13:42328 SetScrollOffsetDelta(scroll_layer, kScrollDelta);
[email protected]fb661802013-03-25 01:59:32329 gfx::Transform impl_transform;
danakja04855a2015-11-18 20:39:10330 scroll_layer->AddChild(std::move(sublayer_scoped_ptr));
[email protected]adeda572014-01-31 00:49:47331 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
danakja04855a2015-11-18 20:39:10332 clip_layer->AddChild(std::move(scroll_layer_scoped_ptr));
sunxdb7e79432016-03-09 21:13:42333 scroll_layer_raw_ptr->layer_tree_impl()
334 ->property_trees()
335 ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer_raw_ptr->id(),
336 kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20337
danakj60bc3bc2016-04-09 00:24:48338 std::unique_ptr<LayerImpl> root(
339 LayerImpl::Create(host_impl.active_tree(), 3));
awoloszyne83f28c2014-12-22 15:40:00340 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
341 gfx::PointF(), gfx::Size(3, 4), true, false,
[email protected]fb661802013-03-25 01:59:32342 false);
danakja04855a2015-11-18 20:39:10343 root->AddChild(std::move(clip_layer_scoped_ptr));
awoloszyne83f28c2014-12-22 15:40:00344 root->SetHasRenderSurface(true);
jaydasika2411692c2016-03-23 01:56:09345 LayerImpl* root_layer = root.get();
346 host_impl.active_tree()->SetRootLayer(std::move(root));
[email protected]657b24c2013-03-06 09:01:20347
jaydasikaa534a472016-03-31 01:12:16348 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
jaydasika2411692c2016-03-23 01:56:09349 scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32350 gfx::Transform expected_transform = identity_matrix;
351 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
danakj2c8d12c2015-06-18 06:15:33352 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
jaydasikaa534a472016-03-31 01:12:16353 page_scale * kDeviceScale),
danakj2c8d12c2015-06-18 06:15:33354 MathUtil::Round(sub_layer_screen_position.y() *
jaydasikaa534a472016-03-31 01:12:16355 page_scale * kDeviceScale));
356 expected_transform.Scale(page_scale * kDeviceScale,
357 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32358 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44359 sublayer->DrawTransform());
[email protected]fb661802013-03-25 01:59:32360 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumab6aa1c62015-12-01 21:01:10361 sublayer->ScreenSpaceTransform());
[email protected]657b24c2013-03-06 09:01:20362
[email protected]fb661802013-03-25 01:59:32363 gfx::Transform arbitrary_translate;
364 const float kTranslateX = 10.6f;
365 const float kTranslateY = 20.6f;
366 arbitrary_translate.Translate(kTranslateX, kTranslateY);
awoloszyne83f28c2014-12-22 15:40:00367 SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate,
368 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
369 true, false, false);
jaydasika2411692c2016-03-23 01:56:09370 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikaa534a472016-03-31 01:12:16371 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
jaydasika2411692c2016-03-23 01:56:09372 scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32373 expected_transform.MakeIdentity();
374 expected_transform.Translate(
jaydasikaa534a472016-03-31 01:12:16375 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
376 sub_layer_screen_position.x() * page_scale *
danakj2c8d12c2015-06-18 06:15:33377 kDeviceScale),
jaydasikaa534a472016-03-31 01:12:16378 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
379 sub_layer_screen_position.y() * page_scale *
danakj2c8d12c2015-06-18 06:15:33380 kDeviceScale));
jaydasikaa534a472016-03-31 01:12:16381 expected_transform.Scale(page_scale * kDeviceScale,
382 page_scale * kDeviceScale);
383 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
384 sublayer->DrawTransform());
385
386 // Test that page scale is updated even when we don't rebuild property trees.
387 page_scale = 1.888f;
388 root_layer->layer_tree_impl()->SetViewportLayersFromIds(
389 Layer::INVALID_ID, scroll_layer->parent()->id(), Layer::INVALID_ID,
390 Layer::INVALID_ID);
391 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale);
392 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild);
393 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale,
394 scroll_layer->parent());
395
396 expected_transform.MakeIdentity();
397 expected_transform.Translate(
398 MathUtil::Round(kTranslateX * page_scale * kDeviceScale +
399 sub_layer_screen_position.x() * page_scale *
400 kDeviceScale),
401 MathUtil::Round(kTranslateY * page_scale * kDeviceScale +
402 sub_layer_screen_position.y() * page_scale *
403 kDeviceScale));
404 expected_transform.Scale(page_scale * kDeviceScale,
405 page_scale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32406 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44407 sublayer->DrawTransform());
[email protected]657b24c2013-03-06 09:01:20408}
409
[email protected]989386c2013-07-18 21:37:23410TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32411 gfx::Transform identity_matrix;
sunxdfd920f3f2016-04-05 16:17:51412 LayerImpl* root = root_layer();
413 LayerImpl* parent = AddChild<LayerImpl>(root);
414 LayerImpl* child = AddChild<LayerImpl>(parent);
415 LayerImpl* grand_child = AddChild<LayerImpl>(child);
[email protected]d600df7d2013-08-03 02:34:28416
[email protected]fb661802013-03-25 01:59:32417 // One-time setup of root layer
sunxdfd920f3f2016-04-05 16:17:51418 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31419 gfx::PointF(), gfx::Size(1, 2), true, false);
420
sunxdfd920f3f2016-04-05 16:17:51421 TransformTree& tree =
422 host_impl()->active_tree()->property_trees()->transform_tree;
[email protected]ecc12622012-10-30 20:45:42423
[email protected]fb661802013-03-25 01:59:32424 // Case 1: parent's anchor point should not affect child or grand_child.
sunxdfd920f3f2016-04-05 16:17:51425 SetLayerPropertiesForTesting(parent, identity_matrix,
enne826452722015-08-18 22:22:31426 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
427 gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51428 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31429 gfx::PointF(), gfx::Size(16, 18), true, false);
sunxdfd920f3f2016-04-05 16:17:51430 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
431 gfx::PointF(), gfx::Size(76, 78), true, false);
432 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31433
434 EXPECT_TRANSFORMATION_MATRIX_EQ(
sunxdfd920f3f2016-04-05 16:17:51435 identity_matrix, draw_property_utils::DrawTransform(child, tree));
436 EXPECT_TRANSFORMATION_MATRIX_EQ(
437 identity_matrix, draw_property_utils::ScreenSpaceTransform(child, tree));
438 EXPECT_TRANSFORMATION_MATRIX_EQ(
439 identity_matrix, draw_property_utils::DrawTransform(grand_child, tree));
enne826452722015-08-18 22:22:31440 EXPECT_TRANSFORMATION_MATRIX_EQ(
441 identity_matrix,
sunxdfd920f3f2016-04-05 16:17:51442 draw_property_utils::ScreenSpaceTransform(grand_child, tree));
[email protected]94f206c12012-08-25 00:09:14443
[email protected]fb661802013-03-25 01:59:32444 // Case 2: parent's position affects child and grand_child.
445 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05446 parent_position_transform.Translate(0.f, 1.2f);
enne826452722015-08-18 22:22:31447 SetLayerPropertiesForTesting(
sunxdfd920f3f2016-04-05 16:17:51448 parent, identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
enne826452722015-08-18 22:22:31449 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51450 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31451 gfx::PointF(), gfx::Size(16, 18), true, false);
sunxdfd920f3f2016-04-05 16:17:51452 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
453 gfx::PointF(), gfx::Size(76, 78), true, false);
454 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
455 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31456 EXPECT_TRANSFORMATION_MATRIX_EQ(
457 parent_position_transform,
sunxdfd920f3f2016-04-05 16:17:51458 draw_property_utils::DrawTransform(child, tree));
enne826452722015-08-18 22:22:31459 EXPECT_TRANSFORMATION_MATRIX_EQ(
460 parent_position_transform,
sunxdfd920f3f2016-04-05 16:17:51461 draw_property_utils::ScreenSpaceTransform(child, tree));
enne826452722015-08-18 22:22:31462 EXPECT_TRANSFORMATION_MATRIX_EQ(
463 parent_position_transform,
sunxdfd920f3f2016-04-05 16:17:51464 draw_property_utils::DrawTransform(grand_child, tree));
enne826452722015-08-18 22:22:31465 EXPECT_TRANSFORMATION_MATRIX_EQ(
466 parent_position_transform,
sunxdfd920f3f2016-04-05 16:17:51467 draw_property_utils::ScreenSpaceTransform(grand_child, tree));
[email protected]94f206c12012-08-25 00:09:14468
[email protected]fb661802013-03-25 01:59:32469 // Case 3: parent's local transform affects child and grandchild
470 gfx::Transform parent_layer_transform;
471 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
472 gfx::Transform parent_translation_to_anchor;
473 parent_translation_to_anchor.Translate(2.5, 3.0);
474 gfx::Transform parent_composite_transform =
475 parent_translation_to_anchor * parent_layer_transform *
476 Inverse(parent_translation_to_anchor);
sunxdfd920f3f2016-04-05 16:17:51477 SetLayerPropertiesForTesting(parent, parent_layer_transform,
enne826452722015-08-18 22:22:31478 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
479 gfx::Size(10, 12), true, false);
sunxdfd920f3f2016-04-05 16:17:51480 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
enne826452722015-08-18 22:22:31481 gfx::PointF(), gfx::Size(16, 18), true, false);
sunxdfd920f3f2016-04-05 16:17:51482 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
483 gfx::PointF(), gfx::Size(76, 78), true, false);
484 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
485 ExecuteCalculateDrawProperties(root);
enne826452722015-08-18 22:22:31486 EXPECT_TRANSFORMATION_MATRIX_EQ(
487 parent_composite_transform,
sunxdfd920f3f2016-04-05 16:17:51488 draw_property_utils::DrawTransform(child, tree));
enne826452722015-08-18 22:22:31489 EXPECT_TRANSFORMATION_MATRIX_EQ(
490 parent_composite_transform,
sunxdfd920f3f2016-04-05 16:17:51491 draw_property_utils::ScreenSpaceTransform(child, tree));
enne826452722015-08-18 22:22:31492 EXPECT_TRANSFORMATION_MATRIX_EQ(
493 parent_composite_transform,
sunxdfd920f3f2016-04-05 16:17:51494 draw_property_utils::DrawTransform(grand_child, tree));
enne826452722015-08-18 22:22:31495 EXPECT_TRANSFORMATION_MATRIX_EQ(
496 parent_composite_transform,
sunxdfd920f3f2016-04-05 16:17:51497 draw_property_utils::ScreenSpaceTransform(grand_child, tree));
[email protected]94f206c12012-08-25 00:09:14498}
499
[email protected]989386c2013-07-18 21:37:23500TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
enne25dea3f2015-07-27 16:44:28501 LayerImpl* root = root_layer();
502 LayerImpl* parent = AddChildToRoot<LayerImpl>();
503 LayerImpl* child = AddChild<LayerImpl>(parent);
504 LayerImpl* grand_child = AddChild<LayerImpl>(child);
505 grand_child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:14506
[email protected]fb661802013-03-25 01:59:32507 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28508 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
509 gfx::PointF(), gfx::Size(1, 2), true, false,
510 true);
[email protected]ecc12622012-10-30 20:45:42511
[email protected]fb661802013-03-25 01:59:32512 // Child is set up so that a new render surface should be created.
513 child->SetOpacity(0.5f);
jaydasika8640f9f2015-11-10 01:34:36514 child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:14515
[email protected]fb661802013-03-25 01:59:32516 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05517 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32518 gfx::Transform parent_translation_to_anchor;
519 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44520
[email protected]fb661802013-03-25 01:59:32521 gfx::Transform parent_composite_transform =
522 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39523 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32524 gfx::Vector2dF parent_composite_scale =
525 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
526 1.f);
527 gfx::Transform surface_sublayer_transform;
528 surface_sublayer_transform.Scale(parent_composite_scale.x(),
529 parent_composite_scale.y());
530 gfx::Transform surface_sublayer_composite_transform =
531 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14532
enne25dea3f2015-07-27 16:44:28533 SetLayerPropertiesForTesting(parent, parent_layer_transform,
534 gfx::Point3F(25.0f, 30.0f, 0.f), gfx::PointF(),
535 gfx::Size(100, 120), true, false, false);
536 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
537 gfx::PointF(), gfx::Size(16, 18), true, false,
538 true);
539 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
540 gfx::PointF(), gfx::Size(8, 10), true, false,
[email protected]fb661802013-03-25 01:59:32541 false);
enne25dea3f2015-07-27 16:44:28542 ExecuteCalculateDrawProperties(root);
[email protected]94f206c12012-08-25 00:09:14543
[email protected]fb661802013-03-25 01:59:32544 // Render surface should have been created now.
545 ASSERT_TRUE(child->render_surface());
weiliangc189c1a12016-04-11 16:16:25546 ASSERT_EQ(child->render_surface(), child->render_target());
[email protected]94f206c12012-08-25 00:09:14547
[email protected]fb661802013-03-25 01:59:32548 // The child layer's draw transform should refer to its new render surface.
549 // The screen-space transform, however, should still refer to the root.
550 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
ajumad9432e32015-11-30 19:43:44551 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32552 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
ajumab6aa1c62015-12-01 21:01:10553 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:14554
[email protected]fb661802013-03-25 01:59:32555 // Because the grand_child is the only drawable content, the child's render
556 // surface will tighten its bounds to the grand_child. The scale at which the
557 // surface's subtree is drawn must be removed from the composite transform.
weiliangc189c1a12016-04-11 16:16:25558 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_composite_transform,
559 child->render_target()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14560
[email protected]fb661802013-03-25 01:59:32561 // The screen space is the same as the target since the child surface draws
562 // into the root.
563 EXPECT_TRANSFORMATION_MATRIX_EQ(
564 surface_sublayer_composite_transform,
weiliangc189c1a12016-04-11 16:16:25565 child->render_target()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14566}
567
ajuma51d73f72015-10-19 19:43:58568TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) {
569 LayerImpl* root = root_layer();
570 LayerImpl* parent = AddChildToRoot<LayerImpl>();
571 LayerImpl* child = AddChild<LayerImpl>(parent);
572 LayerImpl* grand_child = AddChild<LayerImpl>(child);
573 grand_child->SetDrawsContent(true);
574
575 gfx::Transform identity_matrix;
576 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
577 gfx::PointF(), gfx::Size(100, 100), true, false,
578 true);
579
580 gfx::Transform parent_transform;
581 parent_transform.Translate(10.0, 10.0);
582
583 gfx::Transform child_transform;
584 child_transform.Rotate(45.0);
585
586 // child gets a render surface when surfaces are enabled.
587 SetLayerPropertiesForTesting(parent, parent_transform, gfx::Point3F(),
588 gfx::PointF(), gfx::Size(10, 10), true, false,
589 false);
590 SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(),
591 gfx::PointF(), gfx::Size(10, 10), true, false,
592 true);
593 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
594 gfx::PointF(2.0, 2.0), gfx::Size(20, 20), true,
595 false, false);
596
597 gfx::Transform expected_grand_child_screen_space_transform;
598 expected_grand_child_screen_space_transform.Translate(10.0, 10.0);
599 expected_grand_child_screen_space_transform.Rotate(45.0);
600 expected_grand_child_screen_space_transform.Translate(2.0, 2.0);
601
602 // First compute draw properties with separate surfaces enabled.
603 ExecuteCalculateDrawProperties(root);
604
605 // The grand child's draw transform should be its offset wrt the child.
606 gfx::Transform expected_grand_child_draw_transform;
607 expected_grand_child_draw_transform.Translate(2.0, 2.0);
608 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44609 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58610 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10611 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58612
613 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
614
615 // With separate surfaces disabled, the grand child's draw transform should be
616 // the same as its screen space transform.
617 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumad9432e32015-11-30 19:43:44618 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58619 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:10620 grand_child->ScreenSpaceTransform());
ajuma51d73f72015-10-19 19:43:58621}
622
[email protected]989386c2013-07-18 21:37:23623TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
enne25dea3f2015-07-27 16:44:28624 LayerImpl* root = root_layer();
625 LayerImpl* parent = AddChildToRoot<LayerImpl>();
626 LayerImpl* child = AddChild<LayerImpl>(parent);
627 LayerImpl* grand_child = AddChild<LayerImpl>(child);
628 grand_child->SetDrawsContent(true);
danakj60bc3bc2016-04-09 00:24:48629 std::unique_ptr<LayerImpl> child_replica =
enne25dea3f2015-07-27 16:44:28630 LayerImpl::Create(host_impl()->active_tree(), 100);
[email protected]d600df7d2013-08-03 02:34:28631
[email protected]fb661802013-03-25 01:59:32632 // One-time setup of root layer
633 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28634 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
635 gfx::PointF(), gfx::Size(1, 2), true, false,
636 true);
[email protected]fb661802013-03-25 01:59:32637
638 // Child is set up so that a new render surface should be created.
639 child->SetOpacity(0.5f);
640
641 gfx::Transform parent_layer_transform;
642 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
643 gfx::Transform parent_translation_to_anchor;
644 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32645 gfx::Transform parent_composite_transform =
646 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39647 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32648 gfx::Transform replica_layer_transform;
649 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
650 gfx::Vector2dF parent_composite_scale =
651 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
652 1.f);
653 gfx::Transform surface_sublayer_transform;
654 surface_sublayer_transform.Scale(parent_composite_scale.x(),
655 parent_composite_scale.y());
656 gfx::Transform replica_composite_transform =
657 parent_composite_transform * replica_layer_transform *
658 Inverse(surface_sublayer_transform);
enne25dea3f2015-07-27 16:44:28659 child_replica->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32660 // Child's render surface should not exist yet.
661 ASSERT_FALSE(child->render_surface());
662
enne25dea3f2015-07-27 16:44:28663 SetLayerPropertiesForTesting(parent, parent_layer_transform,
664 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
665 gfx::Size(10, 12), true, false, false);
666 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
667 gfx::PointF(), gfx::Size(16, 18), true, false,
668 true);
669 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
670 gfx::PointF(-0.5f, -0.5f), gfx::Size(1, 1), true,
671 false, false);
672 SetLayerPropertiesForTesting(child_replica.get(), replica_layer_transform,
673 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
674 false, false);
danakja04855a2015-11-18 20:39:10675 child->SetReplicaLayer(std::move(child_replica));
enne25dea3f2015-07-27 16:44:28676
677 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32678
679 // Render surface should have been created now.
680 ASSERT_TRUE(child->render_surface());
weiliangc189c1a12016-04-11 16:16:25681 ASSERT_EQ(child->render_surface(), child->render_target());
[email protected]fb661802013-03-25 01:59:32682
683 EXPECT_TRANSFORMATION_MATRIX_EQ(
684 replica_composite_transform,
weiliangc189c1a12016-04-11 16:16:25685 child->render_target()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:32686 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57687 child->render_target()
[email protected]fb661802013-03-25 01:59:32688 ->replica_screen_space_transform());
689}
690
[email protected]989386c2013-07-18 21:37:23691TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32692 // This test creates a more complex tree and verifies it all at once. This
693 // covers the following cases:
694 // - layers that are described w.r.t. a render surface: should have draw
695 // transforms described w.r.t. that surface
696 // - A render surface described w.r.t. an ancestor render surface: should
697 // have a draw transform described w.r.t. that ancestor surface
698 // - Replicas of a render surface are described w.r.t. the replica's
699 // transform around its anchor, along with the surface itself.
700 // - Sanity check on recursion: verify transforms of layers described w.r.t.
701 // a render surface that is described w.r.t. an ancestor render surface.
702 // - verifying that each layer has a reference to the correct render surface
703 // and render target values.
704
enne25dea3f2015-07-27 16:44:28705 LayerImpl* root = root_layer();
706 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36707 parent->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28708 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36709 render_surface1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28710 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36711 render_surface2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28712 LayerImpl* child_of_root = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36713 child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28714 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36715 child_of_rs1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28716 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:36717 child_of_rs2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28718 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
jaydasika8640f9f2015-11-10 01:34:36719 grand_child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28720 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
721 grand_child_of_rs1->SetDrawsContent(true);
722 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
723 grand_child_of_rs2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32724
danakj60bc3bc2016-04-09 00:24:48725 std::unique_ptr<LayerImpl> replica_of_rs1 =
enne25dea3f2015-07-27 16:44:28726 LayerImpl::Create(host_impl()->active_tree(), 101);
danakj60bc3bc2016-04-09 00:24:48727 std::unique_ptr<LayerImpl> replica_of_rs2 =
enne25dea3f2015-07-27 16:44:28728 LayerImpl::Create(host_impl()->active_tree(), 102);
[email protected]d600df7d2013-08-03 02:34:28729
[email protected]fb661802013-03-25 01:59:32730 // In combination with descendant draws content, opacity != 1 forces the layer
731 // to have a new render surface.
732 render_surface1->SetOpacity(0.5f);
733 render_surface2->SetOpacity(0.33f);
734
735 // One-time setup of root layer
736 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28737 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
738 gfx::PointF(), gfx::Size(1, 2), true, false,
739 true);
[email protected]fb661802013-03-25 01:59:32740
741 // All layers in the tree are initialized with an anchor at .25 and a size of
742 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39743 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32744 gfx::Transform translation_to_anchor;
745 translation_to_anchor.Translate(2.5, 0.0);
746 gfx::Transform layer_transform;
747 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32748 gfx::Transform replica_layer_transform;
749 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
750
751 gfx::Transform A =
752 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32753 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
754 Inverse(translation_to_anchor);
755
756 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39757 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32758 gfx::Transform surface1_sublayer_transform;
759 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
760 surface1_parent_transform_scale.y());
761
762 // SS1 = transform given to the subtree of render_surface1
763 gfx::Transform SS1 = surface1_sublayer_transform;
764 // S1 = transform to move from render_surface1 pixels to the layer space of
765 // the owning layer
766 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
767
768 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39769 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32770 gfx::Transform surface2_sublayer_transform;
771 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
772 surface2_parent_transform_scale.y());
773
774 // SS2 = transform given to the subtree of render_surface2
775 gfx::Transform SS2 = surface2_sublayer_transform;
776 // S2 = transform to move from render_surface2 pixels to the layer space of
777 // the owning layer
778 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
779
enne25dea3f2015-07-27 16:44:28780 SetLayerPropertiesForTesting(parent, layer_transform,
781 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
782 gfx::Size(10, 10), true, false, false);
783 SetLayerPropertiesForTesting(render_surface1, layer_transform,
784 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
785 gfx::Size(10, 10), true, false, true);
786 SetLayerPropertiesForTesting(render_surface2, layer_transform,
787 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
788 gfx::Size(10, 10), true, false, true);
789 SetLayerPropertiesForTesting(child_of_root, layer_transform,
790 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
791 gfx::Size(10, 10), true, false, false);
792 SetLayerPropertiesForTesting(child_of_rs1, layer_transform,
793 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
794 gfx::Size(10, 10), true, false, false);
795 SetLayerPropertiesForTesting(child_of_rs2, layer_transform,
796 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
797 gfx::Size(10, 10), true, false, false);
798 SetLayerPropertiesForTesting(grand_child_of_root, layer_transform,
799 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
800 gfx::Size(10, 10), true, false, false);
801 SetLayerPropertiesForTesting(grand_child_of_rs1, layer_transform,
802 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
803 gfx::Size(10, 10), true, false, false);
804 SetLayerPropertiesForTesting(grand_child_of_rs2, layer_transform,
805 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
806 gfx::Size(10, 10), true, false, false);
807 SetLayerPropertiesForTesting(replica_of_rs1.get(), replica_layer_transform,
808 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
809 gfx::Size(), true, false, false);
810 SetLayerPropertiesForTesting(replica_of_rs2.get(), replica_layer_transform,
811 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
812 gfx::Size(), true, false, false);
[email protected]fb661802013-03-25 01:59:32813
jaydasika5017a332016-03-31 01:06:22814 // We need to set parent on replica layers for property tree building.
815 replica_of_rs1->SetParent(render_surface1);
816 replica_of_rs2->SetParent(render_surface2);
danakja04855a2015-11-18 20:39:10817 render_surface1->SetReplicaLayer(std::move(replica_of_rs1));
818 render_surface2->SetReplicaLayer(std::move(replica_of_rs2));
enne25dea3f2015-07-27 16:44:28819 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32820
821 // Only layers that are associated with render surfaces should have an actual
822 // RenderSurface() value.
823 ASSERT_TRUE(root->render_surface());
824 ASSERT_FALSE(child_of_root->render_surface());
825 ASSERT_FALSE(grand_child_of_root->render_surface());
826
827 ASSERT_TRUE(render_surface1->render_surface());
828 ASSERT_FALSE(child_of_rs1->render_surface());
829 ASSERT_FALSE(grand_child_of_rs1->render_surface());
830
831 ASSERT_TRUE(render_surface2->render_surface());
832 ASSERT_FALSE(child_of_rs2->render_surface());
833 ASSERT_FALSE(grand_child_of_rs2->render_surface());
834
835 // Verify all render target accessors
weiliangc189c1a12016-04-11 16:16:25836 EXPECT_EQ(root->render_surface(), parent->render_target());
837 EXPECT_EQ(root->render_surface(), child_of_root->render_target());
838 EXPECT_EQ(root->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32839
weiliangc189c1a12016-04-11 16:16:25840 EXPECT_EQ(render_surface1->render_surface(),
841 render_surface1->render_target());
842 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
843 EXPECT_EQ(render_surface1->render_surface(),
844 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32845
weiliangc189c1a12016-04-11 16:16:25846 EXPECT_EQ(render_surface2->render_surface(),
847 render_surface2->render_target());
848 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
849 EXPECT_EQ(render_surface2->render_surface(),
850 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32851
852 // Verify layer draw transforms note that draw transforms are described with
853 // respect to the nearest ancestor render surface but screen space transforms
854 // are described with respect to the root.
ajumad9432e32015-11-30 19:43:44855 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform());
856 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39857 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumad9432e32015-11-30 19:43:44858 grand_child_of_root->DrawTransform());
[email protected]fb661802013-03-25 01:59:32859
ajumad9432e32015-11-30 19:43:44860 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform());
861 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39862 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
ajumad9432e32015-11-30 19:43:44863 grand_child_of_rs1->DrawTransform());
[email protected]fb661802013-03-25 01:59:32864
ajumad9432e32015-11-30 19:43:44865 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform());
866 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39867 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
ajumad9432e32015-11-30 19:43:44868 grand_child_of_rs2->DrawTransform());
[email protected]fb661802013-03-25 01:59:32869
870 // Verify layer screen-space transforms
871 //
ajumab6aa1c62015-12-01 21:01:10872 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->ScreenSpaceTransform());
873 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->ScreenSpaceTransform());
874 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
875 grand_child_of_root->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32876
[email protected]baf64d062014-02-16 22:10:39877 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
ajumab6aa1c62015-12-01 21:01:10878 render_surface1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39879 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10880 child_of_rs1->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39881 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10882 grand_child_of_rs1->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32883
[email protected]baf64d062014-02-16 22:10:39884 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumab6aa1c62015-12-01 21:01:10885 render_surface2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39886 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10887 child_of_rs2->ScreenSpaceTransform());
[email protected]baf64d062014-02-16 22:10:39888 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
ajumab6aa1c62015-12-01 21:01:10889 grand_child_of_rs2->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:32890
891 // Verify render surface transforms.
892 //
893 // Draw transform of render surface 1 is described with respect to root.
894 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39895 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32896 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39897 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:32898 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39899 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32900 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39901 A * R * S1,
[email protected]fb661802013-03-25 01:59:32902 render_surface1->render_surface()->replica_screen_space_transform());
903 // Draw transform of render surface 2 is described with respect to render
904 // surface 1.
905 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39906 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32907 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39908 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:32909 render_surface2->render_surface()->replica_draw_transform());
910 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39911 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:32912 render_surface2->render_surface()->screen_space_transform());
913 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39914 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:32915 render_surface2->render_surface()->replica_screen_space_transform());
916
917 // Sanity check. If these fail there is probably a bug in the test itself. It
918 // is expected that we correctly set up transforms so that the y-component of
919 // the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:10920 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:26921 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:10922 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32923 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10924 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32925
[email protected]803f6b52013-09-12 00:51:26926 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:10927 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
928 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32929 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10930 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32931
[email protected]803f6b52013-09-12 00:51:26932 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:10933 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
934 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32935 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:10936 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32937}
938
[email protected]989386c2013-07-18 21:37:23939TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:32940 // For layers that flatten their subtree, there should be an orthographic
941 // projection (for x and y values) in the middle of the transform sequence.
942 // Note that the way the code is currently implemented, it is not expected to
943 // use a canonical orthographic projection.
944
enne25dea3f2015-07-27 16:44:28945 LayerImpl* root = root_layer();
946 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36947 child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28948 LayerImpl* grand_child = AddChild<LayerImpl>(child);
949 grand_child->SetDrawsContent(true);
950 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
951 great_grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32952
953 gfx::Transform rotation_about_y_axis;
954 rotation_about_y_axis.RotateAboutYAxis(30.0);
955
956 const gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28957 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
958 gfx::PointF(), gfx::Size(100, 100), true, false,
959 true);
960 SetLayerPropertiesForTesting(child, rotation_about_y_axis, gfx::Point3F(),
961 gfx::PointF(), gfx::Size(10, 10), true, false,
962 true);
963 SetLayerPropertiesForTesting(grand_child, rotation_about_y_axis,
ajumad0d64422015-03-14 04:20:08964 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
enne25dea3f2015-07-27 16:44:28965 true, false, false);
966 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
967 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
968 true, false, false);
[email protected]d600df7d2013-08-03 02:34:28969
[email protected]fb661802013-03-25 01:59:32970 // No layers in this test should preserve 3d.
jaydasikaca2605e2016-04-23 02:52:52971 ASSERT_TRUE(root->test_properties()->should_flatten_transform);
972 ASSERT_TRUE(child->test_properties()->should_flatten_transform);
973 ASSERT_TRUE(grand_child->test_properties()->should_flatten_transform);
974 ASSERT_TRUE(great_grand_child->test_properties()->should_flatten_transform);
[email protected]fb661802013-03-25 01:59:32975
976 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
977 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
978 gfx::Transform expected_grand_child_draw_transform =
979 rotation_about_y_axis; // draws onto child's render surface
980 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
981 flattened_rotation_about_y.FlattenTo2d();
982 gfx::Transform expected_grand_child_screen_space_transform =
983 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:08984 gfx::Transform expected_great_grand_child_draw_transform =
985 flattened_rotation_about_y;
986 gfx::Transform expected_great_grand_child_screen_space_transform =
987 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:32988
enne25dea3f2015-07-27 16:44:28989 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32990
991 // The child's draw transform should have been taken by its surface.
992 ASSERT_TRUE(child->render_surface());
993 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
994 child->render_surface()->draw_transform());
995 EXPECT_TRANSFORMATION_MATRIX_EQ(
996 expected_child_screen_space_transform,
997 child->render_surface()->screen_space_transform());
ajumad9432e32015-11-30 19:43:44998 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32999 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101000 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321001 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441002 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321003 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101004 grand_child->ScreenSpaceTransform());
ajumad0d64422015-03-14 04:20:081005 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:441006 great_grand_child->DrawTransform());
ajumad0d64422015-03-14 04:20:081007 EXPECT_TRANSFORMATION_MATRIX_EQ(
1008 expected_great_grand_child_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:101009 great_grand_child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:321010}
1011
ajumadbd92cb2015-07-16 13:47:061012TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
jaydasika6f972de2016-04-07 16:16:141013 LayerImpl* root = root_layer();
1014 LayerImpl* child = AddChild<LayerImpl>(root);
1015 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajumadbd92cb2015-07-16 13:47:061016
1017 gfx::Transform child_transform;
1018 child_transform.Translate(50.0, 50.0);
1019 child_transform.RotateAboutZAxis(30.0);
1020
1021 gfx::Transform grand_child_transform;
1022 grand_child_transform.RotateAboutYAxis(90.0);
1023
1024 const gfx::Transform identity_matrix;
jaydasika6f972de2016-04-07 16:16:141025 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1026 gfx::PointF(), gfx::Size(200, 200), true, false,
1027 true);
1028 SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(),
1029 gfx::PointF(), gfx::Size(10, 10), true, false,
1030 false);
1031 SetLayerPropertiesForTesting(grand_child, grand_child_transform,
ajumadbd92cb2015-07-16 13:47:061032 gfx::Point3F(), gfx::PointF(),
jaydasika6f972de2016-04-07 16:16:141033 gfx::Size(100, 100), true, false, false);
ajumadbd92cb2015-07-16 13:47:061034
jaydasikaca2605e2016-04-23 02:52:521035 grand_child->test_properties()->should_flatten_transform = false;
jaydasika6f972de2016-04-07 16:16:141036 grand_child->SetDrawsContent(true);
ajumadbd92cb2015-07-16 13:47:061037
jaydasika6f972de2016-04-07 16:16:141038 ExecuteCalculateDrawProperties(root);
ajumadbd92cb2015-07-16 13:47:061039
1040 // Mapping grand_child's bounds to target space produces a non-empty rect
1041 // that is fully contained within the target's bounds, so grand_child should
1042 // be considered fully visible.
1043 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
jaydasika6f972de2016-04-07 16:16:141044 grand_child->visible_layer_rect());
ajumadbd92cb2015-07-16 13:47:061045}
1046
[email protected]989386c2013-07-18 21:37:231047TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321048 // A layer that is empty in one axis, but not the other, was accidentally
1049 // skipping a necessary translation. Without that translation, the coordinate
1050 // space of the layer's draw transform is incorrect.
1051 //
1052 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1053 // but if that layer becomes a render surface, then its draw transform is
1054 // implicitly inherited by the rest of the subtree, which then is positioned
1055 // incorrectly as a result.
1056
ennec1332992015-08-24 19:45:091057 LayerImpl* root = root_layer();
1058 LayerImpl* child = AddChild<LayerImpl>(root);
1059 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1060 grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321061
1062 // The child height is zero, but has non-zero width that should be accounted
1063 // for while computing draw transforms.
1064 const gfx::Transform identity_matrix;
ennec1332992015-08-24 19:45:091065 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1066 gfx::PointF(), gfx::Size(100, 100), true, false,
1067 true);
1068 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1069 gfx::PointF(), gfx::Size(10, 0), true, false,
1070 true);
1071 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1072 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321073 false);
1074
ennec1332992015-08-24 19:45:091075 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321076
ennec1332992015-08-24 19:45:091077 ASSERT_TRUE(child->has_render_surface());
[email protected]fb661802013-03-25 01:59:321078 // This is the real test, the rest are sanity checks.
1079 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1080 child->render_surface()->draw_transform());
ajumad9432e32015-11-30 19:43:441081 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321082 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
ajumad9432e32015-11-30 19:43:441083 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321084}
1085
jaydasika9bbee9b2016-01-13 00:36:481086TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) {
1087 const gfx::Transform identity_matrix;
1088 LayerImpl* root = root_layer();
1089 LayerImpl* render_surface = AddChild<LayerImpl>(root);
1090 LayerImpl* child = AddChild<LayerImpl>(render_surface);
1091 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1092
1093 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1094 gfx::PointF(), gfx::Size(100, 100), true, false,
1095 true);
1096 gfx::Transform translate;
1097 translate.Translate3d(5, 5, 5);
1098 SetLayerPropertiesForTesting(render_surface, translate, gfx::Point3F(),
1099 gfx::PointF(), gfx::Size(100, 100), true, false,
1100 true);
1101 SetLayerPropertiesForTesting(child, translate, gfx::Point3F(), gfx::PointF(),
1102 gfx::Size(100, 100), true, false, false);
1103 SetLayerPropertiesForTesting(grand_child, translate, gfx::Point3F(),
1104 gfx::PointF(), gfx::Size(100, 100), true, false,
1105 false);
1106 grand_child->SetDrawsContent(true);
1107
1108 // render_surface will have a sublayer scale because of device scale factor.
1109 float device_scale_factor = 2.0f;
1110 LayerImplList render_surface_layer_list_impl;
jaydasika9bbee9b2016-01-13 00:36:481111 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381112 root, root->bounds(), translate, &render_surface_layer_list_impl);
jaydasika9bbee9b2016-01-13 00:36:481113 inputs.device_scale_factor = device_scale_factor;
1114 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571115 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika9bbee9b2016-01-13 00:36:481116
1117 // Between grand_child and render_surface, we translate by (10, 10) and scale
1118 // by a factor of 2.
1119 gfx::Vector2dF expected_translation(20.0f, 20.0f);
1120 EXPECT_EQ(grand_child->DrawTransform().To2dTranslation(),
1121 expected_translation);
1122}
1123
[email protected]989386c2013-07-18 21:37:231124TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321125 // Transformations applied at the root of the tree should be forwarded
1126 // to child layers instead of applied to the root RenderSurface.
1127 const gfx::Transform identity_matrix;
enned3f61fb02015-08-18 22:54:391128 LayerImpl* root = root_layer();
1129 root->SetDrawsContent(true);
1130 LayerImpl* child = AddChild<LayerImpl>(root);
1131 child->SetDrawsContent(true);
[email protected]f224cc92013-06-06 23:23:321132
enned3f61fb02015-08-18 22:54:391133 child->SetScrollClipLayer(root->id());
[email protected]d600df7d2013-08-03 02:34:281134
enned3f61fb02015-08-18 22:54:391135 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1136 gfx::PointF(), gfx::Size(20, 20), true, false,
1137 true);
1138 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1139 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]f224cc92013-06-06 23:23:321140 false);
1141
[email protected]f224cc92013-06-06 23:23:321142 gfx::Transform translate;
1143 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231144 {
enned3f61fb02015-08-18 22:54:391145 LayerImplList render_surface_layer_list_impl;
enned3f61fb02015-08-18 22:54:391146 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381147 root, root->bounds(), translate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321148 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571149 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231150 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1151 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1152 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1153 }
[email protected]f224cc92013-06-06 23:23:321154
1155 gfx::Transform scale;
1156 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231157 {
enned3f61fb02015-08-18 22:54:391158 LayerImplList render_surface_layer_list_impl;
enned3f61fb02015-08-18 22:54:391159 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381160 root, root->bounds(), scale, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321161 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571162 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231163 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1164 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1165 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1166 }
[email protected]f224cc92013-06-06 23:23:321167
1168 gfx::Transform rotate;
1169 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231170 {
enned3f61fb02015-08-18 22:54:391171 LayerImplList render_surface_layer_list_impl;
enned3f61fb02015-08-18 22:54:391172 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381173 root, root->bounds(), rotate, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321174 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571175 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231176 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1177 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1178 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1179 }
[email protected]f224cc92013-06-06 23:23:321180
1181 gfx::Transform composite;
1182 composite.ConcatTransform(translate);
1183 composite.ConcatTransform(scale);
1184 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231185 {
enned3f61fb02015-08-18 22:54:391186 LayerImplList render_surface_layer_list_impl;
enned3f61fb02015-08-18 22:54:391187 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381188 root, root->bounds(), composite, &render_surface_layer_list_impl);
vollick5057e1e2015-04-17 19:12:321189 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571190 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231191 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1192 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1193 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1194 }
[email protected]f224cc92013-06-06 23:23:321195
[email protected]9781afa2013-07-17 23:15:321196 // Verify it composes correctly with device scale.
1197 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231198
1199 {
enned3f61fb02015-08-18 22:54:391200 LayerImplList render_surface_layer_list_impl;
enned3f61fb02015-08-18 22:54:391201 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381202 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531203 inputs.device_scale_factor = device_scale_factor;
vollick5057e1e2015-04-17 19:12:321204 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571205 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231206 gfx::Transform device_scaled_translate = translate;
1207 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1208 EXPECT_EQ(device_scaled_translate,
1209 root->draw_properties().target_space_transform);
1210 EXPECT_EQ(device_scaled_translate,
1211 child->draw_properties().target_space_transform);
1212 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1213 }
[email protected]9781afa2013-07-17 23:15:321214
1215 // Verify it composes correctly with page scale.
1216 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231217
1218 {
enned3f61fb02015-08-18 22:54:391219 LayerImplList render_surface_layer_list_impl;
enned3f61fb02015-08-18 22:54:391220 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381221 root, root->bounds(), translate, &render_surface_layer_list_impl);
[email protected]7aad55f2013-07-26 11:25:531222 inputs.page_scale_factor = page_scale_factor;
enned3f61fb02015-08-18 22:54:391223 inputs.page_scale_layer = root;
vollick5057e1e2015-04-17 19:12:321224 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571225 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231226 gfx::Transform page_scaled_translate = translate;
1227 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
enne6394d5b42015-05-26 22:23:111228 EXPECT_EQ(page_scaled_translate,
1229 root->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231230 EXPECT_EQ(page_scaled_translate,
1231 child->draw_properties().target_space_transform);
1232 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1233 }
[email protected]9781afa2013-07-17 23:15:321234
[email protected]f224cc92013-06-06 23:23:321235 // Verify that it composes correctly with transforms directly on root layer.
1236 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231237
1238 {
enned3f61fb02015-08-18 22:54:391239 LayerImplList render_surface_layer_list_impl;
enned3f61fb02015-08-18 22:54:391240 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381241 root, root->bounds(), composite, &render_surface_layer_list_impl);
enned3f61fb02015-08-18 22:54:391242 inputs.property_trees->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:571243 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]989386c2013-07-18 21:37:231244 gfx::Transform compositeSquared = composite;
1245 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261246 EXPECT_TRANSFORMATION_MATRIX_EQ(
1247 compositeSquared, root->draw_properties().target_space_transform);
1248 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391249 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231250 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1251 }
[email protected]f224cc92013-06-06 23:23:321252}
1253
[email protected]989386c2013-07-18 21:37:231254TEST_F(LayerTreeHostCommonTest,
1255 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
enneea850232015-07-27 16:43:121256 LayerImpl* parent = root_layer();
1257 parent->SetMasksToBounds(true);
1258 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1259 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1260 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:281261
[email protected]fb661802013-03-25 01:59:321262 const gfx::Transform identity_matrix;
enneea850232015-07-27 16:43:121263 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1264 gfx::PointF(), gfx::Size(10, 10), true, false,
1265 true);
1266 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1267 gfx::PointF(), gfx::Size(10, 10), true, false,
1268 true);
1269 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1270 gfx::PointF(30.f, 30.f), gfx::Size(10, 10), true,
1271 false, false);
[email protected]fb661802013-03-25 01:59:321272
enneea850232015-07-27 16:43:121273 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321274
1275 // The child layer's content is entirely outside the parent's clip rect, so
1276 // the intermediate render surface should not be listed here, even if it was
1277 // forced to be created. Render surfaces without children or visible content
1278 // are unexpected at draw time (e.g. we might try to create a content texture
1279 // of size 0).
1280 ASSERT_TRUE(parent->render_surface());
enneea850232015-07-27 16:43:121281 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:321282}
1283
[email protected]989386c2013-07-18 21:37:231284TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
enne03b0e9a2015-06-19 00:08:021285 LayerImpl* parent = root_layer();
1286 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
1287 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1288 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:281289
[email protected]fb661802013-03-25 01:59:321290 const gfx::Transform identity_matrix;
enne03b0e9a2015-06-19 00:08:021291 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1292 gfx::PointF(), gfx::Size(10, 10), true, false,
1293 true);
1294 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1295 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321296 false);
[email protected]fb661802013-03-25 01:59:321297 render_surface1->SetOpacity(0.f);
1298
enne03b0e9a2015-06-19 00:08:021299 LayerImplList render_surface_layer_list;
enne03b0e9a2015-06-19 00:08:021300 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381301 parent, parent->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531302 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571303 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]fb661802013-03-25 01:59:321304
1305 // Since the layer is transparent, render_surface1->render_surface() should
1306 // not have gotten added anywhere. Also, the drawable content rect should not
1307 // have been extended by the children.
1308 ASSERT_TRUE(parent->render_surface());
1309 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1310 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231311 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321312 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1313}
1314
hendrikwc266f7b2015-08-21 23:41:341315TEST_F(LayerTreeHostCommonTest,
1316 RenderSurfaceListForTransparentChildWithBackgroundFilter) {
1317 LayerImpl* parent = root_layer();
1318 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
1319 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1320 child->SetDrawsContent(true);
1321
1322 const gfx::Transform identity_matrix;
1323 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1324 gfx::PointF(), gfx::Size(10, 10), true, false,
1325 true);
1326 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1327 gfx::PointF(), gfx::Size(10, 10), true, false,
1328 true);
1329 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1330 gfx::PointF(), gfx::Size(10, 10), true, false,
1331 false);
1332 render_surface1->SetOpacity(0.f);
jaydasika86654512016-01-27 17:05:071333 render_surface1->SetDrawsContent(true);
1334 child->SetDrawsContent(true);
hendrikwc266f7b2015-08-21 23:41:341335 FilterOperations filters;
1336 filters.Append(FilterOperation::CreateBlurFilter(1.5f));
1337 render_surface1->SetBackgroundFilters(filters);
1338
jaydasika369c24b2016-04-06 23:44:161339 {
1340 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161341 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381342 parent, parent->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161343 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571344 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161345 EXPECT_EQ(2U, render_surface_layer_list.size());
1346 }
hendrikwc266f7b2015-08-21 23:41:341347 // The layer is fully transparent, but has a background filter, so it
jaydasika369c24b2016-04-06 23:44:161348 // shouldn't be skipped and should be drawn.
hendrikwc266f7b2015-08-21 23:41:341349 ASSERT_TRUE(parent->render_surface());
1350 EXPECT_EQ(1U, parent->render_surface()->layer_list().size());
jaydasika8640f9f2015-11-10 01:34:361351 EXPECT_EQ(gfx::RectF(0, 0, 10, 10),
1352 parent->render_surface()->DrawableContentRect());
jaydasika369c24b2016-04-06 23:44:161353 EffectTree& effect_tree =
1354 parent->layer_tree_impl()->property_trees()->effect_tree;
1355 EffectNode* node = effect_tree.Node(render_surface1->effect_tree_index());
1356 EXPECT_TRUE(node->data.is_drawn);
1357
1358 // When parent is transparent, the layer should not be drawn.
1359 parent->OnOpacityAnimated(0.f);
1360 render_surface1->OnOpacityAnimated(1.f);
jaydasika8185d302016-04-14 15:20:061361 render_surface1->set_visible_layer_rect(gfx::Rect());
jaydasika369c24b2016-04-06 23:44:161362 {
1363 LayerImplList render_surface_layer_list;
jaydasika369c24b2016-04-06 23:44:161364 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381365 parent, parent->bounds(), &render_surface_layer_list);
jaydasika369c24b2016-04-06 23:44:161366 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571367 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika369c24b2016-04-06 23:44:161368 }
1369
1370 node = effect_tree.Node(render_surface1->effect_tree_index());
1371 EXPECT_FALSE(node->data.is_drawn);
jaydasika8185d302016-04-14 15:20:061372 EXPECT_EQ(gfx::Rect(), render_surface1->visible_layer_rect());
hendrikwc266f7b2015-08-21 23:41:341373}
1374
senorblanco38858c52016-01-20 23:15:001375TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForFilter) {
1376 LayerImpl* root = root_layer();
1377 LayerImpl* parent = AddChild<LayerImpl>(root);
1378 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1379 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1380 child1->SetDrawsContent(true);
1381 child2->SetDrawsContent(true);
1382
1383 const gfx::Transform identity_matrix;
1384 gfx::Transform scale_matrix;
1385 scale_matrix.Scale(2.0f, 2.0f);
1386 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1387 gfx::PointF(), gfx::Size(100, 100), true, false,
1388 true);
1389 SetLayerPropertiesForTesting(parent, scale_matrix, gfx::Point3F(),
1390 gfx::PointF(), gfx::Size(), true, false, true);
1391 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1392 gfx::PointF(0, 0), gfx::Size(25, 25), true,
1393 false, true);
1394 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1395 gfx::PointF(25, 25), gfx::Size(25, 25), true,
1396 false, true);
1397 FilterOperations filters;
1398 filters.Append(FilterOperation::CreateBlurFilter(10.0f));
1399 parent->SetFilters(filters);
1400
1401 LayerImplList render_surface_layer_list;
senorblanco38858c52016-01-20 23:15:001402 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:381403 root, root->bounds(), &render_surface_layer_list);
senorblanco38858c52016-01-20 23:15:001404 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:571405 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
senorblanco38858c52016-01-20 23:15:001406
1407 ASSERT_TRUE(parent->render_surface());
1408 EXPECT_EQ(2U, parent->render_surface()->layer_list().size());
1409 EXPECT_EQ(4U, render_surface_layer_list.size());
jbroman6797dde2016-05-20 18:59:551410 EXPECT_EQ(gfx::RectF(-30, -30, 160, 160),
senorblanco38858c52016-01-20 23:15:001411 parent->render_surface()->DrawableContentRect());
1412}
1413
rosca948d29d2014-11-09 10:25:131414TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
enned5f4ddd2015-08-18 16:50:061415 LayerImpl* parent = root_layer();
1416 LayerImpl* child = AddChild<LayerImpl>(parent);
1417 child->SetDrawsContent(true);
rosca948d29d2014-11-09 10:25:131418
1419 const gfx::Transform identity_matrix;
1420 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
enned5f4ddd2015-08-18 16:50:061421 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1422 gfx::PointF(), gfx::Size(10, 10), true, false,
1423 true);
1424 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1425 gfx::PointF(), gfx::Size(10, 10), true, false,
1426 true);
rosca948d29d2014-11-09 10:25:131427
rosca948d29d2014-11-09 10:25:131428 child->SetBlendMode(blend_mode);
weiliangc451b818f2015-07-24 17:52:291429 child->SetOpacity(0.5f);
rosca948d29d2014-11-09 10:25:131430
enned5f4ddd2015-08-18 16:50:061431 ExecuteCalculateDrawProperties(parent);
rosca948d29d2014-11-09 10:25:131432
1433 // Since the child layer has a blend mode other than normal, it should get
1434 // its own render surface. Also, layer's draw_properties should contain the
1435 // default blend mode, since the render surface becomes responsible for
1436 // applying the blend mode.
1437 ASSERT_TRUE(child->render_surface());
weiliangc451b818f2015-07-24 17:52:291438 EXPECT_EQ(1.0f, child->draw_opacity());
1439 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
jaydasika92239dc2015-08-15 02:59:261440 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode());
rosca948d29d2014-11-09 10:25:131441}
1442
jaydasikafbdb86e2016-01-21 18:57:511443TEST_F(LayerTreeHostCommonTest, RenderSurfaceDrawOpacity) {
1444 LayerImpl* root = root_layer();
1445 LayerImpl* surface1 = AddChildToRoot<LayerImpl>();
1446 LayerImpl* not_surface = AddChild<LayerImpl>(surface1);
1447 LayerImpl* surface2 = AddChild<LayerImpl>(not_surface);
1448
1449 const gfx::Transform identity_matrix;
1450 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1451 gfx::PointF(), gfx::Size(10, 10), true, false,
1452 true);
1453 SetLayerPropertiesForTesting(surface1, identity_matrix, gfx::Point3F(),
1454 gfx::PointF(), gfx::Size(10, 10), true, false,
1455 true);
1456 SetLayerPropertiesForTesting(not_surface, identity_matrix, gfx::Point3F(),
1457 gfx::PointF(), gfx::Size(10, 10), true, false,
1458 false);
1459 SetLayerPropertiesForTesting(surface2, identity_matrix, gfx::Point3F(),
1460 gfx::PointF(), gfx::Size(10, 10), true, false,
1461 true);
1462 surface1->SetDrawsContent(true);
1463 surface2->SetDrawsContent(true);
1464
1465 surface1->SetOpacity(0.5f);
1466 not_surface->SetOpacity(0.5f);
1467 surface2->SetOpacity(0.5f);
1468
1469 ExecuteCalculateDrawProperties(root);
1470
1471 ASSERT_TRUE(surface1->render_surface());
1472 ASSERT_FALSE(not_surface->render_surface());
1473 ASSERT_TRUE(surface2->render_surface());
1474 EXPECT_EQ(0.5f, surface1->render_surface()->draw_opacity());
1475 // surface2's draw opacity should include the opacity of not-surface and
1476 // itself, but not the opacity of surface1.
1477 EXPECT_EQ(0.25f, surface2->render_surface()->draw_opacity());
1478}
1479
ajuma51d73f72015-10-19 19:43:581480TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) {
1481 // Tests that when separate surfaces are disabled, a layer's draw opacity is
1482 // the product of all ancestor layer opacties and the layer's own opacity.
1483 // (Rendering will still be incorrect in situations where we really do need
1484 // surfaces to apply opacity, such as when we have overlapping layers with an
1485 // ancestor whose opacity is <1.)
1486 LayerImpl* root = root_layer();
1487 LayerImpl* parent = AddChild<LayerImpl>(root);
1488 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1489 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1490 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1491 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1492 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1493
1494 root->SetDrawsContent(true);
1495 parent->SetDrawsContent(true);
1496 child1->SetDrawsContent(true);
1497 child2->SetDrawsContent(true);
1498 grand_child->SetDrawsContent(true);
1499 leaf_node1->SetDrawsContent(true);
1500 leaf_node2->SetDrawsContent(true);
1501
1502 const gfx::Transform identity_matrix;
1503
1504 // child1 and grand_child get render surfaces when surfaces are enabled.
1505 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1506 gfx::PointF(), gfx::Size(100, 100), true, false,
1507 true);
1508 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1509 gfx::PointF(), gfx::Size(100, 100), true, false,
1510 false);
1511 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1512 gfx::PointF(), gfx::Size(100, 100), true, false,
1513 true);
1514 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1515 gfx::PointF(), gfx::Size(100, 100), true, false,
1516 false);
1517 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1518 gfx::PointF(), gfx::Size(100, 100), true, false,
1519 true);
1520 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1521 gfx::PointF(), gfx::Size(100, 100), true, false,
1522 false);
1523 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1524 gfx::PointF(), gfx::Size(100, 100), true, false,
1525 false);
1526
1527 child1->SetOpacity(0.5f);
1528 grand_child->SetOpacity(0.5f);
1529 leaf_node1->SetOpacity(0.5f);
1530 leaf_node2->SetOpacity(0.5f);
1531
1532 // With surfaces enabled, each layer's draw opacity is the product of layer
1533 // opacities on the path from the layer to its render target, not including
1534 // the opacity of the layer that owns the target surface (since that opacity
1535 // is applied by the surface).
1536 ExecuteCalculateDrawProperties(root);
1537 EXPECT_EQ(1.f, root->draw_opacity());
1538 EXPECT_EQ(1.f, parent->draw_opacity());
1539 EXPECT_EQ(1.f, child1->draw_opacity());
1540 EXPECT_EQ(1.f, child2->draw_opacity());
1541 EXPECT_EQ(1.f, grand_child->draw_opacity());
1542 EXPECT_EQ(0.5f, leaf_node1->draw_opacity());
1543 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1544
1545 // With surfaces disabled, each layer's draw opacity is the product of layer
1546 // opacities on the path from the layer to the root.
1547 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1548 EXPECT_EQ(1.f, root->draw_opacity());
1549 EXPECT_EQ(1.f, parent->draw_opacity());
1550 EXPECT_EQ(0.5f, child1->draw_opacity());
1551 EXPECT_EQ(1.f, child2->draw_opacity());
1552 EXPECT_EQ(0.25f, grand_child->draw_opacity());
1553 EXPECT_EQ(0.125f, leaf_node1->draw_opacity());
1554 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1555}
1556
[email protected]989386c2013-07-18 21:37:231557TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
weiliangcc154ce22015-12-09 03:39:261558 LayerImpl* parent = root_layer();
1559 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1560 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
weiliangceffae0462015-12-08 23:17:261561
1562 const gfx::Transform identity_matrix;
weiliangcc154ce22015-12-09 03:39:261563 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
weiliangceffae0462015-12-08 23:17:261564 gfx::PointF(), gfx::Size(10, 10), true, false);
weiliangcc154ce22015-12-09 03:39:261565 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1566 gfx::PointF(), gfx::Size(10, 10), true, false);
1567 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
weiliangceffae0462015-12-08 23:17:261568 gfx::PointF(), gfx::Size(10, 10), true, false);
1569
weiliangcc154ce22015-12-09 03:39:261570 child->SetDrawsContent(true);
jaydasika6b5a32bf2016-04-22 21:56:361571 render_surface1->test_properties()->force_render_surface = true;
weiliangceffae0462015-12-08 23:17:261572
[email protected]989386c2013-07-18 21:37:231573 {
weiliangcc154ce22015-12-09 03:39:261574 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:321575
[email protected]989386c2013-07-18 21:37:231576 // The root layer always creates a render surface
ennec1332992015-08-24 19:45:091577 EXPECT_TRUE(parent->has_render_surface());
1578 EXPECT_TRUE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231579 }
[email protected]fb661802013-03-25 01:59:321580
[email protected]989386c2013-07-18 21:37:231581 {
jaydasika6b5a32bf2016-04-22 21:56:361582 render_surface1->test_properties()->force_render_surface = false;
weiliangcc154ce22015-12-09 03:39:261583 render_surface1->layer_tree_impl()->property_trees()->needs_rebuild = true;
1584 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
ennec1332992015-08-24 19:45:091585 EXPECT_TRUE(parent->has_render_surface());
1586 EXPECT_FALSE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231587 }
[email protected]fb661802013-03-25 01:59:321588}
1589
ajuma246190a2015-03-11 20:56:031590TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1591 // Render surfaces act as a flattening point for their subtree, so should
1592 // always flatten the target-to-screen space transform seen by descendants.
1593
enne1a79c5542015-08-18 19:43:571594 LayerImpl* root = root_layer();
1595 LayerImpl* parent = AddChild<LayerImpl>(root);
1596 LayerImpl* child = AddChild<LayerImpl>(parent);
1597 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1598
1599 child->SetDrawsContent(true);
1600 grand_child->SetDrawsContent(true);
ajuma246190a2015-03-11 20:56:031601
1602 gfx::Transform rotation_about_y_axis;
1603 rotation_about_y_axis.RotateAboutYAxis(30.0);
1604 // Make |parent| have a render surface.
1605 parent->SetOpacity(0.9f);
1606
1607 const gfx::Transform identity_matrix;
enne1a79c5542015-08-18 19:43:571608 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1609 gfx::PointF(), gfx::Size(100, 100), true, false,
1610 true);
1611 SetLayerPropertiesForTesting(parent, rotation_about_y_axis, gfx::Point3F(),
1612 gfx::PointF(), gfx::Size(10, 10), true, false,
1613 true);
1614 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1615 gfx::PointF(), gfx::Size(10, 10), true, false,
1616 false);
1617 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1618 gfx::PointF(), gfx::Size(10, 10), true, false,
1619 false);
ajuma246190a2015-03-11 20:56:031620
jaydasikaca2605e2016-04-23 02:52:521621 grand_child->test_properties()->should_flatten_transform = false;
ajuma246190a2015-03-11 20:56:031622
ajuma246190a2015-03-11 20:56:031623 // Only grand_child should preserve 3d.
jaydasikaca2605e2016-04-23 02:52:521624 EXPECT_TRUE(root->test_properties()->should_flatten_transform);
1625 EXPECT_TRUE(parent->test_properties()->should_flatten_transform);
1626 EXPECT_TRUE(child->test_properties()->should_flatten_transform);
1627 EXPECT_FALSE(grand_child->test_properties()->should_flatten_transform);
ajuma246190a2015-03-11 20:56:031628
1629 gfx::Transform expected_child_draw_transform = identity_matrix;
1630 gfx::Transform expected_grand_child_draw_transform = identity_matrix;
1631
1632 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1633 flattened_rotation_about_y.FlattenTo2d();
1634
enne1a79c5542015-08-18 19:43:571635 ExecuteCalculateDrawProperties(root);
ajuma246190a2015-03-11 20:56:031636
1637 EXPECT_TRUE(parent->render_surface());
1638 EXPECT_FALSE(child->render_surface());
1639 EXPECT_FALSE(grand_child->render_surface());
1640
ajumad9432e32015-11-30 19:43:441641 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
ajuma246190a2015-03-11 20:56:031642 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
ajumad9432e32015-11-30 19:43:441643 grand_child->DrawTransform());
ajuma246190a2015-03-11 20:56:031644
1645 // The screen-space transform inherited by |child| and |grand_child| should
1646 // have been flattened at their render target. In particular, the fact that
1647 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1648 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101649 child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031650 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
ajumab6aa1c62015-12-01 21:01:101651 grand_child->ScreenSpaceTransform());
ajuma246190a2015-03-11 20:56:031652}
1653
[email protected]989386c2013-07-18 21:37:231654TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321655 // The entire subtree of layers that are outside the clip rect should be
1656 // culled away, and should not affect the render_surface_layer_list.
1657 //
1658 // The test tree is set up as follows:
1659 // - all layers except the leaf_nodes are forced to be a new render surface
1660 // that have something to draw.
1661 // - parent is a large container layer.
1662 // - child has masksToBounds=true to cause clipping.
1663 // - grand_child is positioned outside of the child's bounds
1664 // - great_grand_child is also kept outside child's bounds.
1665 //
1666 // In this configuration, grand_child and great_grand_child are completely
1667 // outside the clip rect, and they should never get scheduled on the list of
1668 // render surfaces.
[email protected]fb661802013-03-25 01:59:321669
weiliangcfb3d5eaa2015-07-28 23:54:571670 LayerImpl* parent = root_layer();
1671 LayerImpl* child = AddChildToRoot<LayerImpl>();
1672 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1673 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
[email protected]d600df7d2013-08-03 02:34:281674
[email protected]fb661802013-03-25 01:59:321675 // leaf_node1 ensures that parent and child are kept on the
1676 // render_surface_layer_list, even though grand_child and great_grand_child
1677 // should be clipped.
weiliangcfb3d5eaa2015-07-28 23:54:571678 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
1679 leaf_node1->SetDrawsContent(true);
1680 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
1681 leaf_node2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321682
weiliangcfb3d5eaa2015-07-28 23:54:571683 const gfx::Transform identity_matrix;
1684
1685 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1686 gfx::PointF(), gfx::Size(500, 500), true, false,
1687 true);
1688 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1689 gfx::PointF(), gfx::Size(20, 20), true, false,
1690 true);
1691 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1692 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1693 false, false);
1694 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
1695 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1696 true, false, false);
1697 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1698 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:321699 false);
weiliangcfb3d5eaa2015-07-28 23:54:571700 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1701 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]fb661802013-03-25 01:59:321702 false);
1703
1704 child->SetMasksToBounds(true);
1705 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321706 grand_child->SetOpacity(0.5f);
1707 great_grand_child->SetOpacity(0.4f);
1708
weiliangcfb3d5eaa2015-07-28 23:54:571709 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321710
weiliangcfb3d5eaa2015-07-28 23:54:571711 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
1712 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id());
1713 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id());
[email protected]fb661802013-03-25 01:59:321714}
1715
[email protected]989386c2013-07-18 21:37:231716TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321717 // When a render surface has a clip rect, it is used to clip the content rect
weiliangcfb3d5eaa2015-07-28 23:54:571718 // of the surface.
[email protected]fb661802013-03-25 01:59:321719
1720 // The test tree is set up as follows:
1721 // - parent is a container layer that masksToBounds=true to cause clipping.
1722 // - child is a render surface, which has a clip rect set to the bounds of
1723 // the parent.
1724 // - grand_child is a render surface, and the only visible content in child.
1725 // It is positioned outside of the clip rect from parent.
1726
1727 // In this configuration, grand_child should be outside the clipped
1728 // content rect of the child, making grand_child not appear in the
weiliangcfb3d5eaa2015-07-28 23:54:571729 // render_surface_layer_list.
1730
1731 LayerImpl* parent = root_layer();
1732 LayerImpl* child = AddChildToRoot<LayerImpl>();
1733 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1734 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
1735 leaf_node->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321736
1737 const gfx::Transform identity_matrix;
[email protected]fb661802013-03-25 01:59:321738
weiliangcfb3d5eaa2015-07-28 23:54:571739 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1740 gfx::PointF(), gfx::Size(100, 100), true, false,
1741 true);
1742 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1743 gfx::PointF(), gfx::Size(20, 20), true, false,
1744 true);
1745 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1746 gfx::PointF(200.f, 200.f), gfx::Size(10, 10),
1747 true, false, true);
1748 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
1749 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321750 false);
1751
1752 parent->SetMasksToBounds(true);
1753 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321754 grand_child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321755
weiliangcfb3d5eaa2015-07-28 23:54:571756 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321757
weiliangcfb3d5eaa2015-07-28 23:54:571758 // We should cull child and grand_child from the
1759 // render_surface_layer_list.
1760 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
1761 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id());
[email protected]fb661802013-03-25 01:59:321762}
1763
ajumae2b7a5c2015-09-30 21:41:421764TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1765 // Tests that LayerImpl's IsClipped() property is set to true when:
[email protected]fb661802013-03-25 01:59:321766 // - the layer clips its subtree, e.g. masks to bounds,
1767 // - the layer is clipped by an ancestor that contributes to the same
1768 // render target,
1769 // - a surface is clipped by an ancestor that contributes to the same
1770 // render target.
1771 //
1772 // In particular, for a layer that owns a render surface:
1773 // - the render surface inherits any clip from ancestors, and does NOT
1774 // pass that clipped status to the layer itself.
1775 // - but if the layer itself masks to bounds, it is considered clipped
1776 // and propagates the clip to the subtree.
1777
1778 const gfx::Transform identity_matrix;
enne76bf8982015-08-18 17:55:331779 LayerImpl* root = root_layer();
1780 LayerImpl* parent = AddChild<LayerImpl>(root);
jaydasika8640f9f2015-11-10 01:34:361781 parent->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331782 LayerImpl* child1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:361783 child1->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331784 LayerImpl* child2 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:361785 child2->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331786 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
jaydasika8640f9f2015-11-10 01:34:361787 grand_child->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331788 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1789 leaf_node1->SetDrawsContent(true);
1790 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1791 leaf_node2->SetDrawsContent(true);
1792
1793 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1794 gfx::PointF(), gfx::Size(100, 100), true, false,
1795 true);
1796 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1797 gfx::PointF(), gfx::Size(100, 100), true, false,
1798 false);
1799 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1800 gfx::PointF(), gfx::Size(100, 100), true, false,
1801 false);
1802 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1803 gfx::PointF(), gfx::Size(100, 100), true, false,
1804 true);
1805 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1806 gfx::PointF(), gfx::Size(100, 100), true, false,
1807 false);
1808 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1809 gfx::PointF(), gfx::Size(100, 100), true, false,
1810 false);
1811 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1812 gfx::PointF(), gfx::Size(100, 100), true, false,
1813 false);
1814
1815 // Case 1: nothing is clipped except the root render surface.
weiliangce3f09a612016-03-16 17:02:521816 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331817
weiliangce3f09a612016-03-16 17:02:521818 ASSERT_TRUE(root->render_surface());
1819 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331820
weiliangce3f09a612016-03-16 17:02:521821 EXPECT_FALSE(root->is_clipped());
1822 EXPECT_TRUE(root->render_surface()->is_clipped());
1823 EXPECT_FALSE(parent->is_clipped());
1824 EXPECT_FALSE(child1->is_clipped());
1825 EXPECT_FALSE(child2->is_clipped());
1826 EXPECT_FALSE(child2->render_surface()->is_clipped());
1827 EXPECT_FALSE(grand_child->is_clipped());
1828 EXPECT_FALSE(leaf_node1->is_clipped());
1829 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331830
1831 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1832 // surface are clipped. But layers that contribute to child2's surface are
1833 // not clipped explicitly because child2's surface already accounts for
1834 // that clip.
weiliangce3f09a612016-03-16 17:02:521835 parent->SetMasksToBounds(true);
1836 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331837
weiliangce3f09a612016-03-16 17:02:521838 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331839
weiliangce3f09a612016-03-16 17:02:521840 ASSERT_TRUE(root->render_surface());
1841 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331842
weiliangce3f09a612016-03-16 17:02:521843 EXPECT_FALSE(root->is_clipped());
1844 EXPECT_TRUE(root->render_surface()->is_clipped());
1845 EXPECT_TRUE(parent->is_clipped());
1846 EXPECT_TRUE(child1->is_clipped());
1847 EXPECT_FALSE(child2->is_clipped());
1848 EXPECT_TRUE(child2->render_surface()->is_clipped());
1849 EXPECT_TRUE(grand_child->is_clipped());
1850 EXPECT_TRUE(leaf_node1->is_clipped());
1851 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331852
weiliangce3f09a612016-03-16 17:02:521853 parent->SetMasksToBounds(false);
enne76bf8982015-08-18 17:55:331854
1855 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1856 // child2's render surface is not clipped.
weiliangce3f09a612016-03-16 17:02:521857 child2->SetMasksToBounds(true);
1858 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
enne76bf8982015-08-18 17:55:331859
weiliangce3f09a612016-03-16 17:02:521860 ExecuteCalculateDrawProperties(root);
enne76bf8982015-08-18 17:55:331861
weiliangce3f09a612016-03-16 17:02:521862 ASSERT_TRUE(root->render_surface());
1863 ASSERT_TRUE(child2->render_surface());
enne76bf8982015-08-18 17:55:331864
weiliangce3f09a612016-03-16 17:02:521865 EXPECT_FALSE(root->is_clipped());
1866 EXPECT_TRUE(root->render_surface()->is_clipped());
1867 EXPECT_FALSE(parent->is_clipped());
1868 EXPECT_FALSE(child1->is_clipped());
1869 EXPECT_TRUE(child2->is_clipped());
1870 EXPECT_FALSE(child2->render_surface()->is_clipped());
1871 EXPECT_FALSE(grand_child->is_clipped());
1872 EXPECT_FALSE(leaf_node1->is_clipped());
1873 EXPECT_TRUE(leaf_node2->is_clipped());
1874}
1875
1876TEST_F(LayerTreeHostCommonTest, UpdateClipRectCorrectly) {
1877 // Tests that when as long as layer is clipped, it's clip rect is set to
1878 // correct value.
1879 LayerImpl* root = root_layer();
1880 LayerImpl* parent = AddChild<LayerImpl>(root);
1881 LayerImpl* child = AddChild<LayerImpl>(parent);
1882
1883 root->SetDrawsContent(true);
1884 parent->SetDrawsContent(true);
1885 child->SetDrawsContent(true);
1886
1887 const gfx::Transform identity_matrix;
1888
1889 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1890 gfx::PointF(), gfx::Size(100, 100), true, false,
1891 true);
1892 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1893 gfx::PointF(), gfx::Size(100, 100), true, false,
1894 false);
1895 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1896 gfx::PointF(), gfx::Size(100, 100), true, false,
1897 false);
1898 child->SetMasksToBounds(true);
1899
1900 ExecuteCalculateDrawProperties(root);
1901
1902 EXPECT_FALSE(root->is_clipped());
1903 EXPECT_FALSE(parent->is_clipped());
1904 EXPECT_TRUE(child->is_clipped());
1905 EXPECT_EQ(gfx::Rect(100, 100), child->clip_rect());
1906
1907 parent->SetMasksToBounds(true);
1908 child->SetPosition(gfx::PointF(100, 100));
1909 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1910
1911 ExecuteCalculateDrawProperties(root);
1912
1913 EXPECT_FALSE(root->is_clipped());
1914 EXPECT_TRUE(parent->is_clipped());
1915 EXPECT_TRUE(child->is_clipped());
1916 EXPECT_EQ(gfx::Rect(), child->clip_rect());
[email protected]fb661802013-03-25 01:59:321917}
1918
ajuma51d73f72015-10-19 19:43:581919TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) {
1920 // Tests that when separate surfaces are disabled, is_clipped is true exactly
1921 // when a layer or its ancestor has a clip; in particular, if a layer
1922 // is_clipped, so is its entire subtree (since there are no render surfaces
1923 // that can reset is_clipped).
1924 LayerImpl* root = root_layer();
1925 LayerImpl* parent = AddChild<LayerImpl>(root);
1926 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1927 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1928 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1929 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1930 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1931
1932 root->SetDrawsContent(true);
1933 parent->SetDrawsContent(true);
1934 child1->SetDrawsContent(true);
1935 child2->SetDrawsContent(true);
1936 grand_child->SetDrawsContent(true);
1937 leaf_node1->SetDrawsContent(true);
1938 leaf_node2->SetDrawsContent(true);
1939
1940 const gfx::Transform identity_matrix;
1941
1942 // child1 and grand_child get render surfaces when surfaces are enabled.
1943 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1944 gfx::PointF(), gfx::Size(100, 100), true, false,
1945 true);
1946 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1947 gfx::PointF(), gfx::Size(100, 100), true, false,
1948 false);
1949 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1950 gfx::PointF(), gfx::Size(100, 100), true, false,
1951 true);
1952 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1953 gfx::PointF(), gfx::Size(100, 100), true, false,
1954 false);
1955 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1956 gfx::PointF(), gfx::Size(100, 100), true, false,
1957 true);
1958 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1959 gfx::PointF(), gfx::Size(100, 100), true, false,
1960 false);
1961 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1962 gfx::PointF(), gfx::Size(100, 100), true, false,
1963 false);
1964
1965 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with
1966 // or without surfaces.
weiliangcc154ce22015-12-09 03:39:261967 root->SetHasRenderSurface(true);
1968 child1->SetHasRenderSurface(true);
1969 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:581970 ExecuteCalculateDrawProperties(root);
1971 EXPECT_FALSE(root->is_clipped());
1972 EXPECT_FALSE(parent->is_clipped());
1973 EXPECT_FALSE(child1->is_clipped());
1974 EXPECT_FALSE(child2->is_clipped());
1975 EXPECT_FALSE(grand_child->is_clipped());
1976 EXPECT_FALSE(leaf_node1->is_clipped());
1977 EXPECT_FALSE(leaf_node2->is_clipped());
1978
1979 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1980 EXPECT_FALSE(root->is_clipped());
1981 EXPECT_FALSE(parent->is_clipped());
1982 EXPECT_FALSE(child1->is_clipped());
1983 EXPECT_FALSE(child2->is_clipped());
1984 EXPECT_FALSE(grand_child->is_clipped());
1985 EXPECT_FALSE(leaf_node1->is_clipped());
1986 EXPECT_FALSE(leaf_node2->is_clipped());
1987
1988 // Case 2: The root is clipped. With surfaces, this only persists until the
1989 // next render surface. Without surfaces, the entire tree is clipped.
1990 root->SetMasksToBounds(true);
1991 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:261992 root->SetHasRenderSurface(true);
1993 child1->SetHasRenderSurface(true);
1994 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:581995 ExecuteCalculateDrawProperties(root);
1996 EXPECT_TRUE(root->is_clipped());
1997 EXPECT_TRUE(parent->is_clipped());
1998 EXPECT_FALSE(child1->is_clipped());
1999 EXPECT_TRUE(child2->is_clipped());
2000 EXPECT_FALSE(grand_child->is_clipped());
2001 EXPECT_FALSE(leaf_node1->is_clipped());
2002 EXPECT_TRUE(leaf_node2->is_clipped());
2003
2004 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2005 EXPECT_TRUE(root->is_clipped());
2006 EXPECT_TRUE(parent->is_clipped());
2007 EXPECT_TRUE(child1->is_clipped());
2008 EXPECT_TRUE(child2->is_clipped());
2009 EXPECT_TRUE(grand_child->is_clipped());
2010 EXPECT_TRUE(leaf_node1->is_clipped());
2011 EXPECT_TRUE(leaf_node2->is_clipped());
2012
2013 root->SetMasksToBounds(false);
2014
2015 // Case 3: The parent is clipped. Again, with surfaces, this only persists
2016 // until the next render surface. Without surfaces, parent's entire subtree is
2017 // clipped.
2018 parent->SetMasksToBounds(true);
2019 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262020 root->SetHasRenderSurface(true);
2021 child1->SetHasRenderSurface(true);
2022 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582023 ExecuteCalculateDrawProperties(root);
2024 EXPECT_FALSE(root->is_clipped());
2025 EXPECT_TRUE(parent->is_clipped());
2026 EXPECT_FALSE(child1->is_clipped());
2027 EXPECT_TRUE(child2->is_clipped());
2028 EXPECT_FALSE(grand_child->is_clipped());
2029 EXPECT_FALSE(leaf_node1->is_clipped());
2030 EXPECT_TRUE(leaf_node2->is_clipped());
2031
2032 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2033 EXPECT_FALSE(root->is_clipped());
2034 EXPECT_TRUE(parent->is_clipped());
2035 EXPECT_TRUE(child1->is_clipped());
2036 EXPECT_TRUE(child2->is_clipped());
2037 EXPECT_TRUE(grand_child->is_clipped());
2038 EXPECT_TRUE(leaf_node1->is_clipped());
2039 EXPECT_TRUE(leaf_node2->is_clipped());
2040
2041 parent->SetMasksToBounds(false);
2042
2043 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it
2044 // has no non-surface children. Without surfaces, child1's entire subtree is
2045 // clipped.
2046 child1->SetMasksToBounds(true);
2047 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262048 root->SetHasRenderSurface(true);
2049 child1->SetHasRenderSurface(true);
2050 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582051 ExecuteCalculateDrawProperties(root);
2052 EXPECT_FALSE(root->is_clipped());
2053 EXPECT_FALSE(parent->is_clipped());
2054 EXPECT_TRUE(child1->is_clipped());
2055 EXPECT_FALSE(child2->is_clipped());
2056 EXPECT_FALSE(grand_child->is_clipped());
2057 EXPECT_FALSE(leaf_node1->is_clipped());
2058 EXPECT_FALSE(leaf_node2->is_clipped());
2059
2060 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2061 EXPECT_FALSE(root->is_clipped());
2062 EXPECT_FALSE(parent->is_clipped());
2063 EXPECT_TRUE(child1->is_clipped());
2064 EXPECT_FALSE(child2->is_clipped());
2065 EXPECT_TRUE(grand_child->is_clipped());
2066 EXPECT_TRUE(leaf_node1->is_clipped());
2067 EXPECT_FALSE(leaf_node2->is_clipped());
2068
2069 child1->SetMasksToBounds(false);
2070
2071 // Case 5: Only the leaf nodes are clipped. The behavior with and without
2072 // surfaces is the same.
2073 leaf_node1->SetMasksToBounds(true);
2074 leaf_node2->SetMasksToBounds(true);
2075 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:262076 root->SetHasRenderSurface(true);
2077 child1->SetHasRenderSurface(true);
2078 grand_child->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:582079 ExecuteCalculateDrawProperties(root);
2080 EXPECT_FALSE(root->is_clipped());
2081 EXPECT_FALSE(parent->is_clipped());
2082 EXPECT_FALSE(child1->is_clipped());
2083 EXPECT_FALSE(child2->is_clipped());
2084 EXPECT_FALSE(grand_child->is_clipped());
2085 EXPECT_TRUE(leaf_node1->is_clipped());
2086 EXPECT_TRUE(leaf_node2->is_clipped());
2087
2088 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2089 EXPECT_FALSE(root->is_clipped());
2090 EXPECT_FALSE(parent->is_clipped());
2091 EXPECT_FALSE(child1->is_clipped());
2092 EXPECT_FALSE(child2->is_clipped());
2093 EXPECT_FALSE(grand_child->is_clipped());
2094 EXPECT_TRUE(leaf_node1->is_clipped());
2095 EXPECT_TRUE(leaf_node2->is_clipped());
2096}
2097
[email protected]fd9a3b6d2013-08-03 00:46:172098TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:322099 // Verify that layers get the appropriate DrawableContentRect when their
2100 // parent masksToBounds is true.
2101 //
2102 // grand_child1 - completely inside the region; DrawableContentRect should
2103 // be the layer rect expressed in target space.
2104 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
2105 // will be the intersection of layer bounds and the mask region.
2106 // grand_child3 - partially clipped and masksToBounds; the
2107 // DrawableContentRect will still be the intersection of layer bounds and
2108 // the mask region.
2109 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
2110 // be empty.
[email protected]fb661802013-03-25 01:59:322111
2112 const gfx::Transform identity_matrix;
enne07405c772015-08-18 17:56:452113 LayerImpl* parent = root_layer();
2114 LayerImpl* child = AddChild<LayerImpl>(parent);
2115 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362116 grand_child1->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452117 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362118 grand_child2->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452119 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362120 grand_child3->SetDrawsContent(true);
enne07405c772015-08-18 17:56:452121 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:362122 grand_child4->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322123
enne07405c772015-08-18 17:56:452124 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2125 gfx::PointF(), gfx::Size(500, 500), true, false,
2126 true);
2127 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2128 gfx::PointF(), gfx::Size(20, 20), true, false,
2129 true);
2130 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2131 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
2132 false, false);
2133 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2134 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2135 false, false);
2136 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2137 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2138 false, false);
2139 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
2140 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
2141 false, false);
[email protected]fb661802013-03-25 01:59:322142
2143 child->SetMasksToBounds(true);
2144 grand_child3->SetMasksToBounds(true);
2145
enne07405c772015-08-18 17:56:452146 // Force child to be a render surface.
[email protected]fb661802013-03-25 01:59:322147 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:322148
enne07405c772015-08-18 17:56:452149 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322150
hush6b614212014-12-04 22:37:322151 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2152 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2153 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322154 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2155}
2156
[email protected]989386c2013-07-18 21:37:232157TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322158 // Verify that render surfaces (and their layers) get the appropriate
2159 // clip rects when their parent masksToBounds is true.
2160 //
2161 // Layers that own render surfaces (at least for now) do not inherit any
2162 // clipping; instead the surface will enforce the clip for the entire subtree.
2163 // They may still have a clip rect of their own layer bounds, however, if
2164 // masksToBounds was true.
weiliangcfb3d5eaa2015-07-28 23:54:572165 LayerImpl* parent = root_layer();
2166 LayerImpl* child = AddChildToRoot<LayerImpl>();
2167 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2168 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2169 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2170 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
[email protected]fb661802013-03-25 01:59:322171 // the leaf nodes ensure that these grand_children become render surfaces for
2172 // this test.
weiliangcfb3d5eaa2015-07-28 23:54:572173 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
2174 leaf_node1->SetDrawsContent(true);
2175 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
2176 leaf_node2->SetDrawsContent(true);
2177 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
2178 leaf_node3->SetDrawsContent(true);
2179 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
2180 leaf_node4->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322181
weiliangcfb3d5eaa2015-07-28 23:54:572182 const gfx::Transform identity_matrix;
2183
2184 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2185 gfx::PointF(), gfx::Size(500, 500), true, false,
2186 true);
2187 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2188 gfx::PointF(), gfx::Size(20, 20), true, false,
2189 true);
2190 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2191 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
2192 false, true);
2193 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2194 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2195 false, true);
2196 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2197 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2198 false, true);
2199 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
2200 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
2201 false, true);
2202 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2203 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322204 false);
weiliangcfb3d5eaa2015-07-28 23:54:572205 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2206 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322207 false);
weiliangcfb3d5eaa2015-07-28 23:54:572208 SetLayerPropertiesForTesting(leaf_node3, identity_matrix, gfx::Point3F(),
2209 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322210 false);
weiliangcfb3d5eaa2015-07-28 23:54:572211 SetLayerPropertiesForTesting(leaf_node4, identity_matrix, gfx::Point3F(),
2212 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322213 false);
2214
2215 child->SetMasksToBounds(true);
2216 grand_child3->SetMasksToBounds(true);
2217 grand_child4->SetMasksToBounds(true);
2218
2219 // Force everyone to be a render surface.
2220 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:322221 grand_child1->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322222 grand_child2->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322223 grand_child3->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322224 grand_child4->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322225
weiliangcfb3d5eaa2015-07-28 23:54:572226 ExecuteCalculateDrawProperties(parent);
2227
[email protected]fb661802013-03-25 01:59:322228 ASSERT_TRUE(grand_child1->render_surface());
2229 ASSERT_TRUE(grand_child2->render_surface());
2230 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322231
2232 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2233 // masksToBounds.
hush6b614212014-12-04 22:37:322234 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2235 grand_child1->render_surface()->clip_rect());
2236 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2237 grand_child2->render_surface()->clip_rect());
2238 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2239 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322240}
2241
ajuma51d73f72015-10-19 19:43:582242TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) {
2243 // Tests that when separate surfaces are disabled, a layer's clip_rect is the
2244 // intersection of all ancestor clips in screen space; in particular, if a
2245 // layer masks to bounds, it contributes to the clip_rect of all layers in its
2246 // subtree (since there are no render surfaces that can reset the clip_rect).
2247 LayerImpl* root = root_layer();
2248 LayerImpl* parent = AddChild<LayerImpl>(root);
2249 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2250 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2251 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2252 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2253 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2254
2255 root->SetDrawsContent(true);
2256 parent->SetDrawsContent(true);
2257 child1->SetDrawsContent(true);
2258 child2->SetDrawsContent(true);
2259 grand_child->SetDrawsContent(true);
2260 leaf_node1->SetDrawsContent(true);
2261 leaf_node2->SetDrawsContent(true);
2262
2263 const gfx::Transform identity_matrix;
2264
2265 // child1 and grand_child get render surfaces when surfaces are enabled.
2266 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:262267 gfx::PointF(), gfx::Size(100, 100), true, false);
ajuma51d73f72015-10-19 19:43:582268 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2269 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
weiliangcc154ce22015-12-09 03:39:262270 false);
ajuma51d73f72015-10-19 19:43:582271 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2272 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
weiliangcc154ce22015-12-09 03:39:262273 false);
ajuma51d73f72015-10-19 19:43:582274 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2275 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
weiliangcc154ce22015-12-09 03:39:262276 false);
ajuma51d73f72015-10-19 19:43:582277 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2278 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
weiliangcc154ce22015-12-09 03:39:262279 true, false);
ajuma51d73f72015-10-19 19:43:582280 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2281 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
weiliangcc154ce22015-12-09 03:39:262282 true, false);
ajuma51d73f72015-10-19 19:43:582283 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2284 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
weiliangcc154ce22015-12-09 03:39:262285 true, false);
ajuma51d73f72015-10-19 19:43:582286
2287 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its
2288 // bounds in target space. The only thing that changes when surfaces are
2289 // disabled is that target space is always screen space.
jaydasika6b5a32bf2016-04-22 21:56:362290 root->test_properties()->force_render_surface = true;
2291 child1->test_properties()->force_render_surface = true;
2292 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582293 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262294 EXPECT_TRUE(root->has_render_surface());
2295 EXPECT_FALSE(parent->has_render_surface());
2296 EXPECT_TRUE(child1->has_render_surface());
2297 EXPECT_FALSE(child2->has_render_surface());
2298 EXPECT_TRUE(grand_child->has_render_surface());
2299 EXPECT_FALSE(leaf_node1->has_render_surface());
2300 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422301 EXPECT_FALSE(root->is_clipped());
2302 EXPECT_FALSE(parent->is_clipped());
2303 EXPECT_FALSE(child1->is_clipped());
2304 EXPECT_FALSE(child2->is_clipped());
2305 EXPECT_FALSE(grand_child->is_clipped());
2306 EXPECT_FALSE(leaf_node1->is_clipped());
2307 EXPECT_FALSE(leaf_node2->is_clipped());
2308 EXPECT_TRUE(root->render_surface()->is_clipped());
2309 EXPECT_FALSE(child1->render_surface()->is_clipped());
2310 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2311 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582312
2313 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422314 EXPECT_FALSE(root->is_clipped());
2315 EXPECT_FALSE(parent->is_clipped());
2316 EXPECT_FALSE(child1->is_clipped());
2317 EXPECT_FALSE(child2->is_clipped());
2318 EXPECT_FALSE(grand_child->is_clipped());
2319 EXPECT_FALSE(leaf_node1->is_clipped());
2320 EXPECT_FALSE(leaf_node2->is_clipped());
2321 EXPECT_TRUE(root->render_surface()->is_clipped());
2322 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582323
2324 // Case 2: The root is clipped. In this case, layers that draw into the root
2325 // render surface are clipped by the root's bounds.
2326 root->SetMasksToBounds(true);
2327 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362328 root->test_properties()->force_render_surface = true;
2329 child1->test_properties()->force_render_surface = true;
2330 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582331 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262332 EXPECT_TRUE(root->has_render_surface());
2333 EXPECT_FALSE(parent->has_render_surface());
2334 EXPECT_TRUE(child1->has_render_surface());
2335 EXPECT_FALSE(child2->has_render_surface());
2336 EXPECT_TRUE(grand_child->has_render_surface());
2337 EXPECT_FALSE(leaf_node1->has_render_surface());
2338 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422339 EXPECT_TRUE(root->is_clipped());
2340 EXPECT_TRUE(parent->is_clipped());
2341 EXPECT_FALSE(child1->is_clipped());
2342 EXPECT_TRUE(child1->render_surface()->is_clipped());
2343 EXPECT_TRUE(child2->is_clipped());
2344 EXPECT_FALSE(grand_child->is_clipped());
2345 EXPECT_FALSE(grand_child->render_surface()->is_clipped());
2346 EXPECT_FALSE(leaf_node1->is_clipped());
2347 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582348 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2349 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422350 EXPECT_EQ(gfx::Rect(100, 100), child1->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582351 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
ajuma51d73f72015-10-19 19:43:582352 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2353
2354 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422355 EXPECT_TRUE(root->is_clipped());
2356 EXPECT_TRUE(parent->is_clipped());
2357 EXPECT_TRUE(child1->is_clipped());
2358 EXPECT_TRUE(child2->is_clipped());
2359 EXPECT_TRUE(grand_child->is_clipped());
2360 EXPECT_TRUE(leaf_node1->is_clipped());
2361 EXPECT_TRUE(leaf_node2->is_clipped());
ajuma51d73f72015-10-19 19:43:582362 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2363 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2364 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect());
2365 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2366 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect());
2367 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect());
2368 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2369
2370 root->SetMasksToBounds(false);
2371
2372 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the
2373 // parent clip rect only contributes to the subtree rooted at child2, since
2374 // the subtree rooted at child1 renders into a separate surface. Similarly,
2375 // child1's clip rect doesn't contribute to its descendants, since its only
2376 // child is a render surface. However, without surfaces, these clip rects
2377 // contribute to all descendants.
2378 parent->SetMasksToBounds(true);
2379 child1->SetMasksToBounds(true);
2380 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
jaydasika6b5a32bf2016-04-22 21:56:362381 root->test_properties()->force_render_surface = true;
2382 child1->test_properties()->force_render_surface = true;
2383 grand_child->test_properties()->force_render_surface = true;
ajuma51d73f72015-10-19 19:43:582384 ExecuteCalculateDrawProperties(root);
weiliangcc154ce22015-12-09 03:39:262385 EXPECT_TRUE(root->has_render_surface());
2386 EXPECT_FALSE(parent->has_render_surface());
2387 EXPECT_TRUE(child1->has_render_surface());
2388 EXPECT_FALSE(child2->has_render_surface());
2389 EXPECT_TRUE(grand_child->has_render_surface());
2390 EXPECT_FALSE(leaf_node1->has_render_surface());
2391 EXPECT_FALSE(leaf_node2->has_render_surface());
weiliangcbb2e8642016-03-04 00:24:422392 EXPECT_FALSE(root->is_clipped());
2393 EXPECT_TRUE(root->render_surface()->is_clipped());
2394 EXPECT_TRUE(parent->is_clipped());
2395 EXPECT_TRUE(child1->is_clipped());
2396 EXPECT_TRUE(child2->is_clipped());
2397 EXPECT_FALSE(grand_child->is_clipped());
2398 EXPECT_TRUE(grand_child->render_surface()->is_clipped());
2399 EXPECT_FALSE(leaf_node1->is_clipped());
2400 EXPECT_TRUE(leaf_node2->is_clipped());
2401 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582402 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2403 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2404 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
weiliangcbb2e8642016-03-04 00:24:422405 EXPECT_EQ(gfx::Rect(800, 800), grand_child->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582406 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2407
2408 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422409 EXPECT_FALSE(root->is_clipped());
2410 EXPECT_TRUE(root->render_surface()->is_clipped());
2411 EXPECT_TRUE(parent->is_clipped());
2412 EXPECT_TRUE(child1->is_clipped());
2413 EXPECT_TRUE(child2->is_clipped());
2414 EXPECT_TRUE(grand_child->is_clipped());
2415 EXPECT_TRUE(leaf_node1->is_clipped());
2416 EXPECT_TRUE(leaf_node2->is_clipped());
2417 EXPECT_EQ(gfx::Rect(100, 100), root->render_surface()->clip_rect());
ajuma51d73f72015-10-19 19:43:582418 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2419 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect());
2420 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2421 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect());
2422 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect());
2423 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2424}
2425
2426TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) {
2427 // Tests that draw properties are computed correctly when we disable and then
2428 // re-enable separate surfaces.
2429 LayerImpl* root = root_layer();
2430 LayerImpl* parent = AddChild<LayerImpl>(root);
2431 LayerImpl* child = AddChild<LayerImpl>(parent);
2432 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2433 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2434
2435 root->SetDrawsContent(true);
2436 parent->SetDrawsContent(true);
2437 child->SetDrawsContent(true);
2438 grand_child->SetDrawsContent(true);
2439 leaf_node->SetDrawsContent(true);
2440
2441 const gfx::Transform identity_matrix;
2442
2443 // child and grand_child get render surfaces when surfaces are enabled.
2444 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2445 gfx::PointF(), gfx::Size(100, 100), true, false,
2446 true);
2447 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2448 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2449 false, false);
2450 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2451 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2452 false, true);
2453 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2454 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2455 true, false, true);
2456 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
2457 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2458 true, false, false);
2459
2460 parent->SetMasksToBounds(true);
2461 child->SetMasksToBounds(true);
2462
weiliangcc154ce22015-12-09 03:39:262463 root->SetHasRenderSurface(true);
2464 child->SetHasRenderSurface(true);
2465 grand_child->SetHasRenderSurface(true);
2466
ajuma51d73f72015-10-19 19:43:582467 gfx::Transform expected_leaf_draw_transform_with_surfaces;
2468 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0);
2469
2470 gfx::Transform expected_leaf_draw_transform_without_surfaces;
2471 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0);
2472
2473 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422474 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252475 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582476 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2477 EXPECT_EQ(expected_leaf_draw_transform_with_surfaces,
ajumad9432e32015-11-30 19:43:442478 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582479
weiliangcc154ce22015-12-09 03:39:262480 root->SetHasRenderSurface(true);
2481 child->SetHasRenderSurface(true);
2482 grand_child->SetHasRenderSurface(true);
2483
ajuma51d73f72015-10-19 19:43:582484 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
weiliangcbb2e8642016-03-04 00:24:422485 EXPECT_TRUE(leaf_node->is_clipped());
ajuma51d73f72015-10-19 19:43:582486 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect());
2487 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect());
2488 EXPECT_EQ(expected_leaf_draw_transform_without_surfaces,
ajumad9432e32015-11-30 19:43:442489 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582490
weiliangcc154ce22015-12-09 03:39:262491 root->SetHasRenderSurface(true);
2492 child->SetHasRenderSurface(true);
2493 grand_child->SetHasRenderSurface(true);
2494
ajuma51d73f72015-10-19 19:43:582495 ExecuteCalculateDrawProperties(root);
weiliangcbb2e8642016-03-04 00:24:422496 EXPECT_FALSE(leaf_node->is_clipped());
weiliangc189c1a12016-04-11 16:16:252497 EXPECT_TRUE(leaf_node->render_target()->is_clipped());
ajuma51d73f72015-10-19 19:43:582498 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2499 EXPECT_EQ(expected_leaf_draw_transform_with_surfaces,
ajumad9432e32015-11-30 19:43:442500 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582501}
2502
[email protected]989386c2013-07-18 21:37:232503TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
enneab0fee42015-07-07 17:36:422504 LayerImpl* parent = root_layer();
2505 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2506 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
2507 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
2508 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2509 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2510 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2511 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2512 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
[email protected]fb661802013-03-25 01:59:322513
jaydasika8640f9f2015-11-10 01:34:362514 parent->SetDrawsContent(true);
2515 render_surface1->SetDrawsContent(true);
2516 child_of_rs1->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422517 grand_child_of_rs1->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362518 render_surface2->SetDrawsContent(true);
2519 child_of_rs2->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422520 grand_child_of_rs2->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362521 child_of_root->SetDrawsContent(true);
2522 grand_child_of_root->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322523
2524 gfx::Transform layer_transform;
2525 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322526
enneab0fee42015-07-07 17:36:422527 SetLayerPropertiesForTesting(
2528 parent, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2529 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2530 SetLayerPropertiesForTesting(
2531 render_surface1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2532 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2533 SetLayerPropertiesForTesting(
2534 render_surface2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2535 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2536 SetLayerPropertiesForTesting(
2537 child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2538 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2539 SetLayerPropertiesForTesting(
2540 child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2541 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2542 SetLayerPropertiesForTesting(
2543 child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2544 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2545 SetLayerPropertiesForTesting(
2546 grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2547 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2548 SetLayerPropertiesForTesting(
2549 grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2550 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2551 SetLayerPropertiesForTesting(
2552 grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2553 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
[email protected]fb661802013-03-25 01:59:322554
jaydasika9cb21c772016-05-10 22:37:082555 parent->layer_tree_impl()->BuildPropertyTreesForTesting();
2556
loyso9556c732016-03-11 07:54:582557 // Put an animated opacity on the render surface.
2558 AddOpacityTransitionToLayerWithPlayer(render_surface1->id(), timeline_impl(),
2559 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322560
loyso9556c732016-03-11 07:54:582561 // Also put an animated opacity on a layer without descendants.
2562 AddOpacityTransitionToLayerWithPlayer(grand_child_of_root->id(),
2563 timeline_impl(), 10.0, 1.f, 0.f, false);
[email protected]fb661802013-03-25 01:59:322564
loyso9556c732016-03-11 07:54:582565 // Put a transform animation on the render surface.
2566 AddAnimatedTransformToLayerWithPlayer(render_surface2->id(), timeline_impl(),
2567 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322568
loyso9556c732016-03-11 07:54:582569 // Also put transform animations on grand_child_of_root, and
2570 // grand_child_of_rs2
2571 AddAnimatedTransformToLayerWithPlayer(grand_child_of_root->id(),
2572 timeline_impl(), 10.0, 30, 0);
2573 AddAnimatedTransformToLayerWithPlayer(grand_child_of_rs2->id(),
2574 timeline_impl(), 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:322575
jaydasika9cb21c772016-05-10 22:37:082576 parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneab0fee42015-07-07 17:36:422577 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322578
2579 // Only layers that are associated with render surfaces should have an actual
2580 // RenderSurface() value.
2581 ASSERT_TRUE(parent->render_surface());
2582 ASSERT_FALSE(child_of_root->render_surface());
2583 ASSERT_FALSE(grand_child_of_root->render_surface());
2584
2585 ASSERT_TRUE(render_surface1->render_surface());
2586 ASSERT_FALSE(child_of_rs1->render_surface());
2587 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2588
2589 ASSERT_TRUE(render_surface2->render_surface());
2590 ASSERT_FALSE(child_of_rs2->render_surface());
2591 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2592
2593 // Verify all render target accessors
weiliangc189c1a12016-04-11 16:16:252594 EXPECT_EQ(parent->render_surface(), parent->render_target());
2595 EXPECT_EQ(parent->render_surface(), child_of_root->render_target());
2596 EXPECT_EQ(parent->render_surface(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322597
weiliangc189c1a12016-04-11 16:16:252598 EXPECT_EQ(render_surface1->render_surface(),
2599 render_surface1->render_target());
2600 EXPECT_EQ(render_surface1->render_surface(), child_of_rs1->render_target());
2601 EXPECT_EQ(render_surface1->render_surface(),
2602 grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322603
weiliangc189c1a12016-04-11 16:16:252604 EXPECT_EQ(render_surface2->render_surface(),
2605 render_surface2->render_target());
2606 EXPECT_EQ(render_surface2->render_surface(), child_of_rs2->render_target());
2607 EXPECT_EQ(render_surface2->render_surface(),
2608 grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322609
[email protected]fb661802013-03-25 01:59:322610 // Verify screen_space_transform_is_animating values
2611 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2612 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2613 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2614 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322615 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2616 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2617 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322618 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2619 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2620
2621 // Sanity check. If these fail there is probably a bug in the test itself.
2622 // It is expected that we correctly set up transforms so that the y-component
2623 // of the screen-space transform encodes the "depth" of the layer in the tree.
ajumab6aa1c62015-12-01 21:01:102624 EXPECT_FLOAT_EQ(1.0, parent->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]803f6b52013-09-12 00:51:262625 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102626 child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322627 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102628 3.0, grand_child_of_root->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322629
[email protected]803f6b52013-09-12 00:51:262630 EXPECT_FLOAT_EQ(2.0,
ajumab6aa1c62015-12-01 21:01:102631 render_surface1->ScreenSpaceTransform().matrix().get(1, 3));
2632 EXPECT_FLOAT_EQ(3.0, child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322633 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102634 4.0, grand_child_of_rs1->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322635
[email protected]803f6b52013-09-12 00:51:262636 EXPECT_FLOAT_EQ(3.0,
ajumab6aa1c62015-12-01 21:01:102637 render_surface2->ScreenSpaceTransform().matrix().get(1, 3));
2638 EXPECT_FLOAT_EQ(4.0, child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322639 EXPECT_FLOAT_EQ(
ajumab6aa1c62015-12-01 21:01:102640 5.0, grand_child_of_rs2->ScreenSpaceTransform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322641}
2642
ajuma9384b9c22015-09-17 20:35:032643TEST_F(LayerTreeHostCommonTest, LargeTransforms) {
2644 LayerImpl* parent = root_layer();
2645 LayerImpl* child = AddChildToRoot<LayerImpl>();
2646 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2647
2648 grand_child->SetDrawsContent(true);
2649
2650 gfx::Transform large_transform;
2651 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2652
2653 gfx::Transform identity;
2654
2655 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(),
2656 gfx::Size(10, 10), true, false, true);
2657 SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(),
2658 gfx::PointF(), gfx::Size(10, 10), true, false,
2659 false);
2660 SetLayerPropertiesForTesting(grand_child, large_transform, gfx::Point3F(),
2661 gfx::PointF(), gfx::Size(10, 10), true, false,
2662 false);
2663 ExecuteCalculateDrawProperties(parent);
2664
2665 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
2666}
2667
ajuma315a4782015-07-24 21:16:342668TEST_F(LayerTreeHostCommonTest,
2669 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
2670 LayerImpl* parent = root_layer();
2671 LayerImpl* child = AddChild<LayerImpl>(parent);
2672 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2673 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2674
2675 parent->SetDrawsContent(true);
2676 child->SetDrawsContent(true);
2677 grand_child->SetDrawsContent(true);
2678 great_grand_child->SetDrawsContent(true);
2679
2680 gfx::Transform identity;
2681
2682 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(),
2683 gfx::Size(10, 10), true, false, true);
2684 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
2685 gfx::Size(10, 10), true, false, false);
2686 SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(),
2687 gfx::PointF(), gfx::Size(10, 10), true, false,
2688 false);
2689 SetLayerPropertiesForTesting(great_grand_child, identity, gfx::Point3F(),
2690 gfx::PointF(), gfx::Size(10, 10), true, false,
2691 false);
2692
2693 // Add a transform animation with a start delay to |grand_child|.
danakj60bc3bc2016-04-09 00:24:482694 std::unique_ptr<Animation> animation = Animation::Create(
2695 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1,
loyso0c8e4402016-02-25 04:12:302696 TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:552697 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:342698 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso9556c732016-03-11 07:54:582699 AddAnimationToLayerWithPlayer(grand_child->id(), timeline_impl(),
2700 std::move(animation));
ajuma315a4782015-07-24 21:16:342701 ExecuteCalculateDrawProperties(parent);
2702
2703 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2704 EXPECT_FALSE(child->screen_space_transform_is_animating());
2705
2706 EXPECT_FALSE(grand_child->TransformIsAnimating());
2707 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2708 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2709 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2710}
2711
weiliangc6da32862016-04-20 16:40:112712TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForIdentityTransform) {
2713 // Test visible layer rect and drawable content rect are calculated correctly
2714 // correctly for identity transforms.
[email protected]fb661802013-03-25 01:59:322715
[email protected]2c7c6702013-03-26 03:14:052716 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322717 gfx::Transform layer_to_surface_transform;
2718
2719 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232720 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
weiliangc6da32862016-04-20 16:40:112721 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2722 gfx::Rect expected_drawable_content_rect = gfx::Rect(10, 10, 30, 30);
2723 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2724 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2725 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2726 EXPECT_EQ(expected_drawable_content_rect,
2727 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322728
2729 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052730 layer_content_rect = gfx::Rect(120, 120, 30, 30);
weiliangc6da32862016-04-20 16:40:112731 expected_visible_layer_rect = gfx::Rect();
2732 expected_drawable_content_rect = gfx::Rect();
2733 drawing_layer = TestVisibleRectAndDrawableContentRect(
2734 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2735 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2736 EXPECT_EQ(expected_drawable_content_rect,
2737 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322738
2739 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052740 layer_content_rect = gfx::Rect(80, 80, 30, 30);
weiliangc6da32862016-04-20 16:40:112741 expected_visible_layer_rect = gfx::Rect(20, 20);
2742 expected_drawable_content_rect = gfx::Rect(80, 80, 20, 20);
2743 drawing_layer = TestVisibleRectAndDrawableContentRect(
2744 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2745 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2746 EXPECT_EQ(expected_drawable_content_rect,
2747 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322748}
2749
weiliangc6da32862016-04-20 16:40:112750TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor2DRotations) {
2751 // Test visible layer rect and drawable content rect are calculated correctly
2752 // for rotations about z-axis (i.e. 2D rotations).
[email protected]fb661802013-03-25 01:59:322753
[email protected]2c7c6702013-03-26 03:14:052754 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2755 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322756 gfx::Transform layer_to_surface_transform;
2757
2758 // Case 1: Layer is contained within the surface.
2759 layer_to_surface_transform.MakeIdentity();
2760 layer_to_surface_transform.Translate(50.0, 50.0);
2761 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112762 gfx::Rect expected_visible_layer_rect = gfx::Rect(30, 30);
2763 gfx::Rect expected_drawable_content_rect = gfx::Rect(28, 50, 44, 43);
2764 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2765 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2766 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2767 EXPECT_EQ(expected_drawable_content_rect,
2768 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322769
2770 // Case 2: Layer is outside the surface rect.
2771 layer_to_surface_transform.MakeIdentity();
2772 layer_to_surface_transform.Translate(-50.0, 0.0);
2773 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112774 expected_visible_layer_rect = gfx::Rect();
2775 expected_drawable_content_rect = gfx::Rect();
2776 drawing_layer = TestVisibleRectAndDrawableContentRect(
2777 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2778 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2779 EXPECT_EQ(expected_drawable_content_rect,
2780 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322781
2782 // Case 3: The layer is rotated about its top-left corner. In surface space,
2783 // the layer is oriented diagonally, with the left half outside of the render
2784 // surface. In this case, the g should still be the entire layer
2785 // (remember the g is computed in layer space); both the top-left
2786 // and bottom-right corners of the layer are still visible.
2787 layer_to_surface_transform.MakeIdentity();
2788 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112789 expected_visible_layer_rect = gfx::Rect(30, 30);
2790 expected_drawable_content_rect = gfx::Rect(22, 43);
2791 drawing_layer = TestVisibleRectAndDrawableContentRect(
2792 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2793 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2794 EXPECT_EQ(expected_drawable_content_rect,
2795 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322796
2797 // Case 4: The layer is rotated about its top-left corner, and translated
2798 // upwards. In surface space, the layer is oriented diagonally, with only the
2799 // top corner of the surface overlapping the layer. In layer space, the render
2800 // surface overlaps the right side of the layer. The g should be
2801 // the layer's right half.
2802 layer_to_surface_transform.MakeIdentity();
2803 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2804 layer_to_surface_transform.Rotate(45.0);
weiliangc6da32862016-04-20 16:40:112805 // Right half of layer bounds.
2806 expected_visible_layer_rect = gfx::Rect(15, 0, 15, 30);
2807 expected_drawable_content_rect = gfx::Rect(22, 22);
2808 drawing_layer = TestVisibleRectAndDrawableContentRect(
2809 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2810 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2811 EXPECT_EQ(expected_drawable_content_rect,
2812 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322813}
2814
weiliangc6da32862016-04-20 16:40:112815TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dOrthographicTransform) {
2816 // Test visible layer rect and drawable content rect are calculated correctly
2817 // for 3d transforms.
[email protected]fb661802013-03-25 01:59:322818
[email protected]2c7c6702013-03-26 03:14:052819 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2820 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322821 gfx::Transform layer_to_surface_transform;
2822
2823 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2824 // degrees, should be fully contained in the render surface.
weiliangc6da32862016-04-20 16:40:112825 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]fb661802013-03-25 01:59:322826 layer_to_surface_transform.MakeIdentity();
2827 layer_to_surface_transform.RotateAboutYAxis(45.0);
weiliangc6da32862016-04-20 16:40:112828 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2829 gfx::Rect expected_drawable_content_rect = gfx::Rect(71, 100);
2830 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2831 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2832 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2833 EXPECT_EQ(expected_drawable_content_rect,
2834 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322835
2836 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2837 // degrees, but shifted to the side so only the right-half the layer would be
2838 // visible on the surface.
weiliangc6da32862016-04-20 16:40:112839 // 50 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262840 SkMScalar half_width_of_rotated_layer =
2841 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322842 layer_to_surface_transform.MakeIdentity();
2843 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232844 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2845 // edge of the layer.
weiliangc6da32862016-04-20 16:40:112846 // Tight half of the layer.
2847 expected_visible_layer_rect = gfx::Rect(50, 0, 50, 100);
2848 expected_drawable_content_rect = gfx::Rect(36, 100);
2849 drawing_layer = TestVisibleRectAndDrawableContentRect(
2850 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2851 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2852 EXPECT_EQ(expected_drawable_content_rect,
2853 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322854}
2855
weiliangc6da32862016-04-20 16:40:112856TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsFor3dPerspectiveTransform) {
2857 // Test visible layer rect and drawable content rect are calculated correctly
2858 // when the layer has a perspective projection onto the target surface.
[email protected]fb661802013-03-25 01:59:322859
[email protected]2c7c6702013-03-26 03:14:052860 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2861 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322862 gfx::Transform layer_to_surface_transform;
2863
2864 // Case 1: Even though the layer is twice as large as the surface, due to
2865 // perspective foreshortening, the layer will fit fully in the surface when
2866 // its translated more than the perspective amount.
2867 layer_to_surface_transform.MakeIdentity();
2868
2869 // The following sequence of transforms applies the perspective about the
2870 // center of the surface.
2871 layer_to_surface_transform.Translate(50.0, 50.0);
2872 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2873 layer_to_surface_transform.Translate(-50.0, -50.0);
2874
2875 // This translate places the layer in front of the surface's projection plane.
2876 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2877
weiliangc6da32862016-04-20 16:40:112878 // Layer position is (-50, -50), visible rect in layer space is layer bounds
2879 // offset by layer position.
2880 gfx::Rect expected_visible_layer_rect = gfx::Rect(50, 50, 150, 150);
2881 gfx::Rect expected_drawable_content_rect = gfx::Rect(38, 38);
2882 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2883 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2884 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2885 EXPECT_EQ(expected_drawable_content_rect,
2886 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322887
2888 // Case 2: same projection as before, except that the layer is also translated
2889 // to the side, so that only the right half of the layer should be visible.
2890 //
2891 // Explanation of expected result: The perspective ratio is (z distance
2892 // between layer and camera origin) / (z distance between projection plane and
2893 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
weiliangc6da32862016-04-20 16:40:112894 // move a layer by translating -25 units in projected surface units (so that
[email protected]fb661802013-03-25 01:59:322895 // only half of it is visible), then we would need to translate by (-36 / 9) *
weiliangc6da32862016-04-20 16:40:112896 // -25 == -100 in the layer's units.
2897 layer_to_surface_transform.Translate3d(-100.0, 0.0, 0.0);
2898 // Visible layer rect is moved by 100, and drawable content rect is in target
2899 // space and is moved by 25.
2900 expected_visible_layer_rect = gfx::Rect(150, 50, 50, 150);
2901 expected_drawable_content_rect = gfx::Rect(13, 38);
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
weiliangc6da32862016-04-20 16:40:112909TEST_F(LayerTreeHostCommonDrawRectsTest,
2910 DrawRectsFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322911 // There is currently no explicit concept of an orthographic projection plane
2912 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2913 // are technically behind the surface in an orthographic world should not be
2914 // clipped when they are flattened to the surface.
2915
[email protected]2c7c6702013-03-26 03:14:052916 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2917 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322918 gfx::Transform layer_to_surface_transform;
2919
2920 // This sequence of transforms effectively rotates the layer about the y-axis
2921 // at the center of the layer.
2922 layer_to_surface_transform.MakeIdentity();
2923 layer_to_surface_transform.Translate(50.0, 0.0);
2924 layer_to_surface_transform.RotateAboutYAxis(45.0);
2925 layer_to_surface_transform.Translate(-50.0, 0.0);
2926
weiliangc6da32862016-04-20 16:40:112927 // Layer is rotated about Y Axis, and its width is 100/sqrt(2) in surface
2928 // space.
2929 gfx::Rect expected_visible_layer_rect = gfx::Rect(100, 100);
2930 gfx::Rect expected_drawable_content_rect = gfx::Rect(14, 0, 72, 100);
2931 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2932 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2933 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2934 EXPECT_EQ(expected_drawable_content_rect,
2935 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322936}
2937
weiliangc6da32862016-04-20 16:40:112938TEST_F(LayerTreeHostCommonDrawRectsTest,
2939 DrawRectsFor3dPerspectiveWhenClippedByW) {
2940 // Test visible layer rect and drawable content rect are calculated correctly
2941 // when projecting a surface onto a layer, but the layer is partially behind
2942 // the camera (not just behind the projection plane). In this case, the
2943 // cartesian coordinates may seem to be valid, but actually they are not. The
2944 // visible rect needs to be properly clipped by the w = 0 plane in homogeneous
2945 // coordinates before converting to cartesian coordinates. The drawable
2946 // content rect would be entire surface rect because layer is rotated at the
2947 // camera position.
[email protected]fb661802013-03-25 01:59:322948
weiliangc6da32862016-04-20 16:40:112949 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 200, 200);
2950 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 2);
[email protected]fb661802013-03-25 01:59:322951 gfx::Transform layer_to_surface_transform;
2952
2953 // The layer is positioned so that the right half of the layer should be in
2954 // front of the camera, while the other half is behind the surface's
2955 // projection plane. The following sequence of transforms applies the
2956 // perspective and rotation about the center of the layer.
2957 layer_to_surface_transform.MakeIdentity();
2958 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
weiliangc6da32862016-04-20 16:40:112959 layer_to_surface_transform.Translate3d(10.0, 0.0, 1.0);
2960 layer_to_surface_transform.RotateAboutYAxis(-45.0);
2961 layer_to_surface_transform.Translate(-10, -1);
[email protected]fb661802013-03-25 01:59:322962
2963 // Sanity check that this transform does indeed cause w < 0 when applying the
2964 // transform, otherwise this code is not testing the intended scenario.
2965 bool clipped;
2966 MathUtil::MapQuad(layer_to_surface_transform,
2967 gfx::QuadF(gfx::RectF(layer_content_rect)),
2968 &clipped);
2969 ASSERT_TRUE(clipped);
2970
weiliangc6da32862016-04-20 16:40:112971 gfx::Rect expected_visible_layer_rect = gfx::Rect(0, 1, 10, 1);
2972 gfx::Rect expected_drawable_content_rect = target_surface_rect;
2973 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
2974 target_surface_rect, layer_to_surface_transform, layer_content_rect);
2975 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
2976 EXPECT_EQ(expected_drawable_content_rect,
2977 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322978}
2979
weiliangc6da32862016-04-20 16:40:112980TEST_F(LayerTreeHostCommonDrawRectsTest, DrawRectsForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322981 // To determine visible rect in layer space, there needs to be an
2982 // un-projection from surface space to layer space. When the original
2983 // transform was a perspective projection that was clipped, it returns a rect
2984 // that encloses the clipped bounds. Un-projecting this new rect may require
2985 // clipping again.
2986
2987 // This sequence of transforms causes one corner of the layer to protrude
2988 // across the w = 0 plane, and should be clipped.
weiliangc6da32862016-04-20 16:40:112989 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 150, 150);
2990 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322991 gfx::Transform layer_to_surface_transform;
2992 layer_to_surface_transform.MakeIdentity();
weiliangc6da32862016-04-20 16:40:112993 layer_to_surface_transform.Translate(10, 10);
[email protected]fb661802013-03-25 01:59:322994 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2995 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2996 layer_to_surface_transform.RotateAboutYAxis(45.0);
2997 layer_to_surface_transform.RotateAboutXAxis(80.0);
weiliangc6da32862016-04-20 16:40:112998 layer_to_surface_transform.Translate(-10, -10);
[email protected]fb661802013-03-25 01:59:322999
3000 // Sanity check that un-projection does indeed cause w < 0, otherwise this
3001 // code is not testing the intended scenario.
3002 bool clipped;
danakj5e6ff6d2015-09-05 04:43:443003 gfx::RectF clipped_rect = MathUtil::MapClippedRect(
3004 layer_to_surface_transform, gfx::RectF(layer_content_rect));
[email protected]fb661802013-03-25 01:59:323005 MathUtil::ProjectQuad(
3006 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
3007 ASSERT_TRUE(clipped);
3008
3009 // Only the corner of the layer is not visible on the surface because of being
3010 // clipped. But, the net result of rounding visible region to an axis-aligned
3011 // rect is that the entire layer should still be considered visible.
weiliangc6da32862016-04-20 16:40:113012 gfx::Rect expected_visible_layer_rect = layer_content_rect;
3013 gfx::Rect expected_drawable_content_rect = target_surface_rect;
3014 LayerImpl* drawing_layer = TestVisibleRectAndDrawableContentRect(
3015 target_surface_rect, layer_to_surface_transform, layer_content_rect);
3016 EXPECT_EQ(expected_visible_layer_rect, drawing_layer->visible_layer_rect());
3017 EXPECT_EQ(expected_drawable_content_rect,
3018 drawing_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323019}
3020
miletus9d3da522015-06-05 19:45:073021TEST_F(LayerTreeHostCommonTest,
3022 VisibleRectsForPositionedRootLayerClippedByViewport) {
enne6c281f6e2015-08-18 23:23:003023 LayerImpl* root = root_layer();
3024 root->SetDrawsContent(true);
miletus9d3da522015-06-05 19:45:073025
3026 gfx::Transform identity_matrix;
3027 // Root layer is positioned at (60, 70). The default device viewport size
3028 // is (0, 0, 100x100) in target space. So the root layer's visible rect
3029 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
enne6c281f6e2015-08-18 23:23:003030 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
miletus9d3da522015-06-05 19:45:073031 gfx::PointF(60, 70), gfx::Size(100, 100), true,
enne6c281f6e2015-08-18 23:23:003032 false, true);
3033 ExecuteCalculateDrawProperties(root);
miletus9d3da522015-06-05 19:45:073034
danakj5e6ff6d2015-09-05 04:43:443035 EXPECT_EQ(gfx::RectF(100.f, 100.f),
miletus9d3da522015-06-05 19:45:073036 root->render_surface()->DrawableContentRect());
3037 // In target space, not clipped.
3038 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
3039 // In layer space, clipped.
danakj5e6ff6d2015-09-05 04:43:443040 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
miletus9d3da522015-06-05 19:45:073041}
3042
[email protected]989386c2013-07-18 21:37:233043TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
weiliangc0dece732015-07-27 19:06:173044 LayerImpl* root = root_layer();
3045 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
3046 child1_layer->SetDrawsContent(true);
3047 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
3048 child2_layer->SetDrawsContent(true);
3049 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
3050 child3_layer->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283051
[email protected]fb661802013-03-25 01:59:323052 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173053 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3054 gfx::PointF(), gfx::Size(100, 100), true, false,
3055 true);
3056 SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(),
3057 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]fb661802013-03-25 01:59:323058 false);
weiliangc0dece732015-07-27 19:06:173059 SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(),
3060 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3061 false, false);
3062 SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(),
3063 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3064 true, false, false);
[email protected]fb661802013-03-25 01:59:323065
weiliangc0dece732015-07-27 19:06:173066 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323067
danakj5e6ff6d2015-09-05 04:43:443068 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323069 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323070
danakj64767d902015-06-19 00:10:433071 // Layers that do not draw content should have empty visible_layer_rects.
3072 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323073
danakj64767d902015-06-19 00:10:433074 // layer visible_layer_rects are clipped by their target surface.
weiliangc0dece732015-07-27 19:06:173075 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
3076 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
3077 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323078
3079 // layer drawable_content_rects are not clipped.
weiliangc0dece732015-07-27 19:06:173080 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
3081 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
3082 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323083}
3084
[email protected]989386c2013-07-18 21:37:233085TEST_F(LayerTreeHostCommonTest,
3086 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
weiliangc0dece732015-07-27 19:06:173087 LayerImpl* root = root_layer();
3088 LayerImpl* child = AddChildToRoot<LayerImpl>();
3089 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
3090 grand_child1->SetDrawsContent(true);
3091 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
3092 grand_child2->SetDrawsContent(true);
3093 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
3094 grand_child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283095
[email protected]fb661802013-03-25 01:59:323096 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173097 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3098 gfx::PointF(), gfx::Size(100, 100), true, false,
3099 true);
3100 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
3101 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]fb661802013-03-25 01:59:323102 false);
weiliangc0dece732015-07-27 19:06:173103 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
3104 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3105 false, false);
3106 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
3107 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3108 false, false);
3109 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
3110 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3111 true, false, false);
[email protected]fb661802013-03-25 01:59:323112
3113 child->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:173114 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323115
danakj5e6ff6d2015-09-05 04:43:443116 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323117 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323118
3119 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433120 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3121 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323122
3123 // All grandchild visible content rects should be clipped by child.
danakj64767d902015-06-19 00:10:433124 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
3125 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
3126 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323127
3128 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:323129 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
3130 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323131 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
3132}
3133
ajuma27442dd2015-03-30 19:19:483134TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
jaydasika6f972de2016-04-07 16:16:143135 LayerImpl* root = root_layer();
3136 LayerImpl* child = AddChild<LayerImpl>(root);
3137 LayerImpl* grand_child = AddChild<LayerImpl>(child);
ajuma27442dd2015-03-30 19:19:483138
3139 gfx::Transform identity_matrix;
3140 gfx::Transform child_scale_matrix;
3141 child_scale_matrix.Scale(0.25f, 0.25f);
3142 gfx::Transform grand_child_scale_matrix;
3143 grand_child_scale_matrix.Scale(0.246f, 0.246f);
jaydasika6f972de2016-04-07 16:16:143144 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3145 gfx::PointF(), gfx::Size(100, 100), true, false,
3146 true);
3147 SetLayerPropertiesForTesting(child, child_scale_matrix, gfx::Point3F(),
3148 gfx::PointF(), gfx::Size(10, 10), true, false,
3149 false);
3150 SetLayerPropertiesForTesting(grand_child, grand_child_scale_matrix,
ajuma27442dd2015-03-30 19:19:483151 gfx::Point3F(), gfx::PointF(),
jaydasika6f972de2016-04-07 16:16:143152 gfx::Size(100, 100), true, false, false);
ajuma27442dd2015-03-30 19:19:483153
3154 child->SetMasksToBounds(true);
jaydasika6f972de2016-04-07 16:16:143155 grand_child->SetDrawsContent(true);
3156 ExecuteCalculateDrawProperties(root);
ajuma27442dd2015-03-30 19:19:483157
3158 // The visible rect is expanded to integer coordinates in target space before
3159 // being projected back to layer space, where it is once again expanded to
3160 // integer coordinates.
jaydasika6f972de2016-04-07 16:16:143161 EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_layer_rect());
ajuma27442dd2015-03-30 19:19:483162}
3163
[email protected]989386c2013-07-18 21:37:233164TEST_F(LayerTreeHostCommonTest,
3165 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
weiliangc0dece732015-07-27 19:06:173166 LayerImpl* root = root_layer();
3167 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3168 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3169 child1->SetDrawsContent(true);
3170 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
3171 child2->SetDrawsContent(true);
3172 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
3173 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283174
[email protected]fb661802013-03-25 01:59:323175 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173176 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3177 gfx::PointF(), gfx::Size(100, 100), true, false,
3178 true);
3179 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3180 gfx::PointF(), gfx::Size(3, 4), true, false,
3181 true);
3182 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3183 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3184 false, false);
3185 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3186 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3187 false, false);
3188 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3189 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3190 true, false, false);
[email protected]fb661802013-03-25 01:59:323191
weiliangc0dece732015-07-27 19:06:173192 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323193
weiliangc0dece732015-07-27 19:06:173194 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323195
danakj5e6ff6d2015-09-05 04:43:443196 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323197 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323198
3199 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433200 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173201 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323202
3203 // An unclipped surface grows its DrawableContentRect to include all drawable
3204 // regions of the subtree.
danakj5e6ff6d2015-09-05 04:43:443205 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
weiliangc0dece732015-07-27 19:06:173206 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323207
3208 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:433209 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3210 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3211 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323212
hush6b614212014-12-04 22:37:323213 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3214 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3215 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323216}
3217
[email protected]989386c2013-07-18 21:37:233218TEST_F(LayerTreeHostCommonTest,
ajuma51d73f72015-10-19 19:43:583219 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) {
3220 LayerImpl* root = root_layer();
3221 LayerImpl* parent = AddChild<LayerImpl>(root);
3222 LayerImpl* child1 = AddChild<LayerImpl>(parent);
3223 LayerImpl* child2 = AddChild<LayerImpl>(parent);
3224 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1);
3225 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2);
3226 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
3227 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
3228
3229 root->SetDrawsContent(true);
3230 parent->SetDrawsContent(true);
3231 child1->SetDrawsContent(true);
3232 child2->SetDrawsContent(true);
3233 grand_child1->SetDrawsContent(true);
3234 grand_child2->SetDrawsContent(true);
3235 leaf_node1->SetDrawsContent(true);
3236 leaf_node2->SetDrawsContent(true);
3237
3238 const gfx::Transform identity_matrix;
3239
3240 // child1 and child2 get render surfaces when surfaces are enabled.
3241 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3242 gfx::PointF(), gfx::Size(100, 100), true, false,
3243 true);
3244 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
3245 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
3246 false, false);
3247 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3248 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
3249 false, true);
3250 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3251 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
3252 false, true);
3253 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
3254 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
3255 true, false, false);
3256 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
3257 gfx::PointF(7.f, 7.f), gfx::Size(1500, 1500),
3258 true, false, false);
3259 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
3260 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
3261 true, false, false);
3262 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
3263 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
3264 true, false, false);
3265
3266 // Case 1: No layers clip. Visible rects are clipped by the viewport, but the
3267 // viewport clip doesn't apply to layers that draw into unclipped surfaces.
3268 // Each layer's drawable content rect is its bounds in target space; the only
3269 // thing that changes with surfaces disabled is that target space is always
3270 // screen space.
weiliangcc154ce22015-12-09 03:39:263271 root->SetHasRenderSurface(true);
3272 child1->SetHasRenderSurface(true);
3273 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583274 ExecuteCalculateDrawProperties(root);
3275 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3276 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect());
3277 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3278 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3279 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child1->visible_layer_rect());
3280 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3281 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node1->visible_layer_rect());
3282 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node2->visible_layer_rect());
3283
3284 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3285 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3286 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3287 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3288 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3289 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3290 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3291 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3292
3293 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3294 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3295 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3296 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3297 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3298 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3299 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3300 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3301 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3302
3303 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3304 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3305 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3306 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3307 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500),
3308 grand_child1->drawable_content_rect());
3309 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3310 grand_child2->drawable_content_rect());
3311 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect());
3312 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect());
3313
3314 // Case 2: The parent clips. In this case, neither surface is unclipped, so
3315 // all visible layer rects are clipped by the intersection of all ancestor
3316 // clips, whether or not surfaces are disabled. However, drawable content
3317 // rects are clipped only until the next render surface is reached, so
3318 // descendants of parent have their drawable content rects clipped only when
3319 // surfaces are disabled.
3320 parent->SetMasksToBounds(true);
3321 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:263322 root->SetHasRenderSurface(true);
3323 child1->SetHasRenderSurface(true);
3324 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583325 ExecuteCalculateDrawProperties(root);
3326 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3327 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3328 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3329 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3330 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3331 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3332 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3333 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3334
3335 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3336 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3337 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3338 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3339 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3340 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3341 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3342 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3343
3344 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3345 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3346 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3347 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3348 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3349 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3350 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3351 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3352 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3353
3354 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3355 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3356 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect());
3357 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect());
3358 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect());
3359 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect());
3360 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect());
3361 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect());
3362
3363 parent->SetMasksToBounds(false);
3364
3365 // Case 3: child1 and grand_child2 clip. In this case, descendants of these
3366 // layers have their visible rects clipped by them; without surfaces, these
3367 // rects are also clipped by the viewport. Similarly, descendants of these
3368 // layers have their drawable content rects clipped by them.
3369 child1->SetMasksToBounds(true);
3370 grand_child2->SetMasksToBounds(true);
3371 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
weiliangcc154ce22015-12-09 03:39:263372 root->SetHasRenderSurface(true);
3373 child1->SetHasRenderSurface(true);
3374 child2->SetHasRenderSurface(true);
ajuma51d73f72015-10-19 19:43:583375 ExecuteCalculateDrawProperties(root);
3376 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3377 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3378 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3379 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3380 EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect());
3381 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3382 EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect());
3383 EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect());
3384
3385 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3386 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3387 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3388 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3389 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect());
3390 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3391 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect());
3392 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect());
3393
3394 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3395 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3396 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3397 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3398 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3399 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3400 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3401 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3402 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3403
3404 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3405 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3406 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3407 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3408 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect());
3409 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3410 grand_child2->drawable_content_rect());
3411 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect());
3412 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect());
3413}
3414
3415TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:023416 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
enne6c281f6e2015-08-18 23:23:003417 LayerImpl* root = root_layer();
3418 LayerImpl* child1 = AddChild<LayerImpl>(root);
3419 LayerImpl* child2 = AddChild<LayerImpl>(root);
3420 LayerImpl* child3 = AddChild<LayerImpl>(root);
3421 child1->SetDrawsContent(true);
3422 child2->SetDrawsContent(true);
3423 child3->SetDrawsContent(true);
hush887bb542014-12-02 22:49:023424
3425 gfx::Transform identity_matrix;
enne6c281f6e2015-08-18 23:23:003426 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3427 gfx::PointF(), gfx::Size(100, 100), true, false,
3428 true);
3429 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023430 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
enne6c281f6e2015-08-18 23:23:003431 false, false);
3432 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023433 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
enne6c281f6e2015-08-18 23:23:003434 false, false);
3435 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023436 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
enne6c281f6e2015-08-18 23:23:003437 true, false, false);
hush887bb542014-12-02 22:49:023438
enne6c281f6e2015-08-18 23:23:003439 LayerImplList render_surface_layer_list_impl;
hush887bb542014-12-02 22:49:023440 // Now set the root render surface an empty clip.
enne6c281f6e2015-08-18 23:23:003441 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:383442 root, gfx::Size(), &render_surface_layer_list_impl);
hush887bb542014-12-02 22:49:023443
sunxdb365de02016-04-28 20:32:573444 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
hush887bb542014-12-02 22:49:023445 ASSERT_TRUE(root->render_surface());
3446 EXPECT_FALSE(root->is_clipped());
3447
3448 gfx::Rect empty;
3449 EXPECT_EQ(empty, root->render_surface()->clip_rect());
3450 EXPECT_TRUE(root->render_surface()->is_clipped());
3451
3452 // Visible content rect calculation will check if the target surface is
3453 // clipped or not. An empty clip rect does not indicate the render surface
3454 // is unclipped.
danakj64767d902015-06-19 00:10:433455 EXPECT_EQ(empty, child1->visible_layer_rect());
3456 EXPECT_EQ(empty, child2->visible_layer_rect());
3457 EXPECT_EQ(empty, child3->visible_layer_rect());
hush887bb542014-12-02 22:49:023458}
3459
3460TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233461 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
weiliangc0dece732015-07-27 19:06:173462 LayerImpl* root = root_layer();
3463 LayerImpl* child = AddChildToRoot<LayerImpl>();
3464 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283465
[email protected]630ddad2013-08-16 03:01:323466 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473467 gfx::Transform identity_matrix;
3468 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323469 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473470
weiliangc0dece732015-07-27 19:06:173471 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3472 gfx::PointF(), gfx::Size(100, 100), true, false,
3473 true);
3474 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3475 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3476 false, false);
[email protected]451107a32013-04-10 05:12:473477
weiliangc0dece732015-07-27 19:06:173478 ExecuteCalculateDrawProperties(root);
[email protected]451107a32013-04-10 05:12:473479
danakj64767d902015-06-19 00:10:433480 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473481 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323482
[email protected]08bdf1b2014-04-16 23:23:293483 // Case 2: a matrix with flattened z, uninvertible and not visible according
3484 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:323485 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263486 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323487 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3488
weiliangc0dece732015-07-27 19:06:173489 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3490 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3491 false, false);
[email protected]630ddad2013-08-16 03:01:323492
weiliangc0dece732015-07-27 19:06:173493 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323494
danakj64767d902015-06-19 00:10:433495 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293496 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323497
[email protected]08bdf1b2014-04-16 23:23:293498 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:323499 uninvertible_matrix.MakeIdentity();
3500 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263501 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323502 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3503
weiliangc0dece732015-07-27 19:06:173504 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3505 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3506 false, false);
[email protected]630ddad2013-08-16 03:01:323507
weiliangc0dece732015-07-27 19:06:173508 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323509
danakj64767d902015-06-19 00:10:433510 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293511 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473512}
3513
[email protected]989386c2013-07-18 21:37:233514TEST_F(LayerTreeHostCommonTest,
ajumaae0dc2d2015-08-05 21:55:563515 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
3516 LayerImpl* root = root_layer();
3517 LayerImpl* child = AddChildToRoot<LayerImpl>();
3518 LayerImpl* grand_child = AddChild<LayerImpl>(child);
3519 child->SetDrawsContent(true);
3520 grand_child->SetDrawsContent(true);
3521
3522 gfx::Transform identity_matrix;
3523
3524 gfx::Transform perspective;
3525 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3526
3527 gfx::Transform rotation;
3528 rotation.RotateAboutYAxis(45.0);
3529
3530 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3531 gfx::PointF(), gfx::Size(100, 100), true, false,
3532 true);
3533 SetLayerPropertiesForTesting(child, perspective, gfx::Point3F(),
3534 gfx::PointF(10.f, 10.f), gfx::Size(100, 100),
3535 false, true, false);
3536 SetLayerPropertiesForTesting(grand_child, rotation, gfx::Point3F(),
3537 gfx::PointF(), gfx::Size(100, 100), false, true,
3538 false);
3539
3540 ExecuteCalculateDrawProperties(root);
3541
3542 // Though all layers have invertible transforms, matrix multiplication using
3543 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053544 EXPECT_FALSE(root->layer_tree_impl()
3545 ->property_trees()
3546 ->transform_tree.Node(grand_child->transform_tree_index())
3547 ->data.ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563548
sunxd71aea3e2016-04-01 23:48:053549 // CalcDrawProps skips a subtree when a layer's screen space transform is
3550 // uninvertible
3551 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
ajumaae0dc2d2015-08-05 21:55:563552}
3553
3554TEST_F(LayerTreeHostCommonTest,
3555 OcclusionForLayerWithUninvertibleDrawTransform) {
khushalsagarb64b360d2015-10-21 19:25:163556 FakeImplTaskRunnerProvider task_runner_provider;
ajumaae0dc2d2015-08-05 21:55:563557 TestSharedBitmapManager shared_bitmap_manager;
3558 TestTaskGraphRunner task_graph_runner;
danakj60bc3bc2016-04-09 00:24:483559 std::unique_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
khushalsagarb64b360d2015-10-21 19:25:163560 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
ajumaae0dc2d2015-08-05 21:55:563561 &task_graph_runner);
danakj60bc3bc2016-04-09 00:24:483562 std::unique_ptr<LayerImpl> root =
3563 LayerImpl::Create(host_impl.active_tree(), 1);
3564 std::unique_ptr<LayerImpl> child =
3565 LayerImpl::Create(host_impl.active_tree(), 2);
3566 std::unique_ptr<LayerImpl> grand_child =
ajumaae0dc2d2015-08-05 21:55:563567 LayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:483568 std::unique_ptr<LayerImpl> occluding_child =
ajumaae0dc2d2015-08-05 21:55:563569 LayerImpl::Create(host_impl.active_tree(), 4);
3570 child->SetDrawsContent(true);
3571 grand_child->SetDrawsContent(true);
3572 occluding_child->SetDrawsContent(true);
3573 occluding_child->SetContentsOpaque(true);
3574
3575 gfx::Transform identity_matrix;
3576 gfx::Transform perspective;
3577 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3578
3579 gfx::Transform rotation;
3580 rotation.RotateAboutYAxis(45.0);
3581
3582 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
3583 gfx::PointF(), gfx::Size(1000, 1000), true,
3584 false, true);
3585 SetLayerPropertiesForTesting(child.get(), perspective, gfx::Point3F(),
3586 gfx::PointF(10.f, 10.f), gfx::Size(300, 300),
3587 false, true, false);
3588 SetLayerPropertiesForTesting(grand_child.get(), rotation, gfx::Point3F(),
3589 gfx::PointF(), gfx::Size(200, 200), false, true,
3590 false);
3591 SetLayerPropertiesForTesting(occluding_child.get(), identity_matrix,
3592 gfx::Point3F(), gfx::PointF(),
3593 gfx::Size(200, 200), false, false, false);
3594
3595 host_impl.SetViewportSize(root->bounds());
3596
danakja04855a2015-11-18 20:39:103597 child->AddChild(std::move(grand_child));
3598 root->AddChild(std::move(child));
3599 root->AddChild(std::move(occluding_child));
3600 host_impl.active_tree()->SetRootLayer(std::move(root));
sievers71c62dd52015-10-07 01:44:393601 host_impl.SetVisible(true);
revemand180dfc32015-09-24 00:19:433602 host_impl.InitializeRenderer(output_surface.get());
jaydasikad7dea632015-11-06 04:40:123603 host_impl.active_tree()->BuildPropertyTreesForTesting();
ajumaae0dc2d2015-08-05 21:55:563604 bool update_lcd_text = false;
3605 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3606
3607 LayerImpl* grand_child_ptr =
vollick83fbfc82016-03-22 18:33:273608 host_impl.active_tree()->root_layer()->children()[0]->children()[0];
ajumaae0dc2d2015-08-05 21:55:563609
3610 // Though all layers have invertible transforms, matrix multiplication using
3611 // floating-point math makes the draw transform uninvertible.
sunxd71aea3e2016-04-01 23:48:053612 EXPECT_FALSE(
3613 host_impl.active_tree()
3614 ->property_trees()
3615 ->transform_tree.Node(grand_child_ptr->transform_tree_index())
3616 ->data.ancestors_are_invertible);
ajumaae0dc2d2015-08-05 21:55:563617
sunxd71aea3e2016-04-01 23:48:053618 // Since |grand_child| has an uninvertible screen space transform, it is
3619 // skipped so
3620 // that we are not computing its occlusion_in_content_space.
3621 gfx::Rect layer_bounds = gfx::Rect();
ajumaae0dc2d2015-08-05 21:55:563622 EXPECT_EQ(
3623 layer_bounds,
3624 grand_child_ptr->draw_properties()
3625 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
3626}
3627
3628TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233629 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
weiliangc0dece732015-07-27 19:06:173630 LayerImpl* root = root_layer();
3631 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3632 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3633 child1->SetDrawsContent(true);
3634 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
3635 child2->SetDrawsContent(true);
3636 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
3637 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283638
[email protected]fb661802013-03-25 01:59:323639 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173640 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3641 gfx::PointF(), gfx::Size(100, 100), true, false,
3642 true);
3643 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3644 gfx::PointF(), gfx::Size(3, 4), true, false,
3645 true);
3646 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3647 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3648 false, false);
3649 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3650 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3651 false, false);
3652 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3653 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3654 true, false, false);
[email protected]fb661802013-03-25 01:59:323655
3656 root->SetMasksToBounds(true);
[email protected]fb661802013-03-25 01:59:323657
weiliangc0dece732015-07-27 19:06:173658 ExecuteCalculateDrawProperties(root);
3659
3660 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323661
danakj5e6ff6d2015-09-05 04:43:443662 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323663 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323664
3665 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433666 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173667 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323668
3669 // A clipped surface grows its DrawableContentRect to include all drawable
3670 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443671 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
weiliangc0dece732015-07-27 19:06:173672 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323673
3674 // All layers that draw content into the surface have their visible content
3675 // rect clipped by the surface clip rect.
danakj64767d902015-06-19 00:10:433676 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3677 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3678 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323679
3680 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323681 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3682 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3683 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323684}
3685
[email protected]989386c2013-07-18 21:37:233686TEST_F(LayerTreeHostCommonTest,
3687 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323688 // Check that clipping does not propagate down surfaces.
weiliangc0dece732015-07-27 19:06:173689 LayerImpl* root = root_layer();
3690 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3691 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
3692 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
3693 child1->SetDrawsContent(true);
3694 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
3695 child2->SetDrawsContent(true);
3696 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
3697 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283698
[email protected]fb661802013-03-25 01:59:323699 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173700 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3701 gfx::PointF(), gfx::Size(100, 100), true, false,
3702 true);
3703 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3704 gfx::PointF(), gfx::Size(3, 4), true, false,
3705 true);
3706 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3707 gfx::PointF(), gfx::Size(7, 13), true, false,
3708 true);
3709 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3710 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3711 false, false);
3712 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3713 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3714 false, false);
3715 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3716 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3717 true, false, false);
[email protected]fb661802013-03-25 01:59:323718
3719 root->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:173720
3721 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323722
3723 ASSERT_TRUE(render_surface1->render_surface());
3724 ASSERT_TRUE(render_surface2->render_surface());
3725
danakj5e6ff6d2015-09-05 04:43:443726 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323727 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323728
3729 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433730 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3731 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3732 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323733
3734 // A clipped surface grows its DrawableContentRect to include all drawable
3735 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443736 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
hush6b614212014-12-04 22:37:323737 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323738
3739 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3740 // is only implicitly clipped by render_surface1's content rect. So,
3741 // render_surface2 grows to enclose all drawable content of its subtree.
danakj5e6ff6d2015-09-05 04:43:443742 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
hush6b614212014-12-04 22:37:323743 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323744
3745 // All layers that draw content into render_surface2 think they are unclipped.
danakj64767d902015-06-19 00:10:433746 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3747 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3748 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323749
3750 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323751 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3752 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3753 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323754}
3755
[email protected]989386c2013-07-18 21:37:233756TEST_F(LayerTreeHostCommonTest,
jaydasika27d0f2e2015-10-16 23:52:463757 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) {
3758 LayerImpl* root = root_layer();
3759 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3760 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
3761 LayerImpl* child2 = AddChild<LayerImpl>(child1);
3762 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2);
3763 child1->SetDrawsContent(true);
3764 child2->SetDrawsContent(true);
3765 render_surface2->SetDrawsContent(true);
3766
3767 gfx::Transform identity_matrix;
3768 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3769 gfx::PointF(), gfx::Size(100, 100), true, false,
3770 true);
3771 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3772 gfx::PointF(), gfx::Size(100, 100), true, false,
3773 true);
3774 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3775 gfx::PointF(), gfx::Size(500, 500), true, false,
3776 false);
3777 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3778 gfx::PointF(), gfx::Size(700, 700), true, false,
3779 false);
3780 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3781 gfx::PointF(), gfx::Size(1000, 1000), true,
3782 false, true);
3783
3784 child1->SetMasksToBounds(true);
3785 child2->SetMasksToBounds(true);
3786
3787 ExecuteCalculateDrawProperties(root);
3788 EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect());
3789 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect());
3790}
3791
jaydasika27d0f2e2015-10-16 23:52:463792TEST_F(LayerTreeHostCommonTest,
3793 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) {
3794 LayerImpl* root = root_layer();
3795 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3796 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3797 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3798 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3799
3800 render_surface1->SetDrawsContent(true);
3801 render_surface2->SetDrawsContent(true);
3802 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563803 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:483804 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika27d0f2e2015-10-16 23:52:463805 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:563806 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika27d0f2e2015-10-16 23:52:463807
3808 gfx::Transform identity_matrix;
3809 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3810 gfx::PointF(), gfx::Size(100, 100), true, false,
3811 true);
3812 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3813 gfx::PointF(), gfx::Size(50, 50), true, false,
3814 false);
3815 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3816 gfx::PointF(), gfx::Size(20, 20), true, false,
3817 true);
3818 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3819 gfx::PointF(), gfx::Size(60, 60), true, false,
3820 false);
3821 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3822 gfx::PointF(), gfx::Size(60, 60), true, false,
3823 true);
3824 clip_parent->SetMasksToBounds(true);
3825 render_surface1->SetMasksToBounds(true);
3826
3827 ExecuteCalculateDrawProperties(root);
3828 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect());
3829 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect());
3830 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect());
3831}
3832
jaydasika1f5312d2015-10-21 21:34:323833TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) {
3834 LayerImpl* root = root_layer();
3835 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3836 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3837 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3838 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3839
3840 render_surface1->SetDrawsContent(true);
3841 render_surface2->SetDrawsContent(true);
3842 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563843 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:483844 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika1f5312d2015-10-21 21:34:323845 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:563846 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika1f5312d2015-10-21 21:34:323847
3848 gfx::Transform identity_matrix;
3849 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3850 gfx::PointF(), gfx::Size(100, 100), true, false,
3851 true);
3852 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3853 gfx::PointF(2.f, 2.f), gfx::Size(50, 50), true,
3854 false, false);
3855 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3856 gfx::PointF(), gfx::Size(20, 20), true, false,
3857 true);
3858 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3859 gfx::PointF(), gfx::Size(60, 60), true, false,
3860 false);
3861 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3862 gfx::PointF(), gfx::Size(60, 60), true, false,
3863 true);
3864 clip_parent->SetMasksToBounds(true);
3865 render_surface1->SetMasksToBounds(true);
3866
3867 ExecuteCalculateDrawProperties(root);
3868 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect());
3869}
3870
jaydasika77a4a072015-10-20 21:47:273871TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) {
3872 // Test that only drawn layers contribute to render surface content rect.
3873 LayerImpl* root = root_layer();
3874 LayerImpl* surface = AddChildToRoot<LayerImpl>();
3875 LayerImpl* test_layer = AddChild<LayerImpl>(surface);
3876
3877 test_layer->SetDrawsContent(false);
3878 surface->SetDrawsContent(true);
3879 gfx::Transform identity_matrix;
3880 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3881 gfx::PointF(), gfx::Size(200, 200), true, false,
3882 true);
3883 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
3884 gfx::PointF(), gfx::Size(100, 100), true, false,
3885 true);
3886 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
3887 gfx::PointF(), gfx::Size(150, 150), true, false,
3888 false);
3889
3890 ExecuteCalculateDrawProperties(root);
3891 EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect());
3892
3893 test_layer->SetDrawsContent(true);
3894 ExecuteCalculateDrawProperties(root);
3895 EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect());
3896}
3897
jaydasika27d0f2e2015-10-16 23:52:463898TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) {
3899 // Tests visible rects computation when we have unclipped_surface->
3900 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3901 // of surface_with_unclipped_descendants doesn't propagate to the
3902 // clipped_surface below it.
3903 LayerImpl* root = root_layer();
3904 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3905 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3906 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3907 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3908 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3909
3910 unclipped_surface->SetDrawsContent(true);
3911 unclipped_desc_surface->SetDrawsContent(true);
3912 clipped_surface->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563913 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:483914 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika27d0f2e2015-10-16 23:52:463915 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:563916 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika27d0f2e2015-10-16 23:52:463917
3918 gfx::Transform identity_matrix;
3919 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3920 gfx::PointF(), gfx::Size(100, 100), true, false,
3921 true);
3922 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
3923 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
3924 true, false, true);
3925 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3926 gfx::PointF(), gfx::Size(50, 50), true, false,
3927 false);
3928 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
3929 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
3930 true, false, true);
3931 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3932 gfx::PointF(), gfx::Size(60, 60), true, false,
3933 false);
3934 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
3935 gfx::PointF(), gfx::Size(60, 60), true, false,
3936 true);
3937 clip_parent->SetMasksToBounds(true);
3938
3939 ExecuteCalculateDrawProperties(root);
3940 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect());
3941 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect());
3942 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect());
3943}
3944
3945TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) {
3946 // Tests visible rects computation when we have unclipped_surface->
3947 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3948 // of root propagate to the clipped_surface.
3949 LayerImpl* root = root_layer();
3950 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3951 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3952 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3953 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3954 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3955
3956 unclipped_surface->SetDrawsContent(true);
3957 unclipped_desc_surface->SetDrawsContent(true);
3958 clipped_surface->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:563959 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:483960 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika27d0f2e2015-10-16 23:52:463961 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:563962 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika27d0f2e2015-10-16 23:52:463963
3964 gfx::Transform identity_matrix;
3965 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3966 gfx::PointF(), gfx::Size(10, 10), true, false,
3967 true);
3968 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
3969 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
3970 true, false, true);
3971 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3972 gfx::PointF(), gfx::Size(50, 50), true, false,
3973 false);
3974 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
3975 gfx::Point3F(), gfx::PointF(),
3976 gfx::Size(100, 100), true, false, true);
3977 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3978 gfx::PointF(), gfx::Size(100, 100), true, false,
3979 false);
3980 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
3981 gfx::PointF(), gfx::Size(50, 50), true, false,
3982 true);
3983 clip_parent->SetMasksToBounds(true);
3984 unclipped_desc_surface->SetMasksToBounds(true);
3985
3986 ExecuteCalculateDrawProperties(root);
3987 EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect());
weiliangc0e13ba602016-03-12 04:53:563988 EXPECT_EQ(gfx::Rect(50, 50), unclipped_desc_surface->visible_layer_rect());
jaydasika27d0f2e2015-10-16 23:52:463989 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect());
3990}
3991
3992TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233993 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323994 // Layers that have non-axis aligned bounds (due to transforms) have an
3995 // expanded, axis-aligned DrawableContentRect and visible content rect.
weiliangc0dece732015-07-27 19:06:173996 LayerImpl* root = root_layer();
3997 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3998 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3999 child1->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284000
[email protected]fb661802013-03-25 01:59:324001 gfx::Transform identity_matrix;
4002 gfx::Transform child_rotation;
4003 child_rotation.Rotate(45.0);
weiliangc0dece732015-07-27 19:06:174004 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4005 gfx::PointF(), gfx::Size(100, 100), true, false,
4006 true);
4007 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
4008 gfx::PointF(), gfx::Size(3, 4), true, false,
4009 true);
4010 SetLayerPropertiesForTesting(
4011 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
4012 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
[email protected]fb661802013-03-25 01:59:324013
weiliangc0dece732015-07-27 19:06:174014 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:324015
weiliangc0dece732015-07-27 19:06:174016 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324017
danakj5e6ff6d2015-09-05 04:43:444018 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:324019 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324020
4021 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:434022 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:174023 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324024
4025 // The unclipped surface grows its DrawableContentRect to include all drawable
4026 // regions of the subtree.
4027 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
4028 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:264029 gfx::Rect(50 - diagonal_radius,
4030 50 - diagonal_radius,
4031 diagonal_radius * 2,
4032 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444033 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content),
weiliangc0dece732015-07-27 19:06:174034 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324035
4036 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:434037 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
hush6b614212014-12-04 22:37:324038 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324039}
4040
[email protected]989386c2013-07-18 21:37:234041TEST_F(LayerTreeHostCommonTest,
4042 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:324043 // Layers that have non-axis aligned bounds (due to transforms) have an
4044 // expanded, axis-aligned DrawableContentRect and visible content rect.
weiliangc0dece732015-07-27 19:06:174045 LayerImpl* root = root_layer();
4046 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
4047 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
4048 child1->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284049
[email protected]fb661802013-03-25 01:59:324050 gfx::Transform identity_matrix;
4051 gfx::Transform child_rotation;
4052 child_rotation.Rotate(45.0);
weiliangc0dece732015-07-27 19:06:174053 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4054 gfx::PointF(), gfx::Size(50, 50), true, false,
4055 true);
4056 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
4057 gfx::PointF(), gfx::Size(3, 4), true, false,
4058 true);
[email protected]a2566412014-06-05 03:14:204059
weiliangc0dece732015-07-27 19:06:174060 SetLayerPropertiesForTesting(
4061 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
4062 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
[email protected]fb661802013-03-25 01:59:324063
4064 root->SetMasksToBounds(true);
[email protected]fb661802013-03-25 01:59:324065
weiliangc0dece732015-07-27 19:06:174066 ExecuteCalculateDrawProperties(root);
4067
4068 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:324069
4070 // The clipped surface clamps the DrawableContentRect that encloses the
4071 // rotated layer.
4072 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:264073 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
4074 50 - diagonal_radius,
4075 diagonal_radius * 2,
4076 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:444077 gfx::RectF expected_surface_drawable_content(
4078 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
hush6b614212014-12-04 22:37:324079 EXPECT_EQ(expected_surface_drawable_content,
weiliangc0dece732015-07-27 19:06:174080 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324081
4082 // On the clipped surface, only a quarter of the child1 is visible, but when
4083 // rotating it back to child1's content space, the actual enclosing rect ends
4084 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:264085 //
4086 // Given the floating point math, this number is a little bit fuzzy.
danakj64767d902015-06-19 00:10:434087 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324088
4089 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:324090 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324091}
4092
[email protected]989386c2013-07-18 21:37:234093TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
weiliangc0dece732015-07-27 19:06:174094 LayerImpl* root = root_layer();
4095 FakePictureLayerImpl* render_surface1 =
4096 AddChildToRoot<FakePictureLayerImpl>();
4097 render_surface1->SetDrawsContent(true);
4098 FakePictureLayerImpl* render_surface2 =
4099 AddChild<FakePictureLayerImpl>(render_surface1);
4100 render_surface2->SetDrawsContent(true);
4101 FakePictureLayerImpl* child1 =
4102 AddChild<FakePictureLayerImpl>(render_surface2);
4103 child1->SetDrawsContent(true);
4104 FakePictureLayerImpl* child2 =
4105 AddChild<FakePictureLayerImpl>(render_surface2);
4106 child2->SetDrawsContent(true);
4107 FakePictureLayerImpl* child3 =
4108 AddChild<FakePictureLayerImpl>(render_surface2);
4109 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284110
[email protected]fb661802013-03-25 01:59:324111 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:174112 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4113 gfx::PointF(), gfx::Size(100, 100), true, false,
4114 true);
4115 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
4116 gfx::PointF(5.f, 5.f), gfx::Size(3, 4), true,
4117 false, true);
4118 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
4119 gfx::PointF(5.f, 5.f), gfx::Size(7, 13), true,
4120 false, true);
4121 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
4122 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
4123 false, false);
4124 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4125 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
4126 false, false);
4127 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
4128 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
4129 true, false, false);
[email protected]fb661802013-03-25 01:59:324130
4131 float device_scale_factor = 2.f;
4132
4133 root->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:174134
4135 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324136
4137 ASSERT_TRUE(render_surface1->render_surface());
4138 ASSERT_TRUE(render_surface2->render_surface());
4139
4140 // drawable_content_rects for all layers and surfaces are scaled by
4141 // device_scale_factor.
danakj5e6ff6d2015-09-05 04:43:444142 EXPECT_EQ(gfx::RectF(200.f, 200.f),
hush6b614212014-12-04 22:37:324143 root->render_surface()->DrawableContentRect());
danakj5e6ff6d2015-09-05 04:43:444144 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
hush6b614212014-12-04 22:37:324145 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324146
4147 // render_surface2 lives in the "unclipped universe" of render_surface1, and
4148 // is only implicitly clipped by render_surface1.
danakj5e6ff6d2015-09-05 04:43:444149 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f),
hush6b614212014-12-04 22:37:324150 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:324151
hush6b614212014-12-04 22:37:324152 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
4153 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
4154 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:324155
4156 // The root layer does not actually draw content of its own.
danakj64767d902015-06-19 00:10:434157 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324158
sohan.jyotie3bd6192014-10-13 07:13:594159 // All layer visible content rects are not expressed in content space of each
4160 // layer, so they are not scaled by the device_scale_factor.
danakj64767d902015-06-19 00:10:434161 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
4162 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
4163 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
4164 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
4165 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324166}
4167
[email protected]989386c2013-07-18 21:37:234168TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:324169 // Verify the behavior of back-face culling when there are no preserve-3d
4170 // layers. Note that 3d transforms still apply in this case, but they are
4171 // "flattened" to each parent layer according to current W3C spec.
4172
4173 const gfx::Transform identity_matrix;
ajuma4711f4b12016-05-16 18:48:324174 LayerImpl* parent = root_layer();
4175 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4176 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4177 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4178 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4179 LayerImpl* front_facing_child_of_front_facing_surface =
4180 AddChild<LayerImpl>(front_facing_surface);
4181 LayerImpl* back_facing_child_of_front_facing_surface =
4182 AddChild<LayerImpl>(front_facing_surface);
4183 LayerImpl* front_facing_child_of_back_facing_surface =
4184 AddChild<LayerImpl>(back_facing_surface);
4185 LayerImpl* back_facing_child_of_back_facing_surface =
4186 AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284187
[email protected]fb661802013-03-25 01:59:324188 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324189 front_facing_child->test_properties()->double_sided = false;
4190 back_facing_child->test_properties()->double_sided = false;
4191 front_facing_surface->test_properties()->double_sided = false;
4192 back_facing_surface->test_properties()->double_sided = false;
4193 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4194 false;
4195 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4196 false;
4197 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4198 false;
4199 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4200 false;
4201
4202 // Everything draws content.
4203 front_facing_child->SetDrawsContent(true);
4204 back_facing_child->SetDrawsContent(true);
4205 front_facing_surface->SetDrawsContent(true);
4206 back_facing_surface->SetDrawsContent(true);
4207 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4208 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4209 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4210 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324211
4212 gfx::Transform backface_matrix;
4213 backface_matrix.Translate(50.0, 50.0);
4214 backface_matrix.RotateAboutYAxis(180.0);
4215 backface_matrix.Translate(-50.0, -50.0);
4216
4217 // Having a descendant and opacity will force these to have render surfaces.
4218 front_facing_surface->SetOpacity(0.5f);
4219 back_facing_surface->SetOpacity(0.5f);
4220
4221 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
4222 // these layers should blindly use their own local transforms to determine
4223 // back-face culling.
ajuma4711f4b12016-05-16 18:48:324224 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4225 gfx::PointF(), gfx::Size(100, 100), true, false);
4226 SetLayerPropertiesForTesting(front_facing_child, identity_matrix,
4227 gfx::Point3F(), gfx::PointF(),
4228 gfx::Size(100, 100), true, false);
4229 SetLayerPropertiesForTesting(back_facing_child, backface_matrix,
4230 gfx::Point3F(), gfx::PointF(),
4231 gfx::Size(100, 100), true, false);
4232 SetLayerPropertiesForTesting(front_facing_surface, identity_matrix,
4233 gfx::Point3F(), gfx::PointF(),
4234 gfx::Size(100, 100), true, false);
4235 SetLayerPropertiesForTesting(back_facing_surface, backface_matrix,
4236 gfx::Point3F(), gfx::PointF(),
4237 gfx::Size(100, 100), true, false);
4238 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface,
4239 identity_matrix, gfx::Point3F(), gfx::PointF(),
4240 gfx::Size(100, 100), true, false);
4241 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface,
4242 backface_matrix, gfx::Point3F(), gfx::PointF(),
4243 gfx::Size(100, 100), true, false);
4244 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface,
4245 identity_matrix, gfx::Point3F(), gfx::PointF(),
4246 gfx::Size(100, 100), true, false);
4247 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface,
4248 backface_matrix, gfx::Point3F(), gfx::PointF(),
4249 gfx::Size(100, 100), true, false);
[email protected]fb661802013-03-25 01:59:324250
ajuma4711f4b12016-05-16 18:48:324251 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:324252
4253 // Verify which render surfaces were created.
ennec1332992015-08-24 19:45:094254 EXPECT_FALSE(front_facing_child->has_render_surface());
4255 EXPECT_FALSE(back_facing_child->has_render_surface());
4256 EXPECT_TRUE(front_facing_surface->has_render_surface());
4257 EXPECT_TRUE(back_facing_surface->has_render_surface());
4258 EXPECT_FALSE(
4259 front_facing_child_of_front_facing_surface->has_render_surface());
4260 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4261 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4262 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324263
ajuma4711f4b12016-05-16 18:48:324264 EXPECT_EQ(4u, update_layer_list_impl()->size());
4265 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4266 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4267 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534268 front_facing_child_of_front_facing_surface->id()));
ajuma4711f4b12016-05-16 18:48:324269 EXPECT_TRUE(UpdateLayerListImplContains(
4270 front_facing_child_of_back_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324271}
4272
[email protected]989386c2013-07-18 21:37:234273TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:324274 // Verify the behavior of back-face culling when preserves-3d transform style
4275 // is used.
4276
4277 const gfx::Transform identity_matrix;
weiliangcc154ce22015-12-09 03:39:264278 LayerImpl* parent = root_layer();
4279 LayerImpl* front_facing_child = AddChildToRoot<LayerImpl>();
4280 LayerImpl* back_facing_child = AddChildToRoot<LayerImpl>();
4281 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4282 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4283 LayerImpl* front_facing_child_of_front_facing_surface =
4284 AddChild<LayerImpl>(front_facing_surface);
4285 LayerImpl* back_facing_child_of_front_facing_surface =
4286 AddChild<LayerImpl>(front_facing_surface);
4287 LayerImpl* front_facing_child_of_back_facing_surface =
4288 AddChild<LayerImpl>(back_facing_surface);
4289 LayerImpl* back_facing_child_of_back_facing_surface =
4290 AddChild<LayerImpl>(back_facing_surface);
4291 // Opacity will not force creation of render surfaces in this case because of
4292 // the preserve-3d transform style. Instead, an example of when a surface
4293 // would be created with preserve-3d is when there is a replica layer.
4294 LayerImpl* dummy_replica_layer1 =
4295 AddReplicaLayer<LayerImpl>(front_facing_surface);
4296 LayerImpl* dummy_replica_layer2 =
4297 AddReplicaLayer<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284298
[email protected]fb661802013-03-25 01:59:324299 // Nothing is double-sided
jaydasika6b5a32bf2016-04-22 21:56:364300 front_facing_child->test_properties()->double_sided = false;
4301 back_facing_child->test_properties()->double_sided = false;
4302 front_facing_surface->test_properties()->double_sided = false;
4303 back_facing_surface->test_properties()->double_sided = false;
4304 front_facing_child_of_front_facing_surface->test_properties()->double_sided =
4305 false;
4306 back_facing_child_of_front_facing_surface->test_properties()->double_sided =
4307 false;
4308 front_facing_child_of_back_facing_surface->test_properties()->double_sided =
4309 false;
4310 back_facing_child_of_back_facing_surface->test_properties()->double_sided =
4311 false;
[email protected]fb661802013-03-25 01:59:324312
weiliangcc154ce22015-12-09 03:39:264313 // Everything draws content.
4314 front_facing_child->SetDrawsContent(true);
4315 back_facing_child->SetDrawsContent(true);
4316 front_facing_surface->SetDrawsContent(true);
4317 back_facing_surface->SetDrawsContent(true);
4318 front_facing_child_of_front_facing_surface->SetDrawsContent(true);
4319 back_facing_child_of_front_facing_surface->SetDrawsContent(true);
4320 front_facing_child_of_back_facing_surface->SetDrawsContent(true);
4321 back_facing_child_of_back_facing_surface->SetDrawsContent(true);
4322 dummy_replica_layer1->SetDrawsContent(true);
4323 dummy_replica_layer2->SetDrawsContent(true);
4324
[email protected]fb661802013-03-25 01:59:324325 gfx::Transform backface_matrix;
4326 backface_matrix.Translate(50.0, 50.0);
4327 backface_matrix.RotateAboutYAxis(180.0);
4328 backface_matrix.Translate(-50.0, -50.0);
4329
[email protected]fb661802013-03-25 01:59:324330 // Each surface creates its own new 3d rendering context (as defined by W3C
4331 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
4332 // rendering context should use the transform with respect to that context.
4333 // This 3d rendering context occurs when (a) parent's transform style is flat
4334 // and (b) the layer's transform style is preserve-3d.
weiliangcc154ce22015-12-09 03:39:264335 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
weiliangc4374c2cc2015-12-07 19:26:014336 gfx::PointF(), gfx::Size(100, 100), true,
[email protected]fb661802013-03-25 01:59:324337 false); // parent transform style is flat.
weiliangcc154ce22015-12-09 03:39:264338 SetLayerPropertiesForTesting(front_facing_child, identity_matrix,
weiliangc4374c2cc2015-12-07 19:26:014339 gfx::Point3F(), gfx::PointF(),
4340 gfx::Size(100, 100), true, false);
weiliangcc154ce22015-12-09 03:39:264341 SetLayerPropertiesForTesting(back_facing_child, backface_matrix,
weiliangc4374c2cc2015-12-07 19:26:014342 gfx::Point3F(), gfx::PointF(),
4343 gfx::Size(100, 100), true, false);
[email protected]56fffdd2014-02-11 19:50:574344 // surface transform style is preserve-3d.
weiliangcc154ce22015-12-09 03:39:264345 SetLayerPropertiesForTesting(front_facing_surface, identity_matrix,
weiliangc4374c2cc2015-12-07 19:26:014346 gfx::Point3F(), gfx::PointF(),
4347 gfx::Size(100, 100), false, true);
[email protected]56fffdd2014-02-11 19:50:574348 // surface transform style is preserve-3d.
weiliangcc154ce22015-12-09 03:39:264349 SetLayerPropertiesForTesting(back_facing_surface, backface_matrix,
weiliangc4374c2cc2015-12-07 19:26:014350 gfx::Point3F(), gfx::PointF(),
4351 gfx::Size(100, 100), false, true);
weiliangcc154ce22015-12-09 03:39:264352 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014353 identity_matrix, gfx::Point3F(), gfx::PointF(),
4354 gfx::Size(100, 100), true, true);
weiliangcc154ce22015-12-09 03:39:264355 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014356 backface_matrix, gfx::Point3F(), gfx::PointF(),
4357 gfx::Size(100, 100), true, true);
weiliangcc154ce22015-12-09 03:39:264358 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014359 identity_matrix, gfx::Point3F(), gfx::PointF(),
4360 gfx::Size(100, 100), true, true);
weiliangcc154ce22015-12-09 03:39:264361 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface,
weiliangc4374c2cc2015-12-07 19:26:014362 backface_matrix, gfx::Point3F(), gfx::PointF(),
4363 gfx::Size(100, 100), true, true);
[email protected]fb661802013-03-25 01:59:324364
weiliangcc154ce22015-12-09 03:39:264365 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:324366
awoloszyne83f28c2014-12-22 15:40:004367 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094368 EXPECT_FALSE(front_facing_child->has_render_surface());
4369 EXPECT_FALSE(back_facing_child->has_render_surface());
4370 EXPECT_TRUE(front_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094371 // We expect that a has_render_surface was created but not used.
4372 EXPECT_TRUE(back_facing_surface->has_render_surface());
4373 EXPECT_FALSE(
4374 front_facing_child_of_front_facing_surface->has_render_surface());
4375 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4376 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4377 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324378
weiliangcc154ce22015-12-09 03:39:264379 EXPECT_EQ(3u, update_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:324380
weiliangcc154ce22015-12-09 03:39:264381 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id()));
4382 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4383 EXPECT_TRUE(UpdateLayerListImplContains(
enne7b2a2172015-07-14 00:04:534384 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324385}
4386
[email protected]989386c2013-07-18 21:37:234387TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:324388 // Verify that layers are appropriately culled when their back face is showing
4389 // and they are not double sided, while animations are going on.
4390 //
ajuma4711f4b12016-05-16 18:48:324391 // Even layers that are animating get culled if their back face is showing and
4392 // they are not double sided.
[email protected]fb661802013-03-25 01:59:324393 const gfx::Transform identity_matrix;
ajuma4711f4b12016-05-16 18:48:324394 LayerImpl* parent = root_layer();
4395 LayerImpl* child = AddChildToRoot<LayerImpl>();
4396 LayerImpl* animating_surface = AddChildToRoot<LayerImpl>();
4397 LayerImpl* child_of_animating_surface =
4398 AddChild<LayerImpl>(animating_surface);
4399 LayerImpl* animating_child = AddChildToRoot<LayerImpl>();
4400 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
[email protected]d600df7d2013-08-03 02:34:284401
[email protected]fb661802013-03-25 01:59:324402 // Nothing is double-sided
ajuma4711f4b12016-05-16 18:48:324403 child->test_properties()->double_sided = false;
4404 child2->test_properties()->double_sided = false;
4405 animating_surface->test_properties()->double_sided = false;
4406 child_of_animating_surface->test_properties()->double_sided = false;
4407 animating_child->test_properties()->double_sided = false;
4408
4409 // Everything draws content.
4410 child->SetDrawsContent(true);
4411 child2->SetDrawsContent(true);
4412 animating_surface->SetDrawsContent(true);
4413 child_of_animating_surface->SetDrawsContent(true);
4414 animating_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324415
4416 gfx::Transform backface_matrix;
4417 backface_matrix.Translate(50.0, 50.0);
4418 backface_matrix.RotateAboutYAxis(180.0);
4419 backface_matrix.Translate(-50.0, -50.0);
4420
loyso9556c732016-03-11 07:54:584421 // Animate the transform on the render surface.
ajuma4711f4b12016-05-16 18:48:324422 AddAnimatedTransformToLayerWithPlayer(animating_surface->id(),
4423 timeline_impl(), 10.0, 30, 0);
loyso9556c732016-03-11 07:54:584424 // This is just an animating layer, not a surface.
ajuma4711f4b12016-05-16 18:48:324425 AddAnimatedTransformToLayerWithPlayer(animating_child->id(), timeline_impl(),
4426 10.0, 30, 0);
[email protected]fb661802013-03-25 01:59:324427
ajuma4711f4b12016-05-16 18:48:324428 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4429 gfx::PointF(), gfx::Size(100, 100), true, false);
4430 SetLayerPropertiesForTesting(child, backface_matrix, gfx::Point3F(),
4431 gfx::PointF(), gfx::Size(100, 100), true, false);
4432 SetLayerPropertiesForTesting(animating_surface, backface_matrix,
4433 gfx::Point3F(), gfx::PointF(),
4434 gfx::Size(100, 100), true, false, true);
4435 SetLayerPropertiesForTesting(child_of_animating_surface, backface_matrix,
4436 gfx::Point3F(), gfx::PointF(),
4437 gfx::Size(100, 100), true, false);
4438 SetLayerPropertiesForTesting(animating_child, backface_matrix, gfx::Point3F(),
4439 gfx::PointF(), gfx::Size(100, 100), true, false);
4440 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4441 gfx::PointF(), gfx::Size(100, 100), true, false);
[email protected]fb661802013-03-25 01:59:324442
ajuma4711f4b12016-05-16 18:48:324443 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:324444
ennec1332992015-08-24 19:45:094445 EXPECT_FALSE(child->has_render_surface());
4446 EXPECT_TRUE(animating_surface->has_render_surface());
4447 EXPECT_FALSE(child_of_animating_surface->has_render_surface());
4448 EXPECT_FALSE(animating_child->has_render_surface());
4449 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324450
ajuma4711f4b12016-05-16 18:48:324451 EXPECT_EQ(1u, update_layer_list_impl()->size());
enne7b2a2172015-07-14 00:04:534452
ajuma4711f4b12016-05-16 18:48:324453 // The back facing layers are culled from the layer list, and have an empty
4454 // visible rect.
4455 EXPECT_TRUE(UpdateLayerListImplContains(child2->id()));
4456 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
4457 EXPECT_TRUE(animating_surface->visible_layer_rect().IsEmpty());
4458 EXPECT_TRUE(child_of_animating_surface->visible_layer_rect().IsEmpty());
4459 EXPECT_TRUE(animating_child->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:324460
ajuma4711f4b12016-05-16 18:48:324461 EXPECT_EQ(gfx::Rect(100, 100), child2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:324462}
4463
[email protected]989386c2013-07-18 21:37:234464TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324465 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4466 // Verify the behavior of back-face culling for a render surface that is
4467 // created when it flattens its subtree, and its parent has preserves-3d.
4468
4469 const gfx::Transform identity_matrix;
ajuma4711f4b12016-05-16 18:48:324470 LayerImpl* parent = root_layer();
4471 LayerImpl* front_facing_surface = AddChildToRoot<LayerImpl>();
4472 LayerImpl* back_facing_surface = AddChildToRoot<LayerImpl>();
4473 LayerImpl* child1 = AddChild<LayerImpl>(front_facing_surface);
4474 LayerImpl* child2 = AddChild<LayerImpl>(back_facing_surface);
[email protected]d600df7d2013-08-03 02:34:284475
[email protected]fb661802013-03-25 01:59:324476 // RenderSurfaces are not double-sided
ajuma4711f4b12016-05-16 18:48:324477 front_facing_surface->test_properties()->double_sided = false;
4478 back_facing_surface->test_properties()->double_sided = false;
4479
4480 // Everything draws content.
4481 front_facing_surface->SetDrawsContent(true);
4482 back_facing_surface->SetDrawsContent(true);
4483 child1->SetDrawsContent(true);
4484 child2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:324485
4486 gfx::Transform backface_matrix;
4487 backface_matrix.Translate(50.0, 50.0);
4488 backface_matrix.RotateAboutYAxis(180.0);
4489 backface_matrix.Translate(-50.0, -50.0);
4490
ajuma4711f4b12016-05-16 18:48:324491 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4492 gfx::PointF(), gfx::Size(100, 100), false,
[email protected]56fffdd2014-02-11 19:50:574493 true); // parent transform style is preserve3d.
ajuma4711f4b12016-05-16 18:48:324494 SetLayerPropertiesForTesting(front_facing_surface, identity_matrix,
4495 gfx::Point3F(), gfx::PointF(),
4496 gfx::Size(100, 100), true,
[email protected]56fffdd2014-02-11 19:50:574497 true); // surface transform style is flat.
ajuma4711f4b12016-05-16 18:48:324498 SetLayerPropertiesForTesting(back_facing_surface, backface_matrix,
4499 gfx::Point3F(), gfx::PointF(),
4500 gfx::Size(100, 100), true,
[email protected]56fffdd2014-02-11 19:50:574501 true); // surface transform style is flat.
ajuma4711f4b12016-05-16 18:48:324502 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
4503 gfx::PointF(), gfx::Size(100, 100), true, false);
4504 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4505 gfx::PointF(), gfx::Size(100, 100), true, false);
[email protected]fb661802013-03-25 01:59:324506
[email protected]a9d4d4f2014-06-19 06:49:284507 front_facing_surface->Set3dSortingContextId(1);
4508 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574509
ajuma4711f4b12016-05-16 18:48:324510 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent);
[email protected]fb661802013-03-25 01:59:324511
awoloszyne83f28c2014-12-22 15:40:004512 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094513 EXPECT_TRUE(front_facing_surface->has_render_surface());
awoloszyne83f28c2014-12-22 15:40:004514
4515 // We expect the render surface to have been created, but remain unused.
ennec1332992015-08-24 19:45:094516 EXPECT_TRUE(back_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094517 EXPECT_FALSE(child1->has_render_surface());
4518 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324519
ajuma4711f4b12016-05-16 18:48:324520 EXPECT_EQ(2u, update_layer_list_impl()->size());
4521 EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id()));
4522 EXPECT_TRUE(UpdateLayerListImplContains(child1->id()));
[email protected]fb661802013-03-25 01:59:324523}
4524
enne637715732015-07-07 02:05:264525TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324526 // Verify draw and screen space transforms of layers not in a surface.
[email protected]fb661802013-03-25 01:59:324527 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:144528
enne637715732015-07-07 02:05:264529 LayerImpl* parent = root_layer();
jaydasika8640f9f2015-11-10 01:34:364530 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264531 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4532 gfx::PointF(), gfx::Size(100, 100), false, true,
[email protected]fb661802013-03-25 01:59:324533 true);
[email protected]94f206c12012-08-25 00:09:144534
enne637715732015-07-07 02:05:264535 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364536 child->SetDrawsContent(true);
enne637715732015-07-07 02:05:264537 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4538 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4539 true, false);
[email protected]94f206c12012-08-25 00:09:144540
jaydasika8640f9f2015-11-10 01:34:364541 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
4542 child2->SetDrawsContent(true);
4543 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4544 gfx::PointF(2.f, 2.f), gfx::Size(5, 5), false,
4545 true, false);
[email protected]d600df7d2013-08-03 02:34:284546
[email protected]fb661802013-03-25 01:59:324547 float device_scale_factor = 2.5f;
enne637715732015-07-07 02:05:264548 gfx::Size viewport_size(100, 100);
4549 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144550
enne637715732015-07-07 02:05:264551 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent);
4552 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child);
jaydasika8640f9f2015-11-10 01:34:364553 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child2);
[email protected]518ee582012-10-24 18:29:444554
enne637715732015-07-07 02:05:264555 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144556
[email protected]fb661802013-03-25 01:59:324557 // Verify parent transforms
4558 gfx::Transform expected_parent_transform;
enne637715732015-07-07 02:05:264559 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324560 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104561 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324562 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444563 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144564
[email protected]fb661802013-03-25 01:59:324565 // Verify results of transformed parent rects
danakjddaec912015-09-25 19:38:404566 gfx::RectF parent_bounds(gfx::SizeF(parent->bounds()));
[email protected]94f206c12012-08-25 00:09:144567
[email protected]fb661802013-03-25 01:59:324568 gfx::RectF parent_draw_rect =
ajumad9432e32015-11-30 19:43:444569 MathUtil::MapClippedRect(parent->DrawTransform(), parent_bounds);
Dana Jansensc46d3742015-06-18 01:33:144570 gfx::RectF parent_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104571 MathUtil::MapClippedRect(parent->ScreenSpaceTransform(), parent_bounds);
[email protected]94f206c12012-08-25 00:09:144572
danakjddaec912015-09-25 19:38:404573 gfx::RectF expected_parent_draw_rect(gfx::SizeF(parent->bounds()));
[email protected]fb661802013-03-25 01:59:324574 expected_parent_draw_rect.Scale(device_scale_factor);
4575 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4576 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144577
jaydasika8640f9f2015-11-10 01:34:364578 // Verify child and child2 transforms. They should match.
[email protected]fb661802013-03-25 01:59:324579 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594580 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4581 expected_child_transform.Translate(child->position().x(),
4582 child->position().y());
[email protected]fb661802013-03-25 01:59:324583 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444584 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:324585 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104586 child->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324587 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444588 child2->DrawTransform());
[email protected]fb661802013-03-25 01:59:324589 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumab6aa1c62015-12-01 21:01:104590 child2->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144591
jaydasika8640f9f2015-11-10 01:34:364592 // Verify results of transformed child and child2 rects. They should
[email protected]fb661802013-03-25 01:59:324593 // match.
danakjddaec912015-09-25 19:38:404594 gfx::RectF child_bounds(gfx::SizeF(child->bounds()));
[email protected]94f206c12012-08-25 00:09:144595
[email protected]fb661802013-03-25 01:59:324596 gfx::RectF child_draw_rect =
ajumad9432e32015-11-30 19:43:444597 MathUtil::MapClippedRect(child->DrawTransform(), child_bounds);
Dana Jansensc46d3742015-06-18 01:33:144598 gfx::RectF child_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104599 MathUtil::MapClippedRect(child->ScreenSpaceTransform(), child_bounds);
[email protected]94f206c12012-08-25 00:09:144600
jaydasika8640f9f2015-11-10 01:34:364601 gfx::RectF child2_draw_rect =
ajumad9432e32015-11-30 19:43:444602 MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds);
jaydasika8640f9f2015-11-10 01:34:364603 gfx::RectF child2_screen_space_rect =
ajumab6aa1c62015-12-01 21:01:104604 MathUtil::MapClippedRect(child2->ScreenSpaceTransform(), child_bounds);
[email protected]f89f5632012-11-14 23:34:454605
danakjddaec912015-09-25 19:38:404606 gfx::RectF expected_child_draw_rect(child->position(),
4607 gfx::SizeF(child->bounds()));
[email protected]fb661802013-03-25 01:59:324608 expected_child_draw_rect.Scale(device_scale_factor);
4609 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4610 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
jaydasika8640f9f2015-11-10 01:34:364611 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect);
4612 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144613}
4614
enne637715732015-07-07 02:05:264615TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324616 // Verify draw and screen space transforms of layers in a surface.
[email protected]fb661802013-03-25 01:59:324617 gfx::Transform identity_matrix;
[email protected]fb661802013-03-25 01:59:324618 gfx::Transform perspective_matrix;
4619 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094620
[email protected]fb661802013-03-25 01:59:324621 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054622 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094623
enne637715732015-07-07 02:05:264624 LayerImpl* root = root_layer();
4625 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4626 gfx::PointF(), gfx::Size(100, 100), false, true,
4627 false);
4628 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364629 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264630 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4631 gfx::PointF(), gfx::Size(100, 100), false, true,
4632 false);
[email protected]9781afa2013-07-17 23:15:324633
enne637715732015-07-07 02:05:264634 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
4635 SetLayerPropertiesForTesting(perspective_surface,
[email protected]fb661802013-03-25 01:59:324636 perspective_matrix * scale_small_matrix,
enne637715732015-07-07 02:05:264637 gfx::Point3F(), gfx::PointF(2.f, 2.f),
4638 gfx::Size(10, 10), false, true, true);
4639 perspective_surface->SetDrawsContent(true);
[email protected]1b30e8e2012-12-21 02:59:094640
enne637715732015-07-07 02:05:264641 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
4642 SetLayerPropertiesForTesting(scale_surface, scale_small_matrix,
4643 gfx::Point3F(), gfx::PointF(2.f, 2.f),
4644 gfx::Size(10, 10), false, true, true);
4645 scale_surface->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284646
[email protected]fb661802013-03-25 01:59:324647 float device_scale_factor = 2.5f;
4648 float page_scale_factor = 3.f;
enne637715732015-07-07 02:05:264649 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4650 root);
[email protected]1b30e8e2012-12-21 02:59:094651
sohan.jyotie3bd6192014-10-13 07:13:594652 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4653 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
4654 perspective_surface);
4655 // Ideal scale is the max 2d scale component of the combined transform up to
4656 // the nearest render target. Here this includes the layer transform as well
4657 // as the device and page scale factors.
4658 gfx::Transform transform = scale_small_matrix;
4659 transform.Scale(device_scale_factor * page_scale_factor,
4660 device_scale_factor * page_scale_factor);
4661 gfx::Vector2dF scales =
4662 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4663 float max_2d_scale = std::max(scales.x(), scales.y());
4664 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
4665
4666 // The ideal scale will draw 1:1 with its render target space along
4667 // the larger-scale axis.
4668 gfx::Vector2dF target_space_transform_scales =
4669 MathUtil::ComputeTransform2dScaleComponents(
4670 scale_surface->draw_properties().target_space_transform, 0.f);
4671 EXPECT_FLOAT_EQ(max_2d_scale,
4672 std::max(target_space_transform_scales.x(),
4673 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094674
enne637715732015-07-07 02:05:264675 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]1b30e8e2012-12-21 02:59:094676
[email protected]fb661802013-03-25 01:59:324677 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594678 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4679 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324680 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
ajumad9432e32015-11-30 19:43:444681 parent->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094682
[email protected]fb661802013-03-25 01:59:324683 // The scale for the perspective surface is not known, so it is rendered 1:1
4684 // with the screen, and then scaled during drawing.
4685 gfx::Transform expected_perspective_surface_draw_transform;
4686 expected_perspective_surface_draw_transform.Translate(
4687 device_scale_factor * page_scale_factor *
4688 perspective_surface->position().x(),
4689 device_scale_factor * page_scale_factor *
4690 perspective_surface->position().y());
4691 expected_perspective_surface_draw_transform.PreconcatTransform(
4692 perspective_matrix);
4693 expected_perspective_surface_draw_transform.PreconcatTransform(
4694 scale_small_matrix);
4695 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594696 expected_perspective_surface_layer_draw_transform.Scale(
4697 device_scale_factor * page_scale_factor,
4698 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324699 EXPECT_TRANSFORMATION_MATRIX_EQ(
4700 expected_perspective_surface_draw_transform,
4701 perspective_surface->render_surface()->draw_transform());
4702 EXPECT_TRANSFORMATION_MATRIX_EQ(
4703 expected_perspective_surface_layer_draw_transform,
ajumad9432e32015-11-30 19:43:444704 perspective_surface->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094705}
4706
enne637715732015-07-07 02:05:264707TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294708 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264709 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294710 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4711
4712 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264713 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294714 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4715
enne637715732015-07-07 02:05:264716 LayerImpl* root = root_layer();
[email protected]35a99a12013-05-09 23:52:294717 root->SetBounds(gfx::Size(100, 100));
4718
enne637715732015-07-07 02:05:264719 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364720 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264721 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4722 gfx::PointF(), gfx::Size(100, 100), false, true,
4723 false);
[email protected]35a99a12013-05-09 23:52:294724
enne637715732015-07-07 02:05:264725 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:364726 child_scale->SetDrawsContent(true);
enne637715732015-07-07 02:05:264727 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4728 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4729 true, false);
[email protected]d600df7d2013-08-03 02:34:284730
[email protected]fb661802013-03-25 01:59:324731 float device_scale_factor = 2.5f;
4732 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214733
[email protected]989386c2013-07-18 21:37:234734 {
enne637715732015-07-07 02:05:264735 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4736 root);
[email protected]11ec92972012-11-10 03:06:214737
sohan.jyotie3bd6192014-10-13 07:13:594738 // The ideal scale is able to go below 1.
4739 float expected_ideal_scale =
4740 device_scale_factor * page_scale_factor * initial_parent_scale;
4741 EXPECT_LT(expected_ideal_scale, 1.f);
4742 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
[email protected]11ec92972012-11-10 03:06:214743
sohan.jyotie3bd6192014-10-13 07:13:594744 expected_ideal_scale = device_scale_factor * page_scale_factor *
4745 initial_parent_scale * initial_child_scale;
4746 EXPECT_LT(expected_ideal_scale, 1.f);
4747 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
[email protected]989386c2013-07-18 21:37:234748 }
[email protected]11ec92972012-11-10 03:06:214749}
4750
enne637715732015-07-07 02:05:264751TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:324752 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264753 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324754 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:264755
[email protected]fb661802013-03-25 01:59:324756 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264757 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324758 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:264759
enne637715732015-07-07 02:05:264760 LayerImpl* root = root_layer();
[email protected]35a99a12013-05-09 23:52:294761 root->SetBounds(gfx::Size(100, 100));
4762
enne637715732015-07-07 02:05:264763 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364764 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264765 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4766 gfx::PointF(), gfx::Size(100, 100), false, true,
4767 false);
[email protected]6a9cff92012-11-08 11:53:264768
enne637715732015-07-07 02:05:264769 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:364770 child_scale->SetDrawsContent(true);
enne637715732015-07-07 02:05:264771 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4772 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4773 true, false);
[email protected]d600df7d2013-08-03 02:34:284774
[email protected]989386c2013-07-18 21:37:234775 {
enne637715732015-07-07 02:05:264776 ExecuteCalculateDrawProperties(root);
[email protected]6a9cff92012-11-08 11:53:264777
sohan.jyotie3bd6192014-10-13 07:13:594778 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
4779 // Animating layers compute ideal scale in the same way as when
4780 // they are static.
4781 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
4782 child_scale);
[email protected]989386c2013-07-18 21:37:234783 }
[email protected]6a9cff92012-11-08 11:53:264784}
4785
[email protected]989386c2013-07-18 21:37:234786TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324787 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:264788
enneea850232015-07-27 16:43:124789 LayerImpl* parent = root_layer();
4790 parent->SetDrawsContent(true);
4791 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4792 gfx::PointF(), gfx::Size(30, 30), false, true,
[email protected]fb661802013-03-25 01:59:324793 true);
[email protected]94f206c12012-08-25 00:09:144794
enneea850232015-07-27 16:43:124795 LayerImpl* child = AddChildToRoot<LayerImpl>();
4796 child->SetDrawsContent(true);
4797 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4798 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4799 true, true);
[email protected]94f206c12012-08-25 00:09:144800
[email protected]fb661802013-03-25 01:59:324801 gfx::Transform replica_transform;
4802 replica_transform.Scale(1.0, -1.0);
enneea850232015-07-27 16:43:124803
danakj60bc3bc2016-04-09 00:24:484804 std::unique_ptr<LayerImpl> replica =
enneea850232015-07-27 16:43:124805 LayerImpl::Create(host_impl()->active_tree(), 7);
4806 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
4807 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4808 true, false);
jaydasika5017a332016-03-31 01:06:224809 // We need to set parent on replica layer for property tree building.
4810 replica->SetParent(child);
danakja04855a2015-11-18 20:39:104811 child->SetReplicaLayer(std::move(replica));
[email protected]94f206c12012-08-25 00:09:144812
[email protected]fb661802013-03-25 01:59:324813 // This layer should end up in the same surface as child, with the same draw
4814 // and screen space transforms.
enneea850232015-07-27 16:43:124815 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
4816 duplicate_child_non_owner->SetDrawsContent(true);
4817 SetLayerPropertiesForTesting(duplicate_child_non_owner, identity_matrix,
4818 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4819 false, true, false);
[email protected]94f206c12012-08-25 00:09:144820
[email protected]fb661802013-03-25 01:59:324821 float device_scale_factor = 1.5f;
enneea850232015-07-27 16:43:124822 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144823
[email protected]fb661802013-03-25 01:59:324824 // We should have two render surfaces. The root's render surface and child's
4825 // render surface (it needs one because it has a replica layer).
enneea850232015-07-27 16:43:124826 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144827
[email protected]fb661802013-03-25 01:59:324828 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594829 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324830 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumab6aa1c62015-12-01 21:01:104831 parent->ScreenSpaceTransform());
[email protected]fb661802013-03-25 01:59:324832 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444833 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144834
[email protected]fb661802013-03-25 01:59:324835 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594836 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324837 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
ajumad9432e32015-11-30 19:43:444838 child->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144839
[email protected]fb661802013-03-25 01:59:324840 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:594841 expected_screen_space_transform.Scale(device_scale_factor,
4842 device_scale_factor);
4843 expected_screen_space_transform.Translate(child->position().x(),
4844 child->position().y());
[email protected]fb661802013-03-25 01:59:324845 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
ajumab6aa1c62015-12-01 21:01:104846 child->ScreenSpaceTransform());
[email protected]94f206c12012-08-25 00:09:144847
[email protected]fb661802013-03-25 01:59:324848 gfx::Transform expected_duplicate_child_draw_transform =
ajumad9432e32015-11-30 19:43:444849 child->DrawTransform();
4850 EXPECT_TRANSFORMATION_MATRIX_EQ(child->DrawTransform(),
4851 duplicate_child_non_owner->DrawTransform());
[email protected]fb661802013-03-25 01:59:324852 EXPECT_TRANSFORMATION_MATRIX_EQ(
ajumab6aa1c62015-12-01 21:01:104853 child->ScreenSpaceTransform(),
4854 duplicate_child_non_owner->ScreenSpaceTransform());
hush6b614212014-12-04 22:37:324855 EXPECT_EQ(child->drawable_content_rect(),
4856 duplicate_child_non_owner->drawable_content_rect());
Dana Jansensc46d3742015-06-18 01:33:144857 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
[email protected]94f206c12012-08-25 00:09:144858
[email protected]fb661802013-03-25 01:59:324859 gfx::Transform expected_render_surface_draw_transform;
4860 expected_render_surface_draw_transform.Translate(
4861 device_scale_factor * child->position().x(),
4862 device_scale_factor * child->position().y());
4863 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
4864 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144865
[email protected]fb661802013-03-25 01:59:324866 gfx::Transform expected_surface_draw_transform;
4867 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
4868 device_scale_factor * 2.f);
4869 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
4870 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144871
[email protected]fb661802013-03-25 01:59:324872 gfx::Transform expected_surface_screen_space_transform;
4873 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
4874 device_scale_factor * 2.f);
4875 EXPECT_TRANSFORMATION_MATRIX_EQ(
4876 expected_surface_screen_space_transform,
4877 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144878
[email protected]fb661802013-03-25 01:59:324879 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:264880 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
4881 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
4882 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:324883 EXPECT_TRANSFORMATION_MATRIX_EQ(
4884 expected_replica_draw_transform,
4885 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:144886
[email protected]fb661802013-03-25 01:59:324887 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:264888 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
4889 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
4890 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:324891 EXPECT_TRANSFORMATION_MATRIX_EQ(
4892 expected_replica_screen_space_transform,
4893 child->render_surface()->replica_screen_space_transform());
4894 EXPECT_TRANSFORMATION_MATRIX_EQ(
4895 expected_replica_screen_space_transform,
4896 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:474897}
4898
[email protected]989386c2013-07-18 21:37:234899TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324900 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
[email protected]fb661802013-03-25 01:59:324901 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:474902
enneea850232015-07-27 16:43:124903 LayerImpl* parent = root_layer();
4904 parent->SetDrawsContent(true);
4905 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4906 gfx::PointF(), gfx::Size(33, 31), false, true,
[email protected]fb661802013-03-25 01:59:324907 true);
[email protected]904e9132012-11-01 00:12:474908
enneea850232015-07-27 16:43:124909 LayerImpl* child = AddChildToRoot<LayerImpl>();
4910 child->SetDrawsContent(true);
4911 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4912 gfx::PointF(), gfx::Size(13, 11), false, true,
[email protected]fb661802013-03-25 01:59:324913 true);
[email protected]904e9132012-11-01 00:12:474914
[email protected]fb661802013-03-25 01:59:324915 gfx::Transform replica_transform;
4916 replica_transform.Scale(1.0, -1.0);
danakj60bc3bc2016-04-09 00:24:484917 std::unique_ptr<LayerImpl> replica =
enneea850232015-07-27 16:43:124918 LayerImpl::Create(host_impl()->active_tree(), 7);
4919 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
4920 gfx::PointF(), gfx::Size(13, 11), false, true,
4921 false);
danakja04855a2015-11-18 20:39:104922 child->SetReplicaLayer(std::move(replica));
[email protected]d600df7d2013-08-03 02:34:284923
[email protected]873639e2013-07-24 19:56:314924 float device_scale_factor = 1.7f;
enneea850232015-07-27 16:43:124925 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]904e9132012-11-01 00:12:474926
[email protected]fb661802013-03-25 01:59:324927 // We should have two render surfaces. The root's render surface and child's
4928 // render surface (it needs one because it has a replica layer).
enneea850232015-07-27 16:43:124929 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]904e9132012-11-01 00:12:474930
[email protected]fb661802013-03-25 01:59:324931 gfx::Transform identity_transform;
[email protected]fb661802013-03-25 01:59:324932 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
4933 child->render_surface()->draw_transform());
4934 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
4935 child->render_surface()->draw_transform());
4936 EXPECT_TRANSFORMATION_MATRIX_EQ(
4937 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474938
[email protected]fb661802013-03-25 01:59:324939 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:264940 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:324941 EXPECT_TRANSFORMATION_MATRIX_EQ(
4942 expected_replica_draw_transform,
4943 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:474944
[email protected]fb661802013-03-25 01:59:324945 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:264946 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:324947 EXPECT_TRANSFORMATION_MATRIX_EQ(
4948 expected_replica_screen_space_transform,
4949 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144950}
4951
jaydasikadb41a582016-03-28 20:48:214952TEST_F(LayerTreeHostCommonTest, LayerSearch) {
loyso0940d412016-03-14 01:30:314953 scoped_refptr<Layer> root = Layer::Create();
4954 scoped_refptr<Layer> child = Layer::Create();
4955 scoped_refptr<Layer> grand_child = Layer::Create();
4956 scoped_refptr<Layer> mask_layer = Layer::Create();
4957 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:144958
[email protected]fb661802013-03-25 01:59:324959 grand_child->SetReplicaLayer(replica_layer.get());
4960 child->AddChild(grand_child.get());
4961 child->SetMaskLayer(mask_layer.get());
4962 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:144963
ennea7b43c32015-06-18 20:01:334964 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:284965
[email protected]fb661802013-03-25 01:59:324966 int nonexistent_id = -1;
jaydasikadb41a582016-03-28 20:48:214967 EXPECT_EQ(root.get(), host()->LayerById(root->id()));
4968 EXPECT_EQ(child.get(), host()->LayerById(child->id()));
4969 EXPECT_EQ(grand_child.get(), host()->LayerById(grand_child->id()));
4970 EXPECT_EQ(mask_layer.get(), host()->LayerById(mask_layer->id()));
4971 EXPECT_EQ(replica_layer.get(), host()->LayerById(replica_layer->id()));
4972 EXPECT_FALSE(host()->LayerById(nonexistent_id));
[email protected]94f206c12012-08-25 00:09:144973}
4974
[email protected]989386c2013-07-18 21:37:234975TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
ajuma4711f4b12016-05-16 18:48:324976 LayerImpl* root = root_layer();
4977 LayerImpl* child = AddChild<LayerImpl>(root);
4978 LayerImpl* grand_child = AddChild<LayerImpl>(child);
4979 grand_child->SetDrawsContent(true);
[email protected]498ec6e0e2012-11-30 18:24:574980
[email protected]fb661802013-03-25 01:59:324981 const gfx::Transform identity_matrix;
ajuma4711f4b12016-05-16 18:48:324982 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4983 gfx::PointF(), gfx::Size(100, 100), true, false);
4984 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4985 gfx::PointF(), gfx::Size(10, 10), true, false);
4986 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
4987 gfx::PointF(), gfx::Size(10, 10), true, false);
[email protected]498ec6e0e2012-11-30 18:24:574988
[email protected]fb661802013-03-25 01:59:324989 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:574990
ajuma4711f4b12016-05-16 18:48:324991 ExecuteCalculateDrawProperties(root);
[email protected]498ec6e0e2012-11-30 18:24:574992
ennec1332992015-08-24 19:45:094993 EXPECT_FALSE(child->has_render_surface());
[email protected]498ec6e0e2012-11-30 18:24:574994}
4995
[email protected]989386c2013-07-18 21:37:234996TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
khushalsagarb64b360d2015-10-21 19:25:164997 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:454998 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:564999 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:485000 FakeLayerTreeHostImpl host_impl(host()->settings(), &task_runner_provider,
5001 &shared_bitmap_manager, &task_graph_runner);
[email protected]f90fc412013-03-30 20:13:165002 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:485003 std::unique_ptr<LayerImpl> root =
5004 LayerImpl::Create(host_impl.pending_tree(), 1);
[email protected]f90fc412013-03-30 20:13:165005
5006 const gfx::Transform identity_matrix;
awoloszyne83f28c2014-12-22 15:40:005007 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5008 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]f90fc412013-03-30 20:13:165009 false);
5010 root->SetDrawsContent(true);
5011
danakj60bc3bc2016-04-09 00:24:485012 std::unique_ptr<LayerImpl> child =
5013 LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005014 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5015 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]f90fc412013-03-30 20:13:165016 false);
5017 child->SetDrawsContent(true);
5018 child->SetOpacity(0.0f);
5019
jaydasika9cb21c772016-05-10 22:37:085020 const int child_id = child->id();
5021 root->AddChild(std::move(child));
5022 root->SetHasRenderSurface(true);
5023 LayerImpl* root_layer = root.get();
5024 host_impl.pending_tree()->SetRootLayer(std::move(root));
5025 host_impl.pending_tree()->BuildPropertyTreesForTesting();
[email protected]f90fc412013-03-30 20:13:165026 // Add opacity animation.
loyso9556c732016-03-11 07:54:585027 scoped_refptr<AnimationTimeline> timeline =
5028 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
5029 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:485030
jaydasika9cb21c772016-05-10 22:37:085031 AddOpacityTransitionToLayerWithPlayer(child_id, timeline, 10.0, 0.0f, 1.0f,
loyso9556c732016-03-11 07:54:585032 false);
[email protected]f90fc412013-03-30 20:13:165033
[email protected]c0ae06c12013-06-24 18:32:195034 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535035 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385036 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535037 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575038 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]f90fc412013-03-30 20:13:165039
5040 // We should have one render surface and two layers. The child
5041 // layer should be included even though it is transparent.
5042 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:055043 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
jaydasika86654512016-01-27 17:05:075044
5045 // If the root itself is hidden, the child should not be drawn even if it has
5046 // an animating opacity.
jaydasika0c2fd472016-03-24 01:26:055047 root_layer->SetOpacity(0.0f);
5048 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika86654512016-01-27 17:05:075049 LayerImplList render_surface_layer_list2;
jaydasika86654512016-01-27 17:05:075050 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs2(
ajuma0adb5902016-04-28 16:32:385051 root_layer, root_layer->bounds(), &render_surface_layer_list2);
jaydasika86654512016-01-27 17:05:075052 inputs2.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575053 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs2);
jaydasika86654512016-01-27 17:05:075054
jaydasika0c2fd472016-03-24 01:26:055055 LayerImpl* child_ptr = root_layer->layer_tree_impl()->LayerById(2);
jaydasika8185d302016-04-14 15:20:065056 EffectTree& tree =
jaydasika0c2fd472016-03-24 01:26:055057 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:075058 EffectNode* node = tree.Node(child_ptr->effect_tree_index());
5059 EXPECT_FALSE(node->data.is_drawn);
jaydasikae99e83e2016-01-29 19:35:405060
5061 // A layer should be drawn and it should contribute to drawn surface when
5062 // it has animating opacity even if it has opacity 0.
jaydasika0c2fd472016-03-24 01:26:055063 root_layer->SetOpacity(1.0f);
jaydasikae99e83e2016-01-29 19:35:405064 child_ptr->SetOpacity(0.0f);
jaydasika0c2fd472016-03-24 01:26:055065 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasikae99e83e2016-01-29 19:35:405066 LayerImplList render_surface_layer_list3;
jaydasikae99e83e2016-01-29 19:35:405067 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs3(
ajuma0adb5902016-04-28 16:32:385068 root_layer, root_layer->bounds(), &render_surface_layer_list3);
jaydasikae99e83e2016-01-29 19:35:405069 inputs3.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575070 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs3);
jaydasikae99e83e2016-01-29 19:35:405071
jaydasika0c2fd472016-03-24 01:26:055072 child_ptr = root_layer->layer_tree_impl()->LayerById(2);
5073 tree = root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasikae99e83e2016-01-29 19:35:405074 node = tree.Node(child_ptr->effect_tree_index());
5075 EXPECT_TRUE(node->data.is_drawn);
5076 EXPECT_TRUE(tree.ContributesToDrawnSurface(child_ptr->effect_tree_index()));
jaydasika8185d302016-04-14 15:20:065077
5078 // But if the opacity of the layer remains 0 after activation, it should not
5079 // be drawn.
5080 host_impl.ActivateSyncTree();
5081 LayerImpl* active_root = host_impl.active_tree()->root_layer();
5082 LayerImpl* active_child = host_impl.active_tree()->LayerById(child_ptr->id());
5083
5084 EffectTree& active_effect_tree =
5085 host_impl.active_tree()->property_trees()->effect_tree;
5086 EXPECT_TRUE(active_effect_tree.needs_update());
5087
5088 ExecuteCalculateDrawProperties(active_root);
5089
5090 node = active_effect_tree.Node(active_child->effect_tree_index());
5091 EXPECT_FALSE(node->data.is_drawn);
5092 EXPECT_FALSE(active_effect_tree.ContributesToDrawnSurface(
5093 active_child->effect_tree_index()));
[email protected]f90fc412013-03-30 20:13:165094}
5095
danakj3f76ace2014-11-18 16:56:005096using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
enne637715732015-07-07 02:05:265097class LCDTextTest : public LayerTreeHostCommonTestBase,
5098 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:365099 public:
5100 LCDTextTest()
loyso0940d412016-03-14 01:30:315101 : LayerTreeHostCommonTestBase(LayerTreeSettings()),
5102 host_impl_(&task_runner_provider_,
khushalsagarb64b360d2015-10-21 19:25:165103 &shared_bitmap_manager_,
5104 &task_graph_runner_),
enneaf5bda32015-02-19 01:27:365105 root_(nullptr),
5106 child_(nullptr),
5107 grand_child_(nullptr) {}
5108
loyso968163c92016-01-04 23:18:485109 scoped_refptr<AnimationTimeline> timeline() { return timeline_; }
5110
[email protected]fb661802013-03-25 01:59:325111 protected:
dcheng93a52eb2014-12-23 02:14:235112 void SetUp() override {
loyso9556c732016-03-11 07:54:585113 timeline_ =
5114 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
5115 host_impl_.animation_host()->AddAnimationTimeline(timeline_);
loyso968163c92016-01-04 23:18:485116
[email protected]fb661802013-03-25 01:59:325117 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
danakj3f76ace2014-11-18 16:56:005118 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
[email protected]10aabcc32012-12-13 09:18:595119
danakj60bc3bc2016-04-09 00:24:485120 std::unique_ptr<LayerImpl> root_ptr =
enneaf5bda32015-02-19 01:27:365121 LayerImpl::Create(host_impl_.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:485122 std::unique_ptr<LayerImpl> child_ptr =
enneaf5bda32015-02-19 01:27:365123 LayerImpl::Create(host_impl_.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:485124 std::unique_ptr<LayerImpl> grand_child_ptr =
enneaf5bda32015-02-19 01:27:365125 LayerImpl::Create(host_impl_.active_tree(), 3);
5126
5127 // Stash raw pointers to look at later.
5128 root_ = root_ptr.get();
5129 child_ = child_ptr.get();
5130 grand_child_ = grand_child_ptr.get();
5131
danakja04855a2015-11-18 20:39:105132 child_->AddChild(std::move(grand_child_ptr));
5133 root_->AddChild(std::move(child_ptr));
5134 host_impl_.active_tree()->SetRootLayer(std::move(root_ptr));
[email protected]10aabcc32012-12-13 09:18:595135
fmalita51b5e202014-11-18 20:11:505136 root_->SetContentsOpaque(true);
5137 child_->SetContentsOpaque(true);
5138 grand_child_->SetContentsOpaque(true);
5139
jaydasika3f930c12015-06-30 15:18:255140 root_->SetDrawsContent(true);
5141 child_->SetDrawsContent(true);
5142 grand_child_->SetDrawsContent(true);
5143
[email protected]fb661802013-03-25 01:59:325144 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365145 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
5146 gfx::PointF(), gfx::Size(1, 1), true, false,
5147 true);
5148 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
5149 gfx::PointF(), gfx::Size(1, 1), true, false,
5150 std::tr1::get<2>(GetParam()));
5151 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
5152 gfx::PointF(), gfx::Size(1, 1), true, false,
[email protected]fb661802013-03-25 01:59:325153 false);
[email protected]fb661802013-03-25 01:59:325154 }
[email protected]10aabcc32012-12-13 09:18:595155
[email protected]fb661802013-03-25 01:59:325156 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005157 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:365158
khushalsagarb64b360d2015-10-21 19:25:165159 FakeImplTaskRunnerProvider task_runner_provider_;
enneaf5bda32015-02-19 01:27:365160 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:475161 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:365162 FakeLayerTreeHostImpl host_impl_;
loyso968163c92016-01-04 23:18:485163 scoped_refptr<AnimationTimeline> timeline_;
enneaf5bda32015-02-19 01:27:365164
5165 LayerImpl* root_;
5166 LayerImpl* child_;
5167 LayerImpl* grand_child_;
[email protected]10aabcc32012-12-13 09:18:595168};
5169
[email protected]fb661802013-03-25 01:59:325170TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005171 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5172 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5173
[email protected]fb661802013-03-25 01:59:325174 // Case 1: Identity transform.
5175 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365176 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005177 layers_always_allowed_lcd_text_);
5178 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5179 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5180 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595181
[email protected]fb661802013-03-25 01:59:325182 // Case 2: Integral translation.
5183 gfx::Transform integral_translation;
5184 integral_translation.Translate(1.0, 2.0);
5185 child_->SetTransform(integral_translation);
jaydasika3f930c12015-06-30 15:18:255186 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365187 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005188 layers_always_allowed_lcd_text_);
5189 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5190 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5191 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595192
[email protected]fb661802013-03-25 01:59:325193 // Case 3: Non-integral translation.
5194 gfx::Transform non_integral_translation;
5195 non_integral_translation.Translate(1.5, 2.5);
5196 child_->SetTransform(non_integral_translation);
jaydasika3f930c12015-06-30 15:18:255197 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365198 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005199 layers_always_allowed_lcd_text_);
5200 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5201 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5202 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595203
[email protected]fb661802013-03-25 01:59:325204 // Case 4: Rotation.
5205 gfx::Transform rotation;
5206 rotation.Rotate(10.0);
5207 child_->SetTransform(rotation);
jaydasika3f930c12015-06-30 15:18:255208 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365209 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005210 layers_always_allowed_lcd_text_);
5211 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5212 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5213 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595214
[email protected]fb661802013-03-25 01:59:325215 // Case 5: Scale.
5216 gfx::Transform scale;
5217 scale.Scale(2.0, 2.0);
5218 child_->SetTransform(scale);
jaydasika3f930c12015-06-30 15:18:255219 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365220 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005221 layers_always_allowed_lcd_text_);
5222 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5223 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5224 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595225
[email protected]fb661802013-03-25 01:59:325226 // Case 6: Skew.
5227 gfx::Transform skew;
nainar8ca8ee62015-09-03 01:04:105228 skew.Skew(10.0, 0.0);
[email protected]fb661802013-03-25 01:59:325229 child_->SetTransform(skew);
jaydasika3f930c12015-06-30 15:18:255230 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365231 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005232 layers_always_allowed_lcd_text_);
5233 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5234 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5235 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595236
[email protected]fb661802013-03-25 01:59:325237 // Case 7: Translucent.
5238 child_->SetTransform(identity_matrix);
jaydasika3f930c12015-06-30 15:18:255239 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]fb661802013-03-25 01:59:325240 child_->SetOpacity(0.5f);
enneaf5bda32015-02-19 01:27:365241 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005242 layers_always_allowed_lcd_text_);
5243 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5244 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5245 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595246
[email protected]fb661802013-03-25 01:59:325247 // Case 8: Sanity check: restore transform and opacity.
5248 child_->SetTransform(identity_matrix);
jaydasika3f930c12015-06-30 15:18:255249 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]fb661802013-03-25 01:59:325250 child_->SetOpacity(1.f);
enneaf5bda32015-02-19 01:27:365251 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005252 layers_always_allowed_lcd_text_);
5253 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5254 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5255 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalita51b5e202014-11-18 20:11:505256
5257 // Case 9: Non-opaque content.
5258 child_->SetContentsOpaque(false);
enneaf5bda32015-02-19 01:27:365259 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505260 layers_always_allowed_lcd_text_);
5261 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5262 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5263 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5264
5265 // Case 10: Sanity check: restore content opaqueness.
5266 child_->SetContentsOpaque(true);
enneaf5bda32015-02-19 01:27:365267 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505268 layers_always_allowed_lcd_text_);
5269 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5270 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5271 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595272}
5273
[email protected]fd9a3b6d2013-08-03 00:46:175274TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005275 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
fmalitafcd926a2015-05-13 20:19:335276 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
danakj3f76ace2014-11-18 16:56:005277
[email protected]fb661802013-03-25 01:59:325278 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
enneaf5bda32015-02-19 01:27:365279 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005280 layers_always_allowed_lcd_text_);
5281 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5282 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5283 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595284
[email protected]fb661802013-03-25 01:59:325285 // Add opacity animation.
5286 child_->SetOpacity(0.9f);
jaydasika3f930c12015-06-30 15:18:255287 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso9556c732016-03-11 07:54:585288 AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f,
5289 0.1f, false);
enneaf5bda32015-02-19 01:27:365290 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005291 layers_always_allowed_lcd_text_);
fmalitafcd926a2015-05-13 20:19:335292 // Text LCD should be adjusted while animation is active.
5293 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5294 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5295 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5296}
5297
5298TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
5299 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5300 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5301
5302 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
5303 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5304 layers_always_allowed_lcd_text_);
danakj3f76ace2014-11-18 16:56:005305 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5306 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5307 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalitafcd926a2015-05-13 20:19:335308
5309 // Mark contents non-opaque within the first animation frame.
5310 child_->SetContentsOpaque(false);
loyso9556c732016-03-11 07:54:585311 AddOpacityTransitionToLayerWithPlayer(child_->id(), timeline(), 10.0, 0.9f,
5312 0.1f, false);
fmalitafcd926a2015-05-13 20:19:335313 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5314 layers_always_allowed_lcd_text_);
5315 // LCD text should be disabled for non-opaque layers even during animations.
5316 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5317 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5318 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595319}
5320
5321INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5322 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005323 testing::Combine(testing::Bool(),
5324 testing::Bool(),
5325 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595326
[email protected]989386c2013-07-18 21:37:235327TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:165328 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455329 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565330 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165331 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565332 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195333 host_impl.CreatePendingTree();
5334 const gfx::Transform identity_matrix;
5335
danakj60bc3bc2016-04-09 00:24:485336 std::unique_ptr<LayerImpl> root =
5337 LayerImpl::Create(host_impl.pending_tree(), 1);
jaydasika0c2fd472016-03-24 01:26:055338 LayerImpl* root_layer = root.get();
awoloszyne83f28c2014-12-22 15:40:005339 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5340 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]c0ae06c12013-06-24 18:32:195341 false);
5342 root->SetDrawsContent(true);
5343
danakj60bc3bc2016-04-09 00:24:485344 std::unique_ptr<LayerImpl> child =
5345 LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005346 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5347 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:195348 false);
5349 child->SetDrawsContent(true);
5350
danakj60bc3bc2016-04-09 00:24:485351 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195352 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:005353 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5354 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5355 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:195356 grand_child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355357 grand_child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195358
danakja04855a2015-11-18 20:39:105359 child->AddChild(std::move(grand_child));
5360 root->AddChild(std::move(child));
awoloszyne83f28c2014-12-22 15:40:005361 root->SetHasRenderSurface(true);
jaydasika0c2fd472016-03-24 01:26:055362 host_impl.pending_tree()->SetRootLayer(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195363
5364 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535365 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385366 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535367 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575368 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195369
5370 // We should have one render surface and two layers. The grand child has
5371 // hidden itself.
5372 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika0c2fd472016-03-24 01:26:055373 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5374 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
5375 EXPECT_EQ(2, root_layer->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195376}
5377
[email protected]989386c2013-07-18 21:37:235378TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
khushalsagarb64b360d2015-10-21 19:25:165379 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455380 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565381 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165382 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565383 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195384 host_impl.CreatePendingTree();
5385 const gfx::Transform identity_matrix;
5386
danakj60bc3bc2016-04-09 00:24:485387 std::unique_ptr<LayerImpl> root =
5388 LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:005389 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5390 gfx::PointF(), gfx::Size(50, 50), true, false,
5391 true);
[email protected]c0ae06c12013-06-24 18:32:195392 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095393 LayerImpl* root_layer = root.get();
[email protected]c0ae06c12013-06-24 18:32:195394
danakj60bc3bc2016-04-09 00:24:485395 std::unique_ptr<LayerImpl> child =
5396 LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005397 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5398 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:195399 false);
5400 child->SetDrawsContent(true);
jaydasika5121caa82016-05-05 15:43:355401 child->test_properties()->hide_layer_and_subtree = true;
[email protected]c0ae06c12013-06-24 18:32:195402
danakj60bc3bc2016-04-09 00:24:485403 std::unique_ptr<LayerImpl> grand_child =
[email protected]c0ae06c12013-06-24 18:32:195404 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:005405 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5406 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5407 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:195408 grand_child->SetDrawsContent(true);
5409
danakja04855a2015-11-18 20:39:105410 child->AddChild(std::move(grand_child));
5411 root->AddChild(std::move(child));
jaydasika2411692c2016-03-23 01:56:095412 host_impl.pending_tree()->SetRootLayer(std::move(root));
[email protected]c0ae06c12013-06-24 18:32:195413
5414 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535415 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385416 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535417 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575418 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195419
5420 // We should have one render surface and one layers. The child has
5421 // hidden itself and the grand child.
5422 ASSERT_EQ(1u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095423 ASSERT_EQ(1u, root_layer->render_surface()->layer_list().size());
5424 EXPECT_EQ(1, root_layer->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:195425}
5426
danakj60bc3bc2016-04-09 00:24:485427void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
[email protected]30fe19ff2013-07-04 00:54:455428
[email protected]989386c2013-07-18 21:37:235429TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165430 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455431 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565432 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165433 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565434 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455435 host_impl.CreatePendingTree();
5436 const gfx::Transform identity_matrix;
5437
danakj60bc3bc2016-04-09 00:24:485438 std::unique_ptr<LayerImpl> root =
5439 LayerImpl::Create(host_impl.pending_tree(), 1);
weiliangc51fb255d2015-07-24 15:32:305440 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5441 gfx::PointF(), gfx::Size(50, 50), true, false,
5442 true);
5443 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:095444 LayerImpl* root_layer = root.get();
[email protected]30fe19ff2013-07-04 00:54:455445
danakj60bc3bc2016-04-09 00:24:485446 std::unique_ptr<LayerImpl> copy_grand_parent =
weiliangc51fb255d2015-07-24 15:32:305447 LayerImpl::Create(host_impl.pending_tree(), 2);
5448 SetLayerPropertiesForTesting(copy_grand_parent.get(), identity_matrix,
5449 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5450 true, false, false);
5451 copy_grand_parent->SetDrawsContent(true);
5452 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455453
danakj60bc3bc2016-04-09 00:24:485454 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305455 LayerImpl::Create(host_impl.pending_tree(), 3);
5456 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
5457 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5458 true, false, true);
5459 copy_parent->SetDrawsContent(true);
5460 LayerImpl* copy_parent_layer = copy_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455461
danakj60bc3bc2016-04-09 00:24:485462 std::unique_ptr<LayerImpl> copy_request =
weiliangc51fb255d2015-07-24 15:32:305463 LayerImpl::Create(host_impl.pending_tree(), 4);
5464 SetLayerPropertiesForTesting(copy_request.get(), identity_matrix,
5465 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5466 true, false, true);
5467 copy_request->SetDrawsContent(true);
5468 LayerImpl* copy_layer = copy_request.get();
[email protected]30fe19ff2013-07-04 00:54:455469
danakj60bc3bc2016-04-09 00:24:485470 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305471 LayerImpl::Create(host_impl.pending_tree(), 5);
5472 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
5473 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5474 true, false, false);
5475 copy_child->SetDrawsContent(true);
5476 LayerImpl* copy_child_layer = copy_child.get();
[email protected]30fe19ff2013-07-04 00:54:455477
danakj60bc3bc2016-04-09 00:24:485478 std::unique_ptr<LayerImpl> copy_grand_child =
thakise53c5272016-01-24 01:20:405479 LayerImpl::Create(host_impl.pending_tree(), 6);
jaydasika86654512016-01-27 17:05:075480 SetLayerPropertiesForTesting(copy_grand_child.get(), identity_matrix,
5481 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5482 true, false, false);
5483 copy_child->SetDrawsContent(true);
5484 LayerImpl* copy_grand_child_layer = copy_grand_child.get();
5485
danakj60bc3bc2016-04-09 00:24:485486 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_before =
jaydasika86654512016-01-27 17:05:075487 LayerImpl::Create(host_impl.pending_tree(), 7);
[email protected]ac020122013-07-12 23:45:535488 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
weiliangc51fb255d2015-07-24 15:32:305489 identity_matrix, gfx::Point3F(), gfx::PointF(),
5490 gfx::Size(40, 40), true, false, false);
5491 copy_grand_parent_sibling_before->SetDrawsContent(true);
5492 LayerImpl* copy_grand_parent_sibling_before_layer =
5493 copy_grand_parent_sibling_before.get();
[email protected]ac020122013-07-12 23:45:535494
danakj60bc3bc2016-04-09 00:24:485495 std::unique_ptr<LayerImpl> copy_grand_parent_sibling_after =
jaydasika86654512016-01-27 17:05:075496 LayerImpl::Create(host_impl.pending_tree(), 8);
[email protected]ac020122013-07-12 23:45:535497 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
weiliangc51fb255d2015-07-24 15:32:305498 identity_matrix, gfx::Point3F(), gfx::PointF(),
5499 gfx::Size(40, 40), true, false, false);
5500 copy_grand_parent_sibling_after->SetDrawsContent(true);
5501 LayerImpl* copy_grand_parent_sibling_after_layer =
5502 copy_grand_parent_sibling_after.get();
[email protected]ac020122013-07-12 23:45:535503
jaydasika86654512016-01-27 17:05:075504 copy_child->AddChild(std::move(copy_grand_child));
danakja04855a2015-11-18 20:39:105505 copy_request->AddChild(std::move(copy_child));
5506 copy_parent->AddChild(std::move(copy_request));
5507 copy_grand_parent->AddChild(std::move(copy_parent));
5508 root->AddChild(std::move(copy_grand_parent_sibling_before));
5509 root->AddChild(std::move(copy_grand_parent));
5510 root->AddChild(std::move(copy_grand_parent_sibling_after));
jaydasika2411692c2016-03-23 01:56:095511 host_impl.pending_tree()->SetRootLayer(std::move(root));
[email protected]d600df7d2013-08-03 02:34:285512
[email protected]30fe19ff2013-07-04 00:54:455513 // Hide the copy_grand_parent and its subtree. But make a copy request in that
jaydasika86654512016-01-27 17:05:075514 // hidden subtree on copy_layer. Also hide the copy grand child and its
5515 // subtree.
jaydasika5121caa82016-05-05 15:43:355516 copy_grand_parent_layer->test_properties()->hide_layer_and_subtree = true;
5517 copy_grand_parent_sibling_before_layer->test_properties()
5518 ->hide_layer_and_subtree = true;
5519 copy_grand_parent_sibling_after_layer->test_properties()
5520 ->hide_layer_and_subtree = true;
5521 copy_grand_child_layer->test_properties()->hide_layer_and_subtree = true;
weiliangc51fb255d2015-07-24 15:32:305522
danakj60bc3bc2016-04-09 00:24:485523 std::vector<std::unique_ptr<CopyOutputRequest>> copy_requests;
weiliangc51fb255d2015-07-24 15:32:305524 copy_requests.push_back(
5525 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5526 copy_layer->PassCopyRequests(&copy_requests);
[email protected]30fe19ff2013-07-04 00:54:455527 EXPECT_TRUE(copy_layer->HasCopyRequest());
5528
weiliangc51fb255d2015-07-24 15:32:305529 LayerImplList render_surface_layer_list;
weiliangc51fb255d2015-07-24 15:32:305530 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385531 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535532 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575533 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455534
jaydasika2411692c2016-03-23 01:56:095535 EXPECT_GT(root_layer->num_copy_requests_in_target_subtree(), 0);
sunxded58688e2016-01-11 21:01:025536 EXPECT_GT(copy_grand_parent_layer->num_copy_requests_in_target_subtree(), 0);
5537 EXPECT_GT(copy_parent_layer->num_copy_requests_in_target_subtree(), 0);
5538 EXPECT_GT(copy_layer->num_copy_requests_in_target_subtree(), 0);
[email protected]ac020122013-07-12 23:45:535539
jaydasika86654512016-01-27 17:05:075540 // We should have four render surfaces, one for the root, one for the grand
5541 // parent since it has opacity and two drawing descendants, one for the parent
[email protected]30fe19ff2013-07-04 00:54:455542 // since it owns a surface, and one for the copy_layer.
jaydasika86654512016-01-27 17:05:075543 ASSERT_EQ(4u, render_surface_layer_list.size());
jaydasika2411692c2016-03-23 01:56:095544 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
jaydasika86654512016-01-27 17:05:075545 EXPECT_EQ(copy_grand_parent_layer->id(),
5546 render_surface_layer_list.at(1)->id());
5547 EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(2)->id());
5548 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(3)->id());
[email protected]30fe19ff2013-07-04 00:54:455549
jaydasika86654512016-01-27 17:05:075550 // The root render surface should have 2 contributing layers.
jaydasika2411692c2016-03-23 01:56:095551 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5552 EXPECT_EQ(root_layer->id(),
5553 root_layer->render_surface()->layer_list().at(0)->id());
jaydasika86654512016-01-27 17:05:075554 EXPECT_EQ(copy_grand_parent_layer->id(),
jaydasika2411692c2016-03-23 01:56:095555 root_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:455556
[email protected]7392c7b2014-02-07 08:28:285557 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:455558 // appear in its list, since it needs to be drawn for the copy request.
weiliangc51fb255d2015-07-24 15:32:305559 ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size());
[email protected]30fe19ff2013-07-04 00:54:455560 EXPECT_EQ(copy_layer->id(),
jaydasika8185d302016-04-14 15:20:065561 copy_parent_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455562
5563 // The copy_layer's render surface should have two contributing layers.
5564 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
5565 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:235566 copy_layer->render_surface()->layer_list().at(0)->id());
weiliangc51fb255d2015-07-24 15:32:305567 EXPECT_EQ(copy_child_layer->id(),
[email protected]989386c2013-07-18 21:37:235568 copy_layer->render_surface()->layer_list().at(1)->id());
jaydasika86654512016-01-27 17:05:075569
5570 // copy_grand_parent, copy_parent shouldn't be drawn because they are hidden,
5571 // but the copy_layer and copy_child should be drawn for the copy request.
5572 // copy grand child should not be drawn as its hidden even in the copy
5573 // request.
ajumae4af47062016-05-24 23:59:045574 EffectTree& tree =
jaydasika2411692c2016-03-23 01:56:095575 root_layer->layer_tree_impl()->property_trees()->effect_tree;
jaydasika86654512016-01-27 17:05:075576 EffectNode* node = tree.Node(copy_grand_parent_layer->effect_tree_index());
5577 EXPECT_FALSE(node->data.is_drawn);
5578 node = tree.Node(copy_parent_layer->effect_tree_index());
5579 EXPECT_FALSE(node->data.is_drawn);
5580 node = tree.Node(copy_layer->effect_tree_index());
5581 EXPECT_TRUE(node->data.is_drawn);
5582 node = tree.Node(copy_child_layer->effect_tree_index());
5583 EXPECT_TRUE(node->data.is_drawn);
5584 node = tree.Node(copy_grand_child_layer->effect_tree_index());
5585 EXPECT_FALSE(node->data.is_drawn);
5586
5587 // Though copy_layer is drawn, it shouldn't contribute to drawn surface as its
5588 // actually hidden.
5589 EXPECT_FALSE(copy_layer->render_surface()->contributes_to_drawn_surface());
[email protected]30fe19ff2013-07-04 00:54:455590}
5591
[email protected]989386c2013-07-18 21:37:235592TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165593 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455594 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565595 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165596 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565597 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455598 host_impl.CreatePendingTree();
5599 const gfx::Transform identity_matrix;
5600
danakj60bc3bc2016-04-09 00:24:485601 std::unique_ptr<LayerImpl> root =
5602 LayerImpl::Create(host_impl.pending_tree(), 1);
weiliangc51fb255d2015-07-24 15:32:305603 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5604 gfx::PointF(), gfx::Size(50, 50), true, false,
5605 true);
5606 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455607
danakj60bc3bc2016-04-09 00:24:485608 std::unique_ptr<LayerImpl> copy_parent =
weiliangc51fb255d2015-07-24 15:32:305609 LayerImpl::Create(host_impl.pending_tree(), 2);
5610 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
5611 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
5612 false, false);
5613 copy_parent->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455614 copy_parent->SetMasksToBounds(true);
5615
danakj60bc3bc2016-04-09 00:24:485616 std::unique_ptr<LayerImpl> copy_layer =
weiliangc51fb255d2015-07-24 15:32:305617 LayerImpl::Create(host_impl.pending_tree(), 3);
5618 SetLayerPropertiesForTesting(copy_layer.get(), identity_matrix,
5619 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5620 true, false, true);
5621 copy_layer->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455622
danakj60bc3bc2016-04-09 00:24:485623 std::unique_ptr<LayerImpl> copy_child =
weiliangc51fb255d2015-07-24 15:32:305624 LayerImpl::Create(host_impl.pending_tree(), 4);
5625 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
5626 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5627 true, false, false);
5628 copy_child->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455629
danakj60bc3bc2016-04-09 00:24:485630 std::vector<std::unique_ptr<CopyOutputRequest>> copy_requests;
weiliangc51fb255d2015-07-24 15:32:305631 copy_requests.push_back(
5632 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5633 copy_layer->PassCopyRequests(&copy_requests);
[email protected]30fe19ff2013-07-04 00:54:455634 EXPECT_TRUE(copy_layer->HasCopyRequest());
5635
danakja04855a2015-11-18 20:39:105636 copy_layer->AddChild(std::move(copy_child));
5637 copy_parent->AddChild(std::move(copy_layer));
5638 root->AddChild(std::move(copy_parent));
weiliangc51fb255d2015-07-24 15:32:305639
5640 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:055641 LayerImpl* root_layer = root.get();
5642 root_layer->layer_tree_impl()->SetRootLayer(std::move(root));
weiliangc51fb255d2015-07-24 15:32:305643 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:385644 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535645 inputs.can_adjust_raster_scales = true;
sunxdb365de02016-04-28 20:32:575646 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455647
xjze19f76402015-11-06 21:48:445648 // We should have two render surface, as the others are clipped out.
5649 ASSERT_EQ(2u, render_surface_layer_list.size());
sunxd71aea3e2016-04-01 23:48:055650 EXPECT_EQ(root_layer->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455651
xjze19f76402015-11-06 21:48:445652 // The root render surface should only have 2 contributing layer, since the
[email protected]30fe19ff2013-07-04 00:54:455653 // other layers are empty/clipped away.
sunxd71aea3e2016-04-01 23:48:055654 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size());
5655 EXPECT_EQ(root_layer->id(),
5656 root_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455657}
5658
[email protected]11a07b102013-07-24 17:33:195659TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
jaydasika6f972de2016-04-07 16:16:145660 LayerImpl* root = root_layer();
5661 LayerImpl* surface = AddChild<LayerImpl>(root);
5662 LayerImpl* surface_child = AddChild<LayerImpl>(surface);
5663
[email protected]11a07b102013-07-24 17:33:195664 const gfx::Transform identity_matrix;
jaydasika6f972de2016-04-07 16:16:145665 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
5666 gfx::PointF(), gfx::Size(50, 50), true, false,
5667 true);
5668 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
5669 gfx::PointF(-10, 20), gfx::Size(), true, false,
5670 true);
5671 SetLayerPropertiesForTesting(surface_child, identity_matrix, gfx::Point3F(),
5672 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]11a07b102013-07-24 17:33:195673 false);
jaydasika6f972de2016-04-07 16:16:145674 root->SetDrawsContent(true);
5675 surface_child->SetDrawsContent(true);
[email protected]11a07b102013-07-24 17:33:195676
jaydasika6f972de2016-04-07 16:16:145677 ExecuteCalculateDrawProperties(root);
[email protected]11a07b102013-07-24 17:33:195678
danakj64767d902015-06-19 00:10:435679 // The visible_layer_rect for the |surface_child| should not be clipped by
[email protected]11a07b102013-07-24 17:33:195680 // the viewport.
jaydasika6f972de2016-04-07 16:16:145681 EXPECT_EQ(gfx::Rect(50, 50), surface_child->visible_layer_rect());
[email protected]11a07b102013-07-24 17:33:195682}
5683
[email protected]420fdf6e2013-08-26 20:36:385684TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5685 // Ensure that a transform between the layer and its render surface is not a
5686 // problem. Constructs the following layer tree.
5687 //
5688 // root (a render surface)
5689 // + render_surface
5690 // + clip_parent (scaled)
5691 // + intervening_clipping_layer
5692 // + clip_child
5693 //
5694 // The render surface should be resized correctly and the clip child should
5695 // inherit the right clip rect.
enne70aa712d2015-07-28 22:46:315696 LayerImpl* root = root_layer();
5697 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
5698 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
jaydasika0d98ba92015-11-17 05:17:285699 clip_parent->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315700 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285701 intervening->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315702 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5703 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:565704 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:485705 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enne70aa712d2015-07-28 22:46:315706 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:565707 clip_parent->test_properties()->clip_children.reset(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385708
5709 intervening->SetMasksToBounds(true);
5710 clip_parent->SetMasksToBounds(true);
5711
[email protected]420fdf6e2013-08-26 20:36:385712 gfx::Transform scale_transform;
5713 scale_transform.Scale(2, 2);
5714
5715 gfx::Transform identity_transform;
5716
enne70aa712d2015-07-28 22:46:315717 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5718 gfx::PointF(), gfx::Size(50, 50), true, false,
5719 true);
5720 SetLayerPropertiesForTesting(render_surface, identity_transform,
5721 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5722 true, false, true);
5723 SetLayerPropertiesForTesting(clip_parent, scale_transform, gfx::Point3F(),
5724 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
5725 false, false);
5726 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5727 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5728 false, false);
5729 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5730 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
5731 false, false);
[email protected]420fdf6e2013-08-26 20:36:385732
enne70aa712d2015-07-28 22:46:315733 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385734
5735 ASSERT_TRUE(root->render_surface());
5736 ASSERT_TRUE(render_surface->render_surface());
5737
5738 // Ensure that we've inherited our clip parent's clip and weren't affected
5739 // by the intervening clip layer.
jaydasika6f972de2016-04-07 16:16:145740 ASSERT_EQ(gfx::Rect(1, 1, 20, 20), clip_parent->clip_rect());
5741 ASSERT_EQ(clip_parent->clip_rect(), clip_child->clip_rect());
5742 ASSERT_EQ(gfx::Rect(3, 3, 10, 10), intervening->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385743
5744 // Ensure that the render surface reports a content rect that has been grown
5745 // to accomodate for the clip child.
jaydasika6f972de2016-04-07 16:16:145746 ASSERT_EQ(gfx::Rect(1, 1, 20, 20),
5747 render_surface->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385748
5749 // The above check implies the two below, but they nicely demonstrate that
5750 // we've grown, despite the intervening layer's clip.
5751 ASSERT_TRUE(clip_parent->clip_rect().Contains(
5752 render_surface->render_surface()->content_rect()));
5753 ASSERT_FALSE(intervening->clip_rect().Contains(
5754 render_surface->render_surface()->content_rect()));
5755}
5756
5757TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5758 // Ensure that intervening render surfaces are not a problem in the basic
5759 // case. In the following tree, both render surfaces should be resized to
5760 // accomodate for the clip child, despite an intervening clip.
5761 //
5762 // root (a render surface)
5763 // + clip_parent (masks to bounds)
5764 // + render_surface1 (sets opacity)
5765 // + intervening (masks to bounds)
5766 // + render_surface2 (also sets opacity)
5767 // + clip_child
5768 //
weiliangcd6a836d2015-07-28 21:20:235769 LayerImpl* root = root_layer();
5770 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5771 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5772 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5773 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5774 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365775 render_surface1->SetDrawsContent(true);
5776 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235777 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385778
jaydasika1c0a27d42016-04-28 01:54:565779 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385780
5781 intervening->SetMasksToBounds(true);
5782 clip_parent->SetMasksToBounds(true);
5783
[email protected]420fdf6e2013-08-26 20:36:385784 gfx::Transform translation_transform;
5785 translation_transform.Translate(2, 2);
5786
5787 gfx::Transform identity_transform;
weiliangcd6a836d2015-07-28 21:20:235788 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5789 gfx::PointF(), gfx::Size(50, 50), true, false,
5790 true);
5791 SetLayerPropertiesForTesting(clip_parent, translation_transform,
5792 gfx::Point3F(), gfx::PointF(1.f, 1.f),
5793 gfx::Size(40, 40), true, false, false);
5794 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5795 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5796 true, false, true);
5797 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5798 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5799 false, false);
5800 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5801 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5802 true, false, true);
5803 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5804 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
5805 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:385806
weiliangcd6a836d2015-07-28 21:20:235807 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385808
5809 EXPECT_TRUE(root->render_surface());
5810 EXPECT_TRUE(render_surface1->render_surface());
5811 EXPECT_TRUE(render_surface2->render_surface());
5812
5813 // Since the render surfaces could have expanded, they should not clip (their
5814 // bounds would no longer be reliable). We should resort to layer clipping
5815 // in this case.
jaydasika6f972de2016-04-07 16:16:145816 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5817 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385818 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145819 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5820 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385821 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5822
5823 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145824 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385825 EXPECT_TRUE(render_surface1->is_clipped());
5826
5827 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145828 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385829 EXPECT_TRUE(render_surface2->is_clipped());
5830
5831 // The content rects of both render surfaces should both have expanded to
5832 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145833 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5834 render_surface1->render_surface()->content_rect());
5835 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40),
5836 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385837
5838 // The clip child should have inherited the clip parent's clip (projected to
5839 // the right space, of course), and should have the correctly sized visible
5840 // content rect.
jaydasika6f972de2016-04-07 16:16:145841 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40), clip_child->clip_rect());
5842 EXPECT_EQ(gfx::Rect(9, 9, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385843 EXPECT_TRUE(clip_child->is_clipped());
5844}
5845
5846TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
5847 // Ensure that intervening render surfaces are not a problem, even if there
5848 // is a scroll involved. Note, we do _not_ have to consider any other sort
5849 // of transform.
5850 //
5851 // root (a render surface)
5852 // + clip_parent (masks to bounds)
5853 // + render_surface1 (sets opacity)
5854 // + intervening (masks to bounds AND scrolls)
5855 // + render_surface2 (also sets opacity)
5856 // + clip_child
5857 //
weiliangcd6a836d2015-07-28 21:20:235858 LayerImpl* root = root_layer();
5859 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5860 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5861 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5862 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5863 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365864 render_surface1->SetDrawsContent(true);
5865 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235866 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385867
jaydasika1c0a27d42016-04-28 01:54:565868 clip_child->test_properties()->clip_parent = clip_parent;
[email protected]420fdf6e2013-08-26 20:36:385869
5870 intervening->SetMasksToBounds(true);
5871 clip_parent->SetMasksToBounds(true);
weiliangcd6a836d2015-07-28 21:20:235872 intervening->SetScrollClipLayer(clip_parent->id());
5873 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:385874
5875 gfx::Transform translation_transform;
5876 translation_transform.Translate(2, 2);
5877
5878 gfx::Transform identity_transform;
weiliangcd6a836d2015-07-28 21:20:235879 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5880 gfx::PointF(), gfx::Size(50, 50), true, false,
5881 true);
5882 SetLayerPropertiesForTesting(clip_parent, translation_transform,
5883 gfx::Point3F(), gfx::PointF(1.f, 1.f),
5884 gfx::Size(40, 40), true, false, false);
5885 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5886 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5887 true, false, true);
5888 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5889 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5890 false, false);
5891 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5892 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5893 true, false, true);
5894 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5895 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
5896 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:385897
weiliangcd6a836d2015-07-28 21:20:235898 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385899
5900 EXPECT_TRUE(root->render_surface());
5901 EXPECT_TRUE(render_surface1->render_surface());
5902 EXPECT_TRUE(render_surface2->render_surface());
5903
5904 // Since the render surfaces could have expanded, they should not clip (their
5905 // bounds would no longer be reliable). We should resort to layer clipping
5906 // in this case.
jaydasika6f972de2016-04-07 16:16:145907 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5908 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385909 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
jaydasika6f972de2016-04-07 16:16:145910 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
5911 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385912 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5913
5914 // NB: clip rects are in target space.
jaydasika6f972de2016-04-07 16:16:145915 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385916 EXPECT_TRUE(render_surface1->is_clipped());
5917
5918 // This value is inherited from the clipping ancestor layer, 'intervening'.
jaydasika6f972de2016-04-07 16:16:145919 EXPECT_EQ(gfx::Rect(2, 2, 3, 3), render_surface2->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385920 EXPECT_TRUE(render_surface2->is_clipped());
5921
5922 // The content rects of both render surfaces should both have expanded to
5923 // contain the clip child.
jaydasika6f972de2016-04-07 16:16:145924 EXPECT_EQ(gfx::Rect(0, 0, 40, 40),
5925 render_surface1->render_surface()->content_rect());
5926 EXPECT_EQ(gfx::Rect(2, 2, 40, 40),
5927 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:385928
5929 // The clip child should have inherited the clip parent's clip (projected to
5930 // the right space, of course), and should have the correctly sized visible
5931 // content rect.
jaydasika6f972de2016-04-07 16:16:145932 EXPECT_EQ(gfx::Rect(2, 2, 40, 40), clip_child->clip_rect());
5933 EXPECT_EQ(gfx::Rect(12, 12, 40, 40), clip_child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385934 EXPECT_TRUE(clip_child->is_clipped());
5935}
5936
5937TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
5938 // Ensures that descendants of the clip child inherit the correct clip.
5939 //
5940 // root (a render surface)
5941 // + clip_parent (masks to bounds)
5942 // + intervening (masks to bounds)
5943 // + clip_child
5944 // + child
5945 //
enne2d0d8e62015-08-18 18:29:175946 LayerImpl* root = root_layer();
5947 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
5948 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
5949 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5950 LayerImpl* child = AddChild<LayerImpl>(clip_child);
jaydasika8640f9f2015-11-10 01:34:365951 clip_child->SetDrawsContent(true);
enne2d0d8e62015-08-18 18:29:175952 child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385953
jaydasika1c0a27d42016-04-28 01:54:565954 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:485955 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enne2d0d8e62015-08-18 18:29:175956 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:565957 clip_parent->test_properties()->clip_children.reset(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385958
5959 intervening->SetMasksToBounds(true);
5960 clip_parent->SetMasksToBounds(true);
5961
5962 gfx::Transform identity_transform;
enne2d0d8e62015-08-18 18:29:175963 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5964 gfx::PointF(), gfx::Size(50, 50), true, false,
5965 true);
5966 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
5967 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]420fdf6e2013-08-26 20:36:385968 false);
enne2d0d8e62015-08-18 18:29:175969 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5970 gfx::PointF(), gfx::Size(5, 5), true, false,
[email protected]420fdf6e2013-08-26 20:36:385971 false);
enne2d0d8e62015-08-18 18:29:175972 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5973 gfx::PointF(), gfx::Size(60, 60), true, false,
[email protected]420fdf6e2013-08-26 20:36:385974 false);
enne2d0d8e62015-08-18 18:29:175975 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
5976 gfx::PointF(), gfx::Size(60, 60), true, false,
[email protected]420fdf6e2013-08-26 20:36:385977 false);
5978
enne2d0d8e62015-08-18 18:29:175979 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385980
5981 EXPECT_TRUE(root->render_surface());
5982
5983 // Neither the clip child nor its descendant should have inherited the clip
5984 // from |intervening|.
jaydasika6f972de2016-04-07 16:16:145985 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), clip_child->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:385986 EXPECT_TRUE(clip_child->is_clipped());
jaydasika6f972de2016-04-07 16:16:145987 EXPECT_EQ(gfx::Rect(0, 0, 40, 40), child->visible_layer_rect());
[email protected]420fdf6e2013-08-26 20:36:385988 EXPECT_TRUE(child->is_clipped());
5989}
5990
5991TEST_F(LayerTreeHostCommonTest,
5992 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
5993 // Ensures that non-descendant clip children in the tree do not affect
5994 // render surfaces.
5995 //
5996 // root (a render surface)
5997 // + clip_parent (masks to bounds)
5998 // + render_surface1
5999 // + clip_child
6000 // + render_surface2
6001 // + non_clip_child
6002 //
6003 // In this example render_surface2 should be unaffected by clip_child.
enneb441cdd2015-07-28 22:47:506004 LayerImpl* root = root_layer();
6005 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
6006 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:286007 render_surface1->SetDrawsContent(true);
enneb441cdd2015-07-28 22:47:506008 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
6009 clip_child->SetDrawsContent(true);
6010 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:286011 render_surface2->SetDrawsContent(true);
enneb441cdd2015-07-28 22:47:506012 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
6013 non_clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:386014
jaydasika1c0a27d42016-04-28 01:54:566015 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:486016 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
enneb441cdd2015-07-28 22:47:506017 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:566018 clip_parent->test_properties()->clip_children.reset(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:386019
6020 clip_parent->SetMasksToBounds(true);
6021 render_surface1->SetMasksToBounds(true);
6022
6023 gfx::Transform identity_transform;
enneb441cdd2015-07-28 22:47:506024 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6025 gfx::PointF(), gfx::Size(15, 15), true, false,
6026 true);
6027 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
6028 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]420fdf6e2013-08-26 20:36:386029 false);
enneb441cdd2015-07-28 22:47:506030 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6031 gfx::Point3F(), gfx::PointF(5, 5),
6032 gfx::Size(5, 5), true, false, true);
6033 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6034 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
6035 true, false, true);
6036 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
6037 gfx::PointF(-1, 1), gfx::Size(10, 10), true,
6038 false, false);
6039 SetLayerPropertiesForTesting(non_clip_child, identity_transform,
6040 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
6041 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:386042
enneb441cdd2015-07-28 22:47:506043 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:386044
6045 EXPECT_TRUE(root->render_surface());
6046 EXPECT_TRUE(render_surface1->render_surface());
6047 EXPECT_TRUE(render_surface2->render_surface());
6048
jaydasika6f972de2016-04-07 16:16:146049 EXPECT_EQ(gfx::Rect(0, 0, 5, 5), render_surface1->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386050 EXPECT_TRUE(render_surface1->is_clipped());
6051
6052 // The render surface should not clip (it has unclipped descendants), instead
6053 // it should rely on layer clipping.
jaydasika6f972de2016-04-07 16:16:146054 EXPECT_EQ(gfx::Rect(0, 0, 0, 0),
6055 render_surface1->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386056 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6057
jaydasika0d98ba92015-11-17 05:17:286058 // That said, it should have grown to accomodate the unclipped descendant and
6059 // its own size.
jaydasika6f972de2016-04-07 16:16:146060 EXPECT_EQ(gfx::Rect(-1, 0, 6, 5),
6061 render_surface1->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:386062
6063 // This render surface should clip. It has no unclipped descendants.
jaydasika6f972de2016-04-07 16:16:146064 EXPECT_EQ(gfx::Rect(0, 0, 10, 10),
6065 render_surface2->render_surface()->clip_rect());
[email protected]420fdf6e2013-08-26 20:36:386066 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
weiliangcbb2e8642016-03-04 00:24:426067 EXPECT_FALSE(render_surface2->is_clipped());
[email protected]420fdf6e2013-08-26 20:36:386068
6069 // It also shouldn't have grown to accomodate the clip child.
jaydasika6f972de2016-04-07 16:16:146070 EXPECT_EQ(gfx::Rect(0, 0, 5, 5),
6071 render_surface2->render_surface()->content_rect());
[email protected]420fdf6e2013-08-26 20:36:386072
6073 // Sanity check our num_unclipped_descendants values.
ajuma0641ded2016-05-05 21:28:216074 EXPECT_EQ(1u, render_surface1->test_properties()->num_unclipped_descendants);
6075 EXPECT_EQ(0u, render_surface2->test_properties()->num_unclipped_descendants);
[email protected]420fdf6e2013-08-26 20:36:386076}
6077
weiliangc9ced1592015-11-17 19:04:376078TEST_F(LayerTreeHostCommonTest,
6079 CreateRenderSurfaceWhenFlattenInsideRenderingContext) {
6080 // Verifies that Render Surfaces are created at the edge of rendering context.
6081
weiliangcc154ce22015-12-09 03:39:266082 LayerImpl* root = root_layer();
6083 LayerImpl* child1 = AddChildToRoot<LayerImpl>();
6084 LayerImpl* child2 = AddChild<LayerImpl>(child1);
6085 LayerImpl* child3 = AddChild<LayerImpl>(child2);
6086 root->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376087
6088 const gfx::Transform identity_matrix;
6089 gfx::Point3F transform_origin;
6090 gfx::PointF position;
6091 gfx::Size bounds(100, 100);
6092
6093 SetLayerPropertiesForTesting(root, identity_matrix, transform_origin,
6094 position, bounds, true, false);
6095 SetLayerPropertiesForTesting(child1, identity_matrix, transform_origin,
6096 position, bounds, false, true);
weiliangcc154ce22015-12-09 03:39:266097 child1->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376098 SetLayerPropertiesForTesting(child2, identity_matrix, transform_origin,
6099 position, bounds, true, false);
weiliangcc154ce22015-12-09 03:39:266100 child2->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376101 SetLayerPropertiesForTesting(child3, identity_matrix, transform_origin,
6102 position, bounds, true, false);
weiliangcc154ce22015-12-09 03:39:266103 child3->SetDrawsContent(true);
weiliangc9ced1592015-11-17 19:04:376104
6105 child2->Set3dSortingContextId(1);
6106 child3->Set3dSortingContextId(1);
6107
weiliangcc154ce22015-12-09 03:39:266108 ExecuteCalculateDrawPropertiesWithPropertyTrees(root);
weiliangc9ced1592015-11-17 19:04:376109
6110 // Verify which render surfaces were created.
6111 EXPECT_TRUE(root->has_render_surface());
6112 EXPECT_FALSE(child1->has_render_surface());
6113 EXPECT_TRUE(child2->has_render_surface());
6114 EXPECT_FALSE(child3->has_render_surface());
6115}
6116
[email protected]45948712013-09-27 02:46:486117TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
khushalsagarb64b360d2015-10-21 19:25:166118 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:456119 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:566120 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:166121 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:566122 &task_graph_runner);
weiliangcc154ce22015-12-09 03:39:266123
danakj60bc3bc2016-04-09 00:24:486124 std::unique_ptr<LayerImpl> root =
[email protected]45948712013-09-27 02:46:486125 LayerImpl::Create(host_impl.active_tree(), 12345);
danakj60bc3bc2016-04-09 00:24:486126 std::unique_ptr<LayerImpl> child1 =
[email protected]45948712013-09-27 02:46:486127 LayerImpl::Create(host_impl.active_tree(), 123456);
danakj60bc3bc2016-04-09 00:24:486128 std::unique_ptr<LayerImpl> child2 =
[email protected]45948712013-09-27 02:46:486129 LayerImpl::Create(host_impl.active_tree(), 1234567);
danakj60bc3bc2016-04-09 00:24:486130 std::unique_ptr<LayerImpl> child3 =
[email protected]45948712013-09-27 02:46:486131 LayerImpl::Create(host_impl.active_tree(), 12345678);
6132
6133 gfx::Transform identity_matrix;
[email protected]a2566412014-06-05 03:14:206134 gfx::Point3F transform_origin;
[email protected]45948712013-09-27 02:46:486135 gfx::PointF position;
6136 gfx::Size bounds(100, 100);
awoloszyne83f28c2014-12-22 15:40:006137 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
6138 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:486139 root->SetDrawsContent(true);
6140
6141 // This layer structure normally forces render surface due to preserves3d
6142 // behavior.
awoloszyne83f28c2014-12-22 15:40:006143 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin,
weiliangc9ced1592015-11-17 19:04:376144 position, bounds, false, true, false);
[email protected]45948712013-09-27 02:46:486145 child1->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:006146 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin,
weiliangc9ced1592015-11-17 19:04:376147 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:486148 child2->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:006149 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin,
6150 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:486151 child3->SetDrawsContent(true);
6152
[email protected]a9d4d4f2014-06-19 06:49:286153 child2->Set3dSortingContextId(1);
6154 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:576155
danakja04855a2015-11-18 20:39:106156 child2->AddChild(std::move(child3));
6157 child1->AddChild(std::move(child2));
6158 root->AddChild(std::move(child1));
sunxd71aea3e2016-04-01 23:48:056159 LayerImpl* root_layer = root.get();
6160 root_layer->layer_tree_impl()->SetRootLayer(std::move(root));
[email protected]45948712013-09-27 02:46:486161
6162 {
6163 LayerImplList render_surface_layer_list;
sunxd71aea3e2016-04-01 23:48:056164 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root_layer);
[email protected]45948712013-09-27 02:46:486165 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386166 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:486167 inputs.can_render_to_separate_surface = true;
sunxdb365de02016-04-28 20:32:576168 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:486169
6170 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026171
6172 int count_represents_target_render_surface = 0;
6173 int count_represents_contributing_render_surface = 0;
6174 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516175 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6176 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026177 it != end; ++it) {
6178 if (it.represents_target_render_surface())
6179 count_represents_target_render_surface++;
6180 if (it.represents_contributing_render_surface())
6181 count_represents_contributing_render_surface++;
6182 if (it.represents_itself())
6183 count_represents_itself++;
6184 }
6185
6186 // Two render surfaces.
6187 EXPECT_EQ(2, count_represents_target_render_surface);
6188 // Second render surface contributes to root render surface.
6189 EXPECT_EQ(1, count_represents_contributing_render_surface);
6190 // All 4 layers represent itself.
6191 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486192 }
6193
6194 {
6195 LayerImplList render_surface_layer_list;
[email protected]45948712013-09-27 02:46:486196 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386197 root_layer, root_layer->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:486198 inputs.can_render_to_separate_surface = false;
sunxdb365de02016-04-28 20:32:576199 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]45948712013-09-27 02:46:486200
6201 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026202
6203 int count_represents_target_render_surface = 0;
6204 int count_represents_contributing_render_surface = 0;
6205 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516206 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6207 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026208 it != end; ++it) {
6209 if (it.represents_target_render_surface())
6210 count_represents_target_render_surface++;
6211 if (it.represents_contributing_render_surface())
6212 count_represents_contributing_render_surface++;
6213 if (it.represents_itself())
6214 count_represents_itself++;
6215 }
6216
6217 // Only root layer has a render surface.
6218 EXPECT_EQ(1, count_represents_target_render_surface);
6219 // No layer contributes a render surface to root render surface.
6220 EXPECT_EQ(0, count_represents_contributing_render_surface);
6221 // All 4 layers represent itself.
6222 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486223 }
6224}
6225
[email protected]a9aa60a82013-08-29 04:28:266226TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
enne03b0e9a2015-06-19 00:08:026227 LayerImpl* root = root_layer();
jaydasikae00c8a42016-01-28 20:18:336228 LayerImpl* back_facing = AddChild<LayerImpl>(root);
6229 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
6230 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
6231 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
6232 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
6233 child1->SetDrawsContent(true);
6234 child2->SetDrawsContent(true);
[email protected]a9aa60a82013-08-29 04:28:266235
6236 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026237 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6238 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]56fffdd2014-02-11 19:50:576239 true);
jaydasikae00c8a42016-01-28 20:18:336240 SetLayerPropertiesForTesting(back_facing, identity_transform, gfx::Point3F(),
6241 gfx::PointF(), gfx::Size(50, 50), true, false,
6242 false);
6243 SetLayerPropertiesForTesting(render_surface1, identity_transform,
enne03b0e9a2015-06-19 00:08:026244 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6245 false, true, true);
jaydasikae00c8a42016-01-28 20:18:336246 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6247 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6248 false, true, true);
6249 SetLayerPropertiesForTesting(child1, identity_transform, gfx::Point3F(),
6250 gfx::PointF(), gfx::Size(20, 20), true, false,
6251 false);
6252 SetLayerPropertiesForTesting(child2, identity_transform, gfx::Point3F(),
enne03b0e9a2015-06-19 00:08:026253 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]a9aa60a82013-08-29 04:28:266254 false);
6255
jaydasikaca2605e2016-04-23 02:52:526256 root->test_properties()->should_flatten_transform = false;
[email protected]a9d4d4f2014-06-19 06:49:286257 root->Set3dSortingContextId(1);
jaydasikae00c8a42016-01-28 20:18:336258 back_facing->Set3dSortingContextId(1);
jaydasikaca2605e2016-04-23 02:52:526259 back_facing->test_properties()->should_flatten_transform = false;
jaydasika6b5a32bf2016-04-22 21:56:366260 render_surface1->test_properties()->double_sided = false;
jaydasikae00c8a42016-01-28 20:18:336261 render_surface2->Set3dSortingContextId(2);
jaydasika6b5a32bf2016-04-22 21:56:366262 render_surface2->test_properties()->double_sided = false;
[email protected]a9aa60a82013-08-29 04:28:266263
enne03b0e9a2015-06-19 00:08:026264 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266265
jaydasikae00c8a42016-01-28 20:18:336266 EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id());
6267 EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id());
6268 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6269 EXPECT_EQ(2u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026270 ->at(0)
6271 ->render_surface()
6272 ->layer_list()
6273 .size());
6274 EXPECT_EQ(1u, render_surface_layer_list_impl()
6275 ->at(1)
6276 ->render_surface()
6277 ->layer_list()
6278 .size());
[email protected]a9aa60a82013-08-29 04:28:266279
6280 gfx::Transform rotation_transform = identity_transform;
6281 rotation_transform.RotateAboutXAxis(180.0);
6282
jaydasikae00c8a42016-01-28 20:18:336283 back_facing->SetTransform(rotation_transform);
jaydasika5aa88b82015-11-10 01:48:036284 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]a9aa60a82013-08-29 04:28:266285
enne03b0e9a2015-06-19 00:08:026286 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266287
jaydasikae00c8a42016-01-28 20:18:336288 // render_surface1 is in the same 3d rendering context as back_facing and is
6289 // not double sided, so it should not be in RSLL. render_surface2 is also not
6290 // double-sided, but will still be in RSLL as it's in a different 3d rendering
6291 // context.
6292 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
6293 EXPECT_EQ(1u, render_surface_layer_list_impl()
enne03b0e9a2015-06-19 00:08:026294 ->at(0)
6295 ->render_surface()
6296 ->layer_list()
6297 .size());
[email protected]a9aa60a82013-08-29 04:28:266298}
6299
ajumaaa0d3862015-11-09 22:24:466300TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) {
6301 LayerImpl* root = root_layer();
6302 LayerImpl* child = AddChild<LayerImpl>(root);
6303 LayerImpl* grand_child = AddChild<LayerImpl>(child);
6304 grand_child->SetDrawsContent(true);
6305
jaydasika6b5a32bf2016-04-22 21:56:366306 child->test_properties()->double_sided = false;
ajumaaa0d3862015-11-09 22:24:466307 grand_child->SetUseParentBackfaceVisibility(true);
6308
6309 gfx::Transform identity_transform;
6310 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
jaydasika62bd3dd2016-02-04 18:52:556311 gfx::PointF(), gfx::Size(50, 50), false, false,
ajumaaa0d3862015-11-09 22:24:466312 true);
6313 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
jaydasika62bd3dd2016-02-04 18:52:556314 gfx::PointF(), gfx::Size(30, 30), false, false,
ajumaaa0d3862015-11-09 22:24:466315 false);
6316 SetLayerPropertiesForTesting(grand_child, identity_transform, gfx::Point3F(),
jaydasika62bd3dd2016-02-04 18:52:556317 gfx::PointF(), gfx::Size(20, 20), false, false,
ajumaaa0d3862015-11-09 22:24:466318 false);
6319
6320 ExecuteCalculateDrawProperties(root);
6321
6322 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6323 EXPECT_EQ(grand_child, render_surface_layer_list_impl()
6324 ->at(0)
6325 ->render_surface()
6326 ->layer_list()[0]);
jaydasika62bd3dd2016-02-04 18:52:556327
6328 // As all layers have identity transform, we shouldn't check for backface
6329 // visibility.
6330 EXPECT_FALSE(root->should_check_backface_visibility());
6331 EXPECT_FALSE(child->should_check_backface_visibility());
6332 EXPECT_FALSE(grand_child->should_check_backface_visibility());
6333 // As there are no 3d rendering contexts, all layers should use their local
6334 // transform for backface visibility.
6335 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6336 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6337 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6338
ajumaaa0d3862015-11-09 22:24:466339 gfx::Transform rotation_transform = identity_transform;
6340 rotation_transform.RotateAboutXAxis(180.0);
6341
6342 child->SetTransform(rotation_transform);
jaydasika62bd3dd2016-02-04 18:52:556343 child->Set3dSortingContextId(1);
6344 grand_child->Set3dSortingContextId(1);
ajumaaa0d3862015-11-09 22:24:466345 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6346
6347 ExecuteCalculateDrawProperties(root);
6348 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6349 EXPECT_EQ(0u, render_surface_layer_list_impl()
6350 ->at(0)
6351 ->render_surface()
6352 ->layer_list()
6353 .size());
jaydasika62bd3dd2016-02-04 18:52:556354
6355 // We should check for backface visibilty of child as it has a rotation
6356 // transform. We should also check for grand_child as it uses the backface
6357 // visibility of its parent.
6358 EXPECT_FALSE(root->should_check_backface_visibility());
6359 EXPECT_TRUE(child->should_check_backface_visibility());
6360 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6361 // child uses its local transform for backface visibility as it is the root of
6362 // a 3d rendering context. grand_child is in a 3d rendering context and is not
6363 // the root, but it derives its backface visibility from its parent which uses
6364 // its local transform.
6365 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6366 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6367 EXPECT_TRUE(grand_child->use_local_transform_for_backface_visibility());
6368
6369 grand_child->SetUseParentBackfaceVisibility(false);
jaydasika6b5a32bf2016-04-22 21:56:366370 grand_child->test_properties()->double_sided = false;
jaydasika62bd3dd2016-02-04 18:52:556371 grand_child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6372
6373 ExecuteCalculateDrawProperties(root);
6374 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6375 EXPECT_EQ(0u, render_surface_layer_list_impl()
6376 ->at(0)
6377 ->render_surface()
6378 ->layer_list()
6379 .size());
6380
6381 // We should check the backface visibility of child as it has a rotation
6382 // transform and for grand_child as it is in a 3d rendering context and not
6383 // the root of it.
6384 EXPECT_FALSE(root->should_check_backface_visibility());
6385 EXPECT_TRUE(child->should_check_backface_visibility());
6386 EXPECT_TRUE(grand_child->should_check_backface_visibility());
6387 // grand_child is in an existing 3d rendering context, so it should not use
6388 // local transform for backface visibility.
6389 EXPECT_TRUE(root->use_local_transform_for_backface_visibility());
6390 EXPECT_TRUE(child->use_local_transform_for_backface_visibility());
6391 EXPECT_FALSE(grand_child->use_local_transform_for_backface_visibility());
ajumaaa0d3862015-11-09 22:24:466392}
6393
sunxd59dd7da2016-05-19 20:07:476394TEST_F(LayerTreeHostCommonTest, TransformAnimationUpdatesBackfaceVisibility) {
6395 LayerImpl* root = root_layer();
6396 LayerImpl* back_facing = AddChild<LayerImpl>(root);
6397 LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing);
6398 LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing);
6399
6400 gfx::Transform identity_transform;
6401 gfx::Transform rotate_about_y;
6402 rotate_about_y.RotateAboutYAxis(180.0);
6403 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6404 gfx::PointF(), gfx::Size(50, 50), false, true,
6405 true);
6406 SetLayerPropertiesForTesting(back_facing, rotate_about_y, gfx::Point3F(),
6407 gfx::PointF(), gfx::Size(50, 50), false, true,
6408 false);
6409 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6410 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6411 false, true, true);
6412 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6413 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6414 false, true, true);
6415
6416 render_surface1->test_properties()->double_sided = false;
6417 render_surface2->test_properties()->double_sided = false;
6418
6419 ExecuteCalculateDrawProperties(root);
6420
6421 const EffectTree& tree =
6422 root->layer_tree_impl()->property_trees()->effect_tree;
6423 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
6424 ->data.hidden_by_backface_visibility);
6425 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
6426 ->data.hidden_by_backface_visibility);
6427
6428 back_facing->OnTransformAnimated(identity_transform);
6429 render_surface2->OnTransformAnimated(rotate_about_y);
6430 ExecuteCalculateDrawProperties(root);
6431 EXPECT_FALSE(tree.Node(render_surface1->effect_tree_index())
6432 ->data.hidden_by_backface_visibility);
6433 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
6434 ->data.hidden_by_backface_visibility);
6435
6436 render_surface1->OnTransformAnimated(rotate_about_y);
6437 ExecuteCalculateDrawProperties(root);
6438 EXPECT_TRUE(tree.Node(render_surface1->effect_tree_index())
6439 ->data.hidden_by_backface_visibility);
6440 EXPECT_TRUE(tree.Node(render_surface2->effect_tree_index())
6441 ->data.hidden_by_backface_visibility);
6442}
6443
[email protected]995708c52013-10-17 20:52:596444TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
6445 // Checks that the simple case (being clipped by a scroll parent that would
6446 // have been processed before you anyhow) results in the right clips.
6447 //
6448 // + root
6449 // + scroll_parent_border
6450 // | + scroll_parent_clip
6451 // | + scroll_parent
6452 // + scroll_child
6453 //
enne085b48a2015-08-18 17:54:486454 LayerImpl* root = root_layer();
6455 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
6456 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6457 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6458 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596459
enne085b48a2015-08-18 17:54:486460 scroll_parent->SetDrawsContent(true);
6461 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596462 scroll_parent_clip->SetMasksToBounds(true);
6463
jaydasika1c0a27d42016-04-28 01:54:566464 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakj60bc3bc2016-04-09 00:24:486465 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
6466 new std::set<LayerImpl*>);
enne085b48a2015-08-18 17:54:486467 scroll_children->insert(scroll_child);
jaydasika1c0a27d42016-04-28 01:54:566468 scroll_parent->test_properties()->scroll_children.reset(
6469 scroll_children.release());
[email protected]995708c52013-10-17 20:52:596470
6471 gfx::Transform identity_transform;
enne085b48a2015-08-18 17:54:486472 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6473 gfx::PointF(), gfx::Size(50, 50), true, false,
6474 true);
6475 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6476 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6477 true, false, false);
6478 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6479 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6480 true, false, false);
6481 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6482 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6483 true, false, false);
6484 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6485 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596486 false);
6487
enne085b48a2015-08-18 17:54:486488 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596489
6490 EXPECT_TRUE(root->render_surface());
6491
jaydasika6f972de2016-04-07 16:16:146492 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596493 EXPECT_TRUE(scroll_child->is_clipped());
6494}
6495
jaydasika8ccff3d2016-01-20 19:51:306496TEST_F(LayerTreeHostCommonTest, ScrollChildAndScrollParentDifferentTargets) {
6497 // Tests the computation of draw transform for the scroll child when its
6498 // target is different from its scroll parent's target.
6499 LayerImpl* root = root_layer();
6500 LayerImpl* scroll_child_target = AddChildToRoot<LayerImpl>();
6501 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_child_target);
6502 LayerImpl* scroll_parent_target = AddChild<LayerImpl>(scroll_child_target);
6503 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_target);
6504
6505 scroll_parent->SetDrawsContent(true);
6506 scroll_child->SetDrawsContent(true);
6507
jaydasika1c0a27d42016-04-28 01:54:566508 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakj60bc3bc2016-04-09 00:24:486509 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
6510 new std::set<LayerImpl*>);
jaydasika8ccff3d2016-01-20 19:51:306511 scroll_children->insert(scroll_child);
jaydasika1c0a27d42016-04-28 01:54:566512 scroll_parent->test_properties()->scroll_children.reset(
6513 scroll_children.release());
jaydasika8ccff3d2016-01-20 19:51:306514
6515 gfx::Transform identity_transform;
6516 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6517 gfx::PointF(), gfx::Size(50, 50), true, false,
6518 true);
6519 SetLayerPropertiesForTesting(scroll_child_target, identity_transform,
6520 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6521 true, false, true);
6522 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6523 gfx::PointF(), gfx::Size(50, 50), true, false,
6524 false);
6525 SetLayerPropertiesForTesting(scroll_parent_target, identity_transform,
6526 gfx::Point3F(), gfx::PointF(10, 10),
6527 gfx::Size(50, 50), true, false, true);
6528 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6529 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
jaydasika2489a442016-01-29 02:26:006530 true, false, false);
6531 scroll_parent_target->SetMasksToBounds(true);
jaydasika8ccff3d2016-01-20 19:51:306532
jaydasika2489a442016-01-29 02:26:006533 float device_scale_factor = 1.5f;
6534 LayerImplList render_surface_layer_list_impl;
jaydasika2489a442016-01-29 02:26:006535 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386536 root, root->bounds(), identity_transform,
6537 &render_surface_layer_list_impl);
jaydasika2489a442016-01-29 02:26:006538 inputs.device_scale_factor = device_scale_factor;
sunxdb365de02016-04-28 20:32:576539 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
jaydasika2489a442016-01-29 02:26:006540
weiliangc1da3fb892016-03-14 20:23:526541 EXPECT_EQ(scroll_child->effect_tree_index(),
6542 scroll_child_target->effect_tree_index());
jaydasika2489a442016-01-29 02:26:006543 EXPECT_EQ(scroll_child->visible_layer_rect(), gfx::Rect(10, 10, 40, 40));
6544 EXPECT_EQ(scroll_child->clip_rect(), gfx::Rect(15, 15, 75, 75));
6545 gfx::Transform scale;
6546 scale.Scale(1.5f, 1.5f);
6547 EXPECT_EQ(scroll_child->DrawTransform(), scale);
jaydasika8ccff3d2016-01-20 19:51:306548}
6549
[email protected]08bdf1b2014-04-16 23:23:296550TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
enneca33fed2015-07-27 18:22:196551 LayerImpl* root = root_layer();
6552 root->SetDrawsContent(true);
6553 LayerImpl* parent = AddChildToRoot<LayerImpl>();
6554 parent->SetDrawsContent(true);
6555 LayerImpl* child = AddChild<LayerImpl>(parent);
6556 child->SetDrawsContent(true);
[email protected]08bdf1b2014-04-16 23:23:296557
6558 gfx::Transform identity_transform;
enneca33fed2015-07-27 18:22:196559 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6560 gfx::PointF(), gfx::Size(50, 50), true, true,
[email protected]08bdf1b2014-04-16 23:23:296561 true);
enneca33fed2015-07-27 18:22:196562 SetLayerPropertiesForTesting(parent, identity_transform, gfx::Point3F(),
6563 gfx::PointF(), gfx::Size(30, 30), true, true,
[email protected]08bdf1b2014-04-16 23:23:296564 true);
enneca33fed2015-07-27 18:22:196565 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6566 gfx::PointF(), gfx::Size(20, 20), true, true,
[email protected]08bdf1b2014-04-16 23:23:296567 true);
[email protected]08bdf1b2014-04-16 23:23:296568
enneca33fed2015-07-27 18:22:196569 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296570
enneca33fed2015-07-27 18:22:196571 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296572
6573 gfx::Transform singular_transform;
6574 singular_transform.Scale3d(
6575 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6576
6577 child->SetTransform(singular_transform);
6578
sunxd71aea3e2016-04-01 23:48:056579 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196580 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296581
enneca33fed2015-07-27 18:22:196582 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296583
6584 // Ensure that the entire subtree under a layer with singular transform does
6585 // not get rendered.
6586 parent->SetTransform(singular_transform);
6587 child->SetTransform(identity_transform);
6588
sunxd71aea3e2016-04-01 23:48:056589 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneca33fed2015-07-27 18:22:196590 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296591
enneca33fed2015-07-27 18:22:196592 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296593}
6594
[email protected]995708c52013-10-17 20:52:596595TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
6596 // Checks that clipping by a scroll parent that follows you in paint order
6597 // still results in correct clipping.
6598 //
6599 // + root
[email protected]995708c52013-10-17 20:52:596600 // + scroll_parent_border
6601 // + scroll_parent_clip
6602 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026603 // + scroll_child
[email protected]995708c52013-10-17 20:52:596604 //
enne03b0e9a2015-06-19 00:08:026605 LayerImpl* root = root_layer();
6606 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6607 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6608 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6609 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596610
enne03b0e9a2015-06-19 00:08:026611 scroll_parent->SetDrawsContent(true);
6612 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596613
6614 scroll_parent_clip->SetMasksToBounds(true);
6615
jaydasika1c0a27d42016-04-28 01:54:566616 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakj60bc3bc2016-04-09 00:24:486617 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
6618 new std::set<LayerImpl*>);
ajuma9af2e92b2015-06-29 22:26:386619 scroll_children->insert(scroll_child);
jaydasika1c0a27d42016-04-28 01:54:566620 scroll_parent->test_properties()->scroll_children.reset(
6621 scroll_children.release());
[email protected]995708c52013-10-17 20:52:596622
6623 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026624 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6625 gfx::PointF(), gfx::Size(50, 50), true, false,
6626 true);
6627 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6628 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6629 true, false, false);
6630 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6631 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6632 true, false, false);
6633 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6634 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6635 true, false, false);
6636 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6637 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596638 false);
6639
enne03b0e9a2015-06-19 00:08:026640 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596641
6642 EXPECT_TRUE(root->render_surface());
6643
jaydasika6f972de2016-04-07 16:16:146644 EXPECT_EQ(gfx::Rect(0, 0, 30, 30), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596645 EXPECT_TRUE(scroll_child->is_clipped());
6646}
6647
6648TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
6649 // Checks that clipping by a scroll parent and scroll grandparent that follow
6650 // you in paint order still results in correct clipping.
6651 //
6652 // + root
6653 // + scroll_child
6654 // + scroll_parent_border
6655 // | + scroll_parent_clip
6656 // | + scroll_parent
6657 // + scroll_grandparent_border
6658 // + scroll_grandparent_clip
6659 // + scroll_grandparent
6660 //
enne03b0e9a2015-06-19 00:08:026661 LayerImpl* root = root_layer();
6662 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6663 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6664 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6665 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6666 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6667 LayerImpl* scroll_grandparent_clip =
6668 AddChild<LayerImpl>(scroll_grandparent_border);
6669 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:596670
enne03b0e9a2015-06-19 00:08:026671 scroll_parent->SetDrawsContent(true);
6672 scroll_grandparent->SetDrawsContent(true);
6673 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596674
6675 scroll_parent_clip->SetMasksToBounds(true);
6676 scroll_grandparent_clip->SetMasksToBounds(true);
6677
jaydasika1c0a27d42016-04-28 01:54:566678 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakj60bc3bc2016-04-09 00:24:486679 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
6680 new std::set<LayerImpl*>);
ajuma9af2e92b2015-06-29 22:26:386681 scroll_children->insert(scroll_child);
jaydasika1c0a27d42016-04-28 01:54:566682 scroll_parent->test_properties()->scroll_children.reset(
6683 scroll_children.release());
ajuma9af2e92b2015-06-29 22:26:386684
jaydasika1c0a27d42016-04-28 01:54:566685 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
ajuma9af2e92b2015-06-29 22:26:386686 scroll_children.reset(new std::set<LayerImpl*>);
6687 scroll_children->insert(scroll_parent_border);
jaydasika1c0a27d42016-04-28 01:54:566688 scroll_grandparent->test_properties()->scroll_children.reset(
6689 scroll_children.release());
[email protected]995708c52013-10-17 20:52:596690
6691 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026692 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6693 gfx::PointF(), gfx::Size(50, 50), true, false,
6694 true);
6695 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6696 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6697 true, false, false);
6698 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6699 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6700 true, false, false);
6701 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6702 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6703 true, false, false);
6704 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6705 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6706 true, false, false);
6707 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6708 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6709 true, false, false);
6710 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6711 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6712 true, false, false);
6713 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6714 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596715 false);
6716
enne03b0e9a2015-06-19 00:08:026717 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596718
6719 EXPECT_TRUE(root->render_surface());
6720
jaydasika6f972de2016-04-07 16:16:146721 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596722 EXPECT_TRUE(scroll_child->is_clipped());
6723
6724 // Despite the fact that we visited the above layers out of order to get the
6725 // correct clip, the layer lists should be unaffected.
6726 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
enne03b0e9a2015-06-19 00:08:026727 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
6728 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
6729 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
[email protected]995708c52013-10-17 20:52:596730}
6731
6732TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
6733 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:226734 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:596735 // + root
6736 // + scroll_child
6737 // + scroll_parent_border
6738 // + scroll_parent_clip
6739 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026740 // + render_surface2
[email protected]995708c52013-10-17 20:52:596741 // + scroll_grandparent_border
6742 // + scroll_grandparent_clip
6743 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:026744 // + render_surface1
[email protected]995708c52013-10-17 20:52:596745 //
enne03b0e9a2015-06-19 00:08:026746 LayerImpl* root = root_layer();
6747 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596748
enne03b0e9a2015-06-19 00:08:026749 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6750 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596751
enne03b0e9a2015-06-19 00:08:026752 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6753 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6754 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6755 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
6756 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6757 LayerImpl* scroll_grandparent_clip =
6758 AddChild<LayerImpl>(scroll_grandparent_border);
6759 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6760 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:596761
enne03b0e9a2015-06-19 00:08:026762 scroll_parent->SetDrawsContent(true);
6763 render_surface1->SetDrawsContent(true);
6764 scroll_grandparent->SetDrawsContent(true);
6765 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596766
6767 scroll_parent_clip->SetMasksToBounds(true);
6768 scroll_grandparent_clip->SetMasksToBounds(true);
6769
jaydasika1c0a27d42016-04-28 01:54:566770 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakj60bc3bc2016-04-09 00:24:486771 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
6772 new std::set<LayerImpl*>);
ajuma9af2e92b2015-06-29 22:26:386773 scroll_children->insert(scroll_child);
jaydasika1c0a27d42016-04-28 01:54:566774 scroll_parent->test_properties()->scroll_children.reset(
6775 scroll_children.release());
ajuma9af2e92b2015-06-29 22:26:386776
jaydasika1c0a27d42016-04-28 01:54:566777 scroll_parent_border->test_properties()->scroll_parent = scroll_grandparent;
ajuma9af2e92b2015-06-29 22:26:386778 scroll_children.reset(new std::set<LayerImpl*>);
6779 scroll_children->insert(scroll_parent_border);
jaydasika1c0a27d42016-04-28 01:54:566780 scroll_grandparent->test_properties()->scroll_children.reset(
6781 scroll_children.release());
[email protected]995708c52013-10-17 20:52:596782
6783 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026784 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6785 gfx::PointF(), gfx::Size(50, 50), true, false,
6786 true);
6787 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6788 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6789 true, false, false);
6790 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6791 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6792 true, false, false);
6793 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6794 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6795 true, false, false);
6796 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6797 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6798 true, false, true);
6799 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6800 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6801 true, false, false);
6802 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6803 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6804 true, false, false);
6805 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6806 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6807 true, false, false);
6808 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6809 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6810 true, false, true);
6811 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6812 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596813 false);
6814
enne03b0e9a2015-06-19 00:08:026815 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596816
6817 EXPECT_TRUE(root->render_surface());
6818
jaydasika6f972de2016-04-07 16:16:146819 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), scroll_child->clip_rect());
[email protected]995708c52013-10-17 20:52:596820 EXPECT_TRUE(scroll_child->is_clipped());
6821
6822 // Despite the fact that we had to process the layers out of order to get the
6823 // right clip, our render_surface_layer_list's order should be unaffected.
enne03b0e9a2015-06-19 00:08:026824 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6825 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
6826 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
6827 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
6828 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6829 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6830 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:596831}
6832
ajuma0b10f942015-03-21 07:45:536833TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
6834 // Ensures that when we have a render surface between a fixed position layer
6835 // and its container, we compute the fixed position layer's draw transform
6836 // with respect to that intervening render surface, not with respect to its
6837 // container's render target.
6838 //
6839 // + root
6840 // + render_surface
6841 // + fixed
ajuma737b2702015-05-06 01:18:376842 // + child
ajuma0b10f942015-03-21 07:45:536843 //
sunxdfd920f3f2016-04-05 16:17:516844 LayerImpl* root = root_layer();
6845 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6846 LayerImpl* fixed = AddChild<LayerImpl>(render_surface);
6847 LayerImpl* child = AddChild<LayerImpl>(fixed);
ajuma0b10f942015-03-21 07:45:536848
sunxdfd920f3f2016-04-05 16:17:516849 render_surface->SetDrawsContent(true);
6850 fixed->SetDrawsContent(true);
6851 child->SetDrawsContent(true);
ajuma0b10f942015-03-21 07:45:536852
jaydasika6b5a32bf2016-04-22 21:56:366853 render_surface->test_properties()->force_render_surface = true;
jaydasikaca2605e2016-04-23 02:52:526854 root->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0b10f942015-03-21 07:45:536855
6856 LayerPositionConstraint constraint;
6857 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526858 fixed->test_properties()->position_constraint = constraint;
ajuma0b10f942015-03-21 07:45:536859
sunxdfd920f3f2016-04-05 16:17:516860 SetLayerPropertiesForTesting(root, gfx::Transform(), gfx::Point3F(),
ajuma0b10f942015-03-21 07:45:536861 gfx::PointF(), gfx::Size(50, 50), true, false);
sunxdfd920f3f2016-04-05 16:17:516862 SetLayerPropertiesForTesting(render_surface, gfx::Transform(), gfx::Point3F(),
6863 gfx::PointF(7.f, 9.f), gfx::Size(50, 50), true,
6864 false);
6865 SetLayerPropertiesForTesting(fixed, gfx::Transform(), gfx::Point3F(),
ajuma0b10f942015-03-21 07:45:536866 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true,
6867 false);
sunxdfd920f3f2016-04-05 16:17:516868 SetLayerPropertiesForTesting(child, gfx::Transform(), gfx::Point3F(),
ajuma737b2702015-05-06 01:18:376869 gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true,
6870 false);
ajuma0b10f942015-03-21 07:45:536871
sunxdfd920f3f2016-04-05 16:17:516872 ExecuteCalculateDrawProperties(root);
ajuma0b10f942015-03-21 07:45:536873
sunxdfd920f3f2016-04-05 16:17:516874 TransformTree& tree =
6875 host_impl()->active_tree()->property_trees()->transform_tree;
ennef6903532015-08-18 05:10:156876
ajuma737b2702015-05-06 01:18:376877 gfx::Transform expected_fixed_draw_transform;
6878 expected_fixed_draw_transform.Translate(10.f, 15.f);
ennef6903532015-08-18 05:10:156879 EXPECT_EQ(expected_fixed_draw_transform,
sunxdfd920f3f2016-04-05 16:17:516880 draw_property_utils::DrawTransform(fixed, tree));
ajuma0b10f942015-03-21 07:45:536881
ajuma737b2702015-05-06 01:18:376882 gfx::Transform expected_fixed_screen_space_transform;
6883 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
6884 EXPECT_EQ(expected_fixed_screen_space_transform,
sunxdfd920f3f2016-04-05 16:17:516885 draw_property_utils::ScreenSpaceTransform(fixed, tree));
ajuma737b2702015-05-06 01:18:376886
6887 gfx::Transform expected_child_draw_transform;
6888 expected_child_draw_transform.Translate(11.f, 17.f);
ennef6903532015-08-18 05:10:156889 EXPECT_EQ(expected_child_draw_transform,
sunxdfd920f3f2016-04-05 16:17:516890 draw_property_utils::DrawTransform(child, tree));
ajuma737b2702015-05-06 01:18:376891
6892 gfx::Transform expected_child_screen_space_transform;
6893 expected_child_screen_space_transform.Translate(18.f, 26.f);
6894 EXPECT_EQ(expected_child_screen_space_transform,
sunxdfd920f3f2016-04-05 16:17:516895 draw_property_utils::ScreenSpaceTransform(child, tree));
ajuma0b10f942015-03-21 07:45:536896}
6897
[email protected]d81752b2013-10-25 08:32:236898TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
6899 // This test verifies that a scrolling layer that gets snapped to
6900 // integer coordinates doesn't move a fixed position child.
6901 //
6902 // + root
6903 // + container
6904 // + scroller
6905 // + fixed
6906 //
khushalsagarb64b360d2015-10-21 19:25:166907 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:456908 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:566909 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:166910 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:566911 &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:236912 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:486913 std::unique_ptr<LayerImpl> root_ptr =
sunxdb7e79432016-03-09 21:13:426914 LayerImpl::Create(host_impl.active_tree(), 1);
6915 LayerImpl* root = root_ptr.get();
danakj60bc3bc2016-04-09 00:24:486916 std::unique_ptr<LayerImpl> container =
[email protected]d81752b2013-10-25 08:32:236917 LayerImpl::Create(host_impl.active_tree(), 2);
6918 LayerImpl* container_layer = container.get();
danakj60bc3bc2016-04-09 00:24:486919 std::unique_ptr<LayerImpl> scroller =
[email protected]d81752b2013-10-25 08:32:236920 LayerImpl::Create(host_impl.active_tree(), 3);
6921 LayerImpl* scroll_layer = scroller.get();
danakj60bc3bc2016-04-09 00:24:486922 std::unique_ptr<LayerImpl> fixed =
6923 LayerImpl::Create(host_impl.active_tree(), 4);
[email protected]d81752b2013-10-25 08:32:236924 LayerImpl* fixed_layer = fixed.get();
6925
jaydasikaca2605e2016-04-23 02:52:526926 container->test_properties()->is_container_for_fixed_position_layers = true;
[email protected]d81752b2013-10-25 08:32:236927
6928 LayerPositionConstraint constraint;
6929 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:526930 fixed->test_properties()->position_constraint = constraint;
[email protected]d81752b2013-10-25 08:32:236931
[email protected]adeda572014-01-31 00:49:476932 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:236933
6934 gfx::Transform identity_transform;
6935 gfx::Transform container_transform;
6936 container_transform.Translate3d(10.0, 20.0, 0.0);
6937 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
6938
sunxdb7e79432016-03-09 21:13:426939 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
awoloszyne83f28c2014-12-22 15:40:006940 gfx::PointF(), gfx::Size(50, 50), true, false,
6941 true);
6942 SetLayerPropertiesForTesting(container.get(), container_transform,
6943 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6944 true, false, false);
6945 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
6946 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6947 true, false, false);
6948 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
6949 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]d81752b2013-10-25 08:32:236950 false);
6951
jaydasika0d98ba92015-11-17 05:17:286952 root->SetDrawsContent(true);
6953 container->SetDrawsContent(true);
6954 scroller->SetDrawsContent(true);
6955 fixed->SetDrawsContent(true);
danakja04855a2015-11-18 20:39:106956 scroller->AddChild(std::move(fixed));
6957 container->AddChild(std::move(scroller));
6958 root->AddChild(std::move(container));
[email protected]d81752b2013-10-25 08:32:236959
6960 // Rounded to integers already.
6961 {
sunxdb7e79432016-03-09 21:13:426962 root->layer_tree_impl()->SetRootLayer(std::move(root_ptr));
6963 root->layer_tree_impl()->BuildPropertyTreesForTesting();
6964
[email protected]d81752b2013-10-25 08:32:236965 gfx::Vector2dF scroll_delta(3.0, 5.0);
sunxdb7e79432016-03-09 21:13:426966 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236967
6968 LayerImplList render_surface_layer_list;
[email protected]d81752b2013-10-25 08:32:236969 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386970 root, root->bounds(), &render_surface_layer_list);
sunxdb7e79432016-03-09 21:13:426971 root->layer_tree_impl()
6972 ->property_trees()
6973 ->transform_tree.set_source_to_parent_updates_allowed(false);
sunxdb365de02016-04-28 20:32:576974 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:236975
6976 EXPECT_TRANSFORMATION_MATRIX_EQ(
6977 container_layer->draw_properties().screen_space_transform,
6978 fixed_layer->draw_properties().screen_space_transform);
6979 EXPECT_VECTOR_EQ(
6980 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6981 container_offset);
6982 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6983 .screen_space_transform.To2dTranslation(),
6984 container_offset - scroll_delta);
6985 }
6986
6987 // Scroll delta requiring rounding.
6988 {
sunxdb7e79432016-03-09 21:13:426989 root->layer_tree_impl()->BuildPropertyTreesForTesting();
6990
[email protected]d81752b2013-10-25 08:32:236991 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
sunxdb7e79432016-03-09 21:13:426992 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]d81752b2013-10-25 08:32:236993
6994 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
6995
6996 LayerImplList render_surface_layer_list;
[email protected]d81752b2013-10-25 08:32:236997 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:386998 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:576999 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]d81752b2013-10-25 08:32:237000
7001 EXPECT_TRANSFORMATION_MATRIX_EQ(
7002 container_layer->draw_properties().screen_space_transform,
7003 fixed_layer->draw_properties().screen_space_transform);
7004 EXPECT_VECTOR_EQ(
7005 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7006 container_offset);
7007 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7008 .screen_space_transform.To2dTranslation(),
7009 container_offset - rounded_scroll_delta);
7010 }
[email protected]cf15ad7b2014-04-02 03:59:267011
7012 // Scale is applied earlier in the tree.
7013 {
sunxdb7e79432016-03-09 21:13:427014 SetScrollOffsetDelta(scroll_layer, gfx::Vector2dF());
[email protected]cf15ad7b2014-04-02 03:59:267015 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:287016 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
[email protected]cf15ad7b2014-04-02 03:59:267017 container_layer->SetTransform(scaled_container_transform);
jaydasika0d98ba92015-11-17 05:17:287018 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxdb7e79432016-03-09 21:13:427019 root->layer_tree_impl()->BuildPropertyTreesForTesting();
[email protected]cf15ad7b2014-04-02 03:59:267020
7021 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
sunxdb7e79432016-03-09 21:13:427022 SetScrollOffsetDelta(scroll_layer, scroll_delta);
[email protected]cf15ad7b2014-04-02 03:59:267023
7024 LayerImplList render_surface_layer_list;
[email protected]cf15ad7b2014-04-02 03:59:267025 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:387026 root, root->bounds(), &render_surface_layer_list);
sunxdb365de02016-04-28 20:32:577027 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]cf15ad7b2014-04-02 03:59:267028
7029 EXPECT_TRANSFORMATION_MATRIX_EQ(
7030 container_layer->draw_properties().screen_space_transform,
7031 fixed_layer->draw_properties().screen_space_transform);
7032 EXPECT_VECTOR_EQ(
7033 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7034 container_offset);
7035
7036 container_layer->SetTransform(container_transform);
7037 }
[email protected]d81752b2013-10-25 08:32:237038}
7039
miletus2c78036b2015-01-29 20:52:377040TEST_F(LayerTreeHostCommonTest,
ajuma5e8e40d2015-07-31 01:50:507041 ScrollSnappingWithAnimatedScreenSpaceTransform) {
7042 // This test verifies that a scrolling layer whose screen space transform is
7043 // animating doesn't get snapped to integer coordinates.
7044 //
7045 // + root
7046 // + animated layer
7047 // + surface
7048 // + container
7049 // + scroller
7050 //
7051 LayerImpl* root = root_layer();
7052 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
7053 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
7054 LayerImpl* container = AddChild<LayerImpl>(surface);
7055 LayerImpl* scroller = AddChild<LayerImpl>(container);
7056 scroller->SetScrollClipLayer(container->id());
7057 scroller->SetDrawsContent(true);
7058
7059 gfx::Transform identity_transform;
7060 gfx::Transform start_scale;
7061 start_scale.Scale(1.5f, 1.5f);
7062 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
7063 gfx::PointF(), gfx::Size(50, 50), true, false,
7064 true);
7065 SetLayerPropertiesForTesting(animated_layer, start_scale, gfx::Point3F(),
7066 gfx::PointF(), gfx::Size(50, 50), true, false,
7067 false);
7068 SetLayerPropertiesForTesting(surface, identity_transform, gfx::Point3F(),
7069 gfx::PointF(), gfx::Size(50, 50), true, false,
7070 true);
7071 SetLayerPropertiesForTesting(container, identity_transform, gfx::Point3F(),
7072 gfx::PointF(), gfx::Size(50, 50), true, false,
7073 false);
7074 SetLayerPropertiesForTesting(scroller, identity_transform, gfx::Point3F(),
7075 gfx::PointF(), gfx::Size(100, 100), true, false,
7076 false);
7077
7078 gfx::Transform end_scale;
7079 end_scale.Scale(2.f, 2.f);
7080 TransformOperations start_operations;
7081 start_operations.AppendMatrix(start_scale);
7082 TransformOperations end_operations;
7083 end_operations.AppendMatrix(end_scale);
loyso9556c732016-03-11 07:54:587084 AddAnimatedTransformToLayerWithPlayer(animated_layer->id(), timeline_impl(),
7085 1.0, start_operations, end_operations);
ajuma5e8e40d2015-07-31 01:50:507086 gfx::Vector2dF scroll_delta(5.f, 9.f);
sunxdb7e79432016-03-09 21:13:427087 SetScrollOffsetDelta(scroller, scroll_delta);
ajuma5e8e40d2015-07-31 01:50:507088
7089 ExecuteCalculateDrawProperties(root);
7090
7091 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
7092 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:447093 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:507094}
7095
[email protected]1c3626e2014-04-09 17:49:227096class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7097 public:
danakj60bc3bc2016-04-09 00:24:487098 static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
[email protected]1c3626e2014-04-09 17:49:227099 LayerTreeImpl* tree_impl,
7100 int id) {
danakj60bc3bc2016-04-09 00:24:487101 return base::WrapUnique(
[email protected]1c3626e2014-04-09 17:49:227102 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7103 }
7104
dcheng716bedf2014-10-21 09:51:087105 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227106
[email protected]1c3626e2014-04-09 17:49:227107 private:
7108 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7109 int id)
[email protected]a57cb8b12014-06-13 18:15:377110 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227111 SetDrawsContent(true);
7112 }
[email protected]1c3626e2014-04-09 17:49:227113};
7114
7115TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:167116 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]1c3626e2014-04-09 17:49:227117 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567118 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:487119 LayerTreeSettings settings = host()->settings();
ajumab4a846f22015-08-24 19:13:447120 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167121 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7122 &shared_bitmap_manager, &task_graph_runner);
[email protected]1c3626e2014-04-09 17:49:227123 gfx::Transform identity_matrix;
danakj60bc3bc2016-04-09 00:24:487124 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
[email protected]1c3626e2014-04-09 17:49:227125 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487126 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
[email protected]1c3626e2014-04-09 17:49:227127 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
danakj60bc3bc2016-04-09 00:24:487128 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> child =
[email protected]1c3626e2014-04-09 17:49:227129 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
danakj60bc3bc2016-04-09 00:24:487130 std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
[email protected]1c3626e2014-04-09 17:49:227131 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7132
7133 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7134 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7135 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
jaydasika2411692c2016-03-23 01:56:097136 AnimationScaleFactorTrackingLayerImpl* grand_parent_raw = grand_parent.get();
[email protected]1c3626e2014-04-09 17:49:227137
danakja04855a2015-11-18 20:39:107138 child->AddChild(std::move(grand_child));
7139 parent->AddChild(std::move(child));
7140 grand_parent->AddChild(std::move(parent));
[email protected]1c3626e2014-04-09 17:49:227141
jaydasika2411692c2016-03-23 01:56:097142 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
awoloszyne83f28c2014-12-22 15:40:007143 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7144 true, false, true);
7145 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7146 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227147 false);
awoloszyne83f28c2014-12-22 15:40:007148 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7149 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227150 false);
awoloszyne83f28c2014-12-22 15:40:007151
7152 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
7153 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227154 false);
7155
sunxd71aea3e2016-04-01 23:48:057156 host_impl.active_tree()->SetRootLayer(std::move(grand_parent));
7157
jaydasika2411692c2016-03-23 01:56:097158 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227159
7160 // No layers have animations.
jaydasika2411692c2016-03-23 01:56:097161 EXPECT_EQ(
7162 0.f,
7163 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377164 EXPECT_EQ(0.f,
7165 parent_raw->draw_properties().maximum_animation_contents_scale);
7166 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7167 EXPECT_EQ(
7168 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227169
jaydasika2411692c2016-03-23 01:56:097170 EXPECT_EQ(
7171 0.f,
7172 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037173 EXPECT_EQ(0.f,
7174 parent_raw->draw_properties().starting_animation_contents_scale);
7175 EXPECT_EQ(0.f,
7176 child_raw->draw_properties().starting_animation_contents_scale);
7177 EXPECT_EQ(
7178 0.f,
7179 grand_child_raw->draw_properties().starting_animation_contents_scale);
7180
[email protected]1c3626e2014-04-09 17:49:227181 TransformOperations translation;
7182 translation.AppendTranslate(1.f, 2.f, 3.f);
7183
loyso968163c92016-01-04 23:18:487184 scoped_refptr<AnimationTimeline> timeline;
loyso9556c732016-03-11 07:54:587185 timeline = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7186 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487187
loyso9556c732016-03-11 07:54:587188 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7189 TransformOperations(), translation);
[email protected]1c3626e2014-04-09 17:49:227190
7191 // No layers have scale-affecting animations.
jaydasika2411692c2016-03-23 01:56:097192 EXPECT_EQ(
7193 0.f,
7194 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377195 EXPECT_EQ(0.f,
7196 parent_raw->draw_properties().maximum_animation_contents_scale);
7197 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7198 EXPECT_EQ(
7199 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227200
jaydasika2411692c2016-03-23 01:56:097201 EXPECT_EQ(
7202 0.f,
7203 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037204 EXPECT_EQ(0.f,
7205 parent_raw->draw_properties().starting_animation_contents_scale);
7206 EXPECT_EQ(0.f,
7207 child_raw->draw_properties().starting_animation_contents_scale);
7208 EXPECT_EQ(
7209 0.f,
7210 grand_child_raw->draw_properties().starting_animation_contents_scale);
7211
[email protected]1c3626e2014-04-09 17:49:227212 TransformOperations scale;
7213 scale.AppendScale(5.f, 4.f, 3.f);
7214
loyso9556c732016-03-11 07:54:587215 AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0,
7216 TransformOperations(), scale);
ajumacaaa9b32015-08-04 15:55:297217 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097218 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227219
7220 // Only |child| has a scale-affecting animation.
jaydasika2411692c2016-03-23 01:56:097221 EXPECT_EQ(
7222 0.f,
7223 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377224 EXPECT_EQ(0.f,
7225 parent_raw->draw_properties().maximum_animation_contents_scale);
7226 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
7227 EXPECT_EQ(
7228 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227229
jaydasika2411692c2016-03-23 01:56:097230 EXPECT_EQ(
7231 0.f,
7232 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037233 EXPECT_EQ(0.f,
7234 parent_raw->draw_properties().starting_animation_contents_scale);
7235 EXPECT_EQ(1.f,
7236 child_raw->draw_properties().starting_animation_contents_scale);
7237 EXPECT_EQ(
7238 1.f,
7239 grand_child_raw->draw_properties().starting_animation_contents_scale);
7240
jaydasika2411692c2016-03-23 01:56:097241 AddAnimatedTransformToLayerWithPlayer(grand_parent_raw->id(), timeline, 1.0,
loyso9556c732016-03-11 07:54:587242 TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:097243 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7244 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227245
7246 // |grand_parent| and |child| have scale-affecting animations.
jaydasika2411692c2016-03-23 01:56:097247 EXPECT_EQ(
7248 5.f,
7249 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377250 EXPECT_EQ(5.f,
7251 parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227252 // We don't support combining animated scales from two nodes; 0.f means
7253 // that the maximum scale could not be computed.
[email protected]a57cb8b12014-06-13 18:15:377254 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7255 EXPECT_EQ(
7256 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227257
jaydasika2411692c2016-03-23 01:56:097258 EXPECT_EQ(
7259 1.f,
7260 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037261 EXPECT_EQ(1.f,
7262 parent_raw->draw_properties().starting_animation_contents_scale);
7263 EXPECT_EQ(0.f,
7264 child_raw->draw_properties().starting_animation_contents_scale);
7265 EXPECT_EQ(
7266 0.f,
7267 grand_child_raw->draw_properties().starting_animation_contents_scale);
7268
loyso9556c732016-03-11 07:54:587269 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7270 TransformOperations(), scale);
ajumacaaa9b32015-08-04 15:55:297271 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097272 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227273
7274 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
jaydasika2411692c2016-03-23 01:56:097275 EXPECT_EQ(
7276 5.f,
7277 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377278 EXPECT_EQ(0.f,
7279 parent_raw->draw_properties().maximum_animation_contents_scale);
7280 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7281 EXPECT_EQ(
7282 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227283
jaydasika2411692c2016-03-23 01:56:097284 EXPECT_EQ(
7285 1.f,
7286 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037287 EXPECT_EQ(0.f,
7288 parent_raw->draw_properties().starting_animation_contents_scale);
7289 EXPECT_EQ(0.f,
7290 child_raw->draw_properties().starting_animation_contents_scale);
7291 EXPECT_EQ(
7292 0.f,
7293 grand_child_raw->draw_properties().starting_animation_contents_scale);
7294
jaydasika2411692c2016-03-23 01:56:097295 AbortAnimationsOnLayerWithPlayer(grand_parent_raw->id(), timeline,
loyso9556c732016-03-11 07:54:587296 TargetProperty::TRANSFORM);
7297 AbortAnimationsOnLayerWithPlayer(parent_raw->id(), timeline,
7298 TargetProperty::TRANSFORM);
7299 AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline,
7300 TargetProperty::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227301
7302 TransformOperations perspective;
7303 perspective.AppendPerspective(10.f);
7304
loyso9556c732016-03-11 07:54:587305 AddAnimatedTransformToLayerWithPlayer(child_raw->id(), timeline, 1.0,
7306 TransformOperations(), perspective);
ajumab4a846f22015-08-24 19:13:447307 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:097308 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227309
7310 // |child| has a scale-affecting animation but computing the maximum of this
7311 // animation is not supported.
jaydasika2411692c2016-03-23 01:56:097312 EXPECT_EQ(
7313 0.f,
7314 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377315 EXPECT_EQ(0.f,
7316 parent_raw->draw_properties().maximum_animation_contents_scale);
7317 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7318 EXPECT_EQ(
7319 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227320
jaydasika2411692c2016-03-23 01:56:097321 EXPECT_EQ(
7322 0.f,
7323 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037324 EXPECT_EQ(0.f,
7325 parent_raw->draw_properties().starting_animation_contents_scale);
7326 EXPECT_EQ(0.f,
7327 child_raw->draw_properties().starting_animation_contents_scale);
7328 EXPECT_EQ(
7329 0.f,
7330 grand_child_raw->draw_properties().starting_animation_contents_scale);
7331
loyso9556c732016-03-11 07:54:587332 AbortAnimationsOnLayerWithPlayer(child_raw->id(), timeline,
7333 TargetProperty::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227334 gfx::Transform scale_matrix;
7335 scale_matrix.Scale(1.f, 2.f);
jaydasika2411692c2016-03-23 01:56:097336 grand_parent_raw->SetTransform(scale_matrix);
[email protected]1c3626e2014-04-09 17:49:227337 parent_raw->SetTransform(scale_matrix);
jaydasika2411692c2016-03-23 01:56:097338 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
loyso968163c92016-01-04 23:18:487339
loyso9556c732016-03-11 07:54:587340 AddAnimatedTransformToLayerWithPlayer(parent_raw->id(), timeline, 1.0,
7341 TransformOperations(), scale);
jaydasika2411692c2016-03-23 01:56:097342 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227343
7344 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7345 // animation with maximum scale 5.f.
jaydasika2411692c2016-03-23 01:56:097346 EXPECT_EQ(
7347 0.f,
7348 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377349 EXPECT_EQ(10.f,
7350 parent_raw->draw_properties().maximum_animation_contents_scale);
7351 EXPECT_EQ(10.f,
7352 child_raw->draw_properties().maximum_animation_contents_scale);
7353 EXPECT_EQ(
7354 10.f,
7355 grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227356
jaydasika2411692c2016-03-23 01:56:097357 EXPECT_EQ(
7358 0.f,
7359 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037360 EXPECT_EQ(2.f,
7361 parent_raw->draw_properties().starting_animation_contents_scale);
7362 EXPECT_EQ(2.f,
7363 child_raw->draw_properties().starting_animation_contents_scale);
7364 EXPECT_EQ(
7365 2.f,
7366 grand_child_raw->draw_properties().starting_animation_contents_scale);
7367
[email protected]1c3626e2014-04-09 17:49:227368 gfx::Transform perspective_matrix;
7369 perspective_matrix.ApplyPerspectiveDepth(2.f);
7370 child_raw->SetTransform(perspective_matrix);
jaydasika2411692c2016-03-23 01:56:097371 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7372 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227373
7374 // |child| has a transform that's neither a translation nor a scale.
jaydasika2411692c2016-03-23 01:56:097375 EXPECT_EQ(
7376 0.f,
7377 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377378 EXPECT_EQ(10.f,
7379 parent_raw->draw_properties().maximum_animation_contents_scale);
7380 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7381 EXPECT_EQ(
7382 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227383
jaydasika2411692c2016-03-23 01:56:097384 EXPECT_EQ(
7385 0.f,
7386 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037387 EXPECT_EQ(2.f,
7388 parent_raw->draw_properties().starting_animation_contents_scale);
7389 EXPECT_EQ(0.f,
7390 child_raw->draw_properties().starting_animation_contents_scale);
7391 EXPECT_EQ(
7392 0.f,
7393 grand_child_raw->draw_properties().starting_animation_contents_scale);
7394
[email protected]1c3626e2014-04-09 17:49:227395 parent_raw->SetTransform(perspective_matrix);
jaydasika2411692c2016-03-23 01:56:097396 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
7397 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227398
7399 // |parent| and |child| have transforms that are neither translations nor
7400 // scales.
jaydasika2411692c2016-03-23 01:56:097401 EXPECT_EQ(
7402 0.f,
7403 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377404 EXPECT_EQ(0.f,
7405 parent_raw->draw_properties().maximum_animation_contents_scale);
7406 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7407 EXPECT_EQ(
7408 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227409
jaydasika2411692c2016-03-23 01:56:097410 EXPECT_EQ(
7411 0.f,
7412 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037413 EXPECT_EQ(0.f,
7414 parent_raw->draw_properties().starting_animation_contents_scale);
7415 EXPECT_EQ(0.f,
7416 child_raw->draw_properties().starting_animation_contents_scale);
7417 EXPECT_EQ(
7418 0.f,
7419 grand_child_raw->draw_properties().starting_animation_contents_scale);
7420
[email protected]1c3626e2014-04-09 17:49:227421 parent_raw->SetTransform(identity_matrix);
7422 child_raw->SetTransform(identity_matrix);
jaydasika2411692c2016-03-23 01:56:097423 grand_parent_raw->SetTransform(perspective_matrix);
7424 grand_parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227425
jaydasika2411692c2016-03-23 01:56:097426 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]1c3626e2014-04-09 17:49:227427
7428 // |grand_parent| has a transform that's neither a translation nor a scale.
jaydasika2411692c2016-03-23 01:56:097429 EXPECT_EQ(
7430 0.f,
7431 grand_parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]a57cb8b12014-06-13 18:15:377432 EXPECT_EQ(0.f,
7433 parent_raw->draw_properties().maximum_animation_contents_scale);
7434 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7435 EXPECT_EQ(
7436 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037437
jaydasika2411692c2016-03-23 01:56:097438 EXPECT_EQ(
7439 0.f,
7440 grand_parent_raw->draw_properties().starting_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037441 EXPECT_EQ(0.f,
7442 parent_raw->draw_properties().starting_animation_contents_scale);
7443 EXPECT_EQ(0.f,
7444 child_raw->draw_properties().starting_animation_contents_scale);
7445 EXPECT_EQ(
7446 0.f,
7447 grand_child_raw->draw_properties().starting_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227448}
7449
[email protected]390bb1ff2014-05-09 17:14:407450static void GatherDrawnLayers(LayerImplList* rsll,
7451 std::set<LayerImpl*>* drawn_layers) {
enne389d1a12015-06-18 20:40:517452 for (LayerIterator it = LayerIterator::Begin(rsll),
7453 end = LayerIterator::End(rsll);
7454 it != end; ++it) {
[email protected]390bb1ff2014-05-09 17:14:407455 LayerImpl* layer = *it;
7456 if (it.represents_itself())
7457 drawn_layers->insert(layer);
7458
7459 if (!it.represents_contributing_render_surface())
7460 continue;
7461
7462 if (layer->mask_layer())
7463 drawn_layers->insert(layer->mask_layer());
7464 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
7465 drawn_layers->insert(layer->replica_layer()->mask_layer());
7466 }
7467}
7468
7469TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:167470 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]390bb1ff2014-05-09 17:14:407471 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567472 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167473 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567474 &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:407475 gfx::Transform identity_matrix;
7476
danakj60bc3bc2016-04-09 00:24:487477 std::unique_ptr<LayerImpl> grand_parent =
[email protected]390bb1ff2014-05-09 17:14:407478 LayerImpl::Create(host_impl.active_tree(), 1);
danakj60bc3bc2016-04-09 00:24:487479 std::unique_ptr<LayerImpl> parent =
7480 LayerImpl::Create(host_impl.active_tree(), 3);
7481 std::unique_ptr<LayerImpl> child =
7482 LayerImpl::Create(host_impl.active_tree(), 5);
7483 std::unique_ptr<LayerImpl> grand_child1 =
[email protected]390bb1ff2014-05-09 17:14:407484 LayerImpl::Create(host_impl.active_tree(), 7);
danakj60bc3bc2016-04-09 00:24:487485 std::unique_ptr<LayerImpl> grand_child2 =
[email protected]390bb1ff2014-05-09 17:14:407486 LayerImpl::Create(host_impl.active_tree(), 9);
7487
7488 LayerImpl* grand_parent_raw = grand_parent.get();
7489 LayerImpl* parent_raw = parent.get();
7490 LayerImpl* child_raw = child.get();
7491 LayerImpl* grand_child1_raw = grand_child1.get();
7492 LayerImpl* grand_child2_raw = grand_child2.get();
7493
danakja04855a2015-11-18 20:39:107494 child->AddChild(std::move(grand_child1));
7495 child->AddChild(std::move(grand_child2));
7496 parent->AddChild(std::move(child));
7497 grand_parent->AddChild(std::move(parent));
jaydasika2411692c2016-03-23 01:56:097498 host_impl.active_tree()->SetRootLayer(std::move(grand_parent));
[email protected]390bb1ff2014-05-09 17:14:407499
awoloszyne83f28c2014-12-22 15:40:007500 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
7501 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7502 true, false, true);
7503 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7504 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:407505 false);
awoloszyne83f28c2014-12-22 15:40:007506
7507 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7508 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:407509 false);
awoloszyne83f28c2014-12-22 15:40:007510
7511 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
7512 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7513 true, false, false);
7514
7515 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
7516 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7517 true, false, false);
[email protected]390bb1ff2014-05-09 17:14:407518
7519 // Start with nothing being drawn.
7520 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407521
ajuma0adb5902016-04-28 16:32:387522 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7523 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7524 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7525 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7526 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407527
7528 std::set<LayerImpl*> expected;
7529 std::set<LayerImpl*> actual;
7530 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7531 EXPECT_EQ(expected, actual);
7532
7533 // If we force render surface, but none of the layers are in the layer list,
7534 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:007535 grand_child1_raw->SetHasRenderSurface(true);
jaydasikaebf9e4ea2015-08-14 21:29:127536 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407537
7538 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407539
ajuma0adb5902016-04-28 16:32:387540 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7541 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7542 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7543 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7544 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407545
7546 expected.clear();
7547 actual.clear();
7548 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7549 EXPECT_EQ(expected, actual);
7550
7551 // However, if we say that this layer also draws content, it will appear in
7552 // RSLL.
7553 grand_child1_raw->SetDrawsContent(true);
7554
7555 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407556
ajuma0adb5902016-04-28 16:32:387557 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7558 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7559 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7560 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7561 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407562
7563 expected.clear();
7564 expected.insert(grand_child1_raw);
7565
7566 actual.clear();
7567 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7568 EXPECT_EQ(expected, actual);
7569
7570 // Now child is forced to have a render surface, and one if its children draws
7571 // content.
7572 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:007573 grand_child1_raw->SetHasRenderSurface(false);
jaydasikaebf9e4ea2015-08-14 21:29:127574 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
awoloszyne83f28c2014-12-22 15:40:007575 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:407576 grand_child2_raw->SetDrawsContent(true);
7577
7578 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407579
ajuma0adb5902016-04-28 16:32:387580 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7581 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7582 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7583 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7584 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407585
7586 expected.clear();
7587 expected.insert(grand_child2_raw);
7588
7589 actual.clear();
7590 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7591 EXPECT_EQ(expected, actual);
7592
7593 // Add a mask layer to child.
danakja5a05ba02015-11-20 20:14:217594 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:047595 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407596
7597 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407598
ajuma0adb5902016-04-28 16:32:387599 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7600 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7601 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7602 EXPECT_TRUE(
7603 child_raw->mask_layer()->is_drawn_render_surface_layer_list_member());
7604 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7605 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407606
7607 expected.clear();
7608 expected.insert(grand_child2_raw);
7609 expected.insert(child_raw->mask_layer());
7610
7611 expected.clear();
7612 expected.insert(grand_child2_raw);
7613 expected.insert(child_raw->mask_layer());
7614
7615 actual.clear();
7616 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7617 EXPECT_EQ(expected, actual);
7618
7619 // Add replica mask layer.
danakj60bc3bc2016-04-09 00:24:487620 std::unique_ptr<LayerImpl> replica_layer =
[email protected]390bb1ff2014-05-09 17:14:407621 LayerImpl::Create(host_impl.active_tree(), 20);
7622 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
danakja04855a2015-11-18 20:39:107623 child_raw->SetReplicaLayer(std::move(replica_layer));
jaydasika23fb3822015-08-25 03:22:597624 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407625
7626 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407627
ajuma0adb5902016-04-28 16:32:387628 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7629 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7630 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7631 EXPECT_TRUE(
7632 child_raw->mask_layer()->is_drawn_render_surface_layer_list_member());
7633 EXPECT_TRUE(child_raw->replica_layer()
7634 ->mask_layer()
7635 ->is_drawn_render_surface_layer_list_member());
7636 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7637 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407638
7639 expected.clear();
7640 expected.insert(grand_child2_raw);
7641 expected.insert(child_raw->mask_layer());
7642 expected.insert(child_raw->replica_layer()->mask_layer());
7643
7644 actual.clear();
7645 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7646 EXPECT_EQ(expected, actual);
7647
7648 child_raw->TakeReplicaLayer();
7649
7650 // With nothing drawing, we should have no layers.
7651 grand_child2_raw->SetDrawsContent(false);
7652
7653 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407654
ajuma0adb5902016-04-28 16:32:387655 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7656 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7657 EXPECT_FALSE(child_raw->is_drawn_render_surface_layer_list_member());
7658 EXPECT_FALSE(
7659 child_raw->mask_layer()->is_drawn_render_surface_layer_list_member());
7660 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7661 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407662
7663 expected.clear();
7664 actual.clear();
7665 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7666 EXPECT_EQ(expected, actual);
7667
7668 // Child itself draws means that we should have the child and the mask in the
7669 // list.
7670 child_raw->SetDrawsContent(true);
7671
7672 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407673
ajuma0adb5902016-04-28 16:32:387674 EXPECT_FALSE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7675 EXPECT_FALSE(parent_raw->is_drawn_render_surface_layer_list_member());
7676 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
7677 EXPECT_TRUE(
7678 child_raw->mask_layer()->is_drawn_render_surface_layer_list_member());
7679 EXPECT_FALSE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7680 EXPECT_FALSE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407681
7682 expected.clear();
7683 expected.insert(child_raw);
7684 expected.insert(child_raw->mask_layer());
7685 actual.clear();
7686 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7687 EXPECT_EQ(expected, actual);
7688
7689 child_raw->TakeMaskLayer();
jaydasikad36e7fa2015-07-14 15:15:047690 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407691
7692 // Now everyone's a member!
7693 grand_parent_raw->SetDrawsContent(true);
7694 parent_raw->SetDrawsContent(true);
7695 child_raw->SetDrawsContent(true);
7696 grand_child1_raw->SetDrawsContent(true);
7697 grand_child2_raw->SetDrawsContent(true);
7698
7699 ExecuteCalculateDrawProperties(grand_parent_raw);
[email protected]390bb1ff2014-05-09 17:14:407700
ajuma0adb5902016-04-28 16:32:387701 EXPECT_TRUE(grand_parent_raw->is_drawn_render_surface_layer_list_member());
7702 EXPECT_TRUE(parent_raw->is_drawn_render_surface_layer_list_member());
7703 EXPECT_TRUE(child_raw->is_drawn_render_surface_layer_list_member());
7704 EXPECT_TRUE(grand_child1_raw->is_drawn_render_surface_layer_list_member());
7705 EXPECT_TRUE(grand_child2_raw->is_drawn_render_surface_layer_list_member());
[email protected]390bb1ff2014-05-09 17:14:407706
7707 expected.clear();
7708 expected.insert(grand_parent_raw);
7709 expected.insert(parent_raw);
7710 expected.insert(child_raw);
7711 expected.insert(grand_child1_raw);
7712 expected.insert(grand_child2_raw);
7713
7714 actual.clear();
7715 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7716 EXPECT_EQ(expected, actual);
7717}
[email protected]18e69652014-06-13 12:50:587718
7719TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:167720 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]18e69652014-06-13 12:50:587721 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567722 TestTaskGraphRunner task_graph_runner;
loyso968163c92016-01-04 23:18:487723 LayerTreeSettings settings = host()->settings();
enne637715732015-07-07 02:05:267724 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167725 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7726 &shared_bitmap_manager, &task_graph_runner);
[email protected]18e69652014-06-13 12:50:587727
danakj60bc3bc2016-04-09 00:24:487728 std::unique_ptr<LayerImpl> root =
7729 LayerImpl::Create(host_impl.active_tree(), 1);
[email protected]18e69652014-06-13 12:50:587730 LayerImpl* root_layer = root.get();
danakj60bc3bc2016-04-09 00:24:487731 std::unique_ptr<LayerImpl> child1 =
7732 LayerImpl::Create(host_impl.active_tree(), 2);
[email protected]18e69652014-06-13 12:50:587733 LayerImpl* child1_layer = child1.get();
danakj60bc3bc2016-04-09 00:24:487734 std::unique_ptr<LayerImpl> child2 =
7735 LayerImpl::Create(host_impl.active_tree(), 3);
[email protected]18e69652014-06-13 12:50:587736 LayerImpl* child2_layer = child2.get();
7737
danakja04855a2015-11-18 20:39:107738 root->AddChild(std::move(child1));
7739 root->AddChild(std::move(child2));
jaydasika6b5a32bf2016-04-22 21:56:367740 root->test_properties()->force_render_surface = true;
jaydasika0d98ba92015-11-17 05:17:287741 root->SetDrawsContent(true);
jaydasika2411692c2016-03-23 01:56:097742 host_impl.active_tree()->SetRootLayer(std::move(root));
[email protected]18e69652014-06-13 12:50:587743
7744 gfx::Transform identity_matrix, scale_transform_child1,
7745 scale_transform_child2;
7746 scale_transform_child1.Scale(2, 3);
7747 scale_transform_child2.Scale(4, 5);
7748
awoloszyne83f28c2014-12-22 15:40:007749 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
7750 gfx::PointF(), gfx::Size(1, 1), true, false,
7751 true);
7752 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
jaydasika0d98ba92015-11-17 05:17:287753 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1),
7754 true, false, false);
[email protected]18e69652014-06-13 12:50:587755
danakja5a05ba02015-11-20 20:14:217756 child1_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4));
jaydasika0d98ba92015-11-17 05:17:287757 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587758
danakj60bc3bc2016-04-09 00:24:487759 std::unique_ptr<LayerImpl> replica_layer =
[email protected]18e69652014-06-13 12:50:587760 LayerImpl::Create(host_impl.active_tree(), 5);
7761 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
danakja04855a2015-11-18 20:39:107762 child1_layer->SetReplicaLayer(std::move(replica_layer));
awoloszyne83f28c2014-12-22 15:40:007763 child1_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:587764
7765 ExecuteCalculateDrawProperties(root_layer);
7766
7767 TransformOperations scale;
7768 scale.AppendScale(5.f, 8.f, 3.f);
7769
loyso9556c732016-03-11 07:54:587770 scoped_refptr<AnimationTimeline> timeline =
7771 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId());
7772 host_impl.animation_host()->AddAnimationTimeline(timeline);
loyso968163c92016-01-04 23:18:487773
loyso9556c732016-03-11 07:54:587774 AddAnimatedTransformToLayerWithPlayer(child2_layer->id(), timeline, 1.0,
7775 TransformOperations(), scale);
loyso968163c92016-01-04 23:18:487776
awoloszyne83f28c2014-12-22 15:40:007777 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
jaydasika0d98ba92015-11-17 05:17:287778 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1),
7779 true, false, false);
7780 child2_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587781
jaydasika2411692c2016-03-23 01:56:097782 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:587783 ExecuteCalculateDrawProperties(root_layer);
7784
enne637715732015-07-07 02:05:267785 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
7786 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
7787 EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale());
7788 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587789
7790 EXPECT_FLOAT_EQ(
7791 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7792 EXPECT_FLOAT_EQ(
7793 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7794 EXPECT_FLOAT_EQ(0.f,
7795 child1_layer->mask_layer()
7796 ->draw_properties()
7797 .maximum_animation_contents_scale);
7798 EXPECT_FLOAT_EQ(0.f,
7799 child1_layer->replica_layer()
7800 ->mask_layer()
7801 ->draw_properties()
7802 .maximum_animation_contents_scale);
7803 EXPECT_FLOAT_EQ(
7804 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
7805
[email protected]18e69652014-06-13 12:50:587806 // Changing page-scale would affect ideal_contents_scale and
7807 // maximum_animation_contents_scale.
7808
7809 float page_scale_factor = 3.f;
7810 float device_scale_factor = 1.0f;
7811 std::vector<LayerImpl*> render_surface_layer_list;
7812 gfx::Size device_viewport_size =
7813 gfx::Size(root_layer->bounds().width() * device_scale_factor,
7814 root_layer->bounds().height() * device_scale_factor);
[email protected]18e69652014-06-13 12:50:587815 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:387816 root_layer, device_viewport_size, &render_surface_layer_list);
[email protected]18e69652014-06-13 12:50:587817
7818 inputs.page_scale_factor = page_scale_factor;
7819 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:117820 inputs.page_scale_layer = root_layer;
sunxdb365de02016-04-28 20:32:577821 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:587822
enne637715732015-07-07 02:05:267823 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
7824 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
7825 EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587826 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267827 9.f,
7828 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
7829 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587830
7831 EXPECT_FLOAT_EQ(
7832 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7833 EXPECT_FLOAT_EQ(
7834 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7835 EXPECT_FLOAT_EQ(0.f,
7836 child1_layer->mask_layer()
7837 ->draw_properties()
7838 .maximum_animation_contents_scale);
7839 EXPECT_FLOAT_EQ(0.f,
7840 child1_layer->replica_layer()
7841 ->mask_layer()
7842 ->draw_properties()
7843 .maximum_animation_contents_scale);
7844 EXPECT_FLOAT_EQ(
7845 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
7846
[email protected]18e69652014-06-13 12:50:587847 // Changing device-scale would affect ideal_contents_scale and
7848 // maximum_animation_contents_scale.
7849
7850 device_scale_factor = 4.0f;
7851 inputs.device_scale_factor = device_scale_factor;
7852 inputs.can_adjust_raster_scales = true;
jaydasika2411692c2016-03-23 01:56:097853 root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true;
sunxdb365de02016-04-28 20:32:577854 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
[email protected]18e69652014-06-13 12:50:587855
enne637715732015-07-07 02:05:267856 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
7857 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
7858 EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587859 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267860 36.f,
7861 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
7862 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587863
7864 EXPECT_FLOAT_EQ(
7865 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7866 EXPECT_FLOAT_EQ(
7867 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7868 EXPECT_FLOAT_EQ(0.f,
7869 child1_layer->mask_layer()
7870 ->draw_properties()
7871 .maximum_animation_contents_scale);
7872 EXPECT_FLOAT_EQ(0.f,
7873 child1_layer->replica_layer()
7874 ->mask_layer()
7875 ->draw_properties()
7876 .maximum_animation_contents_scale);
7877 EXPECT_FLOAT_EQ(
7878 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
[email protected]18e69652014-06-13 12:50:587879}
7880
danakjf6069db2014-09-13 00:46:477881TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
jaydasika6f972de2016-04-07 16:16:147882 LayerImpl* root = root_layer();
7883 LayerImpl* clip = AddChild<LayerImpl>(root);
7884 LayerImpl* content = AddChild<LayerImpl>(clip);
danakjf6069db2014-09-13 00:46:477885
jaydasika6f972de2016-04-07 16:16:147886 const gfx::Transform identity_matrix;
7887 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
7888 gfx::PointF(), gfx::Size(768 / 2, 3000), true,
7889 false, true);
7890 SetLayerPropertiesForTesting(clip, identity_matrix, gfx::Point3F(),
7891 gfx::PointF(), gfx::Size(768 / 2, 10000), true,
7892 false, false);
7893 SetLayerPropertiesForTesting(content, identity_matrix, gfx::Point3F(),
7894 gfx::PointF(), gfx::Size(768 / 2, 10000), true,
7895 false, true);
7896 root->SetDrawsContent(true);
danakjf6069db2014-09-13 00:46:477897 clip->SetMasksToBounds(true);
jaydasika6f972de2016-04-07 16:16:147898 content->SetDrawsContent(true);
danakjf6069db2014-09-13 00:46:477899
7900 gfx::Size device_viewport_size(768, 582);
jaydasika6f972de2016-04-07 16:16:147901 LayerImplList render_surface_layer_list_impl;
jaydasika6f972de2016-04-07 16:16:147902 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7903 root, device_viewport_size, identity_matrix,
ajuma0adb5902016-04-28 16:32:387904 &render_surface_layer_list_impl);
danakjf6069db2014-09-13 00:46:477905 inputs.device_scale_factor = 2.f;
7906 inputs.page_scale_factor = 1.f;
enne6394d5b42015-05-26 22:23:117907 inputs.page_scale_layer = NULL;
sunxdb365de02016-04-28 20:32:577908 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakjf6069db2014-09-13 00:46:477909
7910 // Layers in the root render surface have their visible content rect clipped
7911 // by the viewport.
jaydasika6f972de2016-04-07 16:16:147912 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect());
danakjf6069db2014-09-13 00:46:477913
7914 // Layers drawing to a child render surface should still have their visible
7915 // content rect clipped by the viewport.
jaydasika6f972de2016-04-07 16:16:147916 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect());
danakjf6069db2014-09-13 00:46:477917}
7918
timav599f4359d2014-12-05 00:12:227919TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:167920 FakeImplTaskRunnerProvider task_runner_provider;
timav599f4359d2014-12-05 00:12:227921 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567922 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167923 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567924 &task_graph_runner);
timav599f4359d2014-12-05 00:12:227925
7926 // Set two layers: the root layer clips it's child,
7927 // the child draws its content.
7928
7929 gfx::Size root_size = gfx::Size(300, 500);
7930
7931 // Sublayer should be bigger than the root enlarged by bounds_delta.
7932 gfx::Size sublayer_size = gfx::Size(300, 1000);
7933
7934 // Device viewport accomidated the root and the top controls.
7935 gfx::Size device_viewport_size = gfx::Size(300, 600);
7936 gfx::Transform identity_matrix;
7937
miletus8bd08a622015-06-16 18:44:527938 host_impl.SetViewportSize(device_viewport_size);
timav599f4359d2014-12-05 00:12:227939 host_impl.active_tree()->SetRootLayer(
7940 LayerImpl::Create(host_impl.active_tree(), 1));
7941
7942 LayerImpl* root = host_impl.active_tree()->root_layer();
7943 SetLayerPropertiesForTesting(root,
7944 identity_matrix,
7945 gfx::Point3F(),
7946 gfx::PointF(),
7947 root_size,
7948 false,
awoloszyne83f28c2014-12-22 15:40:007949 false,
7950 true);
timav599f4359d2014-12-05 00:12:227951 root->SetMasksToBounds(true);
7952
7953 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
7954
7955 LayerImpl* sublayer = root->child_at(0);
7956 SetLayerPropertiesForTesting(sublayer,
7957 identity_matrix,
7958 gfx::Point3F(),
7959 gfx::PointF(),
7960 sublayer_size,
7961 false,
awoloszyne83f28c2014-12-22 15:40:007962 false,
timav599f4359d2014-12-05 00:12:227963 false);
timav599f4359d2014-12-05 00:12:227964 sublayer->SetDrawsContent(true);
7965
7966 LayerImplList layer_impl_list;
timav599f4359d2014-12-05 00:12:227967 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajuma0adb5902016-04-28 16:32:387968 root, device_viewport_size, &layer_impl_list);
timav599f4359d2014-12-05 00:12:227969
sunxdb365de02016-04-28 20:32:577970 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
danakj64767d902015-06-19 00:10:437971 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:227972
7973 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
sunxdb365de02016-04-28 20:32:577974 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
timav599f4359d2014-12-05 00:12:227975
7976 gfx::Rect affected_by_delta(0, 0, root_size.width(),
7977 root_size.height() + 50);
danakj64767d902015-06-19 00:10:437978 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:227979}
7980
ajumadd2802e72015-06-30 20:28:297981TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
loyso0940d412016-03-14 01:30:317982 scoped_refptr<Layer> root = Layer::Create();
7983 scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create();
7984 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create();
7985 scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create();
7986 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create();
ajumadd2802e72015-06-30 20:28:297987
7988 root->AddChild(inner_viewport_container_layer);
7989 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
7990 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
7991 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
7992
7993 inner_viewport_scroll_layer->SetScrollClipLayerId(
7994 inner_viewport_container_layer->id());
7995 outer_viewport_scroll_layer->SetScrollClipLayerId(
7996 outer_viewport_container_layer->id());
7997
7998 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
7999 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
8000
8001 host()->SetRootLayer(root);
8002 host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer,
8003 outer_viewport_scroll_layer);
8004
loyso0940d412016-03-14 01:30:318005 scoped_refptr<Layer> fixed_to_inner = Layer::Create();
8006 scoped_refptr<Layer> fixed_to_outer = Layer::Create();
ajumadd2802e72015-06-30 20:28:298007
8008 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
8009 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
8010
8011 LayerPositionConstraint fixed_to_right;
8012 fixed_to_right.set_is_fixed_position(true);
8013 fixed_to_right.set_is_fixed_to_right_edge(true);
8014
8015 fixed_to_inner->SetPositionConstraint(fixed_to_right);
8016 fixed_to_outer->SetPositionConstraint(fixed_to_right);
8017
8018 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8019
8020 TransformTree& transform_tree = host()->property_trees()->transform_tree;
8021 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8022 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8023
8024 LayerPositionConstraint fixed_to_left;
8025 fixed_to_left.set_is_fixed_position(true);
8026 fixed_to_inner->SetPositionConstraint(fixed_to_left);
8027
8028 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8029 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8030 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8031
8032 fixed_to_outer->SetPositionConstraint(fixed_to_left);
8033
8034 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8035 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
8036 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
8037}
8038
vollick7d83b452015-02-24 20:18:068039TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
8040 const gfx::Transform identity_matrix;
loyso0940d412016-03-14 01:30:318041 scoped_refptr<Layer> root = Layer::Create();
vollick7d83b452015-02-24 20:18:068042 scoped_refptr<LayerWithForcedDrawsContent> animated =
loyso0940d412016-03-14 01:30:318043 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick7d83b452015-02-24 20:18:068044
8045 root->AddChild(animated);
8046
ennea7b43c32015-06-18 20:01:338047 host()->SetRootLayer(root);
vollick7d83b452015-02-24 20:18:068048
8049 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8050 gfx::PointF(), gfx::Size(100, 100), true, false);
8051 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
8052 gfx::PointF(), gfx::Size(20, 20), true, false);
8053
8054 root->SetMasksToBounds(true);
jaydasika6b5a32bf2016-04-22 21:56:368055 root->SetForceRenderSurfaceForTesting(true);
vollick7d83b452015-02-24 20:18:068056 animated->SetOpacity(0.f);
8057
loyso9556c732016-03-11 07:54:588058 AddOpacityTransitionToLayerWithPlayer(animated->id(), timeline(), 10.0, 0.f,
8059 1.f, false);
enne601f2ef12015-05-19 18:20:178060 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick7d83b452015-02-24 20:18:068061
jaydasika74bf516f2016-04-01 19:48:158062 EXPECT_FALSE(animated->visible_layer_rect_for_testing().IsEmpty());
vollick7d83b452015-02-24 20:18:068063}
8064
ajumaa92fdc12015-03-31 22:47:418065TEST_F(LayerTreeHostCommonTest,
8066 VisibleContentRectForAnimatedLayerWithSingularTransform) {
8067 const gfx::Transform identity_matrix;
loyso0940d412016-03-14 01:30:318068 scoped_refptr<Layer> root = Layer::Create();
8069 scoped_refptr<Layer> clip = Layer::Create();
ajumaa92fdc12015-03-31 22:47:418070 scoped_refptr<LayerWithForcedDrawsContent> animated =
loyso0940d412016-03-14 01:30:318071 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaa92fdc12015-03-31 22:47:418072 scoped_refptr<LayerWithForcedDrawsContent> surface =
loyso0940d412016-03-14 01:30:318073 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaa92fdc12015-03-31 22:47:418074 scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation =
loyso0940d412016-03-14 01:30:318075 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumaa92fdc12015-03-31 22:47:418076
8077 root->AddChild(clip);
8078 clip->AddChild(animated);
8079 animated->AddChild(surface);
8080 surface->AddChild(descendant_of_animation);
8081
8082 clip->SetMasksToBounds(true);
jaydasika6b5a32bf2016-04-22 21:56:368083 surface->SetForceRenderSurfaceForTesting(true);
ajumaa92fdc12015-03-31 22:47:418084
ennea7b43c32015-06-18 20:01:338085 host()->SetRootLayer(root);
ajumaa92fdc12015-03-31 22:47:418086
8087 gfx::Transform uninvertible_matrix;
8088 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
8089
8090 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8091 gfx::PointF(), gfx::Size(100, 100), true, false);
8092 SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(),
8093 gfx::PointF(), gfx::Size(10, 10), true, false);
8094 SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix,
8095 gfx::Point3F(), gfx::PointF(),
8096 gfx::Size(120, 120), true, false);
8097 SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(),
8098 gfx::PointF(), gfx::Size(100, 100), true, false);
8099 SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix,
8100 gfx::Point3F(), gfx::PointF(),
8101 gfx::Size(200, 200), true, false);
8102
8103 TransformOperations start_transform_operations;
8104 start_transform_operations.AppendMatrix(uninvertible_matrix);
8105 TransformOperations end_transform_operations;
8106
loyso9556c732016-03-11 07:54:588107 AddAnimatedTransformToLayerWithPlayer(animated->id(), timeline(), 10.0,
8108 start_transform_operations,
8109 end_transform_operations);
enne601f2ef12015-05-19 18:20:178110 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:418111
8112 // The animated layer has a singular transform and maps to a non-empty rect in
8113 // clipped target space, so is treated as fully visible.
jaydasika74bf516f2016-04-01 19:48:158114 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:418115
8116 // The singular transform on |animated| is flattened when inherited by
8117 // |surface|, and this happens to make it invertible.
jaydasika74bf516f2016-04-01 19:48:158118 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_layer_rect_for_testing());
8119 EXPECT_EQ(gfx::Rect(2, 2),
8120 descendant_of_animation->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:418121
8122 gfx::Transform zero_matrix;
8123 zero_matrix.Scale3d(0.f, 0.f, 0.f);
8124 SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(),
8125 gfx::PointF(), gfx::Size(120, 120), true, false);
8126
enne601f2ef12015-05-19 18:20:178127 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:418128
8129 // The animated layer maps to the empty rect in clipped target space, so is
8130 // treated as having an empty visible rect.
jaydasika74bf516f2016-04-01 19:48:158131 EXPECT_EQ(gfx::Rect(), animated->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:418132
8133 // This time, flattening does not make |animated|'s transform invertible. This
8134 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:348135 // |surface| and layers that draw into it as having empty visible rect.
jaydasika74bf516f2016-04-01 19:48:158136 EXPECT_EQ(gfx::Rect(), surface->visible_layer_rect_for_testing());
8137 EXPECT_EQ(gfx::Rect(),
8138 descendant_of_animation->visible_layer_rect_for_testing());
ajumaa92fdc12015-03-31 22:47:418139}
8140
enne92f2f6d92015-02-25 23:13:318141// Verify that having an animated filter (but no current filter, as these
8142// are mutually exclusive) correctly creates a render surface.
8143TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
ajuma4711f4b12016-05-16 18:48:328144 LayerImpl* root = root_layer();
8145 LayerImpl* child = AddChild<LayerImpl>(root);
8146 LayerImpl* grandchild = AddChild<LayerImpl>(child);
enne92f2f6d92015-02-25 23:13:318147
8148 gfx::Transform identity_transform;
ajuma4711f4b12016-05-16 18:48:328149 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
enne92f2f6d92015-02-25 23:13:318150 gfx::PointF(), gfx::Size(50, 50), true, false);
ajuma4711f4b12016-05-16 18:48:328151 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
enne92f2f6d92015-02-25 23:13:318152 gfx::PointF(), gfx::Size(50, 50), true, false);
ajuma4711f4b12016-05-16 18:48:328153 SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(),
8154 gfx::PointF(), gfx::Size(50, 50), true, false);
enne92f2f6d92015-02-25 23:13:318155
ajuma4711f4b12016-05-16 18:48:328156 AddAnimatedFilterToLayerWithPlayer(child->id(), timeline_impl(), 10.0, 0.1f,
8157 0.2f);
8158 ExecuteCalculateDrawProperties(root);
enne92f2f6d92015-02-25 23:13:318159
ennec1332992015-08-24 19:45:098160 EXPECT_TRUE(root->has_render_surface());
8161 EXPECT_TRUE(child->has_render_surface());
8162 EXPECT_FALSE(grandchild->has_render_surface());
enne92f2f6d92015-02-25 23:13:318163
8164 EXPECT_TRUE(root->filters().IsEmpty());
8165 EXPECT_TRUE(child->filters().IsEmpty());
8166 EXPECT_TRUE(grandchild->filters().IsEmpty());
8167
8168 EXPECT_FALSE(root->FilterIsAnimating());
8169 EXPECT_TRUE(child->FilterIsAnimating());
8170 EXPECT_FALSE(grandchild->FilterIsAnimating());
8171}
8172
ajuma315a4782015-07-24 21:16:348173// Verify that having a filter animation with a delayed start time creates a
8174// render surface.
8175TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
ajuma4711f4b12016-05-16 18:48:328176 LayerImpl* root = root_layer();
8177 LayerImpl* child = AddChild<LayerImpl>(root);
8178 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma315a4782015-07-24 21:16:348179
8180 gfx::Transform identity_transform;
ajuma4711f4b12016-05-16 18:48:328181 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
ajuma315a4782015-07-24 21:16:348182 gfx::PointF(), gfx::Size(50, 50), true, false);
ajuma4711f4b12016-05-16 18:48:328183 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
ajuma315a4782015-07-24 21:16:348184 gfx::PointF(), gfx::Size(50, 50), true, false);
ajuma4711f4b12016-05-16 18:48:328185 SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(),
8186 gfx::PointF(), gfx::Size(50, 50), true, false);
ajuma315a4782015-07-24 21:16:348187
danakj60bc3bc2016-04-09 00:24:488188 std::unique_ptr<KeyframedFilterAnimationCurve> curve(
ajuma315a4782015-07-24 21:16:348189 KeyframedFilterAnimationCurve::Create());
8190 FilterOperations start_filters;
8191 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
8192 FilterOperations end_filters;
8193 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
8194 curve->AddKeyframe(
8195 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
8196 curve->AddKeyframe(FilterKeyframe::Create(
8197 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
danakj60bc3bc2016-04-09 00:24:488198 std::unique_ptr<Animation> animation =
loyso0c8e4402016-02-25 04:12:308199 Animation::Create(std::move(curve), 0, 1, TargetProperty::FILTER);
loysoc255f272016-05-18 02:53:558200 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348201 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
ajuma315a4782015-07-24 21:16:348202
ajuma4711f4b12016-05-16 18:48:328203 AddAnimationToLayerWithPlayer(child->id(), timeline_impl(),
8204 std::move(animation));
8205 ExecuteCalculateDrawProperties(root);
ajuma315a4782015-07-24 21:16:348206
ennec1332992015-08-24 19:45:098207 EXPECT_TRUE(root->has_render_surface());
8208 EXPECT_TRUE(child->has_render_surface());
8209 EXPECT_FALSE(grandchild->has_render_surface());
ajuma315a4782015-07-24 21:16:348210
8211 EXPECT_TRUE(root->filters().IsEmpty());
8212 EXPECT_TRUE(child->filters().IsEmpty());
8213 EXPECT_TRUE(grandchild->filters().IsEmpty());
8214
8215 EXPECT_FALSE(root->FilterIsAnimating());
8216 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
8217 EXPECT_FALSE(child->FilterIsAnimating());
8218 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
8219 EXPECT_FALSE(grandchild->FilterIsAnimating());
8220 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
8221}
8222
vollick0120eb22015-03-02 03:07:348223// Ensures that the property tree code accounts for offsets between fixed
8224// position layers and their respective containers.
8225TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
jaydasika6f972de2016-04-07 16:16:148226 LayerImpl* root = root_layer();
8227 LayerImpl* child = AddChild<LayerImpl>(root);
8228 LayerImpl* grandchild = AddChild<LayerImpl>(child);
vollick0120eb22015-03-02 03:07:348229
8230 gfx::Transform identity_transform;
jaydasika6f972de2016-04-07 16:16:148231 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
8232 gfx::PointF(), gfx::Size(50, 50), true, false,
8233 true);
8234 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
vollick0120eb22015-03-02 03:07:348235 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
jaydasika6f972de2016-04-07 16:16:148236 false, false);
8237 SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(),
8238 gfx::PointF(-1000, -1000), gfx::Size(50, 50),
8239 true, false, false);
vollick0120eb22015-03-02 03:07:348240
8241 root->SetMasksToBounds(true);
jaydasikaca2605e2016-04-23 02:52:528242 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick0120eb22015-03-02 03:07:348243 LayerPositionConstraint constraint;
8244 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528245 grandchild->test_properties()->position_constraint = constraint;
jaydasika6f972de2016-04-07 16:16:148246 grandchild->SetDrawsContent(true);
vollick0120eb22015-03-02 03:07:348247
jaydasikaca2605e2016-04-23 02:52:528248 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick0120eb22015-03-02 03:07:348249
jaydasika6f972de2016-04-07 16:16:148250 ExecuteCalculateDrawProperties(root);
vollick0120eb22015-03-02 03:07:348251
jaydasika6f972de2016-04-07 16:16:148252 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
vollick0120eb22015-03-02 03:07:348253}
8254
ajuma0178b522015-07-02 21:08:418255// Ensures that the property tree code accounts for offsets between fixed
8256// position containers and their transform tree parents, when a fixed position
8257// layer's container is its layer tree parent, but this parent doesn't have its
8258// own transform tree node.
8259TEST_F(LayerTreeHostCommonTest,
8260 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
jaydasika6f972de2016-04-07 16:16:148261 LayerImpl* root = root_layer();
8262 LayerImpl* child = AddChild<LayerImpl>(root);
8263 LayerImpl* grandchild = AddChild<LayerImpl>(child);
ajuma0178b522015-07-02 21:08:418264
8265 gfx::Transform identity_transform;
jaydasika6f972de2016-04-07 16:16:148266 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
8267 gfx::PointF(), gfx::Size(50, 50), true, false,
8268 true);
8269 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
ajuma0178b522015-07-02 21:08:418270 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
jaydasika6f972de2016-04-07 16:16:148271 false, false);
8272 SetLayerPropertiesForTesting(grandchild, identity_transform, gfx::Point3F(),
8273 gfx::PointF(-1000, -1000), gfx::Size(50, 50),
8274 true, false, false);
ajuma0178b522015-07-02 21:08:418275
8276 root->SetMasksToBounds(true);
jaydasikaca2605e2016-04-23 02:52:528277 child->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0178b522015-07-02 21:08:418278 LayerPositionConstraint constraint;
8279 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528280 grandchild->test_properties()->position_constraint = constraint;
jaydasika6f972de2016-04-07 16:16:148281 grandchild->SetDrawsContent(true);
ajuma0178b522015-07-02 21:08:418282
jaydasikaca2605e2016-04-23 02:52:528283 root->test_properties()->is_container_for_fixed_position_layers = true;
ajuma0178b522015-07-02 21:08:418284
jaydasika6f972de2016-04-07 16:16:148285 ExecuteCalculateDrawProperties(root);
ajuma0178b522015-07-02 21:08:418286
jaydasika6f972de2016-04-07 16:16:148287 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grandchild->visible_layer_rect());
ajuma0178b522015-07-02 21:08:418288}
8289
vollick67394b42015-03-10 00:22:308290TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) {
8291 // In the following layer tree, the layer |box|'s render target is |surface|.
8292 // |surface| also creates a transform node. We want to combine clips for |box|
8293 // in the space of its target (i.e., |surface|), not its target's target. This
8294 // test ensures that happens.
8295
8296 gfx::Transform rotate;
8297 rotate.Rotate(5);
8298 gfx::Transform identity;
8299
loyso0940d412016-03-14 01:30:318300 scoped_refptr<Layer> root = Layer::Create();
vollick67394b42015-03-10 00:22:308301 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8302 gfx::PointF(), gfx::Size(2500, 1500), true,
8303 false);
8304
loyso0940d412016-03-14 01:30:318305 scoped_refptr<Layer> frame_clip = Layer::Create();
vollick67394b42015-03-10 00:22:308306 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8307 gfx::PointF(), gfx::Size(2500, 1500), true,
8308 false);
8309 frame_clip->SetMasksToBounds(true);
8310
loyso0940d412016-03-14 01:30:318311 scoped_refptr<Layer> rotated = Layer::Create();
vollick67394b42015-03-10 00:22:308312 SetLayerPropertiesForTesting(rotated.get(), rotate,
8313 gfx::Point3F(1250, 250, 0), gfx::PointF(),
8314 gfx::Size(2500, 500), true, false);
8315
loyso0940d412016-03-14 01:30:318316 scoped_refptr<Layer> surface = Layer::Create();
vollick67394b42015-03-10 00:22:308317 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(),
8318 gfx::PointF(), gfx::Size(2500, 500), true,
8319 false);
8320 surface->SetOpacity(0.5);
8321
8322 scoped_refptr<LayerWithForcedDrawsContent> container =
loyso0940d412016-03-14 01:30:318323 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick67394b42015-03-10 00:22:308324 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(),
8325 gfx::PointF(), gfx::Size(300, 300), true, false);
8326
8327 scoped_refptr<LayerWithForcedDrawsContent> box =
loyso0940d412016-03-14 01:30:318328 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick67394b42015-03-10 00:22:308329 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(),
8330 gfx::PointF(), gfx::Size(100, 100), true, false);
8331
8332 root->AddChild(frame_clip);
8333 frame_clip->AddChild(rotated);
8334 rotated->AddChild(surface);
8335 surface->AddChild(container);
8336 surface->AddChild(box);
8337
ennea7b43c32015-06-18 20:01:338338 host()->SetRootLayer(root);
vollick67394b42015-03-10 00:22:308339
8340 ExecuteCalculateDrawProperties(root.get());
8341}
8342
vollick8c824742015-03-20 22:21:088343TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
jaydasika6f972de2016-04-07 16:16:148344 LayerImpl* root = root_layer();
8345 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8346 LayerImpl* fixed = AddChild<LayerImpl>(frame_clip);
vollick8c824742015-03-20 22:21:088347 gfx::Transform identity;
8348 gfx::Transform translate_z;
8349 translate_z.Translate3d(0, 0, 10);
8350
jaydasika6f972de2016-04-07 16:16:148351 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
8352 gfx::Size(800, 800), true, false, true);
jaydasikaca2605e2016-04-23 02:52:528353 root->test_properties()->is_container_for_fixed_position_layers = true;
vollick8c824742015-03-20 22:21:088354
jaydasika6f972de2016-04-07 16:16:148355 SetLayerPropertiesForTesting(frame_clip, translate_z, gfx::Point3F(),
vollick8c824742015-03-20 22:21:088356 gfx::PointF(500, 100), gfx::Size(100, 100), true,
jaydasika6f972de2016-04-07 16:16:148357 false, false);
vollick8c824742015-03-20 22:21:088358 frame_clip->SetMasksToBounds(true);
8359
jaydasika6f972de2016-04-07 16:16:148360 SetLayerPropertiesForTesting(fixed, identity, gfx::Point3F(), gfx::PointF(),
8361 gfx::Size(1000, 1000), true, false, false);
vollick8c824742015-03-20 22:21:088362
8363 LayerPositionConstraint constraint;
8364 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528365 fixed->test_properties()->position_constraint = constraint;
jaydasika6f972de2016-04-07 16:16:148366 fixed->SetDrawsContent(true);
vollick8c824742015-03-20 22:21:088367
jaydasika6f972de2016-04-07 16:16:148368 ExecuteCalculateDrawProperties(root);
vollick8c824742015-03-20 22:21:088369
8370 gfx::Rect expected(0, 0, 100, 100);
jaydasika6f972de2016-04-07 16:16:148371 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick8c824742015-03-20 22:21:088372}
8373
vollick06ca3e832015-03-31 19:37:128374TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
jaydasika6f972de2016-04-07 16:16:148375 LayerImpl* root = root_layer();
8376 LayerImpl* frame_clip = AddChild<LayerImpl>(root);
8377 LayerImpl* scroller = AddChild<LayerImpl>(frame_clip);
8378 LayerImpl* fixed = AddChild<LayerImpl>(scroller);
8379
vollick06ca3e832015-03-31 19:37:128380 gfx::Transform identity;
jaydasika6f972de2016-04-07 16:16:148381 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
8382 gfx::Size(800, 800), true, false, true);
8383 SetLayerPropertiesForTesting(frame_clip, identity, gfx::Point3F(),
vollick06ca3e832015-03-31 19:37:128384 gfx::PointF(500, 100), gfx::Size(100, 100), true,
jaydasika6f972de2016-04-07 16:16:148385 false, false);
8386 SetLayerPropertiesForTesting(scroller, identity, gfx::Point3F(),
vollick06ca3e832015-03-31 19:37:128387 gfx::PointF(), gfx::Size(1000, 1000), true,
jaydasika6f972de2016-04-07 16:16:148388 false, false);
8389 SetLayerPropertiesForTesting(fixed, identity, gfx::Point3F(),
vollick06ca3e832015-03-31 19:37:128390 gfx::PointF(100, 100), gfx::Size(50, 50), true,
jaydasika6f972de2016-04-07 16:16:148391 false, true);
8392
jaydasikaca2605e2016-04-23 02:52:528393 root->test_properties()->is_container_for_fixed_position_layers = true;
jaydasika6f972de2016-04-07 16:16:148394 root->SetDrawsContent(true);
8395
8396 frame_clip->SetMasksToBounds(true);
8397 frame_clip->SetDrawsContent(true);
8398
8399 scroller->SetCurrentScrollOffset(gfx::ScrollOffset(100, 100));
8400 scroller->SetScrollClipLayer(frame_clip->id());
8401 scroller->SetDrawsContent(true);
vollick06ca3e832015-03-31 19:37:128402
8403 LayerPositionConstraint constraint;
8404 constraint.set_is_fixed_position(true);
jaydasikaca2605e2016-04-23 02:52:528405 fixed->test_properties()->position_constraint = constraint;
vollick06ca3e832015-03-31 19:37:128406 fixed->SetMasksToBounds(true);
jaydasika6f972de2016-04-07 16:16:148407 fixed->SetDrawsContent(true);
vollick06ca3e832015-03-31 19:37:128408
jaydasika6f972de2016-04-07 16:16:148409 ExecuteCalculateDrawProperties(root);
vollick06ca3e832015-03-31 19:37:128410
8411 gfx::Rect expected(0, 0, 50, 50);
jaydasika6f972de2016-04-07 16:16:148412 EXPECT_EQ(expected, fixed->visible_layer_rect());
vollick06ca3e832015-03-31 19:37:128413}
8414
vollick5057e1e2015-04-17 19:12:328415TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
8416 gfx::Transform identity;
8417 gfx::Transform translate;
8418 gfx::Transform rotate;
8419
8420 translate.Translate(10, 10);
8421 rotate.Rotate(45);
8422
loyso0940d412016-03-14 01:30:318423 scoped_refptr<Layer> root = Layer::Create();
vollick5057e1e2015-04-17 19:12:328424 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8425 gfx::PointF(), gfx::Size(800, 800), true, false);
8426 root->SetIsContainerForFixedPositionLayers(true);
8427
ennea7b43c32015-06-18 20:01:338428 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:328429
enne601f2ef12015-05-19 18:20:178430 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ennea7b43c32015-06-18 20:01:338431 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328432
8433 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:338434 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328435
8436 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:338437 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328438}
8439
ajumab0e0c1c2015-04-23 00:29:238440TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
jaydasika6f972de2016-04-07 16:16:148441 LayerImpl* root = root_layer();
8442 LayerImpl* child = AddChild<LayerImpl>(root);
ajumab0e0c1c2015-04-23 00:29:238443
8444 gfx::Transform identity_matrix;
8445 gfx::Transform scale_matrix;
8446 scale_matrix.Scale(2.f, 2.f);
jaydasika6f972de2016-04-07 16:16:148447 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
8448 gfx::PointF(), gfx::Size(100, 100), true, false,
8449 true);
8450 SetLayerPropertiesForTesting(child, scale_matrix, gfx::Point3F(),
8451 gfx::PointF(), gfx::Size(10, 10), true, false,
8452 false);
ajumab0e0c1c2015-04-23 00:29:238453
jaydasika6f972de2016-04-07 16:16:148454 root->SetDrawsContent(true);
8455 child->SetDrawsContent(true);
8456
8457 ExecuteCalculateDrawProperties(root);
8458 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238459
jaydasika38be7a822016-04-21 16:07:068460 child->test_properties()->transform_origin = gfx::Point3F(10.f, 10.f, 10.f);
ajumab0e0c1c2015-04-23 00:29:238461
jaydasika6f972de2016-04-07 16:16:148462 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8463 ExecuteCalculateDrawProperties(root);
8464 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_layer_rect());
ajumab0e0c1c2015-04-23 00:29:238465}
8466
ajumaf09db8962015-04-24 21:55:348467TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
jaydasika6f972de2016-04-07 16:16:148468 LayerImpl* root = root_layer();
8469 LayerImpl* scroll_parent = AddChild<LayerImpl>(root);
8470 LayerImpl* scroll_child = AddChild<LayerImpl>(scroll_parent);
ajumaf09db8962015-04-24 21:55:348471
jaydasika6f972de2016-04-07 16:16:148472 scroll_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:568473 scroll_child->test_properties()->scroll_parent = scroll_parent;
danakj60bc3bc2016-04-09 00:24:488474 std::unique_ptr<std::set<LayerImpl*>> scroll_children(
8475 new std::set<LayerImpl*>);
jaydasika6f972de2016-04-07 16:16:148476 scroll_children->insert(scroll_child);
jaydasika1c0a27d42016-04-28 01:54:568477 scroll_parent->test_properties()->scroll_children.reset(
8478 scroll_children.release());
jaydasika6f972de2016-04-07 16:16:148479 scroll_parent->SetDrawsContent(true);
ajumaf09db8962015-04-24 21:55:348480
8481 gfx::Transform identity_transform;
8482 gfx::Transform scale;
8483 scale.Scale(2.f, 2.f);
jaydasika6f972de2016-04-07 16:16:148484 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
8485 gfx::PointF(), gfx::Size(50, 50), true, false,
8486 true);
8487 SetLayerPropertiesForTesting(scroll_child, scale, gfx::Point3F(),
8488 gfx::PointF(), gfx::Size(40, 40), true, false,
8489 false);
8490 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
ajumaf09db8962015-04-24 21:55:348491 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
jaydasika6f972de2016-04-07 16:16:148492 true, false, false);
ajumaf09db8962015-04-24 21:55:348493
jaydasika6f972de2016-04-07 16:16:148494 ExecuteCalculateDrawProperties(root);
8495 EXPECT_EQ(gfx::Rect(25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348496
8497 scroll_child->SetPosition(gfx::PointF(0, -10.f));
jaydasika6f972de2016-04-07 16:16:148498 scroll_parent->SetCurrentScrollOffset(gfx::ScrollOffset(0.f, 10.f));
8499 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8500 ExecuteCalculateDrawProperties(root);
8501 EXPECT_EQ(gfx::Rect(0, 5, 25, 25), scroll_child->visible_layer_rect());
ajumaf09db8962015-04-24 21:55:348502}
8503
danakj60bc3bc2016-04-09 00:24:488504static void CopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {}
vollick2175fae82015-04-27 21:18:128505
sunxded58688e2016-01-11 21:01:028506TEST_F(LayerTreeHostCommonTest, NumCopyRequestsInTargetSubtree) {
8507 // If the layer has a node in effect_tree, the return value of
8508 // num_copy_requests_in_target_subtree() must be equal to the actual number
8509 // of copy requests in the sub-layer_tree; Otherwise, the number is expected
8510 // to be the value of its nearest ancestor that owns an effect node and
8511 // greater than or equal to the actual number of copy requests in the
8512 // sub-layer_tree.
8513
loyso0940d412016-03-14 01:30:318514 scoped_refptr<Layer> root = Layer::Create();
8515 scoped_refptr<Layer> child1 = Layer::Create();
8516 scoped_refptr<Layer> child2 = Layer::Create();
8517 scoped_refptr<Layer> grandchild = Layer::Create();
8518 scoped_refptr<Layer> greatgrandchild = Layer::Create();
sunxded58688e2016-01-11 21:01:028519
8520 root->AddChild(child1);
8521 root->AddChild(child2);
8522 child1->AddChild(grandchild);
8523 grandchild->AddChild(greatgrandchild);
8524 host()->SetRootLayer(root);
8525
8526 child1->RequestCopyOfOutput(
8527 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8528 greatgrandchild->RequestCopyOfOutput(
8529 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
8530 child2->SetOpacity(0.f);
8531 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8532
8533 EXPECT_EQ(root->num_copy_requests_in_target_subtree(), 2);
8534 EXPECT_EQ(child1->num_copy_requests_in_target_subtree(), 2);
8535 EXPECT_EQ(child2->num_copy_requests_in_target_subtree(), 0);
8536 EXPECT_EQ(grandchild->num_copy_requests_in_target_subtree(), 2);
8537 EXPECT_EQ(greatgrandchild->num_copy_requests_in_target_subtree(), 1);
8538}
8539
vollick2175fae82015-04-27 21:18:128540TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
8541 gfx::Transform identity;
loyso0940d412016-03-14 01:30:318542 scoped_refptr<Layer> root = Layer::Create();
chrishtr01539b802015-11-24 08:11:328543 FakeContentLayerClient client;
8544 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:128545 scoped_refptr<LayerWithForcedDrawsContent> child =
loyso0940d412016-03-14 01:30:318546 make_scoped_refptr(new LayerWithForcedDrawsContent());
vollick2175fae82015-04-27 21:18:128547 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loyso0940d412016-03-14 01:30:318548 make_scoped_refptr(new LayerWithForcedDrawsContent());
danakj4e95f7632015-06-05 19:46:258549 scoped_refptr<FakePictureLayer> greatgrandchild(
loyso0940d412016-03-14 01:30:318550 FakePictureLayer::Create(&client));
vollick2175fae82015-04-27 21:18:128551 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8552 gfx::PointF(), gfx::Size(100, 100), true, false);
8553 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8554 gfx::PointF(), gfx::Size(10, 10), true, false);
8555 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8556 gfx::PointF(), gfx::Size(10, 10), true, false);
8557 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
8558 gfx::PointF(), gfx::Size(10, 10), true, false);
8559
8560 root->AddChild(child);
8561 child->AddChild(grandchild);
8562 grandchild->AddChild(greatgrandchild);
8563
ennea7b43c32015-06-18 20:01:338564 host()->SetRootLayer(root);
vollick2175fae82015-04-27 21:18:128565
8566 // Check the non-skipped case.
enne601f2ef12015-05-19 18:20:178567 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158568 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128569
8570 // Now we will reset the visible rect from property trees for the grandchild,
8571 // and we will configure |child| in several ways that should force the subtree
8572 // to be skipped. The visible content rect for |grandchild| should, therefore,
8573 // remain empty.
weiliangcc97575c2016-03-03 18:34:278574 grandchild->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:128575 gfx::Transform singular;
8576 singular.matrix().set(0, 0, 0);
8577
8578 child->SetTransform(singular);
enne601f2ef12015-05-19 18:20:178579 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158580 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128581 child->SetTransform(identity);
8582
8583 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:178584 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158585 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128586 child->SetHideLayerAndSubtree(false);
8587
ajuma315a4782015-07-24 21:16:348588 gfx::Transform zero_z_scale;
8589 zero_z_scale.Scale3d(1, 1, 0);
8590 child->SetTransform(zero_z_scale);
8591
8592 // Add a transform animation with a start delay. Now, even though |child| has
8593 // a singular transform, the subtree should still get processed.
8594 int animation_id = 0;
danakj60bc3bc2016-04-09 00:24:488595 std::unique_ptr<Animation> animation = Animation::Create(
8596 std::unique_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
loyso0c8e4402016-02-25 04:12:308597 animation_id, 1, TargetProperty::TRANSFORM);
loysoc255f272016-05-18 02:53:558598 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348599 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso9556c732016-03-11 07:54:588600 AddAnimationToLayerWithPlayer(child->id(), timeline(), std::move(animation));
ajuma315a4782015-07-24 21:16:348601 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158602 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
weiliangcc97575c2016-03-03 18:34:278603 grandchild->set_visible_layer_rect(gfx::Rect());
ajuma315a4782015-07-24 21:16:348604
loyso9556c732016-03-11 07:54:588605 RemoveAnimationFromLayerWithExistingPlayer(child->id(), timeline(),
8606 animation_id);
ajuma315a4782015-07-24 21:16:348607 child->SetTransform(identity);
vollick2175fae82015-04-27 21:18:128608 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:178609 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158610 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128611
8612 // Now, even though child has zero opacity, we will configure |grandchild| and
8613 // |greatgrandchild| in several ways that should force the subtree to be
8614 // processed anyhow.
jaydasika86654512016-01-27 17:05:078615 grandchild->RequestCopyOfOutput(
vollick2175fae82015-04-27 21:18:128616 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
enne601f2ef12015-05-19 18:20:178617 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158618 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
weiliangcc97575c2016-03-03 18:34:278619 greatgrandchild->set_visible_layer_rect(gfx::Rect());
ajuma315a4782015-07-24 21:16:348620
8621 // Add an opacity animation with a start delay.
8622 animation_id = 1;
8623 animation = Animation::Create(
danakj60bc3bc2016-04-09 00:24:488624 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
loyso0c8e4402016-02-25 04:12:308625 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:558626 animation->set_fill_mode(Animation::FillMode::NONE);
ajuma315a4782015-07-24 21:16:348627 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
loyso9556c732016-03-11 07:54:588628 AddAnimationToLayerWithExistingPlayer(child->id(), timeline(),
8629 std::move(animation));
ajuma315a4782015-07-24 21:16:348630 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
jaydasika74bf516f2016-04-01 19:48:158631 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_layer_rect_for_testing());
vollick2175fae82015-04-27 21:18:128632}
8633
sunxd71aea3e2016-04-01 23:48:058634TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:168635 FakeImplTaskRunnerProvider task_runner_provider;
vollick2175fae82015-04-27 21:18:128636 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:568637 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:168638 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:568639 &task_graph_runner);
vollick2175fae82015-04-27 21:18:128640
8641 gfx::Transform identity;
danakj60bc3bc2016-04-09 00:24:488642 std::unique_ptr<LayerImpl> root =
8643 LayerImpl::Create(host_impl.active_tree(), 1);
8644 std::unique_ptr<LayerImpl> child =
8645 LayerImpl::Create(host_impl.active_tree(), 2);
8646 std::unique_ptr<LayerImpl> grandchild =
vollick2175fae82015-04-27 21:18:128647 LayerImpl::Create(host_impl.active_tree(), 3);
8648
danakj60bc3bc2016-04-09 00:24:488649 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
danakj4e95f7632015-06-05 19:46:258650 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:128651
8652 child->SetDrawsContent(true);
8653 grandchild->SetDrawsContent(true);
8654 greatgrandchild->SetDrawsContent(true);
8655
8656 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8657 gfx::PointF(), gfx::Size(100, 100), true, false,
8658 true);
8659 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8660 gfx::PointF(), gfx::Size(10, 10), true, false,
8661 false);
8662 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8663 gfx::PointF(), gfx::Size(10, 10), true, false,
8664 false);
vollick2175fae82015-04-27 21:18:128665
jaydasika2411692c2016-03-23 01:56:098666 LayerImpl* root_ptr = root.get();
vollick2175fae82015-04-27 21:18:128667 LayerImpl* child_ptr = child.get();
8668 LayerImpl* grandchild_ptr = grandchild.get();
vollick2175fae82015-04-27 21:18:128669
danakja04855a2015-11-18 20:39:108670 child->AddChild(std::move(grandchild));
8671 root->AddChild(std::move(child));
jaydasika2411692c2016-03-23 01:56:098672 host_impl.active_tree()->SetRootLayer(std::move(root));
vollick2175fae82015-04-27 21:18:128673
8674 // Check the non-skipped case.
sunxd71aea3e2016-04-01 23:48:058675 // ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8676 // EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128677
8678 // Now we will reset the visible rect from property trees for the grandchild,
8679 // and we will configure |child| in several ways that should force the subtree
8680 // to be skipped. The visible content rect for |grandchild| should, therefore,
8681 // remain empty.
weiliangcc97575c2016-03-03 18:34:278682 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
sunxd71aea3e2016-04-01 23:48:058683
vollick2175fae82015-04-27 21:18:128684 gfx::Transform singular;
8685 singular.matrix().set(0, 0, 0);
sunxd71aea3e2016-04-01 23:48:058686 // This line is used to make the results of skipping and not skipping layers
8687 // different.
8688 singular.matrix().set(0, 1, 1);
8689
8690 gfx::Transform rotate;
8691 rotate.Rotate(90);
8692
8693 gfx::Transform rotate_back_and_translate;
8694 rotate_back_and_translate.RotateAboutYAxis(180);
8695 rotate_back_and_translate.Translate(-10, 0);
vollick2175fae82015-04-27 21:18:128696
8697 child_ptr->SetTransform(singular);
sunxd71aea3e2016-04-01 23:48:058698 host_impl.active_tree()->property_trees()->needs_rebuild = true;
jaydasika2411692c2016-03-23 01:56:098699 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278700 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128701 child_ptr->SetTransform(identity);
8702
jaydasika5121caa82016-05-05 15:43:358703 child_ptr->test_properties()->hide_layer_and_subtree = true;
jaydasika2411692c2016-03-23 01:56:098704 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278705 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:358706 child_ptr->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:128707
8708 child_ptr->SetOpacity(0.f);
jaydasika2411692c2016-03-23 01:56:098709 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278710 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:058711 child_ptr->SetOpacity(1.f);
vollick2175fae82015-04-27 21:18:128712
sunxd71aea3e2016-04-01 23:48:058713 root_ptr->SetTransform(singular);
8714 // Force transform tree to have a node for child, so that ancestor's
8715 // invertible transform can be tested.
8716 child_ptr->SetTransform(rotate);
8717 host_impl.active_tree()->property_trees()->needs_rebuild = true;
8718 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8719 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
8720 root_ptr->SetTransform(identity);
8721 child_ptr->SetTransform(identity);
8722
8723 root_ptr->SetOpacity(0.f);
8724 child_ptr->SetOpacity(0.7f);
8725 host_impl.active_tree()->property_trees()->needs_rebuild = true;
8726 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8727 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
8728 root_ptr->SetOpacity(1.f);
8729
8730 child_ptr->SetOpacity(0.f);
vollick2175fae82015-04-27 21:18:128731 // Now, even though child has zero opacity, we will configure |grandchild| and
8732 // |greatgrandchild| in several ways that should force the subtree to be
8733 // processed anyhow.
danakj60bc3bc2016-04-09 00:24:488734 std::vector<std::unique_ptr<CopyOutputRequest>> requests;
vollick2175fae82015-04-27 21:18:128735 requests.push_back(CopyOutputRequest::CreateEmptyRequest());
8736
jaydasika86654512016-01-27 17:05:078737 grandchild_ptr->PassCopyRequests(&requests);
jaydasika2411692c2016-03-23 01:56:098738 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8739 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
weiliangcc97575c2016-03-03 18:34:278740 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:058741 requests.clear();
8742 grandchild_ptr->PassCopyRequests(&requests);
8743 child_ptr->SetOpacity(1.f);
8744
8745 // A double sided render surface with backface visible should not be skipped
8746 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
8747 child_ptr->SetHasRenderSurface(true);
jaydasika6b5a32bf2016-04-22 21:56:368748 child_ptr->test_properties()->double_sided = true;
sunxd71aea3e2016-04-01 23:48:058749 child_ptr->SetTransform(rotate_back_and_translate);
8750 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8751 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8752 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
8753 child_ptr->SetTransform(identity);
8754
danakj60bc3bc2016-04-09 00:24:488755 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:058756 KeyframedTransformAnimationCurve::Create());
8757 TransformOperations start;
8758 start.AppendTranslate(1.f, 2.f, 3.f);
8759 gfx::Transform transform;
8760 transform.Scale3d(1.0, 2.0, 3.0);
8761 TransformOperations operation;
8762 operation.AppendMatrix(transform);
8763 curve->AddKeyframe(
8764 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8765 curve->AddKeyframe(TransformKeyframe::Create(
8766 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj60bc3bc2016-04-09 00:24:488767 std::unique_ptr<Animation> transform_animation(
sunxd71aea3e2016-04-01 23:48:058768 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8769 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:588770 host_impl.active_tree()->animation_host()->RegisterPlayerForElement(
sunxd71aea3e2016-04-01 23:48:058771 root_ptr->id(), player.get());
8772 host_impl.active_tree()
8773 ->animation_host()
loysofb69174e2016-04-27 00:58:588774 ->GetElementAnimationsForElementId(root_ptr->id())
sunxd71aea3e2016-04-01 23:48:058775 ->AddAnimation(std::move(transform_animation));
8776 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
8777 child_ptr->SetScrollClipLayer(root_ptr->id());
8778 root_ptr->SetTransform(singular);
8779 child_ptr->SetTransform(singular);
8780 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8781 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
jaydasikaf187b06b2016-04-11 23:30:278782 EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect());
sunxd71aea3e2016-04-01 23:48:058783
loysofb69174e2016-04-27 00:58:588784 host_impl.active_tree()->animation_host()->UnregisterPlayerForElement(
sunxd71aea3e2016-04-01 23:48:058785 root_ptr->id(), player.get());
8786}
8787
jaydasikaf187b06b2016-04-11 23:30:278788TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) {
8789 LayerImpl* root = root_layer();
8790 LayerImpl* child = AddChild<LayerImpl>(root);
8791 LayerImpl* grand_child = AddChild<LayerImpl>(child);
8792
8793 gfx::Transform identity;
8794 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
8795 gfx::Size(10, 10), true, false, true);
8796 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
8797 gfx::Size(10, 10), true, false, false);
8798 SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(),
8799 gfx::PointF(), gfx::Size(10, 10), true, false,
8800 false);
8801
8802 gfx::Transform singular;
8803 singular.matrix().set(0, 0, 0);
8804 singular.matrix().set(0, 1, 1);
8805
8806 child->SetTransform(singular);
8807 child->SetDrawsContent(true);
8808 grand_child->SetDrawsContent(true);
8809
danakj25c52c32016-04-12 21:51:088810 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
jaydasikaf187b06b2016-04-11 23:30:278811 KeyframedTransformAnimationCurve::Create());
8812 TransformOperations start;
8813 start.AppendTranslate(1.f, 2.f, 3.f);
8814 gfx::Transform transform;
8815 transform.Scale3d(1.0, 2.0, 3.0);
8816 TransformOperations operation;
8817 operation.AppendMatrix(transform);
8818 curve->AddKeyframe(
8819 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
8820 curve->AddKeyframe(TransformKeyframe::Create(
8821 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
danakj25c52c32016-04-12 21:51:088822 std::unique_ptr<Animation> transform_animation(
jaydasikaf187b06b2016-04-11 23:30:278823 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
8824 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:588825 host_impl()->active_tree()->animation_host()->RegisterPlayerForElement(
jaydasikaf187b06b2016-04-11 23:30:278826 grand_child->id(), player.get());
8827 host_impl()
8828 ->active_tree()
8829 ->animation_host()
loysofb69174e2016-04-27 00:58:588830 ->GetElementAnimationsForElementId(grand_child->id())
jaydasikaf187b06b2016-04-11 23:30:278831 ->AddAnimation(std::move(transform_animation));
8832
8833 ExecuteCalculateDrawProperties(root);
8834 EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect());
8835 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
8836
loysofb69174e2016-04-27 00:58:588837 host_impl()->active_tree()->animation_host()->UnregisterPlayerForElement(
jaydasikaf187b06b2016-04-11 23:30:278838 grand_child->id(), player.get());
8839}
8840
sunxd71aea3e2016-04-01 23:48:058841TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) {
8842 FakeImplTaskRunnerProvider task_runner_provider;
8843 TestSharedBitmapManager shared_bitmap_manager;
8844 TestTaskGraphRunner task_graph_runner;
8845 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
8846 &task_graph_runner);
8847
8848 gfx::Transform identity;
8849 host_impl.CreatePendingTree();
danakj60bc3bc2016-04-09 00:24:488850 std::unique_ptr<LayerImpl> root =
8851 LayerImpl::Create(host_impl.pending_tree(), 1);
8852 std::unique_ptr<LayerImpl> child =
8853 LayerImpl::Create(host_impl.pending_tree(), 2);
8854 std::unique_ptr<LayerImpl> grandchild =
sunxd71aea3e2016-04-01 23:48:058855 LayerImpl::Create(host_impl.pending_tree(), 3);
8856
danakj60bc3bc2016-04-09 00:24:488857 std::unique_ptr<FakePictureLayerImpl> greatgrandchild(
sunxd71aea3e2016-04-01 23:48:058858 FakePictureLayerImpl::Create(host_impl.pending_tree(), 4));
8859
8860 child->SetDrawsContent(true);
8861 grandchild->SetDrawsContent(true);
8862 greatgrandchild->SetDrawsContent(true);
8863
8864 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8865 gfx::PointF(), gfx::Size(100, 100), true, false,
8866 true);
8867 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8868 gfx::PointF(), gfx::Size(10, 10), true, false,
8869 false);
8870 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8871 gfx::PointF(), gfx::Size(10, 10), true, false,
8872 false);
8873
8874 LayerImpl* root_ptr = root.get();
8875 LayerImpl* grandchild_ptr = grandchild.get();
8876
8877 child->AddChild(std::move(grandchild));
8878 root->AddChild(std::move(child));
8879
8880 host_impl.pending_tree()->SetRootLayer(std::move(root));
8881
8882 // Check the non-skipped case.
8883 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8884 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
8885
danakj60bc3bc2016-04-09 00:24:488886 std::unique_ptr<KeyframedFloatAnimationCurve> curve(
sunxd71aea3e2016-04-01 23:48:058887 KeyframedFloatAnimationCurve::Create());
danakj60bc3bc2016-04-09 00:24:488888 std::unique_ptr<TimingFunction> func = EaseTimingFunction::Create();
sunxd71aea3e2016-04-01 23:48:058889 curve->AddKeyframe(
8890 FloatKeyframe::Create(base::TimeDelta(), 0.9f, std::move(func)));
8891 curve->AddKeyframe(
8892 FloatKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), 0.3f, nullptr));
danakj60bc3bc2016-04-09 00:24:488893 std::unique_ptr<Animation> animation(
sunxd71aea3e2016-04-01 23:48:058894 Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY));
8895 scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1));
loysofb69174e2016-04-27 00:58:588896 host_impl.active_tree()->animation_host()->RegisterPlayerForElement(
sunxd71aea3e2016-04-01 23:48:058897 root_ptr->id(), player.get());
8898 host_impl.active_tree()
8899 ->animation_host()
loysofb69174e2016-04-27 00:58:588900 ->GetElementAnimationsForElementId(root_ptr->id())
sunxd71aea3e2016-04-01 23:48:058901 ->AddAnimation(std::move(animation));
8902 root_ptr->SetOpacity(0);
8903 grandchild_ptr->set_visible_layer_rect(gfx::Rect());
8904 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true;
8905 ExecuteCalculateDrawPropertiesWithPropertyTrees(root_ptr);
8906 EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect());
8907
loysofb69174e2016-04-27 00:58:588908 host_impl.active_tree()->animation_host()->UnregisterPlayerForElement(
sunxd71aea3e2016-04-01 23:48:058909 root_ptr->id(), player.get());
vollick2175fae82015-04-27 21:18:128910}
8911
8912TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
8913 gfx::Transform identity;
jaydasika6f972de2016-04-07 16:16:148914 LayerImpl* root = root_layer();
8915 LayerImpl* child = AddChild<LayerImpl>(root);
vollick2175fae82015-04-27 21:18:128916
jaydasika6f972de2016-04-07 16:16:148917 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
8918 gfx::Size(100, 100), true, false, true);
8919 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
8920 gfx::Size(10, 10), true, false, false);
8921 child->SetDrawsContent(true);
vollick2175fae82015-04-27 21:18:128922
jaydasika6f972de2016-04-07 16:16:148923 ExecuteCalculateDrawProperties(root);
8924 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect());
weiliangcc97575c2016-03-03 18:34:278925 child->set_visible_layer_rect(gfx::Rect());
vollick2175fae82015-04-27 21:18:128926
jaydasika5121caa82016-05-05 15:43:358927 child->test_properties()->hide_layer_and_subtree = true;
jaydasika6f972de2016-04-07 16:16:148928 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8929 ExecuteCalculateDrawProperties(root);
8930 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika5121caa82016-05-05 15:43:358931 child->test_properties()->hide_layer_and_subtree = false;
vollick2175fae82015-04-27 21:18:128932
8933 child->SetBounds(gfx::Size());
jaydasika6f972de2016-04-07 16:16:148934 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8935 ExecuteCalculateDrawProperties(root);
8936 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128937 child->SetBounds(gfx::Size(10, 10));
8938
8939 gfx::Transform rotate;
jaydasika6b5a32bf2016-04-22 21:56:368940 child->test_properties()->double_sided = false;
vollick2175fae82015-04-27 21:18:128941 rotate.RotateAboutXAxis(180.f);
8942 child->SetTransform(rotate);
jaydasika6f972de2016-04-07 16:16:148943 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8944 ExecuteCalculateDrawProperties(root);
8945 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
jaydasika6b5a32bf2016-04-22 21:56:368946 child->test_properties()->double_sided = true;
vollick2175fae82015-04-27 21:18:128947 child->SetTransform(identity);
8948
8949 child->SetOpacity(0.f);
jaydasika6f972de2016-04-07 16:16:148950 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
8951 ExecuteCalculateDrawProperties(root);
8952 EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect());
vollick2175fae82015-04-27 21:18:128953}
8954
jaydasika3d10aa62015-05-06 17:50:448955TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
8956 // Ensure that the treewalk in LayerTreeHostCommom::
8957 // PreCalculateMetaInformation happens when its required.
loyso0940d412016-03-14 01:30:318958 scoped_refptr<Layer> root = Layer::Create();
8959 scoped_refptr<Layer> parent = Layer::Create();
8960 scoped_refptr<Layer> child = Layer::Create();
jaydasika3d10aa62015-05-06 17:50:448961
8962 root->AddChild(parent);
8963 parent->AddChild(child);
8964
8965 child->SetClipParent(root.get());
8966
8967 gfx::Transform identity;
8968
8969 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8970 gfx::PointF(), gfx::Size(100, 100), true, false);
8971 SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(),
8972 gfx::PointF(), gfx::Size(100, 100), true, false);
8973 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8974 gfx::PointF(), gfx::Size(100, 100), true, false);
8975
ennea7b43c32015-06-18 20:01:338976 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:448977
jaydasika3d10aa62015-05-06 17:50:448978 child->RequestCopyOfOutput(
8979 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
sunxded58688e2016-01-11 21:01:028980
8981 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8982 EXPECT_EQ(parent->num_unclipped_descendants(), 1u);
8983
8984 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
8985 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8986 EXPECT_GT(root->num_copy_requests_in_target_subtree(), 0);
jaydasika3d10aa62015-05-06 17:50:448987}
8988
vollick692444f2015-05-20 15:39:148989TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
8990 gfx::Transform identity;
8991 gfx::Transform translate_z;
8992 translate_z.Translate3d(0, 0, 10);
8993
loyso0940d412016-03-14 01:30:318994 scoped_refptr<Layer> root = Layer::Create();
vollick692444f2015-05-20 15:39:148995 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8996 gfx::PointF(), gfx::Size(800, 800), true, false);
8997
loyso0940d412016-03-14 01:30:318998 scoped_refptr<Layer> child = Layer::Create();
vollick692444f2015-05-20 15:39:148999 SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(),
9000 gfx::PointF(), gfx::Size(100, 100), true, false);
9001
9002 root->AddChild(child);
9003
ennea7b43c32015-06-18 20:01:339004 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:149005
9006 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9007 EXPECT_NE(-1, child->transform_tree_index());
9008
9009 child->RemoveFromParent();
9010
9011 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9012 EXPECT_EQ(-1, child->transform_tree_index());
9013}
9014
jaydasika67d7989e2015-08-06 21:55:349015TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
9016 // Ensure that a Clip Node is added when a render surface applies clip.
9017 LayerImpl* root = root_layer();
9018 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
9019 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
9020 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
9021 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9022
9023 const gfx::Transform identity_matrix;
9024 // This transform should be a significant one so that a transform node is
9025 // formed for it.
9026 gfx::Transform transform1;
9027 transform1.RotateAboutYAxis(45);
9028 transform1.RotateAboutXAxis(30);
9029 // This transform should be a 3d transform as we want the render surface
9030 // to flatten the transform
9031 gfx::Transform transform2;
9032 transform2.Translate3d(10, 10, 10);
9033
9034 layer_clips_subtree->SetMasksToBounds(true);
9035 test_layer->SetDrawsContent(true);
9036
9037 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269038 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349039 SetLayerPropertiesForTesting(significant_transform, transform1,
9040 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
weiliangcc154ce22015-12-09 03:39:269041 true, false);
jaydasika67d7989e2015-08-06 21:55:349042 SetLayerPropertiesForTesting(layer_clips_subtree, identity_matrix,
9043 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
weiliangcc154ce22015-12-09 03:39:269044 true, false);
jaydasika67d7989e2015-08-06 21:55:349045 SetLayerPropertiesForTesting(render_surface, transform2, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269046 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349047 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
weiliangcc154ce22015-12-09 03:39:269048 gfx::PointF(), gfx::Size(30, 30), true, false);
jaydasika67d7989e2015-08-06 21:55:349049
jaydasika6b5a32bf2016-04-22 21:56:369050 root->test_properties()->force_render_surface = true;
9051 significant_transform->test_properties()->force_render_surface = false;
9052 layer_clips_subtree->test_properties()->force_render_surface = true;
9053 render_surface->test_properties()->force_render_surface = true;
9054 test_layer->test_properties()->force_render_surface = false;
jaydasika67d7989e2015-08-06 21:55:349055 ExecuteCalculateDrawProperties(root);
9056
ajumae4af47062016-05-24 23:59:049057 TransformTree& transform_tree =
jaydasika67d7989e2015-08-06 21:55:349058 root->layer_tree_impl()->property_trees()->transform_tree;
9059 TransformNode* transform_node =
9060 transform_tree.Node(significant_transform->transform_tree_index());
9061 EXPECT_EQ(transform_node->owner_id, significant_transform->id());
9062
weiliangcc154ce22015-12-09 03:39:269063 EXPECT_TRUE(root->has_render_surface());
9064 EXPECT_FALSE(significant_transform->has_render_surface());
9065 EXPECT_TRUE(layer_clips_subtree->has_render_surface());
9066 EXPECT_TRUE(render_surface->has_render_surface());
9067 EXPECT_FALSE(test_layer->has_render_surface());
9068
ajumae4af47062016-05-24 23:59:049069 ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
jaydasika67d7989e2015-08-06 21:55:349070 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
ajuma01734dd02015-10-07 01:22:089071 EXPECT_FALSE(clip_node->data.applies_local_clip);
weiliangcc97575c2016-03-03 18:34:279072 EXPECT_EQ(gfx::Rect(22, 21), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349073}
9074
9075TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
9076 // Ensure that when parent clip node's transform is an ancestor of current
9077 // clip node's target, clip is 'projected' from parent space to current
9078 // target space and visible rects are calculated correctly.
9079 LayerImpl* root = root_layer();
9080 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
9081 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
9082 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
9083
9084 const gfx::Transform identity_matrix;
9085 gfx::Transform transform;
9086 transform.RotateAboutYAxis(45);
9087 clip_layer->SetMasksToBounds(true);
9088 target_layer->SetMasksToBounds(true);
9089 test_layer->SetDrawsContent(true);
9090
9091 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9092 gfx::PointF(), gfx::Size(30, 30), true, false,
9093 true);
9094 SetLayerPropertiesForTesting(clip_layer, transform, gfx::Point3F(),
9095 gfx::PointF(), gfx::Size(30, 30), true, false,
9096 false);
9097 SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(),
9098 gfx::PointF(), gfx::Size(30, 30), true, false,
9099 true);
9100 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9101 gfx::PointF(), gfx::Size(30, 30), true, false,
9102 false);
9103 ExecuteCalculateDrawProperties(root);
9104
weiliangcc97575c2016-03-03 18:34:279105 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_layer_rect());
jaydasika67d7989e2015-08-06 21:55:349106}
9107
jaydasika7d5c1ed2015-08-14 14:27:029108TEST_F(LayerTreeHostCommonTest,
9109 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
9110 // Ensure clip rect is calculated correctly when render surface has unclipped
9111 // descendants.
9112 LayerImpl* root = root_layer();
9113 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9114 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
9115 LayerImpl* render_surface =
9116 AddChild<LayerImpl>(between_clip_parent_and_child);
9117 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9118
9119 const gfx::Transform identity_matrix;
weiliangcbb2e8642016-03-04 00:24:429120 gfx::Transform translate;
9121 translate.Translate(2.0, 2.0);
jaydasika7d5c1ed2015-08-14 14:27:029122
weiliangcbb2e8642016-03-04 00:24:429123 clip_parent->SetMasksToBounds(true);
jaydasika7d5c1ed2015-08-14 14:27:029124 test_layer->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569125 render_surface->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489126 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasikae9d09702015-09-15 01:26:419127 clip_children->insert(render_surface);
jaydasika1c0a27d42016-04-28 01:54:569128 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika7d5c1ed2015-08-14 14:27:029129 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9130 gfx::PointF(), gfx::Size(30, 30), true, false,
9131 true);
weiliangcbb2e8642016-03-04 00:24:429132 SetLayerPropertiesForTesting(clip_parent, translate, gfx::Point3F(),
jaydasika7d5c1ed2015-08-14 14:27:029133 gfx::PointF(), gfx::Size(30, 30), true, false,
9134 false);
weiliangcbb2e8642016-03-04 00:24:429135 SetLayerPropertiesForTesting(between_clip_parent_and_child, translate,
jaydasika7d5c1ed2015-08-14 14:27:029136 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
9137 true, false, false);
9138 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9139 gfx::PointF(), gfx::Size(30, 30), true, false,
9140 true);
9141 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9142 gfx::PointF(), gfx::Size(30, 30), true, false,
9143 false);
9144
9145 ExecuteCalculateDrawProperties(root);
9146
weiliangcbb2e8642016-03-04 00:24:429147 EXPECT_TRUE(test_layer->is_clipped());
weiliangc189c1a12016-04-11 16:16:259148 EXPECT_FALSE(test_layer->render_target()->is_clipped());
weiliangc0b41eaf2016-03-14 21:35:569149 EXPECT_EQ(gfx::Rect(-2, -2, 30, 30), test_layer->clip_rect());
9150 EXPECT_EQ(gfx::Rect(28, 28), test_layer->drawable_content_rect());
jaydasika7d5c1ed2015-08-14 14:27:029151}
9152
jaydasika571dd2cf2015-09-25 20:55:429153TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:089154 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
9155 // Ensure that the visible layer rect of a descendant of a surface with
9156 // unclipped descendants is computed correctly, when the surface doesn't apply
9157 // a clip.
9158 LayerImpl* root = root_layer();
9159 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9160 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9161 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9162 LayerImpl* child = AddChild<LayerImpl>(render_surface);
9163
9164 const gfx::Transform identity_matrix;
9165
9166 clip_child->SetDrawsContent(true);
9167 child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569168 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489169 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
ajuma01734dd02015-10-07 01:22:089170 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569171 clip_parent->test_properties()->clip_children.reset(clip_children.release());
ajuma01734dd02015-10-07 01:22:089172 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9173 gfx::PointF(), gfx::Size(30, 10), true, false,
9174 true);
9175 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9176 gfx::PointF(), gfx::Size(30, 30), true, false,
9177 false);
9178 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9179 gfx::PointF(), gfx::Size(10, 15), true, false,
9180 true);
9181 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9182 gfx::PointF(), gfx::Size(10, 10), true, false,
9183 false);
9184 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
9185 gfx::PointF(), gfx::Size(40, 40), true, false,
9186 false);
9187
9188 ExecuteCalculateDrawProperties(root);
9189 EXPECT_EQ(gfx::Rect(40, 40), child->visible_layer_rect());
9190}
9191
9192TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:429193 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
9194 LayerImpl* root = root_layer();
9195 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9196 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9197 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
9198 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
9199 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
9200
9201 const gfx::Transform identity_matrix;
9202 root->SetMasksToBounds(true);
9203 render_surface->SetMasksToBounds(true);
9204 render_surface->SetDrawsContent(true);
9205 clip_child->SetDrawsContent(true);
9206 test_layer1->SetDrawsContent(true);
9207 test_layer2->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569208 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489209 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika571dd2cf2015-09-25 20:55:429210 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569211 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika571dd2cf2015-09-25 20:55:429212
9213 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9214 gfx::PointF(), gfx::Size(30, 30), true, false,
9215 true);
9216 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9217 gfx::PointF(), gfx::Size(30, 30), true, false,
9218 false);
9219 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9220 gfx::PointF(), gfx::Size(50, 50), true, false,
9221 true);
9222 SetLayerPropertiesForTesting(test_layer1, identity_matrix, gfx::Point3F(),
9223 gfx::PointF(), gfx::Size(50, 50), true, false,
9224 false);
9225 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9226 gfx::PointF(), gfx::Size(50, 50), true, false,
9227 false);
9228 SetLayerPropertiesForTesting(test_layer2, identity_matrix, gfx::Point3F(),
9229 gfx::PointF(), gfx::Size(50, 50), true, false,
9230 false);
9231
9232 ExecuteCalculateDrawProperties(root);
weiliangc0e13ba602016-03-12 04:53:569233 EXPECT_EQ(gfx::Rect(30, 30), render_surface->visible_layer_rect());
9234 EXPECT_EQ(gfx::Rect(30, 30), test_layer1->visible_layer_rect());
jaydasika571dd2cf2015-09-25 20:55:429235 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
9236 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
9237}
9238
ajumae2b7a5c2015-09-30 21:41:429239TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
9240 LayerImpl* root = root_layer();
9241 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9242 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9243 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9244
9245 const gfx::Transform identity_matrix;
9246 clip_parent->SetDrawsContent(true);
9247 render_surface->SetMasksToBounds(true);
9248 render_surface->SetDrawsContent(true);
9249 clip_child->SetDrawsContent(true);
9250
jaydasika1c0a27d42016-04-28 01:54:569251 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489252 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
ajumae2b7a5c2015-09-30 21:41:429253 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569254 clip_parent->test_properties()->clip_children.reset(clip_children.release());
ajumae2b7a5c2015-09-30 21:41:429255
9256 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9257 gfx::PointF(), gfx::Size(50, 50), true, false,
9258 true);
9259 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9260 gfx::PointF(), gfx::Size(50, 50), true, false,
9261 false);
9262 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9263 gfx::PointF(), gfx::Size(30, 30), true, false,
9264 true);
9265 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9266 gfx::PointF(), gfx::Size(50, 50), true, false,
9267 false);
9268
9269 ExecuteCalculateDrawProperties(root);
9270
9271 // The clip child should inherit its clip parent's clipping state, not its
9272 // tree parent's clipping state.
9273 EXPECT_FALSE(clip_parent->is_clipped());
9274 EXPECT_TRUE(render_surface->is_clipped());
9275 EXPECT_FALSE(clip_child->is_clipped());
9276}
9277
jaydasika77a4a072015-10-20 21:47:279278TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
9279 // Tests the value of render surface content rect when we have multiple types
9280 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
9281 // clipped surfaces.
9282 LayerImpl* root = root_layer();
9283 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
9284 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
9285 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9286 LayerImpl* unclipped_desc_surface2 =
9287 AddChild<LayerImpl>(unclipped_desc_surface);
9288 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
9289 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
9290
9291 unclipped_surface->SetDrawsContent(true);
9292 unclipped_desc_surface->SetDrawsContent(true);
9293 unclipped_desc_surface2->SetDrawsContent(true);
9294 clipped_surface->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569295 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489296 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika77a4a072015-10-20 21:47:279297 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569298 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika77a4a072015-10-20 21:47:279299
9300 gfx::Transform identity_matrix;
9301 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9302 gfx::PointF(), gfx::Size(80, 80), true, false,
9303 true);
9304 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
9305 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
9306 true, false, true);
9307 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9308 gfx::PointF(), gfx::Size(50, 50), true, false,
9309 false);
9310 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
9311 gfx::Point3F(), gfx::PointF(),
9312 gfx::Size(100, 100), true, false, true);
9313 SetLayerPropertiesForTesting(unclipped_desc_surface2, identity_matrix,
9314 gfx::Point3F(), gfx::PointF(), gfx::Size(60, 60),
9315 true, false, true);
9316 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9317 gfx::PointF(), gfx::Size(100, 100), true, false,
9318 false);
9319 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
9320 gfx::PointF(), gfx::Size(70, 70), true, false,
9321 true);
9322 clip_parent->SetMasksToBounds(true);
9323 unclipped_surface->SetMasksToBounds(true);
9324 unclipped_desc_surface->SetMasksToBounds(true);
9325
9326 ExecuteCalculateDrawProperties(root);
9327 EXPECT_EQ(gfx::Rect(50, 50),
9328 unclipped_surface->render_surface()->content_rect());
weiliangc0e13ba602016-03-12 04:53:569329 EXPECT_EQ(gfx::Rect(50, 50),
jaydasika77a4a072015-10-20 21:47:279330 unclipped_desc_surface->render_surface()->content_rect());
9331 EXPECT_EQ(gfx::Rect(50, 50),
9332 unclipped_desc_surface2->render_surface()->content_rect());
9333 EXPECT_EQ(gfx::Rect(50, 50),
9334 clipped_surface->render_surface()->content_rect());
9335}
9336
9337TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
9338 // Tests the value of render surface content rect when we have a layer that
9339 // clips between the clip parent's target and clip child's target.
9340 LayerImpl* root = root_layer();
9341 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9342 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9343 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9344 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9345 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9346
9347 clip_child->SetDrawsContent(true);
9348 unclipped_desc_surface->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569349 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489350 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika77a4a072015-10-20 21:47:279351 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569352 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika77a4a072015-10-20 21:47:279353
9354 gfx::Transform identity_matrix;
9355 gfx::Transform translate;
9356 translate.Translate(10, 10);
9357 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9358 gfx::PointF(), gfx::Size(100, 100), true, false,
9359 true);
9360 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
9361 gfx::PointF(), gfx::Size(100, 100), true, false,
9362 true);
9363 SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(),
9364 gfx::PointF(), gfx::Size(20, 20), true, false,
9365 false);
9366 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9367 gfx::PointF(), gfx::Size(50, 50), true, false,
9368 false);
9369 SetLayerPropertiesForTesting(unclipped_desc_surface, translate,
9370 gfx::Point3F(), gfx::PointF(),
9371 gfx::Size(100, 100), true, false, true);
9372 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9373 gfx::PointF(), gfx::Size(100, 100), true, false,
9374 false);
9375 surface->SetMasksToBounds(true);
9376 clip_layer->SetMasksToBounds(true);
9377
9378 ExecuteCalculateDrawProperties(root);
9379
9380 EXPECT_EQ(gfx::Rect(10, 10),
9381 unclipped_desc_surface->render_surface()->content_rect());
9382}
9383
jaydasika2c8c2872015-10-21 23:28:219384TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
9385 LayerImpl* root = root_layer();
9386 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9387 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9388 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9389 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9390 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9391
9392 clip_child->SetDrawsContent(true);
9393 unclipped_desc_surface->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569394 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489395 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasika2c8c2872015-10-21 23:28:219396 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569397 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasika2c8c2872015-10-21 23:28:219398
9399 gfx::Transform identity_matrix;
9400 gfx::Transform scale;
9401 scale.Scale(2, 2);
9402 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9403 gfx::PointF(), gfx::Size(100, 100), true, false,
9404 true);
9405 SetLayerPropertiesForTesting(surface, scale, gfx::Point3F(), gfx::PointF(),
9406 gfx::Size(100, 100), true, false, true);
9407 SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(),
9408 gfx::PointF(), gfx::Size(20, 20), true, false,
9409 false);
9410 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9411 gfx::PointF(), gfx::Size(50, 50), true, false,
9412 false);
9413 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
9414 gfx::Point3F(), gfx::PointF(),
9415 gfx::Size(100, 100), true, false, true);
9416 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9417 gfx::PointF(), gfx::Size(100, 100), true, false,
9418 false);
9419 surface->SetMasksToBounds(true);
9420 clip_layer->SetMasksToBounds(true);
9421
9422 ExecuteCalculateDrawProperties(root);
9423
9424 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9425}
9426
jaydasika60f85862015-10-01 20:36:149427TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
9428 LayerImpl* root = root_layer();
9429 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9430 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9431
9432 const gfx::Transform identity_matrix;
9433 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9434 gfx::PointF(), gfx::Size(30, 30), true, false,
9435 true);
9436 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9437 gfx::PointF(), gfx::Size(30, 30), true, false,
9438 true);
jaydasika86654512016-01-27 17:05:079439 gfx::Transform translation;
9440 translation.Translate(10, 10);
9441 SetLayerPropertiesForTesting(test_layer, translation, gfx::Point3F(),
jaydasika60f85862015-10-01 20:36:149442 gfx::PointF(), gfx::Size(20, 20), true, false,
9443 false);
9444
9445 render_surface->SetMasksToBounds(true);
9446 test_layer->SetDrawsContent(true);
9447 test_layer->SetOpacity(0);
dtapuskaee0b6982016-01-29 15:14:489448 test_layer->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 20, 20));
jaydasika60f85862015-10-01 20:36:149449
9450 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079451 EXPECT_EQ(translation, test_layer->ScreenSpaceTransform());
jaydasika60f85862015-10-01 20:36:149452}
9453
jaydasikae4910fa22015-10-09 00:52:099454TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
9455 LayerImpl* root = root_layer();
9456 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9457 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9458 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9459
9460 const gfx::Transform identity_matrix;
9461 clip_parent->SetMasksToBounds(true);
9462 render_surface->SetMasksToBounds(true);
9463 render_surface->SetDrawsContent(true);
9464 clip_child->SetDrawsContent(true);
jaydasika1c0a27d42016-04-28 01:54:569465 clip_child->test_properties()->clip_parent = clip_parent;
danakj60bc3bc2016-04-09 00:24:489466 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasikae4910fa22015-10-09 00:52:099467 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569468 clip_parent->test_properties()->clip_children.reset(clip_children.release());
jaydasikae4910fa22015-10-09 00:52:099469
9470 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9471 gfx::PointF(), gfx::Size(30, 30), true, false,
9472 true);
9473 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9474 gfx::PointF(10.f, 10.f), gfx::Size(40, 40), true,
9475 false, false);
9476 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9477 gfx::PointF(), gfx::Size(50, 50), true, false,
9478 true);
9479 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9480 gfx::PointF(), gfx::Size(50, 50), true, false,
9481 false);
9482
9483 ExecuteCalculateDrawProperties(root);
9484 EXPECT_EQ(gfx::Rect(40, 40), clip_child->visible_layer_rect());
9485}
9486
jaydasika571dd2cf2015-09-25 20:55:429487TEST_F(LayerTreeHostCommonTest,
9488 LayerClipRectLargerThanClippingRenderSurfaceRect) {
9489 LayerImpl* root = root_layer();
9490 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9491 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9492 const gfx::Transform identity_matrix;
9493 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9494 gfx::PointF(), gfx::Size(30, 30), true, false,
9495 true);
9496 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9497 gfx::PointF(), gfx::Size(50, 50), true, false,
9498 true);
9499 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9500 gfx::PointF(), gfx::Size(50, 50), true, false,
9501 false);
9502 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369503 root->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429504 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369505 render_surface->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429506 test_layer->SetMasksToBounds(true);
9507 test_layer->SetDrawsContent(true);
9508 ExecuteCalculateDrawProperties(root);
9509
9510 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
9511 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
9512 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
9513}
9514
jaydasikab5504ca2015-12-18 23:41:559515TEST_F(LayerTreeHostCommonTest, SubtreeIsHiddenTest) {
9516 // Tests that subtree is hidden is updated.
9517 LayerImpl* root = root_layer();
9518 LayerImpl* hidden = AddChild<LayerImpl>(root);
9519 LayerImpl* test = AddChild<LayerImpl>(hidden);
9520
9521 const gfx::Transform identity_matrix;
9522 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9523 gfx::PointF(), gfx::Size(30, 30), true, false,
9524 true);
9525 SetLayerPropertiesForTesting(hidden, identity_matrix, gfx::Point3F(),
9526 gfx::PointF(10, 10), gfx::Size(30, 30), true,
9527 false, true);
9528 SetLayerPropertiesForTesting(test, identity_matrix, gfx::Point3F(),
9529 gfx::PointF(), gfx::Size(30, 30), true, false,
9530 true);
9531
jaydasika5121caa82016-05-05 15:43:359532 hidden->test_properties()->hide_layer_and_subtree = true;
jaydasikab5504ca2015-12-18 23:41:559533 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079534 EXPECT_TRUE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559535
jaydasika5121caa82016-05-05 15:43:359536 hidden->test_properties()->hide_layer_and_subtree = false;
jaydasikab5504ca2015-12-18 23:41:559537 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9538 ExecuteCalculateDrawProperties(root);
jaydasika86654512016-01-27 17:05:079539 EXPECT_FALSE(test->IsHidden());
jaydasikab5504ca2015-12-18 23:41:559540}
9541
jaydasikac0137282015-10-01 15:50:309542TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
9543 LayerImpl* root = root_layer();
9544 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9545 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9546 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
9547
9548 const gfx::Transform identity_matrix;
jaydasika1c0a27d42016-04-28 01:54:569549 clip_child->test_properties()->clip_parent = root;
danakj60bc3bc2016-04-09 00:24:489550 std::unique_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
jaydasikac0137282015-10-01 15:50:309551 clip_children->insert(clip_child);
jaydasika1c0a27d42016-04-28 01:54:569552 root->test_properties()->clip_children.reset(clip_children.release());
jaydasikac0137282015-10-01 15:50:309553 root->SetMasksToBounds(true);
9554 render_surface1->SetDrawsContent(true);
9555 render_surface2->SetDrawsContent(true);
9556
9557 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9558 gfx::PointF(), gfx::Size(30, 30), true, false,
9559 true);
9560 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
9561 gfx::PointF(10, 10), gfx::Size(30, 30), true,
9562 false, true);
9563 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
9564 gfx::PointF(), gfx::Size(30, 30), true, false,
9565 true);
9566 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9567 gfx::PointF(), gfx::Size(30, 30), true, false,
9568 false);
9569 ExecuteCalculateDrawProperties(root);
9570
9571 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
jaydasikadaf0af02016-01-06 15:33:379572 // A clip node is created for every render surface and for layers that have
9573 // local clip. So, here it should be craeted for every layer.
9574 EXPECT_EQ(root->layer_tree_impl()->property_trees()->clip_tree.size(), 5u);
jaydasikac0137282015-10-01 15:50:309575}
9576
jaydasika224bca02015-12-18 02:37:099577TEST_F(LayerTreeHostCommonTest, MaskLayerScreenSpaceTransform) {
9578 // Tests that the mask layer gets its owning layer's screen space transform.
9579 LayerImpl* root = root_layer();
9580 LayerImpl* child = AddChild<LayerImpl>(root);
9581
9582 const gfx::Transform identity_matrix;
9583 gfx::Transform transform;
9584 transform.Translate(10, 10);
9585
9586 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9587 gfx::PointF(), gfx::Size(30, 30), true, false,
9588 true);
9589 SetLayerPropertiesForTesting(child, transform, gfx::Point3F(), gfx::PointF(),
9590 gfx::Size(30, 30), true, false, false);
9591 root->SetDrawsContent(true);
9592 child->SetDrawsContent(false);
9593 child->SetMaskLayer(LayerImpl::Create(root->layer_tree_impl(), 100));
9594 ExecuteCalculateDrawProperties(root);
9595
9596 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
9597 child->mask_layer()->ScreenSpaceTransform());
9598 transform.Translate(10, 10);
9599 child->SetTransform(transform);
9600 child->SetDrawsContent(true);
9601 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
9602 ExecuteCalculateDrawProperties(root);
9603 EXPECT_TRANSFORMATION_MATRIX_EQ(transform,
9604 child->mask_layer()->ScreenSpaceTransform());
9605}
9606
jaydasikaf62311f2016-04-20 14:38:459607TEST_F(LayerTreeHostCommonTest,
9608 SublayerScaleWithTransformNodeBetweenTwoTargets) {
9609 LayerImpl* root = root_layer();
9610 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9611 LayerImpl* between_targets = AddChild<LayerImpl>(render_surface1);
9612 LayerImpl* render_surface2 = AddChild<LayerImpl>(between_targets);
9613 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface2);
9614 const gfx::Transform identity_matrix;
9615 test_layer->SetDrawsContent(true);
9616
9617 gfx::Transform scale;
9618 scale.Scale(2.f, 2.f);
9619 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9620 gfx::PointF(), gfx::Size(30, 30), true, false,
9621 true);
9622 SetLayerPropertiesForTesting(render_surface1, scale, gfx::Point3F(),
9623 gfx::PointF(), gfx::Size(30, 30), true, false,
9624 true);
9625 SetLayerPropertiesForTesting(between_targets, identity_matrix, gfx::Point3F(),
9626 gfx::PointF(), gfx::Size(30, 30), true, false,
9627 false);
9628 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
9629 gfx::PointF(), gfx::Size(30, 30), true, false,
9630 true);
9631 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9632 gfx::PointF(), gfx::Size(30, 30), true, false,
9633 false);
9634 // We want layer between the two targets to create a clip node and transform
9635 // node but it shouldn't create a render surface.
9636 between_targets->SetMasksToBounds(true);
9637 between_targets->Set3dSortingContextId(2);
9638
9639 ExecuteCalculateDrawProperties(root);
9640
9641 TransformTree& tree =
9642 root->layer_tree_impl()->property_trees()->transform_tree;
9643 TransformNode* node = tree.Node(render_surface1->transform_tree_index());
9644 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(2.f, 2.f));
9645
9646 node = tree.Node(between_targets->transform_tree_index());
9647 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(1.f, 1.f));
9648
9649 node = tree.Node(render_surface2->transform_tree_index());
9650 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(2.f, 2.f));
9651
9652 EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect());
9653}
9654
jaydasika5160e672015-10-15 15:25:149655TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
9656 LayerImpl* root = root_layer();
9657 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
sunxd71aea3e2016-04-01 23:48:059658 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
jaydasika5160e672015-10-15 15:25:149659
9660 const gfx::Transform identity_matrix;
sunxd71aea3e2016-04-01 23:48:059661 child->SetDrawsContent(true);
9662 child->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:149663
9664 gfx::Transform large_transform;
9665 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
9666 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
9667 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
9668 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
9669
9670 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9671 gfx::PointF(), gfx::Size(30, 30), true, false,
9672 true);
sunxd71aea3e2016-04-01 23:48:059673 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
jaydasika5160e672015-10-15 15:25:149674 gfx::PointF(), gfx::Size(30, 30), true, false,
9675 true);
sunxd71aea3e2016-04-01 23:48:059676 // TODO(sunxd): we make child have no render surface, because if the
9677 // child has one, the large transform applied to child will result in NaNs in
9678 // the draw_transform of the render_surface, thus make draw property updates
9679 // skip the child layer. We need further investigation into this to know
9680 // what exactly happens here.
9681 SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(),
jaydasika5160e672015-10-15 15:25:149682 gfx::PointF(), gfx::Size(30, 30), true, false,
sunxd71aea3e2016-04-01 23:48:059683 false);
jaydasika5160e672015-10-15 15:25:149684
9685 ExecuteCalculateDrawProperties(root);
9686
jaydasika5160e672015-10-15 15:25:149687 EXPECT_EQ(gfx::RectF(),
sunxd71aea3e2016-04-01 23:48:059688 render_surface1->render_surface()->DrawableContentRect());
9689
9690 bool is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(0, 0)) ||
9691 std::isnan(child->DrawTransform().matrix().get(0, 0));
9692 EXPECT_TRUE(is_inf_or_nan);
9693
9694 is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) ||
9695 std::isnan(child->DrawTransform().matrix().get(1, 1));
9696 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:149697
9698 std::vector<LayerImpl*>* rsll = render_surface_layer_list_impl();
9699 bool root_in_rsll =
9700 std::find(rsll->begin(), rsll->end(), root) != rsll->end();
9701 EXPECT_TRUE(root_in_rsll);
jaydasika5160e672015-10-15 15:25:149702}
9703
jaydasika8d6efe2e2016-05-17 15:37:219704TEST_F(LayerTreeHostCommonTest, PropertyTreesRebuildWithOpacityChanges) {
9705 const gfx::Transform identity_matrix;
9706 scoped_refptr<Layer> root = Layer::Create();
9707 scoped_refptr<LayerWithForcedDrawsContent> child =
9708 make_scoped_refptr(new LayerWithForcedDrawsContent());
9709 root->AddChild(child);
9710
9711 host()->SetRootLayer(root);
9712
9713 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
9714 gfx::PointF(), gfx::Size(100, 100), true, false);
9715 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
9716 gfx::PointF(), gfx::Size(20, 20), true, false);
9717
9718 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9719
9720 // Changing the opacity from 1 to non-1 value should trigger rebuild of
9721 // property trees as a new effect node will be created.
9722 child->SetOpacity(0.5f);
9723 PropertyTrees* property_trees = host()->property_trees();
9724 EXPECT_TRUE(property_trees->needs_rebuild);
9725
9726 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9727 EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()),
9728 property_trees->effect_id_to_index_map.end());
9729
9730 // child already has an effect node. Changing its opacity shouldn't trigger
9731 // a property trees rebuild.
9732 child->SetOpacity(0.8f);
9733 property_trees = host()->property_trees();
9734 EXPECT_FALSE(property_trees->needs_rebuild);
9735
9736 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9737 EXPECT_NE(property_trees->effect_id_to_index_map.find(child->id()),
9738 property_trees->effect_id_to_index_map.end());
9739
9740 // Changing the opacity from non-1 value to 1 should trigger a rebuild of
9741 // property trees as the effect node may no longer be needed.
9742 child->SetOpacity(1.f);
9743 property_trees = host()->property_trees();
9744 EXPECT_TRUE(property_trees->needs_rebuild);
9745
9746 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9747 EXPECT_EQ(property_trees->effect_id_to_index_map.find(child->id()),
9748 property_trees->effect_id_to_index_map.end());
9749}
9750
jaydasika9cb21c772016-05-10 22:37:089751TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) {
9752 const gfx::Transform identity_matrix;
9753 scoped_refptr<Layer> root = Layer::Create();
9754 scoped_refptr<LayerWithForcedDrawsContent> animated =
9755 make_scoped_refptr(new LayerWithForcedDrawsContent());
9756 root->AddChild(animated);
9757
9758 host()->SetRootLayer(root);
9759
9760 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
9761 gfx::PointF(), gfx::Size(100, 100), true, false);
9762 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
9763 gfx::PointF(), gfx::Size(20, 20), true, false);
9764
9765 root->SetForceRenderSurfaceForTesting(true);
9766 animated->SetOpacity(0.f);
9767
9768 scoped_refptr<AnimationPlayer> player =
9769 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
9770 timeline()->AttachPlayer(player);
9771 player->AttachElement(animated->id());
9772
9773 int animation_id = 0;
9774 std::unique_ptr<Animation> animation = Animation::Create(
9775 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
9776 animation_id, 1, TargetProperty::OPACITY);
loysoc255f272016-05-18 02:53:559777 animation->set_fill_mode(Animation::FillMode::NONE);
jaydasika9cb21c772016-05-10 22:37:089778 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
9779 Animation* animation_ptr = animation.get();
9780 AddAnimationToLayerWithExistingPlayer(animated->id(), timeline(),
9781 std::move(animation));
9782
9783 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9784
9785 EffectTree& tree = root->layer_tree_host()->property_trees()->effect_tree;
9786 EffectNode* node = tree.Node(animated->effect_tree_index());
9787 EXPECT_FALSE(node->data.is_currently_animating_opacity);
9788 EXPECT_TRUE(node->data.has_potential_opacity_animation);
9789
9790 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
9791 root->layer_tree_host()->AnimateLayers(
9792 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
9793 node = tree.Node(animated->effect_tree_index());
9794 EXPECT_TRUE(node->data.is_currently_animating_opacity);
9795 EXPECT_TRUE(node->data.has_potential_opacity_animation);
9796
9797 player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/);
9798 node = tree.Node(animated->effect_tree_index());
9799 EXPECT_FALSE(node->data.is_currently_animating_opacity);
9800 EXPECT_FALSE(node->data.has_potential_opacity_animation);
9801}
9802
jaydasika6c3404e92016-05-19 02:40:369803TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) {
9804 const gfx::Transform identity_matrix;
9805 scoped_refptr<Layer> root = Layer::Create();
9806 scoped_refptr<LayerWithForcedDrawsContent> animated =
9807 make_scoped_refptr(new LayerWithForcedDrawsContent());
9808 root->AddChild(animated);
9809
9810 host()->SetRootLayer(root);
9811
9812 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
9813 gfx::PointF(), gfx::Size(100, 100), true, false);
9814 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
9815 gfx::PointF(), gfx::Size(20, 20), true, false);
9816
9817 root->SetForceRenderSurfaceForTesting(true);
9818
9819 scoped_refptr<AnimationPlayer> player =
9820 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId());
9821 timeline()->AttachPlayer(player);
9822 player->AttachElement(animated->id());
9823
9824 std::unique_ptr<KeyframedTransformAnimationCurve> curve(
9825 KeyframedTransformAnimationCurve::Create());
9826 TransformOperations start;
9827 start.AppendTranslate(1.f, 2.f, 3.f);
9828 gfx::Transform transform;
9829 transform.Scale3d(1.0, 2.0, 3.0);
9830 TransformOperations operation;
9831 operation.AppendMatrix(transform);
9832 curve->AddKeyframe(
9833 TransformKeyframe::Create(base::TimeDelta(), start, nullptr));
9834 curve->AddKeyframe(TransformKeyframe::Create(
9835 base::TimeDelta::FromSecondsD(1.0), operation, nullptr));
9836 std::unique_ptr<Animation> animation(
9837 Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM));
9838 animation->set_fill_mode(Animation::FillMode::NONE);
9839 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
9840 Animation* animation_ptr = animation.get();
9841 AddAnimationToLayerWithExistingPlayer(animated->id(), timeline(),
9842 std::move(animation));
9843
9844 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9845
9846 TransformTree& tree =
9847 root->layer_tree_host()->property_trees()->transform_tree;
9848 TransformNode* node = tree.Node(animated->transform_tree_index());
9849 EXPECT_FALSE(node->data.is_currently_animating);
9850 EXPECT_TRUE(node->data.has_potential_animation);
9851
9852 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0));
9853 root->layer_tree_host()->AnimateLayers(
9854 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max()));
9855 node = tree.Node(animated->transform_tree_index());
9856 EXPECT_TRUE(node->data.is_currently_animating);
9857 EXPECT_TRUE(node->data.has_potential_animation);
9858
9859 player->AbortAnimations(TargetProperty::TRANSFORM,
9860 false /*needs_completion*/);
9861 node = tree.Node(animated->transform_tree_index());
9862 EXPECT_FALSE(node->data.is_currently_animating);
9863 EXPECT_FALSE(node->data.has_potential_animation);
9864}
9865
khushalsagar37694212016-01-15 20:46:489866TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) {
9867 LayerTreeHostCommon::ScrollUpdateInfo scroll;
9868 scroll.layer_id = 2;
9869 scroll.scroll_delta = gfx::Vector2d(5, 10);
9870
9871 proto::ScrollUpdateInfo proto;
9872 scroll.ToProtobuf(&proto);
9873 LayerTreeHostCommon::ScrollUpdateInfo new_scroll;
9874 new_scroll.FromProtobuf(proto);
9875
9876 EXPECT_EQ(scroll, new_scroll);
9877}
9878
9879TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) {
9880 ScrollAndScaleSet scroll_and_scale_set;
9881
9882 LayerTreeHostCommon::ScrollUpdateInfo scroll1;
9883 scroll1.layer_id = 1;
9884 scroll1.scroll_delta = gfx::Vector2d(5, 10);
9885 LayerTreeHostCommon::ScrollUpdateInfo scroll2;
9886 scroll2.layer_id = 2;
9887 scroll2.scroll_delta = gfx::Vector2d(1, 5);
9888 scroll_and_scale_set.scrolls.push_back(scroll1);
9889 scroll_and_scale_set.scrolls.push_back(scroll2);
9890
9891 scroll_and_scale_set.page_scale_delta = 0.3f;
9892 scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f);
9893 scroll_and_scale_set.top_controls_delta = 0.9f;
9894
9895 proto::ScrollAndScaleSet proto;
9896 scroll_and_scale_set.ToProtobuf(&proto);
9897 ScrollAndScaleSet new_scroll_and_scale_set;
9898 new_scroll_and_scale_set.FromProtobuf(proto);
9899
9900 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set));
9901}
9902
sunxdea1df782016-01-28 00:12:339903TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) {
9904 // Test the behavior of scroll tree builder
9905 // Topology:
sunxdcfccd1b32016-02-11 00:54:209906 // +root1(1)[inner_viewport_container_layer]
9907 // +-page_scale_layer
9908 // +----parent2(2)[kHasBackgroundAttachmentFixedObjects|kScrollbarScrolling &
9909 // scrollable, inner_viewport_scroll_layer]
9910 // +------child6(6)[kScrollbarScrolling]
9911 // +--------grand_child10(10)[kScrollbarScrolling]
9912 // +----parent3(3)
9913 // +------child7(7)[scrollable]
9914 // +------child8(8)[scroll_parent=7]
9915 // +--------grand_child11(11)[scrollable]
9916 // +----parent4(4)
9917 // +------child9(9)
9918 // +--------grand_child12(12)
9919 // +----parent5(5)[contains_non_fast_scrollable_region]
sunxdea1df782016-01-28 00:12:339920 //
9921 // Expected scroll tree topology:
9922 // +property_tree_root---owner:-1
9923 // +--root---owner:1, id:1
9924 // +----node---owner:2, id:2
9925 // +------node---owner:6, id:3
9926 // +----node---owner:7, id:4
9927 // +------node---owner:11, id:5
9928 // +----node---owner:5, id:6
9929 //
9930 // Extra check:
9931 // scroll_tree_index() of:
9932 // grand_child10:3
9933 // parent3:1
9934 // child8:4
9935 // parent4:1
9936 // child9:1
9937 // grand_child12:1
loyso0940d412016-03-14 01:30:319938 scoped_refptr<Layer> root1 = Layer::Create();
9939 scoped_refptr<Layer> page_scale_layer = Layer::Create();
9940 scoped_refptr<Layer> parent2 = Layer::Create();
9941 scoped_refptr<Layer> parent3 = Layer::Create();
9942 scoped_refptr<Layer> parent4 = Layer::Create();
9943 scoped_refptr<Layer> parent5 = Layer::Create();
9944 scoped_refptr<Layer> child6 = Layer::Create();
9945 scoped_refptr<Layer> child7 = Layer::Create();
9946 scoped_refptr<Layer> child8 = Layer::Create();
9947 scoped_refptr<Layer> child9 = Layer::Create();
9948 scoped_refptr<Layer> grand_child10 = Layer::Create();
9949 scoped_refptr<Layer> grand_child11 = Layer::Create();
9950 scoped_refptr<Layer> grand_child12 = Layer::Create();
sunxdea1df782016-01-28 00:12:339951
sunxdcfccd1b32016-02-11 00:54:209952 root1->AddChild(page_scale_layer);
9953 page_scale_layer->AddChild(parent2);
9954 page_scale_layer->AddChild(parent3);
9955 page_scale_layer->AddChild(parent4);
9956 page_scale_layer->AddChild(parent5);
sunxdea1df782016-01-28 00:12:339957 parent2->AddChild(child6);
9958 parent3->AddChild(child7);
9959 parent3->AddChild(child8);
9960 parent4->AddChild(child9);
9961 child6->AddChild(grand_child10);
9962 child8->AddChild(grand_child11);
9963 child9->AddChild(grand_child12);
9964 host()->SetRootLayer(root1);
9965
9966 parent2->AddMainThreadScrollingReasons(
9967 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects);
sunxd29f17bf2016-02-03 02:47:489968 parent2->AddMainThreadScrollingReasons(
9969 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:339970 parent2->SetScrollClipLayerId(root1->id());
9971 child6->AddMainThreadScrollingReasons(
sunxd29f17bf2016-02-03 02:47:489972 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:339973 grand_child10->AddMainThreadScrollingReasons(
sunxd29f17bf2016-02-03 02:47:489974 MainThreadScrollingReason::kScrollbarScrolling);
sunxdea1df782016-01-28 00:12:339975
sunxdcfccd1b32016-02-11 00:54:209976 child7->SetScrollClipLayerId(parent3->id());
9977
sunxdea1df782016-01-28 00:12:339978 child8->SetScrollParent(child7.get());
sunxdcfccd1b32016-02-11 00:54:209979 grand_child11->SetScrollClipLayerId(parent3->id());
sunxdea1df782016-01-28 00:12:339980
9981 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50));
sunxdcfccd1b32016-02-11 00:54:209982 parent5->SetBounds(gfx::Size(10, 10));
sunxdea1df782016-01-28 00:12:339983
sunxdcfccd1b32016-02-11 00:54:209984 host()->RegisterViewportLayers(NULL, page_scale_layer, parent2, NULL);
sunxdea1df782016-01-28 00:12:339985 ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get());
9986
9987 const int kInvalidPropertyTreeNodeId = -1;
9988 const int kRootPropertyTreeNodeId = 0;
9989
9990 // Property tree root
ajumae4af47062016-05-24 23:59:049991 ScrollTree& scroll_tree = host()->property_trees()->scroll_tree;
sunxdc36713a2016-03-03 22:31:109992 PropertyTrees property_trees;
sunxdc044b11a2016-03-16 16:23:209993 property_trees.is_main_thread = true;
9994 property_trees.is_active = false;
ajumae4af47062016-05-24 23:59:049995 ScrollTree& expected_scroll_tree = property_trees.scroll_tree;
sunxdea1df782016-01-28 00:12:339996 ScrollNode* property_tree_root = expected_scroll_tree.Node(0);
9997 property_tree_root->id = kRootPropertyTreeNodeId;
9998 property_tree_root->parent_id = kInvalidPropertyTreeNodeId;
9999 property_tree_root->owner_id = kInvalidPropertyTreeNodeId;
10000 property_tree_root->data.scrollable = false;
sunxd29f17bf2016-02-03 02:47:4810001 property_tree_root->data.main_thread_scrolling_reasons =
10002 MainThreadScrollingReason::kNotScrollingOnMain;
sunxdea1df782016-01-28 00:12:3310003 property_tree_root->data.contains_non_fast_scrollable_region = false;
sunxdd1abacf2016-02-16 22:08:3010004 property_tree_root->data.transform_id = kRootPropertyTreeNodeId;
sunxdea1df782016-01-28 00:12:3310005
10006 // The node owned by root1
10007 ScrollNode scroll_root1;
10008 scroll_root1.id = 1;
10009 scroll_root1.owner_id = root1->id();
sunxd54e08e9d2016-02-22 23:01:2810010 scroll_root1.data.user_scrollable_horizontal = true;
10011 scroll_root1.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010012 scroll_root1.data.transform_id = root1->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310013 expected_scroll_tree.Insert(scroll_root1, 0);
10014
10015 // The node owned by parent2
10016 ScrollNode scroll_parent2;
10017 scroll_parent2.id = 2;
10018 scroll_parent2.owner_id = parent2->id();
10019 scroll_parent2.data.scrollable = true;
sunxd29f17bf2016-02-03 02:47:4810020 scroll_parent2.data.main_thread_scrolling_reasons =
10021 parent2->main_thread_scrolling_reasons();
sunxdcfccd1b32016-02-11 00:54:2010022 scroll_parent2.data.scroll_clip_layer_bounds = root1->bounds();
10023 scroll_parent2.data.bounds = parent2->bounds();
10024 scroll_parent2.data.max_scroll_offset_affected_by_page_scale = true;
10025 scroll_parent2.data.is_inner_viewport_scroll_layer = true;
sunxd54e08e9d2016-02-22 23:01:2810026 scroll_parent2.data.user_scrollable_horizontal = true;
10027 scroll_parent2.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010028 scroll_parent2.data.transform_id = parent2->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310029 expected_scroll_tree.Insert(scroll_parent2, 1);
10030
10031 // The node owned by child6
10032 ScrollNode scroll_child6;
10033 scroll_child6.id = 3;
10034 scroll_child6.owner_id = child6->id();
sunxd29f17bf2016-02-03 02:47:4810035 scroll_child6.data.main_thread_scrolling_reasons =
10036 child6->main_thread_scrolling_reasons();
sunxdd1abacf2016-02-16 22:08:3010037 scroll_child6.data.should_flatten = true;
sunxd54e08e9d2016-02-22 23:01:2810038 scroll_child6.data.user_scrollable_horizontal = true;
10039 scroll_child6.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010040 scroll_child6.data.transform_id = child6->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310041 expected_scroll_tree.Insert(scroll_child6, 2);
10042
10043 // The node owned by child7, child7 also owns a transform node
10044 ScrollNode scroll_child7;
10045 scroll_child7.id = 4;
10046 scroll_child7.owner_id = child7->id();
10047 scroll_child7.data.scrollable = true;
sunxdd1abacf2016-02-16 22:08:3010048 scroll_child7.data.scroll_clip_layer_bounds = parent3->bounds();
10049 scroll_child7.data.bounds = child7->bounds();
sunxd54e08e9d2016-02-22 23:01:2810050 scroll_child7.data.user_scrollable_horizontal = true;
10051 scroll_child7.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010052 scroll_child7.data.transform_id = child7->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310053 expected_scroll_tree.Insert(scroll_child7, 1);
10054
10055 // The node owned by grand_child11, grand_child11 also owns a transform node
10056 ScrollNode scroll_grand_child11;
10057 scroll_grand_child11.id = 5;
10058 scroll_grand_child11.owner_id = grand_child11->id();
10059 scroll_grand_child11.data.scrollable = true;
sunxd54e08e9d2016-02-22 23:01:2810060 scroll_grand_child11.data.user_scrollable_horizontal = true;
10061 scroll_grand_child11.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010062 scroll_grand_child11.data.transform_id =
10063 grand_child11->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310064 expected_scroll_tree.Insert(scroll_grand_child11, 4);
10065
10066 // The node owned by parent5
10067 ScrollNode scroll_parent5;
10068 scroll_parent5.id = 8;
10069 scroll_parent5.owner_id = parent5->id();
10070 scroll_parent5.data.contains_non_fast_scrollable_region = true;
sunxdcfccd1b32016-02-11 00:54:2010071 scroll_parent5.data.bounds = gfx::Size(10, 10);
sunxdd1abacf2016-02-16 22:08:3010072 scroll_parent5.data.should_flatten = true;
sunxd54e08e9d2016-02-22 23:01:2810073 scroll_parent5.data.user_scrollable_horizontal = true;
10074 scroll_parent5.data.user_scrollable_vertical = true;
sunxdd1abacf2016-02-16 22:08:3010075 scroll_parent5.data.transform_id = parent5->transform_tree_index();
sunxdea1df782016-01-28 00:12:3310076 expected_scroll_tree.Insert(scroll_parent5, 1);
10077
sunxdc044b11a2016-03-16 16:23:2010078 expected_scroll_tree.SetScrollOffset(parent2->id(), gfx::ScrollOffset(0, 0));
10079 expected_scroll_tree.SetScrollOffset(child7->id(), gfx::ScrollOffset(0, 0));
10080 expected_scroll_tree.SetScrollOffset(grand_child11->id(),
10081 gfx::ScrollOffset(0, 0));
sunxdea1df782016-01-28 00:12:3310082 expected_scroll_tree.set_needs_update(false);
10083
10084 EXPECT_EQ(expected_scroll_tree, scroll_tree);
10085
10086 // Check other layers' scroll_tree_index
sunxdcfccd1b32016-02-11 00:54:2010087 EXPECT_EQ(scroll_root1.id, page_scale_layer->scroll_tree_index());
sunxdea1df782016-01-28 00:12:3310088 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index());
10089 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index());
10090 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index());
10091 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index());
10092 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index());
10093 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index());
10094}
10095
[email protected]ba565742012-11-10 09:29:4810096} // namespace
10097} // namespace cc