blob: f506ce12446a11421178a878bbd052b25e614659 [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
danakj6496cba2014-10-16 01:31:087#include <algorithm>
[email protected]995708c52013-10-17 20:52:598#include <set>
vmpstra370ef52015-11-18 10:41:289#include <vector>
[email protected]995708c52013-10-17 20:52:5910
ajuma315a4782015-07-24 21:16:3411#include "cc/animation/keyframed_animation_curve.h"
[email protected]95e4e1a02013-03-18 07:09:0912#include "cc/animation/layer_animation_controller.h"
[email protected]1c3626e2014-04-09 17:49:2213#include "cc/animation/transform_operations.h"
[email protected]681ccff2013-03-18 06:13:5214#include "cc/base/math_util.h"
[email protected]cc3cfaa2013-03-18 09:05:5215#include "cc/layers/content_layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5216#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5917#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5218#include "cc/layers/layer_impl.h"
[email protected]390bb1ff2014-05-09 17:14:4019#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2820#include "cc/layers/render_surface_impl.h"
[email protected]30fe19ff2013-07-04 00:54:4521#include "cc/output/copy_output_request.h"
22#include "cc/output/copy_output_result.h"
[email protected]101441ce2012-10-16 01:45:0323#include "cc/test/animation_test_common.h"
vollick2175fae82015-04-27 21:18:1224#include "cc/test/fake_content_layer_client.h"
khushalsagarb64b360d2015-10-21 19:25:1625#include "cc/test/fake_impl_task_runner_provider.h"
[email protected]d600df7d2013-08-03 02:34:2826#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4527#include "cc/test/fake_layer_tree_host_impl.h"
ajumaae0dc2d2015-08-05 21:55:5628#include "cc/test/fake_output_surface.h"
sohan.jyotie3bd6192014-10-13 07:13:5929#include "cc/test/fake_picture_layer.h"
30#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0331#include "cc/test/geometry_test_utils.h"
[email protected]28336d52014-05-12 19:07:2832#include "cc/test/layer_tree_host_common_test.h"
reveman34b7a1522015-03-23 20:27:4733#include "cc/test/test_task_graph_runner.h"
ennef6903532015-08-18 05:10:1534#include "cc/trees/draw_property_utils.h"
[email protected]556fd292013-03-18 08:03:0435#include "cc/trees/layer_tree_impl.h"
[email protected]556fd292013-03-18 08:03:0436#include "cc/trees/single_thread_proxy.h"
khushalsagarb64b360d2015-10-21 19:25:1637#include "cc/trees/task_runner_provider.h"
[email protected]7f0c53db2012-10-02 00:23:1838#include "testing/gmock/include/gmock/gmock.h"
39#include "testing/gtest/include/gtest/gtest.h"
heejin.r.chungd28506ba2014-10-23 16:36:2040#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3741#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0042#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1443
[email protected]ba565742012-11-10 09:29:4844namespace cc {
[email protected]94f206c12012-08-25 00:09:1445namespace {
46
[email protected]96baf3e2012-10-22 23:09:5547class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:3248 public:
loysoa6edaaff2015-05-25 03:26:4449 explicit LayerWithForcedDrawsContent(const LayerSettings& settings)
50 : Layer(settings) {}
[email protected]94f206c12012-08-25 00:09:1451
dcheng716bedf2014-10-21 09:51:0852 bool DrawsContent() const override;
[email protected]d58499a2012-10-09 22:27:4753
[email protected]fb661802013-03-25 01:59:3254 private:
dcheng716bedf2014-10-21 09:51:0855 ~LayerWithForcedDrawsContent() override {}
[email protected]94f206c12012-08-25 00:09:1456};
57
[email protected]fb661802013-03-25 01:59:3258bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:4459
[email protected]96baf3e2012-10-22 23:09:5560class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:3261 public:
62 MockContentLayerClient() {}
dcheng716bedf2014-10-21 09:51:0863 ~MockContentLayerClient() override {}
chrishtr01539b802015-11-24 08:11:3264 gfx::Rect PaintableRegion() override { return gfx::Rect(); }
jbroman16d628c2015-05-29 20:11:5965 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
ajuma5e77f7d42014-11-27 14:19:1466 const gfx::Rect& clip,
schenney0154bfa2015-02-05 19:46:4967 PaintingControlSetting picture_control) override {
ajuma5e77f7d42014-11-27 14:19:1468 NOTIMPLEMENTED();
jbroman16d628c2015-05-29 20:11:5969 return nullptr;
ajuma5e77f7d42014-11-27 14:19:1470 }
dcheng716bedf2014-10-21 09:51:0871 bool FillsBoundsCompletely() const override { return false; }
jbroman9f60f1a2015-07-16 21:40:3272 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; }
[email protected]f34a24232012-09-20 22:59:5573};
74
[email protected]989386c2013-07-18 21:37:2375#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
76 do { \
77 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
78 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:4779 } while (false)
80
enne637715732015-07-07 02:05:2681#define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
82 do { \
83 EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \
sohan.jyotie3bd6192014-10-13 07:13:5984 } while (false)
85
enne637715732015-07-07 02:05:2686class LayerTreeSettingsScaleContent : public LayerTreeSettings {
87 public:
88 LayerTreeSettingsScaleContent() {
89 layer_transforms_should_scale_layer_contents = true;
90 }
91};
92
93class LayerTreeHostCommonScalingTest : public LayerTreeHostCommonTest {
94 public:
95 LayerTreeHostCommonScalingTest()
96 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
97};
98
[email protected]989386c2013-07-18 21:37:2399TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32100 // Sanity check: For layers positioned at zero, with zero size,
101 // and with identity transforms, then the draw transform,
102 // screen space transform, and the hierarchy passed on to children
103 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14104
loysoa6edaaff2015-05-25 03:26:44105 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
106 scoped_refptr<Layer> child = Layer::Create(layer_settings());
107 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:32108 parent->AddChild(child);
109 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14110
ennea7b43c32015-06-18 20:01:33111 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:28112
[email protected]fb661802013-03-25 01:59:32113 gfx::Transform identity_matrix;
114 SetLayerPropertiesForTesting(parent.get(),
115 identity_matrix,
[email protected]a2566412014-06-05 03:14:20116 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32117 gfx::PointF(),
118 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:57119 true,
[email protected]fb661802013-03-25 01:59:32120 false);
121 SetLayerPropertiesForTesting(child.get(),
122 identity_matrix,
[email protected]a2566412014-06-05 03:14:20123 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32124 gfx::PointF(),
125 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57126 true,
[email protected]fb661802013-03-25 01:59:32127 false);
128 SetLayerPropertiesForTesting(grand_child.get(),
129 identity_matrix,
[email protected]a2566412014-06-05 03:14:20130 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32131 gfx::PointF(),
132 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57133 true,
[email protected]fb661802013-03-25 01:59:32134 false);
[email protected]94f206c12012-08-25 00:09:14135
[email protected]fb661802013-03-25 01:59:32136 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14137
[email protected]fb661802013-03-25 01:59:32138 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
139 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
140 child->screen_space_transform());
141 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
142 grand_child->draw_transform());
143 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
144 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14145}
146
[email protected]f9e56702014-06-13 01:19:59147TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) {
enne367152322015-08-18 18:06:09148 LayerImpl* parent = root_layer();
149 LayerImpl* child = AddChild<LayerImpl>(parent);
150 LayerImpl* grand_child = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:36151 child->SetDrawsContent(true);
152 grand_child->SetDrawsContent(true);
[email protected]f9e56702014-06-13 01:19:59153
154 gfx::Transform identity_matrix;
enne367152322015-08-18 18:06:09155 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
156 gfx::PointF(), gfx::Size(100, 100), true, false,
157 true);
158 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
159 gfx::PointF(10, 10), gfx::Size(100, 100), true,
160 false, false);
[email protected]f9e56702014-06-13 01:19:59161 // This would have previously caused us to skip our subtree, but this would be
162 // wrong; we need up-to-date draw properties to do hit testing on the layers
163 // with handlers.
164 child->SetOpacity(0.f);
enne367152322015-08-18 18:06:09165 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
166 gfx::PointF(10, 10), gfx::Size(100, 100), true,
167 false, false);
[email protected]f9e56702014-06-13 01:19:59168 grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
169
enne367152322015-08-18 18:06:09170 ExecuteCalculateDrawProperties(parent);
[email protected]f9e56702014-06-13 01:19:59171
172 // Check that we've computed draw properties for the subtree rooted at
173 // |child|.
ajumad9432e32015-11-30 19:43:44174 EXPECT_FALSE(child->draw_properties().target_space_transform.IsIdentity());
175 EXPECT_FALSE(
176 grand_child->draw_properties().target_space_transform.IsIdentity());
[email protected]f9e56702014-06-13 01:19:59177}
178
[email protected]989386c2013-07-18 21:37:23179TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32180 gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:44181 scoped_refptr<Layer> layer = Layer::Create(layer_settings());
[email protected]94f206c12012-08-25 00:09:14182
loysoa6edaaff2015-05-25 03:26:44183 scoped_refptr<Layer> root = Layer::Create(layer_settings());
enne826452722015-08-18 22:22:31184 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
185 gfx::PointF(), gfx::Size(1, 2), true, false);
[email protected]fb661802013-03-25 01:59:32186 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42187
ennea7b43c32015-06-18 20:01:33188 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:28189
enne826452722015-08-18 22:22:31190 TransformTree& tree = host()->property_trees()->transform_tree;
191
[email protected]fb661802013-03-25 01:59:32192 // Case 2: Setting the bounds of the layer should not affect either the draw
193 // transform or the screenspace transform.
194 gfx::Transform translation_to_center;
195 translation_to_center.Translate(5.0, 6.0);
enne826452722015-08-18 22:22:31196 SetLayerPropertiesForTesting(layer.get(), identity_matrix, gfx::Point3F(),
197 gfx::PointF(), gfx::Size(10, 12), true, false);
[email protected]fb661802013-03-25 01:59:32198 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31199 EXPECT_TRANSFORMATION_MATRIX_EQ(
200 identity_matrix, DrawTransformFromPropertyTrees(layer.get(), tree));
201 EXPECT_TRANSFORMATION_MATRIX_EQ(
202 identity_matrix,
203 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
[email protected]94f206c12012-08-25 00:09:14204
[email protected]fb661802013-03-25 01:59:32205 // Case 3: The anchor point by itself (without a layer transform) should have
206 // no effect on the transforms.
enne826452722015-08-18 22:22:31207 SetLayerPropertiesForTesting(layer.get(), identity_matrix,
208 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
209 gfx::Size(10, 12), true, false);
[email protected]fb661802013-03-25 01:59:32210 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31211 EXPECT_TRANSFORMATION_MATRIX_EQ(
212 identity_matrix, DrawTransformFromPropertyTrees(layer.get(), tree));
213 EXPECT_TRANSFORMATION_MATRIX_EQ(
214 identity_matrix,
215 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
[email protected]94f206c12012-08-25 00:09:14216
[email protected]fb661802013-03-25 01:59:32217 // Case 4: A change in actual position affects both the draw transform and
218 // screen space transform.
219 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05220 position_transform.Translate(0.f, 1.2f);
enne826452722015-08-18 22:22:31221 SetLayerPropertiesForTesting(
222 layer.get(), identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
223 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
[email protected]fb661802013-03-25 01:59:32224 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31225 EXPECT_TRANSFORMATION_MATRIX_EQ(
226 position_transform, DrawTransformFromPropertyTrees(layer.get(), tree));
227 EXPECT_TRANSFORMATION_MATRIX_EQ(
228 position_transform,
229 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
[email protected]94f206c12012-08-25 00:09:14230
[email protected]fb661802013-03-25 01:59:32231 // Case 5: In the correct sequence of transforms, the layer transform should
232 // pre-multiply the translation_to_center. This is easily tested by using a
233 // scale transform, because scale and translation are not commutative.
234 gfx::Transform layer_transform;
235 layer_transform.Scale3d(2.0, 2.0, 1.0);
enne826452722015-08-18 22:22:31236 SetLayerPropertiesForTesting(layer.get(), layer_transform, gfx::Point3F(),
237 gfx::PointF(), gfx::Size(10, 12), true, false);
[email protected]fb661802013-03-25 01:59:32238 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31239 EXPECT_TRANSFORMATION_MATRIX_EQ(
240 layer_transform, DrawTransformFromPropertyTrees(layer.get(), tree));
241 EXPECT_TRANSFORMATION_MATRIX_EQ(
242 layer_transform,
243 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
[email protected]94f206c12012-08-25 00:09:14244
[email protected]fb661802013-03-25 01:59:32245 // Case 6: The layer transform should occur with respect to the anchor point.
246 gfx::Transform translation_to_anchor;
247 translation_to_anchor.Translate(5.0, 0.0);
248 gfx::Transform expected_result =
249 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
enne826452722015-08-18 22:22:31250 SetLayerPropertiesForTesting(layer.get(), layer_transform,
251 gfx::Point3F(5.0f, 0.f, 0.f), gfx::PointF(),
252 gfx::Size(10, 12), true, false);
[email protected]fb661802013-03-25 01:59:32253 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31254 EXPECT_TRANSFORMATION_MATRIX_EQ(
255 expected_result, DrawTransformFromPropertyTrees(layer.get(), tree));
256 EXPECT_TRANSFORMATION_MATRIX_EQ(
257 expected_result,
258 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
[email protected]94f206c12012-08-25 00:09:14259
[email protected]fb661802013-03-25 01:59:32260 // Case 7: Verify that position pre-multiplies the layer transform. The
261 // current implementation of CalculateDrawProperties does this implicitly, but
262 // it is still worth testing to detect accidental regressions.
263 expected_result = position_transform * translation_to_anchor *
264 layer_transform * Inverse(translation_to_anchor);
enne826452722015-08-18 22:22:31265 SetLayerPropertiesForTesting(
266 layer.get(), layer_transform, gfx::Point3F(5.0f, 0.f, 0.f),
267 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
[email protected]fb661802013-03-25 01:59:32268 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31269 EXPECT_TRANSFORMATION_MATRIX_EQ(
270 expected_result, DrawTransformFromPropertyTrees(layer.get(), tree));
271 EXPECT_TRANSFORMATION_MATRIX_EQ(
272 expected_result,
273 ScreenSpaceTransformFromPropertyTrees(layer.get(), tree));
[email protected]94f206c12012-08-25 00:09:14274}
275
[email protected]989386c2013-07-18 21:37:23276TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13277 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32278 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01279 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32280 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
281 -kScrollOffset.y());
282 const float kPageScale = 0.888f;
283 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20284
khushalsagarb64b360d2015-10-21 19:25:16285 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:45286 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:56287 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:16288 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:56289 &task_graph_runner);
[email protected]657b24c2013-03-06 09:01:20290
[email protected]fb661802013-03-25 01:59:32291 gfx::Transform identity_matrix;
292 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
293 LayerImpl::Create(host_impl.active_tree(), 1));
294 LayerImpl* sublayer = sublayer_scoped_ptr.get();
jaydasika0d98ba92015-11-17 05:17:28295 sublayer->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:00296 SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(),
297 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:32298 false);
[email protected]657b24c2013-03-06 09:01:20299
[email protected]adeda572014-01-31 00:49:47300 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32301 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47302 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
awoloszyne83f28c2014-12-22 15:40:00303 SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(),
304 gfx::PointF(), gfx::Size(10, 20), true, false,
[email protected]fb661802013-03-25 01:59:32305 false);
[email protected]adeda572014-01-31 00:49:47306 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
307 LayerImpl::Create(host_impl.active_tree(), 4));
308 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
309
310 scroll_layer->SetScrollClipLayer(clip_layer->id());
311 clip_layer->SetBounds(
312 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
313 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
314 scroll_layer->SetScrollClipLayer(clip_layer->id());
[email protected]fb661802013-03-25 01:59:32315 scroll_layer->SetScrollDelta(kScrollDelta);
316 gfx::Transform impl_transform;
danakja04855a2015-11-18 20:39:10317 scroll_layer->AddChild(std::move(sublayer_scoped_ptr));
[email protected]adeda572014-01-31 00:49:47318 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
danakja04855a2015-11-18 20:39:10319 clip_layer->AddChild(std::move(scroll_layer_scoped_ptr));
aeliasf998da82015-02-03 01:40:51320 scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20321
[email protected]fb661802013-03-25 01:59:32322 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
awoloszyne83f28c2014-12-22 15:40:00323 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
324 gfx::PointF(), gfx::Size(3, 4), true, false,
[email protected]fb661802013-03-25 01:59:32325 false);
danakja04855a2015-11-18 20:39:10326 root->AddChild(std::move(clip_layer_scoped_ptr));
awoloszyne83f28c2014-12-22 15:40:00327 root->SetHasRenderSurface(true);
[email protected]657b24c2013-03-06 09:01:20328
[email protected]f2136262013-04-26 21:10:19329 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32330 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32331 gfx::Transform expected_transform = identity_matrix;
332 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
danakj2c8d12c2015-06-18 06:15:33333 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() *
334 kPageScale * kDeviceScale),
335 MathUtil::Round(sub_layer_screen_position.y() *
336 kPageScale * kDeviceScale));
337 expected_transform.Scale(kPageScale * kDeviceScale,
338 kPageScale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32339 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44340 sublayer->DrawTransform());
[email protected]fb661802013-03-25 01:59:32341 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
342 sublayer->screen_space_transform());
[email protected]657b24c2013-03-06 09:01:20343
[email protected]fb661802013-03-25 01:59:32344 gfx::Transform arbitrary_translate;
345 const float kTranslateX = 10.6f;
346 const float kTranslateY = 20.6f;
347 arbitrary_translate.Translate(kTranslateX, kTranslateY);
awoloszyne83f28c2014-12-22 15:40:00348 SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate,
349 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
350 true, false, false);
jaydasika0d98ba92015-11-17 05:17:28351 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]f2136262013-04-26 21:10:19352 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32353 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32354 expected_transform.MakeIdentity();
355 expected_transform.Translate(
356 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
danakj2c8d12c2015-06-18 06:15:33357 sub_layer_screen_position.x() * kPageScale *
358 kDeviceScale),
[email protected]fb661802013-03-25 01:59:32359 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
danakj2c8d12c2015-06-18 06:15:33360 sub_layer_screen_position.y() * kPageScale *
361 kDeviceScale));
362 expected_transform.Scale(kPageScale * kDeviceScale,
363 kPageScale * kDeviceScale);
[email protected]fb661802013-03-25 01:59:32364 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
ajumad9432e32015-11-30 19:43:44365 sublayer->DrawTransform());
[email protected]657b24c2013-03-06 09:01:20366}
367
[email protected]989386c2013-07-18 21:37:23368TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32369 gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:44370 scoped_refptr<Layer> root = Layer::Create(layer_settings());
371 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
372 scoped_refptr<Layer> child = Layer::Create(layer_settings());
373 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:32374 root->AddChild(parent);
375 parent->AddChild(child);
376 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14377
ennea7b43c32015-06-18 20:01:33378 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:28379
[email protected]fb661802013-03-25 01:59:32380 // One-time setup of root layer
enne826452722015-08-18 22:22:31381 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
382 gfx::PointF(), gfx::Size(1, 2), true, false);
383
384 TransformTree& tree = host()->property_trees()->transform_tree;
[email protected]ecc12622012-10-30 20:45:42385
[email protected]fb661802013-03-25 01:59:32386 // Case 1: parent's anchor point should not affect child or grand_child.
enne826452722015-08-18 22:22:31387 SetLayerPropertiesForTesting(parent.get(), identity_matrix,
388 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
389 gfx::Size(10, 12), true, false);
390 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
391 gfx::PointF(), gfx::Size(16, 18), true, false);
392 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
393 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
394 true, false);
[email protected]fb661802013-03-25 01:59:32395 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31396
397 EXPECT_TRANSFORMATION_MATRIX_EQ(
398 identity_matrix, DrawTransformFromPropertyTrees(child.get(), tree));
399 EXPECT_TRANSFORMATION_MATRIX_EQ(
400 identity_matrix,
401 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
402 EXPECT_TRANSFORMATION_MATRIX_EQ(
403 identity_matrix, DrawTransformFromPropertyTrees(grand_child.get(), tree));
404 EXPECT_TRANSFORMATION_MATRIX_EQ(
405 identity_matrix,
406 ScreenSpaceTransformFromPropertyTrees(grand_child.get(), tree));
[email protected]94f206c12012-08-25 00:09:14407
[email protected]fb661802013-03-25 01:59:32408 // Case 2: parent's position affects child and grand_child.
409 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05410 parent_position_transform.Translate(0.f, 1.2f);
enne826452722015-08-18 22:22:31411 SetLayerPropertiesForTesting(
412 parent.get(), identity_matrix, gfx::Point3F(2.5f, 3.0f, 0.f),
413 gfx::PointF(0.f, 1.2f), gfx::Size(10, 12), true, false);
414 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
415 gfx::PointF(), gfx::Size(16, 18), true, false);
416 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
417 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
418 true, false);
[email protected]fb661802013-03-25 01:59:32419 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31420 EXPECT_TRANSFORMATION_MATRIX_EQ(
421 parent_position_transform,
422 DrawTransformFromPropertyTrees(child.get(), tree));
423 EXPECT_TRANSFORMATION_MATRIX_EQ(
424 parent_position_transform,
425 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
426 EXPECT_TRANSFORMATION_MATRIX_EQ(
427 parent_position_transform,
428 DrawTransformFromPropertyTrees(grand_child.get(), tree));
429 EXPECT_TRANSFORMATION_MATRIX_EQ(
430 parent_position_transform,
431 ScreenSpaceTransformFromPropertyTrees(grand_child.get(), tree));
[email protected]94f206c12012-08-25 00:09:14432
[email protected]fb661802013-03-25 01:59:32433 // Case 3: parent's local transform affects child and grandchild
434 gfx::Transform parent_layer_transform;
435 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
436 gfx::Transform parent_translation_to_anchor;
437 parent_translation_to_anchor.Translate(2.5, 3.0);
438 gfx::Transform parent_composite_transform =
439 parent_translation_to_anchor * parent_layer_transform *
440 Inverse(parent_translation_to_anchor);
enne826452722015-08-18 22:22:31441 SetLayerPropertiesForTesting(parent.get(), parent_layer_transform,
442 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
443 gfx::Size(10, 12), true, false);
444 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
445 gfx::PointF(), gfx::Size(16, 18), true, false);
446 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
447 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
448 true, false);
[email protected]fb661802013-03-25 01:59:32449 ExecuteCalculateDrawProperties(root.get());
enne826452722015-08-18 22:22:31450 EXPECT_TRANSFORMATION_MATRIX_EQ(
451 parent_composite_transform,
452 DrawTransformFromPropertyTrees(child.get(), tree));
453 EXPECT_TRANSFORMATION_MATRIX_EQ(
454 parent_composite_transform,
455 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
456 EXPECT_TRANSFORMATION_MATRIX_EQ(
457 parent_composite_transform,
458 DrawTransformFromPropertyTrees(grand_child.get(), tree));
459 EXPECT_TRANSFORMATION_MATRIX_EQ(
460 parent_composite_transform,
461 ScreenSpaceTransformFromPropertyTrees(grand_child.get(), tree));
[email protected]94f206c12012-08-25 00:09:14462}
463
[email protected]989386c2013-07-18 21:37:23464TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
enne25dea3f2015-07-27 16:44:28465 LayerImpl* root = root_layer();
466 LayerImpl* parent = AddChildToRoot<LayerImpl>();
467 LayerImpl* child = AddChild<LayerImpl>(parent);
468 LayerImpl* grand_child = AddChild<LayerImpl>(child);
469 grand_child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:14470
[email protected]fb661802013-03-25 01:59:32471 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28472 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
473 gfx::PointF(), gfx::Size(1, 2), true, false,
474 true);
[email protected]ecc12622012-10-30 20:45:42475
[email protected]fb661802013-03-25 01:59:32476 // Child is set up so that a new render surface should be created.
477 child->SetOpacity(0.5f);
jaydasika8640f9f2015-11-10 01:34:36478 child->SetDrawsContent(true);
[email protected]94f206c12012-08-25 00:09:14479
[email protected]fb661802013-03-25 01:59:32480 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05481 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32482 gfx::Transform parent_translation_to_anchor;
483 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44484
[email protected]fb661802013-03-25 01:59:32485 gfx::Transform parent_composite_transform =
486 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39487 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32488 gfx::Vector2dF parent_composite_scale =
489 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
490 1.f);
491 gfx::Transform surface_sublayer_transform;
492 surface_sublayer_transform.Scale(parent_composite_scale.x(),
493 parent_composite_scale.y());
494 gfx::Transform surface_sublayer_composite_transform =
495 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14496
enne25dea3f2015-07-27 16:44:28497 SetLayerPropertiesForTesting(parent, parent_layer_transform,
498 gfx::Point3F(25.0f, 30.0f, 0.f), gfx::PointF(),
499 gfx::Size(100, 120), true, false, false);
500 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
501 gfx::PointF(), gfx::Size(16, 18), true, false,
502 true);
503 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
504 gfx::PointF(), gfx::Size(8, 10), true, false,
[email protected]fb661802013-03-25 01:59:32505 false);
enne25dea3f2015-07-27 16:44:28506 ExecuteCalculateDrawProperties(root);
[email protected]94f206c12012-08-25 00:09:14507
[email protected]fb661802013-03-25 01:59:32508 // Render surface should have been created now.
509 ASSERT_TRUE(child->render_surface());
enne25dea3f2015-07-27 16:44:28510 ASSERT_EQ(child, child->render_target());
[email protected]94f206c12012-08-25 00:09:14511
[email protected]fb661802013-03-25 01:59:32512 // The child layer's draw transform should refer to its new render surface.
513 // The screen-space transform, however, should still refer to the root.
514 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
ajumad9432e32015-11-30 19:43:44515 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32516 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
517 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14518
[email protected]fb661802013-03-25 01:59:32519 // Because the grand_child is the only drawable content, the child's render
520 // surface will tighten its bounds to the grand_child. The scale at which the
521 // surface's subtree is drawn must be removed from the composite transform.
522 EXPECT_TRANSFORMATION_MATRIX_EQ(
523 surface_sublayer_composite_transform,
524 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14525
[email protected]fb661802013-03-25 01:59:32526 // The screen space is the same as the target since the child surface draws
527 // into the root.
528 EXPECT_TRANSFORMATION_MATRIX_EQ(
529 surface_sublayer_composite_transform,
530 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14531}
532
ajuma51d73f72015-10-19 19:43:58533TEST_F(LayerTreeHostCommonTest, TransformsWhenCannotRenderToSeparateSurface) {
534 LayerImpl* root = root_layer();
535 LayerImpl* parent = AddChildToRoot<LayerImpl>();
536 LayerImpl* child = AddChild<LayerImpl>(parent);
537 LayerImpl* grand_child = AddChild<LayerImpl>(child);
538 grand_child->SetDrawsContent(true);
539
540 gfx::Transform identity_matrix;
541 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
542 gfx::PointF(), gfx::Size(100, 100), true, false,
543 true);
544
545 gfx::Transform parent_transform;
546 parent_transform.Translate(10.0, 10.0);
547
548 gfx::Transform child_transform;
549 child_transform.Rotate(45.0);
550
551 // child gets a render surface when surfaces are enabled.
552 SetLayerPropertiesForTesting(parent, parent_transform, gfx::Point3F(),
553 gfx::PointF(), gfx::Size(10, 10), true, false,
554 false);
555 SetLayerPropertiesForTesting(child, child_transform, gfx::Point3F(),
556 gfx::PointF(), gfx::Size(10, 10), true, false,
557 true);
558 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
559 gfx::PointF(2.0, 2.0), gfx::Size(20, 20), true,
560 false, false);
561
562 gfx::Transform expected_grand_child_screen_space_transform;
563 expected_grand_child_screen_space_transform.Translate(10.0, 10.0);
564 expected_grand_child_screen_space_transform.Rotate(45.0);
565 expected_grand_child_screen_space_transform.Translate(2.0, 2.0);
566
567 // First compute draw properties with separate surfaces enabled.
568 ExecuteCalculateDrawProperties(root);
569
570 // The grand child's draw transform should be its offset wrt the child.
571 gfx::Transform expected_grand_child_draw_transform;
572 expected_grand_child_draw_transform.Translate(2.0, 2.0);
573 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44574 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58575 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
576 grand_child->screen_space_transform());
577
578 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
579
580 // With separate surfaces disabled, the grand child's draw transform should be
581 // the same as its screen space transform.
582 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
ajumad9432e32015-11-30 19:43:44583 grand_child->DrawTransform());
ajuma51d73f72015-10-19 19:43:58584 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
585 grand_child->screen_space_transform());
586}
587
[email protected]989386c2013-07-18 21:37:23588TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
enne25dea3f2015-07-27 16:44:28589 LayerImpl* root = root_layer();
590 LayerImpl* parent = AddChildToRoot<LayerImpl>();
591 LayerImpl* child = AddChild<LayerImpl>(parent);
592 LayerImpl* grand_child = AddChild<LayerImpl>(child);
593 grand_child->SetDrawsContent(true);
594 scoped_ptr<LayerImpl> child_replica =
595 LayerImpl::Create(host_impl()->active_tree(), 100);
[email protected]d600df7d2013-08-03 02:34:28596
[email protected]fb661802013-03-25 01:59:32597 // One-time setup of root layer
598 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28599 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
600 gfx::PointF(), gfx::Size(1, 2), true, false,
601 true);
[email protected]fb661802013-03-25 01:59:32602
603 // Child is set up so that a new render surface should be created.
604 child->SetOpacity(0.5f);
605
606 gfx::Transform parent_layer_transform;
607 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
608 gfx::Transform parent_translation_to_anchor;
609 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32610 gfx::Transform parent_composite_transform =
611 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39612 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32613 gfx::Transform replica_layer_transform;
614 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
615 gfx::Vector2dF parent_composite_scale =
616 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
617 1.f);
618 gfx::Transform surface_sublayer_transform;
619 surface_sublayer_transform.Scale(parent_composite_scale.x(),
620 parent_composite_scale.y());
621 gfx::Transform replica_composite_transform =
622 parent_composite_transform * replica_layer_transform *
623 Inverse(surface_sublayer_transform);
enne25dea3f2015-07-27 16:44:28624 child_replica->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32625 // Child's render surface should not exist yet.
626 ASSERT_FALSE(child->render_surface());
627
enne25dea3f2015-07-27 16:44:28628 SetLayerPropertiesForTesting(parent, parent_layer_transform,
629 gfx::Point3F(2.5f, 3.0f, 0.f), gfx::PointF(),
630 gfx::Size(10, 12), true, false, false);
631 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
632 gfx::PointF(), gfx::Size(16, 18), true, false,
633 true);
634 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
635 gfx::PointF(-0.5f, -0.5f), gfx::Size(1, 1), true,
636 false, false);
637 SetLayerPropertiesForTesting(child_replica.get(), replica_layer_transform,
638 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
639 false, false);
danakja04855a2015-11-18 20:39:10640 child->SetReplicaLayer(std::move(child_replica));
enne25dea3f2015-07-27 16:44:28641
642 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32643
644 // Render surface should have been created now.
645 ASSERT_TRUE(child->render_surface());
enne25dea3f2015-07-27 16:44:28646 ASSERT_EQ(child, child->render_target());
[email protected]fb661802013-03-25 01:59:32647
648 EXPECT_TRANSFORMATION_MATRIX_EQ(
649 replica_composite_transform,
650 child->render_target()->render_surface()->replica_draw_transform());
651 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57652 child->render_target()
653 ->render_surface()
[email protected]fb661802013-03-25 01:59:32654 ->replica_screen_space_transform());
655}
656
[email protected]989386c2013-07-18 21:37:23657TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32658 // This test creates a more complex tree and verifies it all at once. This
659 // covers the following cases:
660 // - layers that are described w.r.t. a render surface: should have draw
661 // transforms described w.r.t. that surface
662 // - A render surface described w.r.t. an ancestor render surface: should
663 // have a draw transform described w.r.t. that ancestor surface
664 // - Replicas of a render surface are described w.r.t. the replica's
665 // transform around its anchor, along with the surface itself.
666 // - Sanity check on recursion: verify transforms of layers described w.r.t.
667 // a render surface that is described w.r.t. an ancestor render surface.
668 // - verifying that each layer has a reference to the correct render surface
669 // and render target values.
670
enne25dea3f2015-07-27 16:44:28671 LayerImpl* root = root_layer();
672 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36673 parent->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28674 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36675 render_surface1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28676 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36677 render_surface2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28678 LayerImpl* child_of_root = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:36679 child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28680 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
jaydasika8640f9f2015-11-10 01:34:36681 child_of_rs1->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28682 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:36683 child_of_rs2->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28684 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
jaydasika8640f9f2015-11-10 01:34:36685 grand_child_of_root->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28686 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
687 grand_child_of_rs1->SetDrawsContent(true);
688 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
689 grand_child_of_rs2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32690
enne25dea3f2015-07-27 16:44:28691 scoped_ptr<LayerImpl> replica_of_rs1 =
692 LayerImpl::Create(host_impl()->active_tree(), 101);
693 scoped_ptr<LayerImpl> replica_of_rs2 =
694 LayerImpl::Create(host_impl()->active_tree(), 102);
[email protected]d600df7d2013-08-03 02:34:28695
[email protected]fb661802013-03-25 01:59:32696 // In combination with descendant draws content, opacity != 1 forces the layer
697 // to have a new render surface.
698 render_surface1->SetOpacity(0.5f);
699 render_surface2->SetOpacity(0.33f);
700
701 // One-time setup of root layer
702 gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28703 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
704 gfx::PointF(), gfx::Size(1, 2), true, false,
705 true);
[email protected]fb661802013-03-25 01:59:32706
707 // All layers in the tree are initialized with an anchor at .25 and a size of
708 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39709 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32710 gfx::Transform translation_to_anchor;
711 translation_to_anchor.Translate(2.5, 0.0);
712 gfx::Transform layer_transform;
713 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32714 gfx::Transform replica_layer_transform;
715 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
716
717 gfx::Transform A =
718 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32719 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
720 Inverse(translation_to_anchor);
721
722 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39723 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32724 gfx::Transform surface1_sublayer_transform;
725 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
726 surface1_parent_transform_scale.y());
727
728 // SS1 = transform given to the subtree of render_surface1
729 gfx::Transform SS1 = surface1_sublayer_transform;
730 // S1 = transform to move from render_surface1 pixels to the layer space of
731 // the owning layer
732 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
733
734 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39735 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32736 gfx::Transform surface2_sublayer_transform;
737 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
738 surface2_parent_transform_scale.y());
739
740 // SS2 = transform given to the subtree of render_surface2
741 gfx::Transform SS2 = surface2_sublayer_transform;
742 // S2 = transform to move from render_surface2 pixels to the layer space of
743 // the owning layer
744 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
745
enne25dea3f2015-07-27 16:44:28746 SetLayerPropertiesForTesting(parent, layer_transform,
747 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
748 gfx::Size(10, 10), true, false, false);
749 SetLayerPropertiesForTesting(render_surface1, layer_transform,
750 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
751 gfx::Size(10, 10), true, false, true);
752 SetLayerPropertiesForTesting(render_surface2, layer_transform,
753 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
754 gfx::Size(10, 10), true, false, true);
755 SetLayerPropertiesForTesting(child_of_root, layer_transform,
756 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
757 gfx::Size(10, 10), true, false, false);
758 SetLayerPropertiesForTesting(child_of_rs1, layer_transform,
759 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
760 gfx::Size(10, 10), true, false, false);
761 SetLayerPropertiesForTesting(child_of_rs2, layer_transform,
762 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
763 gfx::Size(10, 10), true, false, false);
764 SetLayerPropertiesForTesting(grand_child_of_root, layer_transform,
765 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
766 gfx::Size(10, 10), true, false, false);
767 SetLayerPropertiesForTesting(grand_child_of_rs1, layer_transform,
768 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
769 gfx::Size(10, 10), true, false, false);
770 SetLayerPropertiesForTesting(grand_child_of_rs2, layer_transform,
771 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
772 gfx::Size(10, 10), true, false, false);
773 SetLayerPropertiesForTesting(replica_of_rs1.get(), replica_layer_transform,
774 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
775 gfx::Size(), true, false, false);
776 SetLayerPropertiesForTesting(replica_of_rs2.get(), replica_layer_transform,
777 gfx::Point3F(2.5f, 0.f, 0.f), gfx::PointF(),
778 gfx::Size(), true, false, false);
[email protected]fb661802013-03-25 01:59:32779
danakja04855a2015-11-18 20:39:10780 render_surface1->SetReplicaLayer(std::move(replica_of_rs1));
781 render_surface2->SetReplicaLayer(std::move(replica_of_rs2));
enne25dea3f2015-07-27 16:44:28782 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32783
784 // Only layers that are associated with render surfaces should have an actual
785 // RenderSurface() value.
786 ASSERT_TRUE(root->render_surface());
787 ASSERT_FALSE(child_of_root->render_surface());
788 ASSERT_FALSE(grand_child_of_root->render_surface());
789
790 ASSERT_TRUE(render_surface1->render_surface());
791 ASSERT_FALSE(child_of_rs1->render_surface());
792 ASSERT_FALSE(grand_child_of_rs1->render_surface());
793
794 ASSERT_TRUE(render_surface2->render_surface());
795 ASSERT_FALSE(child_of_rs2->render_surface());
796 ASSERT_FALSE(grand_child_of_rs2->render_surface());
797
798 // Verify all render target accessors
enne25dea3f2015-07-27 16:44:28799 EXPECT_EQ(root, parent->render_target());
800 EXPECT_EQ(root, child_of_root->render_target());
801 EXPECT_EQ(root, grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32802
enne25dea3f2015-07-27 16:44:28803 EXPECT_EQ(render_surface1, render_surface1->render_target());
804 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
805 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32806
enne25dea3f2015-07-27 16:44:28807 EXPECT_EQ(render_surface2, render_surface2->render_target());
808 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
809 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32810
811 // Verify layer draw transforms note that draw transforms are described with
812 // respect to the nearest ancestor render surface but screen space transforms
813 // are described with respect to the root.
ajumad9432e32015-11-30 19:43:44814 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->DrawTransform());
815 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39816 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
ajumad9432e32015-11-30 19:43:44817 grand_child_of_root->DrawTransform());
[email protected]fb661802013-03-25 01:59:32818
ajumad9432e32015-11-30 19:43:44819 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->DrawTransform());
820 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39821 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
ajumad9432e32015-11-30 19:43:44822 grand_child_of_rs1->DrawTransform());
[email protected]fb661802013-03-25 01:59:32823
ajumad9432e32015-11-30 19:43:44824 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->DrawTransform());
825 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->DrawTransform());
[email protected]baf64d062014-02-16 22:10:39826 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
ajumad9432e32015-11-30 19:43:44827 grand_child_of_rs2->DrawTransform());
[email protected]fb661802013-03-25 01:59:32828
829 // Verify layer screen-space transforms
830 //
831 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39832 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:32833 child_of_root->screen_space_transform());
834 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39835 A * A * A, grand_child_of_root->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32836
[email protected]baf64d062014-02-16 22:10:39837 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:32838 render_surface1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39839 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32840 child_of_rs1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39841 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:32842 grand_child_of_rs1->screen_space_transform());
843
[email protected]baf64d062014-02-16 22:10:39844 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32845 render_surface2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39846 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:32847 child_of_rs2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39848 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
[email protected]fb661802013-03-25 01:59:32849 grand_child_of_rs2->screen_space_transform());
850
851 // Verify render surface transforms.
852 //
853 // Draw transform of render surface 1 is described with respect to root.
854 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39855 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32856 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39857 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:32858 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39859 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32860 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39861 A * R * S1,
[email protected]fb661802013-03-25 01:59:32862 render_surface1->render_surface()->replica_screen_space_transform());
863 // Draw transform of render surface 2 is described with respect to render
864 // surface 1.
865 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39866 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32867 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39868 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:32869 render_surface2->render_surface()->replica_draw_transform());
870 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39871 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:32872 render_surface2->render_surface()->screen_space_transform());
873 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39874 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:32875 render_surface2->render_surface()->replica_screen_space_transform());
876
877 // Sanity check. If these fail there is probably a bug in the test itself. It
878 // is expected that we correctly set up transforms so that the y-component of
879 // the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:26880 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
881 EXPECT_FLOAT_EQ(2.0,
882 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32883 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:26884 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32885
[email protected]803f6b52013-09-12 00:51:26886 EXPECT_FLOAT_EQ(2.0,
887 render_surface1->screen_space_transform().matrix().get(1, 3));
888 EXPECT_FLOAT_EQ(3.0,
889 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32890 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:26891 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32892
[email protected]803f6b52013-09-12 00:51:26893 EXPECT_FLOAT_EQ(3.0,
894 render_surface2->screen_space_transform().matrix().get(1, 3));
895 EXPECT_FLOAT_EQ(4.0,
896 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32897 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:26898 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32899}
900
[email protected]989386c2013-07-18 21:37:23901TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:32902 // For layers that flatten their subtree, there should be an orthographic
903 // projection (for x and y values) in the middle of the transform sequence.
904 // Note that the way the code is currently implemented, it is not expected to
905 // use a canonical orthographic projection.
906
enne25dea3f2015-07-27 16:44:28907 LayerImpl* root = root_layer();
908 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:36909 child->SetDrawsContent(true);
enne25dea3f2015-07-27 16:44:28910 LayerImpl* grand_child = AddChild<LayerImpl>(child);
911 grand_child->SetDrawsContent(true);
912 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
913 great_grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:32914
915 gfx::Transform rotation_about_y_axis;
916 rotation_about_y_axis.RotateAboutYAxis(30.0);
917
918 const gfx::Transform identity_matrix;
enne25dea3f2015-07-27 16:44:28919 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
920 gfx::PointF(), gfx::Size(100, 100), true, false,
921 true);
922 SetLayerPropertiesForTesting(child, rotation_about_y_axis, gfx::Point3F(),
923 gfx::PointF(), gfx::Size(10, 10), true, false,
924 true);
925 SetLayerPropertiesForTesting(grand_child, rotation_about_y_axis,
ajumad0d64422015-03-14 04:20:08926 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
enne25dea3f2015-07-27 16:44:28927 true, false, false);
928 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
929 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
930 true, false, false);
[email protected]d600df7d2013-08-03 02:34:28931
[email protected]fb661802013-03-25 01:59:32932 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:57933 ASSERT_TRUE(root->should_flatten_transform());
934 ASSERT_TRUE(child->should_flatten_transform());
935 ASSERT_TRUE(grand_child->should_flatten_transform());
ajumad0d64422015-03-14 04:20:08936 ASSERT_TRUE(great_grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:32937
938 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
939 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
940 gfx::Transform expected_grand_child_draw_transform =
941 rotation_about_y_axis; // draws onto child's render surface
942 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
943 flattened_rotation_about_y.FlattenTo2d();
944 gfx::Transform expected_grand_child_screen_space_transform =
945 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:08946 gfx::Transform expected_great_grand_child_draw_transform =
947 flattened_rotation_about_y;
948 gfx::Transform expected_great_grand_child_screen_space_transform =
949 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:32950
enne25dea3f2015-07-27 16:44:28951 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:32952
953 // The child's draw transform should have been taken by its surface.
954 ASSERT_TRUE(child->render_surface());
955 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
956 child->render_surface()->draw_transform());
957 EXPECT_TRANSFORMATION_MATRIX_EQ(
958 expected_child_screen_space_transform,
959 child->render_surface()->screen_space_transform());
ajumad9432e32015-11-30 19:43:44960 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32961 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
962 child->screen_space_transform());
963 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44964 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:32965 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
966 grand_child->screen_space_transform());
ajumad0d64422015-03-14 04:20:08967 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
ajumad9432e32015-11-30 19:43:44968 great_grand_child->DrawTransform());
ajumad0d64422015-03-14 04:20:08969 EXPECT_TRANSFORMATION_MATRIX_EQ(
970 expected_great_grand_child_screen_space_transform,
971 great_grand_child->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32972}
973
ajumadbd92cb2015-07-16 13:47:06974TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) {
975 scoped_refptr<Layer> root = Layer::Create(layer_settings());
976 scoped_refptr<Layer> child = Layer::Create(layer_settings());
977 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
978 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
979
980 gfx::Transform child_transform;
981 child_transform.Translate(50.0, 50.0);
982 child_transform.RotateAboutZAxis(30.0);
983
984 gfx::Transform grand_child_transform;
985 grand_child_transform.RotateAboutYAxis(90.0);
986
987 const gfx::Transform identity_matrix;
988 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
989 gfx::PointF(), gfx::Size(200, 200), true, false);
990 SetLayerPropertiesForTesting(child.get(), child_transform, gfx::Point3F(),
991 gfx::PointF(), gfx::Size(10, 10), true, false);
992 SetLayerPropertiesForTesting(grand_child.get(), grand_child_transform,
993 gfx::Point3F(), gfx::PointF(),
994 gfx::Size(100, 100), true, false);
995
996 root->AddChild(child);
997 child->AddChild(grand_child);
998 grand_child->SetShouldFlattenTransform(false);
999
1000 host()->SetRootLayer(root);
1001
1002 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
1003
1004 // Mapping grand_child's bounds to target space produces a non-empty rect
1005 // that is fully contained within the target's bounds, so grand_child should
1006 // be considered fully visible.
1007 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
1008 grand_child->visible_rect_from_property_trees());
1009}
1010
[email protected]989386c2013-07-18 21:37:231011TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321012 // A layer that is empty in one axis, but not the other, was accidentally
1013 // skipping a necessary translation. Without that translation, the coordinate
1014 // space of the layer's draw transform is incorrect.
1015 //
1016 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1017 // but if that layer becomes a render surface, then its draw transform is
1018 // implicitly inherited by the rest of the subtree, which then is positioned
1019 // incorrectly as a result.
1020
ennec1332992015-08-24 19:45:091021 LayerImpl* root = root_layer();
1022 LayerImpl* child = AddChild<LayerImpl>(root);
1023 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1024 grand_child->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321025
1026 // The child height is zero, but has non-zero width that should be accounted
1027 // for while computing draw transforms.
1028 const gfx::Transform identity_matrix;
ennec1332992015-08-24 19:45:091029 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1030 gfx::PointF(), gfx::Size(100, 100), true, false,
1031 true);
1032 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1033 gfx::PointF(), gfx::Size(10, 0), true, false,
1034 true);
1035 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1036 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321037 false);
1038
ennec1332992015-08-24 19:45:091039 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:321040
ennec1332992015-08-24 19:45:091041 ASSERT_TRUE(child->has_render_surface());
[email protected]fb661802013-03-25 01:59:321042 // This is the real test, the rest are sanity checks.
1043 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1044 child->render_surface()->draw_transform());
ajumad9432e32015-11-30 19:43:441045 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321046 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
ajumad9432e32015-11-30 19:43:441047 grand_child->DrawTransform());
[email protected]fb661802013-03-25 01:59:321048}
1049
[email protected]989386c2013-07-18 21:37:231050TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321051 // Transformations applied at the root of the tree should be forwarded
1052 // to child layers instead of applied to the root RenderSurface.
1053 const gfx::Transform identity_matrix;
enned3f61fb02015-08-18 22:54:391054 LayerImpl* root = root_layer();
1055 root->SetDrawsContent(true);
1056 LayerImpl* child = AddChild<LayerImpl>(root);
1057 child->SetDrawsContent(true);
[email protected]f224cc92013-06-06 23:23:321058
enned3f61fb02015-08-18 22:54:391059 child->SetScrollClipLayer(root->id());
[email protected]d600df7d2013-08-03 02:34:281060
enned3f61fb02015-08-18 22:54:391061 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1062 gfx::PointF(), gfx::Size(20, 20), true, false,
1063 true);
1064 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1065 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]f224cc92013-06-06 23:23:321066 false);
1067
[email protected]f224cc92013-06-06 23:23:321068 gfx::Transform translate;
1069 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231070 {
enned3f61fb02015-08-18 22:54:391071 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441072 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391073 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441074 root, root->bounds(), translate, &render_surface_layer_list_impl,
1075 root->layer_tree_impl()->current_render_surface_list_id());
vollick5057e1e2015-04-17 19:12:321076 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531077 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231078 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1079 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1080 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1081 }
[email protected]f224cc92013-06-06 23:23:321082
1083 gfx::Transform scale;
1084 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231085 {
enned3f61fb02015-08-18 22:54:391086 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441087 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391088 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441089 root, root->bounds(), scale, &render_surface_layer_list_impl,
1090 root->layer_tree_impl()->current_render_surface_list_id());
vollick5057e1e2015-04-17 19:12:321091 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531092 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231093 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1094 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1095 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1096 }
[email protected]f224cc92013-06-06 23:23:321097
1098 gfx::Transform rotate;
1099 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231100 {
enned3f61fb02015-08-18 22:54:391101 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441102 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391103 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441104 root, root->bounds(), rotate, &render_surface_layer_list_impl,
1105 root->layer_tree_impl()->current_render_surface_list_id());
vollick5057e1e2015-04-17 19:12:321106 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531107 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231108 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1109 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1110 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1111 }
[email protected]f224cc92013-06-06 23:23:321112
1113 gfx::Transform composite;
1114 composite.ConcatTransform(translate);
1115 composite.ConcatTransform(scale);
1116 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231117 {
enned3f61fb02015-08-18 22:54:391118 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441119 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391120 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441121 root, root->bounds(), composite, &render_surface_layer_list_impl,
1122 root->layer_tree_impl()->current_render_surface_list_id());
vollick5057e1e2015-04-17 19:12:321123 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531124 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231125 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1126 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1127 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1128 }
[email protected]f224cc92013-06-06 23:23:321129
[email protected]9781afa2013-07-17 23:15:321130 // Verify it composes correctly with device scale.
1131 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231132
1133 {
enned3f61fb02015-08-18 22:54:391134 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441135 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391136 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441137 root, root->bounds(), translate, &render_surface_layer_list_impl,
1138 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:531139 inputs.device_scale_factor = device_scale_factor;
vollick5057e1e2015-04-17 19:12:321140 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531141 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231142 gfx::Transform device_scaled_translate = translate;
1143 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1144 EXPECT_EQ(device_scaled_translate,
1145 root->draw_properties().target_space_transform);
1146 EXPECT_EQ(device_scaled_translate,
1147 child->draw_properties().target_space_transform);
1148 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1149 }
[email protected]9781afa2013-07-17 23:15:321150
1151 // Verify it composes correctly with page scale.
1152 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231153
1154 {
enned3f61fb02015-08-18 22:54:391155 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441156 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391157 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441158 root, root->bounds(), translate, &render_surface_layer_list_impl,
1159 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:531160 inputs.page_scale_factor = page_scale_factor;
enned3f61fb02015-08-18 22:54:391161 inputs.page_scale_layer = root;
vollick5057e1e2015-04-17 19:12:321162 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531163 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231164 gfx::Transform page_scaled_translate = translate;
1165 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
enne6394d5b42015-05-26 22:23:111166 EXPECT_EQ(page_scaled_translate,
1167 root->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231168 EXPECT_EQ(page_scaled_translate,
1169 child->draw_properties().target_space_transform);
1170 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1171 }
[email protected]9781afa2013-07-17 23:15:321172
[email protected]f224cc92013-06-06 23:23:321173 // Verify that it composes correctly with transforms directly on root layer.
1174 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231175
1176 {
enned3f61fb02015-08-18 22:54:391177 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:441178 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enned3f61fb02015-08-18 22:54:391179 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441180 root, root->bounds(), composite, &render_surface_layer_list_impl,
1181 root->layer_tree_impl()->current_render_surface_list_id());
enned3f61fb02015-08-18 22:54:391182 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531183 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231184 gfx::Transform compositeSquared = composite;
1185 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261186 EXPECT_TRANSFORMATION_MATRIX_EQ(
1187 compositeSquared, root->draw_properties().target_space_transform);
1188 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391189 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231190 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1191 }
[email protected]f224cc92013-06-06 23:23:321192}
1193
[email protected]989386c2013-07-18 21:37:231194TEST_F(LayerTreeHostCommonTest,
1195 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
enneea850232015-07-27 16:43:121196 LayerImpl* parent = root_layer();
1197 parent->SetMasksToBounds(true);
1198 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
1199 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1200 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:281201
[email protected]fb661802013-03-25 01:59:321202 const gfx::Transform identity_matrix;
enneea850232015-07-27 16:43:121203 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1204 gfx::PointF(), gfx::Size(10, 10), true, false,
1205 true);
1206 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1207 gfx::PointF(), gfx::Size(10, 10), true, false,
1208 true);
1209 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1210 gfx::PointF(30.f, 30.f), gfx::Size(10, 10), true,
1211 false, false);
[email protected]fb661802013-03-25 01:59:321212
enneea850232015-07-27 16:43:121213 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321214
1215 // The child layer's content is entirely outside the parent's clip rect, so
1216 // the intermediate render surface should not be listed here, even if it was
1217 // forced to be created. Render surfaces without children or visible content
1218 // are unexpected at draw time (e.g. we might try to create a content texture
1219 // of size 0).
1220 ASSERT_TRUE(parent->render_surface());
enneea850232015-07-27 16:43:121221 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
[email protected]fb661802013-03-25 01:59:321222}
1223
[email protected]989386c2013-07-18 21:37:231224TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
enne03b0e9a2015-06-19 00:08:021225 LayerImpl* parent = root_layer();
1226 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
1227 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1228 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:281229
[email protected]fb661802013-03-25 01:59:321230 const gfx::Transform identity_matrix;
enne03b0e9a2015-06-19 00:08:021231 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1232 gfx::PointF(), gfx::Size(10, 10), true, false,
1233 true);
1234 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1235 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321236 false);
[email protected]fb661802013-03-25 01:59:321237 render_surface1->SetOpacity(0.f);
1238
enne03b0e9a2015-06-19 00:08:021239 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:441240 parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
enne03b0e9a2015-06-19 00:08:021241 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441242 parent, parent->bounds(), &render_surface_layer_list,
1243 parent->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:531244 inputs.can_adjust_raster_scales = true;
1245 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321246
1247 // Since the layer is transparent, render_surface1->render_surface() should
1248 // not have gotten added anywhere. Also, the drawable content rect should not
1249 // have been extended by the children.
1250 ASSERT_TRUE(parent->render_surface());
1251 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1252 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231253 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321254 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1255}
1256
hendrikwc266f7b2015-08-21 23:41:341257TEST_F(LayerTreeHostCommonTest,
1258 RenderSurfaceListForTransparentChildWithBackgroundFilter) {
1259 LayerImpl* parent = root_layer();
1260 LayerImpl* render_surface1 = AddChild<LayerImpl>(parent);
1261 LayerImpl* child = AddChild<LayerImpl>(render_surface1);
1262 child->SetDrawsContent(true);
1263
1264 const gfx::Transform identity_matrix;
1265 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1266 gfx::PointF(), gfx::Size(10, 10), true, false,
1267 true);
1268 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
1269 gfx::PointF(), gfx::Size(10, 10), true, false,
1270 true);
1271 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1272 gfx::PointF(), gfx::Size(10, 10), true, false,
1273 false);
1274 render_surface1->SetOpacity(0.f);
1275 FilterOperations filters;
1276 filters.Append(FilterOperation::CreateBlurFilter(1.5f));
1277 render_surface1->SetBackgroundFilters(filters);
1278
1279 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:441280 parent->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
hendrikwc266f7b2015-08-21 23:41:341281 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:441282 parent, parent->bounds(), &render_surface_layer_list,
1283 parent->layer_tree_impl()->current_render_surface_list_id());
hendrikwc266f7b2015-08-21 23:41:341284 inputs.can_adjust_raster_scales = true;
1285 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1286
1287 // The layer is fully transparent, but has a background filter, so it
1288 // shouldn't be skipped.
1289 ASSERT_TRUE(parent->render_surface());
1290 EXPECT_EQ(1U, parent->render_surface()->layer_list().size());
1291 EXPECT_EQ(2U, render_surface_layer_list.size());
jaydasika8640f9f2015-11-10 01:34:361292 EXPECT_EQ(gfx::RectF(0, 0, 10, 10),
1293 parent->render_surface()->DrawableContentRect());
hendrikwc266f7b2015-08-21 23:41:341294}
1295
rosca948d29d2014-11-09 10:25:131296TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
enned5f4ddd2015-08-18 16:50:061297 LayerImpl* parent = root_layer();
1298 LayerImpl* child = AddChild<LayerImpl>(parent);
1299 child->SetDrawsContent(true);
rosca948d29d2014-11-09 10:25:131300
1301 const gfx::Transform identity_matrix;
1302 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
enned5f4ddd2015-08-18 16:50:061303 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1304 gfx::PointF(), gfx::Size(10, 10), true, false,
1305 true);
1306 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1307 gfx::PointF(), gfx::Size(10, 10), true, false,
1308 true);
rosca948d29d2014-11-09 10:25:131309
rosca948d29d2014-11-09 10:25:131310 child->SetBlendMode(blend_mode);
weiliangc451b818f2015-07-24 17:52:291311 child->SetOpacity(0.5f);
rosca948d29d2014-11-09 10:25:131312
enned5f4ddd2015-08-18 16:50:061313 ExecuteCalculateDrawProperties(parent);
rosca948d29d2014-11-09 10:25:131314
1315 // Since the child layer has a blend mode other than normal, it should get
1316 // its own render surface. Also, layer's draw_properties should contain the
1317 // default blend mode, since the render surface becomes responsible for
1318 // applying the blend mode.
1319 ASSERT_TRUE(child->render_surface());
weiliangc451b818f2015-07-24 17:52:291320 EXPECT_EQ(1.0f, child->draw_opacity());
1321 EXPECT_EQ(0.5f, child->render_surface()->draw_opacity());
jaydasika92239dc2015-08-15 02:59:261322 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_blend_mode());
rosca948d29d2014-11-09 10:25:131323}
1324
ajuma51d73f72015-10-19 19:43:581325TEST_F(LayerTreeHostCommonTest, DrawOpacityWhenCannotRenderToSeparateSurface) {
1326 // Tests that when separate surfaces are disabled, a layer's draw opacity is
1327 // the product of all ancestor layer opacties and the layer's own opacity.
1328 // (Rendering will still be incorrect in situations where we really do need
1329 // surfaces to apply opacity, such as when we have overlapping layers with an
1330 // ancestor whose opacity is <1.)
1331 LayerImpl* root = root_layer();
1332 LayerImpl* parent = AddChild<LayerImpl>(root);
1333 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1334 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1335 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1336 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1337 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1338
1339 root->SetDrawsContent(true);
1340 parent->SetDrawsContent(true);
1341 child1->SetDrawsContent(true);
1342 child2->SetDrawsContent(true);
1343 grand_child->SetDrawsContent(true);
1344 leaf_node1->SetDrawsContent(true);
1345 leaf_node2->SetDrawsContent(true);
1346
1347 const gfx::Transform identity_matrix;
1348
1349 // child1 and grand_child get render surfaces when surfaces are enabled.
1350 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1351 gfx::PointF(), gfx::Size(100, 100), true, false,
1352 true);
1353 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1354 gfx::PointF(), gfx::Size(100, 100), true, false,
1355 false);
1356 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1357 gfx::PointF(), gfx::Size(100, 100), true, false,
1358 true);
1359 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1360 gfx::PointF(), gfx::Size(100, 100), true, false,
1361 false);
1362 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1363 gfx::PointF(), gfx::Size(100, 100), true, false,
1364 true);
1365 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1366 gfx::PointF(), gfx::Size(100, 100), true, false,
1367 false);
1368 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1369 gfx::PointF(), gfx::Size(100, 100), true, false,
1370 false);
1371
1372 child1->SetOpacity(0.5f);
1373 grand_child->SetOpacity(0.5f);
1374 leaf_node1->SetOpacity(0.5f);
1375 leaf_node2->SetOpacity(0.5f);
1376
1377 // With surfaces enabled, each layer's draw opacity is the product of layer
1378 // opacities on the path from the layer to its render target, not including
1379 // the opacity of the layer that owns the target surface (since that opacity
1380 // is applied by the surface).
1381 ExecuteCalculateDrawProperties(root);
1382 EXPECT_EQ(1.f, root->draw_opacity());
1383 EXPECT_EQ(1.f, parent->draw_opacity());
1384 EXPECT_EQ(1.f, child1->draw_opacity());
1385 EXPECT_EQ(1.f, child2->draw_opacity());
1386 EXPECT_EQ(1.f, grand_child->draw_opacity());
1387 EXPECT_EQ(0.5f, leaf_node1->draw_opacity());
1388 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1389
1390 // With surfaces disabled, each layer's draw opacity is the product of layer
1391 // opacities on the path from the layer to the root.
1392 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1393 EXPECT_EQ(1.f, root->draw_opacity());
1394 EXPECT_EQ(1.f, parent->draw_opacity());
1395 EXPECT_EQ(0.5f, child1->draw_opacity());
1396 EXPECT_EQ(1.f, child2->draw_opacity());
1397 EXPECT_EQ(0.25f, grand_child->draw_opacity());
1398 EXPECT_EQ(0.125f, leaf_node1->draw_opacity());
1399 EXPECT_EQ(0.5f, leaf_node2->draw_opacity());
1400}
1401
[email protected]989386c2013-07-18 21:37:231402TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
loysoa6edaaff2015-05-25 03:26:441403 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1404 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:321405 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:441406 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:321407 render_surface1->SetForceRenderSurface(true);
1408
ennea7b43c32015-06-18 20:01:331409 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:281410
[email protected]fb661802013-03-25 01:59:321411 const gfx::Transform identity_matrix;
1412 SetLayerPropertiesForTesting(parent.get(),
1413 identity_matrix,
[email protected]a2566412014-06-05 03:14:201414 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321415 gfx::PointF(),
1416 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571417 true,
[email protected]fb661802013-03-25 01:59:321418 false);
1419 SetLayerPropertiesForTesting(render_surface1.get(),
1420 identity_matrix,
[email protected]a2566412014-06-05 03:14:201421 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321422 gfx::PointF(),
1423 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571424 true,
[email protected]fb661802013-03-25 01:59:321425 false);
1426 SetLayerPropertiesForTesting(child.get(),
1427 identity_matrix,
[email protected]a2566412014-06-05 03:14:201428 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321429 gfx::PointF(),
1430 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571431 true,
[email protected]fb661802013-03-25 01:59:321432 false);
1433
1434 parent->AddChild(render_surface1);
1435 render_surface1->AddChild(child);
1436
1437 // Sanity check before the actual test
ennec1332992015-08-24 19:45:091438 EXPECT_FALSE(parent->has_render_surface());
1439 EXPECT_FALSE(render_surface1->has_render_surface());
[email protected]fb661802013-03-25 01:59:321440
[email protected]989386c2013-07-18 21:37:231441 {
enne1e1008c2015-08-21 00:45:461442 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(parent.get(),
1443 parent->bounds());
[email protected]7aad55f2013-07-26 11:25:531444 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321445
[email protected]989386c2013-07-18 21:37:231446 // The root layer always creates a render surface
ennec1332992015-08-24 19:45:091447 EXPECT_TRUE(parent->has_render_surface());
1448 EXPECT_TRUE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231449 }
[email protected]fb661802013-03-25 01:59:321450
[email protected]989386c2013-07-18 21:37:231451 {
[email protected]989386c2013-07-18 21:37:231452 render_surface1->SetForceRenderSurface(false);
enne1e1008c2015-08-21 00:45:461453 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(parent.get(),
1454 parent->bounds());
[email protected]7aad55f2013-07-26 11:25:531455 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
ennec1332992015-08-24 19:45:091456 EXPECT_TRUE(parent->has_render_surface());
1457 EXPECT_FALSE(render_surface1->has_render_surface());
[email protected]989386c2013-07-18 21:37:231458 }
[email protected]fb661802013-03-25 01:59:321459}
1460
ajuma246190a2015-03-11 20:56:031461TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1462 // Render surfaces act as a flattening point for their subtree, so should
1463 // always flatten the target-to-screen space transform seen by descendants.
1464
enne1a79c5542015-08-18 19:43:571465 LayerImpl* root = root_layer();
1466 LayerImpl* parent = AddChild<LayerImpl>(root);
1467 LayerImpl* child = AddChild<LayerImpl>(parent);
1468 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1469
1470 child->SetDrawsContent(true);
1471 grand_child->SetDrawsContent(true);
ajuma246190a2015-03-11 20:56:031472
1473 gfx::Transform rotation_about_y_axis;
1474 rotation_about_y_axis.RotateAboutYAxis(30.0);
1475 // Make |parent| have a render surface.
1476 parent->SetOpacity(0.9f);
1477
1478 const gfx::Transform identity_matrix;
enne1a79c5542015-08-18 19:43:571479 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1480 gfx::PointF(), gfx::Size(100, 100), true, false,
1481 true);
1482 SetLayerPropertiesForTesting(parent, rotation_about_y_axis, gfx::Point3F(),
1483 gfx::PointF(), gfx::Size(10, 10), true, false,
1484 true);
1485 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1486 gfx::PointF(), gfx::Size(10, 10), true, false,
1487 false);
1488 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1489 gfx::PointF(), gfx::Size(10, 10), true, false,
1490 false);
ajuma246190a2015-03-11 20:56:031491
1492 grand_child->SetShouldFlattenTransform(false);
1493
ajuma246190a2015-03-11 20:56:031494 // Only grand_child should preserve 3d.
1495 EXPECT_TRUE(root->should_flatten_transform());
1496 EXPECT_TRUE(parent->should_flatten_transform());
1497 EXPECT_TRUE(child->should_flatten_transform());
1498 EXPECT_FALSE(grand_child->should_flatten_transform());
1499
1500 gfx::Transform expected_child_draw_transform = identity_matrix;
1501 gfx::Transform expected_grand_child_draw_transform = identity_matrix;
1502
1503 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1504 flattened_rotation_about_y.FlattenTo2d();
1505
enne1a79c5542015-08-18 19:43:571506 ExecuteCalculateDrawProperties(root);
ajuma246190a2015-03-11 20:56:031507
1508 EXPECT_TRUE(parent->render_surface());
1509 EXPECT_FALSE(child->render_surface());
1510 EXPECT_FALSE(grand_child->render_surface());
1511
ajumad9432e32015-11-30 19:43:441512 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->DrawTransform());
ajuma246190a2015-03-11 20:56:031513 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
ajumad9432e32015-11-30 19:43:441514 grand_child->DrawTransform());
ajuma246190a2015-03-11 20:56:031515
1516 // The screen-space transform inherited by |child| and |grand_child| should
1517 // have been flattened at their render target. In particular, the fact that
1518 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1519 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1520 child->screen_space_transform());
1521 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1522 grand_child->screen_space_transform());
1523}
1524
[email protected]989386c2013-07-18 21:37:231525TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321526 // The entire subtree of layers that are outside the clip rect should be
1527 // culled away, and should not affect the render_surface_layer_list.
1528 //
1529 // The test tree is set up as follows:
1530 // - all layers except the leaf_nodes are forced to be a new render surface
1531 // that have something to draw.
1532 // - parent is a large container layer.
1533 // - child has masksToBounds=true to cause clipping.
1534 // - grand_child is positioned outside of the child's bounds
1535 // - great_grand_child is also kept outside child's bounds.
1536 //
1537 // In this configuration, grand_child and great_grand_child are completely
1538 // outside the clip rect, and they should never get scheduled on the list of
1539 // render surfaces.
[email protected]fb661802013-03-25 01:59:321540
weiliangcfb3d5eaa2015-07-28 23:54:571541 LayerImpl* parent = root_layer();
1542 LayerImpl* child = AddChildToRoot<LayerImpl>();
1543 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1544 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
[email protected]d600df7d2013-08-03 02:34:281545
[email protected]fb661802013-03-25 01:59:321546 // leaf_node1 ensures that parent and child are kept on the
1547 // render_surface_layer_list, even though grand_child and great_grand_child
1548 // should be clipped.
weiliangcfb3d5eaa2015-07-28 23:54:571549 LayerImpl* leaf_node1 = AddChild<LayerImpl>(child);
1550 leaf_node1->SetDrawsContent(true);
1551 LayerImpl* leaf_node2 = AddChild<LayerImpl>(great_grand_child);
1552 leaf_node2->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321553
weiliangcfb3d5eaa2015-07-28 23:54:571554 const gfx::Transform identity_matrix;
1555
1556 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1557 gfx::PointF(), gfx::Size(500, 500), true, false,
1558 true);
1559 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1560 gfx::PointF(), gfx::Size(20, 20), true, false,
1561 true);
1562 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1563 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1564 false, false);
1565 SetLayerPropertiesForTesting(great_grand_child, identity_matrix,
1566 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1567 true, false, false);
1568 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1569 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:321570 false);
weiliangcfb3d5eaa2015-07-28 23:54:571571 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1572 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]fb661802013-03-25 01:59:321573 false);
1574
1575 child->SetMasksToBounds(true);
1576 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321577 grand_child->SetOpacity(0.5f);
1578 great_grand_child->SetOpacity(0.4f);
1579
weiliangcfb3d5eaa2015-07-28 23:54:571580 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321581
weiliangcfb3d5eaa2015-07-28 23:54:571582 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
1583 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id());
1584 EXPECT_EQ(child->id(), render_surface_layer_list_impl()->at(1)->id());
[email protected]fb661802013-03-25 01:59:321585}
1586
[email protected]989386c2013-07-18 21:37:231587TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321588 // When a render surface has a clip rect, it is used to clip the content rect
weiliangcfb3d5eaa2015-07-28 23:54:571589 // of the surface.
[email protected]fb661802013-03-25 01:59:321590
1591 // The test tree is set up as follows:
1592 // - parent is a container layer that masksToBounds=true to cause clipping.
1593 // - child is a render surface, which has a clip rect set to the bounds of
1594 // the parent.
1595 // - grand_child is a render surface, and the only visible content in child.
1596 // It is positioned outside of the clip rect from parent.
1597
1598 // In this configuration, grand_child should be outside the clipped
1599 // content rect of the child, making grand_child not appear in the
weiliangcfb3d5eaa2015-07-28 23:54:571600 // render_surface_layer_list.
1601
1602 LayerImpl* parent = root_layer();
1603 LayerImpl* child = AddChildToRoot<LayerImpl>();
1604 LayerImpl* grand_child = AddChild<LayerImpl>(child);
1605 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
1606 leaf_node->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321607
1608 const gfx::Transform identity_matrix;
[email protected]fb661802013-03-25 01:59:321609
weiliangcfb3d5eaa2015-07-28 23:54:571610 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1611 gfx::PointF(), gfx::Size(100, 100), true, false,
1612 true);
1613 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1614 gfx::PointF(), gfx::Size(20, 20), true, false,
1615 true);
1616 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1617 gfx::PointF(200.f, 200.f), gfx::Size(10, 10),
1618 true, false, true);
1619 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
1620 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:321621 false);
1622
1623 parent->SetMasksToBounds(true);
1624 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321625 grand_child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321626
weiliangcfb3d5eaa2015-07-28 23:54:571627 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321628
weiliangcfb3d5eaa2015-07-28 23:54:571629 // We should cull child and grand_child from the
1630 // render_surface_layer_list.
1631 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
1632 EXPECT_EQ(parent->id(), render_surface_layer_list_impl()->at(0)->id());
[email protected]fb661802013-03-25 01:59:321633}
1634
ajumae2b7a5c2015-09-30 21:41:421635TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectlyLayerImpl) {
1636 // Tests that LayerImpl's IsClipped() property is set to true when:
[email protected]fb661802013-03-25 01:59:321637 // - the layer clips its subtree, e.g. masks to bounds,
1638 // - the layer is clipped by an ancestor that contributes to the same
1639 // render target,
1640 // - a surface is clipped by an ancestor that contributes to the same
1641 // render target.
1642 //
1643 // In particular, for a layer that owns a render surface:
1644 // - the render surface inherits any clip from ancestors, and does NOT
1645 // pass that clipped status to the layer itself.
1646 // - but if the layer itself masks to bounds, it is considered clipped
1647 // and propagates the clip to the subtree.
1648
1649 const gfx::Transform identity_matrix;
enne76bf8982015-08-18 17:55:331650 LayerImpl* root = root_layer();
1651 LayerImpl* parent = AddChild<LayerImpl>(root);
jaydasika8640f9f2015-11-10 01:34:361652 parent->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331653 LayerImpl* child1 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:361654 child1->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331655 LayerImpl* child2 = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:361656 child2->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331657 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
jaydasika8640f9f2015-11-10 01:34:361658 grand_child->SetDrawsContent(true);
enne76bf8982015-08-18 17:55:331659 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1660 leaf_node1->SetDrawsContent(true);
1661 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1662 leaf_node2->SetDrawsContent(true);
1663
1664 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1665 gfx::PointF(), gfx::Size(100, 100), true, false,
1666 true);
1667 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1668 gfx::PointF(), gfx::Size(100, 100), true, false,
1669 false);
1670 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1671 gfx::PointF(), gfx::Size(100, 100), true, false,
1672 false);
1673 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1674 gfx::PointF(), gfx::Size(100, 100), true, false,
1675 true);
1676 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1677 gfx::PointF(), gfx::Size(100, 100), true, false,
1678 false);
1679 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1680 gfx::PointF(), gfx::Size(100, 100), true, false,
1681 false);
1682 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1683 gfx::PointF(), gfx::Size(100, 100), true, false,
1684 false);
1685
1686 // Case 1: nothing is clipped except the root render surface.
1687 {
1688 ExecuteCalculateDrawProperties(root);
1689
1690 ASSERT_TRUE(root->render_surface());
1691 ASSERT_TRUE(child2->render_surface());
1692
1693 EXPECT_FALSE(root->is_clipped());
1694 EXPECT_TRUE(root->render_surface()->is_clipped());
1695 EXPECT_FALSE(parent->is_clipped());
1696 EXPECT_FALSE(child1->is_clipped());
1697 EXPECT_FALSE(child2->is_clipped());
1698 EXPECT_FALSE(child2->render_surface()->is_clipped());
1699 EXPECT_FALSE(grand_child->is_clipped());
1700 EXPECT_FALSE(leaf_node1->is_clipped());
1701 EXPECT_FALSE(leaf_node2->is_clipped());
1702 }
1703
1704 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1705 // surface are clipped. But layers that contribute to child2's surface are
1706 // not clipped explicitly because child2's surface already accounts for
1707 // that clip.
1708 {
1709 parent->SetMasksToBounds(true);
enne76bf8982015-08-18 17:55:331710 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1711
1712 ExecuteCalculateDrawProperties(root);
1713
1714 ASSERT_TRUE(root->render_surface());
1715 ASSERT_TRUE(child2->render_surface());
1716
ajumae2b7a5c2015-09-30 21:41:421717 EXPECT_FALSE(root->is_clipped());
enne76bf8982015-08-18 17:55:331718 EXPECT_TRUE(root->render_surface()->is_clipped());
ajumae2b7a5c2015-09-30 21:41:421719 EXPECT_TRUE(parent->is_clipped());
1720 EXPECT_TRUE(child1->is_clipped());
1721 EXPECT_FALSE(child2->is_clipped());
enne76bf8982015-08-18 17:55:331722 EXPECT_TRUE(child2->render_surface()->is_clipped());
ajumae2b7a5c2015-09-30 21:41:421723 EXPECT_TRUE(grand_child->is_clipped());
1724 EXPECT_TRUE(leaf_node1->is_clipped());
1725 EXPECT_FALSE(leaf_node2->is_clipped());
enne76bf8982015-08-18 17:55:331726
1727 parent->SetMasksToBounds(false);
enne76bf8982015-08-18 17:55:331728 }
1729
1730 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1731 // child2's render surface is not clipped.
1732 {
1733 child2->SetMasksToBounds(true);
enne76bf8982015-08-18 17:55:331734 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1735
1736 ExecuteCalculateDrawProperties(root);
1737
1738 ASSERT_TRUE(root->render_surface());
1739 ASSERT_TRUE(child2->render_surface());
1740
1741 EXPECT_FALSE(root->is_clipped());
[email protected]989386c2013-07-18 21:37:231742 EXPECT_TRUE(root->render_surface()->is_clipped());
1743 EXPECT_FALSE(parent->is_clipped());
1744 EXPECT_FALSE(child1->is_clipped());
1745 EXPECT_TRUE(child2->is_clipped());
1746 EXPECT_FALSE(child2->render_surface()->is_clipped());
1747 EXPECT_FALSE(grand_child->is_clipped());
1748 EXPECT_FALSE(leaf_node1->is_clipped());
1749 EXPECT_TRUE(leaf_node2->is_clipped());
1750 }
[email protected]fb661802013-03-25 01:59:321751}
1752
ajuma51d73f72015-10-19 19:43:581753TEST_F(LayerTreeHostCommonTest, IsClippedWhenCannotRenderToSeparateSurface) {
1754 // Tests that when separate surfaces are disabled, is_clipped is true exactly
1755 // when a layer or its ancestor has a clip; in particular, if a layer
1756 // is_clipped, so is its entire subtree (since there are no render surfaces
1757 // that can reset is_clipped).
1758 LayerImpl* root = root_layer();
1759 LayerImpl* parent = AddChild<LayerImpl>(root);
1760 LayerImpl* child1 = AddChild<LayerImpl>(parent);
1761 LayerImpl* child2 = AddChild<LayerImpl>(parent);
1762 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
1763 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
1764 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
1765
1766 root->SetDrawsContent(true);
1767 parent->SetDrawsContent(true);
1768 child1->SetDrawsContent(true);
1769 child2->SetDrawsContent(true);
1770 grand_child->SetDrawsContent(true);
1771 leaf_node1->SetDrawsContent(true);
1772 leaf_node2->SetDrawsContent(true);
1773
1774 const gfx::Transform identity_matrix;
1775
1776 // child1 and grand_child get render surfaces when surfaces are enabled.
1777 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
1778 gfx::PointF(), gfx::Size(100, 100), true, false,
1779 true);
1780 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1781 gfx::PointF(), gfx::Size(100, 100), true, false,
1782 false);
1783 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
1784 gfx::PointF(), gfx::Size(100, 100), true, false,
1785 true);
1786 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
1787 gfx::PointF(), gfx::Size(100, 100), true, false,
1788 false);
1789 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
1790 gfx::PointF(), gfx::Size(100, 100), true, false,
1791 true);
1792 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
1793 gfx::PointF(), gfx::Size(100, 100), true, false,
1794 false);
1795 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
1796 gfx::PointF(), gfx::Size(100, 100), true, false,
1797 false);
1798
1799 // Case 1: Nothing is clipped. In this case, is_clipped is always false, with
1800 // or without surfaces.
1801 ExecuteCalculateDrawProperties(root);
1802 EXPECT_FALSE(root->is_clipped());
1803 EXPECT_FALSE(parent->is_clipped());
1804 EXPECT_FALSE(child1->is_clipped());
1805 EXPECT_FALSE(child2->is_clipped());
1806 EXPECT_FALSE(grand_child->is_clipped());
1807 EXPECT_FALSE(leaf_node1->is_clipped());
1808 EXPECT_FALSE(leaf_node2->is_clipped());
1809
1810 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1811 EXPECT_FALSE(root->is_clipped());
1812 EXPECT_FALSE(parent->is_clipped());
1813 EXPECT_FALSE(child1->is_clipped());
1814 EXPECT_FALSE(child2->is_clipped());
1815 EXPECT_FALSE(grand_child->is_clipped());
1816 EXPECT_FALSE(leaf_node1->is_clipped());
1817 EXPECT_FALSE(leaf_node2->is_clipped());
1818
1819 // Case 2: The root is clipped. With surfaces, this only persists until the
1820 // next render surface. Without surfaces, the entire tree is clipped.
1821 root->SetMasksToBounds(true);
1822 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1823 ExecuteCalculateDrawProperties(root);
1824 EXPECT_TRUE(root->is_clipped());
1825 EXPECT_TRUE(parent->is_clipped());
1826 EXPECT_FALSE(child1->is_clipped());
1827 EXPECT_TRUE(child2->is_clipped());
1828 EXPECT_FALSE(grand_child->is_clipped());
1829 EXPECT_FALSE(leaf_node1->is_clipped());
1830 EXPECT_TRUE(leaf_node2->is_clipped());
1831
1832 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1833 EXPECT_TRUE(root->is_clipped());
1834 EXPECT_TRUE(parent->is_clipped());
1835 EXPECT_TRUE(child1->is_clipped());
1836 EXPECT_TRUE(child2->is_clipped());
1837 EXPECT_TRUE(grand_child->is_clipped());
1838 EXPECT_TRUE(leaf_node1->is_clipped());
1839 EXPECT_TRUE(leaf_node2->is_clipped());
1840
1841 root->SetMasksToBounds(false);
1842
1843 // Case 3: The parent is clipped. Again, with surfaces, this only persists
1844 // until the next render surface. Without surfaces, parent's entire subtree is
1845 // clipped.
1846 parent->SetMasksToBounds(true);
1847 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1848 ExecuteCalculateDrawProperties(root);
1849 EXPECT_FALSE(root->is_clipped());
1850 EXPECT_TRUE(parent->is_clipped());
1851 EXPECT_FALSE(child1->is_clipped());
1852 EXPECT_TRUE(child2->is_clipped());
1853 EXPECT_FALSE(grand_child->is_clipped());
1854 EXPECT_FALSE(leaf_node1->is_clipped());
1855 EXPECT_TRUE(leaf_node2->is_clipped());
1856
1857 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1858 EXPECT_FALSE(root->is_clipped());
1859 EXPECT_TRUE(parent->is_clipped());
1860 EXPECT_TRUE(child1->is_clipped());
1861 EXPECT_TRUE(child2->is_clipped());
1862 EXPECT_TRUE(grand_child->is_clipped());
1863 EXPECT_TRUE(leaf_node1->is_clipped());
1864 EXPECT_TRUE(leaf_node2->is_clipped());
1865
1866 parent->SetMasksToBounds(false);
1867
1868 // Case 4: child1 is clipped. With surfaces, only child1 is_clipped, since it
1869 // has no non-surface children. Without surfaces, child1's entire subtree is
1870 // clipped.
1871 child1->SetMasksToBounds(true);
1872 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1873 ExecuteCalculateDrawProperties(root);
1874 EXPECT_FALSE(root->is_clipped());
1875 EXPECT_FALSE(parent->is_clipped());
1876 EXPECT_TRUE(child1->is_clipped());
1877 EXPECT_FALSE(child2->is_clipped());
1878 EXPECT_FALSE(grand_child->is_clipped());
1879 EXPECT_FALSE(leaf_node1->is_clipped());
1880 EXPECT_FALSE(leaf_node2->is_clipped());
1881
1882 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1883 EXPECT_FALSE(root->is_clipped());
1884 EXPECT_FALSE(parent->is_clipped());
1885 EXPECT_TRUE(child1->is_clipped());
1886 EXPECT_FALSE(child2->is_clipped());
1887 EXPECT_TRUE(grand_child->is_clipped());
1888 EXPECT_TRUE(leaf_node1->is_clipped());
1889 EXPECT_FALSE(leaf_node2->is_clipped());
1890
1891 child1->SetMasksToBounds(false);
1892
1893 // Case 5: Only the leaf nodes are clipped. The behavior with and without
1894 // surfaces is the same.
1895 leaf_node1->SetMasksToBounds(true);
1896 leaf_node2->SetMasksToBounds(true);
1897 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
1898 ExecuteCalculateDrawProperties(root);
1899 EXPECT_FALSE(root->is_clipped());
1900 EXPECT_FALSE(parent->is_clipped());
1901 EXPECT_FALSE(child1->is_clipped());
1902 EXPECT_FALSE(child2->is_clipped());
1903 EXPECT_FALSE(grand_child->is_clipped());
1904 EXPECT_TRUE(leaf_node1->is_clipped());
1905 EXPECT_TRUE(leaf_node2->is_clipped());
1906
1907 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
1908 EXPECT_FALSE(root->is_clipped());
1909 EXPECT_FALSE(parent->is_clipped());
1910 EXPECT_FALSE(child1->is_clipped());
1911 EXPECT_FALSE(child2->is_clipped());
1912 EXPECT_FALSE(grand_child->is_clipped());
1913 EXPECT_TRUE(leaf_node1->is_clipped());
1914 EXPECT_TRUE(leaf_node2->is_clipped());
1915}
1916
[email protected]fd9a3b6d2013-08-03 00:46:171917TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:321918 // Verify that layers get the appropriate DrawableContentRect when their
1919 // parent masksToBounds is true.
1920 //
1921 // grand_child1 - completely inside the region; DrawableContentRect should
1922 // be the layer rect expressed in target space.
1923 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1924 // will be the intersection of layer bounds and the mask region.
1925 // grand_child3 - partially clipped and masksToBounds; the
1926 // DrawableContentRect will still be the intersection of layer bounds and
1927 // the mask region.
1928 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1929 // be empty.
[email protected]fb661802013-03-25 01:59:321930
1931 const gfx::Transform identity_matrix;
enne07405c772015-08-18 17:56:451932 LayerImpl* parent = root_layer();
1933 LayerImpl* child = AddChild<LayerImpl>(parent);
1934 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:361935 grand_child1->SetDrawsContent(true);
enne07405c772015-08-18 17:56:451936 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:361937 grand_child2->SetDrawsContent(true);
enne07405c772015-08-18 17:56:451938 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:361939 grand_child3->SetDrawsContent(true);
enne07405c772015-08-18 17:56:451940 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
jaydasika8640f9f2015-11-10 01:34:361941 grand_child4->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:321942
enne07405c772015-08-18 17:56:451943 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
1944 gfx::PointF(), gfx::Size(500, 500), true, false,
1945 true);
1946 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
1947 gfx::PointF(), gfx::Size(20, 20), true, false,
1948 true);
1949 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
1950 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
1951 false, false);
1952 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
1953 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
1954 false, false);
1955 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
1956 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
1957 false, false);
1958 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
1959 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
1960 false, false);
[email protected]fb661802013-03-25 01:59:321961
1962 child->SetMasksToBounds(true);
1963 grand_child3->SetMasksToBounds(true);
1964
enne07405c772015-08-18 17:56:451965 // Force child to be a render surface.
[email protected]fb661802013-03-25 01:59:321966 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:321967
enne07405c772015-08-18 17:56:451968 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:321969
hush6b614212014-12-04 22:37:321970 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
1971 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
1972 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:321973 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
1974}
1975
[email protected]989386c2013-07-18 21:37:231976TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:321977 // Verify that render surfaces (and their layers) get the appropriate
1978 // clip rects when their parent masksToBounds is true.
1979 //
1980 // Layers that own render surfaces (at least for now) do not inherit any
1981 // clipping; instead the surface will enforce the clip for the entire subtree.
1982 // They may still have a clip rect of their own layer bounds, however, if
1983 // masksToBounds was true.
weiliangcfb3d5eaa2015-07-28 23:54:571984 LayerImpl* parent = root_layer();
1985 LayerImpl* child = AddChildToRoot<LayerImpl>();
1986 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
1987 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
1988 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
1989 LayerImpl* grand_child4 = AddChild<LayerImpl>(child);
[email protected]fb661802013-03-25 01:59:321990 // the leaf nodes ensure that these grand_children become render surfaces for
1991 // this test.
weiliangcfb3d5eaa2015-07-28 23:54:571992 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
1993 leaf_node1->SetDrawsContent(true);
1994 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
1995 leaf_node2->SetDrawsContent(true);
1996 LayerImpl* leaf_node3 = AddChild<LayerImpl>(grand_child3);
1997 leaf_node3->SetDrawsContent(true);
1998 LayerImpl* leaf_node4 = AddChild<LayerImpl>(grand_child4);
1999 leaf_node4->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322000
weiliangcfb3d5eaa2015-07-28 23:54:572001 const gfx::Transform identity_matrix;
2002
2003 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2004 gfx::PointF(), gfx::Size(500, 500), true, false,
2005 true);
2006 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2007 gfx::PointF(), gfx::Size(20, 20), true, false,
2008 true);
2009 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2010 gfx::PointF(5.f, 5.f), gfx::Size(10, 10), true,
2011 false, true);
2012 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2013 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2014 false, true);
2015 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2016 gfx::PointF(15.f, 15.f), gfx::Size(10, 10), true,
2017 false, true);
2018 SetLayerPropertiesForTesting(grand_child4, identity_matrix, gfx::Point3F(),
2019 gfx::PointF(45.f, 45.f), gfx::Size(10, 10), true,
2020 false, true);
2021 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2022 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322023 false);
weiliangcfb3d5eaa2015-07-28 23:54:572024 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2025 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322026 false);
weiliangcfb3d5eaa2015-07-28 23:54:572027 SetLayerPropertiesForTesting(leaf_node3, identity_matrix, gfx::Point3F(),
2028 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322029 false);
weiliangcfb3d5eaa2015-07-28 23:54:572030 SetLayerPropertiesForTesting(leaf_node4, identity_matrix, gfx::Point3F(),
2031 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]fb661802013-03-25 01:59:322032 false);
2033
2034 child->SetMasksToBounds(true);
2035 grand_child3->SetMasksToBounds(true);
2036 grand_child4->SetMasksToBounds(true);
2037
2038 // Force everyone to be a render surface.
2039 child->SetOpacity(0.4f);
[email protected]fb661802013-03-25 01:59:322040 grand_child1->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322041 grand_child2->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322042 grand_child3->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322043 grand_child4->SetOpacity(0.5f);
[email protected]fb661802013-03-25 01:59:322044
weiliangcfb3d5eaa2015-07-28 23:54:572045 ExecuteCalculateDrawProperties(parent);
2046
[email protected]fb661802013-03-25 01:59:322047 ASSERT_TRUE(grand_child1->render_surface());
2048 ASSERT_TRUE(grand_child2->render_surface());
2049 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322050
2051 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2052 // masksToBounds.
hush6b614212014-12-04 22:37:322053 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2054 grand_child1->render_surface()->clip_rect());
2055 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2056 grand_child2->render_surface()->clip_rect());
2057 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2058 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322059}
2060
ajuma51d73f72015-10-19 19:43:582061TEST_F(LayerTreeHostCommonTest, ClipRectWhenCannotRenderToSeparateSurface) {
2062 // Tests that when separate surfaces are disabled, a layer's clip_rect is the
2063 // intersection of all ancestor clips in screen space; in particular, if a
2064 // layer masks to bounds, it contributes to the clip_rect of all layers in its
2065 // subtree (since there are no render surfaces that can reset the clip_rect).
2066 LayerImpl* root = root_layer();
2067 LayerImpl* parent = AddChild<LayerImpl>(root);
2068 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2069 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2070 LayerImpl* grand_child = AddChild<LayerImpl>(child1);
2071 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child);
2072 LayerImpl* leaf_node2 = AddChild<LayerImpl>(child2);
2073
2074 root->SetDrawsContent(true);
2075 parent->SetDrawsContent(true);
2076 child1->SetDrawsContent(true);
2077 child2->SetDrawsContent(true);
2078 grand_child->SetDrawsContent(true);
2079 leaf_node1->SetDrawsContent(true);
2080 leaf_node2->SetDrawsContent(true);
2081
2082 const gfx::Transform identity_matrix;
2083
2084 // child1 and grand_child get render surfaces when surfaces are enabled.
2085 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2086 gfx::PointF(), gfx::Size(100, 100), true, false,
2087 true);
2088 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2089 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2090 false, false);
2091 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2092 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2093 false, true);
2094 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2095 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
2096 false, false);
2097 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2098 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2099 true, false, true);
2100 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2101 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2102 true, false, false);
2103 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2104 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
2105 true, false, false);
2106
2107 // Case 1: Nothing is clipped. In this case, each layer's clip rect is its
2108 // bounds in target space. The only thing that changes when surfaces are
2109 // disabled is that target space is always screen space.
2110 ExecuteCalculateDrawProperties(root);
2111 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2112 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2113 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2114 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->clip_rect());
2115 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child->clip_rect());
2116 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node1->clip_rect());
2117 EXPECT_EQ(gfx::Rect(14, 14, 2000, 2000), leaf_node2->clip_rect());
2118
2119 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2120 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2121 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2122 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->clip_rect());
2123 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->clip_rect());
2124 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500), grand_child->clip_rect());
2125 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->clip_rect());
2126 EXPECT_EQ(gfx::Rect(14, 14, 2000, 2000), leaf_node2->clip_rect());
2127
2128 // Case 2: The root is clipped. In this case, layers that draw into the root
2129 // render surface are clipped by the root's bounds.
2130 root->SetMasksToBounds(true);
2131 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2132 ExecuteCalculateDrawProperties(root);
2133 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2134 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2135 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2136 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2137 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child->clip_rect());
2138 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node1->clip_rect());
2139 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2140
2141 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2142 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2143 EXPECT_EQ(gfx::Rect(100, 100), parent->clip_rect());
2144 EXPECT_EQ(gfx::Rect(100, 100), child1->clip_rect());
2145 EXPECT_EQ(gfx::Rect(100, 100), child2->clip_rect());
2146 EXPECT_EQ(gfx::Rect(100, 100), grand_child->clip_rect());
2147 EXPECT_EQ(gfx::Rect(100, 100), leaf_node1->clip_rect());
2148 EXPECT_EQ(gfx::Rect(100, 100), leaf_node2->clip_rect());
2149
2150 root->SetMasksToBounds(false);
2151
2152 // Case 3: The parent and child1 are clipped. When surfaces are enabled, the
2153 // parent clip rect only contributes to the subtree rooted at child2, since
2154 // the subtree rooted at child1 renders into a separate surface. Similarly,
2155 // child1's clip rect doesn't contribute to its descendants, since its only
2156 // child is a render surface. However, without surfaces, these clip rects
2157 // contribute to all descendants.
2158 parent->SetMasksToBounds(true);
2159 child1->SetMasksToBounds(true);
2160 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
2161 ExecuteCalculateDrawProperties(root);
2162 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2163 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2164 EXPECT_EQ(gfx::Rect(800, 800), child1->clip_rect());
2165 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2166 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child->clip_rect());
2167 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node1->clip_rect());
2168 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2169
2170 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2171 EXPECT_EQ(gfx::Rect(100, 100), root->clip_rect());
2172 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->clip_rect());
2173 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->clip_rect());
2174 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), child2->clip_rect());
2175 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), grand_child->clip_rect());
2176 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node1->clip_rect());
2177 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), leaf_node2->clip_rect());
2178}
2179
2180TEST_F(LayerTreeHostCommonTest, SurfacesDisabledAndReEnabled) {
2181 // Tests that draw properties are computed correctly when we disable and then
2182 // re-enable separate surfaces.
2183 LayerImpl* root = root_layer();
2184 LayerImpl* parent = AddChild<LayerImpl>(root);
2185 LayerImpl* child = AddChild<LayerImpl>(parent);
2186 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2187 LayerImpl* leaf_node = AddChild<LayerImpl>(grand_child);
2188
2189 root->SetDrawsContent(true);
2190 parent->SetDrawsContent(true);
2191 child->SetDrawsContent(true);
2192 grand_child->SetDrawsContent(true);
2193 leaf_node->SetDrawsContent(true);
2194
2195 const gfx::Transform identity_matrix;
2196
2197 // child and grand_child get render surfaces when surfaces are enabled.
2198 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2199 gfx::PointF(), gfx::Size(100, 100), true, false,
2200 true);
2201 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2202 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2203 false, false);
2204 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2205 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2206 false, true);
2207 SetLayerPropertiesForTesting(grand_child, identity_matrix, gfx::Point3F(),
2208 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2209 true, false, true);
2210 SetLayerPropertiesForTesting(leaf_node, identity_matrix, gfx::Point3F(),
2211 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2212 true, false, false);
2213
2214 parent->SetMasksToBounds(true);
2215 child->SetMasksToBounds(true);
2216
2217 gfx::Transform expected_leaf_draw_transform_with_surfaces;
2218 expected_leaf_draw_transform_with_surfaces.Translate(16.0, 16.0);
2219
2220 gfx::Transform expected_leaf_draw_transform_without_surfaces;
2221 expected_leaf_draw_transform_without_surfaces.Translate(30.0, 30.0);
2222
2223 ExecuteCalculateDrawProperties(root);
2224 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->clip_rect());
2225 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2226 EXPECT_EQ(expected_leaf_draw_transform_with_surfaces,
ajumad9432e32015-11-30 19:43:442227 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582228
2229 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
2230 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), leaf_node->clip_rect());
2231 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node->drawable_content_rect());
2232 EXPECT_EQ(expected_leaf_draw_transform_without_surfaces,
ajumad9432e32015-11-30 19:43:442233 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582234
2235 ExecuteCalculateDrawProperties(root);
2236 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->clip_rect());
2237 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node->drawable_content_rect());
2238 EXPECT_EQ(expected_leaf_draw_transform_with_surfaces,
ajumad9432e32015-11-30 19:43:442239 leaf_node->DrawTransform());
ajuma51d73f72015-10-19 19:43:582240}
2241
[email protected]989386c2013-07-18 21:37:232242TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
enneab0fee42015-07-07 17:36:422243 LayerImpl* parent = root_layer();
2244 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
2245 LayerImpl* child_of_rs1 = AddChild<LayerImpl>(render_surface1);
2246 LayerImpl* grand_child_of_rs1 = AddChild<LayerImpl>(child_of_rs1);
2247 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
2248 LayerImpl* child_of_rs2 = AddChild<LayerImpl>(render_surface2);
2249 LayerImpl* grand_child_of_rs2 = AddChild<LayerImpl>(child_of_rs2);
2250 LayerImpl* child_of_root = AddChildToRoot<LayerImpl>();
2251 LayerImpl* grand_child_of_root = AddChild<LayerImpl>(child_of_root);
[email protected]fb661802013-03-25 01:59:322252
jaydasika8640f9f2015-11-10 01:34:362253 parent->SetDrawsContent(true);
2254 render_surface1->SetDrawsContent(true);
2255 child_of_rs1->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422256 grand_child_of_rs1->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362257 render_surface2->SetDrawsContent(true);
2258 child_of_rs2->SetDrawsContent(true);
enneab0fee42015-07-07 17:36:422259 grand_child_of_rs2->SetDrawsContent(true);
jaydasika8640f9f2015-11-10 01:34:362260 child_of_root->SetDrawsContent(true);
2261 grand_child_of_root->SetDrawsContent(true);
[email protected]fb661802013-03-25 01:59:322262
2263 gfx::Transform layer_transform;
2264 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322265
enneab0fee42015-07-07 17:36:422266 SetLayerPropertiesForTesting(
2267 parent, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2268 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2269 SetLayerPropertiesForTesting(
2270 render_surface1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2271 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2272 SetLayerPropertiesForTesting(
2273 render_surface2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2274 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, true);
2275 SetLayerPropertiesForTesting(
2276 child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2277 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2278 SetLayerPropertiesForTesting(
2279 child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2280 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2281 SetLayerPropertiesForTesting(
2282 child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2283 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2284 SetLayerPropertiesForTesting(
2285 grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2286 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2287 SetLayerPropertiesForTesting(
2288 grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2289 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
2290 SetLayerPropertiesForTesting(
2291 grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f),
2292 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false);
[email protected]fb661802013-03-25 01:59:322293
2294 // Put an animated opacity on the render surface.
2295 AddOpacityTransitionToController(
2296 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2297
2298 // Also put an animated opacity on a layer without descendants.
2299 AddOpacityTransitionToController(
2300 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2301
2302 // Put a transform animation on the render surface.
2303 AddAnimatedTransformToController(
2304 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2305
2306 // Also put transform animations on grand_child_of_root, and
2307 // grand_child_of_rs2
2308 AddAnimatedTransformToController(
2309 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2310 AddAnimatedTransformToController(
2311 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2312
enneab0fee42015-07-07 17:36:422313 ExecuteCalculateDrawProperties(parent);
[email protected]fb661802013-03-25 01:59:322314
2315 // Only layers that are associated with render surfaces should have an actual
2316 // RenderSurface() value.
2317 ASSERT_TRUE(parent->render_surface());
2318 ASSERT_FALSE(child_of_root->render_surface());
2319 ASSERT_FALSE(grand_child_of_root->render_surface());
2320
2321 ASSERT_TRUE(render_surface1->render_surface());
2322 ASSERT_FALSE(child_of_rs1->render_surface());
2323 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2324
2325 ASSERT_TRUE(render_surface2->render_surface());
2326 ASSERT_FALSE(child_of_rs2->render_surface());
2327 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2328
2329 // Verify all render target accessors
enneab0fee42015-07-07 17:36:422330 EXPECT_EQ(parent, parent->render_target());
2331 EXPECT_EQ(parent, child_of_root->render_target());
2332 EXPECT_EQ(parent, grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322333
enneab0fee42015-07-07 17:36:422334 EXPECT_EQ(render_surface1, render_surface1->render_target());
2335 EXPECT_EQ(render_surface1, child_of_rs1->render_target());
2336 EXPECT_EQ(render_surface1, grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322337
enneab0fee42015-07-07 17:36:422338 EXPECT_EQ(render_surface2, render_surface2->render_target());
2339 EXPECT_EQ(render_surface2, child_of_rs2->render_target());
2340 EXPECT_EQ(render_surface2, grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322341
[email protected]fb661802013-03-25 01:59:322342 // Verify screen_space_transform_is_animating values
2343 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2344 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2345 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2346 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322347 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2348 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2349 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
[email protected]fb661802013-03-25 01:59:322350 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2351 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2352
2353 // Sanity check. If these fail there is probably a bug in the test itself.
2354 // It is expected that we correctly set up transforms so that the y-component
2355 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262356 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2357 EXPECT_FLOAT_EQ(2.0,
2358 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322359 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262360 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322361
[email protected]803f6b52013-09-12 00:51:262362 EXPECT_FLOAT_EQ(2.0,
2363 render_surface1->screen_space_transform().matrix().get(1, 3));
2364 EXPECT_FLOAT_EQ(3.0,
2365 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322366 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262367 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322368
[email protected]803f6b52013-09-12 00:51:262369 EXPECT_FLOAT_EQ(3.0,
2370 render_surface2->screen_space_transform().matrix().get(1, 3));
2371 EXPECT_FLOAT_EQ(4.0,
2372 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322373 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262374 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322375}
2376
ajuma9384b9c22015-09-17 20:35:032377TEST_F(LayerTreeHostCommonTest, LargeTransforms) {
2378 LayerImpl* parent = root_layer();
2379 LayerImpl* child = AddChildToRoot<LayerImpl>();
2380 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2381
2382 grand_child->SetDrawsContent(true);
2383
2384 gfx::Transform large_transform;
2385 large_transform.Scale(SkDoubleToMScalar(1e37), SkDoubleToMScalar(1e37));
2386
2387 gfx::Transform identity;
2388
2389 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(),
2390 gfx::Size(10, 10), true, false, true);
2391 SetLayerPropertiesForTesting(child, large_transform, gfx::Point3F(),
2392 gfx::PointF(), gfx::Size(10, 10), true, false,
2393 false);
2394 SetLayerPropertiesForTesting(grand_child, large_transform, gfx::Point3F(),
2395 gfx::PointF(), gfx::Size(10, 10), true, false,
2396 false);
2397 ExecuteCalculateDrawProperties(parent);
2398
2399 EXPECT_EQ(gfx::Rect(), grand_child->visible_layer_rect());
2400}
2401
ajuma315a4782015-07-24 21:16:342402TEST_F(LayerTreeHostCommonTest,
2403 ScreenSpaceTransformIsAnimatingWithDelayedAnimation) {
2404 LayerImpl* parent = root_layer();
2405 LayerImpl* child = AddChild<LayerImpl>(parent);
2406 LayerImpl* grand_child = AddChild<LayerImpl>(child);
2407 LayerImpl* great_grand_child = AddChild<LayerImpl>(grand_child);
2408
2409 parent->SetDrawsContent(true);
2410 child->SetDrawsContent(true);
2411 grand_child->SetDrawsContent(true);
2412 great_grand_child->SetDrawsContent(true);
2413
2414 gfx::Transform identity;
2415
2416 SetLayerPropertiesForTesting(parent, identity, gfx::Point3F(), gfx::PointF(),
2417 gfx::Size(10, 10), true, false, true);
2418 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
2419 gfx::Size(10, 10), true, false, false);
2420 SetLayerPropertiesForTesting(grand_child, identity, gfx::Point3F(),
2421 gfx::PointF(), gfx::Size(10, 10), true, false,
2422 false);
2423 SetLayerPropertiesForTesting(great_grand_child, identity, gfx::Point3F(),
2424 gfx::PointF(), gfx::Size(10, 10), true, false,
2425 false);
2426
2427 // Add a transform animation with a start delay to |grand_child|.
2428 scoped_ptr<Animation> animation = Animation::Create(
danakja5a05ba02015-11-20 20:14:212429 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)), 0, 1,
ajuma315a4782015-07-24 21:16:342430 Animation::TRANSFORM);
2431 animation->set_fill_mode(Animation::FILL_MODE_NONE);
2432 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
danakja04855a2015-11-18 20:39:102433 grand_child->layer_animation_controller()->AddAnimation(std::move(animation));
ajuma315a4782015-07-24 21:16:342434
2435 ExecuteCalculateDrawProperties(parent);
2436
2437 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2438 EXPECT_FALSE(child->screen_space_transform_is_animating());
2439
2440 EXPECT_FALSE(grand_child->TransformIsAnimating());
2441 EXPECT_TRUE(grand_child->HasPotentiallyRunningTransformAnimation());
2442 EXPECT_TRUE(grand_child->screen_space_transform_is_animating());
2443 EXPECT_TRUE(great_grand_child->screen_space_transform_is_animating());
2444}
2445
[email protected]989386c2013-07-18 21:37:232446TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322447 // Test the calculateVisibleRect() function works correctly for identity
2448 // transforms.
2449
[email protected]2c7c6702013-03-26 03:14:052450 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322451 gfx::Transform layer_to_surface_transform;
2452
2453 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232454 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052455 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322456 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2457 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322458 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322459
2460 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052461 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322462 actual = LayerTreeHostCommon::CalculateVisibleRect(
2463 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2464 EXPECT_TRUE(actual.IsEmpty());
2465
2466 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052467 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2468 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322469 actual = LayerTreeHostCommon::CalculateVisibleRect(
2470 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322471 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322472}
2473
[email protected]989386c2013-07-18 21:37:232474TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322475 // Test the calculateVisibleRect() function works correctly for scaling
2476 // transforms.
2477
[email protected]2c7c6702013-03-26 03:14:052478 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2479 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322480 gfx::Transform layer_to_surface_transform;
2481
2482 // Case 1: Layer is contained within the surface.
2483 layer_to_surface_transform.MakeIdentity();
2484 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052485 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322486 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2487 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322488 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322489
2490 // Case 2: Layer is outside the surface rect.
2491 layer_to_surface_transform.MakeIdentity();
2492 layer_to_surface_transform.Translate(120.0, 120.0);
2493 actual = LayerTreeHostCommon::CalculateVisibleRect(
2494 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2495 EXPECT_TRUE(actual.IsEmpty());
2496
2497 // Case 3: Layer is partially overlapping the surface rect.
2498 layer_to_surface_transform.MakeIdentity();
2499 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052500 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322501 actual = LayerTreeHostCommon::CalculateVisibleRect(
2502 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322503 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322504}
2505
[email protected]989386c2013-07-18 21:37:232506TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322507 // Test the calculateVisibleRect() function works correctly for rotations
2508 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2509 // should return the g in the layer's space.
2510
[email protected]2c7c6702013-03-26 03:14:052511 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2512 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322513 gfx::Transform layer_to_surface_transform;
2514
2515 // Case 1: Layer is contained within the surface.
2516 layer_to_surface_transform.MakeIdentity();
2517 layer_to_surface_transform.Translate(50.0, 50.0);
2518 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052519 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322520 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2521 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322522 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322523
2524 // Case 2: Layer is outside the surface rect.
2525 layer_to_surface_transform.MakeIdentity();
2526 layer_to_surface_transform.Translate(-50.0, 0.0);
2527 layer_to_surface_transform.Rotate(45.0);
2528 actual = LayerTreeHostCommon::CalculateVisibleRect(
2529 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2530 EXPECT_TRUE(actual.IsEmpty());
2531
2532 // Case 3: The layer is rotated about its top-left corner. In surface space,
2533 // the layer is oriented diagonally, with the left half outside of the render
2534 // surface. In this case, the g should still be the entire layer
2535 // (remember the g is computed in layer space); both the top-left
2536 // and bottom-right corners of the layer are still visible.
2537 layer_to_surface_transform.MakeIdentity();
2538 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052539 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322540 actual = LayerTreeHostCommon::CalculateVisibleRect(
2541 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322542 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322543
2544 // Case 4: The layer is rotated about its top-left corner, and translated
2545 // upwards. In surface space, the layer is oriented diagonally, with only the
2546 // top corner of the surface overlapping the layer. In layer space, the render
2547 // surface overlaps the right side of the layer. The g should be
2548 // the layer's right half.
2549 layer_to_surface_transform.MakeIdentity();
2550 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2551 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052552 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322553 actual = LayerTreeHostCommon::CalculateVisibleRect(
2554 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322555 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322556}
2557
[email protected]989386c2013-07-18 21:37:232558TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322559 // Test that the calculateVisibleRect() function works correctly for 3d
2560 // transforms.
2561
[email protected]2c7c6702013-03-26 03:14:052562 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2563 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322564 gfx::Transform layer_to_surface_transform;
2565
2566 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2567 // degrees, should be fully contained in the render surface.
2568 layer_to_surface_transform.MakeIdentity();
2569 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052570 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322571 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2572 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322573 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322574
2575 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2576 // degrees, but shifted to the side so only the right-half the layer would be
2577 // visible on the surface.
2578 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262579 SkMScalar half_width_of_rotated_layer =
2580 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322581 layer_to_surface_transform.MakeIdentity();
2582 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232583 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2584 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052585 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322586 actual = LayerTreeHostCommon::CalculateVisibleRect(
2587 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322588 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322589}
2590
[email protected]989386c2013-07-18 21:37:232591TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322592 // Test the calculateVisibleRect() function works correctly when the layer has
2593 // a perspective projection onto the target surface.
2594
[email protected]2c7c6702013-03-26 03:14:052595 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2596 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322597 gfx::Transform layer_to_surface_transform;
2598
2599 // Case 1: Even though the layer is twice as large as the surface, due to
2600 // perspective foreshortening, the layer will fit fully in the surface when
2601 // its translated more than the perspective amount.
2602 layer_to_surface_transform.MakeIdentity();
2603
2604 // The following sequence of transforms applies the perspective about the
2605 // center of the surface.
2606 layer_to_surface_transform.Translate(50.0, 50.0);
2607 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2608 layer_to_surface_transform.Translate(-50.0, -50.0);
2609
2610 // This translate places the layer in front of the surface's projection plane.
2611 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2612
[email protected]2c7c6702013-03-26 03:14:052613 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322614 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2615 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322616 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322617
2618 // Case 2: same projection as before, except that the layer is also translated
2619 // to the side, so that only the right half of the layer should be visible.
2620 //
2621 // Explanation of expected result: The perspective ratio is (z distance
2622 // between layer and camera origin) / (z distance between projection plane and
2623 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2624 // move a layer by translating -50 units in projected surface units (so that
2625 // only half of it is visible), then we would need to translate by (-36 / 9) *
2626 // -50 == -200 in the layer's units.
2627 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232628 expected = gfx::Rect(gfx::Point(50, -50),
2629 gfx::Size(100, 200)); // The right half of the layer's
2630 // bounding rect.
[email protected]fb661802013-03-25 01:59:322631 actual = LayerTreeHostCommon::CalculateVisibleRect(
2632 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322633 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322634}
2635
[email protected]989386c2013-07-18 21:37:232636TEST_F(LayerTreeHostCommonTest,
2637 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322638 // There is currently no explicit concept of an orthographic projection plane
2639 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2640 // are technically behind the surface in an orthographic world should not be
2641 // clipped when they are flattened to the surface.
2642
[email protected]2c7c6702013-03-26 03:14:052643 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2644 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322645 gfx::Transform layer_to_surface_transform;
2646
2647 // This sequence of transforms effectively rotates the layer about the y-axis
2648 // at the center of the layer.
2649 layer_to_surface_transform.MakeIdentity();
2650 layer_to_surface_transform.Translate(50.0, 0.0);
2651 layer_to_surface_transform.RotateAboutYAxis(45.0);
2652 layer_to_surface_transform.Translate(-50.0, 0.0);
2653
[email protected]2c7c6702013-03-26 03:14:052654 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322655 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2656 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322657 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322658}
2659
[email protected]989386c2013-07-18 21:37:232660TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322661 // Test the calculateVisibleRect() function works correctly when projecting a
2662 // surface onto a layer, but the layer is partially behind the camera (not
2663 // just behind the projection plane). In this case, the cartesian coordinates
2664 // may seem to be valid, but actually they are not. The visible rect needs to
2665 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2666 // converting to cartesian coordinates.
2667
[email protected]2c7c6702013-03-26 03:14:052668 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232669 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322670 gfx::Transform layer_to_surface_transform;
2671
2672 // The layer is positioned so that the right half of the layer should be in
2673 // front of the camera, while the other half is behind the surface's
2674 // projection plane. The following sequence of transforms applies the
2675 // perspective and rotation about the center of the layer.
2676 layer_to_surface_transform.MakeIdentity();
2677 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2678 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2679 layer_to_surface_transform.RotateAboutYAxis(45.0);
2680
2681 // Sanity check that this transform does indeed cause w < 0 when applying the
2682 // transform, otherwise this code is not testing the intended scenario.
2683 bool clipped;
2684 MathUtil::MapQuad(layer_to_surface_transform,
2685 gfx::QuadF(gfx::RectF(layer_content_rect)),
2686 &clipped);
2687 ASSERT_TRUE(clipped);
2688
2689 int expected_x_position = 0;
2690 int expected_width = 10;
2691 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2692 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2693 EXPECT_EQ(expected_x_position, actual.x());
2694 EXPECT_EQ(expected_width, actual.width());
2695}
2696
[email protected]989386c2013-07-18 21:37:232697TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322698 // To determine visible rect in layer space, there needs to be an
2699 // un-projection from surface space to layer space. When the original
2700 // transform was a perspective projection that was clipped, it returns a rect
2701 // that encloses the clipped bounds. Un-projecting this new rect may require
2702 // clipping again.
2703
2704 // This sequence of transforms causes one corner of the layer to protrude
2705 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232706 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2707 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322708 gfx::Transform layer_to_surface_transform;
2709 layer_to_surface_transform.MakeIdentity();
2710 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2711 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2712 layer_to_surface_transform.RotateAboutYAxis(45.0);
2713 layer_to_surface_transform.RotateAboutXAxis(80.0);
2714
2715 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2716 // code is not testing the intended scenario.
2717 bool clipped;
danakj5e6ff6d2015-09-05 04:43:442718 gfx::RectF clipped_rect = MathUtil::MapClippedRect(
2719 layer_to_surface_transform, gfx::RectF(layer_content_rect));
[email protected]fb661802013-03-25 01:59:322720 MathUtil::ProjectQuad(
2721 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2722 ASSERT_TRUE(clipped);
2723
2724 // Only the corner of the layer is not visible on the surface because of being
2725 // clipped. But, the net result of rounding visible region to an axis-aligned
2726 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052727 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322728 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2729 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322730 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322731}
2732
miletus9d3da522015-06-05 19:45:072733TEST_F(LayerTreeHostCommonTest,
2734 VisibleRectsForPositionedRootLayerClippedByViewport) {
enne6c281f6e2015-08-18 23:23:002735 LayerImpl* root = root_layer();
2736 root->SetDrawsContent(true);
miletus9d3da522015-06-05 19:45:072737
2738 gfx::Transform identity_matrix;
2739 // Root layer is positioned at (60, 70). The default device viewport size
2740 // is (0, 0, 100x100) in target space. So the root layer's visible rect
2741 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
enne6c281f6e2015-08-18 23:23:002742 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
miletus9d3da522015-06-05 19:45:072743 gfx::PointF(60, 70), gfx::Size(100, 100), true,
enne6c281f6e2015-08-18 23:23:002744 false, true);
2745 ExecuteCalculateDrawProperties(root);
miletus9d3da522015-06-05 19:45:072746
danakj5e6ff6d2015-09-05 04:43:442747 EXPECT_EQ(gfx::RectF(100.f, 100.f),
miletus9d3da522015-06-05 19:45:072748 root->render_surface()->DrawableContentRect());
2749 // In target space, not clipped.
2750 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
2751 // In layer space, clipped.
danakj5e6ff6d2015-09-05 04:43:442752 EXPECT_EQ(gfx::Rect(40, 30), root->visible_layer_rect());
miletus9d3da522015-06-05 19:45:072753}
2754
[email protected]989386c2013-07-18 21:37:232755TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
weiliangc0dece732015-07-27 19:06:172756 LayerImpl* root = root_layer();
2757 LayerImpl* child1_layer = AddChildToRoot<LayerImpl>();
2758 child1_layer->SetDrawsContent(true);
2759 LayerImpl* child2_layer = AddChildToRoot<LayerImpl>();
2760 child2_layer->SetDrawsContent(true);
2761 LayerImpl* child3_layer = AddChildToRoot<LayerImpl>();
2762 child3_layer->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:282763
[email protected]fb661802013-03-25 01:59:322764 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:172765 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2766 gfx::PointF(), gfx::Size(100, 100), true, false,
2767 true);
2768 SetLayerPropertiesForTesting(child1_layer, identity_matrix, gfx::Point3F(),
2769 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]fb661802013-03-25 01:59:322770 false);
weiliangc0dece732015-07-27 19:06:172771 SetLayerPropertiesForTesting(child2_layer, identity_matrix, gfx::Point3F(),
2772 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2773 false, false);
2774 SetLayerPropertiesForTesting(child3_layer, identity_matrix, gfx::Point3F(),
2775 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2776 true, false, false);
[email protected]fb661802013-03-25 01:59:322777
weiliangc0dece732015-07-27 19:06:172778 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322779
danakj5e6ff6d2015-09-05 04:43:442780 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:322781 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322782
danakj64767d902015-06-19 00:10:432783 // Layers that do not draw content should have empty visible_layer_rects.
2784 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:322785
danakj64767d902015-06-19 00:10:432786 // layer visible_layer_rects are clipped by their target surface.
weiliangc0dece732015-07-27 19:06:172787 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->visible_layer_rect());
2788 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer->visible_layer_rect());
2789 EXPECT_TRUE(child3_layer->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:322790
2791 // layer drawable_content_rects are not clipped.
weiliangc0dece732015-07-27 19:06:172792 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer->drawable_content_rect());
2793 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer->drawable_content_rect());
2794 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322795}
2796
[email protected]989386c2013-07-18 21:37:232797TEST_F(LayerTreeHostCommonTest,
2798 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
weiliangc0dece732015-07-27 19:06:172799 LayerImpl* root = root_layer();
2800 LayerImpl* child = AddChildToRoot<LayerImpl>();
2801 LayerImpl* grand_child1 = AddChild<LayerImpl>(child);
2802 grand_child1->SetDrawsContent(true);
2803 LayerImpl* grand_child2 = AddChild<LayerImpl>(child);
2804 grand_child2->SetDrawsContent(true);
2805 LayerImpl* grand_child3 = AddChild<LayerImpl>(child);
2806 grand_child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:282807
[email protected]fb661802013-03-25 01:59:322808 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:172809 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2810 gfx::PointF(), gfx::Size(100, 100), true, false,
2811 true);
2812 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
2813 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]fb661802013-03-25 01:59:322814 false);
weiliangc0dece732015-07-27 19:06:172815 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2816 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2817 false, false);
2818 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2819 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2820 false, false);
2821 SetLayerPropertiesForTesting(grand_child3, identity_matrix, gfx::Point3F(),
2822 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2823 true, false, false);
[email protected]fb661802013-03-25 01:59:322824
2825 child->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:172826 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322827
danakj5e6ff6d2015-09-05 04:43:442828 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:322829 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322830
2831 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:432832 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
2833 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:322834
2835 // All grandchild visible content rects should be clipped by child.
danakj64767d902015-06-19 00:10:432836 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_layer_rect());
2837 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_layer_rect());
2838 EXPECT_TRUE(grand_child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:322839
2840 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:322841 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
2842 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322843 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2844}
2845
ajuma27442dd2015-03-30 19:19:482846TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
loysoa6edaaff2015-05-25 03:26:442847 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2848 scoped_refptr<Layer> child = Layer::Create(layer_settings());
ajuma27442dd2015-03-30 19:19:482849 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loysoa6edaaff2015-05-25 03:26:442850 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma27442dd2015-03-30 19:19:482851 root->AddChild(child);
2852 child->AddChild(grand_child);
2853
ennea7b43c32015-06-18 20:01:332854 host()->SetRootLayer(root);
ajuma27442dd2015-03-30 19:19:482855
2856 gfx::Transform identity_matrix;
2857 gfx::Transform child_scale_matrix;
2858 child_scale_matrix.Scale(0.25f, 0.25f);
2859 gfx::Transform grand_child_scale_matrix;
2860 grand_child_scale_matrix.Scale(0.246f, 0.246f);
2861 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2862 gfx::PointF(), gfx::Size(100, 100), true, false);
2863 SetLayerPropertiesForTesting(child.get(), child_scale_matrix, gfx::Point3F(),
2864 gfx::PointF(), gfx::Size(10, 10), true, false);
2865 SetLayerPropertiesForTesting(grand_child.get(), grand_child_scale_matrix,
2866 gfx::Point3F(), gfx::PointF(),
2867 gfx::Size(100, 100), true, false);
2868
2869 child->SetMasksToBounds(true);
enne601f2ef12015-05-19 18:20:172870 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajuma27442dd2015-03-30 19:19:482871
2872 // The visible rect is expanded to integer coordinates in target space before
2873 // being projected back to layer space, where it is once again expanded to
2874 // integer coordinates.
2875 EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_rect_from_property_trees());
2876}
2877
[email protected]989386c2013-07-18 21:37:232878TEST_F(LayerTreeHostCommonTest,
2879 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
weiliangc0dece732015-07-27 19:06:172880 LayerImpl* root = root_layer();
2881 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
2882 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
2883 child1->SetDrawsContent(true);
2884 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
2885 child2->SetDrawsContent(true);
2886 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
2887 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:282888
[email protected]fb661802013-03-25 01:59:322889 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:172890 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2891 gfx::PointF(), gfx::Size(100, 100), true, false,
2892 true);
2893 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
2894 gfx::PointF(), gfx::Size(3, 4), true, false,
2895 true);
2896 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2897 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2898 false, false);
2899 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2900 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2901 false, false);
2902 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
2903 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2904 true, false, false);
[email protected]fb661802013-03-25 01:59:322905
weiliangc0dece732015-07-27 19:06:172906 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:322907
weiliangc0dece732015-07-27 19:06:172908 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:322909
danakj5e6ff6d2015-09-05 04:43:442910 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:322911 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322912
2913 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:432914 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:172915 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:322916
2917 // An unclipped surface grows its DrawableContentRect to include all drawable
2918 // regions of the subtree.
danakj5e6ff6d2015-09-05 04:43:442919 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
weiliangc0dece732015-07-27 19:06:172920 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322921
2922 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:432923 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
2924 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
2925 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:322926
hush6b614212014-12-04 22:37:322927 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2928 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2929 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322930}
2931
[email protected]989386c2013-07-18 21:37:232932TEST_F(LayerTreeHostCommonTest,
ajuma51d73f72015-10-19 19:43:582933 DrawableAndVisibleRectsWhenCannotRenderToSeparateSurface) {
2934 LayerImpl* root = root_layer();
2935 LayerImpl* parent = AddChild<LayerImpl>(root);
2936 LayerImpl* child1 = AddChild<LayerImpl>(parent);
2937 LayerImpl* child2 = AddChild<LayerImpl>(parent);
2938 LayerImpl* grand_child1 = AddChild<LayerImpl>(child1);
2939 LayerImpl* grand_child2 = AddChild<LayerImpl>(child2);
2940 LayerImpl* leaf_node1 = AddChild<LayerImpl>(grand_child1);
2941 LayerImpl* leaf_node2 = AddChild<LayerImpl>(grand_child2);
2942
2943 root->SetDrawsContent(true);
2944 parent->SetDrawsContent(true);
2945 child1->SetDrawsContent(true);
2946 child2->SetDrawsContent(true);
2947 grand_child1->SetDrawsContent(true);
2948 grand_child2->SetDrawsContent(true);
2949 leaf_node1->SetDrawsContent(true);
2950 leaf_node2->SetDrawsContent(true);
2951
2952 const gfx::Transform identity_matrix;
2953
2954 // child1 and child2 get render surfaces when surfaces are enabled.
2955 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
2956 gfx::PointF(), gfx::Size(100, 100), true, false,
2957 true);
2958 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
2959 gfx::PointF(2.f, 2.f), gfx::Size(400, 400), true,
2960 false, false);
2961 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
2962 gfx::PointF(4.f, 4.f), gfx::Size(800, 800), true,
2963 false, true);
2964 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
2965 gfx::PointF(3.f, 3.f), gfx::Size(800, 800), true,
2966 false, true);
2967 SetLayerPropertiesForTesting(grand_child1, identity_matrix, gfx::Point3F(),
2968 gfx::PointF(8.f, 8.f), gfx::Size(1500, 1500),
2969 true, false, false);
2970 SetLayerPropertiesForTesting(grand_child2, identity_matrix, gfx::Point3F(),
2971 gfx::PointF(7.f, 7.f), gfx::Size(1500, 1500),
2972 true, false, false);
2973 SetLayerPropertiesForTesting(leaf_node1, identity_matrix, gfx::Point3F(),
2974 gfx::PointF(16.f, 16.f), gfx::Size(2000, 2000),
2975 true, false, false);
2976 SetLayerPropertiesForTesting(leaf_node2, identity_matrix, gfx::Point3F(),
2977 gfx::PointF(9.f, 9.f), gfx::Size(2000, 2000),
2978 true, false, false);
2979
2980 // Case 1: No layers clip. Visible rects are clipped by the viewport, but the
2981 // viewport clip doesn't apply to layers that draw into unclipped surfaces.
2982 // Each layer's drawable content rect is its bounds in target space; the only
2983 // thing that changes with surfaces disabled is that target space is always
2984 // screen space.
2985 ExecuteCalculateDrawProperties(root);
2986 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
2987 EXPECT_EQ(gfx::Rect(0, 0, 98, 98), parent->visible_layer_rect());
2988 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
2989 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
2990 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child1->visible_layer_rect());
2991 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
2992 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node1->visible_layer_rect());
2993 EXPECT_EQ(gfx::Rect(2000, 2000), leaf_node2->visible_layer_rect());
2994
2995 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
2996 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
2997 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
2998 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
2999 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3000 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3001 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3002 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3003
3004 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3005 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3006 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3007 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3008 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3009 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3010 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3011 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3012 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3013
3014 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3015 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3016 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3017 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3018 EXPECT_EQ(gfx::Rect(14, 14, 1500, 1500),
3019 grand_child1->drawable_content_rect());
3020 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3021 grand_child2->drawable_content_rect());
3022 EXPECT_EQ(gfx::Rect(30, 30, 2000, 2000), leaf_node1->drawable_content_rect());
3023 EXPECT_EQ(gfx::Rect(21, 21, 2000, 2000), leaf_node2->drawable_content_rect());
3024
3025 // Case 2: The parent clips. In this case, neither surface is unclipped, so
3026 // all visible layer rects are clipped by the intersection of all ancestor
3027 // clips, whether or not surfaces are disabled. However, drawable content
3028 // rects are clipped only until the next render surface is reached, so
3029 // descendants of parent have their drawable content rects clipped only when
3030 // surfaces are disabled.
3031 parent->SetMasksToBounds(true);
3032 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3033 ExecuteCalculateDrawProperties(root);
3034 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3035 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3036 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3037 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3038 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3039 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3040 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3041 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3042
3043 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3044 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3045 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3046 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3047 EXPECT_EQ(gfx::Rect(8, 8, 1500, 1500), grand_child1->drawable_content_rect());
3048 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3049 EXPECT_EQ(gfx::Rect(24, 24, 2000, 2000), leaf_node1->drawable_content_rect());
3050 EXPECT_EQ(gfx::Rect(16, 16, 2000, 2000), leaf_node2->drawable_content_rect());
3051
3052 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3053 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3054 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3055 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3056 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3057 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3058 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3059 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3060 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3061
3062 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3063 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3064 EXPECT_EQ(gfx::Rect(6, 6, 396, 396), child1->drawable_content_rect());
3065 EXPECT_EQ(gfx::Rect(5, 5, 397, 397), child2->drawable_content_rect());
3066 EXPECT_EQ(gfx::Rect(14, 14, 388, 388), grand_child1->drawable_content_rect());
3067 EXPECT_EQ(gfx::Rect(12, 12, 390, 390), grand_child2->drawable_content_rect());
3068 EXPECT_EQ(gfx::Rect(30, 30, 372, 372), leaf_node1->drawable_content_rect());
3069 EXPECT_EQ(gfx::Rect(21, 21, 381, 381), leaf_node2->drawable_content_rect());
3070
3071 parent->SetMasksToBounds(false);
3072
3073 // Case 3: child1 and grand_child2 clip. In this case, descendants of these
3074 // layers have their visible rects clipped by them; without surfaces, these
3075 // rects are also clipped by the viewport. Similarly, descendants of these
3076 // layers have their drawable content rects clipped by them.
3077 child1->SetMasksToBounds(true);
3078 grand_child2->SetMasksToBounds(true);
3079 host_impl()->active_tree()->property_trees()->needs_rebuild = true;
3080 ExecuteCalculateDrawProperties(root);
3081 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3082 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3083 EXPECT_EQ(gfx::Rect(800, 800), child1->visible_layer_rect());
3084 EXPECT_EQ(gfx::Rect(800, 800), child2->visible_layer_rect());
3085 EXPECT_EQ(gfx::Rect(792, 792), grand_child1->visible_layer_rect());
3086 EXPECT_EQ(gfx::Rect(1500, 1500), grand_child2->visible_layer_rect());
3087 EXPECT_EQ(gfx::Rect(776, 776), leaf_node1->visible_layer_rect());
3088 EXPECT_EQ(gfx::Rect(1491, 1491), leaf_node2->visible_layer_rect());
3089
3090 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3091 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3092 EXPECT_EQ(gfx::Rect(800, 800), child1->drawable_content_rect());
3093 EXPECT_EQ(gfx::Rect(800, 800), child2->drawable_content_rect());
3094 EXPECT_EQ(gfx::Rect(8, 8, 792, 792), grand_child1->drawable_content_rect());
3095 EXPECT_EQ(gfx::Rect(7, 7, 1500, 1500), grand_child2->drawable_content_rect());
3096 EXPECT_EQ(gfx::Rect(24, 24, 776, 776), leaf_node1->drawable_content_rect());
3097 EXPECT_EQ(gfx::Rect(16, 16, 1491, 1491), leaf_node2->drawable_content_rect());
3098
3099 ExecuteCalculateDrawPropertiesWithoutSeparateSurfaces(root);
3100 EXPECT_EQ(gfx::Rect(100, 100), root->visible_layer_rect());
3101 EXPECT_EQ(gfx::Rect(98, 98), parent->visible_layer_rect());
3102 EXPECT_EQ(gfx::Rect(94, 94), child1->visible_layer_rect());
3103 EXPECT_EQ(gfx::Rect(95, 95), child2->visible_layer_rect());
3104 EXPECT_EQ(gfx::Rect(86, 86), grand_child1->visible_layer_rect());
3105 EXPECT_EQ(gfx::Rect(88, 88), grand_child2->visible_layer_rect());
3106 EXPECT_EQ(gfx::Rect(70, 70), leaf_node1->visible_layer_rect());
3107 EXPECT_EQ(gfx::Rect(79, 79), leaf_node2->visible_layer_rect());
3108
3109 EXPECT_EQ(gfx::Rect(100, 100), root->drawable_content_rect());
3110 EXPECT_EQ(gfx::Rect(2, 2, 400, 400), parent->drawable_content_rect());
3111 EXPECT_EQ(gfx::Rect(6, 6, 800, 800), child1->drawable_content_rect());
3112 EXPECT_EQ(gfx::Rect(5, 5, 800, 800), child2->drawable_content_rect());
3113 EXPECT_EQ(gfx::Rect(14, 14, 792, 792), grand_child1->drawable_content_rect());
3114 EXPECT_EQ(gfx::Rect(12, 12, 1500, 1500),
3115 grand_child2->drawable_content_rect());
3116 EXPECT_EQ(gfx::Rect(30, 30, 776, 776), leaf_node1->drawable_content_rect());
3117 EXPECT_EQ(gfx::Rect(21, 21, 1491, 1491), leaf_node2->drawable_content_rect());
3118}
3119
3120TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:023121 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
enne6c281f6e2015-08-18 23:23:003122 LayerImpl* root = root_layer();
3123 LayerImpl* child1 = AddChild<LayerImpl>(root);
3124 LayerImpl* child2 = AddChild<LayerImpl>(root);
3125 LayerImpl* child3 = AddChild<LayerImpl>(root);
3126 child1->SetDrawsContent(true);
3127 child2->SetDrawsContent(true);
3128 child3->SetDrawsContent(true);
hush887bb542014-12-02 22:49:023129
3130 gfx::Transform identity_matrix;
enne6c281f6e2015-08-18 23:23:003131 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3132 gfx::PointF(), gfx::Size(100, 100), true, false,
3133 true);
3134 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023135 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
enne6c281f6e2015-08-18 23:23:003136 false, false);
3137 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023138 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
enne6c281f6e2015-08-18 23:23:003139 false, false);
3140 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
hush887bb542014-12-02 22:49:023141 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
enne6c281f6e2015-08-18 23:23:003142 true, false, false);
hush887bb542014-12-02 22:49:023143
enne6c281f6e2015-08-18 23:23:003144 LayerImplList render_surface_layer_list_impl;
ajumad9432e32015-11-30 19:43:443145 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
hush887bb542014-12-02 22:49:023146 // Now set the root render surface an empty clip.
enne6c281f6e2015-08-18 23:23:003147 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:443148 root, gfx::Size(), &render_surface_layer_list_impl,
3149 root->layer_tree_impl()->current_render_surface_list_id());
hush887bb542014-12-02 22:49:023150
3151 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
3152 ASSERT_TRUE(root->render_surface());
3153 EXPECT_FALSE(root->is_clipped());
3154
3155 gfx::Rect empty;
3156 EXPECT_EQ(empty, root->render_surface()->clip_rect());
3157 EXPECT_TRUE(root->render_surface()->is_clipped());
3158
3159 // Visible content rect calculation will check if the target surface is
3160 // clipped or not. An empty clip rect does not indicate the render surface
3161 // is unclipped.
danakj64767d902015-06-19 00:10:433162 EXPECT_EQ(empty, child1->visible_layer_rect());
3163 EXPECT_EQ(empty, child2->visible_layer_rect());
3164 EXPECT_EQ(empty, child3->visible_layer_rect());
hush887bb542014-12-02 22:49:023165}
3166
3167TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233168 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
weiliangc0dece732015-07-27 19:06:173169 LayerImpl* root = root_layer();
3170 LayerImpl* child = AddChildToRoot<LayerImpl>();
3171 child->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283172
[email protected]630ddad2013-08-16 03:01:323173 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473174 gfx::Transform identity_matrix;
3175 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323176 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473177
weiliangc0dece732015-07-27 19:06:173178 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3179 gfx::PointF(), gfx::Size(100, 100), true, false,
3180 true);
3181 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3182 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3183 false, false);
[email protected]451107a32013-04-10 05:12:473184
weiliangc0dece732015-07-27 19:06:173185 ExecuteCalculateDrawProperties(root);
[email protected]451107a32013-04-10 05:12:473186
danakj64767d902015-06-19 00:10:433187 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473188 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323189
[email protected]08bdf1b2014-04-16 23:23:293190 // Case 2: a matrix with flattened z, uninvertible and not visible according
3191 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:323192 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263193 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323194 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3195
weiliangc0dece732015-07-27 19:06:173196 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3197 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3198 false, false);
[email protected]630ddad2013-08-16 03:01:323199
weiliangc0dece732015-07-27 19:06:173200 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323201
danakj64767d902015-06-19 00:10:433202 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293203 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323204
[email protected]08bdf1b2014-04-16 23:23:293205 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:323206 uninvertible_matrix.MakeIdentity();
3207 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263208 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323209 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3210
weiliangc0dece732015-07-27 19:06:173211 SetLayerPropertiesForTesting(child, uninvertible_matrix, gfx::Point3F(),
3212 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3213 false, false);
[email protected]630ddad2013-08-16 03:01:323214
weiliangc0dece732015-07-27 19:06:173215 ExecuteCalculateDrawProperties(root);
[email protected]630ddad2013-08-16 03:01:323216
danakj64767d902015-06-19 00:10:433217 EXPECT_TRUE(child->visible_layer_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293218 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473219}
3220
[email protected]989386c2013-07-18 21:37:233221TEST_F(LayerTreeHostCommonTest,
ajumaae0dc2d2015-08-05 21:55:563222 VisibleContentRectForLayerWithUninvertibleDrawTransform) {
3223 LayerImpl* root = root_layer();
3224 LayerImpl* child = AddChildToRoot<LayerImpl>();
3225 LayerImpl* grand_child = AddChild<LayerImpl>(child);
3226 child->SetDrawsContent(true);
3227 grand_child->SetDrawsContent(true);
3228
3229 gfx::Transform identity_matrix;
3230
3231 gfx::Transform perspective;
3232 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3233
3234 gfx::Transform rotation;
3235 rotation.RotateAboutYAxis(45.0);
3236
3237 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3238 gfx::PointF(), gfx::Size(100, 100), true, false,
3239 true);
3240 SetLayerPropertiesForTesting(child, perspective, gfx::Point3F(),
3241 gfx::PointF(10.f, 10.f), gfx::Size(100, 100),
3242 false, true, false);
3243 SetLayerPropertiesForTesting(grand_child, rotation, gfx::Point3F(),
3244 gfx::PointF(), gfx::Size(100, 100), false, true,
3245 false);
3246
3247 ExecuteCalculateDrawProperties(root);
3248
3249 // Though all layers have invertible transforms, matrix multiplication using
3250 // floating-point math makes the draw transform uninvertible.
ajumad9432e32015-11-30 19:43:443251 EXPECT_FALSE(grand_child->DrawTransform().IsInvertible());
ajumaae0dc2d2015-08-05 21:55:563252
3253 // CalcDrawProps only skips a subtree when a layer's own transform is
3254 // uninvertible, not when its draw transform is invertible, since CDP makes
3255 // skipping decisions before computing a layer's draw transform. Property
3256 // trees make skipping decisions after computing draw transforms, so could be
3257 // made to skip layers with an uninvertible draw transform (once CDP is
3258 // deleted).
3259 EXPECT_EQ(gfx::Rect(grand_child->bounds()),
3260 grand_child->visible_layer_rect());
3261}
3262
3263TEST_F(LayerTreeHostCommonTest,
3264 OcclusionForLayerWithUninvertibleDrawTransform) {
khushalsagarb64b360d2015-10-21 19:25:163265 FakeImplTaskRunnerProvider task_runner_provider;
ajumaae0dc2d2015-08-05 21:55:563266 TestSharedBitmapManager shared_bitmap_manager;
3267 TestTaskGraphRunner task_graph_runner;
revemand180dfc32015-09-24 00:19:433268 scoped_ptr<OutputSurface> output_surface = FakeOutputSurface::Create3d();
khushalsagarb64b360d2015-10-21 19:25:163269 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
ajumaae0dc2d2015-08-05 21:55:563270 &task_graph_runner);
3271 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
3272 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
3273 scoped_ptr<LayerImpl> grand_child =
3274 LayerImpl::Create(host_impl.active_tree(), 3);
3275 scoped_ptr<LayerImpl> occluding_child =
3276 LayerImpl::Create(host_impl.active_tree(), 4);
3277 child->SetDrawsContent(true);
3278 grand_child->SetDrawsContent(true);
3279 occluding_child->SetDrawsContent(true);
3280 occluding_child->SetContentsOpaque(true);
3281
3282 gfx::Transform identity_matrix;
3283 gfx::Transform perspective;
3284 perspective.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
3285
3286 gfx::Transform rotation;
3287 rotation.RotateAboutYAxis(45.0);
3288
3289 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
3290 gfx::PointF(), gfx::Size(1000, 1000), true,
3291 false, true);
3292 SetLayerPropertiesForTesting(child.get(), perspective, gfx::Point3F(),
3293 gfx::PointF(10.f, 10.f), gfx::Size(300, 300),
3294 false, true, false);
3295 SetLayerPropertiesForTesting(grand_child.get(), rotation, gfx::Point3F(),
3296 gfx::PointF(), gfx::Size(200, 200), false, true,
3297 false);
3298 SetLayerPropertiesForTesting(occluding_child.get(), identity_matrix,
3299 gfx::Point3F(), gfx::PointF(),
3300 gfx::Size(200, 200), false, false, false);
3301
3302 host_impl.SetViewportSize(root->bounds());
3303
danakja04855a2015-11-18 20:39:103304 child->AddChild(std::move(grand_child));
3305 root->AddChild(std::move(child));
3306 root->AddChild(std::move(occluding_child));
3307 host_impl.active_tree()->SetRootLayer(std::move(root));
sievers71c62dd52015-10-07 01:44:393308 host_impl.SetVisible(true);
revemand180dfc32015-09-24 00:19:433309 host_impl.InitializeRenderer(output_surface.get());
jaydasikad7dea632015-11-06 04:40:123310 host_impl.active_tree()->BuildPropertyTreesForTesting();
ajumaae0dc2d2015-08-05 21:55:563311 bool update_lcd_text = false;
3312 host_impl.active_tree()->UpdateDrawProperties(update_lcd_text);
3313
3314 LayerImpl* grand_child_ptr =
vmpstra370ef52015-11-18 10:41:283315 host_impl.active_tree()->root_layer()->children()[0]->children()[0].get();
ajumaae0dc2d2015-08-05 21:55:563316
3317 // Though all layers have invertible transforms, matrix multiplication using
3318 // floating-point math makes the draw transform uninvertible.
ajumad9432e32015-11-30 19:43:443319 EXPECT_FALSE(grand_child_ptr->DrawTransform().IsInvertible());
ajumaae0dc2d2015-08-05 21:55:563320
3321 // Since |grand_child| has an uninvertible draw transform, it is treated as
3322 // unoccluded (even though |occluding_child| comes later in draw order, and
3323 // hence potentially occludes it).
3324 gfx::Rect layer_bounds = gfx::Rect(grand_child_ptr->bounds());
3325 EXPECT_EQ(
3326 layer_bounds,
3327 grand_child_ptr->draw_properties()
3328 .occlusion_in_content_space.GetUnoccludedContentRect(layer_bounds));
3329}
3330
3331TEST_F(LayerTreeHostCommonTest,
[email protected]e43c68b2014-05-01 05:10:363332 SingularTransformDoesNotPreventClearingDrawProperties) {
loysoa6edaaff2015-05-25 03:26:443333 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]e43c68b2014-05-01 05:10:363334 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:443335 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]e43c68b2014-05-01 05:10:363336 root->AddChild(child);
3337
ennea7b43c32015-06-18 20:01:333338 host()->SetRootLayer(root);
[email protected]e43c68b2014-05-01 05:10:363339
3340 gfx::Transform identity_matrix;
3341 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3342 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3343
3344 SetLayerPropertiesForTesting(root.get(),
3345 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203346 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:363347 gfx::PointF(),
3348 gfx::Size(100, 100),
3349 true,
3350 false);
3351 SetLayerPropertiesForTesting(child.get(),
3352 identity_matrix,
[email protected]a2566412014-06-05 03:14:203353 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:363354 gfx::PointF(5.f, 5.f),
3355 gfx::Size(50, 50),
3356 true,
3357 false);
3358
jaydasika976cd10b2015-05-26 15:45:243359 child->set_sorted_for_recursion(true);
[email protected]e43c68b2014-05-01 05:10:363360
3361 TransformOperations start_transform_operations;
3362 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
3363
3364 TransformOperations end_transform_operations;
3365 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
3366
3367 AddAnimatedTransformToLayer(
3368 root.get(), 10.0, start_transform_operations, end_transform_operations);
3369
3370 EXPECT_TRUE(root->TransformIsAnimating());
3371
3372 ExecuteCalculateDrawProperties(root.get());
3373
jaydasika976cd10b2015-05-26 15:45:243374 EXPECT_FALSE(child->sorted_for_recursion());
[email protected]e43c68b2014-05-01 05:10:363375}
3376
3377TEST_F(LayerTreeHostCommonTest,
[email protected]8dbc85c2014-05-03 03:21:063378 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
loysoa6edaaff2015-05-25 03:26:443379 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]8dbc85c2014-05-03 03:21:063380
ennea7b43c32015-06-18 20:01:333381 host()->SetRootLayer(root);
[email protected]8dbc85c2014-05-03 03:21:063382
3383 gfx::Transform identity_matrix;
3384 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3385 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3386
3387 SetLayerPropertiesForTesting(root.get(),
3388 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203389 gfx::Point3F(),
[email protected]8dbc85c2014-05-03 03:21:063390 gfx::PointF(),
3391 gfx::Size(100, 100),
3392 true,
3393 false);
3394
jaydasika976cd10b2015-05-26 15:45:243395 root->set_sorted_for_recursion(true);
[email protected]8dbc85c2014-05-03 03:21:063396
3397 EXPECT_FALSE(root->TransformIsAnimating());
3398
3399 ExecuteCalculateDrawProperties(root.get());
3400
jaydasika976cd10b2015-05-26 15:45:243401 EXPECT_FALSE(root->sorted_for_recursion());
[email protected]8dbc85c2014-05-03 03:21:063402}
3403
3404TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233405 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
weiliangc0dece732015-07-27 19:06:173406 LayerImpl* root = root_layer();
3407 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3408 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3409 child1->SetDrawsContent(true);
3410 LayerImpl* child2 = AddChild<LayerImpl>(render_surface);
3411 child2->SetDrawsContent(true);
3412 LayerImpl* child3 = AddChild<LayerImpl>(render_surface);
3413 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283414
[email protected]fb661802013-03-25 01:59:323415 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173416 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3417 gfx::PointF(), gfx::Size(100, 100), true, false,
3418 true);
3419 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3420 gfx::PointF(), gfx::Size(3, 4), true, false,
3421 true);
3422 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3423 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3424 false, false);
3425 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3426 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3427 false, false);
3428 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3429 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3430 true, false, false);
[email protected]fb661802013-03-25 01:59:323431
3432 root->SetMasksToBounds(true);
[email protected]fb661802013-03-25 01:59:323433
weiliangc0dece732015-07-27 19:06:173434 ExecuteCalculateDrawProperties(root);
3435
3436 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323437
danakj5e6ff6d2015-09-05 04:43:443438 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323439 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323440
3441 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433442 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173443 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323444
3445 // A clipped surface grows its DrawableContentRect to include all drawable
3446 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443447 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
weiliangc0dece732015-07-27 19:06:173448 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323449
3450 // All layers that draw content into the surface have their visible content
3451 // rect clipped by the surface clip rect.
danakj64767d902015-06-19 00:10:433452 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3453 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_layer_rect());
3454 EXPECT_TRUE(child3->visible_layer_rect().IsEmpty());
[email protected]fb661802013-03-25 01:59:323455
3456 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323457 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3458 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3459 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323460}
3461
[email protected]989386c2013-07-18 21:37:233462TEST_F(LayerTreeHostCommonTest,
3463 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323464 // Check that clipping does not propagate down surfaces.
weiliangc0dece732015-07-27 19:06:173465 LayerImpl* root = root_layer();
3466 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3467 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
3468 LayerImpl* child1 = AddChild<LayerImpl>(render_surface2);
3469 child1->SetDrawsContent(true);
3470 LayerImpl* child2 = AddChild<LayerImpl>(render_surface2);
3471 child2->SetDrawsContent(true);
3472 LayerImpl* child3 = AddChild<LayerImpl>(render_surface2);
3473 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283474
[email protected]fb661802013-03-25 01:59:323475 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173476 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3477 gfx::PointF(), gfx::Size(100, 100), true, false,
3478 true);
3479 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3480 gfx::PointF(), gfx::Size(3, 4), true, false,
3481 true);
3482 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3483 gfx::PointF(), gfx::Size(7, 13), true, false,
3484 true);
3485 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3486 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3487 false, false);
3488 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3489 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3490 false, false);
3491 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3492 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3493 true, false, false);
[email protected]fb661802013-03-25 01:59:323494
3495 root->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:173496
3497 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323498
3499 ASSERT_TRUE(render_surface1->render_surface());
3500 ASSERT_TRUE(render_surface2->render_surface());
3501
danakj5e6ff6d2015-09-05 04:43:443502 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323503 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323504
3505 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433506 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
3507 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_layer_rect());
3508 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323509
3510 // A clipped surface grows its DrawableContentRect to include all drawable
3511 // regions of the subtree, but also gets clamped by the ancestor's clip.
danakj5e6ff6d2015-09-05 04:43:443512 EXPECT_EQ(gfx::RectF(5.f, 5.f, 95.f, 95.f),
hush6b614212014-12-04 22:37:323513 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323514
3515 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3516 // is only implicitly clipped by render_surface1's content rect. So,
3517 // render_surface2 grows to enclose all drawable content of its subtree.
danakj5e6ff6d2015-09-05 04:43:443518 EXPECT_EQ(gfx::RectF(5.f, 5.f, 170.f, 170.f),
hush6b614212014-12-04 22:37:323519 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323520
3521 // All layers that draw content into render_surface2 think they are unclipped.
danakj64767d902015-06-19 00:10:433522 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3523 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3524 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323525
3526 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323527 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3528 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3529 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323530}
3531
[email protected]989386c2013-07-18 21:37:233532TEST_F(LayerTreeHostCommonTest,
jaydasika27d0f2e2015-10-16 23:52:463533 VisibleRectsForClippedDescendantsOfUnclippedSurfaces) {
3534 LayerImpl* root = root_layer();
3535 LayerImpl* render_surface1 = AddChildToRoot<LayerImpl>();
3536 LayerImpl* child1 = AddChild<LayerImpl>(render_surface1);
3537 LayerImpl* child2 = AddChild<LayerImpl>(child1);
3538 LayerImpl* render_surface2 = AddChild<LayerImpl>(child2);
3539 child1->SetDrawsContent(true);
3540 child2->SetDrawsContent(true);
3541 render_surface2->SetDrawsContent(true);
3542
3543 gfx::Transform identity_matrix;
3544 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3545 gfx::PointF(), gfx::Size(100, 100), true, false,
3546 true);
3547 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3548 gfx::PointF(), gfx::Size(100, 100), true, false,
3549 true);
3550 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3551 gfx::PointF(), gfx::Size(500, 500), true, false,
3552 false);
3553 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3554 gfx::PointF(), gfx::Size(700, 700), true, false,
3555 false);
3556 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3557 gfx::PointF(), gfx::Size(1000, 1000), true,
3558 false, true);
3559
3560 child1->SetMasksToBounds(true);
3561 child2->SetMasksToBounds(true);
3562
3563 ExecuteCalculateDrawProperties(root);
3564 EXPECT_EQ(gfx::Rect(500, 500), child1->visible_layer_rect());
3565 EXPECT_EQ(gfx::Rect(100, 100), render_surface2->visible_layer_rect());
3566}
3567
3568TEST_F(LayerTreeHostCommonTest,
3569 VisibleRectsWhenClipChildIsBetweenTwoRenderSurfaces) {
3570 LayerImpl* root = root_layer();
3571 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3572 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3573 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3574 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3575
3576 render_surface1->SetDrawsContent(true);
3577 render_surface2->SetDrawsContent(true);
3578 clip_child->SetDrawsContent(true);
3579 clip_child->SetClipParent(clip_parent);
3580 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3581 clip_children->insert(clip_child);
3582 clip_parent->SetClipChildren(clip_children.release());
3583
3584 gfx::Transform identity_matrix;
3585 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3586 gfx::PointF(), gfx::Size(100, 100), true, false,
3587 true);
3588 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3589 gfx::PointF(), gfx::Size(50, 50), true, false,
3590 false);
3591 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3592 gfx::PointF(), gfx::Size(20, 20), true, false,
3593 true);
3594 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3595 gfx::PointF(), gfx::Size(60, 60), true, false,
3596 false);
3597 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3598 gfx::PointF(), gfx::Size(60, 60), true, false,
3599 true);
3600 clip_parent->SetMasksToBounds(true);
3601 render_surface1->SetMasksToBounds(true);
3602
3603 ExecuteCalculateDrawProperties(root);
3604 EXPECT_EQ(gfx::Rect(20, 20), render_surface1->visible_layer_rect());
3605 EXPECT_EQ(gfx::Rect(50, 50), clip_child->visible_layer_rect());
3606 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->visible_layer_rect());
3607}
3608
jaydasika1f5312d2015-10-21 21:34:323609TEST_F(LayerTreeHostCommonTest, ClipRectOfSurfaceWhoseParentIsAClipChild) {
3610 LayerImpl* root = root_layer();
3611 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
3612 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
3613 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
3614 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_child);
3615
3616 render_surface1->SetDrawsContent(true);
3617 render_surface2->SetDrawsContent(true);
3618 clip_child->SetDrawsContent(true);
3619 clip_child->SetClipParent(clip_parent);
3620 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3621 clip_children->insert(clip_child);
3622 clip_parent->SetClipChildren(clip_children.release());
3623
3624 gfx::Transform identity_matrix;
3625 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3626 gfx::PointF(), gfx::Size(100, 100), true, false,
3627 true);
3628 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3629 gfx::PointF(2.f, 2.f), gfx::Size(50, 50), true,
3630 false, false);
3631 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3632 gfx::PointF(), gfx::Size(20, 20), true, false,
3633 true);
3634 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3635 gfx::PointF(), gfx::Size(60, 60), true, false,
3636 false);
3637 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3638 gfx::PointF(), gfx::Size(60, 60), true, false,
3639 true);
3640 clip_parent->SetMasksToBounds(true);
3641 render_surface1->SetMasksToBounds(true);
3642
3643 ExecuteCalculateDrawProperties(root);
3644 EXPECT_EQ(gfx::Rect(50, 50), render_surface2->render_surface()->clip_rect());
3645}
3646
jaydasika77a4a072015-10-20 21:47:273647TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWhenLayerNotDrawn) {
3648 // Test that only drawn layers contribute to render surface content rect.
3649 LayerImpl* root = root_layer();
3650 LayerImpl* surface = AddChildToRoot<LayerImpl>();
3651 LayerImpl* test_layer = AddChild<LayerImpl>(surface);
3652
3653 test_layer->SetDrawsContent(false);
3654 surface->SetDrawsContent(true);
3655 gfx::Transform identity_matrix;
3656 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3657 gfx::PointF(), gfx::Size(200, 200), true, false,
3658 true);
3659 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
3660 gfx::PointF(), gfx::Size(100, 100), true, false,
3661 true);
3662 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
3663 gfx::PointF(), gfx::Size(150, 150), true, false,
3664 false);
3665
3666 ExecuteCalculateDrawProperties(root);
3667 EXPECT_EQ(gfx::Rect(100, 100), surface->render_surface()->content_rect());
3668
3669 test_layer->SetDrawsContent(true);
3670 ExecuteCalculateDrawProperties(root);
3671 EXPECT_EQ(gfx::Rect(150, 150), surface->render_surface()->content_rect());
3672}
3673
jaydasika27d0f2e2015-10-16 23:52:463674TEST_F(LayerTreeHostCommonTest, VisibleRectsMultipleSurfaces) {
3675 // Tests visible rects computation when we have unclipped_surface->
3676 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3677 // of surface_with_unclipped_descendants doesn't propagate to the
3678 // clipped_surface below it.
3679 LayerImpl* root = root_layer();
3680 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3681 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3682 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3683 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3684 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3685
3686 unclipped_surface->SetDrawsContent(true);
3687 unclipped_desc_surface->SetDrawsContent(true);
3688 clipped_surface->SetDrawsContent(true);
3689 clip_child->SetClipParent(clip_parent);
3690 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3691 clip_children->insert(clip_child);
3692 clip_parent->SetClipChildren(clip_children.release());
3693
3694 gfx::Transform identity_matrix;
3695 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3696 gfx::PointF(), gfx::Size(100, 100), true, false,
3697 true);
3698 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
3699 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
3700 true, false, true);
3701 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3702 gfx::PointF(), gfx::Size(50, 50), true, false,
3703 false);
3704 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
3705 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
3706 true, false, true);
3707 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3708 gfx::PointF(), gfx::Size(60, 60), true, false,
3709 false);
3710 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
3711 gfx::PointF(), gfx::Size(60, 60), true, false,
3712 true);
3713 clip_parent->SetMasksToBounds(true);
3714
3715 ExecuteCalculateDrawProperties(root);
3716 EXPECT_EQ(gfx::Rect(30, 30), unclipped_surface->visible_layer_rect());
3717 EXPECT_EQ(gfx::Rect(20, 20), unclipped_desc_surface->visible_layer_rect());
3718 EXPECT_EQ(gfx::Rect(50, 50), clipped_surface->visible_layer_rect());
3719}
3720
3721TEST_F(LayerTreeHostCommonTest, RootClipPropagationToClippedSurface) {
3722 // Tests visible rects computation when we have unclipped_surface->
3723 // surface_with_unclipped_descendants->clipped_surface, checks that the bounds
3724 // of root propagate to the clipped_surface.
3725 LayerImpl* root = root_layer();
3726 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
3727 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
3728 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
3729 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
3730 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
3731
3732 unclipped_surface->SetDrawsContent(true);
3733 unclipped_desc_surface->SetDrawsContent(true);
3734 clipped_surface->SetDrawsContent(true);
3735 clip_child->SetClipParent(clip_parent);
3736 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
3737 clip_children->insert(clip_child);
3738 clip_parent->SetClipChildren(clip_children.release());
3739
3740 gfx::Transform identity_matrix;
3741 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3742 gfx::PointF(), gfx::Size(10, 10), true, false,
3743 true);
3744 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
3745 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
3746 true, false, true);
3747 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
3748 gfx::PointF(), gfx::Size(50, 50), true, false,
3749 false);
3750 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
3751 gfx::Point3F(), gfx::PointF(),
3752 gfx::Size(100, 100), true, false, true);
3753 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
3754 gfx::PointF(), gfx::Size(100, 100), true, false,
3755 false);
3756 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
3757 gfx::PointF(), gfx::Size(50, 50), true, false,
3758 true);
3759 clip_parent->SetMasksToBounds(true);
3760 unclipped_desc_surface->SetMasksToBounds(true);
3761
3762 ExecuteCalculateDrawProperties(root);
3763 EXPECT_EQ(gfx::Rect(50, 50), unclipped_surface->visible_layer_rect());
3764 EXPECT_EQ(gfx::Rect(100, 100), unclipped_desc_surface->visible_layer_rect());
3765 EXPECT_EQ(gfx::Rect(10, 10), clipped_surface->visible_layer_rect());
3766}
3767
3768TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233769 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323770 // Layers that have non-axis aligned bounds (due to transforms) have an
3771 // expanded, axis-aligned DrawableContentRect and visible content rect.
weiliangc0dece732015-07-27 19:06:173772 LayerImpl* root = root_layer();
3773 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3774 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3775 child1->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283776
[email protected]fb661802013-03-25 01:59:323777 gfx::Transform identity_matrix;
3778 gfx::Transform child_rotation;
3779 child_rotation.Rotate(45.0);
weiliangc0dece732015-07-27 19:06:173780 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3781 gfx::PointF(), gfx::Size(100, 100), true, false,
3782 true);
3783 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3784 gfx::PointF(), gfx::Size(3, 4), true, false,
3785 true);
3786 SetLayerPropertiesForTesting(
3787 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
3788 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
[email protected]fb661802013-03-25 01:59:323789
weiliangc0dece732015-07-27 19:06:173790 ExecuteCalculateDrawProperties(root);
[email protected]fb661802013-03-25 01:59:323791
weiliangc0dece732015-07-27 19:06:173792 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323793
danakj5e6ff6d2015-09-05 04:43:443794 EXPECT_EQ(gfx::RectF(100.f, 100.f),
hush6b614212014-12-04 22:37:323795 root->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323796
3797 // Layers that do not draw content should have empty visible content rects.
danakj64767d902015-06-19 00:10:433798 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
weiliangc0dece732015-07-27 19:06:173799 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323800
3801 // The unclipped surface grows its DrawableContentRect to include all drawable
3802 // regions of the subtree.
3803 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3804 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263805 gfx::Rect(50 - diagonal_radius,
3806 50 - diagonal_radius,
3807 diagonal_radius * 2,
3808 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:443809 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content),
weiliangc0dece732015-07-27 19:06:173810 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323811
3812 // All layers that draw content into the unclipped surface are also unclipped.
danakj64767d902015-06-19 00:10:433813 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
hush6b614212014-12-04 22:37:323814 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323815}
3816
[email protected]989386c2013-07-18 21:37:233817TEST_F(LayerTreeHostCommonTest,
3818 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323819 // Layers that have non-axis aligned bounds (due to transforms) have an
3820 // expanded, axis-aligned DrawableContentRect and visible content rect.
weiliangc0dece732015-07-27 19:06:173821 LayerImpl* root = root_layer();
3822 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
3823 LayerImpl* child1 = AddChild<LayerImpl>(render_surface);
3824 child1->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283825
[email protected]fb661802013-03-25 01:59:323826 gfx::Transform identity_matrix;
3827 gfx::Transform child_rotation;
3828 child_rotation.Rotate(45.0);
weiliangc0dece732015-07-27 19:06:173829 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3830 gfx::PointF(), gfx::Size(50, 50), true, false,
3831 true);
3832 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
3833 gfx::PointF(), gfx::Size(3, 4), true, false,
3834 true);
[email protected]a2566412014-06-05 03:14:203835
weiliangc0dece732015-07-27 19:06:173836 SetLayerPropertiesForTesting(
3837 child1, child_rotation, gfx::Point3F(25, 25, 0.f),
3838 gfx::PointF(25.f, 25.f), gfx::Size(50, 50), true, false, false);
[email protected]fb661802013-03-25 01:59:323839
3840 root->SetMasksToBounds(true);
[email protected]fb661802013-03-25 01:59:323841
weiliangc0dece732015-07-27 19:06:173842 ExecuteCalculateDrawProperties(root);
3843
3844 ASSERT_TRUE(render_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323845
3846 // The clipped surface clamps the DrawableContentRect that encloses the
3847 // rotated layer.
3848 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263849 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3850 50 - diagonal_radius,
3851 diagonal_radius * 2,
3852 diagonal_radius * 2);
danakj5e6ff6d2015-09-05 04:43:443853 gfx::RectF expected_surface_drawable_content(
3854 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(50, 50)));
hush6b614212014-12-04 22:37:323855 EXPECT_EQ(expected_surface_drawable_content,
weiliangc0dece732015-07-27 19:06:173856 render_surface->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323857
3858 // On the clipped surface, only a quarter of the child1 is visible, but when
3859 // rotating it back to child1's content space, the actual enclosing rect ends
3860 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263861 //
3862 // Given the floating point math, this number is a little bit fuzzy.
danakj64767d902015-06-19 00:10:433863 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323864
3865 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:323866 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323867}
3868
[email protected]989386c2013-07-18 21:37:233869TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
weiliangc0dece732015-07-27 19:06:173870 LayerImpl* root = root_layer();
3871 FakePictureLayerImpl* render_surface1 =
3872 AddChildToRoot<FakePictureLayerImpl>();
3873 render_surface1->SetDrawsContent(true);
3874 FakePictureLayerImpl* render_surface2 =
3875 AddChild<FakePictureLayerImpl>(render_surface1);
3876 render_surface2->SetDrawsContent(true);
3877 FakePictureLayerImpl* child1 =
3878 AddChild<FakePictureLayerImpl>(render_surface2);
3879 child1->SetDrawsContent(true);
3880 FakePictureLayerImpl* child2 =
3881 AddChild<FakePictureLayerImpl>(render_surface2);
3882 child2->SetDrawsContent(true);
3883 FakePictureLayerImpl* child3 =
3884 AddChild<FakePictureLayerImpl>(render_surface2);
3885 child3->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:283886
[email protected]fb661802013-03-25 01:59:323887 gfx::Transform identity_matrix;
weiliangc0dece732015-07-27 19:06:173888 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
3889 gfx::PointF(), gfx::Size(100, 100), true, false,
3890 true);
3891 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
3892 gfx::PointF(5.f, 5.f), gfx::Size(3, 4), true,
3893 false, true);
3894 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
3895 gfx::PointF(5.f, 5.f), gfx::Size(7, 13), true,
3896 false, true);
3897 SetLayerPropertiesForTesting(child1, identity_matrix, gfx::Point3F(),
3898 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
3899 false, false);
3900 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
3901 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
3902 false, false);
3903 SetLayerPropertiesForTesting(child3, identity_matrix, gfx::Point3F(),
3904 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
3905 true, false, false);
[email protected]fb661802013-03-25 01:59:323906
3907 float device_scale_factor = 2.f;
3908
3909 root->SetMasksToBounds(true);
weiliangc0dece732015-07-27 19:06:173910
3911 ExecuteCalculateDrawProperties(root, device_scale_factor);
[email protected]fb661802013-03-25 01:59:323912
3913 ASSERT_TRUE(render_surface1->render_surface());
3914 ASSERT_TRUE(render_surface2->render_surface());
3915
3916 // drawable_content_rects for all layers and surfaces are scaled by
3917 // device_scale_factor.
danakj5e6ff6d2015-09-05 04:43:443918 EXPECT_EQ(gfx::RectF(200.f, 200.f),
hush6b614212014-12-04 22:37:323919 root->render_surface()->DrawableContentRect());
danakj5e6ff6d2015-09-05 04:43:443920 EXPECT_EQ(gfx::RectF(10.f, 10.f, 190.f, 190.f),
hush6b614212014-12-04 22:37:323921 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323922
3923 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3924 // is only implicitly clipped by render_surface1.
danakj5e6ff6d2015-09-05 04:43:443925 EXPECT_EQ(gfx::RectF(10.f, 10.f, 350.f, 350.f),
hush6b614212014-12-04 22:37:323926 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323927
hush6b614212014-12-04 22:37:323928 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3929 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
3930 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323931
3932 // The root layer does not actually draw content of its own.
danakj64767d902015-06-19 00:10:433933 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323934
sohan.jyotie3bd6192014-10-13 07:13:593935 // All layer visible content rects are not expressed in content space of each
3936 // layer, so they are not scaled by the device_scale_factor.
danakj64767d902015-06-19 00:10:433937 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_layer_rect());
3938 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_layer_rect());
3939 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_layer_rect());
3940 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_layer_rect());
3941 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_layer_rect());
[email protected]fb661802013-03-25 01:59:323942}
3943
[email protected]989386c2013-07-18 21:37:233944TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323945 // Verify the behavior of back-face culling when there are no preserve-3d
3946 // layers. Note that 3d transforms still apply in this case, but they are
3947 // "flattened" to each parent layer according to current W3C spec.
3948
3949 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:443950 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:323951 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
loysoa6edaaff2015-05-25 03:26:443952 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323953 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
loysoa6edaaff2015-05-25 03:26:443954 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323955 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
loysoa6edaaff2015-05-25 03:26:443956 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323957 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
loysoa6edaaff2015-05-25 03:26:443958 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323959 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233960 front_facing_child_of_front_facing_surface =
loysoa6edaaff2015-05-25 03:26:443961 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323962 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233963 back_facing_child_of_front_facing_surface =
loysoa6edaaff2015-05-25 03:26:443964 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323965 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233966 front_facing_child_of_back_facing_surface =
loysoa6edaaff2015-05-25 03:26:443967 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323968 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233969 back_facing_child_of_back_facing_surface =
loysoa6edaaff2015-05-25 03:26:443970 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323971
3972 parent->AddChild(front_facing_child);
3973 parent->AddChild(back_facing_child);
3974 parent->AddChild(front_facing_surface);
3975 parent->AddChild(back_facing_surface);
3976 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3977 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3978 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3979 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3980
ennea7b43c32015-06-18 20:01:333981 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:283982
[email protected]fb661802013-03-25 01:59:323983 // Nothing is double-sided
3984 front_facing_child->SetDoubleSided(false);
3985 back_facing_child->SetDoubleSided(false);
3986 front_facing_surface->SetDoubleSided(false);
3987 back_facing_surface->SetDoubleSided(false);
3988 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3989 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3990 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3991 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3992
3993 gfx::Transform backface_matrix;
3994 backface_matrix.Translate(50.0, 50.0);
3995 backface_matrix.RotateAboutYAxis(180.0);
3996 backface_matrix.Translate(-50.0, -50.0);
3997
3998 // Having a descendant and opacity will force these to have render surfaces.
3999 front_facing_surface->SetOpacity(0.5f);
4000 back_facing_surface->SetOpacity(0.5f);
4001
4002 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
4003 // these layers should blindly use their own local transforms to determine
4004 // back-face culling.
4005 SetLayerPropertiesForTesting(parent.get(),
4006 identity_matrix,
[email protected]a2566412014-06-05 03:14:204007 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324008 gfx::PointF(),
4009 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574010 true,
[email protected]fb661802013-03-25 01:59:324011 false);
4012 SetLayerPropertiesForTesting(front_facing_child.get(),
4013 identity_matrix,
[email protected]a2566412014-06-05 03:14:204014 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324015 gfx::PointF(),
4016 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574017 true,
[email protected]fb661802013-03-25 01:59:324018 false);
4019 SetLayerPropertiesForTesting(back_facing_child.get(),
4020 backface_matrix,
[email protected]a2566412014-06-05 03:14:204021 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324022 gfx::PointF(),
4023 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574024 true,
[email protected]fb661802013-03-25 01:59:324025 false);
4026 SetLayerPropertiesForTesting(front_facing_surface.get(),
4027 identity_matrix,
[email protected]a2566412014-06-05 03:14:204028 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324029 gfx::PointF(),
4030 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574031 true,
[email protected]fb661802013-03-25 01:59:324032 false);
4033 SetLayerPropertiesForTesting(back_facing_surface.get(),
4034 backface_matrix,
[email protected]a2566412014-06-05 03:14:204035 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324036 gfx::PointF(),
4037 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574038 true,
[email protected]fb661802013-03-25 01:59:324039 false);
4040 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
4041 identity_matrix,
[email protected]a2566412014-06-05 03:14:204042 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324043 gfx::PointF(),
4044 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574045 true,
[email protected]fb661802013-03-25 01:59:324046 false);
4047 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
4048 backface_matrix,
[email protected]a2566412014-06-05 03:14:204049 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324050 gfx::PointF(),
4051 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574052 true,
[email protected]fb661802013-03-25 01:59:324053 false);
4054 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
4055 identity_matrix,
[email protected]a2566412014-06-05 03:14:204056 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324057 gfx::PointF(),
4058 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574059 true,
[email protected]fb661802013-03-25 01:59:324060 false);
4061 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
4062 backface_matrix,
[email protected]a2566412014-06-05 03:14:204063 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324064 gfx::PointF(),
4065 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574066 true,
[email protected]fb661802013-03-25 01:59:324067 false);
4068
enne7b2a2172015-07-14 00:04:534069 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
[email protected]fb661802013-03-25 01:59:324070
4071 // Verify which render surfaces were created.
ennec1332992015-08-24 19:45:094072 EXPECT_FALSE(front_facing_child->has_render_surface());
4073 EXPECT_FALSE(back_facing_child->has_render_surface());
4074 EXPECT_TRUE(front_facing_surface->has_render_surface());
4075 EXPECT_TRUE(back_facing_surface->has_render_surface());
4076 EXPECT_FALSE(
4077 front_facing_child_of_front_facing_surface->has_render_surface());
4078 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4079 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4080 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324081
enne7b2a2172015-07-14 00:04:534082 EXPECT_EQ(4u, update_layer_list().size());
4083 EXPECT_TRUE(UpdateLayerListContains(front_facing_child->id()));
4084 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
4085 EXPECT_TRUE(UpdateLayerListContains(
4086 front_facing_child_of_front_facing_surface->id()));
4087 EXPECT_TRUE(
4088 UpdateLayerListContains(front_facing_child_of_back_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324089}
4090
[email protected]989386c2013-07-18 21:37:234091TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:324092 // Verify the behavior of back-face culling when preserves-3d transform style
4093 // is used.
4094
4095 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:444096 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:324097 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
loysoa6edaaff2015-05-25 03:26:444098 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324099 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
loysoa6edaaff2015-05-25 03:26:444100 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324101 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
loysoa6edaaff2015-05-25 03:26:444102 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324103 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
loysoa6edaaff2015-05-25 03:26:444104 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324105 scoped_refptr<LayerWithForcedDrawsContent>
loysoa6edaaff2015-05-25 03:26:444106 front_facing_child_of_front_facing_surface =
4107 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324108 scoped_refptr<LayerWithForcedDrawsContent>
loysoa6edaaff2015-05-25 03:26:444109 back_facing_child_of_front_facing_surface =
4110 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324111 scoped_refptr<LayerWithForcedDrawsContent>
loysoa6edaaff2015-05-25 03:26:444112 front_facing_child_of_back_facing_surface =
4113 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324114 scoped_refptr<LayerWithForcedDrawsContent>
loysoa6edaaff2015-05-25 03:26:444115 back_facing_child_of_back_facing_surface =
4116 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324117 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
loysoa6edaaff2015-05-25 03:26:444118 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324119 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
loysoa6edaaff2015-05-25 03:26:444120 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324121
4122 parent->AddChild(front_facing_child);
4123 parent->AddChild(back_facing_child);
4124 parent->AddChild(front_facing_surface);
4125 parent->AddChild(back_facing_surface);
4126 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
4127 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
4128 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
4129 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
4130
ennea7b43c32015-06-18 20:01:334131 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:284132
[email protected]fb661802013-03-25 01:59:324133 // Nothing is double-sided
4134 front_facing_child->SetDoubleSided(false);
4135 back_facing_child->SetDoubleSided(false);
4136 front_facing_surface->SetDoubleSided(false);
4137 back_facing_surface->SetDoubleSided(false);
4138 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
4139 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
4140 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
4141 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
4142
4143 gfx::Transform backface_matrix;
4144 backface_matrix.Translate(50.0, 50.0);
4145 backface_matrix.RotateAboutYAxis(180.0);
4146 backface_matrix.Translate(-50.0, -50.0);
4147
4148 // Opacity will not force creation of render surfaces in this case because of
4149 // the preserve-3d transform style. Instead, an example of when a surface
4150 // would be created with preserve-3d is when there is a replica layer.
4151 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
4152 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
4153
4154 // Each surface creates its own new 3d rendering context (as defined by W3C
4155 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
4156 // rendering context should use the transform with respect to that context.
4157 // This 3d rendering context occurs when (a) parent's transform style is flat
4158 // and (b) the layer's transform style is preserve-3d.
4159 SetLayerPropertiesForTesting(parent.get(),
4160 identity_matrix,
[email protected]a2566412014-06-05 03:14:204161 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324162 gfx::PointF(),
4163 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574164 true,
[email protected]fb661802013-03-25 01:59:324165 false); // parent transform style is flat.
4166 SetLayerPropertiesForTesting(front_facing_child.get(),
4167 identity_matrix,
[email protected]a2566412014-06-05 03:14:204168 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324169 gfx::PointF(),
4170 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574171 true,
[email protected]fb661802013-03-25 01:59:324172 false);
4173 SetLayerPropertiesForTesting(back_facing_child.get(),
4174 backface_matrix,
[email protected]a2566412014-06-05 03:14:204175 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324176 gfx::PointF(),
4177 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574178 true,
[email protected]fb661802013-03-25 01:59:324179 false);
[email protected]56fffdd2014-02-11 19:50:574180 // surface transform style is preserve-3d.
4181 SetLayerPropertiesForTesting(front_facing_surface.get(),
4182 identity_matrix,
[email protected]a2566412014-06-05 03:14:204183 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:574184 gfx::PointF(),
4185 gfx::Size(100, 100),
4186 false,
4187 true);
4188 // surface transform style is preserve-3d.
4189 SetLayerPropertiesForTesting(back_facing_surface.get(),
4190 backface_matrix,
[email protected]a2566412014-06-05 03:14:204191 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:574192 gfx::PointF(),
4193 gfx::Size(100, 100),
4194 false,
4195 true);
[email protected]fb661802013-03-25 01:59:324196 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
4197 identity_matrix,
[email protected]a2566412014-06-05 03:14:204198 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324199 gfx::PointF(),
4200 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574201 true,
4202 true);
[email protected]fb661802013-03-25 01:59:324203 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
4204 backface_matrix,
[email protected]a2566412014-06-05 03:14:204205 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324206 gfx::PointF(),
4207 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574208 true,
4209 true);
[email protected]fb661802013-03-25 01:59:324210 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
4211 identity_matrix,
[email protected]a2566412014-06-05 03:14:204212 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324213 gfx::PointF(),
4214 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574215 true,
4216 true);
[email protected]fb661802013-03-25 01:59:324217 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
4218 backface_matrix,
[email protected]a2566412014-06-05 03:14:204219 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324220 gfx::PointF(),
4221 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574222 true,
4223 true);
[email protected]fb661802013-03-25 01:59:324224
enne7b2a2172015-07-14 00:04:534225 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
[email protected]fb661802013-03-25 01:59:324226
awoloszyne83f28c2014-12-22 15:40:004227 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094228 EXPECT_FALSE(front_facing_child->has_render_surface());
4229 EXPECT_FALSE(back_facing_child->has_render_surface());
4230 EXPECT_TRUE(front_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094231 // We expect that a has_render_surface was created but not used.
4232 EXPECT_TRUE(back_facing_surface->has_render_surface());
4233 EXPECT_FALSE(
4234 front_facing_child_of_front_facing_surface->has_render_surface());
4235 EXPECT_FALSE(back_facing_child_of_front_facing_surface->has_render_surface());
4236 EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface());
4237 EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface());
[email protected]fb661802013-03-25 01:59:324238
enne7b2a2172015-07-14 00:04:534239 EXPECT_EQ(3u, update_layer_list().size());
[email protected]fb661802013-03-25 01:59:324240
enne7b2a2172015-07-14 00:04:534241 EXPECT_TRUE(UpdateLayerListContains(front_facing_child->id()));
4242 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
4243 EXPECT_TRUE(UpdateLayerListContains(
4244 front_facing_child_of_front_facing_surface->id()));
[email protected]fb661802013-03-25 01:59:324245}
4246
[email protected]989386c2013-07-18 21:37:234247TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:324248 // Verify that layers are appropriately culled when their back face is showing
4249 // and they are not double sided, while animations are going on.
4250 //
4251 // Layers that are animating do not get culled on the main thread, as their
4252 // transforms should be treated as "unknown" so we can not be sure that their
4253 // back face is really showing.
4254 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:444255 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:324256 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:444257 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324258 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
loysoa6edaaff2015-05-25 03:26:444259 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324260 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
loysoa6edaaff2015-05-25 03:26:444261 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324262 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
loysoa6edaaff2015-05-25 03:26:444263 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324264 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loysoa6edaaff2015-05-25 03:26:444265 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324266
4267 parent->AddChild(child);
4268 parent->AddChild(animating_surface);
4269 animating_surface->AddChild(child_of_animating_surface);
4270 parent->AddChild(animating_child);
4271 parent->AddChild(child2);
4272
ennea7b43c32015-06-18 20:01:334273 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:284274
[email protected]fb661802013-03-25 01:59:324275 // Nothing is double-sided
4276 child->SetDoubleSided(false);
4277 child2->SetDoubleSided(false);
4278 animating_surface->SetDoubleSided(false);
4279 child_of_animating_surface->SetDoubleSided(false);
4280 animating_child->SetDoubleSided(false);
4281
4282 gfx::Transform backface_matrix;
4283 backface_matrix.Translate(50.0, 50.0);
4284 backface_matrix.RotateAboutYAxis(180.0);
4285 backface_matrix.Translate(-50.0, -50.0);
4286
4287 // Make our render surface.
4288 animating_surface->SetForceRenderSurface(true);
4289
4290 // Animate the transform on the render surface.
4291 AddAnimatedTransformToController(
4292 animating_surface->layer_animation_controller(), 10.0, 30, 0);
4293 // This is just an animating layer, not a surface.
4294 AddAnimatedTransformToController(
4295 animating_child->layer_animation_controller(), 10.0, 30, 0);
4296
4297 SetLayerPropertiesForTesting(parent.get(),
4298 identity_matrix,
[email protected]a2566412014-06-05 03:14:204299 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324300 gfx::PointF(),
4301 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574302 true,
[email protected]fb661802013-03-25 01:59:324303 false);
4304 SetLayerPropertiesForTesting(child.get(),
4305 backface_matrix,
[email protected]a2566412014-06-05 03:14:204306 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324307 gfx::PointF(),
4308 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574309 true,
[email protected]fb661802013-03-25 01:59:324310 false);
4311 SetLayerPropertiesForTesting(animating_surface.get(),
4312 backface_matrix,
[email protected]a2566412014-06-05 03:14:204313 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324314 gfx::PointF(),
4315 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574316 true,
[email protected]fb661802013-03-25 01:59:324317 false);
4318 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
4319 backface_matrix,
[email protected]a2566412014-06-05 03:14:204320 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324321 gfx::PointF(),
4322 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574323 true,
[email protected]fb661802013-03-25 01:59:324324 false);
4325 SetLayerPropertiesForTesting(animating_child.get(),
4326 backface_matrix,
[email protected]a2566412014-06-05 03:14:204327 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324328 gfx::PointF(),
4329 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574330 true,
[email protected]fb661802013-03-25 01:59:324331 false);
4332 SetLayerPropertiesForTesting(child2.get(),
4333 identity_matrix,
[email protected]a2566412014-06-05 03:14:204334 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324335 gfx::PointF(),
4336 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574337 true,
[email protected]fb661802013-03-25 01:59:324338 false);
4339
enne1e1008c2015-08-21 00:45:464340 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(parent.get(),
4341 parent->bounds());
[email protected]7aad55f2013-07-26 11:25:534342 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324343
ennec1332992015-08-24 19:45:094344 EXPECT_FALSE(child->has_render_surface());
4345 EXPECT_TRUE(animating_surface->has_render_surface());
4346 EXPECT_FALSE(child_of_animating_surface->has_render_surface());
4347 EXPECT_FALSE(animating_child->has_render_surface());
4348 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324349
enne7b2a2172015-07-14 00:04:534350 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
4351
4352 EXPECT_EQ(4u, update_layer_list().size());
[email protected]fb661802013-03-25 01:59:324353
4354 // The non-animating child be culled from the layer list for the parent render
4355 // surface.
enne7b2a2172015-07-14 00:04:534356 EXPECT_TRUE(UpdateLayerListContains(animating_surface->id()));
4357 EXPECT_TRUE(UpdateLayerListContains(animating_child->id()));
4358 EXPECT_TRUE(UpdateLayerListContains(child2->id()));
4359 EXPECT_TRUE(UpdateLayerListContains(child_of_animating_surface->id()));
[email protected]fb661802013-03-25 01:59:324360
enne7b2a2172015-07-14 00:04:534361 EXPECT_FALSE(child2->visible_rect_from_property_trees().IsEmpty());
[email protected]fb661802013-03-25 01:59:324362
4363 // The animating layers should have a visible content rect that represents the
4364 // area of the front face that is within the viewport.
enne7b2a2172015-07-14 00:04:534365 EXPECT_EQ(animating_child->visible_rect_from_property_trees(),
Dana Jansensc46d3742015-06-18 01:33:144366 gfx::Rect(animating_child->bounds()));
enne7b2a2172015-07-14 00:04:534367 EXPECT_EQ(animating_surface->visible_rect_from_property_trees(),
Dana Jansensc46d3742015-06-18 01:33:144368 gfx::Rect(animating_surface->bounds()));
[email protected]fb661802013-03-25 01:59:324369 // And layers in the subtree of the animating layer should have valid visible
4370 // content rects also.
enne7b2a2172015-07-14 00:04:534371 EXPECT_EQ(child_of_animating_surface->visible_rect_from_property_trees(),
Dana Jansensc46d3742015-06-18 01:33:144372 gfx::Rect(child_of_animating_surface->bounds()));
[email protected]fb661802013-03-25 01:59:324373}
4374
[email protected]989386c2013-07-18 21:37:234375TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324376 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4377 // Verify the behavior of back-face culling for a render surface that is
4378 // created when it flattens its subtree, and its parent has preserves-3d.
4379
4380 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:444381 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:324382 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
loysoa6edaaff2015-05-25 03:26:444383 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324384 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
loysoa6edaaff2015-05-25 03:26:444385 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324386 scoped_refptr<LayerWithForcedDrawsContent> child1 =
loysoa6edaaff2015-05-25 03:26:444387 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324388 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loysoa6edaaff2015-05-25 03:26:444389 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324390
4391 parent->AddChild(front_facing_surface);
4392 parent->AddChild(back_facing_surface);
4393 front_facing_surface->AddChild(child1);
4394 back_facing_surface->AddChild(child2);
4395
ennea7b43c32015-06-18 20:01:334396 host()->SetRootLayer(parent);
[email protected]d600df7d2013-08-03 02:34:284397
[email protected]fb661802013-03-25 01:59:324398 // RenderSurfaces are not double-sided
4399 front_facing_surface->SetDoubleSided(false);
4400 back_facing_surface->SetDoubleSided(false);
4401
4402 gfx::Transform backface_matrix;
4403 backface_matrix.Translate(50.0, 50.0);
4404 backface_matrix.RotateAboutYAxis(180.0);
4405 backface_matrix.Translate(-50.0, -50.0);
4406
4407 SetLayerPropertiesForTesting(parent.get(),
4408 identity_matrix,
[email protected]a2566412014-06-05 03:14:204409 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324410 gfx::PointF(),
4411 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574412 false,
4413 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:324414 SetLayerPropertiesForTesting(front_facing_surface.get(),
4415 identity_matrix,
[email protected]a2566412014-06-05 03:14:204416 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324417 gfx::PointF(),
4418 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574419 true,
4420 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324421 SetLayerPropertiesForTesting(back_facing_surface.get(),
4422 backface_matrix,
[email protected]a2566412014-06-05 03:14:204423 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324424 gfx::PointF(),
4425 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574426 true,
4427 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324428 SetLayerPropertiesForTesting(child1.get(),
4429 identity_matrix,
[email protected]a2566412014-06-05 03:14:204430 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324431 gfx::PointF(),
4432 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574433 true,
[email protected]fb661802013-03-25 01:59:324434 false);
4435 SetLayerPropertiesForTesting(child2.get(),
4436 identity_matrix,
[email protected]a2566412014-06-05 03:14:204437 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324438 gfx::PointF(),
4439 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574440 true,
[email protected]fb661802013-03-25 01:59:324441 false);
4442
[email protected]a9d4d4f2014-06-19 06:49:284443 front_facing_surface->Set3dSortingContextId(1);
4444 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574445
enne7b2a2172015-07-14 00:04:534446 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
[email protected]fb661802013-03-25 01:59:324447
awoloszyne83f28c2014-12-22 15:40:004448 // Verify which render surfaces were created and used.
ennec1332992015-08-24 19:45:094449 EXPECT_TRUE(front_facing_surface->has_render_surface());
awoloszyne83f28c2014-12-22 15:40:004450
4451 // We expect the render surface to have been created, but remain unused.
ennec1332992015-08-24 19:45:094452 EXPECT_TRUE(back_facing_surface->has_render_surface());
ennec1332992015-08-24 19:45:094453 EXPECT_FALSE(child1->has_render_surface());
4454 EXPECT_FALSE(child2->has_render_surface());
[email protected]fb661802013-03-25 01:59:324455
enne7b2a2172015-07-14 00:04:534456 EXPECT_EQ(2u, update_layer_list().size());
4457 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
4458 EXPECT_TRUE(UpdateLayerListContains(child1->id()));
[email protected]fb661802013-03-25 01:59:324459}
4460
enne637715732015-07-07 02:05:264461TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324462 // Verify draw and screen space transforms of layers not in a surface.
[email protected]fb661802013-03-25 01:59:324463 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:144464
enne637715732015-07-07 02:05:264465 LayerImpl* parent = root_layer();
jaydasika8640f9f2015-11-10 01:34:364466 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264467 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4468 gfx::PointF(), gfx::Size(100, 100), false, true,
[email protected]fb661802013-03-25 01:59:324469 true);
[email protected]94f206c12012-08-25 00:09:144470
enne637715732015-07-07 02:05:264471 LayerImpl* child = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364472 child->SetDrawsContent(true);
enne637715732015-07-07 02:05:264473 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4474 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4475 true, false);
[email protected]94f206c12012-08-25 00:09:144476
jaydasika8640f9f2015-11-10 01:34:364477 LayerImpl* child2 = AddChildToRoot<LayerImpl>();
4478 child2->SetDrawsContent(true);
4479 SetLayerPropertiesForTesting(child2, identity_matrix, gfx::Point3F(),
4480 gfx::PointF(2.f, 2.f), gfx::Size(5, 5), false,
4481 true, false);
[email protected]d600df7d2013-08-03 02:34:284482
[email protected]fb661802013-03-25 01:59:324483 float device_scale_factor = 2.5f;
enne637715732015-07-07 02:05:264484 gfx::Size viewport_size(100, 100);
4485 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144486
enne637715732015-07-07 02:05:264487 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, parent);
4488 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child);
jaydasika8640f9f2015-11-10 01:34:364489 EXPECT_IDEAL_SCALE_EQ(device_scale_factor, child2);
[email protected]518ee582012-10-24 18:29:444490
enne637715732015-07-07 02:05:264491 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144492
[email protected]fb661802013-03-25 01:59:324493 // Verify parent transforms
4494 gfx::Transform expected_parent_transform;
enne637715732015-07-07 02:05:264495 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324496 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4497 parent->screen_space_transform());
4498 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444499 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144500
[email protected]fb661802013-03-25 01:59:324501 // Verify results of transformed parent rects
danakjddaec912015-09-25 19:38:404502 gfx::RectF parent_bounds(gfx::SizeF(parent->bounds()));
[email protected]94f206c12012-08-25 00:09:144503
[email protected]fb661802013-03-25 01:59:324504 gfx::RectF parent_draw_rect =
ajumad9432e32015-11-30 19:43:444505 MathUtil::MapClippedRect(parent->DrawTransform(), parent_bounds);
Dana Jansensc46d3742015-06-18 01:33:144506 gfx::RectF parent_screen_space_rect =
4507 MathUtil::MapClippedRect(parent->screen_space_transform(), parent_bounds);
[email protected]94f206c12012-08-25 00:09:144508
danakjddaec912015-09-25 19:38:404509 gfx::RectF expected_parent_draw_rect(gfx::SizeF(parent->bounds()));
[email protected]fb661802013-03-25 01:59:324510 expected_parent_draw_rect.Scale(device_scale_factor);
4511 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4512 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144513
jaydasika8640f9f2015-11-10 01:34:364514 // Verify child and child2 transforms. They should match.
[email protected]fb661802013-03-25 01:59:324515 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594516 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4517 expected_child_transform.Translate(child->position().x(),
4518 child->position().y());
[email protected]fb661802013-03-25 01:59:324519 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444520 child->DrawTransform());
[email protected]fb661802013-03-25 01:59:324521 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4522 child->screen_space_transform());
4523 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
ajumad9432e32015-11-30 19:43:444524 child2->DrawTransform());
[email protected]fb661802013-03-25 01:59:324525 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
jaydasika8640f9f2015-11-10 01:34:364526 child2->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144527
jaydasika8640f9f2015-11-10 01:34:364528 // Verify results of transformed child and child2 rects. They should
[email protected]fb661802013-03-25 01:59:324529 // match.
danakjddaec912015-09-25 19:38:404530 gfx::RectF child_bounds(gfx::SizeF(child->bounds()));
[email protected]94f206c12012-08-25 00:09:144531
[email protected]fb661802013-03-25 01:59:324532 gfx::RectF child_draw_rect =
ajumad9432e32015-11-30 19:43:444533 MathUtil::MapClippedRect(child->DrawTransform(), child_bounds);
Dana Jansensc46d3742015-06-18 01:33:144534 gfx::RectF child_screen_space_rect =
4535 MathUtil::MapClippedRect(child->screen_space_transform(), child_bounds);
[email protected]94f206c12012-08-25 00:09:144536
jaydasika8640f9f2015-11-10 01:34:364537 gfx::RectF child2_draw_rect =
ajumad9432e32015-11-30 19:43:444538 MathUtil::MapClippedRect(child2->DrawTransform(), child_bounds);
jaydasika8640f9f2015-11-10 01:34:364539 gfx::RectF child2_screen_space_rect =
4540 MathUtil::MapClippedRect(child2->screen_space_transform(), child_bounds);
[email protected]f89f5632012-11-14 23:34:454541
danakjddaec912015-09-25 19:38:404542 gfx::RectF expected_child_draw_rect(child->position(),
4543 gfx::SizeF(child->bounds()));
[email protected]fb661802013-03-25 01:59:324544 expected_child_draw_rect.Scale(device_scale_factor);
4545 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4546 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
jaydasika8640f9f2015-11-10 01:34:364547 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_draw_rect);
4548 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child2_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144549}
4550
enne637715732015-07-07 02:05:264551TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324552 // Verify draw and screen space transforms of layers in a surface.
[email protected]fb661802013-03-25 01:59:324553 gfx::Transform identity_matrix;
[email protected]fb661802013-03-25 01:59:324554 gfx::Transform perspective_matrix;
4555 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094556
[email protected]fb661802013-03-25 01:59:324557 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054558 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094559
enne637715732015-07-07 02:05:264560 LayerImpl* root = root_layer();
4561 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
4562 gfx::PointF(), gfx::Size(100, 100), false, true,
4563 false);
4564 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364565 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264566 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4567 gfx::PointF(), gfx::Size(100, 100), false, true,
4568 false);
[email protected]9781afa2013-07-17 23:15:324569
enne637715732015-07-07 02:05:264570 LayerImpl* perspective_surface = AddChild<LayerImpl>(parent);
4571 SetLayerPropertiesForTesting(perspective_surface,
[email protected]fb661802013-03-25 01:59:324572 perspective_matrix * scale_small_matrix,
enne637715732015-07-07 02:05:264573 gfx::Point3F(), gfx::PointF(2.f, 2.f),
4574 gfx::Size(10, 10), false, true, true);
4575 perspective_surface->SetDrawsContent(true);
[email protected]1b30e8e2012-12-21 02:59:094576
enne637715732015-07-07 02:05:264577 LayerImpl* scale_surface = AddChild<LayerImpl>(parent);
4578 SetLayerPropertiesForTesting(scale_surface, scale_small_matrix,
4579 gfx::Point3F(), gfx::PointF(2.f, 2.f),
4580 gfx::Size(10, 10), false, true, true);
4581 scale_surface->SetDrawsContent(true);
[email protected]d600df7d2013-08-03 02:34:284582
[email protected]fb661802013-03-25 01:59:324583 float device_scale_factor = 2.5f;
4584 float page_scale_factor = 3.f;
enne637715732015-07-07 02:05:264585 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4586 root);
[email protected]1b30e8e2012-12-21 02:59:094587
sohan.jyotie3bd6192014-10-13 07:13:594588 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4589 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
4590 perspective_surface);
4591 // Ideal scale is the max 2d scale component of the combined transform up to
4592 // the nearest render target. Here this includes the layer transform as well
4593 // as the device and page scale factors.
4594 gfx::Transform transform = scale_small_matrix;
4595 transform.Scale(device_scale_factor * page_scale_factor,
4596 device_scale_factor * page_scale_factor);
4597 gfx::Vector2dF scales =
4598 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4599 float max_2d_scale = std::max(scales.x(), scales.y());
4600 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
4601
4602 // The ideal scale will draw 1:1 with its render target space along
4603 // the larger-scale axis.
4604 gfx::Vector2dF target_space_transform_scales =
4605 MathUtil::ComputeTransform2dScaleComponents(
4606 scale_surface->draw_properties().target_space_transform, 0.f);
4607 EXPECT_FLOAT_EQ(max_2d_scale,
4608 std::max(target_space_transform_scales.x(),
4609 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094610
enne637715732015-07-07 02:05:264611 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]1b30e8e2012-12-21 02:59:094612
[email protected]fb661802013-03-25 01:59:324613 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594614 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4615 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324616 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
ajumad9432e32015-11-30 19:43:444617 parent->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094618
[email protected]fb661802013-03-25 01:59:324619 // The scale for the perspective surface is not known, so it is rendered 1:1
4620 // with the screen, and then scaled during drawing.
4621 gfx::Transform expected_perspective_surface_draw_transform;
4622 expected_perspective_surface_draw_transform.Translate(
4623 device_scale_factor * page_scale_factor *
4624 perspective_surface->position().x(),
4625 device_scale_factor * page_scale_factor *
4626 perspective_surface->position().y());
4627 expected_perspective_surface_draw_transform.PreconcatTransform(
4628 perspective_matrix);
4629 expected_perspective_surface_draw_transform.PreconcatTransform(
4630 scale_small_matrix);
4631 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594632 expected_perspective_surface_layer_draw_transform.Scale(
4633 device_scale_factor * page_scale_factor,
4634 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324635 EXPECT_TRANSFORMATION_MATRIX_EQ(
4636 expected_perspective_surface_draw_transform,
4637 perspective_surface->render_surface()->draw_transform());
4638 EXPECT_TRANSFORMATION_MATRIX_EQ(
4639 expected_perspective_surface_layer_draw_transform,
ajumad9432e32015-11-30 19:43:444640 perspective_surface->DrawTransform());
[email protected]1b30e8e2012-12-21 02:59:094641}
4642
enne637715732015-07-07 02:05:264643TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294644 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264645 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294646 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4647
4648 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264649 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294650 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4651
enne637715732015-07-07 02:05:264652 LayerImpl* root = root_layer();
[email protected]35a99a12013-05-09 23:52:294653 root->SetBounds(gfx::Size(100, 100));
4654
enne637715732015-07-07 02:05:264655 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364656 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264657 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4658 gfx::PointF(), gfx::Size(100, 100), false, true,
4659 false);
[email protected]35a99a12013-05-09 23:52:294660
enne637715732015-07-07 02:05:264661 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:364662 child_scale->SetDrawsContent(true);
enne637715732015-07-07 02:05:264663 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4664 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4665 true, false);
[email protected]d600df7d2013-08-03 02:34:284666
[email protected]fb661802013-03-25 01:59:324667 float device_scale_factor = 2.5f;
4668 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214669
[email protected]989386c2013-07-18 21:37:234670 {
enne637715732015-07-07 02:05:264671 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor,
4672 root);
[email protected]11ec92972012-11-10 03:06:214673
sohan.jyotie3bd6192014-10-13 07:13:594674 // The ideal scale is able to go below 1.
4675 float expected_ideal_scale =
4676 device_scale_factor * page_scale_factor * initial_parent_scale;
4677 EXPECT_LT(expected_ideal_scale, 1.f);
4678 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
[email protected]11ec92972012-11-10 03:06:214679
sohan.jyotie3bd6192014-10-13 07:13:594680 expected_ideal_scale = device_scale_factor * page_scale_factor *
4681 initial_parent_scale * initial_child_scale;
4682 EXPECT_LT(expected_ideal_scale, 1.f);
4683 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
[email protected]989386c2013-07-18 21:37:234684 }
[email protected]11ec92972012-11-10 03:06:214685}
4686
enne637715732015-07-07 02:05:264687TEST_F(LayerTreeHostCommonScalingTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:324688 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264689 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324690 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:264691
[email protected]fb661802013-03-25 01:59:324692 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264693 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324694 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:264695
enne637715732015-07-07 02:05:264696 LayerImpl* root = root_layer();
[email protected]35a99a12013-05-09 23:52:294697 root->SetBounds(gfx::Size(100, 100));
4698
enne637715732015-07-07 02:05:264699 LayerImpl* parent = AddChildToRoot<LayerImpl>();
jaydasika8640f9f2015-11-10 01:34:364700 parent->SetDrawsContent(true);
enne637715732015-07-07 02:05:264701 SetLayerPropertiesForTesting(parent, parent_scale_matrix, gfx::Point3F(),
4702 gfx::PointF(), gfx::Size(100, 100), false, true,
4703 false);
[email protected]6a9cff92012-11-08 11:53:264704
enne637715732015-07-07 02:05:264705 LayerImpl* child_scale = AddChild<LayerImpl>(parent);
jaydasika8640f9f2015-11-10 01:34:364706 child_scale->SetDrawsContent(true);
enne637715732015-07-07 02:05:264707 SetLayerPropertiesForTesting(child_scale, child_scale_matrix, gfx::Point3F(),
4708 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4709 true, false);
[email protected]d600df7d2013-08-03 02:34:284710
[email protected]989386c2013-07-18 21:37:234711 {
enne637715732015-07-07 02:05:264712 ExecuteCalculateDrawProperties(root);
[email protected]6a9cff92012-11-08 11:53:264713
sohan.jyotie3bd6192014-10-13 07:13:594714 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
4715 // Animating layers compute ideal scale in the same way as when
4716 // they are static.
4717 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
4718 child_scale);
[email protected]989386c2013-07-18 21:37:234719 }
[email protected]6a9cff92012-11-08 11:53:264720}
4721
[email protected]989386c2013-07-18 21:37:234722TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324723 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:264724
enneea850232015-07-27 16:43:124725 LayerImpl* parent = root_layer();
4726 parent->SetDrawsContent(true);
4727 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4728 gfx::PointF(), gfx::Size(30, 30), false, true,
[email protected]fb661802013-03-25 01:59:324729 true);
[email protected]94f206c12012-08-25 00:09:144730
enneea850232015-07-27 16:43:124731 LayerImpl* child = AddChildToRoot<LayerImpl>();
4732 child->SetDrawsContent(true);
4733 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4734 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4735 true, true);
[email protected]94f206c12012-08-25 00:09:144736
[email protected]fb661802013-03-25 01:59:324737 gfx::Transform replica_transform;
4738 replica_transform.Scale(1.0, -1.0);
enneea850232015-07-27 16:43:124739
4740 scoped_ptr<LayerImpl> replica =
4741 LayerImpl::Create(host_impl()->active_tree(), 7);
4742 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
4743 gfx::PointF(2.f, 2.f), gfx::Size(10, 10), false,
4744 true, false);
danakja04855a2015-11-18 20:39:104745 child->SetReplicaLayer(std::move(replica));
[email protected]94f206c12012-08-25 00:09:144746
[email protected]fb661802013-03-25 01:59:324747 // This layer should end up in the same surface as child, with the same draw
4748 // and screen space transforms.
enneea850232015-07-27 16:43:124749 LayerImpl* duplicate_child_non_owner = AddChild<LayerImpl>(child);
4750 duplicate_child_non_owner->SetDrawsContent(true);
4751 SetLayerPropertiesForTesting(duplicate_child_non_owner, identity_matrix,
4752 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4753 false, true, false);
[email protected]94f206c12012-08-25 00:09:144754
[email protected]fb661802013-03-25 01:59:324755 float device_scale_factor = 1.5f;
enneea850232015-07-27 16:43:124756 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]94f206c12012-08-25 00:09:144757
[email protected]fb661802013-03-25 01:59:324758 // We should have two render surfaces. The root's render surface and child's
4759 // render surface (it needs one because it has a replica layer).
enneea850232015-07-27 16:43:124760 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]94f206c12012-08-25 00:09:144761
[email protected]fb661802013-03-25 01:59:324762 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594763 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324764 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4765 parent->screen_space_transform());
4766 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
ajumad9432e32015-11-30 19:43:444767 parent->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144768
[email protected]fb661802013-03-25 01:59:324769 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594770 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:324771 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
ajumad9432e32015-11-30 19:43:444772 child->DrawTransform());
[email protected]94f206c12012-08-25 00:09:144773
[email protected]fb661802013-03-25 01:59:324774 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:594775 expected_screen_space_transform.Scale(device_scale_factor,
4776 device_scale_factor);
4777 expected_screen_space_transform.Translate(child->position().x(),
4778 child->position().y());
[email protected]fb661802013-03-25 01:59:324779 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
4780 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144781
[email protected]fb661802013-03-25 01:59:324782 gfx::Transform expected_duplicate_child_draw_transform =
ajumad9432e32015-11-30 19:43:444783 child->DrawTransform();
4784 EXPECT_TRANSFORMATION_MATRIX_EQ(child->DrawTransform(),
4785 duplicate_child_non_owner->DrawTransform());
[email protected]fb661802013-03-25 01:59:324786 EXPECT_TRANSFORMATION_MATRIX_EQ(
4787 child->screen_space_transform(),
4788 duplicate_child_non_owner->screen_space_transform());
hush6b614212014-12-04 22:37:324789 EXPECT_EQ(child->drawable_content_rect(),
4790 duplicate_child_non_owner->drawable_content_rect());
Dana Jansensc46d3742015-06-18 01:33:144791 EXPECT_EQ(child->bounds(), duplicate_child_non_owner->bounds());
[email protected]94f206c12012-08-25 00:09:144792
[email protected]fb661802013-03-25 01:59:324793 gfx::Transform expected_render_surface_draw_transform;
4794 expected_render_surface_draw_transform.Translate(
4795 device_scale_factor * child->position().x(),
4796 device_scale_factor * child->position().y());
4797 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
4798 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144799
[email protected]fb661802013-03-25 01:59:324800 gfx::Transform expected_surface_draw_transform;
4801 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
4802 device_scale_factor * 2.f);
4803 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
4804 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:144805
[email protected]fb661802013-03-25 01:59:324806 gfx::Transform expected_surface_screen_space_transform;
4807 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
4808 device_scale_factor * 2.f);
4809 EXPECT_TRANSFORMATION_MATRIX_EQ(
4810 expected_surface_screen_space_transform,
4811 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144812
[email protected]fb661802013-03-25 01:59:324813 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:264814 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
4815 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
4816 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:324817 EXPECT_TRANSFORMATION_MATRIX_EQ(
4818 expected_replica_draw_transform,
4819 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:144820
[email protected]fb661802013-03-25 01:59:324821 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:264822 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
4823 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
4824 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:324825 EXPECT_TRANSFORMATION_MATRIX_EQ(
4826 expected_replica_screen_space_transform,
4827 child->render_surface()->replica_screen_space_transform());
4828 EXPECT_TRANSFORMATION_MATRIX_EQ(
4829 expected_replica_screen_space_transform,
4830 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:474831}
4832
[email protected]989386c2013-07-18 21:37:234833TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324834 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
[email protected]fb661802013-03-25 01:59:324835 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:474836
enneea850232015-07-27 16:43:124837 LayerImpl* parent = root_layer();
4838 parent->SetDrawsContent(true);
4839 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4840 gfx::PointF(), gfx::Size(33, 31), false, true,
[email protected]fb661802013-03-25 01:59:324841 true);
[email protected]904e9132012-11-01 00:12:474842
enneea850232015-07-27 16:43:124843 LayerImpl* child = AddChildToRoot<LayerImpl>();
4844 child->SetDrawsContent(true);
4845 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
4846 gfx::PointF(), gfx::Size(13, 11), false, true,
[email protected]fb661802013-03-25 01:59:324847 true);
[email protected]904e9132012-11-01 00:12:474848
[email protected]fb661802013-03-25 01:59:324849 gfx::Transform replica_transform;
4850 replica_transform.Scale(1.0, -1.0);
enneea850232015-07-27 16:43:124851 scoped_ptr<LayerImpl> replica =
4852 LayerImpl::Create(host_impl()->active_tree(), 7);
4853 SetLayerPropertiesForTesting(replica.get(), replica_transform, gfx::Point3F(),
4854 gfx::PointF(), gfx::Size(13, 11), false, true,
4855 false);
danakja04855a2015-11-18 20:39:104856 child->SetReplicaLayer(std::move(replica));
[email protected]d600df7d2013-08-03 02:34:284857
[email protected]873639e2013-07-24 19:56:314858 float device_scale_factor = 1.7f;
enneea850232015-07-27 16:43:124859 ExecuteCalculateDrawProperties(parent, device_scale_factor);
[email protected]904e9132012-11-01 00:12:474860
[email protected]fb661802013-03-25 01:59:324861 // We should have two render surfaces. The root's render surface and child's
4862 // render surface (it needs one because it has a replica layer).
enneea850232015-07-27 16:43:124863 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]904e9132012-11-01 00:12:474864
[email protected]fb661802013-03-25 01:59:324865 gfx::Transform identity_transform;
[email protected]fb661802013-03-25 01:59:324866 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
4867 child->render_surface()->draw_transform());
4868 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
4869 child->render_surface()->draw_transform());
4870 EXPECT_TRANSFORMATION_MATRIX_EQ(
4871 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474872
[email protected]fb661802013-03-25 01:59:324873 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:264874 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:324875 EXPECT_TRANSFORMATION_MATRIX_EQ(
4876 expected_replica_draw_transform,
4877 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:474878
[email protected]fb661802013-03-25 01:59:324879 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:264880 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:324881 EXPECT_TRANSFORMATION_MATRIX_EQ(
4882 expected_replica_screen_space_transform,
4883 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144884}
4885
[email protected]989386c2013-07-18 21:37:234886TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
loysoa6edaaff2015-05-25 03:26:444887 scoped_refptr<Layer> root = Layer::Create(layer_settings());
4888 scoped_refptr<Layer> child = Layer::Create(layer_settings());
4889 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
4890 scoped_refptr<Layer> mask_layer = Layer::Create(layer_settings());
4891 scoped_refptr<Layer> replica_layer = Layer::Create(layer_settings());
[email protected]94f206c12012-08-25 00:09:144892
[email protected]fb661802013-03-25 01:59:324893 grand_child->SetReplicaLayer(replica_layer.get());
4894 child->AddChild(grand_child.get());
4895 child->SetMaskLayer(mask_layer.get());
4896 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:144897
ennea7b43c32015-06-18 20:01:334898 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:284899
[email protected]fb661802013-03-25 01:59:324900 int nonexistent_id = -1;
Daniel Chengeea98042014-08-26 00:28:104901 EXPECT_EQ(root.get(),
[email protected]fb661802013-03-25 01:59:324902 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
Daniel Chengeea98042014-08-26 00:28:104903 EXPECT_EQ(child.get(),
[email protected]fb661802013-03-25 01:59:324904 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
4905 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:104906 grand_child.get(),
[email protected]fb661802013-03-25 01:59:324907 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
4908 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:104909 mask_layer.get(),
[email protected]fb661802013-03-25 01:59:324910 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
4911 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:104912 replica_layer.get(),
[email protected]fb661802013-03-25 01:59:324913 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
4914 EXPECT_EQ(
4915 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:144916}
4917
[email protected]989386c2013-07-18 21:37:234918TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
loysoa6edaaff2015-05-25 03:26:444919 scoped_refptr<Layer> root = Layer::Create(layer_settings());
4920 scoped_refptr<Layer> child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:324921 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loysoa6edaaff2015-05-25 03:26:444922 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]498ec6e0e2012-11-30 18:24:574923
[email protected]fb661802013-03-25 01:59:324924 const gfx::Transform identity_matrix;
4925 SetLayerPropertiesForTesting(root.get(),
4926 identity_matrix,
[email protected]a2566412014-06-05 03:14:204927 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324928 gfx::PointF(),
4929 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574930 true,
[email protected]fb661802013-03-25 01:59:324931 false);
4932 SetLayerPropertiesForTesting(child.get(),
4933 identity_matrix,
[email protected]a2566412014-06-05 03:14:204934 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324935 gfx::PointF(),
4936 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574937 true,
[email protected]fb661802013-03-25 01:59:324938 false);
4939 SetLayerPropertiesForTesting(grand_child.get(),
4940 identity_matrix,
[email protected]a2566412014-06-05 03:14:204941 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324942 gfx::PointF(),
4943 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574944 true,
[email protected]fb661802013-03-25 01:59:324945 false);
[email protected]498ec6e0e2012-11-30 18:24:574946
[email protected]fb661802013-03-25 01:59:324947 root->AddChild(child);
4948 child->AddChild(grand_child);
4949 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:574950
ennea7b43c32015-06-18 20:01:334951 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:284952
[email protected]fb661802013-03-25 01:59:324953 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:574954
ennec1332992015-08-24 19:45:094955 EXPECT_FALSE(child->has_render_surface());
[email protected]498ec6e0e2012-11-30 18:24:574956}
4957
[email protected]989386c2013-07-18 21:37:234958TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
khushalsagarb64b360d2015-10-21 19:25:164959 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:454960 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:564961 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:164962 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:564963 &task_graph_runner);
[email protected]f90fc412013-03-30 20:13:164964 host_impl.CreatePendingTree();
4965 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
4966
4967 const gfx::Transform identity_matrix;
awoloszyne83f28c2014-12-22 15:40:004968 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
4969 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]f90fc412013-03-30 20:13:164970 false);
4971 root->SetDrawsContent(true);
4972
4973 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:004974 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
4975 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]f90fc412013-03-30 20:13:164976 false);
4977 child->SetDrawsContent(true);
4978 child->SetOpacity(0.0f);
4979
4980 // Add opacity animation.
4981 AddOpacityTransitionToController(
4982 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
4983
danakja04855a2015-11-18 20:39:104984 root->AddChild(std::move(child));
awoloszyne83f28c2014-12-22 15:40:004985 root->SetHasRenderSurface(true);
[email protected]f90fc412013-03-30 20:13:164986
[email protected]c0ae06c12013-06-24 18:32:194987 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:444988 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]7aad55f2013-07-26 11:25:534989 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:444990 root.get(), root->bounds(), &render_surface_layer_list,
4991 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:534992 inputs.can_adjust_raster_scales = true;
4993 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:164994
4995 // We should have one render surface and two layers. The child
4996 // layer should be included even though it is transparent.
4997 ASSERT_EQ(1u, render_surface_layer_list.size());
4998 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
4999}
5000
danakj3f76ace2014-11-18 16:56:005001using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
enne637715732015-07-07 02:05:265002class LCDTextTest : public LayerTreeHostCommonTestBase,
5003 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:365004 public:
5005 LCDTextTest()
enne637715732015-07-07 02:05:265006 : LayerTreeHostCommonTestBase(LayerTreeSettings()),
khushalsagarb64b360d2015-10-21 19:25:165007 host_impl_(&task_runner_provider_,
5008 &shared_bitmap_manager_,
5009 &task_graph_runner_),
enneaf5bda32015-02-19 01:27:365010 root_(nullptr),
5011 child_(nullptr),
5012 grand_child_(nullptr) {}
5013
[email protected]fb661802013-03-25 01:59:325014 protected:
dcheng93a52eb2014-12-23 02:14:235015 void SetUp() override {
[email protected]fb661802013-03-25 01:59:325016 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
danakj3f76ace2014-11-18 16:56:005017 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
[email protected]10aabcc32012-12-13 09:18:595018
enneaf5bda32015-02-19 01:27:365019 scoped_ptr<LayerImpl> root_ptr =
5020 LayerImpl::Create(host_impl_.active_tree(), 1);
5021 scoped_ptr<LayerImpl> child_ptr =
5022 LayerImpl::Create(host_impl_.active_tree(), 2);
5023 scoped_ptr<LayerImpl> grand_child_ptr =
5024 LayerImpl::Create(host_impl_.active_tree(), 3);
5025
5026 // Stash raw pointers to look at later.
5027 root_ = root_ptr.get();
5028 child_ = child_ptr.get();
5029 grand_child_ = grand_child_ptr.get();
5030
danakja04855a2015-11-18 20:39:105031 child_->AddChild(std::move(grand_child_ptr));
5032 root_->AddChild(std::move(child_ptr));
5033 host_impl_.active_tree()->SetRootLayer(std::move(root_ptr));
[email protected]10aabcc32012-12-13 09:18:595034
fmalita51b5e202014-11-18 20:11:505035 root_->SetContentsOpaque(true);
5036 child_->SetContentsOpaque(true);
5037 grand_child_->SetContentsOpaque(true);
5038
jaydasika3f930c12015-06-30 15:18:255039 root_->SetDrawsContent(true);
5040 child_->SetDrawsContent(true);
5041 grand_child_->SetDrawsContent(true);
5042
[email protected]fb661802013-03-25 01:59:325043 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365044 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
5045 gfx::PointF(), gfx::Size(1, 1), true, false,
5046 true);
5047 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
5048 gfx::PointF(), gfx::Size(1, 1), true, false,
5049 std::tr1::get<2>(GetParam()));
5050 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
5051 gfx::PointF(), gfx::Size(1, 1), true, false,
[email protected]fb661802013-03-25 01:59:325052 false);
[email protected]fb661802013-03-25 01:59:325053 }
[email protected]10aabcc32012-12-13 09:18:595054
[email protected]fb661802013-03-25 01:59:325055 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005056 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:365057
khushalsagarb64b360d2015-10-21 19:25:165058 FakeImplTaskRunnerProvider task_runner_provider_;
enneaf5bda32015-02-19 01:27:365059 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:475060 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:365061 FakeLayerTreeHostImpl host_impl_;
5062
5063 LayerImpl* root_;
5064 LayerImpl* child_;
5065 LayerImpl* grand_child_;
[email protected]10aabcc32012-12-13 09:18:595066};
5067
[email protected]fb661802013-03-25 01:59:325068TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005069 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5070 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5071
[email protected]fb661802013-03-25 01:59:325072 // Case 1: Identity transform.
5073 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365074 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005075 layers_always_allowed_lcd_text_);
5076 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5077 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5078 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595079
[email protected]fb661802013-03-25 01:59:325080 // Case 2: Integral translation.
5081 gfx::Transform integral_translation;
5082 integral_translation.Translate(1.0, 2.0);
5083 child_->SetTransform(integral_translation);
jaydasika3f930c12015-06-30 15:18:255084 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365085 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005086 layers_always_allowed_lcd_text_);
5087 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5088 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5089 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595090
[email protected]fb661802013-03-25 01:59:325091 // Case 3: Non-integral translation.
5092 gfx::Transform non_integral_translation;
5093 non_integral_translation.Translate(1.5, 2.5);
5094 child_->SetTransform(non_integral_translation);
jaydasika3f930c12015-06-30 15:18:255095 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365096 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005097 layers_always_allowed_lcd_text_);
5098 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5099 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5100 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595101
[email protected]fb661802013-03-25 01:59:325102 // Case 4: Rotation.
5103 gfx::Transform rotation;
5104 rotation.Rotate(10.0);
5105 child_->SetTransform(rotation);
jaydasika3f930c12015-06-30 15:18:255106 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365107 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005108 layers_always_allowed_lcd_text_);
5109 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5110 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5111 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595112
[email protected]fb661802013-03-25 01:59:325113 // Case 5: Scale.
5114 gfx::Transform scale;
5115 scale.Scale(2.0, 2.0);
5116 child_->SetTransform(scale);
jaydasika3f930c12015-06-30 15:18:255117 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365118 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005119 layers_always_allowed_lcd_text_);
5120 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5121 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5122 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595123
[email protected]fb661802013-03-25 01:59:325124 // Case 6: Skew.
5125 gfx::Transform skew;
nainar8ca8ee62015-09-03 01:04:105126 skew.Skew(10.0, 0.0);
[email protected]fb661802013-03-25 01:59:325127 child_->SetTransform(skew);
jaydasika3f930c12015-06-30 15:18:255128 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
enneaf5bda32015-02-19 01:27:365129 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005130 layers_always_allowed_lcd_text_);
5131 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5132 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5133 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595134
[email protected]fb661802013-03-25 01:59:325135 // Case 7: Translucent.
5136 child_->SetTransform(identity_matrix);
jaydasika3f930c12015-06-30 15:18:255137 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]fb661802013-03-25 01:59:325138 child_->SetOpacity(0.5f);
enneaf5bda32015-02-19 01:27:365139 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005140 layers_always_allowed_lcd_text_);
5141 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5142 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5143 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595144
[email protected]fb661802013-03-25 01:59:325145 // Case 8: Sanity check: restore transform and opacity.
5146 child_->SetTransform(identity_matrix);
jaydasika3f930c12015-06-30 15:18:255147 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]fb661802013-03-25 01:59:325148 child_->SetOpacity(1.f);
enneaf5bda32015-02-19 01:27:365149 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005150 layers_always_allowed_lcd_text_);
5151 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5152 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5153 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalita51b5e202014-11-18 20:11:505154
5155 // Case 9: Non-opaque content.
5156 child_->SetContentsOpaque(false);
enneaf5bda32015-02-19 01:27:365157 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505158 layers_always_allowed_lcd_text_);
5159 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5160 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5161 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5162
5163 // Case 10: Sanity check: restore content opaqueness.
5164 child_->SetContentsOpaque(true);
enneaf5bda32015-02-19 01:27:365165 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505166 layers_always_allowed_lcd_text_);
5167 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5168 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5169 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595170}
5171
[email protected]fd9a3b6d2013-08-03 00:46:175172TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005173 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
fmalitafcd926a2015-05-13 20:19:335174 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
danakj3f76ace2014-11-18 16:56:005175
[email protected]fb661802013-03-25 01:59:325176 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
enneaf5bda32015-02-19 01:27:365177 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005178 layers_always_allowed_lcd_text_);
5179 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5180 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5181 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595182
[email protected]fb661802013-03-25 01:59:325183 // Add opacity animation.
5184 child_->SetOpacity(0.9f);
jaydasika3f930c12015-06-30 15:18:255185 child_->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]fb661802013-03-25 01:59:325186 AddOpacityTransitionToController(
5187 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:595188
enneaf5bda32015-02-19 01:27:365189 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005190 layers_always_allowed_lcd_text_);
fmalitafcd926a2015-05-13 20:19:335191 // Text LCD should be adjusted while animation is active.
5192 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5193 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5194 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5195}
5196
5197TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
5198 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5199 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5200
5201 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
5202 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5203 layers_always_allowed_lcd_text_);
danakj3f76ace2014-11-18 16:56:005204 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5205 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5206 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalitafcd926a2015-05-13 20:19:335207
5208 // Mark contents non-opaque within the first animation frame.
5209 child_->SetContentsOpaque(false);
5210 AddOpacityTransitionToController(child_->layer_animation_controller(), 10.0,
5211 0.9f, 0.1f, false);
5212
5213 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5214 layers_always_allowed_lcd_text_);
5215 // LCD text should be disabled for non-opaque layers even during animations.
5216 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5217 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5218 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595219}
5220
5221INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5222 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005223 testing::Combine(testing::Bool(),
5224 testing::Bool(),
5225 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595226
[email protected]989386c2013-07-18 21:37:235227TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
khushalsagarb64b360d2015-10-21 19:25:165228 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455229 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565230 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165231 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565232 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195233 host_impl.CreatePendingTree();
5234 const gfx::Transform identity_matrix;
5235
5236 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:005237 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5238 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]c0ae06c12013-06-24 18:32:195239 false);
5240 root->SetDrawsContent(true);
5241
5242 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005243 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5244 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:195245 false);
5246 child->SetDrawsContent(true);
5247
5248 scoped_ptr<LayerImpl> grand_child =
5249 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:005250 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5251 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5252 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:195253 grand_child->SetDrawsContent(true);
5254 grand_child->SetHideLayerAndSubtree(true);
5255
danakja04855a2015-11-18 20:39:105256 child->AddChild(std::move(grand_child));
5257 root->AddChild(std::move(child));
awoloszyne83f28c2014-12-22 15:40:005258 root->SetHasRenderSurface(true);
[email protected]c0ae06c12013-06-24 18:32:195259
5260 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:445261 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]7aad55f2013-07-26 11:25:535262 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:445263 root.get(), root->bounds(), &render_surface_layer_list,
5264 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535265 inputs.can_adjust_raster_scales = true;
5266 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195267
5268 // We should have one render surface and two layers. The grand child has
5269 // hidden itself.
5270 ASSERT_EQ(1u, render_surface_layer_list.size());
5271 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235272 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
5273 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195274}
5275
[email protected]989386c2013-07-18 21:37:235276TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
khushalsagarb64b360d2015-10-21 19:25:165277 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455278 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565279 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165280 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565281 &task_graph_runner);
[email protected]c0ae06c12013-06-24 18:32:195282 host_impl.CreatePendingTree();
5283 const gfx::Transform identity_matrix;
5284
5285 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:005286 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5287 gfx::PointF(), gfx::Size(50, 50), true, false,
5288 true);
[email protected]c0ae06c12013-06-24 18:32:195289 root->SetDrawsContent(true);
5290
5291 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005292 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5293 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:195294 false);
5295 child->SetDrawsContent(true);
5296 child->SetHideLayerAndSubtree(true);
5297
5298 scoped_ptr<LayerImpl> grand_child =
5299 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:005300 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5301 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5302 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:195303 grand_child->SetDrawsContent(true);
5304
danakja04855a2015-11-18 20:39:105305 child->AddChild(std::move(grand_child));
5306 root->AddChild(std::move(child));
[email protected]c0ae06c12013-06-24 18:32:195307
5308 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:445309 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]7aad55f2013-07-26 11:25:535310 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:445311 root.get(), root->bounds(), &render_surface_layer_list,
5312 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535313 inputs.can_adjust_raster_scales = true;
5314 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195315
5316 // We should have one render surface and one layers. The child has
5317 // hidden itself and the grand child.
5318 ASSERT_EQ(1u, render_surface_layer_list.size());
5319 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235320 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:195321}
5322
[email protected]30fe19ff2013-07-04 00:54:455323void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
5324
[email protected]989386c2013-07-18 21:37:235325TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165326 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455327 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565328 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165329 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565330 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455331 host_impl.CreatePendingTree();
5332 const gfx::Transform identity_matrix;
5333
weiliangc51fb255d2015-07-24 15:32:305334 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5335 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5336 gfx::PointF(), gfx::Size(50, 50), true, false,
5337 true);
5338 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455339
weiliangc51fb255d2015-07-24 15:32:305340 scoped_ptr<LayerImpl> copy_grand_parent =
5341 LayerImpl::Create(host_impl.pending_tree(), 2);
5342 SetLayerPropertiesForTesting(copy_grand_parent.get(), identity_matrix,
5343 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5344 true, false, false);
5345 copy_grand_parent->SetDrawsContent(true);
5346 LayerImpl* copy_grand_parent_layer = copy_grand_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455347
weiliangc51fb255d2015-07-24 15:32:305348 scoped_ptr<LayerImpl> copy_parent =
5349 LayerImpl::Create(host_impl.pending_tree(), 3);
5350 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
5351 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5352 true, false, true);
5353 copy_parent->SetDrawsContent(true);
5354 LayerImpl* copy_parent_layer = copy_parent.get();
[email protected]30fe19ff2013-07-04 00:54:455355
weiliangc51fb255d2015-07-24 15:32:305356 scoped_ptr<LayerImpl> copy_request =
5357 LayerImpl::Create(host_impl.pending_tree(), 4);
5358 SetLayerPropertiesForTesting(copy_request.get(), identity_matrix,
5359 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5360 true, false, true);
5361 copy_request->SetDrawsContent(true);
5362 LayerImpl* copy_layer = copy_request.get();
[email protected]30fe19ff2013-07-04 00:54:455363
weiliangc51fb255d2015-07-24 15:32:305364 scoped_ptr<LayerImpl> copy_child =
5365 LayerImpl::Create(host_impl.pending_tree(), 5);
5366 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
5367 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5368 true, false, false);
5369 copy_child->SetDrawsContent(true);
5370 LayerImpl* copy_child_layer = copy_child.get();
[email protected]30fe19ff2013-07-04 00:54:455371
weiliangc51fb255d2015-07-24 15:32:305372 scoped_ptr<LayerImpl> copy_grand_parent_sibling_before =
5373 LayerImpl::Create(host_impl.pending_tree(), 6);
[email protected]ac020122013-07-12 23:45:535374 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
weiliangc51fb255d2015-07-24 15:32:305375 identity_matrix, gfx::Point3F(), gfx::PointF(),
5376 gfx::Size(40, 40), true, false, false);
5377 copy_grand_parent_sibling_before->SetDrawsContent(true);
5378 LayerImpl* copy_grand_parent_sibling_before_layer =
5379 copy_grand_parent_sibling_before.get();
[email protected]ac020122013-07-12 23:45:535380
weiliangc51fb255d2015-07-24 15:32:305381 scoped_ptr<LayerImpl> copy_grand_parent_sibling_after =
5382 LayerImpl::Create(host_impl.pending_tree(), 7);
[email protected]ac020122013-07-12 23:45:535383 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
weiliangc51fb255d2015-07-24 15:32:305384 identity_matrix, gfx::Point3F(), gfx::PointF(),
5385 gfx::Size(40, 40), true, false, false);
5386 copy_grand_parent_sibling_after->SetDrawsContent(true);
5387 LayerImpl* copy_grand_parent_sibling_after_layer =
5388 copy_grand_parent_sibling_after.get();
[email protected]ac020122013-07-12 23:45:535389
danakja04855a2015-11-18 20:39:105390 copy_request->AddChild(std::move(copy_child));
5391 copy_parent->AddChild(std::move(copy_request));
5392 copy_grand_parent->AddChild(std::move(copy_parent));
5393 root->AddChild(std::move(copy_grand_parent_sibling_before));
5394 root->AddChild(std::move(copy_grand_parent));
5395 root->AddChild(std::move(copy_grand_parent_sibling_after));
[email protected]d600df7d2013-08-03 02:34:285396
[email protected]30fe19ff2013-07-04 00:54:455397 // Hide the copy_grand_parent and its subtree. But make a copy request in that
5398 // hidden subtree on copy_layer.
weiliangc51fb255d2015-07-24 15:32:305399 copy_grand_parent_layer->SetHideLayerAndSubtree(true);
5400 copy_grand_parent_sibling_before_layer->SetHideLayerAndSubtree(true);
5401 copy_grand_parent_sibling_after_layer->SetHideLayerAndSubtree(true);
5402
vmpstra370ef52015-11-18 10:41:285403 std::vector<scoped_ptr<CopyOutputRequest>> copy_requests;
weiliangc51fb255d2015-07-24 15:32:305404 copy_requests.push_back(
5405 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5406 copy_layer->PassCopyRequests(&copy_requests);
[email protected]30fe19ff2013-07-04 00:54:455407 EXPECT_TRUE(copy_layer->HasCopyRequest());
5408
weiliangc51fb255d2015-07-24 15:32:305409 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:445410 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
weiliangc51fb255d2015-07-24 15:32:305411 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:445412 root.get(), root->bounds(), &render_surface_layer_list,
5413 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535414 inputs.can_adjust_raster_scales = true;
5415 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455416
enne25041932015-09-25 19:42:015417 EXPECT_GT(root->num_layer_or_descendants_with_copy_request(), 0);
5418 EXPECT_GT(
5419 copy_grand_parent_layer->num_layer_or_descendants_with_copy_request(), 0);
5420 EXPECT_GT(copy_parent_layer->num_layer_or_descendants_with_copy_request(), 0);
5421 EXPECT_GT(copy_layer->num_layer_or_descendants_with_copy_request(), 0);
5422 EXPECT_EQ(copy_child_layer->num_layer_or_descendants_with_copy_request(), 0);
5423 EXPECT_EQ(copy_grand_parent_sibling_before_layer
5424 ->num_layer_or_descendants_with_copy_request(),
5425 0);
5426 EXPECT_EQ(copy_grand_parent_sibling_after_layer
5427 ->num_layer_or_descendants_with_copy_request(),
5428 0);
[email protected]ac020122013-07-12 23:45:535429
[email protected]30fe19ff2013-07-04 00:54:455430 // We should have three render surfaces, one for the root, one for the parent
5431 // since it owns a surface, and one for the copy_layer.
5432 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:235433 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
weiliangc51fb255d2015-07-24 15:32:305434 EXPECT_EQ(copy_parent_layer->id(), render_surface_layer_list.at(1)->id());
[email protected]989386c2013-07-18 21:37:235435 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:455436
5437 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:535438 // copy_grand_parent is hidden along with its siblings, but the copy_parent
5439 // will appear since something in its subtree needs to be drawn for a copy
5440 // request.
[email protected]30fe19ff2013-07-04 00:54:455441 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235442 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
weiliangc51fb255d2015-07-24 15:32:305443 EXPECT_EQ(copy_parent_layer->id(),
[email protected]989386c2013-07-18 21:37:235444 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:455445
[email protected]7392c7b2014-02-07 08:28:285446 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:455447 // appear in its list, since it needs to be drawn for the copy request.
weiliangc51fb255d2015-07-24 15:32:305448 ASSERT_EQ(1u, copy_parent_layer->render_surface()->layer_list().size());
[email protected]30fe19ff2013-07-04 00:54:455449 EXPECT_EQ(copy_layer->id(),
weiliangc51fb255d2015-07-24 15:32:305450 copy_parent_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455451
5452 // The copy_layer's render surface should have two contributing layers.
5453 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
5454 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:235455 copy_layer->render_surface()->layer_list().at(0)->id());
weiliangc51fb255d2015-07-24 15:32:305456 EXPECT_EQ(copy_child_layer->id(),
[email protected]989386c2013-07-18 21:37:235457 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:455458}
5459
[email protected]989386c2013-07-18 21:37:235460TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
khushalsagarb64b360d2015-10-21 19:25:165461 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455462 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565463 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165464 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565465 &task_graph_runner);
[email protected]30fe19ff2013-07-04 00:54:455466 host_impl.CreatePendingTree();
5467 const gfx::Transform identity_matrix;
5468
weiliangc51fb255d2015-07-24 15:32:305469 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5470 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5471 gfx::PointF(), gfx::Size(50, 50), true, false,
5472 true);
5473 root->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455474
weiliangc51fb255d2015-07-24 15:32:305475 scoped_ptr<LayerImpl> copy_parent =
5476 LayerImpl::Create(host_impl.pending_tree(), 2);
5477 SetLayerPropertiesForTesting(copy_parent.get(), identity_matrix,
5478 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
5479 false, false);
5480 copy_parent->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455481 copy_parent->SetMasksToBounds(true);
5482
weiliangc51fb255d2015-07-24 15:32:305483 scoped_ptr<LayerImpl> copy_layer =
5484 LayerImpl::Create(host_impl.pending_tree(), 3);
5485 SetLayerPropertiesForTesting(copy_layer.get(), identity_matrix,
5486 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5487 true, false, true);
5488 copy_layer->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455489
weiliangc51fb255d2015-07-24 15:32:305490 scoped_ptr<LayerImpl> copy_child =
5491 LayerImpl::Create(host_impl.pending_tree(), 4);
5492 SetLayerPropertiesForTesting(copy_child.get(), identity_matrix,
5493 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5494 true, false, false);
5495 copy_child->SetDrawsContent(true);
[email protected]30fe19ff2013-07-04 00:54:455496
vmpstra370ef52015-11-18 10:41:285497 std::vector<scoped_ptr<CopyOutputRequest>> copy_requests;
weiliangc51fb255d2015-07-24 15:32:305498 copy_requests.push_back(
5499 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
5500 copy_layer->PassCopyRequests(&copy_requests);
[email protected]30fe19ff2013-07-04 00:54:455501 EXPECT_TRUE(copy_layer->HasCopyRequest());
5502
danakja04855a2015-11-18 20:39:105503 copy_layer->AddChild(std::move(copy_child));
5504 copy_parent->AddChild(std::move(copy_layer));
5505 root->AddChild(std::move(copy_parent));
weiliangc51fb255d2015-07-24 15:32:305506
5507 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:445508 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
weiliangc51fb255d2015-07-24 15:32:305509 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:445510 root.get(), root->bounds(), &render_surface_layer_list,
5511 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]7aad55f2013-07-26 11:25:535512 inputs.can_adjust_raster_scales = true;
5513 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:455514
xjze19f76402015-11-06 21:48:445515 // We should have two render surface, as the others are clipped out.
5516 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:235517 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455518
xjze19f76402015-11-06 21:48:445519 // The root render surface should only have 2 contributing layer, since the
[email protected]30fe19ff2013-07-04 00:54:455520 // other layers are empty/clipped away.
xjze19f76402015-11-06 21:48:445521 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235522 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:455523}
5524
[email protected]11a07b102013-07-24 17:33:195525TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
khushalsagarb64b360d2015-10-21 19:25:165526 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:455527 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:565528 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:165529 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:565530 &task_graph_runner);
[email protected]11a07b102013-07-24 17:33:195531 host_impl.CreatePendingTree();
5532 const gfx::Transform identity_matrix;
5533
loysoa6edaaff2015-05-25 03:26:445534 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]11a07b102013-07-24 17:33:195535 SetLayerPropertiesForTesting(root.get(),
5536 identity_matrix,
[email protected]a2566412014-06-05 03:14:205537 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:195538 gfx::PointF(),
5539 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575540 true,
[email protected]11a07b102013-07-24 17:33:195541 false);
5542 root->SetIsDrawable(true);
5543
5544 // The surface is moved slightly outside of the viewport.
loysoa6edaaff2015-05-25 03:26:445545 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
[email protected]11a07b102013-07-24 17:33:195546 SetLayerPropertiesForTesting(surface.get(),
5547 identity_matrix,
[email protected]a2566412014-06-05 03:14:205548 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:195549 gfx::PointF(-10, -20),
5550 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:575551 true,
[email protected]11a07b102013-07-24 17:33:195552 false);
5553 surface->SetForceRenderSurface(true);
5554
loysoa6edaaff2015-05-25 03:26:445555 scoped_refptr<Layer> surface_child = Layer::Create(layer_settings());
[email protected]11a07b102013-07-24 17:33:195556 SetLayerPropertiesForTesting(surface_child.get(),
5557 identity_matrix,
[email protected]a2566412014-06-05 03:14:205558 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:195559 gfx::PointF(),
5560 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575561 true,
[email protected]11a07b102013-07-24 17:33:195562 false);
5563 surface_child->SetIsDrawable(true);
5564
5565 surface->AddChild(surface_child);
5566 root->AddChild(surface);
5567
ennea7b43c32015-06-18 20:01:335568 host()->SetRootLayer(root);
[email protected]d600df7d2013-08-03 02:34:285569
enne1e1008c2015-08-21 00:45:465570 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(root.get(),
5571 root->bounds());
[email protected]7aad55f2013-07-26 11:25:535572 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:195573
danakj64767d902015-06-19 00:10:435574 // The visible_layer_rect for the |surface_child| should not be clipped by
[email protected]11a07b102013-07-24 17:33:195575 // the viewport.
5576 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
enne6c281f6e2015-08-18 23:23:005577 surface_child->visible_rect_from_property_trees().ToString());
[email protected]11a07b102013-07-24 17:33:195578}
5579
[email protected]420fdf6e2013-08-26 20:36:385580TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
5581 // Ensure that a transform between the layer and its render surface is not a
5582 // problem. Constructs the following layer tree.
5583 //
5584 // root (a render surface)
5585 // + render_surface
5586 // + clip_parent (scaled)
5587 // + intervening_clipping_layer
5588 // + clip_child
5589 //
5590 // The render surface should be resized correctly and the clip child should
5591 // inherit the right clip rect.
enne70aa712d2015-07-28 22:46:315592 LayerImpl* root = root_layer();
5593 LayerImpl* render_surface = AddChildToRoot<LayerImpl>();
5594 LayerImpl* clip_parent = AddChild<LayerImpl>(render_surface);
jaydasika0d98ba92015-11-17 05:17:285595 clip_parent->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315596 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285597 intervening->SetDrawsContent(true);
enne70aa712d2015-07-28 22:46:315598 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5599 clip_child->SetDrawsContent(true);
5600 clip_child->SetClipParent(clip_parent);
5601 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
5602 clip_children->insert(clip_child);
5603 clip_parent->SetClipChildren(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385604
5605 intervening->SetMasksToBounds(true);
5606 clip_parent->SetMasksToBounds(true);
5607
[email protected]420fdf6e2013-08-26 20:36:385608 gfx::Transform scale_transform;
5609 scale_transform.Scale(2, 2);
5610
5611 gfx::Transform identity_transform;
5612
enne70aa712d2015-07-28 22:46:315613 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5614 gfx::PointF(), gfx::Size(50, 50), true, false,
5615 true);
5616 SetLayerPropertiesForTesting(render_surface, identity_transform,
5617 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5618 true, false, true);
5619 SetLayerPropertiesForTesting(clip_parent, scale_transform, gfx::Point3F(),
5620 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
5621 false, false);
5622 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5623 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5624 false, false);
5625 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5626 gfx::PointF(1.f, 1.f), gfx::Size(10, 10), true,
5627 false, false);
[email protected]420fdf6e2013-08-26 20:36:385628
enne70aa712d2015-07-28 22:46:315629 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385630
5631 ASSERT_TRUE(root->render_surface());
5632 ASSERT_TRUE(render_surface->render_surface());
5633
5634 // Ensure that we've inherited our clip parent's clip and weren't affected
5635 // by the intervening clip layer.
5636 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
5637 clip_parent->clip_rect().ToString());
5638 ASSERT_EQ(clip_parent->clip_rect().ToString(),
5639 clip_child->clip_rect().ToString());
5640 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
5641 intervening->clip_rect().ToString());
5642
5643 // Ensure that the render surface reports a content rect that has been grown
5644 // to accomodate for the clip child.
jaydasika0d98ba92015-11-17 05:17:285645 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
[email protected]420fdf6e2013-08-26 20:36:385646 render_surface->render_surface()->content_rect().ToString());
5647
5648 // The above check implies the two below, but they nicely demonstrate that
5649 // we've grown, despite the intervening layer's clip.
5650 ASSERT_TRUE(clip_parent->clip_rect().Contains(
5651 render_surface->render_surface()->content_rect()));
5652 ASSERT_FALSE(intervening->clip_rect().Contains(
5653 render_surface->render_surface()->content_rect()));
5654}
5655
5656TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
5657 // Ensure that intervening render surfaces are not a problem in the basic
5658 // case. In the following tree, both render surfaces should be resized to
5659 // accomodate for the clip child, despite an intervening clip.
5660 //
5661 // root (a render surface)
5662 // + clip_parent (masks to bounds)
5663 // + render_surface1 (sets opacity)
5664 // + intervening (masks to bounds)
5665 // + render_surface2 (also sets opacity)
5666 // + clip_child
5667 //
weiliangcd6a836d2015-07-28 21:20:235668 LayerImpl* root = root_layer();
5669 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5670 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5671 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5672 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5673 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365674 render_surface1->SetDrawsContent(true);
5675 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235676 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385677
weiliangcd6a836d2015-07-28 21:20:235678 clip_child->SetClipParent(clip_parent);
[email protected]420fdf6e2013-08-26 20:36:385679
5680 intervening->SetMasksToBounds(true);
5681 clip_parent->SetMasksToBounds(true);
5682
[email protected]420fdf6e2013-08-26 20:36:385683 gfx::Transform translation_transform;
5684 translation_transform.Translate(2, 2);
5685
5686 gfx::Transform identity_transform;
weiliangcd6a836d2015-07-28 21:20:235687 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5688 gfx::PointF(), gfx::Size(50, 50), true, false,
5689 true);
5690 SetLayerPropertiesForTesting(clip_parent, translation_transform,
5691 gfx::Point3F(), gfx::PointF(1.f, 1.f),
5692 gfx::Size(40, 40), true, false, false);
5693 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5694 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5695 true, false, true);
5696 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5697 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5698 false, false);
5699 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5700 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5701 true, false, true);
5702 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5703 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
5704 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:385705
weiliangcd6a836d2015-07-28 21:20:235706 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385707
5708 EXPECT_TRUE(root->render_surface());
5709 EXPECT_TRUE(render_surface1->render_surface());
5710 EXPECT_TRUE(render_surface2->render_surface());
5711
5712 // Since the render surfaces could have expanded, they should not clip (their
5713 // bounds would no longer be reliable). We should resort to layer clipping
5714 // in this case.
5715 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5716 render_surface1->render_surface()->clip_rect().ToString());
5717 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5718 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5719 render_surface2->render_surface()->clip_rect().ToString());
5720 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5721
5722 // NB: clip rects are in target space.
5723 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5724 render_surface1->clip_rect().ToString());
5725 EXPECT_TRUE(render_surface1->is_clipped());
5726
5727 // This value is inherited from the clipping ancestor layer, 'intervening'.
5728 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5729 render_surface2->clip_rect().ToString());
5730 EXPECT_TRUE(render_surface2->is_clipped());
5731
5732 // The content rects of both render surfaces should both have expanded to
5733 // contain the clip child.
5734 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5735 render_surface1->render_surface()->content_rect().ToString());
5736 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
5737 render_surface2->render_surface()->content_rect().ToString());
5738
5739 // The clip child should have inherited the clip parent's clip (projected to
5740 // the right space, of course), and should have the correctly sized visible
5741 // content rect.
5742 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
5743 clip_child->clip_rect().ToString());
5744 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
danakj64767d902015-06-19 00:10:435745 clip_child->visible_layer_rect().ToString());
[email protected]420fdf6e2013-08-26 20:36:385746 EXPECT_TRUE(clip_child->is_clipped());
5747}
5748
5749TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
5750 // Ensure that intervening render surfaces are not a problem, even if there
5751 // is a scroll involved. Note, we do _not_ have to consider any other sort
5752 // of transform.
5753 //
5754 // root (a render surface)
5755 // + clip_parent (masks to bounds)
5756 // + render_surface1 (sets opacity)
5757 // + intervening (masks to bounds AND scrolls)
5758 // + render_surface2 (also sets opacity)
5759 // + clip_child
5760 //
weiliangcd6a836d2015-07-28 21:20:235761 LayerImpl* root = root_layer();
5762 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5763 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
5764 LayerImpl* intervening = AddChild<LayerImpl>(render_surface1);
5765 LayerImpl* render_surface2 = AddChild<LayerImpl>(intervening);
5766 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
jaydasika8640f9f2015-11-10 01:34:365767 render_surface1->SetDrawsContent(true);
5768 render_surface2->SetDrawsContent(true);
weiliangcd6a836d2015-07-28 21:20:235769 clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385770
weiliangcd6a836d2015-07-28 21:20:235771 clip_child->SetClipParent(clip_parent);
[email protected]420fdf6e2013-08-26 20:36:385772
5773 intervening->SetMasksToBounds(true);
5774 clip_parent->SetMasksToBounds(true);
weiliangcd6a836d2015-07-28 21:20:235775 intervening->SetScrollClipLayer(clip_parent->id());
5776 intervening->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:385777
5778 gfx::Transform translation_transform;
5779 translation_transform.Translate(2, 2);
5780
5781 gfx::Transform identity_transform;
weiliangcd6a836d2015-07-28 21:20:235782 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5783 gfx::PointF(), gfx::Size(50, 50), true, false,
5784 true);
5785 SetLayerPropertiesForTesting(clip_parent, translation_transform,
5786 gfx::Point3F(), gfx::PointF(1.f, 1.f),
5787 gfx::Size(40, 40), true, false, false);
5788 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5789 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5790 true, false, true);
5791 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5792 gfx::PointF(1.f, 1.f), gfx::Size(5, 5), true,
5793 false, false);
5794 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5795 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
5796 true, false, true);
5797 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5798 gfx::PointF(-10.f, -10.f), gfx::Size(60, 60),
5799 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:385800
weiliangcd6a836d2015-07-28 21:20:235801 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385802
5803 EXPECT_TRUE(root->render_surface());
5804 EXPECT_TRUE(render_surface1->render_surface());
5805 EXPECT_TRUE(render_surface2->render_surface());
5806
5807 // Since the render surfaces could have expanded, they should not clip (their
5808 // bounds would no longer be reliable). We should resort to layer clipping
5809 // in this case.
5810 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5811 render_surface1->render_surface()->clip_rect().ToString());
5812 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5813 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5814 render_surface2->render_surface()->clip_rect().ToString());
5815 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
5816
5817 // NB: clip rects are in target space.
5818 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5819 render_surface1->clip_rect().ToString());
5820 EXPECT_TRUE(render_surface1->is_clipped());
5821
5822 // This value is inherited from the clipping ancestor layer, 'intervening'.
5823 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
5824 render_surface2->clip_rect().ToString());
5825 EXPECT_TRUE(render_surface2->is_clipped());
5826
5827 // The content rects of both render surfaces should both have expanded to
5828 // contain the clip child.
5829 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5830 render_surface1->render_surface()->content_rect().ToString());
5831 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
5832 render_surface2->render_surface()->content_rect().ToString());
5833
5834 // The clip child should have inherited the clip parent's clip (projected to
5835 // the right space, of course), and should have the correctly sized visible
5836 // content rect.
5837 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
5838 clip_child->clip_rect().ToString());
5839 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
danakj64767d902015-06-19 00:10:435840 clip_child->visible_layer_rect().ToString());
[email protected]420fdf6e2013-08-26 20:36:385841 EXPECT_TRUE(clip_child->is_clipped());
5842}
5843
5844TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
5845 // Ensures that descendants of the clip child inherit the correct clip.
5846 //
5847 // root (a render surface)
5848 // + clip_parent (masks to bounds)
5849 // + intervening (masks to bounds)
5850 // + clip_child
5851 // + child
5852 //
enne2d0d8e62015-08-18 18:29:175853 LayerImpl* root = root_layer();
5854 LayerImpl* clip_parent = AddChild<LayerImpl>(root);
5855 LayerImpl* intervening = AddChild<LayerImpl>(clip_parent);
5856 LayerImpl* clip_child = AddChild<LayerImpl>(intervening);
5857 LayerImpl* child = AddChild<LayerImpl>(clip_child);
jaydasika8640f9f2015-11-10 01:34:365858 clip_child->SetDrawsContent(true);
enne2d0d8e62015-08-18 18:29:175859 child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385860
enne2d0d8e62015-08-18 18:29:175861 clip_child->SetClipParent(clip_parent);
5862 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
5863 clip_children->insert(clip_child);
5864 clip_parent->SetClipChildren(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385865
5866 intervening->SetMasksToBounds(true);
5867 clip_parent->SetMasksToBounds(true);
5868
5869 gfx::Transform identity_transform;
enne2d0d8e62015-08-18 18:29:175870 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5871 gfx::PointF(), gfx::Size(50, 50), true, false,
5872 true);
5873 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
5874 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]420fdf6e2013-08-26 20:36:385875 false);
enne2d0d8e62015-08-18 18:29:175876 SetLayerPropertiesForTesting(intervening, identity_transform, gfx::Point3F(),
5877 gfx::PointF(), gfx::Size(5, 5), true, false,
[email protected]420fdf6e2013-08-26 20:36:385878 false);
enne2d0d8e62015-08-18 18:29:175879 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5880 gfx::PointF(), gfx::Size(60, 60), true, false,
[email protected]420fdf6e2013-08-26 20:36:385881 false);
enne2d0d8e62015-08-18 18:29:175882 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
5883 gfx::PointF(), gfx::Size(60, 60), true, false,
[email protected]420fdf6e2013-08-26 20:36:385884 false);
5885
enne2d0d8e62015-08-18 18:29:175886 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385887
5888 EXPECT_TRUE(root->render_surface());
5889
5890 // Neither the clip child nor its descendant should have inherited the clip
5891 // from |intervening|.
5892 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5893 clip_child->clip_rect().ToString());
5894 EXPECT_TRUE(clip_child->is_clipped());
5895 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
danakj64767d902015-06-19 00:10:435896 child->visible_layer_rect().ToString());
[email protected]420fdf6e2013-08-26 20:36:385897 EXPECT_TRUE(child->is_clipped());
5898}
5899
5900TEST_F(LayerTreeHostCommonTest,
5901 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
5902 // Ensures that non-descendant clip children in the tree do not affect
5903 // render surfaces.
5904 //
5905 // root (a render surface)
5906 // + clip_parent (masks to bounds)
5907 // + render_surface1
5908 // + clip_child
5909 // + render_surface2
5910 // + non_clip_child
5911 //
5912 // In this example render_surface2 should be unaffected by clip_child.
enneb441cdd2015-07-28 22:47:505913 LayerImpl* root = root_layer();
5914 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
5915 LayerImpl* render_surface1 = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285916 render_surface1->SetDrawsContent(true);
enneb441cdd2015-07-28 22:47:505917 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface1);
5918 clip_child->SetDrawsContent(true);
5919 LayerImpl* render_surface2 = AddChild<LayerImpl>(clip_parent);
jaydasika0d98ba92015-11-17 05:17:285920 render_surface2->SetDrawsContent(true);
enneb441cdd2015-07-28 22:47:505921 LayerImpl* non_clip_child = AddChild<LayerImpl>(render_surface2);
5922 non_clip_child->SetDrawsContent(true);
[email protected]420fdf6e2013-08-26 20:36:385923
enneb441cdd2015-07-28 22:47:505924 clip_child->SetClipParent(clip_parent);
5925 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
5926 clip_children->insert(clip_child);
5927 clip_parent->SetClipChildren(clip_children.release());
[email protected]420fdf6e2013-08-26 20:36:385928
5929 clip_parent->SetMasksToBounds(true);
5930 render_surface1->SetMasksToBounds(true);
5931
5932 gfx::Transform identity_transform;
enneb441cdd2015-07-28 22:47:505933 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
5934 gfx::PointF(), gfx::Size(15, 15), true, false,
5935 true);
5936 SetLayerPropertiesForTesting(clip_parent, identity_transform, gfx::Point3F(),
5937 gfx::PointF(), gfx::Size(10, 10), true, false,
[email protected]420fdf6e2013-08-26 20:36:385938 false);
enneb441cdd2015-07-28 22:47:505939 SetLayerPropertiesForTesting(render_surface1, identity_transform,
5940 gfx::Point3F(), gfx::PointF(5, 5),
5941 gfx::Size(5, 5), true, false, true);
5942 SetLayerPropertiesForTesting(render_surface2, identity_transform,
5943 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5944 true, false, true);
5945 SetLayerPropertiesForTesting(clip_child, identity_transform, gfx::Point3F(),
5946 gfx::PointF(-1, 1), gfx::Size(10, 10), true,
5947 false, false);
5948 SetLayerPropertiesForTesting(non_clip_child, identity_transform,
5949 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5950 true, false, false);
[email protected]420fdf6e2013-08-26 20:36:385951
enneb441cdd2015-07-28 22:47:505952 ExecuteCalculateDrawProperties(root);
[email protected]420fdf6e2013-08-26 20:36:385953
5954 EXPECT_TRUE(root->render_surface());
5955 EXPECT_TRUE(render_surface1->render_surface());
5956 EXPECT_TRUE(render_surface2->render_surface());
5957
5958 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5959 render_surface1->clip_rect().ToString());
5960 EXPECT_TRUE(render_surface1->is_clipped());
5961
5962 // The render surface should not clip (it has unclipped descendants), instead
5963 // it should rely on layer clipping.
5964 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5965 render_surface1->render_surface()->clip_rect().ToString());
5966 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
5967
jaydasika0d98ba92015-11-17 05:17:285968 // That said, it should have grown to accomodate the unclipped descendant and
5969 // its own size.
5970 EXPECT_EQ(gfx::Rect(-1, 0, 6, 5).ToString(),
[email protected]420fdf6e2013-08-26 20:36:385971 render_surface1->render_surface()->content_rect().ToString());
5972
5973 // This render surface should clip. It has no unclipped descendants.
5974 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5975 render_surface2->clip_rect().ToString());
5976 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
5977
5978 // It also shouldn't have grown to accomodate the clip child.
5979 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5980 render_surface2->render_surface()->content_rect().ToString());
5981
5982 // Sanity check our num_unclipped_descendants values.
vmpstr762e70d2015-06-10 02:12:575983 EXPECT_EQ(1u, render_surface1->num_unclipped_descendants());
5984 EXPECT_EQ(0u, render_surface2->num_unclipped_descendants());
[email protected]420fdf6e2013-08-26 20:36:385985}
5986
weiliangc9ced1592015-11-17 19:04:375987TEST_F(LayerTreeHostCommonTest,
5988 CreateRenderSurfaceWhenFlattenInsideRenderingContext) {
5989 // Verifies that Render Surfaces are created at the edge of rendering context.
5990
5991 scoped_refptr<LayerWithForcedDrawsContent> parent =
5992 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5993 Layer* root = parent.get();
5994 scoped_refptr<LayerWithForcedDrawsContent> child_1 =
5995 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5996 Layer* child1 = child_1.get();
5997 scoped_refptr<LayerWithForcedDrawsContent> child_2 =
5998 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5999 Layer* child2 = child_2.get();
6000 scoped_refptr<LayerWithForcedDrawsContent> child_3 =
6001 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6002 Layer* child3 = child_3.get();
6003
danakja04855a2015-11-18 20:39:106004 parent->AddChild(std::move(child_1));
6005 child1->AddChild(std::move(child_2));
6006 child2->AddChild(std::move(child_3));
weiliangc9ced1592015-11-17 19:04:376007
6008 host()->SetRootLayer(root);
6009
6010 const gfx::Transform identity_matrix;
6011 gfx::Point3F transform_origin;
6012 gfx::PointF position;
6013 gfx::Size bounds(100, 100);
6014
6015 SetLayerPropertiesForTesting(root, identity_matrix, transform_origin,
6016 position, bounds, true, false);
6017 SetLayerPropertiesForTesting(child1, identity_matrix, transform_origin,
6018 position, bounds, false, true);
6019 SetLayerPropertiesForTesting(child2, identity_matrix, transform_origin,
6020 position, bounds, true, false);
6021 SetLayerPropertiesForTesting(child3, identity_matrix, transform_origin,
6022 position, bounds, true, false);
6023
6024 child2->Set3dSortingContextId(1);
6025 child3->Set3dSortingContextId(1);
6026
6027 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
6028
6029 // Verify which render surfaces were created.
6030 EXPECT_TRUE(root->has_render_surface());
6031 EXPECT_FALSE(child1->has_render_surface());
6032 EXPECT_TRUE(child2->has_render_surface());
6033 EXPECT_FALSE(child3->has_render_surface());
6034}
6035
[email protected]45948712013-09-27 02:46:486036TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
khushalsagarb64b360d2015-10-21 19:25:166037 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:456038 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:566039 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:166040 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:566041 &task_graph_runner);
[email protected]45948712013-09-27 02:46:486042 scoped_ptr<LayerImpl> root =
6043 LayerImpl::Create(host_impl.active_tree(), 12345);
6044 scoped_ptr<LayerImpl> child1 =
6045 LayerImpl::Create(host_impl.active_tree(), 123456);
6046 scoped_ptr<LayerImpl> child2 =
6047 LayerImpl::Create(host_impl.active_tree(), 1234567);
6048 scoped_ptr<LayerImpl> child3 =
6049 LayerImpl::Create(host_impl.active_tree(), 12345678);
6050
6051 gfx::Transform identity_matrix;
[email protected]a2566412014-06-05 03:14:206052 gfx::Point3F transform_origin;
[email protected]45948712013-09-27 02:46:486053 gfx::PointF position;
6054 gfx::Size bounds(100, 100);
awoloszyne83f28c2014-12-22 15:40:006055 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
6056 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:486057 root->SetDrawsContent(true);
6058
6059 // This layer structure normally forces render surface due to preserves3d
6060 // behavior.
awoloszyne83f28c2014-12-22 15:40:006061 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin,
weiliangc9ced1592015-11-17 19:04:376062 position, bounds, false, true, false);
[email protected]45948712013-09-27 02:46:486063 child1->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:006064 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin,
weiliangc9ced1592015-11-17 19:04:376065 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:486066 child2->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:006067 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin,
6068 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:486069 child3->SetDrawsContent(true);
6070
[email protected]a9d4d4f2014-06-19 06:49:286071 child2->Set3dSortingContextId(1);
6072 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:576073
danakja04855a2015-11-18 20:39:106074 child2->AddChild(std::move(child3));
6075 child1->AddChild(std::move(child2));
6076 root->AddChild(std::move(child1));
[email protected]45948712013-09-27 02:46:486077
6078 {
6079 LayerImplList render_surface_layer_list;
[email protected]ad63b2f2014-08-11 17:39:546080 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get());
ajumad9432e32015-11-30 19:43:446081 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]45948712013-09-27 02:46:486082 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:446083 root.get(), root->bounds(), &render_surface_layer_list,
6084 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]45948712013-09-27 02:46:486085 inputs.can_render_to_separate_surface = true;
6086 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6087
6088 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026089
6090 int count_represents_target_render_surface = 0;
6091 int count_represents_contributing_render_surface = 0;
6092 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516093 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6094 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026095 it != end; ++it) {
6096 if (it.represents_target_render_surface())
6097 count_represents_target_render_surface++;
6098 if (it.represents_contributing_render_surface())
6099 count_represents_contributing_render_surface++;
6100 if (it.represents_itself())
6101 count_represents_itself++;
6102 }
6103
6104 // Two render surfaces.
6105 EXPECT_EQ(2, count_represents_target_render_surface);
6106 // Second render surface contributes to root render surface.
6107 EXPECT_EQ(1, count_represents_contributing_render_surface);
6108 // All 4 layers represent itself.
6109 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486110 }
6111
6112 {
6113 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:446114 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]45948712013-09-27 02:46:486115 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:446116 root.get(), root->bounds(), &render_surface_layer_list,
6117 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]45948712013-09-27 02:46:486118 inputs.can_render_to_separate_surface = false;
6119 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6120
6121 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:026122
6123 int count_represents_target_render_surface = 0;
6124 int count_represents_contributing_render_surface = 0;
6125 int count_represents_itself = 0;
enne389d1a12015-06-18 20:40:516126 LayerIterator end = LayerIterator::End(&render_surface_layer_list);
6127 for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list);
boliu13185ca2015-03-16 23:20:026128 it != end; ++it) {
6129 if (it.represents_target_render_surface())
6130 count_represents_target_render_surface++;
6131 if (it.represents_contributing_render_surface())
6132 count_represents_contributing_render_surface++;
6133 if (it.represents_itself())
6134 count_represents_itself++;
6135 }
6136
6137 // Only root layer has a render surface.
6138 EXPECT_EQ(1, count_represents_target_render_surface);
6139 // No layer contributes a render surface to root render surface.
6140 EXPECT_EQ(0, count_represents_contributing_render_surface);
6141 // All 4 layers represent itself.
6142 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:486143 }
6144}
6145
[email protected]a9aa60a82013-08-29 04:28:266146TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
enne03b0e9a2015-06-19 00:08:026147 LayerImpl* root = root_layer();
6148 LayerImpl* render_surface = AddChild<LayerImpl>(root);
6149 LayerImpl* child = AddChild<LayerImpl>(render_surface);
6150 child->SetDrawsContent(true);
[email protected]a9aa60a82013-08-29 04:28:266151
6152 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026153 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6154 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]56fffdd2014-02-11 19:50:576155 true);
enne03b0e9a2015-06-19 00:08:026156 SetLayerPropertiesForTesting(render_surface, identity_transform,
6157 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6158 false, true, true);
6159 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6160 gfx::PointF(), gfx::Size(20, 20), true, false,
[email protected]a9aa60a82013-08-29 04:28:266161 false);
6162
[email protected]56fffdd2014-02-11 19:50:576163 root->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:286164 root->Set3dSortingContextId(1);
[email protected]a9aa60a82013-08-29 04:28:266165 render_surface->SetDoubleSided(false);
[email protected]a9aa60a82013-08-29 04:28:266166
enne03b0e9a2015-06-19 00:08:026167 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266168
enne03b0e9a2015-06-19 00:08:026169 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
6170 EXPECT_EQ(1u, render_surface_layer_list_impl()
6171 ->at(0)
6172 ->render_surface()
6173 ->layer_list()
6174 .size());
6175 EXPECT_EQ(1u, render_surface_layer_list_impl()
6176 ->at(1)
6177 ->render_surface()
6178 ->layer_list()
6179 .size());
[email protected]a9aa60a82013-08-29 04:28:266180
6181 gfx::Transform rotation_transform = identity_transform;
6182 rotation_transform.RotateAboutXAxis(180.0);
6183
6184 render_surface->SetTransform(rotation_transform);
jaydasika5aa88b82015-11-10 01:48:036185 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]a9aa60a82013-08-29 04:28:266186
enne03b0e9a2015-06-19 00:08:026187 ExecuteCalculateDrawProperties(root);
[email protected]a9aa60a82013-08-29 04:28:266188
enne03b0e9a2015-06-19 00:08:026189 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6190 EXPECT_EQ(0u, render_surface_layer_list_impl()
6191 ->at(0)
6192 ->render_surface()
6193 ->layer_list()
6194 .size());
[email protected]a9aa60a82013-08-29 04:28:266195}
6196
ajumaaa0d3862015-11-09 22:24:466197TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleLayers) {
6198 LayerImpl* root = root_layer();
6199 LayerImpl* child = AddChild<LayerImpl>(root);
6200 LayerImpl* grand_child = AddChild<LayerImpl>(child);
6201 grand_child->SetDrawsContent(true);
6202
6203 child->SetDoubleSided(false);
6204 grand_child->SetUseParentBackfaceVisibility(true);
6205
6206 gfx::Transform identity_transform;
6207 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6208 gfx::PointF(), gfx::Size(50, 50), false, true,
6209 true);
6210 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6211 gfx::PointF(), gfx::Size(30, 30), false, true,
6212 false);
6213 SetLayerPropertiesForTesting(grand_child, identity_transform, gfx::Point3F(),
6214 gfx::PointF(), gfx::Size(20, 20), false, true,
6215 false);
6216
6217 ExecuteCalculateDrawProperties(root);
6218
6219 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6220 EXPECT_EQ(grand_child, render_surface_layer_list_impl()
6221 ->at(0)
6222 ->render_surface()
6223 ->layer_list()[0]);
6224 gfx::Transform rotation_transform = identity_transform;
6225 rotation_transform.RotateAboutXAxis(180.0);
6226
6227 child->SetTransform(rotation_transform);
6228 child->layer_tree_impl()->property_trees()->needs_rebuild = true;
6229
6230 ExecuteCalculateDrawProperties(root);
6231 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
6232 EXPECT_EQ(0u, render_surface_layer_list_impl()
6233 ->at(0)
6234 ->render_surface()
6235 ->layer_list()
6236 .size());
6237}
6238
[email protected]995708c52013-10-17 20:52:596239TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
6240 // Checks that the simple case (being clipped by a scroll parent that would
6241 // have been processed before you anyhow) results in the right clips.
6242 //
6243 // + root
6244 // + scroll_parent_border
6245 // | + scroll_parent_clip
6246 // | + scroll_parent
6247 // + scroll_child
6248 //
enne085b48a2015-08-18 17:54:486249 LayerImpl* root = root_layer();
6250 LayerImpl* scroll_parent_border = AddChildToRoot<LayerImpl>();
6251 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6252 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6253 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596254
enne085b48a2015-08-18 17:54:486255 scroll_parent->SetDrawsContent(true);
6256 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596257 scroll_parent_clip->SetMasksToBounds(true);
6258
enne085b48a2015-08-18 17:54:486259 scroll_child->SetScrollParent(scroll_parent);
6260 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6261 scroll_children->insert(scroll_child);
6262 scroll_parent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596263
6264 gfx::Transform identity_transform;
enne085b48a2015-08-18 17:54:486265 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6266 gfx::PointF(), gfx::Size(50, 50), true, false,
6267 true);
6268 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6269 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6270 true, false, false);
6271 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6272 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6273 true, false, false);
6274 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6275 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6276 true, false, false);
6277 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6278 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596279 false);
6280
enne085b48a2015-08-18 17:54:486281 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596282
6283 EXPECT_TRUE(root->render_surface());
6284
6285 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6286 scroll_child->clip_rect().ToString());
6287 EXPECT_TRUE(scroll_child->is_clipped());
6288}
6289
[email protected]08bdf1b2014-04-16 23:23:296290TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
enneca33fed2015-07-27 18:22:196291 LayerImpl* root = root_layer();
6292 root->SetDrawsContent(true);
6293 LayerImpl* parent = AddChildToRoot<LayerImpl>();
6294 parent->SetDrawsContent(true);
6295 LayerImpl* child = AddChild<LayerImpl>(parent);
6296 child->SetDrawsContent(true);
[email protected]08bdf1b2014-04-16 23:23:296297
6298 gfx::Transform identity_transform;
enneca33fed2015-07-27 18:22:196299 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6300 gfx::PointF(), gfx::Size(50, 50), true, true,
[email protected]08bdf1b2014-04-16 23:23:296301 true);
enneca33fed2015-07-27 18:22:196302 SetLayerPropertiesForTesting(parent, identity_transform, gfx::Point3F(),
6303 gfx::PointF(), gfx::Size(30, 30), true, true,
[email protected]08bdf1b2014-04-16 23:23:296304 true);
enneca33fed2015-07-27 18:22:196305 SetLayerPropertiesForTesting(child, identity_transform, gfx::Point3F(),
6306 gfx::PointF(), gfx::Size(20, 20), true, true,
[email protected]08bdf1b2014-04-16 23:23:296307 true);
[email protected]08bdf1b2014-04-16 23:23:296308
enneca33fed2015-07-27 18:22:196309 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296310
enneca33fed2015-07-27 18:22:196311 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296312
6313 gfx::Transform singular_transform;
6314 singular_transform.Scale3d(
6315 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
6316
6317 child->SetTransform(singular_transform);
6318
enneca33fed2015-07-27 18:22:196319 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296320
enneca33fed2015-07-27 18:22:196321 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296322
6323 // Ensure that the entire subtree under a layer with singular transform does
6324 // not get rendered.
6325 parent->SetTransform(singular_transform);
6326 child->SetTransform(identity_transform);
6327
enneca33fed2015-07-27 18:22:196328 ExecuteCalculateDrawProperties(root);
[email protected]08bdf1b2014-04-16 23:23:296329
enneca33fed2015-07-27 18:22:196330 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
[email protected]08bdf1b2014-04-16 23:23:296331}
6332
[email protected]995708c52013-10-17 20:52:596333TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
6334 // Checks that clipping by a scroll parent that follows you in paint order
6335 // still results in correct clipping.
6336 //
6337 // + root
[email protected]995708c52013-10-17 20:52:596338 // + scroll_parent_border
6339 // + scroll_parent_clip
6340 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026341 // + scroll_child
[email protected]995708c52013-10-17 20:52:596342 //
enne03b0e9a2015-06-19 00:08:026343 LayerImpl* root = root_layer();
6344 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6345 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6346 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6347 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
[email protected]995708c52013-10-17 20:52:596348
enne03b0e9a2015-06-19 00:08:026349 scroll_parent->SetDrawsContent(true);
6350 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596351
6352 scroll_parent_clip->SetMasksToBounds(true);
6353
enne03b0e9a2015-06-19 00:08:026354 scroll_child->SetScrollParent(scroll_parent);
ajuma9af2e92b2015-06-29 22:26:386355 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6356 scroll_children->insert(scroll_child);
6357 scroll_parent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596358
6359 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026360 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6361 gfx::PointF(), gfx::Size(50, 50), true, false,
6362 true);
6363 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6364 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6365 true, false, false);
6366 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6367 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6368 true, false, false);
6369 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6370 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6371 true, false, false);
6372 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6373 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596374 false);
6375
enne03b0e9a2015-06-19 00:08:026376 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596377
6378 EXPECT_TRUE(root->render_surface());
6379
6380 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
6381 scroll_child->clip_rect().ToString());
6382 EXPECT_TRUE(scroll_child->is_clipped());
6383}
6384
6385TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
6386 // Checks that clipping by a scroll parent and scroll grandparent that follow
6387 // you in paint order still results in correct clipping.
6388 //
6389 // + root
6390 // + scroll_child
6391 // + scroll_parent_border
6392 // | + scroll_parent_clip
6393 // | + scroll_parent
6394 // + scroll_grandparent_border
6395 // + scroll_grandparent_clip
6396 // + scroll_grandparent
6397 //
enne03b0e9a2015-06-19 00:08:026398 LayerImpl* root = root_layer();
6399 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6400 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6401 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6402 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6403 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6404 LayerImpl* scroll_grandparent_clip =
6405 AddChild<LayerImpl>(scroll_grandparent_border);
6406 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
[email protected]995708c52013-10-17 20:52:596407
enne03b0e9a2015-06-19 00:08:026408 scroll_parent->SetDrawsContent(true);
6409 scroll_grandparent->SetDrawsContent(true);
6410 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596411
6412 scroll_parent_clip->SetMasksToBounds(true);
6413 scroll_grandparent_clip->SetMasksToBounds(true);
6414
enne03b0e9a2015-06-19 00:08:026415 scroll_child->SetScrollParent(scroll_parent);
ajuma9af2e92b2015-06-29 22:26:386416 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6417 scroll_children->insert(scroll_child);
6418 scroll_parent->SetScrollChildren(scroll_children.release());
6419
enne03b0e9a2015-06-19 00:08:026420 scroll_parent_border->SetScrollParent(scroll_grandparent);
ajuma9af2e92b2015-06-29 22:26:386421 scroll_children.reset(new std::set<LayerImpl*>);
6422 scroll_children->insert(scroll_parent_border);
6423 scroll_grandparent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596424
6425 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026426 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6427 gfx::PointF(), gfx::Size(50, 50), true, false,
6428 true);
6429 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6430 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6431 true, false, false);
6432 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6433 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6434 true, false, false);
6435 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6436 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6437 true, false, false);
6438 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6439 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6440 true, false, false);
6441 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6442 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6443 true, false, false);
6444 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6445 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6446 true, false, false);
6447 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6448 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596449 false);
6450
enne03b0e9a2015-06-19 00:08:026451 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596452
6453 EXPECT_TRUE(root->render_surface());
6454
6455 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
6456 scroll_child->clip_rect().ToString());
6457 EXPECT_TRUE(scroll_child->is_clipped());
6458
6459 // Despite the fact that we visited the above layers out of order to get the
6460 // correct clip, the layer lists should be unaffected.
6461 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
enne03b0e9a2015-06-19 00:08:026462 EXPECT_EQ(scroll_child, root->render_surface()->layer_list().at(0));
6463 EXPECT_EQ(scroll_parent, root->render_surface()->layer_list().at(1));
6464 EXPECT_EQ(scroll_grandparent, root->render_surface()->layer_list().at(2));
[email protected]995708c52013-10-17 20:52:596465}
6466
6467TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
6468 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:226469 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:596470 // + root
6471 // + scroll_child
6472 // + scroll_parent_border
6473 // + scroll_parent_clip
6474 // + scroll_parent
enne03b0e9a2015-06-19 00:08:026475 // + render_surface2
[email protected]995708c52013-10-17 20:52:596476 // + scroll_grandparent_border
6477 // + scroll_grandparent_clip
6478 // + scroll_grandparent
enne03b0e9a2015-06-19 00:08:026479 // + render_surface1
[email protected]995708c52013-10-17 20:52:596480 //
enne03b0e9a2015-06-19 00:08:026481 LayerImpl* root = root_layer();
6482 root->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596483
enne03b0e9a2015-06-19 00:08:026484 LayerImpl* scroll_child = AddChild<LayerImpl>(root);
6485 scroll_child->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596486
enne03b0e9a2015-06-19 00:08:026487 LayerImpl* scroll_parent_border = AddChild<LayerImpl>(root);
6488 LayerImpl* scroll_parent_clip = AddChild<LayerImpl>(scroll_parent_border);
6489 LayerImpl* scroll_parent = AddChild<LayerImpl>(scroll_parent_clip);
6490 LayerImpl* render_surface2 = AddChild<LayerImpl>(scroll_parent);
6491 LayerImpl* scroll_grandparent_border = AddChild<LayerImpl>(root);
6492 LayerImpl* scroll_grandparent_clip =
6493 AddChild<LayerImpl>(scroll_grandparent_border);
6494 LayerImpl* scroll_grandparent = AddChild<LayerImpl>(scroll_grandparent_clip);
6495 LayerImpl* render_surface1 = AddChild<LayerImpl>(scroll_grandparent);
[email protected]995708c52013-10-17 20:52:596496
enne03b0e9a2015-06-19 00:08:026497 scroll_parent->SetDrawsContent(true);
6498 render_surface1->SetDrawsContent(true);
6499 scroll_grandparent->SetDrawsContent(true);
6500 render_surface2->SetDrawsContent(true);
[email protected]995708c52013-10-17 20:52:596501
6502 scroll_parent_clip->SetMasksToBounds(true);
6503 scroll_grandparent_clip->SetMasksToBounds(true);
6504
enne03b0e9a2015-06-19 00:08:026505 scroll_child->SetScrollParent(scroll_parent);
ajuma9af2e92b2015-06-29 22:26:386506 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
6507 scroll_children->insert(scroll_child);
6508 scroll_parent->SetScrollChildren(scroll_children.release());
6509
enne03b0e9a2015-06-19 00:08:026510 scroll_parent_border->SetScrollParent(scroll_grandparent);
ajuma9af2e92b2015-06-29 22:26:386511 scroll_children.reset(new std::set<LayerImpl*>);
6512 scroll_children->insert(scroll_parent_border);
6513 scroll_grandparent->SetScrollChildren(scroll_children.release());
[email protected]995708c52013-10-17 20:52:596514
6515 gfx::Transform identity_transform;
enne03b0e9a2015-06-19 00:08:026516 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6517 gfx::PointF(), gfx::Size(50, 50), true, false,
6518 true);
6519 SetLayerPropertiesForTesting(scroll_grandparent_border, identity_transform,
6520 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6521 true, false, false);
6522 SetLayerPropertiesForTesting(scroll_grandparent_clip, identity_transform,
6523 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
6524 true, false, false);
6525 SetLayerPropertiesForTesting(scroll_grandparent, identity_transform,
6526 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6527 true, false, false);
6528 SetLayerPropertiesForTesting(render_surface1, identity_transform,
6529 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6530 true, false, true);
6531 SetLayerPropertiesForTesting(scroll_parent_border, identity_transform,
6532 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6533 true, false, false);
6534 SetLayerPropertiesForTesting(scroll_parent_clip, identity_transform,
6535 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6536 true, false, false);
6537 SetLayerPropertiesForTesting(scroll_parent, identity_transform,
6538 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6539 true, false, false);
6540 SetLayerPropertiesForTesting(render_surface2, identity_transform,
6541 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
6542 true, false, true);
6543 SetLayerPropertiesForTesting(scroll_child, identity_transform, gfx::Point3F(),
6544 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]995708c52013-10-17 20:52:596545 false);
6546
enne03b0e9a2015-06-19 00:08:026547 ExecuteCalculateDrawProperties(root);
[email protected]995708c52013-10-17 20:52:596548
6549 EXPECT_TRUE(root->render_surface());
6550
6551 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
6552 scroll_child->clip_rect().ToString());
6553 EXPECT_TRUE(scroll_child->is_clipped());
6554
6555 // Despite the fact that we had to process the layers out of order to get the
6556 // right clip, our render_surface_layer_list's order should be unaffected.
enne03b0e9a2015-06-19 00:08:026557 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
6558 EXPECT_EQ(root, render_surface_layer_list_impl()->at(0));
6559 EXPECT_EQ(render_surface2, render_surface_layer_list_impl()->at(1));
6560 EXPECT_EQ(render_surface1, render_surface_layer_list_impl()->at(2));
6561 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
6562 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
6563 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:596564}
6565
ajuma0b10f942015-03-21 07:45:536566TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
6567 // Ensures that when we have a render surface between a fixed position layer
6568 // and its container, we compute the fixed position layer's draw transform
6569 // with respect to that intervening render surface, not with respect to its
6570 // container's render target.
6571 //
6572 // + root
6573 // + render_surface
6574 // + fixed
ajuma737b2702015-05-06 01:18:376575 // + child
ajuma0b10f942015-03-21 07:45:536576 //
loysoa6edaaff2015-05-25 03:26:446577 scoped_refptr<Layer> root = Layer::Create(layer_settings());
ajuma0b10f942015-03-21 07:45:536578 scoped_refptr<LayerWithForcedDrawsContent> render_surface =
loysoa6edaaff2015-05-25 03:26:446579 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma0b10f942015-03-21 07:45:536580 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:446581 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma737b2702015-05-06 01:18:376582 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:446583 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma0b10f942015-03-21 07:45:536584
6585 root->AddChild(render_surface);
6586 render_surface->AddChild(fixed);
ajuma737b2702015-05-06 01:18:376587 fixed->AddChild(child);
ajuma0b10f942015-03-21 07:45:536588
6589 root->SetIsContainerForFixedPositionLayers(true);
6590 render_surface->SetForceRenderSurface(true);
6591
6592 LayerPositionConstraint constraint;
6593 constraint.set_is_fixed_position(true);
6594 fixed->SetPositionConstraint(constraint);
6595
6596 SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(),
6597 gfx::PointF(), gfx::Size(50, 50), true, false);
6598 SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(),
6599 gfx::Point3F(), gfx::PointF(7.f, 9.f),
6600 gfx::Size(50, 50), true, false);
6601 SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(),
6602 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true,
6603 false);
ajuma737b2702015-05-06 01:18:376604 SetLayerPropertiesForTesting(child.get(), gfx::Transform(), gfx::Point3F(),
6605 gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true,
6606 false);
ajuma0b10f942015-03-21 07:45:536607
ennea7b43c32015-06-18 20:01:336608 host()->SetRootLayer(root);
ajuma0b10f942015-03-21 07:45:536609
6610 ExecuteCalculateDrawProperties(root.get());
6611
ennef6903532015-08-18 05:10:156612 TransformTree& tree = host()->property_trees()->transform_tree;
6613
ajuma737b2702015-05-06 01:18:376614 gfx::Transform expected_fixed_draw_transform;
6615 expected_fixed_draw_transform.Translate(10.f, 15.f);
ennef6903532015-08-18 05:10:156616 EXPECT_EQ(expected_fixed_draw_transform,
6617 DrawTransformFromPropertyTrees(fixed.get(), tree));
ajuma0b10f942015-03-21 07:45:536618
ajuma737b2702015-05-06 01:18:376619 gfx::Transform expected_fixed_screen_space_transform;
6620 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
6621 EXPECT_EQ(expected_fixed_screen_space_transform,
ennef6903532015-08-18 05:10:156622 ScreenSpaceTransformFromPropertyTrees(fixed.get(), tree));
ajuma737b2702015-05-06 01:18:376623
6624 gfx::Transform expected_child_draw_transform;
6625 expected_child_draw_transform.Translate(11.f, 17.f);
ennef6903532015-08-18 05:10:156626 EXPECT_EQ(expected_child_draw_transform,
6627 DrawTransformFromPropertyTrees(child.get(), tree));
ajuma737b2702015-05-06 01:18:376628
6629 gfx::Transform expected_child_screen_space_transform;
6630 expected_child_screen_space_transform.Translate(18.f, 26.f);
6631 EXPECT_EQ(expected_child_screen_space_transform,
ennef6903532015-08-18 05:10:156632 ScreenSpaceTransformFromPropertyTrees(child.get(), tree));
ajuma0b10f942015-03-21 07:45:536633}
6634
[email protected]d81752b2013-10-25 08:32:236635TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
6636 // This test verifies that a scrolling layer that gets snapped to
6637 // integer coordinates doesn't move a fixed position child.
6638 //
6639 // + root
6640 // + container
6641 // + scroller
6642 // + fixed
6643 //
khushalsagarb64b360d2015-10-21 19:25:166644 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]4e2eb352014-03-20 17:25:456645 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:566646 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:166647 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:566648 &task_graph_runner);
[email protected]d81752b2013-10-25 08:32:236649 host_impl.CreatePendingTree();
6650 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
6651 scoped_ptr<LayerImpl> container =
6652 LayerImpl::Create(host_impl.active_tree(), 2);
6653 LayerImpl* container_layer = container.get();
6654 scoped_ptr<LayerImpl> scroller =
6655 LayerImpl::Create(host_impl.active_tree(), 3);
6656 LayerImpl* scroll_layer = scroller.get();
6657 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
6658 LayerImpl* fixed_layer = fixed.get();
6659
6660 container->SetIsContainerForFixedPositionLayers(true);
6661
6662 LayerPositionConstraint constraint;
6663 constraint.set_is_fixed_position(true);
6664 fixed->SetPositionConstraint(constraint);
6665
[email protected]adeda572014-01-31 00:49:476666 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:236667
6668 gfx::Transform identity_transform;
6669 gfx::Transform container_transform;
6670 container_transform.Translate3d(10.0, 20.0, 0.0);
6671 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
6672
awoloszyne83f28c2014-12-22 15:40:006673 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
6674 gfx::PointF(), gfx::Size(50, 50), true, false,
6675 true);
6676 SetLayerPropertiesForTesting(container.get(), container_transform,
6677 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6678 true, false, false);
6679 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
6680 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6681 true, false, false);
6682 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
6683 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]d81752b2013-10-25 08:32:236684 false);
6685
jaydasika0d98ba92015-11-17 05:17:286686 root->SetDrawsContent(true);
6687 container->SetDrawsContent(true);
6688 scroller->SetDrawsContent(true);
6689 fixed->SetDrawsContent(true);
danakja04855a2015-11-18 20:39:106690 scroller->AddChild(std::move(fixed));
6691 container->AddChild(std::move(scroller));
6692 root->AddChild(std::move(container));
[email protected]d81752b2013-10-25 08:32:236693
6694 // Rounded to integers already.
6695 {
6696 gfx::Vector2dF scroll_delta(3.0, 5.0);
6697 scroll_layer->SetScrollDelta(scroll_delta);
6698
6699 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:446700 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]d81752b2013-10-25 08:32:236701 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:446702 root.get(), root->bounds(), &render_surface_layer_list,
6703 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]d81752b2013-10-25 08:32:236704 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6705
6706 EXPECT_TRANSFORMATION_MATRIX_EQ(
6707 container_layer->draw_properties().screen_space_transform,
6708 fixed_layer->draw_properties().screen_space_transform);
6709 EXPECT_VECTOR_EQ(
6710 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6711 container_offset);
6712 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6713 .screen_space_transform.To2dTranslation(),
6714 container_offset - scroll_delta);
6715 }
6716
6717 // Scroll delta requiring rounding.
6718 {
6719 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
6720 scroll_layer->SetScrollDelta(scroll_delta);
6721
6722 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
6723
6724 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:446725 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]d81752b2013-10-25 08:32:236726 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:446727 root.get(), root->bounds(), &render_surface_layer_list,
6728 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]d81752b2013-10-25 08:32:236729 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6730
6731 EXPECT_TRANSFORMATION_MATRIX_EQ(
6732 container_layer->draw_properties().screen_space_transform,
6733 fixed_layer->draw_properties().screen_space_transform);
6734 EXPECT_VECTOR_EQ(
6735 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6736 container_offset);
6737 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
6738 .screen_space_transform.To2dTranslation(),
6739 container_offset - rounded_scroll_delta);
6740 }
[email protected]cf15ad7b2014-04-02 03:59:266741
6742 // Scale is applied earlier in the tree.
6743 {
6744 gfx::Transform scaled_container_transform = container_transform;
jaydasika0d98ba92015-11-17 05:17:286745 scaled_container_transform.Scale3d(2.0, 2.0, 1.0);
[email protected]cf15ad7b2014-04-02 03:59:266746 container_layer->SetTransform(scaled_container_transform);
jaydasika0d98ba92015-11-17 05:17:286747 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
6748 root->layer_tree_impl()
6749 ->property_trees()
6750 ->transform_tree.set_source_to_parent_updates_allowed(true);
[email protected]cf15ad7b2014-04-02 03:59:266751
6752 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
6753 scroll_layer->SetScrollDelta(scroll_delta);
6754
6755 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:446756 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]cf15ad7b2014-04-02 03:59:266757 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:446758 root.get(), root->bounds(), &render_surface_layer_list,
6759 root->layer_tree_impl()->current_render_surface_list_id());
[email protected]cf15ad7b2014-04-02 03:59:266760 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6761
6762 EXPECT_TRANSFORMATION_MATRIX_EQ(
6763 container_layer->draw_properties().screen_space_transform,
6764 fixed_layer->draw_properties().screen_space_transform);
6765 EXPECT_VECTOR_EQ(
6766 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6767 container_offset);
6768
6769 container_layer->SetTransform(container_transform);
6770 }
[email protected]d81752b2013-10-25 08:32:236771}
6772
miletus2c78036b2015-01-29 20:52:376773TEST_F(LayerTreeHostCommonTest,
6774 ScrollCompensationMainScrollOffsetFractionalPart) {
6775 // This test verifies that a scrolling layer that has fractional scroll offset
6776 // from main doesn't move a fixed position child.
6777 //
6778 // + root
6779 // + container
6780 // + scroller
6781 // + fixed
6782 //
khushalsagarb64b360d2015-10-21 19:25:166783 FakeImplTaskRunnerProvider task_runner_provider;
miletus2c78036b2015-01-29 20:52:376784 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:566785 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:166786 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:566787 &task_graph_runner);
miletus2c78036b2015-01-29 20:52:376788 host_impl.CreatePendingTree();
6789 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
6790 scoped_ptr<LayerImpl> container =
6791 LayerImpl::Create(host_impl.active_tree(), 2);
6792 LayerImpl* container_layer = container.get();
6793 scoped_ptr<LayerImpl> scroller =
6794 LayerImpl::Create(host_impl.active_tree(), 3);
6795 LayerImpl* scroll_layer = scroller.get();
6796 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
6797 LayerImpl* fixed_layer = fixed.get();
6798
6799 container->SetIsContainerForFixedPositionLayers(true);
6800
6801 LayerPositionConstraint constraint;
6802 constraint.set_is_fixed_position(true);
jaydasika8640f9f2015-11-10 01:34:366803 container->SetDrawsContent(true);
6804 fixed->SetDrawsContent(true);
miletus2c78036b2015-01-29 20:52:376805 fixed->SetPositionConstraint(constraint);
6806
jaydasika8640f9f2015-11-10 01:34:366807 scroller->SetDrawsContent(true);
miletus2c78036b2015-01-29 20:52:376808 scroller->SetScrollClipLayer(container->id());
6809
6810 gfx::Transform identity_transform;
6811 gfx::Transform container_transform;
6812 container_transform.Translate3d(10.0, 20.0, 0.0);
6813 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
6814
6815 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
6816 gfx::PointF(), gfx::Size(50, 50), true, false,
6817 true);
6818 SetLayerPropertiesForTesting(container.get(), container_transform,
6819 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
6820 true, false, false);
6821 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
6822 gfx::Point3F(), gfx::PointF(0.0, 0.0),
6823 gfx::Size(30, 30), true, false, false);
6824
6825 gfx::ScrollOffset scroll_offset(3.3, 4.2);
6826 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f);
6827 gfx::Vector2dF scroll_delta(0.1f, 0.4f);
6828 // Blink only uses the integer part of the scroll_offset for fixed
6829 // position layer.
6830 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
6831 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true,
6832 false, false);
aeliasf998da82015-02-03 01:40:516833 scroll_layer->PushScrollOffsetFromMainThread(scroll_offset);
aeliasd0070ba2015-01-31 13:44:496834 scroll_layer->SetScrollDelta(scroll_delta);
miletusff93ab72015-01-30 04:30:446835 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part);
miletus2c78036b2015-01-29 20:52:376836
danakja04855a2015-11-18 20:39:106837 scroller->AddChild(std::move(fixed));
6838 container->AddChild(std::move(scroller));
6839 root->AddChild(std::move(container));
miletus2c78036b2015-01-29 20:52:376840
6841 LayerImplList render_surface_layer_list;
ajumad9432e32015-11-30 19:43:446842 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
miletus2c78036b2015-01-29 20:52:376843 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:446844 root.get(), root->bounds(), &render_surface_layer_list,
6845 root->layer_tree_impl()->current_render_surface_list_id());
miletus2c78036b2015-01-29 20:52:376846 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6847
6848 EXPECT_TRANSFORMATION_MATRIX_EQ(
6849 container_layer->draw_properties().screen_space_transform,
6850 fixed_layer->draw_properties().screen_space_transform);
6851 EXPECT_VECTOR_EQ(
6852 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
6853 container_offset);
6854
6855 gfx::ScrollOffset effective_scroll_offset =
6856 ScrollOffsetWithDelta(scroll_offset, scroll_delta);
6857 gfx::Vector2d rounded_effective_scroll_offset =
6858 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset));
6859 EXPECT_VECTOR_EQ(
6860 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(),
6861 container_offset - rounded_effective_scroll_offset);
6862}
6863
ajuma5e8e40d2015-07-31 01:50:506864TEST_F(LayerTreeHostCommonTest,
6865 ScrollSnappingWithAnimatedScreenSpaceTransform) {
6866 // This test verifies that a scrolling layer whose screen space transform is
6867 // animating doesn't get snapped to integer coordinates.
6868 //
6869 // + root
6870 // + animated layer
6871 // + surface
6872 // + container
6873 // + scroller
6874 //
6875 LayerImpl* root = root_layer();
6876 LayerImpl* animated_layer = AddChildToRoot<FakePictureLayerImpl>();
6877 LayerImpl* surface = AddChild<LayerImpl>(animated_layer);
6878 LayerImpl* container = AddChild<LayerImpl>(surface);
6879 LayerImpl* scroller = AddChild<LayerImpl>(container);
6880 scroller->SetScrollClipLayer(container->id());
6881 scroller->SetDrawsContent(true);
6882
6883 gfx::Transform identity_transform;
6884 gfx::Transform start_scale;
6885 start_scale.Scale(1.5f, 1.5f);
6886 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(),
6887 gfx::PointF(), gfx::Size(50, 50), true, false,
6888 true);
6889 SetLayerPropertiesForTesting(animated_layer, start_scale, gfx::Point3F(),
6890 gfx::PointF(), gfx::Size(50, 50), true, false,
6891 false);
6892 SetLayerPropertiesForTesting(surface, identity_transform, gfx::Point3F(),
6893 gfx::PointF(), gfx::Size(50, 50), true, false,
6894 true);
6895 SetLayerPropertiesForTesting(container, identity_transform, gfx::Point3F(),
6896 gfx::PointF(), gfx::Size(50, 50), true, false,
6897 false);
6898 SetLayerPropertiesForTesting(scroller, identity_transform, gfx::Point3F(),
6899 gfx::PointF(), gfx::Size(100, 100), true, false,
6900 false);
6901
6902 gfx::Transform end_scale;
6903 end_scale.Scale(2.f, 2.f);
6904 TransformOperations start_operations;
6905 start_operations.AppendMatrix(start_scale);
6906 TransformOperations end_operations;
6907 end_operations.AppendMatrix(end_scale);
6908 AddAnimatedTransformToLayer(animated_layer, 1.0, start_operations,
6909 end_operations);
6910
6911 gfx::Vector2dF scroll_delta(5.f, 9.f);
6912 scroller->SetScrollDelta(scroll_delta);
6913
6914 ExecuteCalculateDrawProperties(root);
6915
6916 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f);
6917 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation,
ajumad9432e32015-11-30 19:43:446918 scroller->DrawTransform().To2dTranslation());
ajuma5e8e40d2015-07-31 01:50:506919}
6920
[email protected]1c3626e2014-04-09 17:49:226921class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
6922 public:
6923 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
6924 LayerTreeImpl* tree_impl,
6925 int id) {
6926 return make_scoped_ptr(
6927 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
6928 }
6929
dcheng716bedf2014-10-21 09:51:086930 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:226931
[email protected]1c3626e2014-04-09 17:49:226932 private:
6933 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
6934 int id)
[email protected]a57cb8b12014-06-13 18:15:376935 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:226936 SetDrawsContent(true);
6937 }
[email protected]1c3626e2014-04-09 17:49:226938};
6939
6940TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
khushalsagarb64b360d2015-10-21 19:25:166941 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]1c3626e2014-04-09 17:49:226942 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:566943 TestTaskGraphRunner task_graph_runner;
ajumab4a846f22015-08-24 19:13:446944 LayerTreeSettings settings;
6945 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:166946 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
6947 &shared_bitmap_manager, &task_graph_runner);
[email protected]1c3626e2014-04-09 17:49:226948 gfx::Transform identity_matrix;
6949 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
6950 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
6951 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
6952 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
6953 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
6954 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
6955 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
6956 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
6957
6958 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
6959 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
6960 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
6961
danakja04855a2015-11-18 20:39:106962 child->AddChild(std::move(grand_child));
6963 parent->AddChild(std::move(child));
6964 grand_parent->AddChild(std::move(parent));
[email protected]1c3626e2014-04-09 17:49:226965
awoloszyne83f28c2014-12-22 15:40:006966 SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix,
6967 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6968 true, false, true);
6969 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
6970 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:226971 false);
awoloszyne83f28c2014-12-22 15:40:006972 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
6973 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:226974 false);
awoloszyne83f28c2014-12-22 15:40:006975
6976 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
6977 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:226978 false);
6979
6980 ExecuteCalculateDrawProperties(grand_parent.get());
6981
6982 // No layers have animations.
[email protected]a57cb8b12014-06-13 18:15:376983 EXPECT_EQ(0.f,
6984 grand_parent->draw_properties().maximum_animation_contents_scale);
6985 EXPECT_EQ(0.f,
6986 parent_raw->draw_properties().maximum_animation_contents_scale);
6987 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
6988 EXPECT_EQ(
6989 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:226990
ajuma052892e2015-08-21 14:39:036991 EXPECT_EQ(0.f,
6992 grand_parent->draw_properties().starting_animation_contents_scale);
6993 EXPECT_EQ(0.f,
6994 parent_raw->draw_properties().starting_animation_contents_scale);
6995 EXPECT_EQ(0.f,
6996 child_raw->draw_properties().starting_animation_contents_scale);
6997 EXPECT_EQ(
6998 0.f,
6999 grand_child_raw->draw_properties().starting_animation_contents_scale);
7000
[email protected]1c3626e2014-04-09 17:49:227001 TransformOperations translation;
7002 translation.AppendTranslate(1.f, 2.f, 3.f);
7003
7004 AddAnimatedTransformToLayer(
7005 parent_raw, 1.0, TransformOperations(), translation);
7006
7007 // No layers have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377008 EXPECT_EQ(0.f,
7009 grand_parent->draw_properties().maximum_animation_contents_scale);
7010 EXPECT_EQ(0.f,
7011 parent_raw->draw_properties().maximum_animation_contents_scale);
7012 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7013 EXPECT_EQ(
7014 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227015
ajuma052892e2015-08-21 14:39:037016 EXPECT_EQ(0.f,
7017 grand_parent->draw_properties().starting_animation_contents_scale);
7018 EXPECT_EQ(0.f,
7019 parent_raw->draw_properties().starting_animation_contents_scale);
7020 EXPECT_EQ(0.f,
7021 child_raw->draw_properties().starting_animation_contents_scale);
7022 EXPECT_EQ(
7023 0.f,
7024 grand_child_raw->draw_properties().starting_animation_contents_scale);
7025
[email protected]1c3626e2014-04-09 17:49:227026 TransformOperations scale;
7027 scale.AppendScale(5.f, 4.f, 3.f);
7028
7029 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
ajumacaaa9b32015-08-04 15:55:297030 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227031 ExecuteCalculateDrawProperties(grand_parent.get());
7032
7033 // Only |child| has a scale-affecting animation.
[email protected]a57cb8b12014-06-13 18:15:377034 EXPECT_EQ(0.f,
7035 grand_parent->draw_properties().maximum_animation_contents_scale);
7036 EXPECT_EQ(0.f,
7037 parent_raw->draw_properties().maximum_animation_contents_scale);
7038 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
7039 EXPECT_EQ(
7040 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227041
ajuma052892e2015-08-21 14:39:037042 EXPECT_EQ(0.f,
7043 grand_parent->draw_properties().starting_animation_contents_scale);
7044 EXPECT_EQ(0.f,
7045 parent_raw->draw_properties().starting_animation_contents_scale);
7046 EXPECT_EQ(1.f,
7047 child_raw->draw_properties().starting_animation_contents_scale);
7048 EXPECT_EQ(
7049 1.f,
7050 grand_child_raw->draw_properties().starting_animation_contents_scale);
7051
[email protected]1c3626e2014-04-09 17:49:227052 AddAnimatedTransformToLayer(
7053 grand_parent.get(), 1.0, TransformOperations(), scale);
ajumacaaa9b32015-08-04 15:55:297054 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227055 ExecuteCalculateDrawProperties(grand_parent.get());
7056
7057 // |grand_parent| and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377058 EXPECT_EQ(5.f,
7059 grand_parent->draw_properties().maximum_animation_contents_scale);
7060 EXPECT_EQ(5.f,
7061 parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227062 // We don't support combining animated scales from two nodes; 0.f means
7063 // that the maximum scale could not be computed.
[email protected]a57cb8b12014-06-13 18:15:377064 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7065 EXPECT_EQ(
7066 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227067
ajuma052892e2015-08-21 14:39:037068 EXPECT_EQ(1.f,
7069 grand_parent->draw_properties().starting_animation_contents_scale);
7070 EXPECT_EQ(1.f,
7071 parent_raw->draw_properties().starting_animation_contents_scale);
7072 EXPECT_EQ(0.f,
7073 child_raw->draw_properties().starting_animation_contents_scale);
7074 EXPECT_EQ(
7075 0.f,
7076 grand_child_raw->draw_properties().starting_animation_contents_scale);
7077
[email protected]1c3626e2014-04-09 17:49:227078 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
ajumacaaa9b32015-08-04 15:55:297079 parent_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227080 ExecuteCalculateDrawProperties(grand_parent.get());
7081
7082 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377083 EXPECT_EQ(5.f,
7084 grand_parent->draw_properties().maximum_animation_contents_scale);
7085 EXPECT_EQ(0.f,
7086 parent_raw->draw_properties().maximum_animation_contents_scale);
7087 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7088 EXPECT_EQ(
7089 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227090
ajuma052892e2015-08-21 14:39:037091 EXPECT_EQ(1.f,
7092 grand_parent->draw_properties().starting_animation_contents_scale);
7093 EXPECT_EQ(0.f,
7094 parent_raw->draw_properties().starting_animation_contents_scale);
7095 EXPECT_EQ(0.f,
7096 child_raw->draw_properties().starting_animation_contents_scale);
7097 EXPECT_EQ(
7098 0.f,
7099 grand_child_raw->draw_properties().starting_animation_contents_scale);
7100
[email protected]1c3626e2014-04-09 17:49:227101 grand_parent->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:387102 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227103 parent_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:387104 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227105 child_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:387106 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227107
7108 TransformOperations perspective;
7109 perspective.AppendPerspective(10.f);
7110
7111 AddAnimatedTransformToLayer(
7112 child_raw, 1.0, TransformOperations(), perspective);
ajumab4a846f22015-08-24 19:13:447113 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227114 ExecuteCalculateDrawProperties(grand_parent.get());
7115
7116 // |child| has a scale-affecting animation but computing the maximum of this
7117 // animation is not supported.
[email protected]a57cb8b12014-06-13 18:15:377118 EXPECT_EQ(0.f,
7119 grand_parent->draw_properties().maximum_animation_contents_scale);
7120 EXPECT_EQ(0.f,
7121 parent_raw->draw_properties().maximum_animation_contents_scale);
7122 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7123 EXPECT_EQ(
7124 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227125
ajuma052892e2015-08-21 14:39:037126 EXPECT_EQ(0.f,
7127 grand_parent->draw_properties().starting_animation_contents_scale);
7128 EXPECT_EQ(0.f,
7129 parent_raw->draw_properties().starting_animation_contents_scale);
7130 EXPECT_EQ(0.f,
7131 child_raw->draw_properties().starting_animation_contents_scale);
7132 EXPECT_EQ(
7133 0.f,
7134 grand_child_raw->draw_properties().starting_animation_contents_scale);
7135
[email protected]1c3626e2014-04-09 17:49:227136 child_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:387137 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:227138
7139 gfx::Transform scale_matrix;
7140 scale_matrix.Scale(1.f, 2.f);
7141 grand_parent->SetTransform(scale_matrix);
7142 parent_raw->SetTransform(scale_matrix);
miletus843080c2015-06-11 22:11:017143 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227144 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
7145 ExecuteCalculateDrawProperties(grand_parent.get());
7146
7147 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
7148 // animation with maximum scale 5.f.
[email protected]a57cb8b12014-06-13 18:15:377149 EXPECT_EQ(0.f,
7150 grand_parent->draw_properties().maximum_animation_contents_scale);
7151 EXPECT_EQ(10.f,
7152 parent_raw->draw_properties().maximum_animation_contents_scale);
7153 EXPECT_EQ(10.f,
7154 child_raw->draw_properties().maximum_animation_contents_scale);
7155 EXPECT_EQ(
7156 10.f,
7157 grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227158
ajuma052892e2015-08-21 14:39:037159 EXPECT_EQ(0.f,
7160 grand_parent->draw_properties().starting_animation_contents_scale);
7161 EXPECT_EQ(2.f,
7162 parent_raw->draw_properties().starting_animation_contents_scale);
7163 EXPECT_EQ(2.f,
7164 child_raw->draw_properties().starting_animation_contents_scale);
7165 EXPECT_EQ(
7166 2.f,
7167 grand_child_raw->draw_properties().starting_animation_contents_scale);
7168
[email protected]1c3626e2014-04-09 17:49:227169 gfx::Transform perspective_matrix;
7170 perspective_matrix.ApplyPerspectiveDepth(2.f);
7171 child_raw->SetTransform(perspective_matrix);
miletus843080c2015-06-11 22:11:017172 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227173 ExecuteCalculateDrawProperties(grand_parent.get());
7174
7175 // |child| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:377176 EXPECT_EQ(0.f,
7177 grand_parent->draw_properties().maximum_animation_contents_scale);
7178 EXPECT_EQ(10.f,
7179 parent_raw->draw_properties().maximum_animation_contents_scale);
7180 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7181 EXPECT_EQ(
7182 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227183
ajuma052892e2015-08-21 14:39:037184 EXPECT_EQ(0.f,
7185 grand_parent->draw_properties().starting_animation_contents_scale);
7186 EXPECT_EQ(2.f,
7187 parent_raw->draw_properties().starting_animation_contents_scale);
7188 EXPECT_EQ(0.f,
7189 child_raw->draw_properties().starting_animation_contents_scale);
7190 EXPECT_EQ(
7191 0.f,
7192 grand_child_raw->draw_properties().starting_animation_contents_scale);
7193
[email protected]1c3626e2014-04-09 17:49:227194 parent_raw->SetTransform(perspective_matrix);
miletus843080c2015-06-11 22:11:017195 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227196 ExecuteCalculateDrawProperties(grand_parent.get());
7197
7198 // |parent| and |child| have transforms that are neither translations nor
7199 // scales.
[email protected]a57cb8b12014-06-13 18:15:377200 EXPECT_EQ(0.f,
7201 grand_parent->draw_properties().maximum_animation_contents_scale);
7202 EXPECT_EQ(0.f,
7203 parent_raw->draw_properties().maximum_animation_contents_scale);
7204 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7205 EXPECT_EQ(
7206 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227207
ajuma052892e2015-08-21 14:39:037208 EXPECT_EQ(0.f,
7209 grand_parent->draw_properties().starting_animation_contents_scale);
7210 EXPECT_EQ(0.f,
7211 parent_raw->draw_properties().starting_animation_contents_scale);
7212 EXPECT_EQ(0.f,
7213 child_raw->draw_properties().starting_animation_contents_scale);
7214 EXPECT_EQ(
7215 0.f,
7216 grand_child_raw->draw_properties().starting_animation_contents_scale);
7217
[email protected]1c3626e2014-04-09 17:49:227218 parent_raw->SetTransform(identity_matrix);
7219 child_raw->SetTransform(identity_matrix);
7220 grand_parent->SetTransform(perspective_matrix);
miletus843080c2015-06-11 22:11:017221 grand_parent->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]1c3626e2014-04-09 17:49:227222
7223 ExecuteCalculateDrawProperties(grand_parent.get());
7224
7225 // |grand_parent| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:377226 EXPECT_EQ(0.f,
7227 grand_parent->draw_properties().maximum_animation_contents_scale);
7228 EXPECT_EQ(0.f,
7229 parent_raw->draw_properties().maximum_animation_contents_scale);
7230 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7231 EXPECT_EQ(
7232 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
ajuma052892e2015-08-21 14:39:037233
7234 EXPECT_EQ(0.f,
7235 grand_parent->draw_properties().starting_animation_contents_scale);
7236 EXPECT_EQ(0.f,
7237 parent_raw->draw_properties().starting_animation_contents_scale);
7238 EXPECT_EQ(0.f,
7239 child_raw->draw_properties().starting_animation_contents_scale);
7240 EXPECT_EQ(
7241 0.f,
7242 grand_child_raw->draw_properties().starting_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227243}
7244
[email protected]390bb1ff2014-05-09 17:14:407245static int membership_id(LayerImpl* layer) {
7246 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
7247}
7248
7249static void GatherDrawnLayers(LayerImplList* rsll,
7250 std::set<LayerImpl*>* drawn_layers) {
enne389d1a12015-06-18 20:40:517251 for (LayerIterator it = LayerIterator::Begin(rsll),
7252 end = LayerIterator::End(rsll);
7253 it != end; ++it) {
[email protected]390bb1ff2014-05-09 17:14:407254 LayerImpl* layer = *it;
7255 if (it.represents_itself())
7256 drawn_layers->insert(layer);
7257
7258 if (!it.represents_contributing_render_surface())
7259 continue;
7260
7261 if (layer->mask_layer())
7262 drawn_layers->insert(layer->mask_layer());
7263 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
7264 drawn_layers->insert(layer->replica_layer()->mask_layer());
7265 }
7266}
7267
7268TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
khushalsagarb64b360d2015-10-21 19:25:167269 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]390bb1ff2014-05-09 17:14:407270 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567271 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167272 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567273 &task_graph_runner);
[email protected]390bb1ff2014-05-09 17:14:407274 gfx::Transform identity_matrix;
7275
7276 scoped_ptr<LayerImpl> grand_parent =
7277 LayerImpl::Create(host_impl.active_tree(), 1);
7278 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
7279 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
7280 scoped_ptr<LayerImpl> grand_child1 =
7281 LayerImpl::Create(host_impl.active_tree(), 7);
7282 scoped_ptr<LayerImpl> grand_child2 =
7283 LayerImpl::Create(host_impl.active_tree(), 9);
7284
7285 LayerImpl* grand_parent_raw = grand_parent.get();
7286 LayerImpl* parent_raw = parent.get();
7287 LayerImpl* child_raw = child.get();
7288 LayerImpl* grand_child1_raw = grand_child1.get();
7289 LayerImpl* grand_child2_raw = grand_child2.get();
7290
danakja04855a2015-11-18 20:39:107291 child->AddChild(std::move(grand_child1));
7292 child->AddChild(std::move(grand_child2));
7293 parent->AddChild(std::move(child));
7294 grand_parent->AddChild(std::move(parent));
[email protected]390bb1ff2014-05-09 17:14:407295
awoloszyne83f28c2014-12-22 15:40:007296 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
7297 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7298 true, false, true);
7299 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7300 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:407301 false);
awoloszyne83f28c2014-12-22 15:40:007302
7303 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7304 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:407305 false);
awoloszyne83f28c2014-12-22 15:40:007306
7307 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
7308 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7309 true, false, false);
7310
7311 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
7312 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7313 true, false, false);
[email protected]390bb1ff2014-05-09 17:14:407314
7315 // Start with nothing being drawn.
7316 ExecuteCalculateDrawProperties(grand_parent_raw);
7317 int member_id = render_surface_layer_list_count();
7318
7319 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7320 EXPECT_NE(member_id, membership_id(parent_raw));
7321 EXPECT_NE(member_id, membership_id(child_raw));
7322 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7323 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7324
7325 std::set<LayerImpl*> expected;
7326 std::set<LayerImpl*> actual;
7327 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7328 EXPECT_EQ(expected, actual);
7329
7330 // If we force render surface, but none of the layers are in the layer list,
7331 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:007332 grand_child1_raw->SetHasRenderSurface(true);
jaydasikaebf9e4ea2015-08-14 21:29:127333 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407334
7335 ExecuteCalculateDrawProperties(grand_parent_raw);
7336 member_id = render_surface_layer_list_count();
7337
7338 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7339 EXPECT_NE(member_id, membership_id(parent_raw));
7340 EXPECT_NE(member_id, membership_id(child_raw));
7341 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7342 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7343
7344 expected.clear();
7345 actual.clear();
7346 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7347 EXPECT_EQ(expected, actual);
7348
7349 // However, if we say that this layer also draws content, it will appear in
7350 // RSLL.
7351 grand_child1_raw->SetDrawsContent(true);
7352
7353 ExecuteCalculateDrawProperties(grand_parent_raw);
7354 member_id = render_surface_layer_list_count();
7355
7356 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7357 EXPECT_NE(member_id, membership_id(parent_raw));
7358 EXPECT_NE(member_id, membership_id(child_raw));
7359 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
7360 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7361
7362 expected.clear();
7363 expected.insert(grand_child1_raw);
7364
7365 actual.clear();
7366 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7367 EXPECT_EQ(expected, actual);
7368
7369 // Now child is forced to have a render surface, and one if its children draws
7370 // content.
7371 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:007372 grand_child1_raw->SetHasRenderSurface(false);
jaydasikaebf9e4ea2015-08-14 21:29:127373 grand_child1_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
awoloszyne83f28c2014-12-22 15:40:007374 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:407375 grand_child2_raw->SetDrawsContent(true);
7376
7377 ExecuteCalculateDrawProperties(grand_parent_raw);
7378 member_id = render_surface_layer_list_count();
7379
7380 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7381 EXPECT_NE(member_id, membership_id(parent_raw));
7382 EXPECT_NE(member_id, membership_id(child_raw));
7383 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7384 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7385
7386 expected.clear();
7387 expected.insert(grand_child2_raw);
7388
7389 actual.clear();
7390 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7391 EXPECT_EQ(expected, actual);
7392
7393 // Add a mask layer to child.
danakja5a05ba02015-11-20 20:14:217394 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
jaydasikad36e7fa2015-07-14 15:15:047395 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407396
7397 ExecuteCalculateDrawProperties(grand_parent_raw);
7398 member_id = render_surface_layer_list_count();
7399
7400 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7401 EXPECT_NE(member_id, membership_id(parent_raw));
7402 EXPECT_NE(member_id, membership_id(child_raw));
7403 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7404 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7405 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7406
7407 expected.clear();
7408 expected.insert(grand_child2_raw);
7409 expected.insert(child_raw->mask_layer());
7410
7411 expected.clear();
7412 expected.insert(grand_child2_raw);
7413 expected.insert(child_raw->mask_layer());
7414
7415 actual.clear();
7416 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7417 EXPECT_EQ(expected, actual);
7418
7419 // Add replica mask layer.
7420 scoped_ptr<LayerImpl> replica_layer =
7421 LayerImpl::Create(host_impl.active_tree(), 20);
7422 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
danakja04855a2015-11-18 20:39:107423 child_raw->SetReplicaLayer(std::move(replica_layer));
jaydasika23fb3822015-08-25 03:22:597424 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407425
7426 ExecuteCalculateDrawProperties(grand_parent_raw);
7427 member_id = render_surface_layer_list_count();
7428
7429 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7430 EXPECT_NE(member_id, membership_id(parent_raw));
7431 EXPECT_NE(member_id, membership_id(child_raw));
7432 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7433 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
7434 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7435 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7436
7437 expected.clear();
7438 expected.insert(grand_child2_raw);
7439 expected.insert(child_raw->mask_layer());
7440 expected.insert(child_raw->replica_layer()->mask_layer());
7441
7442 actual.clear();
7443 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7444 EXPECT_EQ(expected, actual);
7445
7446 child_raw->TakeReplicaLayer();
7447
7448 // With nothing drawing, we should have no layers.
7449 grand_child2_raw->SetDrawsContent(false);
7450
7451 ExecuteCalculateDrawProperties(grand_parent_raw);
7452 member_id = render_surface_layer_list_count();
7453
7454 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7455 EXPECT_NE(member_id, membership_id(parent_raw));
7456 EXPECT_NE(member_id, membership_id(child_raw));
7457 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
7458 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7459 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7460
7461 expected.clear();
7462 actual.clear();
7463 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7464 EXPECT_EQ(expected, actual);
7465
7466 // Child itself draws means that we should have the child and the mask in the
7467 // list.
7468 child_raw->SetDrawsContent(true);
7469
7470 ExecuteCalculateDrawProperties(grand_parent_raw);
7471 member_id = render_surface_layer_list_count();
7472
7473 EXPECT_NE(member_id, membership_id(grand_parent_raw));
7474 EXPECT_NE(member_id, membership_id(parent_raw));
7475 EXPECT_EQ(member_id, membership_id(child_raw));
7476 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
7477 EXPECT_NE(member_id, membership_id(grand_child1_raw));
7478 EXPECT_NE(member_id, membership_id(grand_child2_raw));
7479
7480 expected.clear();
7481 expected.insert(child_raw);
7482 expected.insert(child_raw->mask_layer());
7483 actual.clear();
7484 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7485 EXPECT_EQ(expected, actual);
7486
7487 child_raw->TakeMaskLayer();
jaydasikad36e7fa2015-07-14 15:15:047488 child_raw->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]390bb1ff2014-05-09 17:14:407489
7490 // Now everyone's a member!
7491 grand_parent_raw->SetDrawsContent(true);
7492 parent_raw->SetDrawsContent(true);
7493 child_raw->SetDrawsContent(true);
7494 grand_child1_raw->SetDrawsContent(true);
7495 grand_child2_raw->SetDrawsContent(true);
7496
7497 ExecuteCalculateDrawProperties(grand_parent_raw);
7498 member_id = render_surface_layer_list_count();
7499
7500 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
7501 EXPECT_EQ(member_id, membership_id(parent_raw));
7502 EXPECT_EQ(member_id, membership_id(child_raw));
7503 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
7504 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
7505
7506 expected.clear();
7507 expected.insert(grand_parent_raw);
7508 expected.insert(parent_raw);
7509 expected.insert(child_raw);
7510 expected.insert(grand_child1_raw);
7511 expected.insert(grand_child2_raw);
7512
7513 actual.clear();
7514 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
7515 EXPECT_EQ(expected, actual);
7516}
[email protected]18e69652014-06-13 12:50:587517
7518TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
khushalsagarb64b360d2015-10-21 19:25:167519 FakeImplTaskRunnerProvider task_runner_provider;
[email protected]18e69652014-06-13 12:50:587520 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567521 TestTaskGraphRunner task_graph_runner;
enne637715732015-07-07 02:05:267522 LayerTreeSettings settings;
7523 settings.layer_transforms_should_scale_layer_contents = true;
khushalsagarb64b360d2015-10-21 19:25:167524 FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider,
7525 &shared_bitmap_manager, &task_graph_runner);
[email protected]18e69652014-06-13 12:50:587526
7527 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7528 LayerImpl* root_layer = root.get();
7529 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
7530 LayerImpl* child1_layer = child1.get();
7531 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
7532 LayerImpl* child2_layer = child2.get();
7533
danakja04855a2015-11-18 20:39:107534 root->AddChild(std::move(child1));
7535 root->AddChild(std::move(child2));
awoloszyne83f28c2014-12-22 15:40:007536 root->SetHasRenderSurface(true);
jaydasika0d98ba92015-11-17 05:17:287537 root->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587538
7539 gfx::Transform identity_matrix, scale_transform_child1,
7540 scale_transform_child2;
7541 scale_transform_child1.Scale(2, 3);
7542 scale_transform_child2.Scale(4, 5);
7543
awoloszyne83f28c2014-12-22 15:40:007544 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
7545 gfx::PointF(), gfx::Size(1, 1), true, false,
7546 true);
7547 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
jaydasika0d98ba92015-11-17 05:17:287548 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1),
7549 true, false, false);
[email protected]18e69652014-06-13 12:50:587550
danakja5a05ba02015-11-20 20:14:217551 child1_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 4));
jaydasika0d98ba92015-11-17 05:17:287552 child1_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587553
7554 scoped_ptr<LayerImpl> replica_layer =
7555 LayerImpl::Create(host_impl.active_tree(), 5);
awoloszyne83f28c2014-12-22 15:40:007556 replica_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:587557 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
danakja04855a2015-11-18 20:39:107558 child1_layer->SetReplicaLayer(std::move(replica_layer));
awoloszyne83f28c2014-12-22 15:40:007559 child1_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:587560
7561 ExecuteCalculateDrawProperties(root_layer);
7562
7563 TransformOperations scale;
7564 scale.AppendScale(5.f, 8.f, 3.f);
7565
7566 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale);
awoloszyne83f28c2014-12-22 15:40:007567 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
jaydasika0d98ba92015-11-17 05:17:287568 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 1),
7569 true, false, false);
7570 child2_layer->SetDrawsContent(true);
[email protected]18e69652014-06-13 12:50:587571
jaydasika0d98ba92015-11-17 05:17:287572 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:587573 ExecuteCalculateDrawProperties(root_layer);
7574
enne637715732015-07-07 02:05:267575 EXPECT_FLOAT_EQ(1.f, root_layer->GetIdealContentsScale());
7576 EXPECT_FLOAT_EQ(3.f, child1_layer->GetIdealContentsScale());
7577 EXPECT_FLOAT_EQ(3.f, child1_layer->mask_layer()->GetIdealContentsScale());
7578 EXPECT_FLOAT_EQ(5.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587579
7580 EXPECT_FLOAT_EQ(
7581 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7582 EXPECT_FLOAT_EQ(
7583 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7584 EXPECT_FLOAT_EQ(0.f,
7585 child1_layer->mask_layer()
7586 ->draw_properties()
7587 .maximum_animation_contents_scale);
7588 EXPECT_FLOAT_EQ(0.f,
7589 child1_layer->replica_layer()
7590 ->mask_layer()
7591 ->draw_properties()
7592 .maximum_animation_contents_scale);
7593 EXPECT_FLOAT_EQ(
7594 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
7595
[email protected]18e69652014-06-13 12:50:587596 // Changing page-scale would affect ideal_contents_scale and
7597 // maximum_animation_contents_scale.
7598
7599 float page_scale_factor = 3.f;
7600 float device_scale_factor = 1.0f;
7601 std::vector<LayerImpl*> render_surface_layer_list;
7602 gfx::Size device_viewport_size =
7603 gfx::Size(root_layer->bounds().width() * device_scale_factor,
7604 root_layer->bounds().height() * device_scale_factor);
ajumad9432e32015-11-30 19:43:447605 root_layer->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
[email protected]18e69652014-06-13 12:50:587606 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:447607 root_layer, device_viewport_size, &render_surface_layer_list,
7608 root_layer->layer_tree_impl()->current_render_surface_list_id());
[email protected]18e69652014-06-13 12:50:587609
7610 inputs.page_scale_factor = page_scale_factor;
7611 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:117612 inputs.page_scale_layer = root_layer;
[email protected]18e69652014-06-13 12:50:587613 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7614
enne637715732015-07-07 02:05:267615 EXPECT_FLOAT_EQ(3.f, root_layer->GetIdealContentsScale());
7616 EXPECT_FLOAT_EQ(9.f, child1_layer->GetIdealContentsScale());
7617 EXPECT_FLOAT_EQ(9.f, child1_layer->mask_layer()->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587618 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267619 9.f,
7620 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
7621 EXPECT_FLOAT_EQ(15.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587622
7623 EXPECT_FLOAT_EQ(
7624 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7625 EXPECT_FLOAT_EQ(
7626 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7627 EXPECT_FLOAT_EQ(0.f,
7628 child1_layer->mask_layer()
7629 ->draw_properties()
7630 .maximum_animation_contents_scale);
7631 EXPECT_FLOAT_EQ(0.f,
7632 child1_layer->replica_layer()
7633 ->mask_layer()
7634 ->draw_properties()
7635 .maximum_animation_contents_scale);
7636 EXPECT_FLOAT_EQ(
7637 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
7638
[email protected]18e69652014-06-13 12:50:587639 // Changing device-scale would affect ideal_contents_scale and
7640 // maximum_animation_contents_scale.
7641
7642 device_scale_factor = 4.0f;
7643 inputs.device_scale_factor = device_scale_factor;
7644 inputs.can_adjust_raster_scales = true;
jaydasika0d98ba92015-11-17 05:17:287645 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
[email protected]18e69652014-06-13 12:50:587646 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7647
enne637715732015-07-07 02:05:267648 EXPECT_FLOAT_EQ(12.f, root_layer->GetIdealContentsScale());
7649 EXPECT_FLOAT_EQ(36.f, child1_layer->GetIdealContentsScale());
7650 EXPECT_FLOAT_EQ(36.f, child1_layer->mask_layer()->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587651 EXPECT_FLOAT_EQ(
enne637715732015-07-07 02:05:267652 36.f,
7653 child1_layer->replica_layer()->mask_layer()->GetIdealContentsScale());
7654 EXPECT_FLOAT_EQ(60.f, child2_layer->GetIdealContentsScale());
[email protected]18e69652014-06-13 12:50:587655
7656 EXPECT_FLOAT_EQ(
7657 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
7658 EXPECT_FLOAT_EQ(
7659 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
7660 EXPECT_FLOAT_EQ(0.f,
7661 child1_layer->mask_layer()
7662 ->draw_properties()
7663 .maximum_animation_contents_scale);
7664 EXPECT_FLOAT_EQ(0.f,
7665 child1_layer->replica_layer()
7666 ->mask_layer()
7667 ->draw_properties()
7668 .maximum_animation_contents_scale);
7669 EXPECT_FLOAT_EQ(
7670 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
[email protected]18e69652014-06-13 12:50:587671}
7672
danakjf6069db2014-09-13 00:46:477673TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
loysoa6edaaff2015-05-25 03:26:447674 scoped_refptr<Layer> root = Layer::Create(layer_settings());
danakjf6069db2014-09-13 00:46:477675 SetLayerPropertiesForTesting(root.get(),
7676 gfx::Transform(),
7677 gfx::Point3F(),
7678 gfx::PointF(),
7679 gfx::Size(768 / 2, 3000),
7680 true,
7681 false);
7682 root->SetIsDrawable(true);
7683
loysoa6edaaff2015-05-25 03:26:447684 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
danakjf6069db2014-09-13 00:46:477685 SetLayerPropertiesForTesting(clip.get(),
7686 gfx::Transform(),
7687 gfx::Point3F(),
7688 gfx::PointF(),
7689 gfx::Size(768 / 2, 10000),
7690 true,
7691 false);
7692 clip->SetMasksToBounds(true);
7693
loysoa6edaaff2015-05-25 03:26:447694 scoped_refptr<Layer> content = Layer::Create(layer_settings());
danakjf6069db2014-09-13 00:46:477695 SetLayerPropertiesForTesting(content.get(),
7696 gfx::Transform(),
7697 gfx::Point3F(),
7698 gfx::PointF(),
7699 gfx::Size(768 / 2, 10000),
7700 true,
7701 false);
7702 content->SetIsDrawable(true);
7703 content->SetForceRenderSurface(true);
7704
7705 root->AddChild(clip);
7706 clip->AddChild(content);
7707
ennea7b43c32015-06-18 20:01:337708 host()->SetRootLayer(root);
danakjf6069db2014-09-13 00:46:477709
7710 gfx::Size device_viewport_size(768, 582);
enne1e1008c2015-08-21 00:45:467711 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(host()->root_layer(),
7712 device_viewport_size);
danakjf6069db2014-09-13 00:46:477713 inputs.device_scale_factor = 2.f;
7714 inputs.page_scale_factor = 1.f;
enne6394d5b42015-05-26 22:23:117715 inputs.page_scale_layer = NULL;
danakjf6069db2014-09-13 00:46:477716 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7717
7718 // Layers in the root render surface have their visible content rect clipped
7719 // by the viewport.
weiliangc2d58b2c2015-07-29 00:42:437720 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
7721 root->visible_rect_from_property_trees());
danakjf6069db2014-09-13 00:46:477722
7723 // Layers drawing to a child render surface should still have their visible
7724 // content rect clipped by the viewport.
weiliangc2d58b2c2015-07-29 00:42:437725 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
7726 content->visible_rect_from_property_trees());
danakjf6069db2014-09-13 00:46:477727}
7728
timav599f4359d2014-12-05 00:12:227729TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
khushalsagarb64b360d2015-10-21 19:25:167730 FakeImplTaskRunnerProvider task_runner_provider;
timav599f4359d2014-12-05 00:12:227731 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:567732 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:167733 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:567734 &task_graph_runner);
timav599f4359d2014-12-05 00:12:227735
7736 // Set two layers: the root layer clips it's child,
7737 // the child draws its content.
7738
7739 gfx::Size root_size = gfx::Size(300, 500);
7740
7741 // Sublayer should be bigger than the root enlarged by bounds_delta.
7742 gfx::Size sublayer_size = gfx::Size(300, 1000);
7743
7744 // Device viewport accomidated the root and the top controls.
7745 gfx::Size device_viewport_size = gfx::Size(300, 600);
7746 gfx::Transform identity_matrix;
7747
miletus8bd08a622015-06-16 18:44:527748 host_impl.SetViewportSize(device_viewport_size);
timav599f4359d2014-12-05 00:12:227749 host_impl.active_tree()->SetRootLayer(
7750 LayerImpl::Create(host_impl.active_tree(), 1));
7751
7752 LayerImpl* root = host_impl.active_tree()->root_layer();
7753 SetLayerPropertiesForTesting(root,
7754 identity_matrix,
7755 gfx::Point3F(),
7756 gfx::PointF(),
7757 root_size,
7758 false,
awoloszyne83f28c2014-12-22 15:40:007759 false,
7760 true);
timav599f4359d2014-12-05 00:12:227761 root->SetMasksToBounds(true);
7762
7763 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
7764
7765 LayerImpl* sublayer = root->child_at(0);
7766 SetLayerPropertiesForTesting(sublayer,
7767 identity_matrix,
7768 gfx::Point3F(),
7769 gfx::PointF(),
7770 sublayer_size,
7771 false,
awoloszyne83f28c2014-12-22 15:40:007772 false,
timav599f4359d2014-12-05 00:12:227773 false);
timav599f4359d2014-12-05 00:12:227774 sublayer->SetDrawsContent(true);
7775
7776 LayerImplList layer_impl_list;
ajumad9432e32015-11-30 19:43:447777 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting();
timav599f4359d2014-12-05 00:12:227778 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
ajumad9432e32015-11-30 19:43:447779 root, device_viewport_size, &layer_impl_list,
7780 root->layer_tree_impl()->current_render_surface_list_id());
timav599f4359d2014-12-05 00:12:227781
7782 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
danakj64767d902015-06-19 00:10:437783 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:227784
7785 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
timav599f4359d2014-12-05 00:12:227786 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7787
7788 gfx::Rect affected_by_delta(0, 0, root_size.width(),
7789 root_size.height() + 50);
danakj64767d902015-06-19 00:10:437790 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect());
timav599f4359d2014-12-05 00:12:227791}
7792
ajumadd2802e72015-06-30 20:28:297793TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) {
7794 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7795 scoped_refptr<Layer> inner_viewport_container_layer =
7796 Layer::Create(layer_settings());
7797 scoped_refptr<Layer> inner_viewport_scroll_layer =
7798 Layer::Create(layer_settings());
7799 scoped_refptr<Layer> outer_viewport_container_layer =
7800 Layer::Create(layer_settings());
7801 scoped_refptr<Layer> outer_viewport_scroll_layer =
7802 Layer::Create(layer_settings());
7803
7804 root->AddChild(inner_viewport_container_layer);
7805 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer);
7806 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer);
7807 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer);
7808
7809 inner_viewport_scroll_layer->SetScrollClipLayerId(
7810 inner_viewport_container_layer->id());
7811 outer_viewport_scroll_layer->SetScrollClipLayerId(
7812 outer_viewport_container_layer->id());
7813
7814 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
7815 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true);
7816
7817 host()->SetRootLayer(root);
7818 host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer,
7819 outer_viewport_scroll_layer);
7820
7821 scoped_refptr<Layer> fixed_to_inner = Layer::Create(layer_settings());
7822 scoped_refptr<Layer> fixed_to_outer = Layer::Create(layer_settings());
7823
7824 inner_viewport_scroll_layer->AddChild(fixed_to_inner);
7825 outer_viewport_scroll_layer->AddChild(fixed_to_outer);
7826
7827 LayerPositionConstraint fixed_to_right;
7828 fixed_to_right.set_is_fixed_position(true);
7829 fixed_to_right.set_is_fixed_to_right_edge(true);
7830
7831 fixed_to_inner->SetPositionConstraint(fixed_to_right);
7832 fixed_to_outer->SetPositionConstraint(fixed_to_right);
7833
7834 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7835
7836 TransformTree& transform_tree = host()->property_trees()->transform_tree;
7837 EXPECT_TRUE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
7838 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
7839
7840 LayerPositionConstraint fixed_to_left;
7841 fixed_to_left.set_is_fixed_position(true);
7842 fixed_to_inner->SetPositionConstraint(fixed_to_left);
7843
7844 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7845 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
7846 EXPECT_TRUE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
7847
7848 fixed_to_outer->SetPositionConstraint(fixed_to_left);
7849
7850 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
7851 EXPECT_FALSE(transform_tree.HasNodesAffectedByInnerViewportBoundsDelta());
7852 EXPECT_FALSE(transform_tree.HasNodesAffectedByOuterViewportBoundsDelta());
7853}
7854
vollick7d83b452015-02-24 20:18:067855TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
7856 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:447857 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick7d83b452015-02-24 20:18:067858 scoped_refptr<LayerWithForcedDrawsContent> animated =
loysoa6edaaff2015-05-25 03:26:447859 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick7d83b452015-02-24 20:18:067860
7861 root->AddChild(animated);
7862
ennea7b43c32015-06-18 20:01:337863 host()->SetRootLayer(root);
vollick7d83b452015-02-24 20:18:067864
7865 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
7866 gfx::PointF(), gfx::Size(100, 100), true, false);
7867 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
7868 gfx::PointF(), gfx::Size(20, 20), true, false);
7869
7870 root->SetMasksToBounds(true);
7871 root->SetForceRenderSurface(true);
7872 animated->SetOpacity(0.f);
7873
7874 AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0,
7875 0.f, 1.f, false);
7876
enne601f2ef12015-05-19 18:20:177877 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick7d83b452015-02-24 20:18:067878
7879 EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty());
7880}
7881
ajumaa92fdc12015-03-31 22:47:417882TEST_F(LayerTreeHostCommonTest,
7883 VisibleContentRectForAnimatedLayerWithSingularTransform) {
7884 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:447885 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7886 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
ajumaa92fdc12015-03-31 22:47:417887 scoped_refptr<LayerWithForcedDrawsContent> animated =
loysoa6edaaff2015-05-25 03:26:447888 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaa92fdc12015-03-31 22:47:417889 scoped_refptr<LayerWithForcedDrawsContent> surface =
loysoa6edaaff2015-05-25 03:26:447890 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaa92fdc12015-03-31 22:47:417891 scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation =
loysoa6edaaff2015-05-25 03:26:447892 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaa92fdc12015-03-31 22:47:417893
7894 root->AddChild(clip);
7895 clip->AddChild(animated);
7896 animated->AddChild(surface);
7897 surface->AddChild(descendant_of_animation);
7898
7899 clip->SetMasksToBounds(true);
7900 surface->SetForceRenderSurface(true);
7901
ennea7b43c32015-06-18 20:01:337902 host()->SetRootLayer(root);
ajumaa92fdc12015-03-31 22:47:417903
7904 gfx::Transform uninvertible_matrix;
7905 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
7906
7907 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
7908 gfx::PointF(), gfx::Size(100, 100), true, false);
7909 SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(),
7910 gfx::PointF(), gfx::Size(10, 10), true, false);
7911 SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix,
7912 gfx::Point3F(), gfx::PointF(),
7913 gfx::Size(120, 120), true, false);
7914 SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(),
7915 gfx::PointF(), gfx::Size(100, 100), true, false);
7916 SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix,
7917 gfx::Point3F(), gfx::PointF(),
7918 gfx::Size(200, 200), true, false);
7919
7920 TransformOperations start_transform_operations;
7921 start_transform_operations.AppendMatrix(uninvertible_matrix);
7922 TransformOperations end_transform_operations;
7923
7924 AddAnimatedTransformToLayer(animated.get(), 10.0, start_transform_operations,
7925 end_transform_operations);
7926
enne601f2ef12015-05-19 18:20:177927 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:417928
7929 // The animated layer has a singular transform and maps to a non-empty rect in
7930 // clipped target space, so is treated as fully visible.
7931 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_rect_from_property_trees());
7932
7933 // The singular transform on |animated| is flattened when inherited by
7934 // |surface|, and this happens to make it invertible.
7935 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_rect_from_property_trees());
7936 EXPECT_EQ(gfx::Rect(2, 2),
7937 descendant_of_animation->visible_rect_from_property_trees());
7938
7939 gfx::Transform zero_matrix;
7940 zero_matrix.Scale3d(0.f, 0.f, 0.f);
7941 SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(),
7942 gfx::PointF(), gfx::Size(120, 120), true, false);
7943
enne601f2ef12015-05-19 18:20:177944 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:417945
7946 // The animated layer maps to the empty rect in clipped target space, so is
7947 // treated as having an empty visible rect.
7948 EXPECT_EQ(gfx::Rect(), animated->visible_rect_from_property_trees());
7949
7950 // This time, flattening does not make |animated|'s transform invertible. This
7951 // means the clip cannot be projected into |surface|'s space, so we treat
jaydasika67d7989e2015-08-06 21:55:347952 // |surface| and layers that draw into it as having empty visible rect.
7953 EXPECT_EQ(gfx::Rect(), surface->visible_rect_from_property_trees());
7954 EXPECT_EQ(gfx::Rect(),
ajumaa92fdc12015-03-31 22:47:417955 descendant_of_animation->visible_rect_from_property_trees());
7956}
7957
enne92f2f6d92015-02-25 23:13:317958// Verify that having an animated filter (but no current filter, as these
7959// are mutually exclusive) correctly creates a render surface.
7960TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
loysoa6edaaff2015-05-25 03:26:447961 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7962 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7963 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
enne92f2f6d92015-02-25 23:13:317964 root->AddChild(child);
7965 child->AddChild(grandchild);
7966
7967 gfx::Transform identity_transform;
7968 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7969 gfx::PointF(), gfx::Size(50, 50), true, false);
7970 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
7971 gfx::PointF(), gfx::Size(50, 50), true, false);
7972 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
7973 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7974 true, false);
ennea7b43c32015-06-18 20:01:337975 host()->SetRootLayer(root);
enne92f2f6d92015-02-25 23:13:317976
7977 AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f);
7978
7979 ExecuteCalculateDrawProperties(root.get());
7980
ennec1332992015-08-24 19:45:097981 EXPECT_TRUE(root->has_render_surface());
7982 EXPECT_TRUE(child->has_render_surface());
7983 EXPECT_FALSE(grandchild->has_render_surface());
enne92f2f6d92015-02-25 23:13:317984
7985 EXPECT_TRUE(root->filters().IsEmpty());
7986 EXPECT_TRUE(child->filters().IsEmpty());
7987 EXPECT_TRUE(grandchild->filters().IsEmpty());
7988
7989 EXPECT_FALSE(root->FilterIsAnimating());
7990 EXPECT_TRUE(child->FilterIsAnimating());
7991 EXPECT_FALSE(grandchild->FilterIsAnimating());
7992}
7993
ajuma315a4782015-07-24 21:16:347994// Verify that having a filter animation with a delayed start time creates a
7995// render surface.
7996TEST_F(LayerTreeHostCommonTest, DelayedFilterAnimationCreatesRenderSurface) {
7997 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7998 scoped_refptr<Layer> child = Layer::Create(layer_settings());
7999 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
8000 root->AddChild(child);
8001 child->AddChild(grandchild);
8002
8003 gfx::Transform identity_transform;
8004 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8005 gfx::PointF(), gfx::Size(50, 50), true, false);
8006 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8007 gfx::PointF(), gfx::Size(50, 50), true, false);
8008 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8009 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
8010 true, false);
8011 host()->SetRootLayer(root);
8012
8013 scoped_ptr<KeyframedFilterAnimationCurve> curve(
8014 KeyframedFilterAnimationCurve::Create());
8015 FilterOperations start_filters;
8016 start_filters.Append(FilterOperation::CreateBrightnessFilter(0.1f));
8017 FilterOperations end_filters;
8018 end_filters.Append(FilterOperation::CreateBrightnessFilter(0.3f));
8019 curve->AddKeyframe(
8020 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr));
8021 curve->AddKeyframe(FilterKeyframe::Create(
8022 base::TimeDelta::FromMilliseconds(100), end_filters, nullptr));
8023 scoped_ptr<Animation> animation =
danakja04855a2015-11-18 20:39:108024 Animation::Create(std::move(curve), 0, 1, Animation::FILTER);
ajuma315a4782015-07-24 21:16:348025 animation->set_fill_mode(Animation::FILL_MODE_NONE);
8026 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
danakja04855a2015-11-18 20:39:108027 child->layer_animation_controller()->AddAnimation(std::move(animation));
ajuma315a4782015-07-24 21:16:348028
8029 ExecuteCalculateDrawProperties(root.get());
8030
ennec1332992015-08-24 19:45:098031 EXPECT_TRUE(root->has_render_surface());
8032 EXPECT_TRUE(child->has_render_surface());
8033 EXPECT_FALSE(grandchild->has_render_surface());
ajuma315a4782015-07-24 21:16:348034
8035 EXPECT_TRUE(root->filters().IsEmpty());
8036 EXPECT_TRUE(child->filters().IsEmpty());
8037 EXPECT_TRUE(grandchild->filters().IsEmpty());
8038
8039 EXPECT_FALSE(root->FilterIsAnimating());
8040 EXPECT_FALSE(root->HasPotentiallyRunningFilterAnimation());
8041 EXPECT_FALSE(child->FilterIsAnimating());
8042 EXPECT_TRUE(child->HasPotentiallyRunningFilterAnimation());
8043 EXPECT_FALSE(grandchild->FilterIsAnimating());
8044 EXPECT_FALSE(grandchild->HasPotentiallyRunningFilterAnimation());
8045}
8046
vollick0120eb22015-03-02 03:07:348047// Ensures that the property tree code accounts for offsets between fixed
8048// position layers and their respective containers.
8049TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
loysoa6edaaff2015-05-25 03:26:448050 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8051 scoped_refptr<Layer> child = Layer::Create(layer_settings());
vollick0120eb22015-03-02 03:07:348052 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loysoa6edaaff2015-05-25 03:26:448053 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick0120eb22015-03-02 03:07:348054
8055 root->AddChild(child);
8056 child->AddChild(grandchild);
8057
8058 gfx::Transform identity_transform;
8059 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8060 gfx::PointF(), gfx::Size(50, 50), true, false);
8061 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8062 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
8063 false);
8064 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8065 gfx::Point3F(), gfx::PointF(-1000, -1000),
8066 gfx::Size(50, 50), true, false);
8067
8068 root->SetMasksToBounds(true);
8069 root->SetIsContainerForFixedPositionLayers(true);
8070 LayerPositionConstraint constraint;
8071 constraint.set_is_fixed_position(true);
8072 grandchild->SetPositionConstraint(constraint);
8073
8074 root->SetIsContainerForFixedPositionLayers(true);
8075
ennea7b43c32015-06-18 20:01:338076 host()->SetRootLayer(root);
vollick0120eb22015-03-02 03:07:348077
enne601f2ef12015-05-19 18:20:178078 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick0120eb22015-03-02 03:07:348079
8080 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
8081 grandchild->visible_rect_from_property_trees());
8082}
8083
ajuma0178b522015-07-02 21:08:418084// Ensures that the property tree code accounts for offsets between fixed
8085// position containers and their transform tree parents, when a fixed position
8086// layer's container is its layer tree parent, but this parent doesn't have its
8087// own transform tree node.
8088TEST_F(LayerTreeHostCommonTest,
8089 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent) {
8090 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8091 scoped_refptr<Layer> child = Layer::Create(layer_settings());
8092 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
8093 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8094
8095 root->AddChild(child);
8096 child->AddChild(grandchild);
8097
8098 gfx::Transform identity_transform;
8099 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8100 gfx::PointF(), gfx::Size(50, 50), true, false);
8101 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8102 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
8103 false);
8104 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8105 gfx::Point3F(), gfx::PointF(-1000, -1000),
8106 gfx::Size(50, 50), true, false);
8107
8108 root->SetMasksToBounds(true);
8109 child->SetIsContainerForFixedPositionLayers(true);
8110 LayerPositionConstraint constraint;
8111 constraint.set_is_fixed_position(true);
8112 grandchild->SetPositionConstraint(constraint);
8113
8114 root->SetIsContainerForFixedPositionLayers(true);
8115
8116 host()->SetRootLayer(root);
8117
8118 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8119
8120 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
8121 grandchild->visible_rect_from_property_trees());
8122}
8123
vollick67394b42015-03-10 00:22:308124TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) {
8125 // In the following layer tree, the layer |box|'s render target is |surface|.
8126 // |surface| also creates a transform node. We want to combine clips for |box|
8127 // in the space of its target (i.e., |surface|), not its target's target. This
8128 // test ensures that happens.
8129
8130 gfx::Transform rotate;
8131 rotate.Rotate(5);
8132 gfx::Transform identity;
8133
loysoa6edaaff2015-05-25 03:26:448134 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:308135 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8136 gfx::PointF(), gfx::Size(2500, 1500), true,
8137 false);
8138
loysoa6edaaff2015-05-25 03:26:448139 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:308140 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8141 gfx::PointF(), gfx::Size(2500, 1500), true,
8142 false);
8143 frame_clip->SetMasksToBounds(true);
8144
loysoa6edaaff2015-05-25 03:26:448145 scoped_refptr<Layer> rotated = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:308146 SetLayerPropertiesForTesting(rotated.get(), rotate,
8147 gfx::Point3F(1250, 250, 0), gfx::PointF(),
8148 gfx::Size(2500, 500), true, false);
8149
loysoa6edaaff2015-05-25 03:26:448150 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:308151 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(),
8152 gfx::PointF(), gfx::Size(2500, 500), true,
8153 false);
8154 surface->SetOpacity(0.5);
8155
8156 scoped_refptr<LayerWithForcedDrawsContent> container =
loysoa6edaaff2015-05-25 03:26:448157 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick67394b42015-03-10 00:22:308158 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(),
8159 gfx::PointF(), gfx::Size(300, 300), true, false);
8160
8161 scoped_refptr<LayerWithForcedDrawsContent> box =
loysoa6edaaff2015-05-25 03:26:448162 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick67394b42015-03-10 00:22:308163 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(),
8164 gfx::PointF(), gfx::Size(100, 100), true, false);
8165
8166 root->AddChild(frame_clip);
8167 frame_clip->AddChild(rotated);
8168 rotated->AddChild(surface);
8169 surface->AddChild(container);
8170 surface->AddChild(box);
8171
ennea7b43c32015-06-18 20:01:338172 host()->SetRootLayer(root);
vollick67394b42015-03-10 00:22:308173
8174 ExecuteCalculateDrawProperties(root.get());
8175}
8176
vollick8c824742015-03-20 22:21:088177TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
8178 gfx::Transform identity;
8179 gfx::Transform translate_z;
8180 translate_z.Translate3d(0, 0, 10);
8181
loysoa6edaaff2015-05-25 03:26:448182 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick8c824742015-03-20 22:21:088183 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8184 gfx::PointF(), gfx::Size(800, 800), true, false);
8185 root->SetIsContainerForFixedPositionLayers(true);
8186
loysoa6edaaff2015-05-25 03:26:448187 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollick8c824742015-03-20 22:21:088188 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
8189 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8190 false);
8191 frame_clip->SetMasksToBounds(true);
8192
8193 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:448194 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick8c824742015-03-20 22:21:088195 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8196 gfx::PointF(), gfx::Size(1000, 1000), true,
8197 false);
8198
8199 LayerPositionConstraint constraint;
8200 constraint.set_is_fixed_position(true);
8201 fixed->SetPositionConstraint(constraint);
8202
8203 root->AddChild(frame_clip);
8204 frame_clip->AddChild(fixed);
8205
ennea7b43c32015-06-18 20:01:338206 host()->SetRootLayer(root);
vollick8c824742015-03-20 22:21:088207
enne601f2ef12015-05-19 18:20:178208 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick8c824742015-03-20 22:21:088209
8210 gfx::Rect expected(0, 0, 100, 100);
8211 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
8212}
8213
vollickf6281c42015-03-30 21:44:418214TEST_F(LayerTreeHostCommonTest,
8215 PropertyTreesAccountForScrollCompensationAdjustment) {
8216 gfx::Transform identity;
8217 gfx::Transform translate_z;
8218 translate_z.Translate3d(0, 0, 10);
8219
loysoa6edaaff2015-05-25 03:26:448220 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollickf6281c42015-03-30 21:44:418221 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8222 gfx::PointF(), gfx::Size(800, 800), true, false);
8223 root->SetIsContainerForFixedPositionLayers(true);
8224
loysoa6edaaff2015-05-25 03:26:448225 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollickf6281c42015-03-30 21:44:418226 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
8227 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8228 false);
8229 frame_clip->SetMasksToBounds(true);
8230
8231 scoped_refptr<LayerWithForcedDrawsContent> scroller =
loysoa6edaaff2015-05-25 03:26:448232 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollickf6281c42015-03-30 21:44:418233 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
8234 gfx::PointF(), gfx::Size(1000, 1000), true,
8235 false);
8236
8237 scroller->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f, 0.7f));
8238 scroller->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
8239 scroller->SetScrollClipLayerId(frame_clip->id());
8240
8241 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:448242 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollickf6281c42015-03-30 21:44:418243 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8244 gfx::PointF(), gfx::Size(50, 50), true, false);
8245
8246 LayerPositionConstraint constraint;
8247 constraint.set_is_fixed_position(true);
8248 fixed->SetPositionConstraint(constraint);
8249
8250 scoped_refptr<LayerWithForcedDrawsContent> fixed_child =
loysoa6edaaff2015-05-25 03:26:448251 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollickf6281c42015-03-30 21:44:418252 SetLayerPropertiesForTesting(fixed_child.get(), identity, gfx::Point3F(),
8253 gfx::PointF(), gfx::Size(10, 10), true, false);
8254
8255 fixed_child->SetPositionConstraint(constraint);
8256
8257 root->AddChild(frame_clip);
8258 frame_clip->AddChild(scroller);
8259 scroller->AddChild(fixed);
8260 fixed->AddChild(fixed_child);
8261
ennea7b43c32015-06-18 20:01:338262 host()->SetRootLayer(root);
vollickf6281c42015-03-30 21:44:418263
enne601f2ef12015-05-19 18:20:178264 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollickf6281c42015-03-30 21:44:418265
8266 gfx::Rect expected(0, 0, 50, 50);
8267 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
8268
8269 expected = gfx::Rect(0, 0, 10, 10);
8270 EXPECT_EQ(expected, fixed_child->visible_rect_from_property_trees());
8271}
8272
vollick06ca3e832015-03-31 19:37:128273TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
8274 gfx::Transform identity;
8275
loysoa6edaaff2015-05-25 03:26:448276 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick06ca3e832015-03-31 19:37:128277 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8278 gfx::PointF(), gfx::Size(800, 800), true, false);
8279 root->SetIsContainerForFixedPositionLayers(true);
8280
loysoa6edaaff2015-05-25 03:26:448281 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollick06ca3e832015-03-31 19:37:128282 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8283 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8284 false);
8285 frame_clip->SetMasksToBounds(true);
8286
8287 scoped_refptr<LayerWithForcedDrawsContent> scroller =
loysoa6edaaff2015-05-25 03:26:448288 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick06ca3e832015-03-31 19:37:128289 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
8290 gfx::PointF(), gfx::Size(1000, 1000), true,
8291 false);
8292
8293 scroller->SetScrollOffset(gfx::ScrollOffset(100, 100));
8294 scroller->SetScrollClipLayerId(frame_clip->id());
8295
8296 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:448297 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick06ca3e832015-03-31 19:37:128298 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8299 gfx::PointF(100, 100), gfx::Size(50, 50), true,
8300 false);
8301
8302 LayerPositionConstraint constraint;
8303 constraint.set_is_fixed_position(true);
8304 fixed->SetPositionConstraint(constraint);
8305 fixed->SetForceRenderSurface(true);
8306 fixed->SetMasksToBounds(true);
8307
8308 root->AddChild(frame_clip);
8309 frame_clip->AddChild(scroller);
8310 scroller->AddChild(fixed);
8311
ennea7b43c32015-06-18 20:01:338312 host()->SetRootLayer(root);
vollick06ca3e832015-03-31 19:37:128313
enne601f2ef12015-05-19 18:20:178314 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick06ca3e832015-03-31 19:37:128315
8316 gfx::Rect expected(0, 0, 50, 50);
8317 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
8318}
8319
vollick5057e1e2015-04-17 19:12:328320TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
8321 gfx::Transform identity;
8322 gfx::Transform translate;
8323 gfx::Transform rotate;
8324
8325 translate.Translate(10, 10);
8326 rotate.Rotate(45);
8327
loysoa6edaaff2015-05-25 03:26:448328 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick5057e1e2015-04-17 19:12:328329 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8330 gfx::PointF(), gfx::Size(800, 800), true, false);
8331 root->SetIsContainerForFixedPositionLayers(true);
8332
ennea7b43c32015-06-18 20:01:338333 host()->SetRootLayer(root);
vollick5057e1e2015-04-17 19:12:328334
enne601f2ef12015-05-19 18:20:178335 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ennea7b43c32015-06-18 20:01:338336 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328337
8338 root->SetTransform(translate);
ennea7b43c32015-06-18 20:01:338339 EXPECT_FALSE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328340
8341 root->SetTransform(rotate);
ennea7b43c32015-06-18 20:01:338342 EXPECT_TRUE(host()->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:328343}
8344
ajumab0e0c1c2015-04-23 00:29:238345TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
loysoa6edaaff2015-05-25 03:26:448346 scoped_refptr<Layer> root = Layer::Create(layer_settings());
ajumab0e0c1c2015-04-23 00:29:238347 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:448348 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumab0e0c1c2015-04-23 00:29:238349 root->AddChild(child);
8350
ennea7b43c32015-06-18 20:01:338351 host()->SetRootLayer(root);
ajumab0e0c1c2015-04-23 00:29:238352
8353 gfx::Transform identity_matrix;
8354 gfx::Transform scale_matrix;
8355 scale_matrix.Scale(2.f, 2.f);
8356 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8357 gfx::PointF(), gfx::Size(100, 100), true, false);
8358 SetLayerPropertiesForTesting(child.get(), scale_matrix, gfx::Point3F(),
8359 gfx::PointF(), gfx::Size(10, 10), true, false);
8360
enne601f2ef12015-05-19 18:20:178361 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumab0e0c1c2015-04-23 00:29:238362 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
8363
8364 child->SetTransformOrigin(gfx::Point3F(10.f, 10.f, 10.f));
8365
enne601f2ef12015-05-19 18:20:178366 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumab0e0c1c2015-04-23 00:29:238367 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_rect_from_property_trees());
8368}
8369
ajumaf09db8962015-04-24 21:55:348370TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
loysoa6edaaff2015-05-25 03:26:448371 scoped_refptr<Layer> root = Layer::Create(layer_settings());
ajumaf09db8962015-04-24 21:55:348372 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
loysoa6edaaff2015-05-25 03:26:448373 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaf09db8962015-04-24 21:55:348374 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
loysoa6edaaff2015-05-25 03:26:448375 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaf09db8962015-04-24 21:55:348376
8377 root->AddChild(scroll_child);
8378 root->AddChild(scroll_parent);
8379 scroll_child->SetScrollParent(scroll_parent.get());
8380 scroll_parent->SetScrollClipLayerId(root->id());
8381
ennea7b43c32015-06-18 20:01:338382 host()->SetRootLayer(root);
ajumaf09db8962015-04-24 21:55:348383
8384 gfx::Transform identity_transform;
8385 gfx::Transform scale;
8386 scale.Scale(2.f, 2.f);
8387 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8388 gfx::PointF(), gfx::Size(50, 50), true, false);
8389 SetLayerPropertiesForTesting(scroll_child.get(), scale, gfx::Point3F(),
8390 gfx::PointF(), gfx::Size(40, 40), true, false);
8391 SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform,
8392 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
8393 true, false);
8394
enne601f2ef12015-05-19 18:20:178395 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaf09db8962015-04-24 21:55:348396 EXPECT_EQ(gfx::Rect(25, 25),
8397 scroll_child->visible_rect_from_property_trees());
8398
8399 scroll_child->SetPosition(gfx::PointF(0, -10.f));
8400 scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f));
enne601f2ef12015-05-19 18:20:178401 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaf09db8962015-04-24 21:55:348402 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
8403 scroll_child->visible_rect_from_property_trees());
8404}
8405
vollick2175fae82015-04-27 21:18:128406static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
8407}
8408
8409TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
8410 gfx::Transform identity;
loysoa6edaaff2015-05-25 03:26:448411 scoped_refptr<Layer> root = Layer::Create(layer_settings());
chrishtr01539b802015-11-24 08:11:328412 FakeContentLayerClient client;
8413 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:128414 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:448415 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick2175fae82015-04-27 21:18:128416 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loysoa6edaaff2015-05-25 03:26:448417 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
danakj4e95f7632015-06-05 19:46:258418 scoped_refptr<FakePictureLayer> greatgrandchild(
8419 FakePictureLayer::Create(layer_settings(), &client));
vollick2175fae82015-04-27 21:18:128420 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8421 gfx::PointF(), gfx::Size(100, 100), true, false);
8422 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8423 gfx::PointF(), gfx::Size(10, 10), true, false);
8424 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8425 gfx::PointF(), gfx::Size(10, 10), true, false);
8426 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
8427 gfx::PointF(), gfx::Size(10, 10), true, false);
8428
8429 root->AddChild(child);
8430 child->AddChild(grandchild);
8431 grandchild->AddChild(greatgrandchild);
8432
ennea7b43c32015-06-18 20:01:338433 host()->SetRootLayer(root);
vollick2175fae82015-04-27 21:18:128434
8435 // Check the non-skipped case.
enne601f2ef12015-05-19 18:20:178436 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128437 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
8438
8439 // Now we will reset the visible rect from property trees for the grandchild,
8440 // and we will configure |child| in several ways that should force the subtree
8441 // to be skipped. The visible content rect for |grandchild| should, therefore,
8442 // remain empty.
8443 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
8444 gfx::Transform singular;
8445 singular.matrix().set(0, 0, 0);
8446
8447 child->SetTransform(singular);
enne601f2ef12015-05-19 18:20:178448 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128449 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8450 child->SetTransform(identity);
8451
8452 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:178453 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128454 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8455 child->SetHideLayerAndSubtree(false);
8456
ajuma315a4782015-07-24 21:16:348457 gfx::Transform zero_z_scale;
8458 zero_z_scale.Scale3d(1, 1, 0);
8459 child->SetTransform(zero_z_scale);
8460
8461 // Add a transform animation with a start delay. Now, even though |child| has
8462 // a singular transform, the subtree should still get processed.
8463 int animation_id = 0;
8464 scoped_ptr<Animation> animation = Animation::Create(
danakja5a05ba02015-11-20 20:14:218465 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)),
ajuma315a4782015-07-24 21:16:348466 animation_id, 1, Animation::TRANSFORM);
8467 animation->set_fill_mode(Animation::FILL_MODE_NONE);
8468 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
danakja04855a2015-11-18 20:39:108469 child->AddAnimation(std::move(animation));
ajuma315a4782015-07-24 21:16:348470 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8471 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
8472 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
8473
8474 child->RemoveAnimation(animation_id);
8475 child->SetTransform(identity);
vollick2175fae82015-04-27 21:18:128476 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:178477 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128478 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
8479
8480 // Now, even though child has zero opacity, we will configure |grandchild| and
8481 // |greatgrandchild| in several ways that should force the subtree to be
8482 // processed anyhow.
vollick2175fae82015-04-27 21:18:128483 greatgrandchild->RequestCopyOfOutput(
8484 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
enne601f2ef12015-05-19 18:20:178485 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128486 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
ajuma315a4782015-07-24 21:16:348487 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
8488
8489 // Add an opacity animation with a start delay.
8490 animation_id = 1;
8491 animation = Animation::Create(
danakja5a05ba02015-11-20 20:14:218492 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)),
ajuma315a4782015-07-24 21:16:348493 animation_id, 1, Animation::OPACITY);
8494 animation->set_fill_mode(Animation::FILL_MODE_NONE);
8495 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
danakja04855a2015-11-18 20:39:108496 child->AddAnimation(std::move(animation));
ajuma315a4782015-07-24 21:16:348497 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8498 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
vollick2175fae82015-04-27 21:18:128499}
8500
8501TEST_F(LayerTreeHostCommonTest, SkippingSubtreeImpl) {
khushalsagarb64b360d2015-10-21 19:25:168502 FakeImplTaskRunnerProvider task_runner_provider;
vollick2175fae82015-04-27 21:18:128503 TestSharedBitmapManager shared_bitmap_manager;
danakjcf610582015-06-16 22:48:568504 TestTaskGraphRunner task_graph_runner;
khushalsagarb64b360d2015-10-21 19:25:168505 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager,
danakjcf610582015-06-16 22:48:568506 &task_graph_runner);
vollick2175fae82015-04-27 21:18:128507
8508 gfx::Transform identity;
8509 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
8510 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
8511 scoped_ptr<LayerImpl> grandchild =
8512 LayerImpl::Create(host_impl.active_tree(), 3);
8513
danakj4e95f7632015-06-05 19:46:258514 scoped_ptr<FakePictureLayerImpl> greatgrandchild(
8515 FakePictureLayerImpl::Create(host_impl.active_tree(), 4));
vollick2175fae82015-04-27 21:18:128516
8517 child->SetDrawsContent(true);
8518 grandchild->SetDrawsContent(true);
8519 greatgrandchild->SetDrawsContent(true);
8520
8521 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8522 gfx::PointF(), gfx::Size(100, 100), true, false,
8523 true);
8524 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8525 gfx::PointF(), gfx::Size(10, 10), true, false,
8526 false);
8527 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
8528 gfx::PointF(), gfx::Size(10, 10), true, false,
8529 false);
8530 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
8531 gfx::PointF(), gfx::Size(10, 10), true, false,
8532 true);
8533
8534 LayerImpl* child_ptr = child.get();
8535 LayerImpl* grandchild_ptr = grandchild.get();
8536 LayerImpl* greatgrandchild_ptr = greatgrandchild.get();
8537
danakja04855a2015-11-18 20:39:108538 grandchild->AddChild(std::move(greatgrandchild));
8539 child->AddChild(std::move(grandchild));
8540 root->AddChild(std::move(child));
vollick2175fae82015-04-27 21:18:128541
8542 // Check the non-skipped case.
enne601f2ef12015-05-19 18:20:178543 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128544 EXPECT_EQ(gfx::Rect(10, 10),
8545 grandchild_ptr->visible_rect_from_property_trees());
8546
8547 // Now we will reset the visible rect from property trees for the grandchild,
8548 // and we will configure |child| in several ways that should force the subtree
8549 // to be skipped. The visible content rect for |grandchild| should, therefore,
8550 // remain empty.
8551 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
8552 gfx::Transform singular;
8553 singular.matrix().set(0, 0, 0);
8554
8555 child_ptr->SetTransform(singular);
enne601f2ef12015-05-19 18:20:178556 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128557 EXPECT_EQ(gfx::Rect(0, 0),
8558 grandchild_ptr->visible_rect_from_property_trees());
8559 child_ptr->SetTransform(identity);
8560
8561 child_ptr->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:178562 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128563 EXPECT_EQ(gfx::Rect(0, 0),
8564 grandchild_ptr->visible_rect_from_property_trees());
8565 child_ptr->SetHideLayerAndSubtree(false);
8566
8567 child_ptr->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:178568 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128569 EXPECT_EQ(gfx::Rect(0, 0),
8570 grandchild_ptr->visible_rect_from_property_trees());
8571
8572 // Now, even though child has zero opacity, we will configure |grandchild| and
8573 // |greatgrandchild| in several ways that should force the subtree to be
8574 // processed anyhow.
vmpstra370ef52015-11-18 10:41:288575 std::vector<scoped_ptr<CopyOutputRequest>> requests;
vollick2175fae82015-04-27 21:18:128576 requests.push_back(CopyOutputRequest::CreateEmptyRequest());
8577
8578 greatgrandchild_ptr->PassCopyRequests(&requests);
enne601f2ef12015-05-19 18:20:178579 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128580 EXPECT_EQ(gfx::Rect(10, 10),
8581 grandchild_ptr->visible_rect_from_property_trees());
8582}
8583
8584TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
8585 gfx::Transform identity;
loysoa6edaaff2015-05-25 03:26:448586 scoped_refptr<Layer> root = Layer::Create(layer_settings());
chrishtr01539b802015-11-24 08:11:328587 FakeContentLayerClient client;
8588 client.set_bounds(root->bounds());
vollick2175fae82015-04-27 21:18:128589 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:448590 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick2175fae82015-04-27 21:18:128591 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8592 gfx::PointF(), gfx::Size(100, 100), true, false);
8593 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8594 gfx::PointF(), gfx::Size(10, 10), true, false);
8595 root->AddChild(child);
8596
ennea7b43c32015-06-18 20:01:338597 host()->SetRootLayer(root);
vollick2175fae82015-04-27 21:18:128598
enne601f2ef12015-05-19 18:20:178599 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128600 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
8601 child->set_visible_rect_from_property_trees(gfx::Rect());
8602
8603 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:178604 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128605 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
8606 child->SetHideLayerAndSubtree(false);
8607
8608 child->SetBounds(gfx::Size());
enne601f2ef12015-05-19 18:20:178609 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128610 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
8611 child->SetBounds(gfx::Size(10, 10));
8612
8613 gfx::Transform rotate;
8614 child->SetDoubleSided(false);
8615 rotate.RotateAboutXAxis(180.f);
8616 child->SetTransform(rotate);
enne601f2ef12015-05-19 18:20:178617 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128618 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
8619 child->SetDoubleSided(true);
8620 child->SetTransform(identity);
8621
8622 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:178623 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:128624 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
8625}
8626
jaydasika3d10aa62015-05-06 17:50:448627TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
8628 // Ensure that the treewalk in LayerTreeHostCommom::
8629 // PreCalculateMetaInformation happens when its required.
loysoa6edaaff2015-05-25 03:26:448630 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8631 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
8632 scoped_refptr<Layer> child = Layer::Create(layer_settings());
jaydasika3d10aa62015-05-06 17:50:448633
8634 root->AddChild(parent);
8635 parent->AddChild(child);
8636
8637 child->SetClipParent(root.get());
8638
8639 gfx::Transform identity;
8640
8641 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8642 gfx::PointF(), gfx::Size(100, 100), true, false);
8643 SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(),
8644 gfx::PointF(), gfx::Size(100, 100), true, false);
8645 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8646 gfx::PointF(), gfx::Size(100, 100), true, false);
8647
ennea7b43c32015-06-18 20:01:338648 host()->SetRootLayer(root);
jaydasika3d10aa62015-05-06 17:50:448649
8650 ExecuteCalculateDrawProperties(root.get());
ennec95e6622015-08-28 23:23:198651 EXPECT_EQ(parent->num_unclipped_descendants(), 1u);
jaydasika3d10aa62015-05-06 17:50:448652
jaydasika3d10aa62015-05-06 17:50:448653 child->RequestCopyOfOutput(
8654 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
ennec95e6622015-08-28 23:23:198655 EXPECT_GT(root->num_layer_or_descendants_with_copy_request(), 0);
jaydasika3d10aa62015-05-06 17:50:448656 ExecuteCalculateDrawProperties(root.get());
ennec95e6622015-08-28 23:23:198657 EXPECT_GT(root->num_layer_or_descendants_with_copy_request(), 0);
jaydasika3d10aa62015-05-06 17:50:448658}
8659
8660TEST_F(LayerTreeHostCommonTest, InputHandlersRecursiveUpdateTest) {
8661 // Ensure that the treewalk in LayertreeHostCommon::
8662 // PreCalculateMetaInformation updates input handlers correctly.
ennecf94ff0c2015-08-18 22:58:058663 LayerImpl* root = root_layer();
8664 LayerImpl* child = AddChild<LayerImpl>(root);
jaydasika3d10aa62015-05-06 17:50:448665
8666 gfx::Transform identity;
8667
ennecf94ff0c2015-08-18 22:58:058668 SetLayerPropertiesForTesting(root, identity, gfx::Point3F(), gfx::PointF(),
8669 gfx::Size(100, 100), true, false, true);
8670 SetLayerPropertiesForTesting(child, identity, gfx::Point3F(), gfx::PointF(),
8671 gfx::Size(100, 100), true, false, false);
jaydasika3d10aa62015-05-06 17:50:448672
jaydasika60f85862015-10-01 20:36:148673 EXPECT_EQ(root->layer_or_descendant_has_input_handler(), false);
jaydasika3d10aa62015-05-06 17:50:448674
ennecf94ff0c2015-08-18 22:58:058675 child->SetHaveWheelEventHandlers(true);
8676 ExecuteCalculateDrawProperties(root);
jaydasika60f85862015-10-01 20:36:148677 EXPECT_EQ(root->layer_or_descendant_has_input_handler(), true);
ennecf94ff0c2015-08-18 22:58:058678
jaydasika3d10aa62015-05-06 17:50:448679 child->SetHaveWheelEventHandlers(false);
ennecf94ff0c2015-08-18 22:58:058680 ExecuteCalculateDrawProperties(root);
jaydasika60f85862015-10-01 20:36:148681 EXPECT_EQ(root->layer_or_descendant_has_input_handler(), false);
jaydasika3d10aa62015-05-06 17:50:448682}
8683
vollick692444f2015-05-20 15:39:148684TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
8685 gfx::Transform identity;
8686 gfx::Transform translate_z;
8687 translate_z.Translate3d(0, 0, 10);
8688
loysoa6edaaff2015-05-25 03:26:448689 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick692444f2015-05-20 15:39:148690 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8691 gfx::PointF(), gfx::Size(800, 800), true, false);
8692
loysoa6edaaff2015-05-25 03:26:448693 scoped_refptr<Layer> child = Layer::Create(layer_settings());
vollick692444f2015-05-20 15:39:148694 SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(),
8695 gfx::PointF(), gfx::Size(100, 100), true, false);
8696
8697 root->AddChild(child);
8698
ennea7b43c32015-06-18 20:01:338699 host()->SetRootLayer(root);
vollick692444f2015-05-20 15:39:148700
8701 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8702 EXPECT_NE(-1, child->transform_tree_index());
8703
8704 child->RemoveFromParent();
8705
8706 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
8707 EXPECT_EQ(-1, child->transform_tree_index());
8708}
8709
jaydasika976cd10b2015-05-26 15:45:248710TEST_F(LayerTreeHostCommonTest, ResetLayerDrawPropertiestest) {
8711 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8712 scoped_refptr<Layer> child = Layer::Create(layer_settings());
8713
8714 root->AddChild(child);
8715 gfx::Transform identity;
8716
8717 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8718 gfx::PointF(), gfx::Size(100, 100), true, false);
8719 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
8720 gfx::PointF(), gfx::Size(100, 100), true, false);
8721
ennea7b43c32015-06-18 20:01:338722 host()->SetRootLayer(root);
jaydasika976cd10b2015-05-26 15:45:248723
8724 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
8725 EXPECT_FALSE(root->visited());
8726 EXPECT_FALSE(root->sorted_for_recursion());
8727 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
8728 EXPECT_FALSE(child->visited());
8729 EXPECT_FALSE(child->sorted_for_recursion());
8730
8731 root->set_layer_or_descendant_is_drawn(true);
8732 root->set_visited(true);
8733 root->set_sorted_for_recursion(true);
8734 child->set_layer_or_descendant_is_drawn(true);
8735 child->set_visited(true);
8736 child->set_sorted_for_recursion(true);
8737
8738 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root.get());
8739
8740 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
8741 EXPECT_FALSE(root->visited());
8742 EXPECT_FALSE(root->sorted_for_recursion());
8743 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
8744 EXPECT_FALSE(child->visited());
8745 EXPECT_FALSE(child->sorted_for_recursion());
8746}
8747
jaydasika67d7989e2015-08-06 21:55:348748TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) {
8749 // Ensure that a Clip Node is added when a render surface applies clip.
8750 LayerImpl* root = root_layer();
8751 LayerImpl* significant_transform = AddChildToRoot<LayerImpl>();
8752 LayerImpl* layer_clips_subtree = AddChild<LayerImpl>(significant_transform);
8753 LayerImpl* render_surface = AddChild<LayerImpl>(layer_clips_subtree);
8754 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
8755
8756 const gfx::Transform identity_matrix;
8757 // This transform should be a significant one so that a transform node is
8758 // formed for it.
8759 gfx::Transform transform1;
8760 transform1.RotateAboutYAxis(45);
8761 transform1.RotateAboutXAxis(30);
8762 // This transform should be a 3d transform as we want the render surface
8763 // to flatten the transform
8764 gfx::Transform transform2;
8765 transform2.Translate3d(10, 10, 10);
8766
8767 layer_clips_subtree->SetMasksToBounds(true);
8768 test_layer->SetDrawsContent(true);
8769
8770 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
8771 gfx::PointF(), gfx::Size(30, 30), true, false,
8772 true);
8773 SetLayerPropertiesForTesting(significant_transform, transform1,
8774 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
8775 true, false, false);
8776 SetLayerPropertiesForTesting(layer_clips_subtree, identity_matrix,
8777 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
8778 true, false, false);
8779 SetLayerPropertiesForTesting(render_surface, transform2, gfx::Point3F(),
8780 gfx::PointF(), gfx::Size(30, 30), true, false,
8781 true);
8782 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
8783 gfx::PointF(), gfx::Size(30, 30), true, false,
8784 false);
8785
8786 ExecuteCalculateDrawProperties(root);
8787
8788 TransformTree transform_tree =
8789 root->layer_tree_impl()->property_trees()->transform_tree;
8790 TransformNode* transform_node =
8791 transform_tree.Node(significant_transform->transform_tree_index());
8792 EXPECT_EQ(transform_node->owner_id, significant_transform->id());
8793
8794 ClipTree clip_tree = root->layer_tree_impl()->property_trees()->clip_tree;
8795 ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index());
ajuma01734dd02015-10-07 01:22:088796 EXPECT_FALSE(clip_node->data.applies_local_clip);
danakj5e6ff6d2015-09-05 04:43:448797 EXPECT_EQ(gfx::Rect(30, 21), test_layer->visible_rect_from_property_trees());
jaydasika67d7989e2015-08-06 21:55:348798}
8799
8800TEST_F(LayerTreeHostCommonTest, TransformOfParentClipNodeAncestorOfTarget) {
8801 // Ensure that when parent clip node's transform is an ancestor of current
8802 // clip node's target, clip is 'projected' from parent space to current
8803 // target space and visible rects are calculated correctly.
8804 LayerImpl* root = root_layer();
8805 LayerImpl* clip_layer = AddChild<LayerImpl>(root);
8806 LayerImpl* target_layer = AddChild<LayerImpl>(clip_layer);
8807 LayerImpl* test_layer = AddChild<LayerImpl>(target_layer);
8808
8809 const gfx::Transform identity_matrix;
8810 gfx::Transform transform;
8811 transform.RotateAboutYAxis(45);
8812 clip_layer->SetMasksToBounds(true);
8813 target_layer->SetMasksToBounds(true);
8814 test_layer->SetDrawsContent(true);
8815
8816 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
8817 gfx::PointF(), gfx::Size(30, 30), true, false,
8818 true);
8819 SetLayerPropertiesForTesting(clip_layer, transform, gfx::Point3F(),
8820 gfx::PointF(), gfx::Size(30, 30), true, false,
8821 false);
8822 SetLayerPropertiesForTesting(target_layer, transform, gfx::Point3F(),
8823 gfx::PointF(), gfx::Size(30, 30), true, false,
8824 true);
8825 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
8826 gfx::PointF(), gfx::Size(30, 30), true, false,
8827 false);
8828 ExecuteCalculateDrawProperties(root);
8829
danakj5e6ff6d2015-09-05 04:43:448830 EXPECT_EQ(gfx::Rect(30, 30), test_layer->visible_rect_from_property_trees());
jaydasika67d7989e2015-08-06 21:55:348831}
8832
jaydasika7d5c1ed2015-08-14 14:27:028833TEST_F(LayerTreeHostCommonTest,
8834 RenderSurfaceWithUnclippedDescendantsClipsSubtree) {
8835 // Ensure clip rect is calculated correctly when render surface has unclipped
8836 // descendants.
8837 LayerImpl* root = root_layer();
8838 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
8839 LayerImpl* between_clip_parent_and_child = AddChild<LayerImpl>(clip_parent);
8840 LayerImpl* render_surface =
8841 AddChild<LayerImpl>(between_clip_parent_and_child);
8842 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
8843
8844 const gfx::Transform identity_matrix;
8845 gfx::Transform transform;
8846 transform.Translate(2.0, 2.0);
8847
8848 test_layer->SetDrawsContent(true);
8849 render_surface->SetClipParent(clip_parent);
jaydasikae9d09702015-09-15 01:26:418850 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
8851 clip_children->insert(render_surface);
8852 clip_parent->SetClipChildren(clip_children.release());
jaydasika7d5c1ed2015-08-14 14:27:028853 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
8854 gfx::PointF(), gfx::Size(30, 30), true, false,
8855 true);
8856 SetLayerPropertiesForTesting(clip_parent, transform, gfx::Point3F(),
8857 gfx::PointF(), gfx::Size(30, 30), true, false,
8858 false);
8859 SetLayerPropertiesForTesting(between_clip_parent_and_child, transform,
8860 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
8861 true, false, false);
8862 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
8863 gfx::PointF(), gfx::Size(30, 30), true, false,
8864 true);
8865 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
8866 gfx::PointF(), gfx::Size(30, 30), true, false,
8867 false);
8868
8869 ExecuteCalculateDrawProperties(root);
8870
jaydasikae9d09702015-09-15 01:26:418871 EXPECT_EQ(gfx::Rect(30, 30), test_layer->clip_rect());
jaydasika7d5c1ed2015-08-14 14:27:028872}
8873
jaydasika571dd2cf2015-09-25 20:55:428874TEST_F(LayerTreeHostCommonTest,
ajuma01734dd02015-10-07 01:22:088875 RenderSurfaceWithUnclippedDescendantsButDoesntApplyOwnClip) {
8876 // Ensure that the visible layer rect of a descendant of a surface with
8877 // unclipped descendants is computed correctly, when the surface doesn't apply
8878 // a clip.
8879 LayerImpl* root = root_layer();
8880 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
8881 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
8882 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
8883 LayerImpl* child = AddChild<LayerImpl>(render_surface);
8884
8885 const gfx::Transform identity_matrix;
8886
8887 clip_child->SetDrawsContent(true);
8888 child->SetDrawsContent(true);
8889 clip_child->SetClipParent(clip_parent);
8890 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
8891 clip_children->insert(clip_child);
8892 clip_parent->SetClipChildren(clip_children.release());
8893 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
8894 gfx::PointF(), gfx::Size(30, 10), true, false,
8895 true);
8896 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
8897 gfx::PointF(), gfx::Size(30, 30), true, false,
8898 false);
8899 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
8900 gfx::PointF(), gfx::Size(10, 15), true, false,
8901 true);
8902 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
8903 gfx::PointF(), gfx::Size(10, 10), true, false,
8904 false);
8905 SetLayerPropertiesForTesting(child, identity_matrix, gfx::Point3F(),
8906 gfx::PointF(), gfx::Size(40, 40), true, false,
8907 false);
8908
8909 ExecuteCalculateDrawProperties(root);
8910 EXPECT_EQ(gfx::Rect(40, 40), child->visible_layer_rect());
8911}
8912
8913TEST_F(LayerTreeHostCommonTest,
jaydasika571dd2cf2015-09-25 20:55:428914 RenderSurfaceClipsSubtreeAndHasUnclippedDescendants) {
8915 LayerImpl* root = root_layer();
8916 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
8917 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
8918 LayerImpl* test_layer1 = AddChild<LayerImpl>(render_surface);
8919 LayerImpl* clip_child = AddChild<LayerImpl>(test_layer1);
8920 LayerImpl* test_layer2 = AddChild<LayerImpl>(clip_child);
8921
8922 const gfx::Transform identity_matrix;
8923 root->SetMasksToBounds(true);
8924 render_surface->SetMasksToBounds(true);
8925 render_surface->SetDrawsContent(true);
8926 clip_child->SetDrawsContent(true);
8927 test_layer1->SetDrawsContent(true);
8928 test_layer2->SetDrawsContent(true);
8929 clip_child->SetClipParent(clip_parent);
8930 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
8931 clip_children->insert(clip_child);
8932 clip_parent->SetClipChildren(clip_children.release());
8933
8934 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
8935 gfx::PointF(), gfx::Size(30, 30), true, false,
8936 true);
8937 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
8938 gfx::PointF(), gfx::Size(30, 30), true, false,
8939 false);
8940 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
8941 gfx::PointF(), gfx::Size(50, 50), true, false,
8942 true);
8943 SetLayerPropertiesForTesting(test_layer1, identity_matrix, gfx::Point3F(),
8944 gfx::PointF(), gfx::Size(50, 50), true, false,
8945 false);
8946 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
8947 gfx::PointF(), gfx::Size(50, 50), true, false,
8948 false);
8949 SetLayerPropertiesForTesting(test_layer2, identity_matrix, gfx::Point3F(),
8950 gfx::PointF(), gfx::Size(50, 50), true, false,
8951 false);
8952
8953 ExecuteCalculateDrawProperties(root);
8954 EXPECT_EQ(gfx::Rect(50, 50), render_surface->visible_layer_rect());
8955 EXPECT_EQ(gfx::Rect(50, 50), test_layer1->visible_layer_rect());
8956 EXPECT_EQ(gfx::Rect(30, 30), clip_child->visible_layer_rect());
8957 EXPECT_EQ(gfx::Rect(30, 30), test_layer2->visible_layer_rect());
8958}
8959
ajumae2b7a5c2015-09-30 21:41:428960TEST_F(LayerTreeHostCommonTest, UnclippedClipParent) {
8961 LayerImpl* root = root_layer();
8962 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
8963 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
8964 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
8965
8966 const gfx::Transform identity_matrix;
8967 clip_parent->SetDrawsContent(true);
8968 render_surface->SetMasksToBounds(true);
8969 render_surface->SetDrawsContent(true);
8970 clip_child->SetDrawsContent(true);
8971
8972 clip_child->SetClipParent(clip_parent);
8973 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
8974 clip_children->insert(clip_child);
8975 clip_parent->SetClipChildren(clip_children.release());
8976
8977 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
8978 gfx::PointF(), gfx::Size(50, 50), true, false,
8979 true);
8980 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
8981 gfx::PointF(), gfx::Size(50, 50), true, false,
8982 false);
8983 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
8984 gfx::PointF(), gfx::Size(30, 30), true, false,
8985 true);
8986 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
8987 gfx::PointF(), gfx::Size(50, 50), true, false,
8988 false);
8989
8990 ExecuteCalculateDrawProperties(root);
8991
8992 // The clip child should inherit its clip parent's clipping state, not its
8993 // tree parent's clipping state.
8994 EXPECT_FALSE(clip_parent->is_clipped());
8995 EXPECT_TRUE(render_surface->is_clipped());
8996 EXPECT_FALSE(clip_child->is_clipped());
8997}
8998
jaydasika77a4a072015-10-20 21:47:278999TEST_F(LayerTreeHostCommonTest, RenderSurfaceContentRectWithMultipleSurfaces) {
9000 // Tests the value of render surface content rect when we have multiple types
9001 // of surfaces : unclipped surfaces, surfaces with unclipped surfaces and
9002 // clipped surfaces.
9003 LayerImpl* root = root_layer();
9004 LayerImpl* unclipped_surface = AddChildToRoot<LayerImpl>();
9005 LayerImpl* clip_parent = AddChild<LayerImpl>(unclipped_surface);
9006 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9007 LayerImpl* unclipped_desc_surface2 =
9008 AddChild<LayerImpl>(unclipped_desc_surface);
9009 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface2);
9010 LayerImpl* clipped_surface = AddChild<LayerImpl>(clip_child);
9011
9012 unclipped_surface->SetDrawsContent(true);
9013 unclipped_desc_surface->SetDrawsContent(true);
9014 unclipped_desc_surface2->SetDrawsContent(true);
9015 clipped_surface->SetDrawsContent(true);
9016 clip_child->SetClipParent(clip_parent);
9017 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9018 clip_children->insert(clip_child);
9019 clip_parent->SetClipChildren(clip_children.release());
9020
9021 gfx::Transform identity_matrix;
9022 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9023 gfx::PointF(), gfx::Size(80, 80), true, false,
9024 true);
9025 SetLayerPropertiesForTesting(unclipped_surface, identity_matrix,
9026 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
9027 true, false, true);
9028 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9029 gfx::PointF(), gfx::Size(50, 50), true, false,
9030 false);
9031 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
9032 gfx::Point3F(), gfx::PointF(),
9033 gfx::Size(100, 100), true, false, true);
9034 SetLayerPropertiesForTesting(unclipped_desc_surface2, identity_matrix,
9035 gfx::Point3F(), gfx::PointF(), gfx::Size(60, 60),
9036 true, false, true);
9037 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9038 gfx::PointF(), gfx::Size(100, 100), true, false,
9039 false);
9040 SetLayerPropertiesForTesting(clipped_surface, identity_matrix, gfx::Point3F(),
9041 gfx::PointF(), gfx::Size(70, 70), true, false,
9042 true);
9043 clip_parent->SetMasksToBounds(true);
9044 unclipped_surface->SetMasksToBounds(true);
9045 unclipped_desc_surface->SetMasksToBounds(true);
9046
9047 ExecuteCalculateDrawProperties(root);
9048 EXPECT_EQ(gfx::Rect(50, 50),
9049 unclipped_surface->render_surface()->content_rect());
9050 EXPECT_EQ(gfx::Rect(100, 100),
9051 unclipped_desc_surface->render_surface()->content_rect());
9052 EXPECT_EQ(gfx::Rect(50, 50),
9053 unclipped_desc_surface2->render_surface()->content_rect());
9054 EXPECT_EQ(gfx::Rect(50, 50),
9055 clipped_surface->render_surface()->content_rect());
9056}
9057
9058TEST_F(LayerTreeHostCommonTest, ClipBetweenClipChildTargetAndClipParentTarget) {
9059 // Tests the value of render surface content rect when we have a layer that
9060 // clips between the clip parent's target and clip child's target.
9061 LayerImpl* root = root_layer();
9062 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9063 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9064 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9065 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9066 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9067
9068 clip_child->SetDrawsContent(true);
9069 unclipped_desc_surface->SetDrawsContent(true);
9070 clip_child->SetClipParent(clip_parent);
9071 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9072 clip_children->insert(clip_child);
9073 clip_parent->SetClipChildren(clip_children.release());
9074
9075 gfx::Transform identity_matrix;
9076 gfx::Transform translate;
9077 translate.Translate(10, 10);
9078 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9079 gfx::PointF(), gfx::Size(100, 100), true, false,
9080 true);
9081 SetLayerPropertiesForTesting(surface, identity_matrix, gfx::Point3F(),
9082 gfx::PointF(), gfx::Size(100, 100), true, false,
9083 true);
9084 SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(),
9085 gfx::PointF(), gfx::Size(20, 20), true, false,
9086 false);
9087 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9088 gfx::PointF(), gfx::Size(50, 50), true, false,
9089 false);
9090 SetLayerPropertiesForTesting(unclipped_desc_surface, translate,
9091 gfx::Point3F(), gfx::PointF(),
9092 gfx::Size(100, 100), true, false, true);
9093 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9094 gfx::PointF(), gfx::Size(100, 100), true, false,
9095 false);
9096 surface->SetMasksToBounds(true);
9097 clip_layer->SetMasksToBounds(true);
9098
9099 ExecuteCalculateDrawProperties(root);
9100
9101 EXPECT_EQ(gfx::Rect(10, 10),
9102 unclipped_desc_surface->render_surface()->content_rect());
9103}
9104
jaydasika2c8c2872015-10-21 23:28:219105TEST_F(LayerTreeHostCommonTest, VisibleRectForDescendantOfScaledSurface) {
9106 LayerImpl* root = root_layer();
9107 LayerImpl* surface = AddChildToRoot<LayerImpl>();
9108 LayerImpl* clip_layer = AddChild<LayerImpl>(surface);
9109 LayerImpl* clip_parent = AddChild<LayerImpl>(clip_layer);
9110 LayerImpl* unclipped_desc_surface = AddChild<LayerImpl>(clip_parent);
9111 LayerImpl* clip_child = AddChild<LayerImpl>(unclipped_desc_surface);
9112
9113 clip_child->SetDrawsContent(true);
9114 unclipped_desc_surface->SetDrawsContent(true);
9115 clip_child->SetClipParent(clip_parent);
9116 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9117 clip_children->insert(clip_child);
9118 clip_parent->SetClipChildren(clip_children.release());
9119
9120 gfx::Transform identity_matrix;
9121 gfx::Transform scale;
9122 scale.Scale(2, 2);
9123 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9124 gfx::PointF(), gfx::Size(100, 100), true, false,
9125 true);
9126 SetLayerPropertiesForTesting(surface, scale, gfx::Point3F(), gfx::PointF(),
9127 gfx::Size(100, 100), true, false, true);
9128 SetLayerPropertiesForTesting(clip_layer, identity_matrix, gfx::Point3F(),
9129 gfx::PointF(), gfx::Size(20, 20), true, false,
9130 false);
9131 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9132 gfx::PointF(), gfx::Size(50, 50), true, false,
9133 false);
9134 SetLayerPropertiesForTesting(unclipped_desc_surface, identity_matrix,
9135 gfx::Point3F(), gfx::PointF(),
9136 gfx::Size(100, 100), true, false, true);
9137 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9138 gfx::PointF(), gfx::Size(100, 100), true, false,
9139 false);
9140 surface->SetMasksToBounds(true);
9141 clip_layer->SetMasksToBounds(true);
9142
9143 ExecuteCalculateDrawProperties(root);
9144
9145 EXPECT_EQ(gfx::Rect(20, 20), clip_child->visible_layer_rect());
9146}
9147
jaydasika60f85862015-10-01 20:36:149148TEST_F(LayerTreeHostCommonTest, LayerWithInputHandlerAndZeroOpacity) {
9149 LayerImpl* root = root_layer();
9150 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9151 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9152
9153 const gfx::Transform identity_matrix;
9154 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9155 gfx::PointF(), gfx::Size(30, 30), true, false,
9156 true);
9157 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9158 gfx::PointF(), gfx::Size(30, 30), true, false,
9159 true);
9160 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9161 gfx::PointF(), gfx::Size(20, 20), true, false,
9162 false);
9163
9164 render_surface->SetMasksToBounds(true);
9165 test_layer->SetDrawsContent(true);
9166 test_layer->SetOpacity(0);
9167 test_layer->SetHaveWheelEventHandlers(true);
9168
9169 ExecuteCalculateDrawProperties(root);
9170 EXPECT_EQ(gfx::Rect(20, 20), test_layer->drawable_content_rect());
9171 EXPECT_EQ(gfx::RectF(20, 20),
9172 render_surface->render_surface()->DrawableContentRect());
9173}
9174
jaydasikae4910fa22015-10-09 00:52:099175TEST_F(LayerTreeHostCommonTest, ClipChildVisibleRect) {
9176 LayerImpl* root = root_layer();
9177 LayerImpl* clip_parent = AddChildToRoot<LayerImpl>();
9178 LayerImpl* render_surface = AddChild<LayerImpl>(clip_parent);
9179 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface);
9180
9181 const gfx::Transform identity_matrix;
9182 clip_parent->SetMasksToBounds(true);
9183 render_surface->SetMasksToBounds(true);
9184 render_surface->SetDrawsContent(true);
9185 clip_child->SetDrawsContent(true);
9186 clip_child->SetClipParent(clip_parent);
9187 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9188 clip_children->insert(clip_child);
9189 clip_parent->SetClipChildren(clip_children.release());
9190
9191 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9192 gfx::PointF(), gfx::Size(30, 30), true, false,
9193 true);
9194 SetLayerPropertiesForTesting(clip_parent, identity_matrix, gfx::Point3F(),
9195 gfx::PointF(10.f, 10.f), gfx::Size(40, 40), true,
9196 false, false);
9197 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9198 gfx::PointF(), gfx::Size(50, 50), true, false,
9199 true);
9200 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9201 gfx::PointF(), gfx::Size(50, 50), true, false,
9202 false);
9203
9204 ExecuteCalculateDrawProperties(root);
9205 EXPECT_EQ(gfx::Rect(40, 40), clip_child->visible_layer_rect());
9206}
9207
jaydasika571dd2cf2015-09-25 20:55:429208TEST_F(LayerTreeHostCommonTest,
9209 LayerClipRectLargerThanClippingRenderSurfaceRect) {
9210 LayerImpl* root = root_layer();
9211 LayerImpl* render_surface = AddChild<LayerImpl>(root);
9212 LayerImpl* test_layer = AddChild<LayerImpl>(render_surface);
9213 const gfx::Transform identity_matrix;
9214 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9215 gfx::PointF(), gfx::Size(30, 30), true, false,
9216 true);
9217 SetLayerPropertiesForTesting(render_surface, identity_matrix, gfx::Point3F(),
9218 gfx::PointF(), gfx::Size(50, 50), true, false,
9219 true);
9220 SetLayerPropertiesForTesting(test_layer, identity_matrix, gfx::Point3F(),
9221 gfx::PointF(), gfx::Size(50, 50), true, false,
9222 false);
9223 root->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369224 root->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429225 render_surface->SetMasksToBounds(true);
jaydasika8640f9f2015-11-10 01:34:369226 render_surface->SetDrawsContent(true);
jaydasika571dd2cf2015-09-25 20:55:429227 test_layer->SetMasksToBounds(true);
9228 test_layer->SetDrawsContent(true);
9229 ExecuteCalculateDrawProperties(root);
9230
9231 EXPECT_EQ(gfx::Rect(30, 30), root->clip_rect());
9232 EXPECT_EQ(gfx::Rect(50, 50), render_surface->clip_rect());
9233 EXPECT_EQ(gfx::Rect(50, 50), test_layer->clip_rect());
9234}
9235
jaydasikac0137282015-10-01 15:50:309236TEST_F(LayerTreeHostCommonTest, TwoUnclippedRenderSurfaces) {
9237 LayerImpl* root = root_layer();
9238 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9239 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9240 LayerImpl* clip_child = AddChild<LayerImpl>(render_surface2);
9241
9242 const gfx::Transform identity_matrix;
9243 clip_child->SetClipParent(root);
9244 scoped_ptr<std::set<LayerImpl*>> clip_children(new std::set<LayerImpl*>);
9245 clip_children->insert(clip_child);
9246 root->SetClipChildren(clip_children.release());
9247 root->SetMasksToBounds(true);
9248 render_surface1->SetDrawsContent(true);
9249 render_surface2->SetDrawsContent(true);
9250
9251 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9252 gfx::PointF(), gfx::Size(30, 30), true, false,
9253 true);
9254 SetLayerPropertiesForTesting(render_surface1, identity_matrix, gfx::Point3F(),
9255 gfx::PointF(10, 10), gfx::Size(30, 30), true,
9256 false, true);
9257 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
9258 gfx::PointF(), gfx::Size(30, 30), true, false,
9259 true);
9260 SetLayerPropertiesForTesting(clip_child, identity_matrix, gfx::Point3F(),
9261 gfx::PointF(), gfx::Size(30, 30), true, false,
9262 false);
9263 ExecuteCalculateDrawProperties(root);
9264
9265 EXPECT_EQ(gfx::Rect(-10, -10, 30, 30), render_surface2->clip_rect());
9266}
9267
jaydasika5160e672015-10-15 15:25:149268TEST_F(LayerTreeHostCommonTest, LargeTransformTest) {
9269 LayerImpl* root = root_layer();
9270 LayerImpl* render_surface1 = AddChild<LayerImpl>(root);
9271 LayerImpl* render_surface2 = AddChild<LayerImpl>(render_surface1);
9272
9273 const gfx::Transform identity_matrix;
9274 render_surface1->SetDrawsContent(true);
9275 render_surface2->SetDrawsContent(true);
jaydasika445176f2015-11-04 20:14:039276 render_surface2->SetMasksToBounds(true);
jaydasika5160e672015-10-15 15:25:149277
9278 gfx::Transform large_transform;
9279 large_transform.Scale(99999999999999999999.f, 99999999999999999999.f);
9280 large_transform.Scale(9999999999999999999.f, 9999999999999999999.f);
9281 EXPECT_TRUE(std::isinf(large_transform.matrix().get(0, 0)));
9282 EXPECT_TRUE(std::isinf(large_transform.matrix().get(1, 1)));
9283
9284 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(),
9285 gfx::PointF(), gfx::Size(30, 30), true, false,
9286 true);
9287 SetLayerPropertiesForTesting(render_surface1, large_transform, gfx::Point3F(),
9288 gfx::PointF(), gfx::Size(30, 30), true, false,
9289 true);
9290 SetLayerPropertiesForTesting(render_surface2, identity_matrix, gfx::Point3F(),
9291 gfx::PointF(), gfx::Size(30, 30), true, false,
9292 true);
9293
9294 ExecuteCalculateDrawProperties(root);
9295
jaydasika8640f9f2015-11-10 01:34:369296 bool is_inf_or_nan =
9297 std::isinf(
9298 render_surface2->render_surface()->draw_transform().matrix().get(
9299 0, 0)) ||
9300 std::isnan(
9301 render_surface2->render_surface()->draw_transform().matrix().get(0,
9302 0));
9303 EXPECT_TRUE(is_inf_or_nan);
9304 is_inf_or_nan =
9305 std::isinf(
9306 render_surface2->render_surface()->draw_transform().matrix().get(
9307 1, 1)) ||
9308 std::isnan(
9309 render_surface2->render_surface()->draw_transform().matrix().get(1,
9310 1));
9311 EXPECT_TRUE(is_inf_or_nan);
jaydasika5160e672015-10-15 15:25:149312 EXPECT_EQ(gfx::RectF(),
9313 render_surface2->render_surface()->DrawableContentRect());
9314
9315 std::vector<LayerImpl*>* rsll = render_surface_layer_list_impl();
9316 bool root_in_rsll =
9317 std::find(rsll->begin(), rsll->end(), root) != rsll->end();
9318 EXPECT_TRUE(root_in_rsll);
9319 bool render_surface2_in_rsll =
9320 std::find(rsll->begin(), rsll->end(), render_surface2) != rsll->end();
9321 EXPECT_FALSE(render_surface2_in_rsll);
9322}
9323
[email protected]ba565742012-11-10 09:29:489324} // namespace
9325} // namespace cc