blob: e6a942d247ba93829bd661bf1189abdd19169d54 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// Copyright 2011 The Chromium Authors. All rights reserved.
2// 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>
9
[email protected]95e4e1a02013-03-18 07:09:0910#include "cc/animation/layer_animation_controller.h"
[email protected]1c3626e2014-04-09 17:49:2211#include "cc/animation/transform_operations.h"
[email protected]681ccff2013-03-18 06:13:5212#include "cc/base/math_util.h"
[email protected]cc3cfaa2013-03-18 09:05:5213#include "cc/layers/content_layer.h"
14#include "cc/layers/content_layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5215#include "cc/layers/layer.h"
[email protected]995708c52013-10-17 20:52:5916#include "cc/layers/layer_client.h"
[email protected]cc3cfaa2013-03-18 09:05:5217#include "cc/layers/layer_impl.h"
[email protected]390bb1ff2014-05-09 17:14:4018#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2819#include "cc/layers/render_surface.h"
20#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.h"
25#include "cc/test/fake_content_layer_client.h"
26#include "cc/test/fake_content_layer_impl.h"
[email protected]586d51ed2012-12-07 20:31:4527#include "cc/test/fake_impl_proxy.h"
[email protected]d600df7d2013-08-03 02:34:2828#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4529#include "cc/test/fake_layer_tree_host_impl.h"
sohan.jyotie3bd6192014-10-13 07:13:5930#include "cc/test/fake_picture_layer.h"
31#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0332#include "cc/test/geometry_test_utils.h"
[email protected]28336d52014-05-12 19:07:2833#include "cc/test/layer_tree_host_common_test.h"
reveman34b7a1522015-03-23 20:27:4734#include "cc/test/test_task_graph_runner.h"
[email protected]556fd292013-03-18 08:03:0435#include "cc/trees/layer_tree_impl.h"
36#include "cc/trees/proxy.h"
37#include "cc/trees/single_thread_proxy.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 {}
schenney0154bfa2015-02-05 19:46:4964 void PaintContents(SkCanvas* canvas,
65 const gfx::Rect& clip,
66 PaintingControlSetting picture_control) override {}
jbroman16d628c2015-05-29 20:11:5967 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
ajuma5e77f7d42014-11-27 14:19:1468 const gfx::Rect& clip,
schenney0154bfa2015-02-05 19:46:4969 PaintingControlSetting picture_control) override {
ajuma5e77f7d42014-11-27 14:19:1470 NOTIMPLEMENTED();
jbroman16d628c2015-05-29 20:11:5971 return nullptr;
ajuma5e77f7d42014-11-27 14:19:1472 }
dcheng716bedf2014-10-21 09:51:0873 bool FillsBoundsCompletely() const override { return false; }
[email protected]f34a24232012-09-20 22:59:5574};
75
sohan.jyotie3bd6192014-10-13 07:13:5976scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer(
loysoa6edaaff2015-05-25 03:26:4477 const LayerSettings& settings,
sohan.jyotie3bd6192014-10-13 07:13:5978 ContentLayerClient* delegate) {
79 scoped_refptr<FakePictureLayer> to_return =
loysoa6edaaff2015-05-25 03:26:4480 FakePictureLayer::Create(settings, delegate);
sohan.jyotie3bd6192014-10-13 07:13:5981 to_return->SetIsDrawable(true);
82 return to_return;
83}
84
[email protected]fb661802013-03-25 01:59:3285scoped_refptr<ContentLayer> CreateDrawableContentLayer(
loysoa6edaaff2015-05-25 03:26:4486 const LayerSettings& settings,
[email protected]fb661802013-03-25 01:59:3287 ContentLayerClient* delegate) {
loysoa6edaaff2015-05-25 03:26:4488 scoped_refptr<ContentLayer> to_return =
89 ContentLayer::Create(settings, delegate);
[email protected]fb661802013-03-25 01:59:3290 to_return->SetIsDrawable(true);
91 return to_return;
[email protected]f34a24232012-09-20 22:59:5592}
93
[email protected]989386c2013-07-18 21:37:2394#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
95 do { \
96 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
97 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:4798 } while (false)
99
sohan.jyotie3bd6192014-10-13 07:13:59100#define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
101 do { \
102 EXPECT_FLOAT_EQ(expected, layer->draw_properties().ideal_contents_scale); \
103 } while (false)
104
[email protected]989386c2013-07-18 21:37:23105TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:32106 // Sanity check: For layers positioned at zero, with zero size,
107 // and with identity transforms, then the draw transform,
108 // screen space transform, and the hierarchy passed on to children
109 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14110
loysoa6edaaff2015-05-25 03:26:44111 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
112 scoped_refptr<Layer> child = Layer::Create(layer_settings());
113 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:32114 parent->AddChild(child);
115 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14116
enne2097cab2014-09-25 20:16:31117 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28118 host->SetRootLayer(parent);
119
[email protected]fb661802013-03-25 01:59:32120 gfx::Transform identity_matrix;
121 SetLayerPropertiesForTesting(parent.get(),
122 identity_matrix,
[email protected]a2566412014-06-05 03:14:20123 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32124 gfx::PointF(),
125 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:57126 true,
[email protected]fb661802013-03-25 01:59:32127 false);
128 SetLayerPropertiesForTesting(child.get(),
129 identity_matrix,
[email protected]a2566412014-06-05 03:14:20130 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32131 gfx::PointF(),
132 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57133 true,
[email protected]fb661802013-03-25 01:59:32134 false);
135 SetLayerPropertiesForTesting(grand_child.get(),
136 identity_matrix,
[email protected]a2566412014-06-05 03:14:20137 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32138 gfx::PointF(),
139 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57140 true,
[email protected]fb661802013-03-25 01:59:32141 false);
[email protected]94f206c12012-08-25 00:09:14142
[email protected]fb661802013-03-25 01:59:32143 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14144
[email protected]fb661802013-03-25 01:59:32145 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
146 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
147 child->screen_space_transform());
148 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
149 grand_child->draw_transform());
150 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
151 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14152}
153
[email protected]f9e56702014-06-13 01:19:59154TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) {
loysoa6edaaff2015-05-25 03:26:44155 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
156 scoped_refptr<Layer> child = Layer::Create(layer_settings());
157 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
[email protected]f9e56702014-06-13 01:19:59158 parent->AddChild(child);
159 child->AddChild(grand_child);
160
enne2097cab2014-09-25 20:16:31161 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]f9e56702014-06-13 01:19:59162 host->SetRootLayer(parent);
163
164 gfx::Transform identity_matrix;
165 SetLayerPropertiesForTesting(parent.get(),
166 identity_matrix,
167 gfx::Point3F(),
168 gfx::PointF(),
169 gfx::Size(100, 100),
170 true,
171 false);
172 SetLayerPropertiesForTesting(child.get(),
173 identity_matrix,
174 gfx::Point3F(),
175 gfx::PointF(10, 10),
176 gfx::Size(100, 100),
177 true,
178 false);
179 // This would have previously caused us to skip our subtree, but this would be
180 // wrong; we need up-to-date draw properties to do hit testing on the layers
181 // with handlers.
182 child->SetOpacity(0.f);
183 SetLayerPropertiesForTesting(grand_child.get(),
184 identity_matrix,
185 gfx::Point3F(),
186 gfx::PointF(10, 10),
187 gfx::Size(100, 100),
188 true,
189 false);
190 grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
191
192 ExecuteCalculateDrawProperties(parent.get());
193
194 // Check that we've computed draw properties for the subtree rooted at
195 // |child|.
196 EXPECT_FALSE(child->draw_transform().IsIdentity());
197 EXPECT_FALSE(grand_child->draw_transform().IsIdentity());
198}
199
[email protected]989386c2013-07-18 21:37:23200TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32201 gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:44202 scoped_refptr<Layer> layer = Layer::Create(layer_settings());
[email protected]94f206c12012-08-25 00:09:14203
loysoa6edaaff2015-05-25 03:26:44204 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:32205 SetLayerPropertiesForTesting(root.get(),
206 identity_matrix,
[email protected]a2566412014-06-05 03:14:20207 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32208 gfx::PointF(),
209 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57210 true,
[email protected]fb661802013-03-25 01:59:32211 false);
212 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42213
enne2097cab2014-09-25 20:16:31214 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28215 host->SetRootLayer(root);
216
[email protected]fb661802013-03-25 01:59:32217 // Case 2: Setting the bounds of the layer should not affect either the draw
218 // transform or the screenspace transform.
219 gfx::Transform translation_to_center;
220 translation_to_center.Translate(5.0, 6.0);
221 SetLayerPropertiesForTesting(layer.get(),
222 identity_matrix,
[email protected]a2566412014-06-05 03:14:20223 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32224 gfx::PointF(),
225 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57226 true,
[email protected]fb661802013-03-25 01:59:32227 false);
228 ExecuteCalculateDrawProperties(root.get());
229 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
230 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
231 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14232
[email protected]fb661802013-03-25 01:59:32233 // Case 3: The anchor point by itself (without a layer transform) should have
234 // no effect on the transforms.
235 SetLayerPropertiesForTesting(layer.get(),
236 identity_matrix,
[email protected]a2566412014-06-05 03:14:20237 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32238 gfx::PointF(),
239 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57240 true,
[email protected]fb661802013-03-25 01:59:32241 false);
242 ExecuteCalculateDrawProperties(root.get());
243 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
244 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
245 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14246
[email protected]fb661802013-03-25 01:59:32247 // Case 4: A change in actual position affects both the draw transform and
248 // screen space transform.
249 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05250 position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32251 SetLayerPropertiesForTesting(layer.get(),
252 identity_matrix,
[email protected]a2566412014-06-05 03:14:20253 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32254 gfx::PointF(0.f, 1.2f),
255 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57256 true,
[email protected]fb661802013-03-25 01:59:32257 false);
258 ExecuteCalculateDrawProperties(root.get());
259 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform());
260 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
261 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14262
[email protected]fb661802013-03-25 01:59:32263 // Case 5: In the correct sequence of transforms, the layer transform should
264 // pre-multiply the translation_to_center. This is easily tested by using a
265 // scale transform, because scale and translation are not commutative.
266 gfx::Transform layer_transform;
267 layer_transform.Scale3d(2.0, 2.0, 1.0);
268 SetLayerPropertiesForTesting(layer.get(),
269 layer_transform,
[email protected]a2566412014-06-05 03:14:20270 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32271 gfx::PointF(),
272 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57273 true,
[email protected]fb661802013-03-25 01:59:32274 false);
275 ExecuteCalculateDrawProperties(root.get());
276 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
277 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
278 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14279
[email protected]fb661802013-03-25 01:59:32280 // Case 6: The layer transform should occur with respect to the anchor point.
281 gfx::Transform translation_to_anchor;
282 translation_to_anchor.Translate(5.0, 0.0);
283 gfx::Transform expected_result =
284 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
285 SetLayerPropertiesForTesting(layer.get(),
286 layer_transform,
[email protected]a2566412014-06-05 03:14:20287 gfx::Point3F(5.0f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32288 gfx::PointF(),
289 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57290 true,
[email protected]fb661802013-03-25 01:59:32291 false);
292 ExecuteCalculateDrawProperties(root.get());
293 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
294 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
295 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14296
[email protected]fb661802013-03-25 01:59:32297 // Case 7: Verify that position pre-multiplies the layer transform. The
298 // current implementation of CalculateDrawProperties does this implicitly, but
299 // it is still worth testing to detect accidental regressions.
300 expected_result = position_transform * translation_to_anchor *
301 layer_transform * Inverse(translation_to_anchor);
302 SetLayerPropertiesForTesting(layer.get(),
303 layer_transform,
[email protected]a2566412014-06-05 03:14:20304 gfx::Point3F(5.0f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32305 gfx::PointF(0.f, 1.2f),
306 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57307 true,
[email protected]fb661802013-03-25 01:59:32308 false);
309 ExecuteCalculateDrawProperties(root.get());
310 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
311 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
312 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14313}
314
[email protected]989386c2013-07-18 21:37:23315TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13316 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32317 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01318 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32319 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
320 -kScrollOffset.y());
321 const float kPageScale = 0.888f;
322 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20323
[email protected]fb661802013-03-25 01:59:32324 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:45325 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:47326 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]657b24c2013-03-06 09:01:20327
[email protected]fb661802013-03-25 01:59:32328 gfx::Transform identity_matrix;
329 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
330 LayerImpl::Create(host_impl.active_tree(), 1));
331 LayerImpl* sublayer = sublayer_scoped_ptr.get();
332 sublayer->SetContentsScale(kPageScale * kDeviceScale,
333 kPageScale * kDeviceScale);
awoloszyne83f28c2014-12-22 15:40:00334 SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(),
335 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:32336 false);
[email protected]657b24c2013-03-06 09:01:20337
[email protected]adeda572014-01-31 00:49:47338 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32339 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47340 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
awoloszyne83f28c2014-12-22 15:40:00341 SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(),
342 gfx::PointF(), gfx::Size(10, 20), true, false,
[email protected]fb661802013-03-25 01:59:32343 false);
[email protected]adeda572014-01-31 00:49:47344 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
345 LayerImpl::Create(host_impl.active_tree(), 4));
346 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
347
348 scroll_layer->SetScrollClipLayer(clip_layer->id());
349 clip_layer->SetBounds(
350 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
351 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
352 scroll_layer->SetScrollClipLayer(clip_layer->id());
[email protected]fb661802013-03-25 01:59:32353 scroll_layer->SetScrollDelta(kScrollDelta);
354 gfx::Transform impl_transform;
[email protected]fb661802013-03-25 01:59:32355 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
[email protected]adeda572014-01-31 00:49:47356 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
357 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass());
aeliasf998da82015-02-03 01:40:51358 scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20359
[email protected]fb661802013-03-25 01:59:32360 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
awoloszyne83f28c2014-12-22 15:40:00361 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
362 gfx::PointF(), gfx::Size(3, 4), true, false,
[email protected]fb661802013-03-25 01:59:32363 false);
[email protected]adeda572014-01-31 00:49:47364 root->AddChild(clip_layer_scoped_ptr.Pass());
awoloszyne83f28c2014-12-22 15:40:00365 root->SetHasRenderSurface(true);
[email protected]657b24c2013-03-06 09:01:20366
[email protected]f2136262013-04-26 21:10:19367 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32368 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32369 gfx::Transform expected_transform = identity_matrix;
370 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
371 sub_layer_screen_position.Scale(kPageScale * kDeviceScale);
372 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()),
373 MathUtil::Round(sub_layer_screen_position.y()));
374 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
375 sublayer->draw_transform());
376 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
377 sublayer->screen_space_transform());
[email protected]657b24c2013-03-06 09:01:20378
[email protected]fb661802013-03-25 01:59:32379 gfx::Transform arbitrary_translate;
380 const float kTranslateX = 10.6f;
381 const float kTranslateY = 20.6f;
382 arbitrary_translate.Translate(kTranslateX, kTranslateY);
awoloszyne83f28c2014-12-22 15:40:00383 SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate,
384 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
385 true, false, false);
[email protected]f2136262013-04-26 21:10:19386 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32387 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32388 expected_transform.MakeIdentity();
389 expected_transform.Translate(
390 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
391 sub_layer_screen_position.x()),
392 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
393 sub_layer_screen_position.y()));
394 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
395 sublayer->draw_transform());
[email protected]657b24c2013-03-06 09:01:20396}
397
[email protected]989386c2013-07-18 21:37:23398TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32399 gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:44400 scoped_refptr<Layer> root = Layer::Create(layer_settings());
401 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
402 scoped_refptr<Layer> child = Layer::Create(layer_settings());
403 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:32404 root->AddChild(parent);
405 parent->AddChild(child);
406 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14407
enne2097cab2014-09-25 20:16:31408 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28409 host->SetRootLayer(root);
410
[email protected]fb661802013-03-25 01:59:32411 // One-time setup of root layer
412 SetLayerPropertiesForTesting(root.get(),
413 identity_matrix,
[email protected]a2566412014-06-05 03:14:20414 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32415 gfx::PointF(),
416 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57417 true,
[email protected]fb661802013-03-25 01:59:32418 false);
[email protected]ecc12622012-10-30 20:45:42419
[email protected]fb661802013-03-25 01:59:32420 // Case 1: parent's anchor point should not affect child or grand_child.
421 SetLayerPropertiesForTesting(parent.get(),
422 identity_matrix,
[email protected]a2566412014-06-05 03:14:20423 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32424 gfx::PointF(),
425 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57426 true,
[email protected]fb661802013-03-25 01:59:32427 false);
428 SetLayerPropertiesForTesting(child.get(),
429 identity_matrix,
[email protected]a2566412014-06-05 03:14:20430 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32431 gfx::PointF(),
432 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57433 true,
[email protected]fb661802013-03-25 01:59:32434 false);
435 SetLayerPropertiesForTesting(grand_child.get(),
436 identity_matrix,
[email protected]a2566412014-06-05 03:14:20437 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32438 gfx::PointF(),
439 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57440 true,
[email protected]fb661802013-03-25 01:59:32441 false);
442 ExecuteCalculateDrawProperties(root.get());
443 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
444 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
445 child->screen_space_transform());
446 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
447 grand_child->draw_transform());
448 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
449 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14450
[email protected]fb661802013-03-25 01:59:32451 // Case 2: parent's position affects child and grand_child.
452 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05453 parent_position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32454 SetLayerPropertiesForTesting(parent.get(),
455 identity_matrix,
[email protected]a2566412014-06-05 03:14:20456 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32457 gfx::PointF(0.f, 1.2f),
458 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57459 true,
[email protected]fb661802013-03-25 01:59:32460 false);
461 SetLayerPropertiesForTesting(child.get(),
462 identity_matrix,
[email protected]a2566412014-06-05 03:14:20463 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32464 gfx::PointF(),
465 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57466 true,
[email protected]fb661802013-03-25 01:59:32467 false);
468 SetLayerPropertiesForTesting(grand_child.get(),
469 identity_matrix,
[email protected]a2566412014-06-05 03:14:20470 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32471 gfx::PointF(),
472 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57473 true,
[email protected]fb661802013-03-25 01:59:32474 false);
475 ExecuteCalculateDrawProperties(root.get());
476 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
477 child->draw_transform());
478 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
479 child->screen_space_transform());
480 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
481 grand_child->draw_transform());
482 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
483 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14484
[email protected]fb661802013-03-25 01:59:32485 // Case 3: parent's local transform affects child and grandchild
486 gfx::Transform parent_layer_transform;
487 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
488 gfx::Transform parent_translation_to_anchor;
489 parent_translation_to_anchor.Translate(2.5, 3.0);
490 gfx::Transform parent_composite_transform =
491 parent_translation_to_anchor * parent_layer_transform *
492 Inverse(parent_translation_to_anchor);
493 SetLayerPropertiesForTesting(parent.get(),
494 parent_layer_transform,
[email protected]a2566412014-06-05 03:14:20495 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32496 gfx::PointF(),
497 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57498 true,
[email protected]fb661802013-03-25 01:59:32499 false);
500 SetLayerPropertiesForTesting(child.get(),
501 identity_matrix,
[email protected]a2566412014-06-05 03:14:20502 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32503 gfx::PointF(),
504 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57505 true,
[email protected]fb661802013-03-25 01:59:32506 false);
507 SetLayerPropertiesForTesting(grand_child.get(),
508 identity_matrix,
[email protected]a2566412014-06-05 03:14:20509 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32510 gfx::PointF(),
511 gfx::Size(76, 78),
[email protected]56fffdd2014-02-11 19:50:57512 true,
[email protected]fb661802013-03-25 01:59:32513 false);
514 ExecuteCalculateDrawProperties(root.get());
515 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
516 child->draw_transform());
517 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
518 child->screen_space_transform());
519 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
520 grand_child->draw_transform());
521 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
522 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14523}
524
[email protected]989386c2013-07-18 21:37:23525TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
loysoa6edaaff2015-05-25 03:26:44526 scoped_refptr<Layer> root = Layer::Create(layer_settings());
527 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
528 scoped_refptr<Layer> child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:32529 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loysoa6edaaff2015-05-25 03:26:44530 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:32531 root->AddChild(parent);
532 parent->AddChild(child);
533 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14534
enne2097cab2014-09-25 20:16:31535 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28536 host->SetRootLayer(root);
537
[email protected]fb661802013-03-25 01:59:32538 // One-time setup of root layer
539 gfx::Transform identity_matrix;
540 SetLayerPropertiesForTesting(root.get(),
541 identity_matrix,
[email protected]a2566412014-06-05 03:14:20542 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32543 gfx::PointF(),
544 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57545 true,
[email protected]fb661802013-03-25 01:59:32546 false);
[email protected]ecc12622012-10-30 20:45:42547
[email protected]fb661802013-03-25 01:59:32548 // Child is set up so that a new render surface should be created.
549 child->SetOpacity(0.5f);
550 child->SetForceRenderSurface(true);
[email protected]94f206c12012-08-25 00:09:14551
[email protected]fb661802013-03-25 01:59:32552 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05553 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32554 gfx::Transform parent_translation_to_anchor;
555 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44556
[email protected]fb661802013-03-25 01:59:32557 gfx::Transform parent_composite_transform =
558 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39559 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32560 gfx::Vector2dF parent_composite_scale =
561 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
562 1.f);
563 gfx::Transform surface_sublayer_transform;
564 surface_sublayer_transform.Scale(parent_composite_scale.x(),
565 parent_composite_scale.y());
566 gfx::Transform surface_sublayer_composite_transform =
567 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14568
[email protected]fb661802013-03-25 01:59:32569 // Child's render surface should not exist yet.
570 ASSERT_FALSE(child->render_surface());
[email protected]94f206c12012-08-25 00:09:14571
[email protected]fb661802013-03-25 01:59:32572 SetLayerPropertiesForTesting(parent.get(),
573 parent_layer_transform,
[email protected]a2566412014-06-05 03:14:20574 gfx::Point3F(25.0f, 30.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32575 gfx::PointF(),
576 gfx::Size(100, 120),
[email protected]56fffdd2014-02-11 19:50:57577 true,
[email protected]fb661802013-03-25 01:59:32578 false);
579 SetLayerPropertiesForTesting(child.get(),
580 identity_matrix,
[email protected]a2566412014-06-05 03:14:20581 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32582 gfx::PointF(),
583 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57584 true,
[email protected]fb661802013-03-25 01:59:32585 false);
586 SetLayerPropertiesForTesting(grand_child.get(),
587 identity_matrix,
[email protected]a2566412014-06-05 03:14:20588 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32589 gfx::PointF(),
590 gfx::Size(8, 10),
[email protected]56fffdd2014-02-11 19:50:57591 true,
[email protected]fb661802013-03-25 01:59:32592 false);
593 ExecuteCalculateDrawProperties(root.get());
[email protected]94f206c12012-08-25 00:09:14594
[email protected]fb661802013-03-25 01:59:32595 // Render surface should have been created now.
596 ASSERT_TRUE(child->render_surface());
Daniel Chengeea98042014-08-26 00:28:10597 ASSERT_EQ(child.get(), child->render_target());
[email protected]94f206c12012-08-25 00:09:14598
[email protected]fb661802013-03-25 01:59:32599 // The child layer's draw transform should refer to its new render surface.
600 // The screen-space transform, however, should still refer to the root.
601 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
602 child->draw_transform());
603 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
604 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14605
[email protected]fb661802013-03-25 01:59:32606 // Because the grand_child is the only drawable content, the child's render
607 // surface will tighten its bounds to the grand_child. The scale at which the
608 // surface's subtree is drawn must be removed from the composite transform.
609 EXPECT_TRANSFORMATION_MATRIX_EQ(
610 surface_sublayer_composite_transform,
611 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14612
[email protected]fb661802013-03-25 01:59:32613 // The screen space is the same as the target since the child surface draws
614 // into the root.
615 EXPECT_TRANSFORMATION_MATRIX_EQ(
616 surface_sublayer_composite_transform,
617 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14618}
619
[email protected]989386c2013-07-18 21:37:23620TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
loysoa6edaaff2015-05-25 03:26:44621 scoped_refptr<Layer> root = Layer::Create(layer_settings());
622 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
623 scoped_refptr<Layer> child = Layer::Create(layer_settings());
624 scoped_refptr<Layer> child_replica = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:32625 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loysoa6edaaff2015-05-25 03:26:44626 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:32627 root->AddChild(parent);
628 parent->AddChild(child);
629 child->AddChild(grand_child);
630 child->SetReplicaLayer(child_replica.get());
631
enne2097cab2014-09-25 20:16:31632 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28633 host->SetRootLayer(root);
634
[email protected]fb661802013-03-25 01:59:32635 // One-time setup of root layer
636 gfx::Transform identity_matrix;
637 SetLayerPropertiesForTesting(root.get(),
638 identity_matrix,
[email protected]a2566412014-06-05 03:14:20639 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32640 gfx::PointF(),
641 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57642 true,
[email protected]fb661802013-03-25 01:59:32643 false);
644
645 // Child is set up so that a new render surface should be created.
646 child->SetOpacity(0.5f);
647
648 gfx::Transform parent_layer_transform;
649 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
650 gfx::Transform parent_translation_to_anchor;
651 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32652 gfx::Transform parent_composite_transform =
653 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39654 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32655 gfx::Transform replica_layer_transform;
656 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
657 gfx::Vector2dF parent_composite_scale =
658 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
659 1.f);
660 gfx::Transform surface_sublayer_transform;
661 surface_sublayer_transform.Scale(parent_composite_scale.x(),
662 parent_composite_scale.y());
663 gfx::Transform replica_composite_transform =
664 parent_composite_transform * replica_layer_transform *
665 Inverse(surface_sublayer_transform);
vollick51ed1a22014-12-17 02:03:00666 child_replica->SetIsDrawable(true);
[email protected]fb661802013-03-25 01:59:32667 // Child's render surface should not exist yet.
668 ASSERT_FALSE(child->render_surface());
669
670 SetLayerPropertiesForTesting(parent.get(),
671 parent_layer_transform,
[email protected]a2566412014-06-05 03:14:20672 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32673 gfx::PointF(),
674 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57675 true,
[email protected]fb661802013-03-25 01:59:32676 false);
677 SetLayerPropertiesForTesting(child.get(),
678 identity_matrix,
[email protected]a2566412014-06-05 03:14:20679 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32680 gfx::PointF(),
681 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57682 true,
[email protected]fb661802013-03-25 01:59:32683 false);
684 SetLayerPropertiesForTesting(grand_child.get(),
685 identity_matrix,
[email protected]a2566412014-06-05 03:14:20686 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32687 gfx::PointF(-0.5f, -0.5f),
688 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:57689 true,
[email protected]fb661802013-03-25 01:59:32690 false);
691 SetLayerPropertiesForTesting(child_replica.get(),
692 replica_layer_transform,
[email protected]a2566412014-06-05 03:14:20693 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32694 gfx::PointF(),
695 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57696 true,
[email protected]fb661802013-03-25 01:59:32697 false);
698 ExecuteCalculateDrawProperties(root.get());
699
700 // Render surface should have been created now.
701 ASSERT_TRUE(child->render_surface());
Daniel Chengeea98042014-08-26 00:28:10702 ASSERT_EQ(child.get(), child->render_target());
[email protected]fb661802013-03-25 01:59:32703
704 EXPECT_TRANSFORMATION_MATRIX_EQ(
705 replica_composite_transform,
706 child->render_target()->render_surface()->replica_draw_transform());
707 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57708 child->render_target()
709 ->render_surface()
[email protected]fb661802013-03-25 01:59:32710 ->replica_screen_space_transform());
711}
712
[email protected]989386c2013-07-18 21:37:23713TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32714 // This test creates a more complex tree and verifies it all at once. This
715 // covers the following cases:
716 // - layers that are described w.r.t. a render surface: should have draw
717 // transforms described w.r.t. that surface
718 // - A render surface described w.r.t. an ancestor render surface: should
719 // have a draw transform described w.r.t. that ancestor surface
720 // - Replicas of a render surface are described w.r.t. the replica's
721 // transform around its anchor, along with the surface itself.
722 // - Sanity check on recursion: verify transforms of layers described w.r.t.
723 // a render surface that is described w.r.t. an ancestor render surface.
724 // - verifying that each layer has a reference to the correct render surface
725 // and render target values.
726
loysoa6edaaff2015-05-25 03:26:44727 scoped_refptr<Layer> root = Layer::Create(layer_settings());
728 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
729 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
730 scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings());
731 scoped_refptr<Layer> child_of_root = Layer::Create(layer_settings());
732 scoped_refptr<Layer> child_of_rs1 = Layer::Create(layer_settings());
733 scoped_refptr<Layer> child_of_rs2 = Layer::Create(layer_settings());
734 scoped_refptr<Layer> replica_of_rs1 = Layer::Create(layer_settings());
735 scoped_refptr<Layer> replica_of_rs2 = Layer::Create(layer_settings());
736 scoped_refptr<Layer> grand_child_of_root = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:32737 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
loysoa6edaaff2015-05-25 03:26:44738 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:32739 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
loysoa6edaaff2015-05-25 03:26:44740 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:32741 root->AddChild(parent);
742 parent->AddChild(render_surface1);
743 parent->AddChild(child_of_root);
744 render_surface1->AddChild(child_of_rs1);
745 render_surface1->AddChild(render_surface2);
746 render_surface2->AddChild(child_of_rs2);
747 child_of_root->AddChild(grand_child_of_root);
748 child_of_rs1->AddChild(grand_child_of_rs1);
749 child_of_rs2->AddChild(grand_child_of_rs2);
750 render_surface1->SetReplicaLayer(replica_of_rs1.get());
751 render_surface2->SetReplicaLayer(replica_of_rs2.get());
752
enne2097cab2014-09-25 20:16:31753 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28754 host->SetRootLayer(root);
755
[email protected]fb661802013-03-25 01:59:32756 // In combination with descendant draws content, opacity != 1 forces the layer
757 // to have a new render surface.
758 render_surface1->SetOpacity(0.5f);
759 render_surface2->SetOpacity(0.33f);
760
761 // One-time setup of root layer
762 gfx::Transform identity_matrix;
763 SetLayerPropertiesForTesting(root.get(),
764 identity_matrix,
[email protected]a2566412014-06-05 03:14:20765 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32766 gfx::PointF(),
767 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57768 true,
[email protected]fb661802013-03-25 01:59:32769 false);
770
771 // All layers in the tree are initialized with an anchor at .25 and a size of
772 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39773 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32774 gfx::Transform translation_to_anchor;
775 translation_to_anchor.Translate(2.5, 0.0);
776 gfx::Transform layer_transform;
777 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32778 gfx::Transform replica_layer_transform;
779 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
780
781 gfx::Transform A =
782 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32783 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
784 Inverse(translation_to_anchor);
785
786 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39787 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32788 gfx::Transform surface1_sublayer_transform;
789 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
790 surface1_parent_transform_scale.y());
791
792 // SS1 = transform given to the subtree of render_surface1
793 gfx::Transform SS1 = surface1_sublayer_transform;
794 // S1 = transform to move from render_surface1 pixels to the layer space of
795 // the owning layer
796 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
797
798 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39799 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32800 gfx::Transform surface2_sublayer_transform;
801 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
802 surface2_parent_transform_scale.y());
803
804 // SS2 = transform given to the subtree of render_surface2
805 gfx::Transform SS2 = surface2_sublayer_transform;
806 // S2 = transform to move from render_surface2 pixels to the layer space of
807 // the owning layer
808 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
809
810 SetLayerPropertiesForTesting(parent.get(),
811 layer_transform,
[email protected]a2566412014-06-05 03:14:20812 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32813 gfx::PointF(),
814 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57815 true,
[email protected]fb661802013-03-25 01:59:32816 false);
817 SetLayerPropertiesForTesting(render_surface1.get(),
818 layer_transform,
[email protected]a2566412014-06-05 03:14:20819 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32820 gfx::PointF(),
821 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57822 true,
[email protected]fb661802013-03-25 01:59:32823 false);
824 SetLayerPropertiesForTesting(render_surface2.get(),
825 layer_transform,
[email protected]a2566412014-06-05 03:14:20826 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32827 gfx::PointF(),
828 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57829 true,
[email protected]fb661802013-03-25 01:59:32830 false);
831 SetLayerPropertiesForTesting(child_of_root.get(),
832 layer_transform,
[email protected]a2566412014-06-05 03:14:20833 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32834 gfx::PointF(),
835 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57836 true,
[email protected]fb661802013-03-25 01:59:32837 false);
838 SetLayerPropertiesForTesting(child_of_rs1.get(),
839 layer_transform,
[email protected]a2566412014-06-05 03:14:20840 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32841 gfx::PointF(),
842 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57843 true,
[email protected]fb661802013-03-25 01:59:32844 false);
845 SetLayerPropertiesForTesting(child_of_rs2.get(),
846 layer_transform,
[email protected]a2566412014-06-05 03:14:20847 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32848 gfx::PointF(),
849 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57850 true,
[email protected]fb661802013-03-25 01:59:32851 false);
852 SetLayerPropertiesForTesting(grand_child_of_root.get(),
853 layer_transform,
[email protected]a2566412014-06-05 03:14:20854 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32855 gfx::PointF(),
856 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57857 true,
[email protected]fb661802013-03-25 01:59:32858 false);
859 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
860 layer_transform,
[email protected]a2566412014-06-05 03:14:20861 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32862 gfx::PointF(),
863 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57864 true,
[email protected]fb661802013-03-25 01:59:32865 false);
866 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
867 layer_transform,
[email protected]a2566412014-06-05 03:14:20868 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32869 gfx::PointF(),
870 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57871 true,
[email protected]fb661802013-03-25 01:59:32872 false);
873 SetLayerPropertiesForTesting(replica_of_rs1.get(),
874 replica_layer_transform,
[email protected]a2566412014-06-05 03:14:20875 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32876 gfx::PointF(),
877 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57878 true,
[email protected]fb661802013-03-25 01:59:32879 false);
880 SetLayerPropertiesForTesting(replica_of_rs2.get(),
881 replica_layer_transform,
[email protected]a2566412014-06-05 03:14:20882 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32883 gfx::PointF(),
884 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57885 true,
[email protected]fb661802013-03-25 01:59:32886 false);
887
888 ExecuteCalculateDrawProperties(root.get());
889
890 // Only layers that are associated with render surfaces should have an actual
891 // RenderSurface() value.
892 ASSERT_TRUE(root->render_surface());
893 ASSERT_FALSE(child_of_root->render_surface());
894 ASSERT_FALSE(grand_child_of_root->render_surface());
895
896 ASSERT_TRUE(render_surface1->render_surface());
897 ASSERT_FALSE(child_of_rs1->render_surface());
898 ASSERT_FALSE(grand_child_of_rs1->render_surface());
899
900 ASSERT_TRUE(render_surface2->render_surface());
901 ASSERT_FALSE(child_of_rs2->render_surface());
902 ASSERT_FALSE(grand_child_of_rs2->render_surface());
903
904 // Verify all render target accessors
Daniel Chengeea98042014-08-26 00:28:10905 EXPECT_EQ(root.get(), parent->render_target());
906 EXPECT_EQ(root.get(), child_of_root->render_target());
907 EXPECT_EQ(root.get(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32908
Daniel Chengeea98042014-08-26 00:28:10909 EXPECT_EQ(render_surface1.get(), render_surface1->render_target());
910 EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target());
911 EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32912
Daniel Chengeea98042014-08-26 00:28:10913 EXPECT_EQ(render_surface2.get(), render_surface2->render_target());
914 EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target());
915 EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32916
917 // Verify layer draw transforms note that draw transforms are described with
918 // respect to the nearest ancestor render surface but screen space transforms
919 // are described with respect to the root.
920 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
[email protected]baf64d062014-02-16 22:10:39921 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform());
922 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32923 grand_child_of_root->draw_transform());
924
925 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
[email protected]baf64d062014-02-16 22:10:39926 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform());
927 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
[email protected]fb661802013-03-25 01:59:32928 grand_child_of_rs1->draw_transform());
929
930 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
[email protected]baf64d062014-02-16 22:10:39931 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform());
932 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
[email protected]fb661802013-03-25 01:59:32933 grand_child_of_rs2->draw_transform());
934
935 // Verify layer screen-space transforms
936 //
937 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39938 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:32939 child_of_root->screen_space_transform());
940 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39941 A * A * A, grand_child_of_root->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32942
[email protected]baf64d062014-02-16 22:10:39943 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:32944 render_surface1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39945 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32946 child_of_rs1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39947 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:32948 grand_child_of_rs1->screen_space_transform());
949
[email protected]baf64d062014-02-16 22:10:39950 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32951 render_surface2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39952 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:32953 child_of_rs2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39954 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
[email protected]fb661802013-03-25 01:59:32955 grand_child_of_rs2->screen_space_transform());
956
957 // Verify render surface transforms.
958 //
959 // Draw transform of render surface 1 is described with respect to root.
960 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39961 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32962 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39963 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:32964 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39965 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32966 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39967 A * R * S1,
[email protected]fb661802013-03-25 01:59:32968 render_surface1->render_surface()->replica_screen_space_transform());
969 // Draw transform of render surface 2 is described with respect to render
970 // surface 1.
971 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39972 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32973 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39974 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:32975 render_surface2->render_surface()->replica_draw_transform());
976 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39977 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:32978 render_surface2->render_surface()->screen_space_transform());
979 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39980 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:32981 render_surface2->render_surface()->replica_screen_space_transform());
982
983 // Sanity check. If these fail there is probably a bug in the test itself. It
984 // is expected that we correctly set up transforms so that the y-component of
985 // the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:26986 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
987 EXPECT_FLOAT_EQ(2.0,
988 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32989 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:26990 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32991
[email protected]803f6b52013-09-12 00:51:26992 EXPECT_FLOAT_EQ(2.0,
993 render_surface1->screen_space_transform().matrix().get(1, 3));
994 EXPECT_FLOAT_EQ(3.0,
995 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32996 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:26997 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32998
[email protected]803f6b52013-09-12 00:51:26999 EXPECT_FLOAT_EQ(3.0,
1000 render_surface2->screen_space_transform().matrix().get(1, 3));
1001 EXPECT_FLOAT_EQ(4.0,
1002 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321003 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:261004 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:321005}
1006
[email protected]989386c2013-07-18 21:37:231007TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321008 // For layers that flatten their subtree, there should be an orthographic
1009 // projection (for x and y values) in the middle of the transform sequence.
1010 // Note that the way the code is currently implemented, it is not expected to
1011 // use a canonical orthographic projection.
1012
loysoa6edaaff2015-05-25 03:26:441013 scoped_refptr<Layer> root = Layer::Create(layer_settings());
1014 scoped_refptr<Layer> child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:321015 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loysoa6edaaff2015-05-25 03:26:441016 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumad0d64422015-03-14 04:20:081017 scoped_refptr<LayerWithForcedDrawsContent> great_grand_child =
loysoa6edaaff2015-05-25 03:26:441018 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:321019
1020 gfx::Transform rotation_about_y_axis;
1021 rotation_about_y_axis.RotateAboutYAxis(30.0);
1022
1023 const gfx::Transform identity_matrix;
1024 SetLayerPropertiesForTesting(root.get(),
1025 identity_matrix,
[email protected]a2566412014-06-05 03:14:201026 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321027 gfx::PointF(),
1028 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571029 true,
[email protected]fb661802013-03-25 01:59:321030 false);
1031 SetLayerPropertiesForTesting(child.get(),
1032 rotation_about_y_axis,
[email protected]a2566412014-06-05 03:14:201033 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321034 gfx::PointF(),
1035 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571036 true,
[email protected]fb661802013-03-25 01:59:321037 false);
1038 SetLayerPropertiesForTesting(grand_child.get(),
1039 rotation_about_y_axis,
[email protected]a2566412014-06-05 03:14:201040 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321041 gfx::PointF(),
1042 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571043 true,
[email protected]fb661802013-03-25 01:59:321044 false);
ajumad0d64422015-03-14 04:20:081045 SetLayerPropertiesForTesting(great_grand_child.get(), identity_matrix,
1046 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1047 true, false);
[email protected]fb661802013-03-25 01:59:321048
1049 root->AddChild(child);
1050 child->AddChild(grand_child);
ajumad0d64422015-03-14 04:20:081051 grand_child->AddChild(great_grand_child);
[email protected]fb661802013-03-25 01:59:321052 child->SetForceRenderSurface(true);
1053
enne2097cab2014-09-25 20:16:311054 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281055 host->SetRootLayer(root);
1056
[email protected]fb661802013-03-25 01:59:321057 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:571058 ASSERT_TRUE(root->should_flatten_transform());
1059 ASSERT_TRUE(child->should_flatten_transform());
1060 ASSERT_TRUE(grand_child->should_flatten_transform());
ajumad0d64422015-03-14 04:20:081061 ASSERT_TRUE(great_grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:321062
1063 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1064 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1065 gfx::Transform expected_grand_child_draw_transform =
1066 rotation_about_y_axis; // draws onto child's render surface
1067 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1068 flattened_rotation_about_y.FlattenTo2d();
1069 gfx::Transform expected_grand_child_screen_space_transform =
1070 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:081071 gfx::Transform expected_great_grand_child_draw_transform =
1072 flattened_rotation_about_y;
1073 gfx::Transform expected_great_grand_child_screen_space_transform =
1074 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:321075
1076 ExecuteCalculateDrawProperties(root.get());
1077
1078 // The child's draw transform should have been taken by its surface.
1079 ASSERT_TRUE(child->render_surface());
1080 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1081 child->render_surface()->draw_transform());
1082 EXPECT_TRANSFORMATION_MATRIX_EQ(
1083 expected_child_screen_space_transform,
1084 child->render_surface()->screen_space_transform());
1085 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1086 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1087 child->screen_space_transform());
1088 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1089 grand_child->draw_transform());
1090 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1091 grand_child->screen_space_transform());
ajumad0d64422015-03-14 04:20:081092 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
1093 great_grand_child->draw_transform());
1094 EXPECT_TRANSFORMATION_MATRIX_EQ(
1095 expected_great_grand_child_screen_space_transform,
1096 great_grand_child->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321097}
1098
[email protected]989386c2013-07-18 21:37:231099TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321100 // A layer that is empty in one axis, but not the other, was accidentally
1101 // skipping a necessary translation. Without that translation, the coordinate
1102 // space of the layer's draw transform is incorrect.
1103 //
1104 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1105 // but if that layer becomes a render surface, then its draw transform is
1106 // implicitly inherited by the rest of the subtree, which then is positioned
1107 // incorrectly as a result.
1108
loysoa6edaaff2015-05-25 03:26:441109 scoped_refptr<Layer> root = Layer::Create(layer_settings());
1110 scoped_refptr<Layer> child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:321111 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loysoa6edaaff2015-05-25 03:26:441112 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:321113
1114 // The child height is zero, but has non-zero width that should be accounted
1115 // for while computing draw transforms.
1116 const gfx::Transform identity_matrix;
1117 SetLayerPropertiesForTesting(root.get(),
1118 identity_matrix,
[email protected]a2566412014-06-05 03:14:201119 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321120 gfx::PointF(),
1121 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571122 true,
[email protected]fb661802013-03-25 01:59:321123 false);
1124 SetLayerPropertiesForTesting(child.get(),
1125 identity_matrix,
[email protected]a2566412014-06-05 03:14:201126 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321127 gfx::PointF(),
1128 gfx::Size(10, 0),
[email protected]56fffdd2014-02-11 19:50:571129 true,
[email protected]fb661802013-03-25 01:59:321130 false);
1131 SetLayerPropertiesForTesting(grand_child.get(),
1132 identity_matrix,
[email protected]a2566412014-06-05 03:14:201133 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321134 gfx::PointF(),
1135 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571136 true,
[email protected]fb661802013-03-25 01:59:321137 false);
1138
1139 root->AddChild(child);
1140 child->AddChild(grand_child);
1141 child->SetForceRenderSurface(true);
1142
enne2097cab2014-09-25 20:16:311143 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281144 host->SetRootLayer(root);
1145
[email protected]fb661802013-03-25 01:59:321146 ExecuteCalculateDrawProperties(root.get());
1147
1148 ASSERT_TRUE(child->render_surface());
1149 // This is the real test, the rest are sanity checks.
1150 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1151 child->render_surface()->draw_transform());
1152 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1153 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1154 grand_child->draw_transform());
1155}
1156
[email protected]989386c2013-07-18 21:37:231157TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321158 // Transformations applied at the root of the tree should be forwarded
1159 // to child layers instead of applied to the root RenderSurface.
1160 const gfx::Transform identity_matrix;
[email protected]d5754282014-04-09 00:43:291161 scoped_refptr<LayerWithForcedDrawsContent> root =
loysoa6edaaff2015-05-25 03:26:441162 new LayerWithForcedDrawsContent(layer_settings());
[email protected]d5754282014-04-09 00:43:291163 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:441164 new LayerWithForcedDrawsContent(layer_settings());
[email protected]adeda572014-01-31 00:49:471165 child->SetScrollClipLayerId(root->id());
[email protected]f224cc92013-06-06 23:23:321166 root->AddChild(child);
1167
enne2097cab2014-09-25 20:16:311168 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281169 host->SetRootLayer(root);
1170
[email protected]f224cc92013-06-06 23:23:321171 SetLayerPropertiesForTesting(root.get(),
1172 identity_matrix,
[email protected]a2566412014-06-05 03:14:201173 gfx::Point3F(),
[email protected]f224cc92013-06-06 23:23:321174 gfx::PointF(),
1175 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571176 true,
[email protected]f224cc92013-06-06 23:23:321177 false);
1178 SetLayerPropertiesForTesting(child.get(),
1179 identity_matrix,
[email protected]a2566412014-06-05 03:14:201180 gfx::Point3F(),
[email protected]f224cc92013-06-06 23:23:321181 gfx::PointF(),
1182 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571183 true,
[email protected]f224cc92013-06-06 23:23:321184 false);
1185
[email protected]f224cc92013-06-06 23:23:321186 gfx::Transform translate;
1187 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231188 {
1189 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531190 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221191 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531192 inputs.can_adjust_raster_scales = true;
vollick5057e1e2015-04-17 19:12:321193 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531194 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231195 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1196 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1197 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201198 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1199 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231200 }
[email protected]f224cc92013-06-06 23:23:321201
1202 gfx::Transform scale;
1203 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231204 {
1205 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531206 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221207 root.get(), root->bounds(), scale, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531208 inputs.can_adjust_raster_scales = true;
vollick5057e1e2015-04-17 19:12:321209 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531210 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231211 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1212 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1213 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201214 EXPECT_EQ(2.f, root->draw_properties().device_scale_factor);
1215 EXPECT_EQ(2.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231216 }
[email protected]f224cc92013-06-06 23:23:321217
1218 gfx::Transform rotate;
1219 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231220 {
1221 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531222 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221223 root.get(), root->bounds(), rotate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531224 inputs.can_adjust_raster_scales = true;
vollick5057e1e2015-04-17 19:12:321225 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531226 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231227 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1228 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1229 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201230 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1231 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231232 }
[email protected]f224cc92013-06-06 23:23:321233
1234 gfx::Transform composite;
1235 composite.ConcatTransform(translate);
1236 composite.ConcatTransform(scale);
1237 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231238 {
1239 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531240 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221241 root.get(), root->bounds(), composite, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531242 inputs.can_adjust_raster_scales = true;
vollick5057e1e2015-04-17 19:12:321243 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531244 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231245 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1246 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1247 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1248 }
[email protected]f224cc92013-06-06 23:23:321249
[email protected]9781afa2013-07-17 23:15:321250 // Verify it composes correctly with device scale.
1251 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231252
1253 {
1254 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531255 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221256 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531257 inputs.device_scale_factor = device_scale_factor;
1258 inputs.can_adjust_raster_scales = true;
vollick5057e1e2015-04-17 19:12:321259 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531260 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231261 gfx::Transform device_scaled_translate = translate;
1262 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1263 EXPECT_EQ(device_scaled_translate,
1264 root->draw_properties().target_space_transform);
1265 EXPECT_EQ(device_scaled_translate,
1266 child->draw_properties().target_space_transform);
1267 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201268 EXPECT_EQ(device_scale_factor, root->draw_properties().device_scale_factor);
1269 EXPECT_EQ(device_scale_factor,
1270 child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231271 }
[email protected]9781afa2013-07-17 23:15:321272
1273 // Verify it composes correctly with page scale.
1274 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231275
1276 {
1277 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531278 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221279 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531280 inputs.page_scale_factor = page_scale_factor;
enne6394d5b42015-05-26 22:23:111281 inputs.page_scale_layer = root.get();
[email protected]7aad55f2013-07-26 11:25:531282 inputs.can_adjust_raster_scales = true;
vollick5057e1e2015-04-17 19:12:321283 inputs.property_trees->needs_rebuild = true;
[email protected]7aad55f2013-07-26 11:25:531284 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231285 gfx::Transform page_scaled_translate = translate;
1286 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
enne6394d5b42015-05-26 22:23:111287 EXPECT_EQ(page_scaled_translate,
1288 root->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231289 EXPECT_EQ(page_scaled_translate,
1290 child->draw_properties().target_space_transform);
1291 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201292 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1293 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231294 }
[email protected]9781afa2013-07-17 23:15:321295
[email protected]f224cc92013-06-06 23:23:321296 // Verify that it composes correctly with transforms directly on root layer.
1297 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231298
1299 {
1300 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531301 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221302 root.get(), root->bounds(), composite, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531303 inputs.can_adjust_raster_scales = true;
1304 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231305 gfx::Transform compositeSquared = composite;
1306 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261307 EXPECT_TRANSFORMATION_MATRIX_EQ(
1308 compositeSquared, root->draw_properties().target_space_transform);
1309 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391310 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231311 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1312 }
[email protected]f224cc92013-06-06 23:23:321313}
1314
[email protected]989386c2013-07-18 21:37:231315TEST_F(LayerTreeHostCommonTest,
1316 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
loysoa6edaaff2015-05-25 03:26:441317 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1318 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:321319 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:441320 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:321321
enne2097cab2014-09-25 20:16:311322 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281323 host->SetRootLayer(parent);
1324
[email protected]fb661802013-03-25 01:59:321325 const gfx::Transform identity_matrix;
1326 SetLayerPropertiesForTesting(parent.get(),
1327 identity_matrix,
[email protected]a2566412014-06-05 03:14:201328 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321329 gfx::PointF(),
1330 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571331 true,
[email protected]fb661802013-03-25 01:59:321332 false);
1333 SetLayerPropertiesForTesting(render_surface1.get(),
1334 identity_matrix,
[email protected]a2566412014-06-05 03:14:201335 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321336 gfx::PointF(),
1337 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571338 true,
[email protected]fb661802013-03-25 01:59:321339 false);
1340 SetLayerPropertiesForTesting(child.get(),
1341 identity_matrix,
[email protected]a2566412014-06-05 03:14:201342 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321343 gfx::PointF(30.f, 30.f),
1344 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571345 true,
[email protected]fb661802013-03-25 01:59:321346 false);
1347
1348 parent->AddChild(render_surface1);
1349 parent->SetMasksToBounds(true);
1350 render_surface1->AddChild(child);
1351 render_surface1->SetForceRenderSurface(true);
1352
[email protected]989386c2013-07-18 21:37:231353 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531354 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1355 parent.get(),
1356 parent->bounds(),
1357 gfx::Transform(),
1358 &render_surface_layer_list);
1359 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321360
1361 // The child layer's content is entirely outside the parent's clip rect, so
1362 // the intermediate render surface should not be listed here, even if it was
1363 // forced to be created. Render surfaces without children or visible content
1364 // are unexpected at draw time (e.g. we might try to create a content texture
1365 // of size 0).
1366 ASSERT_TRUE(parent->render_surface());
[email protected]fb661802013-03-25 01:59:321367 EXPECT_EQ(1U, render_surface_layer_list.size());
1368}
1369
[email protected]989386c2013-07-18 21:37:231370TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
loysoa6edaaff2015-05-25 03:26:441371 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1372 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:321373 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:441374 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:321375
enne2097cab2014-09-25 20:16:311376 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281377 host->SetRootLayer(parent);
1378
[email protected]fb661802013-03-25 01:59:321379 const gfx::Transform identity_matrix;
1380 SetLayerPropertiesForTesting(render_surface1.get(),
1381 identity_matrix,
[email protected]a2566412014-06-05 03:14:201382 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321383 gfx::PointF(),
1384 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571385 true,
[email protected]fb661802013-03-25 01:59:321386 false);
1387 SetLayerPropertiesForTesting(child.get(),
1388 identity_matrix,
[email protected]a2566412014-06-05 03:14:201389 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321390 gfx::PointF(),
1391 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571392 true,
[email protected]fb661802013-03-25 01:59:321393 false);
1394
1395 parent->AddChild(render_surface1);
1396 render_surface1->AddChild(child);
1397 render_surface1->SetForceRenderSurface(true);
1398 render_surface1->SetOpacity(0.f);
1399
[email protected]989386c2013-07-18 21:37:231400 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531401 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1402 parent.get(), parent->bounds(), &render_surface_layer_list);
1403 inputs.can_adjust_raster_scales = true;
1404 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321405
1406 // Since the layer is transparent, render_surface1->render_surface() should
1407 // not have gotten added anywhere. Also, the drawable content rect should not
1408 // have been extended by the children.
1409 ASSERT_TRUE(parent->render_surface());
1410 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1411 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231412 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321413 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1414}
1415
rosca948d29d2014-11-09 10:25:131416TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
loysoa6edaaff2015-05-25 03:26:441417 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
rosca948d29d2014-11-09 10:25:131418 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:441419 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
rosca948d29d2014-11-09 10:25:131420
1421 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
1422 host->SetRootLayer(parent);
1423
1424 const gfx::Transform identity_matrix;
1425 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
1426 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
1427 gfx::PointF(), gfx::Size(10, 10), true, false);
1428
1429 parent->AddChild(child);
1430 child->SetBlendMode(blend_mode);
1431
1432 RenderSurfaceLayerList render_surface_layer_list;
1433 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1434 parent.get(), parent->bounds(), &render_surface_layer_list);
1435 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1436
1437 // Since the child layer has a blend mode other than normal, it should get
1438 // its own render surface. Also, layer's draw_properties should contain the
1439 // default blend mode, since the render surface becomes responsible for
1440 // applying the blend mode.
1441 ASSERT_TRUE(child->render_surface());
1442 EXPECT_EQ(1U, child->render_surface()->layer_list().size());
1443 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_properties().blend_mode);
1444}
1445
[email protected]989386c2013-07-18 21:37:231446TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
loysoa6edaaff2015-05-25 03:26:441447 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1448 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:321449 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:441450 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:321451 render_surface1->SetForceRenderSurface(true);
1452
enne2097cab2014-09-25 20:16:311453 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281454 host->SetRootLayer(parent);
1455
[email protected]fb661802013-03-25 01:59:321456 const gfx::Transform identity_matrix;
1457 SetLayerPropertiesForTesting(parent.get(),
1458 identity_matrix,
[email protected]a2566412014-06-05 03:14:201459 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321460 gfx::PointF(),
1461 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571462 true,
[email protected]fb661802013-03-25 01:59:321463 false);
1464 SetLayerPropertiesForTesting(render_surface1.get(),
1465 identity_matrix,
[email protected]a2566412014-06-05 03:14:201466 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321467 gfx::PointF(),
1468 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571469 true,
[email protected]fb661802013-03-25 01:59:321470 false);
1471 SetLayerPropertiesForTesting(child.get(),
1472 identity_matrix,
[email protected]a2566412014-06-05 03:14:201473 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321474 gfx::PointF(),
1475 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571476 true,
[email protected]fb661802013-03-25 01:59:321477 false);
1478
1479 parent->AddChild(render_surface1);
1480 render_surface1->AddChild(child);
1481
1482 // Sanity check before the actual test
1483 EXPECT_FALSE(parent->render_surface());
1484 EXPECT_FALSE(render_surface1->render_surface());
1485
[email protected]989386c2013-07-18 21:37:231486 {
1487 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531488 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1489 parent.get(), parent->bounds(), &render_surface_layer_list);
1490 inputs.can_adjust_raster_scales = true;
1491 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321492
[email protected]989386c2013-07-18 21:37:231493 // The root layer always creates a render surface
1494 EXPECT_TRUE(parent->render_surface());
1495 EXPECT_TRUE(render_surface1->render_surface());
1496 EXPECT_EQ(2U, render_surface_layer_list.size());
1497 }
[email protected]fb661802013-03-25 01:59:321498
[email protected]989386c2013-07-18 21:37:231499 {
1500 RenderSurfaceLayerList render_surface_layer_list;
1501 render_surface1->SetForceRenderSurface(false);
[email protected]7aad55f2013-07-26 11:25:531502 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1503 parent.get(), parent->bounds(), &render_surface_layer_list);
1504 inputs.can_adjust_raster_scales = true;
1505 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231506 EXPECT_TRUE(parent->render_surface());
1507 EXPECT_FALSE(render_surface1->render_surface());
1508 EXPECT_EQ(1U, render_surface_layer_list.size());
1509 }
[email protected]fb661802013-03-25 01:59:321510}
1511
ajuma246190a2015-03-11 20:56:031512TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1513 // Render surfaces act as a flattening point for their subtree, so should
1514 // always flatten the target-to-screen space transform seen by descendants.
1515
loysoa6edaaff2015-05-25 03:26:441516 scoped_refptr<Layer> root = Layer::Create(layer_settings());
1517 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
ajuma246190a2015-03-11 20:56:031518 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:441519 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma246190a2015-03-11 20:56:031520 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loysoa6edaaff2015-05-25 03:26:441521 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma246190a2015-03-11 20:56:031522
1523 gfx::Transform rotation_about_y_axis;
1524 rotation_about_y_axis.RotateAboutYAxis(30.0);
1525 // Make |parent| have a render surface.
1526 parent->SetOpacity(0.9f);
1527
1528 const gfx::Transform identity_matrix;
1529 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
1530 gfx::PointF(), gfx::Size(100, 100), true, false);
1531 SetLayerPropertiesForTesting(parent.get(), rotation_about_y_axis,
1532 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1533 true, false);
1534 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
1535 gfx::PointF(), gfx::Size(10, 10), true, false);
1536 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
1537 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1538 true, false);
1539
1540 root->AddChild(parent);
1541 parent->AddChild(child);
1542 child->AddChild(grand_child);
1543
1544 grand_child->SetShouldFlattenTransform(false);
1545
1546 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
1547 host->SetRootLayer(root);
1548
1549 // Only grand_child should preserve 3d.
1550 EXPECT_TRUE(root->should_flatten_transform());
1551 EXPECT_TRUE(parent->should_flatten_transform());
1552 EXPECT_TRUE(child->should_flatten_transform());
1553 EXPECT_FALSE(grand_child->should_flatten_transform());
1554
1555 gfx::Transform expected_child_draw_transform = identity_matrix;
1556 gfx::Transform expected_grand_child_draw_transform = identity_matrix;
1557
1558 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1559 flattened_rotation_about_y.FlattenTo2d();
1560
1561 ExecuteCalculateDrawProperties(root.get());
1562
1563 EXPECT_TRUE(parent->render_surface());
1564 EXPECT_FALSE(child->render_surface());
1565 EXPECT_FALSE(grand_child->render_surface());
1566
1567 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1568 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1569 grand_child->draw_transform());
1570
1571 // The screen-space transform inherited by |child| and |grand_child| should
1572 // have been flattened at their render target. In particular, the fact that
1573 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1574 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1575 child->screen_space_transform());
1576 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1577 grand_child->screen_space_transform());
1578}
1579
[email protected]989386c2013-07-18 21:37:231580TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321581 // The entire subtree of layers that are outside the clip rect should be
1582 // culled away, and should not affect the render_surface_layer_list.
1583 //
1584 // The test tree is set up as follows:
1585 // - all layers except the leaf_nodes are forced to be a new render surface
1586 // that have something to draw.
1587 // - parent is a large container layer.
1588 // - child has masksToBounds=true to cause clipping.
1589 // - grand_child is positioned outside of the child's bounds
1590 // - great_grand_child is also kept outside child's bounds.
1591 //
1592 // In this configuration, grand_child and great_grand_child are completely
1593 // outside the clip rect, and they should never get scheduled on the list of
1594 // render surfaces.
1595 //
1596
1597 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:441598 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1599 scoped_refptr<Layer> child = Layer::Create(layer_settings());
1600 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
1601 scoped_refptr<Layer> great_grand_child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:321602 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
loysoa6edaaff2015-05-25 03:26:441603 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:321604 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
loysoa6edaaff2015-05-25 03:26:441605 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:321606 parent->AddChild(child);
1607 child->AddChild(grand_child);
1608 grand_child->AddChild(great_grand_child);
1609
enne2097cab2014-09-25 20:16:311610 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281611 host->SetRootLayer(parent);
1612
[email protected]fb661802013-03-25 01:59:321613 // leaf_node1 ensures that parent and child are kept on the
1614 // render_surface_layer_list, even though grand_child and great_grand_child
1615 // should be clipped.
1616 child->AddChild(leaf_node1);
1617 great_grand_child->AddChild(leaf_node2);
1618
1619 SetLayerPropertiesForTesting(parent.get(),
1620 identity_matrix,
[email protected]a2566412014-06-05 03:14:201621 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321622 gfx::PointF(),
1623 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571624 true,
[email protected]fb661802013-03-25 01:59:321625 false);
1626 SetLayerPropertiesForTesting(child.get(),
1627 identity_matrix,
[email protected]a2566412014-06-05 03:14:201628 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321629 gfx::PointF(),
1630 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571631 true,
[email protected]fb661802013-03-25 01:59:321632 false);
1633 SetLayerPropertiesForTesting(grand_child.get(),
1634 identity_matrix,
[email protected]a2566412014-06-05 03:14:201635 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321636 gfx::PointF(45.f, 45.f),
1637 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571638 true,
[email protected]fb661802013-03-25 01:59:321639 false);
1640 SetLayerPropertiesForTesting(great_grand_child.get(),
1641 identity_matrix,
[email protected]a2566412014-06-05 03:14:201642 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321643 gfx::PointF(),
1644 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571645 true,
[email protected]fb661802013-03-25 01:59:321646 false);
1647 SetLayerPropertiesForTesting(leaf_node1.get(),
1648 identity_matrix,
[email protected]a2566412014-06-05 03:14:201649 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321650 gfx::PointF(),
1651 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571652 true,
[email protected]fb661802013-03-25 01:59:321653 false);
1654 SetLayerPropertiesForTesting(leaf_node2.get(),
1655 identity_matrix,
[email protected]a2566412014-06-05 03:14:201656 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321657 gfx::PointF(),
1658 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571659 true,
[email protected]fb661802013-03-25 01:59:321660 false);
1661
1662 child->SetMasksToBounds(true);
1663 child->SetOpacity(0.4f);
1664 child->SetForceRenderSurface(true);
1665 grand_child->SetOpacity(0.5f);
1666 great_grand_child->SetOpacity(0.4f);
1667
[email protected]989386c2013-07-18 21:37:231668 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531669 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1670 parent.get(), parent->bounds(), &render_surface_layer_list);
1671 inputs.can_adjust_raster_scales = true;
1672 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321673
1674 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231675 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1676 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321677}
1678
[email protected]989386c2013-07-18 21:37:231679TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321680 // When a render surface has a clip rect, it is used to clip the content rect
1681 // of the surface. When the render surface is animating its transforms, then
1682 // the content rect's position in the clip rect is not defined on the main
1683 // thread, and its content rect should not be clipped.
1684
1685 // The test tree is set up as follows:
1686 // - parent is a container layer that masksToBounds=true to cause clipping.
1687 // - child is a render surface, which has a clip rect set to the bounds of
1688 // the parent.
1689 // - grand_child is a render surface, and the only visible content in child.
1690 // It is positioned outside of the clip rect from parent.
1691
1692 // In this configuration, grand_child should be outside the clipped
1693 // content rect of the child, making grand_child not appear in the
1694 // render_surface_layer_list. However, when we place an animation on the
1695 // child, this clipping should be avoided and we should keep the grand_child
1696 // in the render_surface_layer_list.
1697
1698 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:441699 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1700 scoped_refptr<Layer> child = Layer::Create(layer_settings());
1701 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:321702 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
loysoa6edaaff2015-05-25 03:26:441703 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:321704 parent->AddChild(child);
1705 child->AddChild(grand_child);
1706 grand_child->AddChild(leaf_node);
1707
enne2097cab2014-09-25 20:16:311708 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281709 host->SetRootLayer(parent);
1710
[email protected]fb661802013-03-25 01:59:321711 SetLayerPropertiesForTesting(parent.get(),
1712 identity_matrix,
[email protected]a2566412014-06-05 03:14:201713 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321714 gfx::PointF(),
1715 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571716 true,
[email protected]fb661802013-03-25 01:59:321717 false);
1718 SetLayerPropertiesForTesting(child.get(),
1719 identity_matrix,
[email protected]a2566412014-06-05 03:14:201720 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321721 gfx::PointF(),
1722 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571723 true,
[email protected]fb661802013-03-25 01:59:321724 false);
1725 SetLayerPropertiesForTesting(grand_child.get(),
1726 identity_matrix,
[email protected]a2566412014-06-05 03:14:201727 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321728 gfx::PointF(200.f, 200.f),
1729 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571730 true,
[email protected]fb661802013-03-25 01:59:321731 false);
1732 SetLayerPropertiesForTesting(leaf_node.get(),
1733 identity_matrix,
[email protected]a2566412014-06-05 03:14:201734 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321735 gfx::PointF(),
1736 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571737 true,
[email protected]fb661802013-03-25 01:59:321738 false);
1739
1740 parent->SetMasksToBounds(true);
1741 child->SetOpacity(0.4f);
1742 child->SetForceRenderSurface(true);
1743 grand_child->SetOpacity(0.4f);
1744 grand_child->SetForceRenderSurface(true);
1745
[email protected]989386c2013-07-18 21:37:231746 {
1747 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531748 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1749 parent.get(), parent->bounds(), &render_surface_layer_list);
1750 inputs.can_adjust_raster_scales = true;
1751 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321752
[email protected]989386c2013-07-18 21:37:231753 // Without an animation, we should cull child and grand_child from the
1754 // render_surface_layer_list.
1755 ASSERT_EQ(1U, render_surface_layer_list.size());
1756 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1757 }
[email protected]fb661802013-03-25 01:59:321758
1759 // Now put an animating transform on child.
1760 AddAnimatedTransformToController(
1761 child->layer_animation_controller(), 10.0, 30, 0);
1762
[email protected]989386c2013-07-18 21:37:231763 {
1764 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531765 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1766 parent.get(), parent->bounds(), &render_surface_layer_list);
1767 inputs.can_adjust_raster_scales = true;
1768 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321769
[email protected]989386c2013-07-18 21:37:231770 // With an animating transform, we should keep child and grand_child in the
1771 // render_surface_layer_list.
1772 ASSERT_EQ(3U, render_surface_layer_list.size());
1773 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1774 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1775 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
1776 }
[email protected]fb661802013-03-25 01:59:321777}
1778
[email protected]989386c2013-07-18 21:37:231779TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:321780 // Layer's IsClipped() property is set to true when:
1781 // - the layer clips its subtree, e.g. masks to bounds,
1782 // - the layer is clipped by an ancestor that contributes to the same
1783 // render target,
1784 // - a surface is clipped by an ancestor that contributes to the same
1785 // render target.
1786 //
1787 // In particular, for a layer that owns a render surface:
1788 // - the render surface inherits any clip from ancestors, and does NOT
1789 // pass that clipped status to the layer itself.
1790 // - but if the layer itself masks to bounds, it is considered clipped
1791 // and propagates the clip to the subtree.
1792
1793 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:441794 scoped_refptr<Layer> root = Layer::Create(layer_settings());
1795 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1796 scoped_refptr<Layer> child1 = Layer::Create(layer_settings());
1797 scoped_refptr<Layer> child2 = Layer::Create(layer_settings());
1798 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:321799 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
loysoa6edaaff2015-05-25 03:26:441800 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:321801 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
loysoa6edaaff2015-05-25 03:26:441802 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:321803 root->AddChild(parent);
1804 parent->AddChild(child1);
1805 parent->AddChild(child2);
1806 child1->AddChild(grand_child);
1807 child2->AddChild(leaf_node2);
1808 grand_child->AddChild(leaf_node1);
1809
enne2097cab2014-09-25 20:16:311810 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281811 host->SetRootLayer(root);
1812
[email protected]fb661802013-03-25 01:59:321813 child2->SetForceRenderSurface(true);
1814
1815 SetLayerPropertiesForTesting(root.get(),
1816 identity_matrix,
[email protected]a2566412014-06-05 03:14:201817 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321818 gfx::PointF(),
1819 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571820 true,
[email protected]fb661802013-03-25 01:59:321821 false);
1822 SetLayerPropertiesForTesting(parent.get(),
1823 identity_matrix,
[email protected]a2566412014-06-05 03:14:201824 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321825 gfx::PointF(),
1826 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571827 true,
[email protected]fb661802013-03-25 01:59:321828 false);
1829 SetLayerPropertiesForTesting(child1.get(),
1830 identity_matrix,
[email protected]a2566412014-06-05 03:14:201831 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321832 gfx::PointF(),
1833 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571834 true,
[email protected]fb661802013-03-25 01:59:321835 false);
1836 SetLayerPropertiesForTesting(child2.get(),
1837 identity_matrix,
[email protected]a2566412014-06-05 03:14:201838 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321839 gfx::PointF(),
1840 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571841 true,
[email protected]fb661802013-03-25 01:59:321842 false);
1843 SetLayerPropertiesForTesting(grand_child.get(),
1844 identity_matrix,
[email protected]a2566412014-06-05 03:14:201845 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321846 gfx::PointF(),
1847 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571848 true,
[email protected]fb661802013-03-25 01:59:321849 false);
1850 SetLayerPropertiesForTesting(leaf_node1.get(),
1851 identity_matrix,
[email protected]a2566412014-06-05 03:14:201852 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321853 gfx::PointF(),
1854 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571855 true,
[email protected]fb661802013-03-25 01:59:321856 false);
1857 SetLayerPropertiesForTesting(leaf_node2.get(),
1858 identity_matrix,
[email protected]a2566412014-06-05 03:14:201859 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321860 gfx::PointF(),
1861 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571862 true,
[email protected]fb661802013-03-25 01:59:321863 false);
1864
[email protected]989386c2013-07-18 21:37:231865 // Case 1: nothing is clipped except the root render surface.
1866 {
1867 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531868 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1869 root.get(), parent->bounds(), &render_surface_layer_list);
1870 inputs.can_adjust_raster_scales = true;
1871 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321872
[email protected]989386c2013-07-18 21:37:231873 ASSERT_TRUE(root->render_surface());
1874 ASSERT_TRUE(child2->render_surface());
1875
1876 EXPECT_FALSE(root->is_clipped());
1877 EXPECT_TRUE(root->render_surface()->is_clipped());
1878 EXPECT_FALSE(parent->is_clipped());
1879 EXPECT_FALSE(child1->is_clipped());
1880 EXPECT_FALSE(child2->is_clipped());
1881 EXPECT_FALSE(child2->render_surface()->is_clipped());
1882 EXPECT_FALSE(grand_child->is_clipped());
1883 EXPECT_FALSE(leaf_node1->is_clipped());
1884 EXPECT_FALSE(leaf_node2->is_clipped());
1885 }
[email protected]fb661802013-03-25 01:59:321886
1887 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1888 // surface are clipped. But layers that contribute to child2's surface are
1889 // not clipped explicitly because child2's surface already accounts for
1890 // that clip.
[email protected]989386c2013-07-18 21:37:231891 {
1892 RenderSurfaceLayerList render_surface_layer_list;
1893 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531894 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1895 root.get(), parent->bounds(), &render_surface_layer_list);
1896 inputs.can_adjust_raster_scales = true;
1897 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321898
[email protected]989386c2013-07-18 21:37:231899 ASSERT_TRUE(root->render_surface());
1900 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321901
[email protected]989386c2013-07-18 21:37:231902 EXPECT_FALSE(root->is_clipped());
1903 EXPECT_TRUE(root->render_surface()->is_clipped());
1904 EXPECT_TRUE(parent->is_clipped());
1905 EXPECT_TRUE(child1->is_clipped());
1906 EXPECT_FALSE(child2->is_clipped());
1907 EXPECT_TRUE(child2->render_surface()->is_clipped());
1908 EXPECT_TRUE(grand_child->is_clipped());
1909 EXPECT_TRUE(leaf_node1->is_clipped());
1910 EXPECT_FALSE(leaf_node2->is_clipped());
1911 }
[email protected]fb661802013-03-25 01:59:321912
1913 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1914 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:231915 {
1916 RenderSurfaceLayerList render_surface_layer_list;
1917 parent->SetMasksToBounds(false);
1918 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531919 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1920 root.get(), parent->bounds(), &render_surface_layer_list);
1921 inputs.can_adjust_raster_scales = true;
1922 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321923
[email protected]989386c2013-07-18 21:37:231924 ASSERT_TRUE(root->render_surface());
1925 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321926
[email protected]989386c2013-07-18 21:37:231927 EXPECT_FALSE(root->is_clipped());
1928 EXPECT_TRUE(root->render_surface()->is_clipped());
1929 EXPECT_FALSE(parent->is_clipped());
1930 EXPECT_FALSE(child1->is_clipped());
1931 EXPECT_TRUE(child2->is_clipped());
1932 EXPECT_FALSE(child2->render_surface()->is_clipped());
1933 EXPECT_FALSE(grand_child->is_clipped());
1934 EXPECT_FALSE(leaf_node1->is_clipped());
1935 EXPECT_TRUE(leaf_node2->is_clipped());
1936 }
[email protected]fb661802013-03-25 01:59:321937}
1938
[email protected]fd9a3b6d2013-08-03 00:46:171939TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:321940 // Verify that layers get the appropriate DrawableContentRect when their
1941 // parent masksToBounds is true.
1942 //
1943 // grand_child1 - completely inside the region; DrawableContentRect should
1944 // be the layer rect expressed in target space.
1945 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1946 // will be the intersection of layer bounds and the mask region.
1947 // grand_child3 - partially clipped and masksToBounds; the
1948 // DrawableContentRect will still be the intersection of layer bounds and
1949 // the mask region.
1950 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1951 // be empty.
1952 //
1953
1954 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:441955 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
1956 scoped_refptr<Layer> child = Layer::Create(layer_settings());
1957 scoped_refptr<Layer> grand_child1 = Layer::Create(layer_settings());
1958 scoped_refptr<Layer> grand_child2 = Layer::Create(layer_settings());
1959 scoped_refptr<Layer> grand_child3 = Layer::Create(layer_settings());
1960 scoped_refptr<Layer> grand_child4 = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:321961
1962 parent->AddChild(child);
1963 child->AddChild(grand_child1);
1964 child->AddChild(grand_child2);
1965 child->AddChild(grand_child3);
1966 child->AddChild(grand_child4);
1967
enne2097cab2014-09-25 20:16:311968 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281969 host->SetRootLayer(parent);
1970
[email protected]fb661802013-03-25 01:59:321971 SetLayerPropertiesForTesting(parent.get(),
1972 identity_matrix,
[email protected]a2566412014-06-05 03:14:201973 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321974 gfx::PointF(),
1975 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571976 true,
[email protected]fb661802013-03-25 01:59:321977 false);
1978 SetLayerPropertiesForTesting(child.get(),
1979 identity_matrix,
[email protected]a2566412014-06-05 03:14:201980 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321981 gfx::PointF(),
1982 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571983 true,
[email protected]fb661802013-03-25 01:59:321984 false);
1985 SetLayerPropertiesForTesting(grand_child1.get(),
1986 identity_matrix,
[email protected]a2566412014-06-05 03:14:201987 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321988 gfx::PointF(5.f, 5.f),
1989 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571990 true,
[email protected]fb661802013-03-25 01:59:321991 false);
1992 SetLayerPropertiesForTesting(grand_child2.get(),
1993 identity_matrix,
[email protected]a2566412014-06-05 03:14:201994 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321995 gfx::PointF(15.f, 15.f),
1996 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571997 true,
[email protected]fb661802013-03-25 01:59:321998 false);
1999 SetLayerPropertiesForTesting(grand_child3.get(),
2000 identity_matrix,
[email protected]a2566412014-06-05 03:14:202001 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322002 gfx::PointF(15.f, 15.f),
2003 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572004 true,
[email protected]fb661802013-03-25 01:59:322005 false);
2006 SetLayerPropertiesForTesting(grand_child4.get(),
2007 identity_matrix,
[email protected]a2566412014-06-05 03:14:202008 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322009 gfx::PointF(45.f, 45.f),
2010 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572011 true,
[email protected]fb661802013-03-25 01:59:322012 false);
2013
2014 child->SetMasksToBounds(true);
2015 grand_child3->SetMasksToBounds(true);
2016
2017 // Force everyone to be a render surface.
2018 child->SetOpacity(0.4f);
2019 grand_child1->SetOpacity(0.5f);
2020 grand_child2->SetOpacity(0.5f);
2021 grand_child3->SetOpacity(0.5f);
2022 grand_child4->SetOpacity(0.5f);
2023
[email protected]989386c2013-07-18 21:37:232024 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532025 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2026 parent.get(), parent->bounds(), &render_surface_layer_list);
2027 inputs.can_adjust_raster_scales = true;
2028 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322029
hush6b614212014-12-04 22:37:322030 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2031 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2032 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322033 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2034}
2035
[email protected]989386c2013-07-18 21:37:232036TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322037 // Verify that render surfaces (and their layers) get the appropriate
2038 // clip rects when their parent masksToBounds is true.
2039 //
2040 // Layers that own render surfaces (at least for now) do not inherit any
2041 // clipping; instead the surface will enforce the clip for the entire subtree.
2042 // They may still have a clip rect of their own layer bounds, however, if
2043 // masksToBounds was true.
2044 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:442045 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
2046 scoped_refptr<Layer> child = Layer::Create(layer_settings());
2047 scoped_refptr<Layer> grand_child1 = Layer::Create(layer_settings());
2048 scoped_refptr<Layer> grand_child2 = Layer::Create(layer_settings());
2049 scoped_refptr<Layer> grand_child3 = Layer::Create(layer_settings());
2050 scoped_refptr<Layer> grand_child4 = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:322051 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
loysoa6edaaff2015-05-25 03:26:442052 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322053 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
loysoa6edaaff2015-05-25 03:26:442054 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322055 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
loysoa6edaaff2015-05-25 03:26:442056 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322057 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
loysoa6edaaff2015-05-25 03:26:442058 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322059
2060 parent->AddChild(child);
2061 child->AddChild(grand_child1);
2062 child->AddChild(grand_child2);
2063 child->AddChild(grand_child3);
2064 child->AddChild(grand_child4);
2065
enne2097cab2014-09-25 20:16:312066 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282067 host->SetRootLayer(parent);
2068
[email protected]fb661802013-03-25 01:59:322069 // the leaf nodes ensure that these grand_children become render surfaces for
2070 // this test.
2071 grand_child1->AddChild(leaf_node1);
2072 grand_child2->AddChild(leaf_node2);
2073 grand_child3->AddChild(leaf_node3);
2074 grand_child4->AddChild(leaf_node4);
2075
2076 SetLayerPropertiesForTesting(parent.get(),
2077 identity_matrix,
[email protected]a2566412014-06-05 03:14:202078 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322079 gfx::PointF(),
2080 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:572081 true,
[email protected]fb661802013-03-25 01:59:322082 false);
2083 SetLayerPropertiesForTesting(child.get(),
2084 identity_matrix,
[email protected]a2566412014-06-05 03:14:202085 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322086 gfx::PointF(),
2087 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:572088 true,
[email protected]fb661802013-03-25 01:59:322089 false);
2090 SetLayerPropertiesForTesting(grand_child1.get(),
2091 identity_matrix,
[email protected]a2566412014-06-05 03:14:202092 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322093 gfx::PointF(5.f, 5.f),
2094 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572095 true,
[email protected]fb661802013-03-25 01:59:322096 false);
2097 SetLayerPropertiesForTesting(grand_child2.get(),
2098 identity_matrix,
[email protected]a2566412014-06-05 03:14:202099 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322100 gfx::PointF(15.f, 15.f),
2101 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572102 true,
[email protected]fb661802013-03-25 01:59:322103 false);
2104 SetLayerPropertiesForTesting(grand_child3.get(),
2105 identity_matrix,
[email protected]a2566412014-06-05 03:14:202106 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322107 gfx::PointF(15.f, 15.f),
2108 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572109 true,
[email protected]fb661802013-03-25 01:59:322110 false);
2111 SetLayerPropertiesForTesting(grand_child4.get(),
2112 identity_matrix,
[email protected]a2566412014-06-05 03:14:202113 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322114 gfx::PointF(45.f, 45.f),
2115 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572116 true,
[email protected]fb661802013-03-25 01:59:322117 false);
2118 SetLayerPropertiesForTesting(leaf_node1.get(),
2119 identity_matrix,
[email protected]a2566412014-06-05 03:14:202120 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322121 gfx::PointF(),
2122 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572123 true,
[email protected]fb661802013-03-25 01:59:322124 false);
2125 SetLayerPropertiesForTesting(leaf_node2.get(),
2126 identity_matrix,
[email protected]a2566412014-06-05 03:14:202127 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322128 gfx::PointF(),
2129 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572130 true,
[email protected]fb661802013-03-25 01:59:322131 false);
2132 SetLayerPropertiesForTesting(leaf_node3.get(),
2133 identity_matrix,
[email protected]a2566412014-06-05 03:14:202134 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322135 gfx::PointF(),
2136 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572137 true,
[email protected]fb661802013-03-25 01:59:322138 false);
2139 SetLayerPropertiesForTesting(leaf_node4.get(),
2140 identity_matrix,
[email protected]a2566412014-06-05 03:14:202141 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322142 gfx::PointF(),
2143 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572144 true,
[email protected]fb661802013-03-25 01:59:322145 false);
2146
2147 child->SetMasksToBounds(true);
2148 grand_child3->SetMasksToBounds(true);
2149 grand_child4->SetMasksToBounds(true);
2150
2151 // Force everyone to be a render surface.
2152 child->SetOpacity(0.4f);
2153 child->SetForceRenderSurface(true);
2154 grand_child1->SetOpacity(0.5f);
2155 grand_child1->SetForceRenderSurface(true);
2156 grand_child2->SetOpacity(0.5f);
2157 grand_child2->SetForceRenderSurface(true);
2158 grand_child3->SetOpacity(0.5f);
2159 grand_child3->SetForceRenderSurface(true);
2160 grand_child4->SetOpacity(0.5f);
2161 grand_child4->SetForceRenderSurface(true);
2162
[email protected]989386c2013-07-18 21:37:232163 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532164 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2165 parent.get(), parent->bounds(), &render_surface_layer_list);
2166 inputs.can_adjust_raster_scales = true;
2167 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322168 ASSERT_TRUE(grand_child1->render_surface());
2169 ASSERT_TRUE(grand_child2->render_surface());
2170 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322171
2172 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2173 // masksToBounds.
hush6b614212014-12-04 22:37:322174 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2175 grand_child1->render_surface()->clip_rect());
2176 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2177 grand_child2->render_surface()->clip_rect());
2178 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2179 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322180}
2181
[email protected]989386c2013-07-18 21:37:232182TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
loysoa6edaaff2015-05-25 03:26:442183 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
2184 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
2185 scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings());
2186 scoped_refptr<Layer> child_of_root = Layer::Create(layer_settings());
2187 scoped_refptr<Layer> child_of_rs1 = Layer::Create(layer_settings());
2188 scoped_refptr<Layer> child_of_rs2 = Layer::Create(layer_settings());
2189 scoped_refptr<Layer> grand_child_of_root = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:322190 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
loysoa6edaaff2015-05-25 03:26:442191 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322192 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
loysoa6edaaff2015-05-25 03:26:442193 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322194 parent->AddChild(render_surface1);
2195 parent->AddChild(child_of_root);
2196 render_surface1->AddChild(child_of_rs1);
2197 render_surface1->AddChild(render_surface2);
2198 render_surface2->AddChild(child_of_rs2);
2199 child_of_root->AddChild(grand_child_of_root);
2200 child_of_rs1->AddChild(grand_child_of_rs1);
2201 child_of_rs2->AddChild(grand_child_of_rs2);
2202
enne2097cab2014-09-25 20:16:312203 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282204 host->SetRootLayer(parent);
2205
[email protected]fb661802013-03-25 01:59:322206 // Make our render surfaces.
2207 render_surface1->SetForceRenderSurface(true);
2208 render_surface2->SetForceRenderSurface(true);
2209
2210 gfx::Transform layer_transform;
2211 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322212
2213 SetLayerPropertiesForTesting(parent.get(),
2214 layer_transform,
[email protected]a2566412014-06-05 03:14:202215 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322216 gfx::PointF(2.5f, 0.f),
2217 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572218 true,
[email protected]fb661802013-03-25 01:59:322219 false);
2220 SetLayerPropertiesForTesting(render_surface1.get(),
2221 layer_transform,
[email protected]a2566412014-06-05 03:14:202222 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322223 gfx::PointF(2.5f, 0.f),
2224 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572225 true,
[email protected]fb661802013-03-25 01:59:322226 false);
2227 SetLayerPropertiesForTesting(render_surface2.get(),
2228 layer_transform,
[email protected]a2566412014-06-05 03:14:202229 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322230 gfx::PointF(2.5f, 0.f),
2231 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572232 true,
[email protected]fb661802013-03-25 01:59:322233 false);
2234 SetLayerPropertiesForTesting(child_of_root.get(),
2235 layer_transform,
[email protected]a2566412014-06-05 03:14:202236 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322237 gfx::PointF(2.5f, 0.f),
2238 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572239 true,
[email protected]fb661802013-03-25 01:59:322240 false);
2241 SetLayerPropertiesForTesting(child_of_rs1.get(),
2242 layer_transform,
[email protected]a2566412014-06-05 03:14:202243 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322244 gfx::PointF(2.5f, 0.f),
2245 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572246 true,
[email protected]fb661802013-03-25 01:59:322247 false);
2248 SetLayerPropertiesForTesting(child_of_rs2.get(),
2249 layer_transform,
[email protected]a2566412014-06-05 03:14:202250 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322251 gfx::PointF(2.5f, 0.f),
2252 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572253 true,
[email protected]fb661802013-03-25 01:59:322254 false);
2255 SetLayerPropertiesForTesting(grand_child_of_root.get(),
2256 layer_transform,
[email protected]a2566412014-06-05 03:14:202257 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322258 gfx::PointF(2.5f, 0.f),
2259 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572260 true,
[email protected]fb661802013-03-25 01:59:322261 false);
2262 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
2263 layer_transform,
[email protected]a2566412014-06-05 03:14:202264 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322265 gfx::PointF(2.5f, 0.f),
2266 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572267 true,
[email protected]fb661802013-03-25 01:59:322268 false);
2269 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
2270 layer_transform,
[email protected]a2566412014-06-05 03:14:202271 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322272 gfx::PointF(2.5f, 0.f),
2273 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572274 true,
[email protected]fb661802013-03-25 01:59:322275 false);
2276
2277 // Put an animated opacity on the render surface.
2278 AddOpacityTransitionToController(
2279 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2280
2281 // Also put an animated opacity on a layer without descendants.
2282 AddOpacityTransitionToController(
2283 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2284
2285 // Put a transform animation on the render surface.
2286 AddAnimatedTransformToController(
2287 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2288
2289 // Also put transform animations on grand_child_of_root, and
2290 // grand_child_of_rs2
2291 AddAnimatedTransformToController(
2292 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2293 AddAnimatedTransformToController(
2294 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2295
2296 ExecuteCalculateDrawProperties(parent.get());
2297
2298 // Only layers that are associated with render surfaces should have an actual
2299 // RenderSurface() value.
2300 ASSERT_TRUE(parent->render_surface());
2301 ASSERT_FALSE(child_of_root->render_surface());
2302 ASSERT_FALSE(grand_child_of_root->render_surface());
2303
2304 ASSERT_TRUE(render_surface1->render_surface());
2305 ASSERT_FALSE(child_of_rs1->render_surface());
2306 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2307
2308 ASSERT_TRUE(render_surface2->render_surface());
2309 ASSERT_FALSE(child_of_rs2->render_surface());
2310 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2311
2312 // Verify all render target accessors
Daniel Chengeea98042014-08-26 00:28:102313 EXPECT_EQ(parent.get(), parent->render_target());
2314 EXPECT_EQ(parent.get(), child_of_root->render_target());
2315 EXPECT_EQ(parent.get(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322316
Daniel Chengeea98042014-08-26 00:28:102317 EXPECT_EQ(render_surface1.get(), render_surface1->render_target());
2318 EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target());
2319 EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322320
Daniel Chengeea98042014-08-26 00:28:102321 EXPECT_EQ(render_surface2.get(), render_surface2->render_target());
2322 EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target());
2323 EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322324
2325 // Verify draw_opacity_is_animating values
2326 EXPECT_FALSE(parent->draw_opacity_is_animating());
2327 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2328 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2329 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2330 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2331 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2332 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2333 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2334 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2335 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2336 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2337
2338 // Verify draw_transform_is_animating values
2339 EXPECT_FALSE(parent->draw_transform_is_animating());
2340 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2341 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2342 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2343 EXPECT_FALSE(render_surface1->render_surface()
2344 ->target_surface_transforms_are_animating());
2345 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2346 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2347 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2348 EXPECT_TRUE(render_surface2->render_surface()
2349 ->target_surface_transforms_are_animating());
2350 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2351 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2352
2353 // Verify screen_space_transform_is_animating values
2354 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2355 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2356 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2357 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2358 EXPECT_FALSE(render_surface1->render_surface()
2359 ->screen_space_transforms_are_animating());
2360 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2361 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2362 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2363 EXPECT_TRUE(render_surface2->render_surface()
2364 ->screen_space_transforms_are_animating());
2365 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2366 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2367
2368 // Sanity check. If these fail there is probably a bug in the test itself.
2369 // It is expected that we correctly set up transforms so that the y-component
2370 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262371 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2372 EXPECT_FLOAT_EQ(2.0,
2373 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322374 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262375 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322376
[email protected]803f6b52013-09-12 00:51:262377 EXPECT_FLOAT_EQ(2.0,
2378 render_surface1->screen_space_transform().matrix().get(1, 3));
2379 EXPECT_FLOAT_EQ(3.0,
2380 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322381 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262382 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322383
[email protected]803f6b52013-09-12 00:51:262384 EXPECT_FLOAT_EQ(3.0,
2385 render_surface2->screen_space_transform().matrix().get(1, 3));
2386 EXPECT_FLOAT_EQ(4.0,
2387 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322388 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262389 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322390}
2391
[email protected]989386c2013-07-18 21:37:232392TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322393 // Test the calculateVisibleRect() function works correctly for identity
2394 // transforms.
2395
[email protected]2c7c6702013-03-26 03:14:052396 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322397 gfx::Transform layer_to_surface_transform;
2398
2399 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232400 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052401 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322402 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2403 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322404 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322405
2406 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052407 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322408 actual = LayerTreeHostCommon::CalculateVisibleRect(
2409 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2410 EXPECT_TRUE(actual.IsEmpty());
2411
2412 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052413 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2414 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322415 actual = LayerTreeHostCommon::CalculateVisibleRect(
2416 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322417 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322418}
2419
[email protected]989386c2013-07-18 21:37:232420TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322421 // Test the calculateVisibleRect() function works correctly for scaling
2422 // transforms.
2423
[email protected]2c7c6702013-03-26 03:14:052424 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2425 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322426 gfx::Transform layer_to_surface_transform;
2427
2428 // Case 1: Layer is contained within the surface.
2429 layer_to_surface_transform.MakeIdentity();
2430 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052431 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322432 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2433 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322434 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322435
2436 // Case 2: Layer is outside the surface rect.
2437 layer_to_surface_transform.MakeIdentity();
2438 layer_to_surface_transform.Translate(120.0, 120.0);
2439 actual = LayerTreeHostCommon::CalculateVisibleRect(
2440 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2441 EXPECT_TRUE(actual.IsEmpty());
2442
2443 // Case 3: Layer is partially overlapping the surface rect.
2444 layer_to_surface_transform.MakeIdentity();
2445 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052446 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322447 actual = LayerTreeHostCommon::CalculateVisibleRect(
2448 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322449 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322450}
2451
[email protected]989386c2013-07-18 21:37:232452TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322453 // Test the calculateVisibleRect() function works correctly for rotations
2454 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2455 // should return the g in the layer's space.
2456
[email protected]2c7c6702013-03-26 03:14:052457 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2458 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322459 gfx::Transform layer_to_surface_transform;
2460
2461 // Case 1: Layer is contained within the surface.
2462 layer_to_surface_transform.MakeIdentity();
2463 layer_to_surface_transform.Translate(50.0, 50.0);
2464 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052465 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322466 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2467 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322468 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322469
2470 // Case 2: Layer is outside the surface rect.
2471 layer_to_surface_transform.MakeIdentity();
2472 layer_to_surface_transform.Translate(-50.0, 0.0);
2473 layer_to_surface_transform.Rotate(45.0);
2474 actual = LayerTreeHostCommon::CalculateVisibleRect(
2475 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2476 EXPECT_TRUE(actual.IsEmpty());
2477
2478 // Case 3: The layer is rotated about its top-left corner. In surface space,
2479 // the layer is oriented diagonally, with the left half outside of the render
2480 // surface. In this case, the g should still be the entire layer
2481 // (remember the g is computed in layer space); both the top-left
2482 // and bottom-right corners of the layer are still visible.
2483 layer_to_surface_transform.MakeIdentity();
2484 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052485 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322486 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 4: The layer is rotated about its top-left corner, and translated
2491 // upwards. In surface space, the layer is oriented diagonally, with only the
2492 // top corner of the surface overlapping the layer. In layer space, the render
2493 // surface overlaps the right side of the layer. The g should be
2494 // the layer's right half.
2495 layer_to_surface_transform.MakeIdentity();
2496 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2497 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052498 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322499 actual = LayerTreeHostCommon::CalculateVisibleRect(
2500 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322501 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322502}
2503
[email protected]989386c2013-07-18 21:37:232504TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322505 // Test that the calculateVisibleRect() function works correctly for 3d
2506 // transforms.
2507
[email protected]2c7c6702013-03-26 03:14:052508 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2509 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322510 gfx::Transform layer_to_surface_transform;
2511
2512 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2513 // degrees, should be fully contained in the render surface.
2514 layer_to_surface_transform.MakeIdentity();
2515 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052516 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322517 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2518 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322519 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322520
2521 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2522 // degrees, but shifted to the side so only the right-half the layer would be
2523 // visible on the surface.
2524 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262525 SkMScalar half_width_of_rotated_layer =
2526 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322527 layer_to_surface_transform.MakeIdentity();
2528 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232529 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2530 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052531 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322532 actual = LayerTreeHostCommon::CalculateVisibleRect(
2533 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322534 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322535}
2536
[email protected]989386c2013-07-18 21:37:232537TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322538 // Test the calculateVisibleRect() function works correctly when the layer has
2539 // a perspective projection onto the target surface.
2540
[email protected]2c7c6702013-03-26 03:14:052541 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2542 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322543 gfx::Transform layer_to_surface_transform;
2544
2545 // Case 1: Even though the layer is twice as large as the surface, due to
2546 // perspective foreshortening, the layer will fit fully in the surface when
2547 // its translated more than the perspective amount.
2548 layer_to_surface_transform.MakeIdentity();
2549
2550 // The following sequence of transforms applies the perspective about the
2551 // center of the surface.
2552 layer_to_surface_transform.Translate(50.0, 50.0);
2553 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2554 layer_to_surface_transform.Translate(-50.0, -50.0);
2555
2556 // This translate places the layer in front of the surface's projection plane.
2557 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2558
[email protected]2c7c6702013-03-26 03:14:052559 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322560 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2561 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322562 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322563
2564 // Case 2: same projection as before, except that the layer is also translated
2565 // to the side, so that only the right half of the layer should be visible.
2566 //
2567 // Explanation of expected result: The perspective ratio is (z distance
2568 // between layer and camera origin) / (z distance between projection plane and
2569 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2570 // move a layer by translating -50 units in projected surface units (so that
2571 // only half of it is visible), then we would need to translate by (-36 / 9) *
2572 // -50 == -200 in the layer's units.
2573 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232574 expected = gfx::Rect(gfx::Point(50, -50),
2575 gfx::Size(100, 200)); // The right half of the layer's
2576 // bounding rect.
[email protected]fb661802013-03-25 01:59:322577 actual = LayerTreeHostCommon::CalculateVisibleRect(
2578 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322579 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322580}
2581
[email protected]989386c2013-07-18 21:37:232582TEST_F(LayerTreeHostCommonTest,
2583 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322584 // There is currently no explicit concept of an orthographic projection plane
2585 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2586 // are technically behind the surface in an orthographic world should not be
2587 // clipped when they are flattened to the surface.
2588
[email protected]2c7c6702013-03-26 03:14:052589 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2590 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322591 gfx::Transform layer_to_surface_transform;
2592
2593 // This sequence of transforms effectively rotates the layer about the y-axis
2594 // at the center of the layer.
2595 layer_to_surface_transform.MakeIdentity();
2596 layer_to_surface_transform.Translate(50.0, 0.0);
2597 layer_to_surface_transform.RotateAboutYAxis(45.0);
2598 layer_to_surface_transform.Translate(-50.0, 0.0);
2599
[email protected]2c7c6702013-03-26 03:14:052600 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322601 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2602 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322603 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322604}
2605
[email protected]989386c2013-07-18 21:37:232606TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322607 // Test the calculateVisibleRect() function works correctly when projecting a
2608 // surface onto a layer, but the layer is partially behind the camera (not
2609 // just behind the projection plane). In this case, the cartesian coordinates
2610 // may seem to be valid, but actually they are not. The visible rect needs to
2611 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2612 // converting to cartesian coordinates.
2613
[email protected]2c7c6702013-03-26 03:14:052614 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232615 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322616 gfx::Transform layer_to_surface_transform;
2617
2618 // The layer is positioned so that the right half of the layer should be in
2619 // front of the camera, while the other half is behind the surface's
2620 // projection plane. The following sequence of transforms applies the
2621 // perspective and rotation about the center of the layer.
2622 layer_to_surface_transform.MakeIdentity();
2623 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2624 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2625 layer_to_surface_transform.RotateAboutYAxis(45.0);
2626
2627 // Sanity check that this transform does indeed cause w < 0 when applying the
2628 // transform, otherwise this code is not testing the intended scenario.
2629 bool clipped;
2630 MathUtil::MapQuad(layer_to_surface_transform,
2631 gfx::QuadF(gfx::RectF(layer_content_rect)),
2632 &clipped);
2633 ASSERT_TRUE(clipped);
2634
2635 int expected_x_position = 0;
2636 int expected_width = 10;
2637 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2638 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2639 EXPECT_EQ(expected_x_position, actual.x());
2640 EXPECT_EQ(expected_width, actual.width());
2641}
2642
[email protected]989386c2013-07-18 21:37:232643TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322644 // To determine visible rect in layer space, there needs to be an
2645 // un-projection from surface space to layer space. When the original
2646 // transform was a perspective projection that was clipped, it returns a rect
2647 // that encloses the clipped bounds. Un-projecting this new rect may require
2648 // clipping again.
2649
2650 // This sequence of transforms causes one corner of the layer to protrude
2651 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232652 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2653 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322654 gfx::Transform layer_to_surface_transform;
2655 layer_to_surface_transform.MakeIdentity();
2656 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2657 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2658 layer_to_surface_transform.RotateAboutYAxis(45.0);
2659 layer_to_surface_transform.RotateAboutXAxis(80.0);
2660
2661 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2662 // code is not testing the intended scenario.
2663 bool clipped;
2664 gfx::RectF clipped_rect =
2665 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2666 MathUtil::ProjectQuad(
2667 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2668 ASSERT_TRUE(clipped);
2669
2670 // Only the corner of the layer is not visible on the surface because of being
2671 // clipped. But, the net result of rounding visible region to an axis-aligned
2672 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052673 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322674 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2675 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322676 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322677}
2678
miletus9d3da522015-06-05 19:45:072679TEST_F(LayerTreeHostCommonTest,
2680 VisibleRectsForPositionedRootLayerClippedByViewport) {
2681 scoped_refptr<Layer> root =
2682 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2683 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
2684 host->SetRootLayer(root);
2685
2686 gfx::Transform identity_matrix;
2687 // Root layer is positioned at (60, 70). The default device viewport size
2688 // is (0, 0, 100x100) in target space. So the root layer's visible rect
2689 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
2690 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2691 gfx::PointF(60, 70), gfx::Size(100, 100), true,
2692 false);
2693 ExecuteCalculateDrawProperties(root.get());
2694
2695 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2696 root->render_surface()->DrawableContentRect());
2697 // In target space, not clipped.
2698 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root->drawable_content_rect());
2699 // In layer space, clipped.
2700 EXPECT_EQ(gfx::Rect(0, 0, 40, 30), root->visible_content_rect());
2701}
2702
[email protected]989386c2013-07-18 21:37:232703TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
loysoa6edaaff2015-05-25 03:26:442704 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:322705 scoped_refptr<LayerWithForcedDrawsContent> child1 =
loysoa6edaaff2015-05-25 03:26:442706 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322707 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loysoa6edaaff2015-05-25 03:26:442708 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322709 scoped_refptr<LayerWithForcedDrawsContent> child3 =
loysoa6edaaff2015-05-25 03:26:442710 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322711 root->AddChild(child1);
2712 root->AddChild(child2);
2713 root->AddChild(child3);
2714
enne2097cab2014-09-25 20:16:312715 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282716 host->SetRootLayer(root);
2717
[email protected]fb661802013-03-25 01:59:322718 gfx::Transform identity_matrix;
2719 SetLayerPropertiesForTesting(root.get(),
2720 identity_matrix,
[email protected]a2566412014-06-05 03:14:202721 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322722 gfx::PointF(),
2723 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572724 true,
[email protected]fb661802013-03-25 01:59:322725 false);
2726 SetLayerPropertiesForTesting(child1.get(),
2727 identity_matrix,
[email protected]a2566412014-06-05 03:14:202728 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322729 gfx::PointF(),
2730 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572731 true,
[email protected]fb661802013-03-25 01:59:322732 false);
2733 SetLayerPropertiesForTesting(child2.get(),
2734 identity_matrix,
[email protected]a2566412014-06-05 03:14:202735 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322736 gfx::PointF(75.f, 75.f),
2737 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572738 true,
[email protected]fb661802013-03-25 01:59:322739 false);
2740 SetLayerPropertiesForTesting(child3.get(),
2741 identity_matrix,
[email protected]a2566412014-06-05 03:14:202742 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322743 gfx::PointF(125.f, 125.f),
2744 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572745 true,
[email protected]fb661802013-03-25 01:59:322746 false);
2747
2748 ExecuteCalculateDrawProperties(root.get());
2749
hush6b614212014-12-04 22:37:322750 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2751 root->render_surface()->DrawableContentRect());
2752 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322753
2754 // Layers that do not draw content should have empty visible_content_rects.
hush6b614212014-12-04 22:37:322755 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322756
2757 // layer visible_content_rects are clipped by their target surface.
hush6b614212014-12-04 22:37:322758 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2759 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322760 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
2761
2762 // layer drawable_content_rects are not clipped.
hush6b614212014-12-04 22:37:322763 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
2764 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2765 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322766}
2767
[email protected]989386c2013-07-18 21:37:232768TEST_F(LayerTreeHostCommonTest,
2769 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
loysoa6edaaff2015-05-25 03:26:442770 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2771 scoped_refptr<Layer> child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:322772 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
loysoa6edaaff2015-05-25 03:26:442773 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322774 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
loysoa6edaaff2015-05-25 03:26:442775 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322776 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
loysoa6edaaff2015-05-25 03:26:442777 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322778 root->AddChild(child);
2779 child->AddChild(grand_child1);
2780 child->AddChild(grand_child2);
2781 child->AddChild(grand_child3);
2782
enne2097cab2014-09-25 20:16:312783 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282784 host->SetRootLayer(root);
2785
[email protected]fb661802013-03-25 01:59:322786 gfx::Transform identity_matrix;
2787 SetLayerPropertiesForTesting(root.get(),
2788 identity_matrix,
[email protected]a2566412014-06-05 03:14:202789 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322790 gfx::PointF(),
2791 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572792 true,
[email protected]fb661802013-03-25 01:59:322793 false);
2794 SetLayerPropertiesForTesting(child.get(),
2795 identity_matrix,
[email protected]a2566412014-06-05 03:14:202796 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322797 gfx::PointF(),
2798 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572799 true,
[email protected]fb661802013-03-25 01:59:322800 false);
2801 SetLayerPropertiesForTesting(grand_child1.get(),
2802 identity_matrix,
[email protected]a2566412014-06-05 03:14:202803 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322804 gfx::PointF(5.f, 5.f),
2805 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572806 true,
[email protected]fb661802013-03-25 01:59:322807 false);
2808 SetLayerPropertiesForTesting(grand_child2.get(),
2809 identity_matrix,
[email protected]a2566412014-06-05 03:14:202810 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322811 gfx::PointF(75.f, 75.f),
2812 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572813 true,
[email protected]fb661802013-03-25 01:59:322814 false);
2815 SetLayerPropertiesForTesting(grand_child3.get(),
2816 identity_matrix,
[email protected]a2566412014-06-05 03:14:202817 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322818 gfx::PointF(125.f, 125.f),
2819 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572820 true,
[email protected]fb661802013-03-25 01:59:322821 false);
2822
2823 child->SetMasksToBounds(true);
2824 ExecuteCalculateDrawProperties(root.get());
2825
2826 ASSERT_FALSE(child->render_surface());
2827
hush6b614212014-12-04 22:37:322828 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2829 root->render_surface()->DrawableContentRect());
2830 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322831
2832 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:322833 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2834 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322835
2836 // All grandchild visible content rects should be clipped by child.
hush6b614212014-12-04 22:37:322837 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
2838 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322839 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
2840
2841 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:322842 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
2843 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322844 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2845}
2846
ajuma27442dd2015-03-30 19:19:482847TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
loysoa6edaaff2015-05-25 03:26:442848 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2849 scoped_refptr<Layer> child = Layer::Create(layer_settings());
ajuma27442dd2015-03-30 19:19:482850 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loysoa6edaaff2015-05-25 03:26:442851 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma27442dd2015-03-30 19:19:482852 root->AddChild(child);
2853 child->AddChild(grand_child);
2854
2855 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
2856 host->SetRootLayer(root);
2857
2858 gfx::Transform identity_matrix;
2859 gfx::Transform child_scale_matrix;
2860 child_scale_matrix.Scale(0.25f, 0.25f);
2861 gfx::Transform grand_child_scale_matrix;
2862 grand_child_scale_matrix.Scale(0.246f, 0.246f);
2863 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2864 gfx::PointF(), gfx::Size(100, 100), true, false);
2865 SetLayerPropertiesForTesting(child.get(), child_scale_matrix, gfx::Point3F(),
2866 gfx::PointF(), gfx::Size(10, 10), true, false);
2867 SetLayerPropertiesForTesting(grand_child.get(), grand_child_scale_matrix,
2868 gfx::Point3F(), gfx::PointF(),
2869 gfx::Size(100, 100), true, false);
2870
2871 child->SetMasksToBounds(true);
enne601f2ef12015-05-19 18:20:172872 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajuma27442dd2015-03-30 19:19:482873
2874 // The visible rect is expanded to integer coordinates in target space before
2875 // being projected back to layer space, where it is once again expanded to
2876 // integer coordinates.
2877 EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_rect_from_property_trees());
2878}
2879
[email protected]989386c2013-07-18 21:37:232880TEST_F(LayerTreeHostCommonTest,
2881 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
loysoa6edaaff2015-05-25 03:26:442882 scoped_refptr<Layer> root = Layer::Create(layer_settings());
2883 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:322884 scoped_refptr<LayerWithForcedDrawsContent> child1 =
loysoa6edaaff2015-05-25 03:26:442885 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322886 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loysoa6edaaff2015-05-25 03:26:442887 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322888 scoped_refptr<LayerWithForcedDrawsContent> child3 =
loysoa6edaaff2015-05-25 03:26:442889 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:322890 root->AddChild(render_surface1);
2891 render_surface1->AddChild(child1);
2892 render_surface1->AddChild(child2);
2893 render_surface1->AddChild(child3);
2894
enne2097cab2014-09-25 20:16:312895 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282896 host->SetRootLayer(root);
2897
[email protected]fb661802013-03-25 01:59:322898 gfx::Transform identity_matrix;
2899 SetLayerPropertiesForTesting(root.get(),
2900 identity_matrix,
[email protected]a2566412014-06-05 03:14:202901 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322902 gfx::PointF(),
2903 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572904 true,
[email protected]fb661802013-03-25 01:59:322905 false);
2906 SetLayerPropertiesForTesting(render_surface1.get(),
2907 identity_matrix,
[email protected]a2566412014-06-05 03:14:202908 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322909 gfx::PointF(),
2910 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:572911 true,
[email protected]fb661802013-03-25 01:59:322912 false);
2913 SetLayerPropertiesForTesting(child1.get(),
2914 identity_matrix,
[email protected]a2566412014-06-05 03:14:202915 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322916 gfx::PointF(5.f, 5.f),
2917 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572918 true,
[email protected]fb661802013-03-25 01:59:322919 false);
2920 SetLayerPropertiesForTesting(child2.get(),
2921 identity_matrix,
[email protected]a2566412014-06-05 03:14:202922 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322923 gfx::PointF(75.f, 75.f),
2924 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572925 true,
[email protected]fb661802013-03-25 01:59:322926 false);
2927 SetLayerPropertiesForTesting(child3.get(),
2928 identity_matrix,
[email protected]a2566412014-06-05 03:14:202929 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322930 gfx::PointF(125.f, 125.f),
2931 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572932 true,
[email protected]fb661802013-03-25 01:59:322933 false);
2934
2935 render_surface1->SetForceRenderSurface(true);
2936 ExecuteCalculateDrawProperties(root.get());
2937
2938 ASSERT_TRUE(render_surface1->render_surface());
2939
hush6b614212014-12-04 22:37:322940 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2941 root->render_surface()->DrawableContentRect());
2942 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322943
2944 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:322945 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2946 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322947
2948 // An unclipped surface grows its DrawableContentRect to include all drawable
2949 // regions of the subtree.
hush6b614212014-12-04 22:37:322950 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2951 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322952
2953 // All layers that draw content into the unclipped surface are also unclipped.
hush6b614212014-12-04 22:37:322954 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2955 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
2956 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322957
hush6b614212014-12-04 22:37:322958 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2959 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2960 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322961}
2962
[email protected]989386c2013-07-18 21:37:232963TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:022964 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
loysoa6edaaff2015-05-25 03:26:442965 scoped_refptr<Layer> root = Layer::Create(layer_settings());
hush887bb542014-12-02 22:49:022966 scoped_refptr<LayerWithForcedDrawsContent> child1 =
loysoa6edaaff2015-05-25 03:26:442967 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
hush887bb542014-12-02 22:49:022968 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loysoa6edaaff2015-05-25 03:26:442969 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
hush887bb542014-12-02 22:49:022970 scoped_refptr<LayerWithForcedDrawsContent> child3 =
loysoa6edaaff2015-05-25 03:26:442971 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
hush887bb542014-12-02 22:49:022972 root->AddChild(child1);
2973 root->AddChild(child2);
2974 root->AddChild(child3);
2975
2976 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
2977 host->SetRootLayer(root);
2978
2979 gfx::Transform identity_matrix;
2980 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2981 gfx::PointF(), gfx::Size(100, 100), true, false);
2982 SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(),
2983 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2984 false);
2985 SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(),
2986 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2987 false);
2988 SetLayerPropertiesForTesting(child3.get(), identity_matrix, gfx::Point3F(),
2989 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2990 true, false);
2991
2992 RenderSurfaceLayerList render_surface_layer_list;
2993 // Now set the root render surface an empty clip.
2994 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2995 root.get(), gfx::Size(), &render_surface_layer_list);
2996
2997 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
2998 ASSERT_TRUE(root->render_surface());
2999 EXPECT_FALSE(root->is_clipped());
3000
3001 gfx::Rect empty;
3002 EXPECT_EQ(empty, root->render_surface()->clip_rect());
3003 EXPECT_TRUE(root->render_surface()->is_clipped());
3004
3005 // Visible content rect calculation will check if the target surface is
3006 // clipped or not. An empty clip rect does not indicate the render surface
3007 // is unclipped.
3008 EXPECT_EQ(empty, child1->visible_content_rect());
3009 EXPECT_EQ(empty, child2->visible_content_rect());
3010 EXPECT_EQ(empty, child3->visible_content_rect());
3011}
3012
3013TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233014 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
loysoa6edaaff2015-05-25 03:26:443015 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]451107a32013-04-10 05:12:473016 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:443017 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]451107a32013-04-10 05:12:473018 root->AddChild(child);
3019
enne2097cab2014-09-25 20:16:313020 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283021 host->SetRootLayer(root);
3022
[email protected]630ddad2013-08-16 03:01:323023 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:473024 gfx::Transform identity_matrix;
3025 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:323026 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:473027
3028 SetLayerPropertiesForTesting(root.get(),
3029 identity_matrix,
[email protected]a2566412014-06-05 03:14:203030 gfx::Point3F(),
[email protected]451107a32013-04-10 05:12:473031 gfx::PointF(),
3032 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573033 true,
[email protected]451107a32013-04-10 05:12:473034 false);
3035 SetLayerPropertiesForTesting(child.get(),
3036 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203037 gfx::Point3F(),
[email protected]451107a32013-04-10 05:12:473038 gfx::PointF(5.f, 5.f),
3039 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573040 true,
[email protected]451107a32013-04-10 05:12:473041 false);
3042
3043 ExecuteCalculateDrawProperties(root.get());
3044
3045 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
3046 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323047
[email protected]08bdf1b2014-04-16 23:23:293048 // Case 2: a matrix with flattened z, uninvertible and not visible according
3049 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:323050 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263051 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323052 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3053
3054 SetLayerPropertiesForTesting(child.get(),
3055 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203056 gfx::Point3F(),
[email protected]630ddad2013-08-16 03:01:323057 gfx::PointF(5.f, 5.f),
3058 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573059 true,
[email protected]630ddad2013-08-16 03:01:323060 false);
3061
3062 ExecuteCalculateDrawProperties(root.get());
3063
[email protected]08bdf1b2014-04-16 23:23:293064 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
3065 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323066
[email protected]08bdf1b2014-04-16 23:23:293067 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:323068 uninvertible_matrix.MakeIdentity();
3069 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263070 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323071 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3072
3073 SetLayerPropertiesForTesting(child.get(),
3074 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203075 gfx::Point3F(),
[email protected]630ddad2013-08-16 03:01:323076 gfx::PointF(5.f, 5.f),
3077 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573078 true,
[email protected]630ddad2013-08-16 03:01:323079 false);
3080
3081 ExecuteCalculateDrawProperties(root.get());
3082
3083 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293084 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473085}
3086
[email protected]989386c2013-07-18 21:37:233087TEST_F(LayerTreeHostCommonTest,
[email protected]e43c68b2014-05-01 05:10:363088 SingularTransformDoesNotPreventClearingDrawProperties) {
loysoa6edaaff2015-05-25 03:26:443089 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]e43c68b2014-05-01 05:10:363090 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:443091 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]e43c68b2014-05-01 05:10:363092 root->AddChild(child);
3093
enne2097cab2014-09-25 20:16:313094 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]e43c68b2014-05-01 05:10:363095 host->SetRootLayer(root);
3096
3097 gfx::Transform identity_matrix;
3098 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3099 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3100
3101 SetLayerPropertiesForTesting(root.get(),
3102 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203103 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:363104 gfx::PointF(),
3105 gfx::Size(100, 100),
3106 true,
3107 false);
3108 SetLayerPropertiesForTesting(child.get(),
3109 identity_matrix,
[email protected]a2566412014-06-05 03:14:203110 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:363111 gfx::PointF(5.f, 5.f),
3112 gfx::Size(50, 50),
3113 true,
3114 false);
3115
jaydasika976cd10b2015-05-26 15:45:243116 child->set_sorted_for_recursion(true);
[email protected]e43c68b2014-05-01 05:10:363117
3118 TransformOperations start_transform_operations;
3119 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
3120
3121 TransformOperations end_transform_operations;
3122 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
3123
3124 AddAnimatedTransformToLayer(
3125 root.get(), 10.0, start_transform_operations, end_transform_operations);
3126
3127 EXPECT_TRUE(root->TransformIsAnimating());
3128
3129 ExecuteCalculateDrawProperties(root.get());
3130
jaydasika976cd10b2015-05-26 15:45:243131 EXPECT_FALSE(child->sorted_for_recursion());
[email protected]e43c68b2014-05-01 05:10:363132}
3133
3134TEST_F(LayerTreeHostCommonTest,
[email protected]8dbc85c2014-05-03 03:21:063135 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
loysoa6edaaff2015-05-25 03:26:443136 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]8dbc85c2014-05-03 03:21:063137
enne2097cab2014-09-25 20:16:313138 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]8dbc85c2014-05-03 03:21:063139 host->SetRootLayer(root);
3140
3141 gfx::Transform identity_matrix;
3142 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3143 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3144
3145 SetLayerPropertiesForTesting(root.get(),
3146 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203147 gfx::Point3F(),
[email protected]8dbc85c2014-05-03 03:21:063148 gfx::PointF(),
3149 gfx::Size(100, 100),
3150 true,
3151 false);
3152
jaydasika976cd10b2015-05-26 15:45:243153 root->set_sorted_for_recursion(true);
[email protected]8dbc85c2014-05-03 03:21:063154
3155 EXPECT_FALSE(root->TransformIsAnimating());
3156
3157 ExecuteCalculateDrawProperties(root.get());
3158
jaydasika976cd10b2015-05-26 15:45:243159 EXPECT_FALSE(root->sorted_for_recursion());
[email protected]8dbc85c2014-05-03 03:21:063160}
3161
3162TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233163 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
loysoa6edaaff2015-05-25 03:26:443164 scoped_refptr<Layer> root = Layer::Create(layer_settings());
3165 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:323166 scoped_refptr<LayerWithForcedDrawsContent> child1 =
loysoa6edaaff2015-05-25 03:26:443167 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323168 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loysoa6edaaff2015-05-25 03:26:443169 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323170 scoped_refptr<LayerWithForcedDrawsContent> child3 =
loysoa6edaaff2015-05-25 03:26:443171 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323172 root->AddChild(render_surface1);
3173 render_surface1->AddChild(child1);
3174 render_surface1->AddChild(child2);
3175 render_surface1->AddChild(child3);
3176
enne2097cab2014-09-25 20:16:313177 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283178 host->SetRootLayer(root);
3179
[email protected]fb661802013-03-25 01:59:323180 gfx::Transform identity_matrix;
3181 SetLayerPropertiesForTesting(root.get(),
3182 identity_matrix,
[email protected]a2566412014-06-05 03:14:203183 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323184 gfx::PointF(),
3185 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573186 true,
[email protected]fb661802013-03-25 01:59:323187 false);
3188 SetLayerPropertiesForTesting(render_surface1.get(),
3189 identity_matrix,
[email protected]a2566412014-06-05 03:14:203190 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323191 gfx::PointF(),
3192 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573193 true,
[email protected]fb661802013-03-25 01:59:323194 false);
3195 SetLayerPropertiesForTesting(child1.get(),
3196 identity_matrix,
[email protected]a2566412014-06-05 03:14:203197 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323198 gfx::PointF(5.f, 5.f),
3199 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573200 true,
[email protected]fb661802013-03-25 01:59:323201 false);
3202 SetLayerPropertiesForTesting(child2.get(),
3203 identity_matrix,
[email protected]a2566412014-06-05 03:14:203204 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323205 gfx::PointF(75.f, 75.f),
3206 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573207 true,
[email protected]fb661802013-03-25 01:59:323208 false);
3209 SetLayerPropertiesForTesting(child3.get(),
3210 identity_matrix,
[email protected]a2566412014-06-05 03:14:203211 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323212 gfx::PointF(125.f, 125.f),
3213 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573214 true,
[email protected]fb661802013-03-25 01:59:323215 false);
3216
3217 root->SetMasksToBounds(true);
3218 render_surface1->SetForceRenderSurface(true);
3219 ExecuteCalculateDrawProperties(root.get());
3220
3221 ASSERT_TRUE(render_surface1->render_surface());
3222
hush6b614212014-12-04 22:37:323223 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3224 root->render_surface()->DrawableContentRect());
3225 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323226
3227 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323228 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3229 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323230
3231 // A clipped surface grows its DrawableContentRect to include all drawable
3232 // regions of the subtree, but also gets clamped by the ancestor's clip.
hush6b614212014-12-04 22:37:323233 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3234 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323235
3236 // All layers that draw content into the surface have their visible content
3237 // rect clipped by the surface clip rect.
hush6b614212014-12-04 22:37:323238 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3239 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323240 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3241
3242 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323243 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3244 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3245 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323246}
3247
[email protected]989386c2013-07-18 21:37:233248TEST_F(LayerTreeHostCommonTest,
3249 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323250 // Check that clipping does not propagate down surfaces.
loysoa6edaaff2015-05-25 03:26:443251 scoped_refptr<Layer> root = Layer::Create(layer_settings());
3252 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
3253 scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:323254 scoped_refptr<LayerWithForcedDrawsContent> child1 =
loysoa6edaaff2015-05-25 03:26:443255 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323256 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loysoa6edaaff2015-05-25 03:26:443257 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323258 scoped_refptr<LayerWithForcedDrawsContent> child3 =
loysoa6edaaff2015-05-25 03:26:443259 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323260 root->AddChild(render_surface1);
3261 render_surface1->AddChild(render_surface2);
3262 render_surface2->AddChild(child1);
3263 render_surface2->AddChild(child2);
3264 render_surface2->AddChild(child3);
3265
enne2097cab2014-09-25 20:16:313266 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283267 host->SetRootLayer(root);
3268
[email protected]fb661802013-03-25 01:59:323269 gfx::Transform identity_matrix;
3270 SetLayerPropertiesForTesting(root.get(),
3271 identity_matrix,
[email protected]a2566412014-06-05 03:14:203272 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323273 gfx::PointF(),
3274 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573275 true,
[email protected]fb661802013-03-25 01:59:323276 false);
3277 SetLayerPropertiesForTesting(render_surface1.get(),
3278 identity_matrix,
[email protected]a2566412014-06-05 03:14:203279 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323280 gfx::PointF(),
3281 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573282 true,
[email protected]fb661802013-03-25 01:59:323283 false);
3284 SetLayerPropertiesForTesting(render_surface2.get(),
3285 identity_matrix,
[email protected]a2566412014-06-05 03:14:203286 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323287 gfx::PointF(),
3288 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573289 true,
[email protected]fb661802013-03-25 01:59:323290 false);
3291 SetLayerPropertiesForTesting(child1.get(),
3292 identity_matrix,
[email protected]a2566412014-06-05 03:14:203293 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323294 gfx::PointF(5.f, 5.f),
3295 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573296 true,
[email protected]fb661802013-03-25 01:59:323297 false);
3298 SetLayerPropertiesForTesting(child2.get(),
3299 identity_matrix,
[email protected]a2566412014-06-05 03:14:203300 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323301 gfx::PointF(75.f, 75.f),
3302 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573303 true,
[email protected]fb661802013-03-25 01:59:323304 false);
3305 SetLayerPropertiesForTesting(child3.get(),
3306 identity_matrix,
[email protected]a2566412014-06-05 03:14:203307 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323308 gfx::PointF(125.f, 125.f),
3309 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573310 true,
[email protected]fb661802013-03-25 01:59:323311 false);
3312
3313 root->SetMasksToBounds(true);
3314 render_surface1->SetForceRenderSurface(true);
3315 render_surface2->SetForceRenderSurface(true);
3316 ExecuteCalculateDrawProperties(root.get());
3317
3318 ASSERT_TRUE(render_surface1->render_surface());
3319 ASSERT_TRUE(render_surface2->render_surface());
3320
hush6b614212014-12-04 22:37:323321 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3322 root->render_surface()->DrawableContentRect());
3323 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323324
3325 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323326 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3327 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
3328 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323329
3330 // A clipped surface grows its DrawableContentRect to include all drawable
3331 // regions of the subtree, but also gets clamped by the ancestor's clip.
hush6b614212014-12-04 22:37:323332 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3333 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323334
3335 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3336 // is only implicitly clipped by render_surface1's content rect. So,
3337 // render_surface2 grows to enclose all drawable content of its subtree.
hush6b614212014-12-04 22:37:323338 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
3339 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323340
3341 // All layers that draw content into render_surface2 think they are unclipped.
hush6b614212014-12-04 22:37:323342 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3343 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3344 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323345
3346 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323347 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3348 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3349 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323350}
3351
[email protected]989386c2013-07-18 21:37:233352TEST_F(LayerTreeHostCommonTest,
3353 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323354 // Layers that have non-axis aligned bounds (due to transforms) have an
3355 // expanded, axis-aligned DrawableContentRect and visible content rect.
3356
loysoa6edaaff2015-05-25 03:26:443357 scoped_refptr<Layer> root = Layer::Create(layer_settings());
3358 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:323359 scoped_refptr<LayerWithForcedDrawsContent> child1 =
loysoa6edaaff2015-05-25 03:26:443360 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323361 root->AddChild(render_surface1);
3362 render_surface1->AddChild(child1);
3363
enne2097cab2014-09-25 20:16:313364 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283365 host->SetRootLayer(root);
3366
[email protected]fb661802013-03-25 01:59:323367 gfx::Transform identity_matrix;
3368 gfx::Transform child_rotation;
3369 child_rotation.Rotate(45.0);
3370 SetLayerPropertiesForTesting(root.get(),
3371 identity_matrix,
[email protected]a2566412014-06-05 03:14:203372 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323373 gfx::PointF(),
3374 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573375 true,
[email protected]fb661802013-03-25 01:59:323376 false);
3377 SetLayerPropertiesForTesting(render_surface1.get(),
3378 identity_matrix,
[email protected]a2566412014-06-05 03:14:203379 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323380 gfx::PointF(),
3381 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573382 true,
[email protected]fb661802013-03-25 01:59:323383 false);
3384 SetLayerPropertiesForTesting(child1.get(),
3385 child_rotation,
[email protected]a2566412014-06-05 03:14:203386 gfx::Point3F(25, 25, 0.f),
[email protected]fb661802013-03-25 01:59:323387 gfx::PointF(25.f, 25.f),
3388 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573389 true,
[email protected]fb661802013-03-25 01:59:323390 false);
3391
3392 render_surface1->SetForceRenderSurface(true);
3393 ExecuteCalculateDrawProperties(root.get());
3394
3395 ASSERT_TRUE(render_surface1->render_surface());
3396
hush6b614212014-12-04 22:37:323397 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3398 root->render_surface()->DrawableContentRect());
3399 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323400
3401 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323402 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3403 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323404
3405 // The unclipped surface grows its DrawableContentRect to include all drawable
3406 // regions of the subtree.
3407 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3408 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263409 gfx::Rect(50 - diagonal_radius,
3410 50 - diagonal_radius,
3411 diagonal_radius * 2,
3412 diagonal_radius * 2);
hush6b614212014-12-04 22:37:323413 EXPECT_EQ(expected_surface_drawable_content,
3414 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323415
3416 // All layers that draw content into the unclipped surface are also unclipped.
hush6b614212014-12-04 22:37:323417 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3418 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323419}
3420
[email protected]989386c2013-07-18 21:37:233421TEST_F(LayerTreeHostCommonTest,
3422 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323423 // Layers that have non-axis aligned bounds (due to transforms) have an
3424 // expanded, axis-aligned DrawableContentRect and visible content rect.
3425
loysoa6edaaff2015-05-25 03:26:443426 scoped_refptr<Layer> root = Layer::Create(layer_settings());
3427 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:323428 scoped_refptr<LayerWithForcedDrawsContent> child1 =
loysoa6edaaff2015-05-25 03:26:443429 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323430 root->AddChild(render_surface1);
3431 render_surface1->AddChild(child1);
3432
enne2097cab2014-09-25 20:16:313433 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283434 host->SetRootLayer(root);
3435
[email protected]fb661802013-03-25 01:59:323436 gfx::Transform identity_matrix;
3437 gfx::Transform child_rotation;
3438 child_rotation.Rotate(45.0);
3439 SetLayerPropertiesForTesting(root.get(),
3440 identity_matrix,
[email protected]a2566412014-06-05 03:14:203441 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323442 gfx::PointF(),
3443 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573444 true,
[email protected]fb661802013-03-25 01:59:323445 false);
3446 SetLayerPropertiesForTesting(render_surface1.get(),
3447 identity_matrix,
[email protected]a2566412014-06-05 03:14:203448 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323449 gfx::PointF(),
3450 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573451 true,
[email protected]fb661802013-03-25 01:59:323452 false);
[email protected]a2566412014-06-05 03:14:203453
[email protected]fb661802013-03-25 01:59:323454 SetLayerPropertiesForTesting(child1.get(),
3455 child_rotation,
[email protected]a2566412014-06-05 03:14:203456 gfx::Point3F(25, 25, 0.f),
[email protected]fb661802013-03-25 01:59:323457 gfx::PointF(25.f, 25.f),
3458 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573459 true,
[email protected]fb661802013-03-25 01:59:323460 false);
3461
3462 root->SetMasksToBounds(true);
3463 render_surface1->SetForceRenderSurface(true);
3464 ExecuteCalculateDrawProperties(root.get());
3465
3466 ASSERT_TRUE(render_surface1->render_surface());
3467
3468 // The clipped surface clamps the DrawableContentRect that encloses the
3469 // rotated layer.
3470 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263471 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3472 50 - diagonal_radius,
3473 diagonal_radius * 2,
3474 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323475 gfx::Rect expected_surface_drawable_content =
3476 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
hush6b614212014-12-04 22:37:323477 EXPECT_EQ(expected_surface_drawable_content,
3478 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323479
3480 // On the clipped surface, only a quarter of the child1 is visible, but when
3481 // rotating it back to child1's content space, the actual enclosing rect ends
3482 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263483 //
3484 // Given the floating point math, this number is a little bit fuzzy.
hush6b614212014-12-04 22:37:323485 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323486
3487 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:323488 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323489}
3490
[email protected]989386c2013-07-18 21:37:233491TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323492 MockContentLayerClient client;
3493
loysoa6edaaff2015-05-25 03:26:443494 scoped_refptr<Layer> root = Layer::Create(layer_settings());
sohan.jyotie3bd6192014-10-13 07:13:593495 scoped_refptr<FakePictureLayer> render_surface1 =
loysoa6edaaff2015-05-25 03:26:443496 CreateDrawablePictureLayer(layer_settings(), &client);
sohan.jyotie3bd6192014-10-13 07:13:593497 scoped_refptr<FakePictureLayer> render_surface2 =
loysoa6edaaff2015-05-25 03:26:443498 CreateDrawablePictureLayer(layer_settings(), &client);
3499 scoped_refptr<FakePictureLayer> child1 =
3500 CreateDrawablePictureLayer(layer_settings(), &client);
3501 scoped_refptr<FakePictureLayer> child2 =
3502 CreateDrawablePictureLayer(layer_settings(), &client);
3503 scoped_refptr<FakePictureLayer> child3 =
3504 CreateDrawablePictureLayer(layer_settings(), &client);
[email protected]fb661802013-03-25 01:59:323505 root->AddChild(render_surface1);
3506 render_surface1->AddChild(render_surface2);
3507 render_surface2->AddChild(child1);
3508 render_surface2->AddChild(child2);
3509 render_surface2->AddChild(child3);
3510
enne2097cab2014-09-25 20:16:313511 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283512 host->SetRootLayer(root);
3513
[email protected]fb661802013-03-25 01:59:323514 gfx::Transform identity_matrix;
3515 SetLayerPropertiesForTesting(root.get(),
3516 identity_matrix,
[email protected]a2566412014-06-05 03:14:203517 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323518 gfx::PointF(),
3519 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573520 true,
[email protected]fb661802013-03-25 01:59:323521 false);
3522 SetLayerPropertiesForTesting(render_surface1.get(),
3523 identity_matrix,
[email protected]a2566412014-06-05 03:14:203524 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323525 gfx::PointF(5.f, 5.f),
3526 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573527 true,
[email protected]fb661802013-03-25 01:59:323528 false);
3529 SetLayerPropertiesForTesting(render_surface2.get(),
3530 identity_matrix,
[email protected]a2566412014-06-05 03:14:203531 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323532 gfx::PointF(5.f, 5.f),
3533 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573534 true,
[email protected]fb661802013-03-25 01:59:323535 false);
3536 SetLayerPropertiesForTesting(child1.get(),
3537 identity_matrix,
[email protected]a2566412014-06-05 03:14:203538 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323539 gfx::PointF(5.f, 5.f),
3540 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573541 true,
[email protected]fb661802013-03-25 01:59:323542 false);
3543 SetLayerPropertiesForTesting(child2.get(),
3544 identity_matrix,
[email protected]a2566412014-06-05 03:14:203545 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323546 gfx::PointF(75.f, 75.f),
3547 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573548 true,
[email protected]fb661802013-03-25 01:59:323549 false);
3550 SetLayerPropertiesForTesting(child3.get(),
3551 identity_matrix,
[email protected]a2566412014-06-05 03:14:203552 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323553 gfx::PointF(125.f, 125.f),
3554 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573555 true,
[email protected]fb661802013-03-25 01:59:323556 false);
3557
3558 float device_scale_factor = 2.f;
3559
3560 root->SetMasksToBounds(true);
3561 render_surface1->SetForceRenderSurface(true);
3562 render_surface2->SetForceRenderSurface(true);
3563 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3564
3565 ASSERT_TRUE(render_surface1->render_surface());
3566 ASSERT_TRUE(render_surface2->render_surface());
3567
3568 // drawable_content_rects for all layers and surfaces are scaled by
3569 // device_scale_factor.
hush6b614212014-12-04 22:37:323570 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3571 root->render_surface()->DrawableContentRect());
3572 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3573 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3574 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323575
3576 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3577 // is only implicitly clipped by render_surface1.
hush6b614212014-12-04 22:37:323578 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3579 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323580
hush6b614212014-12-04 22:37:323581 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3582 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
3583 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323584
3585 // The root layer does not actually draw content of its own.
hush6b614212014-12-04 22:37:323586 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323587
sohan.jyotie3bd6192014-10-13 07:13:593588 // All layer visible content rects are not expressed in content space of each
3589 // layer, so they are not scaled by the device_scale_factor.
hush6b614212014-12-04 22:37:323590 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_content_rect());
3591 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_content_rect());
3592 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3593 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3594 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323595}
3596
[email protected]989386c2013-07-18 21:37:233597TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323598 // Verify the behavior of back-face culling when there are no preserve-3d
3599 // layers. Note that 3d transforms still apply in this case, but they are
3600 // "flattened" to each parent layer according to current W3C spec.
3601
3602 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:443603 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:323604 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
loysoa6edaaff2015-05-25 03:26:443605 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323606 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
loysoa6edaaff2015-05-25 03:26:443607 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323608 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
loysoa6edaaff2015-05-25 03:26:443609 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323610 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
loysoa6edaaff2015-05-25 03:26:443611 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323612 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233613 front_facing_child_of_front_facing_surface =
loysoa6edaaff2015-05-25 03:26:443614 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323615 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233616 back_facing_child_of_front_facing_surface =
loysoa6edaaff2015-05-25 03:26:443617 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323618 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233619 front_facing_child_of_back_facing_surface =
loysoa6edaaff2015-05-25 03:26:443620 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323621 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233622 back_facing_child_of_back_facing_surface =
loysoa6edaaff2015-05-25 03:26:443623 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323624
3625 parent->AddChild(front_facing_child);
3626 parent->AddChild(back_facing_child);
3627 parent->AddChild(front_facing_surface);
3628 parent->AddChild(back_facing_surface);
3629 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3630 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3631 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3632 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3633
enne2097cab2014-09-25 20:16:313634 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283635 host->SetRootLayer(parent);
3636
[email protected]fb661802013-03-25 01:59:323637 // Nothing is double-sided
3638 front_facing_child->SetDoubleSided(false);
3639 back_facing_child->SetDoubleSided(false);
3640 front_facing_surface->SetDoubleSided(false);
3641 back_facing_surface->SetDoubleSided(false);
3642 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3643 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3644 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3645 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3646
3647 gfx::Transform backface_matrix;
3648 backface_matrix.Translate(50.0, 50.0);
3649 backface_matrix.RotateAboutYAxis(180.0);
3650 backface_matrix.Translate(-50.0, -50.0);
3651
3652 // Having a descendant and opacity will force these to have render surfaces.
3653 front_facing_surface->SetOpacity(0.5f);
3654 back_facing_surface->SetOpacity(0.5f);
3655
3656 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3657 // these layers should blindly use their own local transforms to determine
3658 // back-face culling.
3659 SetLayerPropertiesForTesting(parent.get(),
3660 identity_matrix,
[email protected]a2566412014-06-05 03:14:203661 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323662 gfx::PointF(),
3663 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573664 true,
[email protected]fb661802013-03-25 01:59:323665 false);
3666 SetLayerPropertiesForTesting(front_facing_child.get(),
3667 identity_matrix,
[email protected]a2566412014-06-05 03:14:203668 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323669 gfx::PointF(),
3670 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573671 true,
[email protected]fb661802013-03-25 01:59:323672 false);
3673 SetLayerPropertiesForTesting(back_facing_child.get(),
3674 backface_matrix,
[email protected]a2566412014-06-05 03:14:203675 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323676 gfx::PointF(),
3677 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573678 true,
[email protected]fb661802013-03-25 01:59:323679 false);
3680 SetLayerPropertiesForTesting(front_facing_surface.get(),
3681 identity_matrix,
[email protected]a2566412014-06-05 03:14:203682 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323683 gfx::PointF(),
3684 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573685 true,
[email protected]fb661802013-03-25 01:59:323686 false);
3687 SetLayerPropertiesForTesting(back_facing_surface.get(),
3688 backface_matrix,
[email protected]a2566412014-06-05 03:14:203689 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323690 gfx::PointF(),
3691 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573692 true,
[email protected]fb661802013-03-25 01:59:323693 false);
3694 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3695 identity_matrix,
[email protected]a2566412014-06-05 03:14:203696 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323697 gfx::PointF(),
3698 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573699 true,
[email protected]fb661802013-03-25 01:59:323700 false);
3701 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3702 backface_matrix,
[email protected]a2566412014-06-05 03:14:203703 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323704 gfx::PointF(),
3705 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573706 true,
[email protected]fb661802013-03-25 01:59:323707 false);
3708 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3709 identity_matrix,
[email protected]a2566412014-06-05 03:14:203710 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323711 gfx::PointF(),
3712 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573713 true,
[email protected]fb661802013-03-25 01:59:323714 false);
3715 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3716 backface_matrix,
[email protected]a2566412014-06-05 03:14:203717 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323718 gfx::PointF(),
3719 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573720 true,
[email protected]fb661802013-03-25 01:59:323721 false);
3722
[email protected]989386c2013-07-18 21:37:233723 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533724 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3725 parent.get(), parent->bounds(), &render_surface_layer_list);
3726 inputs.can_adjust_raster_scales = true;
3727 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323728
3729 // Verify which render surfaces were created.
3730 EXPECT_FALSE(front_facing_child->render_surface());
3731 EXPECT_FALSE(back_facing_child->render_surface());
3732 EXPECT_TRUE(front_facing_surface->render_surface());
3733 EXPECT_TRUE(back_facing_surface->render_surface());
3734 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3735 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3736 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3737 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3738
3739 // Verify the render_surface_layer_list.
3740 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233741 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3742 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323743 // Even though the back facing surface LAYER gets culled, the other
3744 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233745 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323746
3747 // Verify root surface's layer list.
3748 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233749 3u,
3750 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3751 EXPECT_EQ(front_facing_child->id(),
3752 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573753 ->render_surface()
3754 ->layer_list()
3755 .at(0)
3756 ->id());
[email protected]989386c2013-07-18 21:37:233757 EXPECT_EQ(front_facing_surface->id(),
3758 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573759 ->render_surface()
3760 ->layer_list()
3761 .at(1)
3762 ->id());
[email protected]989386c2013-07-18 21:37:233763 EXPECT_EQ(back_facing_surface->id(),
3764 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573765 ->render_surface()
3766 ->layer_list()
3767 .at(2)
3768 ->id());
[email protected]fb661802013-03-25 01:59:323769
3770 // Verify front_facing_surface's layer list.
3771 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233772 2u,
3773 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3774 EXPECT_EQ(front_facing_surface->id(),
3775 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573776 ->render_surface()
3777 ->layer_list()
3778 .at(0)
3779 ->id());
[email protected]989386c2013-07-18 21:37:233780 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3781 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573782 ->render_surface()
3783 ->layer_list()
3784 .at(1)
3785 ->id());
[email protected]fb661802013-03-25 01:59:323786
3787 // Verify back_facing_surface's layer list; its own layer should be culled
3788 // from the surface list.
3789 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233790 1u,
3791 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3792 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3793 render_surface_layer_list.at(2)
[email protected]56fffdd2014-02-11 19:50:573794 ->render_surface()
3795 ->layer_list()
3796 .at(0)
3797 ->id());
[email protected]fb661802013-03-25 01:59:323798}
3799
[email protected]989386c2013-07-18 21:37:233800TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323801 // Verify the behavior of back-face culling when preserves-3d transform style
3802 // is used.
3803
3804 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:443805 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:323806 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
loysoa6edaaff2015-05-25 03:26:443807 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323808 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
loysoa6edaaff2015-05-25 03:26:443809 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323810 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
loysoa6edaaff2015-05-25 03:26:443811 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323812 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
loysoa6edaaff2015-05-25 03:26:443813 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323814 scoped_refptr<LayerWithForcedDrawsContent>
loysoa6edaaff2015-05-25 03:26:443815 front_facing_child_of_front_facing_surface =
3816 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323817 scoped_refptr<LayerWithForcedDrawsContent>
loysoa6edaaff2015-05-25 03:26:443818 back_facing_child_of_front_facing_surface =
3819 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323820 scoped_refptr<LayerWithForcedDrawsContent>
loysoa6edaaff2015-05-25 03:26:443821 front_facing_child_of_back_facing_surface =
3822 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323823 scoped_refptr<LayerWithForcedDrawsContent>
loysoa6edaaff2015-05-25 03:26:443824 back_facing_child_of_back_facing_surface =
3825 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323826 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
loysoa6edaaff2015-05-25 03:26:443827 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323828 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
loysoa6edaaff2015-05-25 03:26:443829 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323830
3831 parent->AddChild(front_facing_child);
3832 parent->AddChild(back_facing_child);
3833 parent->AddChild(front_facing_surface);
3834 parent->AddChild(back_facing_surface);
3835 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3836 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3837 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3838 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3839
enne2097cab2014-09-25 20:16:313840 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283841 host->SetRootLayer(parent);
3842
[email protected]fb661802013-03-25 01:59:323843 // Nothing is double-sided
3844 front_facing_child->SetDoubleSided(false);
3845 back_facing_child->SetDoubleSided(false);
3846 front_facing_surface->SetDoubleSided(false);
3847 back_facing_surface->SetDoubleSided(false);
3848 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3849 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3850 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3851 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3852
3853 gfx::Transform backface_matrix;
3854 backface_matrix.Translate(50.0, 50.0);
3855 backface_matrix.RotateAboutYAxis(180.0);
3856 backface_matrix.Translate(-50.0, -50.0);
3857
3858 // Opacity will not force creation of render surfaces in this case because of
3859 // the preserve-3d transform style. Instead, an example of when a surface
3860 // would be created with preserve-3d is when there is a replica layer.
3861 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3862 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3863
3864 // Each surface creates its own new 3d rendering context (as defined by W3C
3865 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3866 // rendering context should use the transform with respect to that context.
3867 // This 3d rendering context occurs when (a) parent's transform style is flat
3868 // and (b) the layer's transform style is preserve-3d.
3869 SetLayerPropertiesForTesting(parent.get(),
3870 identity_matrix,
[email protected]a2566412014-06-05 03:14:203871 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323872 gfx::PointF(),
3873 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573874 true,
[email protected]fb661802013-03-25 01:59:323875 false); // parent transform style is flat.
3876 SetLayerPropertiesForTesting(front_facing_child.get(),
3877 identity_matrix,
[email protected]a2566412014-06-05 03:14:203878 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323879 gfx::PointF(),
3880 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573881 true,
[email protected]fb661802013-03-25 01:59:323882 false);
3883 SetLayerPropertiesForTesting(back_facing_child.get(),
3884 backface_matrix,
[email protected]a2566412014-06-05 03:14:203885 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323886 gfx::PointF(),
3887 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573888 true,
[email protected]fb661802013-03-25 01:59:323889 false);
[email protected]56fffdd2014-02-11 19:50:573890 // surface transform style is preserve-3d.
3891 SetLayerPropertiesForTesting(front_facing_surface.get(),
3892 identity_matrix,
[email protected]a2566412014-06-05 03:14:203893 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:573894 gfx::PointF(),
3895 gfx::Size(100, 100),
3896 false,
3897 true);
3898 // surface transform style is preserve-3d.
3899 SetLayerPropertiesForTesting(back_facing_surface.get(),
3900 backface_matrix,
[email protected]a2566412014-06-05 03:14:203901 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:573902 gfx::PointF(),
3903 gfx::Size(100, 100),
3904 false,
3905 true);
[email protected]fb661802013-03-25 01:59:323906 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3907 identity_matrix,
[email protected]a2566412014-06-05 03:14:203908 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323909 gfx::PointF(),
3910 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573911 true,
3912 true);
[email protected]fb661802013-03-25 01:59:323913 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3914 backface_matrix,
[email protected]a2566412014-06-05 03:14:203915 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323916 gfx::PointF(),
3917 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573918 true,
3919 true);
[email protected]fb661802013-03-25 01:59:323920 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3921 identity_matrix,
[email protected]a2566412014-06-05 03:14:203922 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323923 gfx::PointF(),
3924 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573925 true,
3926 true);
[email protected]fb661802013-03-25 01:59:323927 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3928 backface_matrix,
[email protected]a2566412014-06-05 03:14:203929 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323930 gfx::PointF(),
3931 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573932 true,
3933 true);
[email protected]fb661802013-03-25 01:59:323934
[email protected]989386c2013-07-18 21:37:233935 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533936 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3937 parent.get(), parent->bounds(), &render_surface_layer_list);
3938 inputs.can_adjust_raster_scales = true;
3939 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323940
awoloszyne83f28c2014-12-22 15:40:003941 // Verify which render surfaces were created and used.
[email protected]fb661802013-03-25 01:59:323942 EXPECT_FALSE(front_facing_child->render_surface());
3943 EXPECT_FALSE(back_facing_child->render_surface());
3944 EXPECT_TRUE(front_facing_surface->render_surface());
awoloszyne83f28c2014-12-22 15:40:003945 EXPECT_NE(back_facing_surface->render_target(), back_facing_surface);
3946 // We expect that a render_surface was created but not used.
3947 EXPECT_TRUE(back_facing_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323948 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3949 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3950 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3951 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3952
3953 // Verify the render_surface_layer_list. The back-facing surface should be
3954 // culled.
3955 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233956 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3957 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323958
3959 // Verify root surface's layer list.
3960 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233961 2u,
3962 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3963 EXPECT_EQ(front_facing_child->id(),
3964 render_surface_layer_list.at(0)
3965 ->render_surface()->layer_list().at(0)->id());
3966 EXPECT_EQ(front_facing_surface->id(),
3967 render_surface_layer_list.at(0)
3968 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323969
3970 // Verify front_facing_surface's layer list.
3971 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233972 2u,
3973 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3974 EXPECT_EQ(front_facing_surface->id(),
3975 render_surface_layer_list.at(1)
3976 ->render_surface()->layer_list().at(0)->id());
3977 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3978 render_surface_layer_list.at(1)
3979 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323980}
3981
[email protected]989386c2013-07-18 21:37:233982TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:323983 // Verify that layers are appropriately culled when their back face is showing
3984 // and they are not double sided, while animations are going on.
3985 //
3986 // Layers that are animating do not get culled on the main thread, as their
3987 // transforms should be treated as "unknown" so we can not be sure that their
3988 // back face is really showing.
3989 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:443990 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:323991 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:443992 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323993 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
loysoa6edaaff2015-05-25 03:26:443994 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323995 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
loysoa6edaaff2015-05-25 03:26:443996 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323997 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
loysoa6edaaff2015-05-25 03:26:443998 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:323999 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loysoa6edaaff2015-05-25 03:26:444000 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324001
4002 parent->AddChild(child);
4003 parent->AddChild(animating_surface);
4004 animating_surface->AddChild(child_of_animating_surface);
4005 parent->AddChild(animating_child);
4006 parent->AddChild(child2);
4007
enne2097cab2014-09-25 20:16:314008 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284009 host->SetRootLayer(parent);
4010
[email protected]fb661802013-03-25 01:59:324011 // Nothing is double-sided
4012 child->SetDoubleSided(false);
4013 child2->SetDoubleSided(false);
4014 animating_surface->SetDoubleSided(false);
4015 child_of_animating_surface->SetDoubleSided(false);
4016 animating_child->SetDoubleSided(false);
4017
4018 gfx::Transform backface_matrix;
4019 backface_matrix.Translate(50.0, 50.0);
4020 backface_matrix.RotateAboutYAxis(180.0);
4021 backface_matrix.Translate(-50.0, -50.0);
4022
4023 // Make our render surface.
4024 animating_surface->SetForceRenderSurface(true);
4025
4026 // Animate the transform on the render surface.
4027 AddAnimatedTransformToController(
4028 animating_surface->layer_animation_controller(), 10.0, 30, 0);
4029 // This is just an animating layer, not a surface.
4030 AddAnimatedTransformToController(
4031 animating_child->layer_animation_controller(), 10.0, 30, 0);
4032
4033 SetLayerPropertiesForTesting(parent.get(),
4034 identity_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(child.get(),
4041 backface_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(animating_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(child_of_animating_surface.get(),
4055 backface_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(animating_child.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 SetLayerPropertiesForTesting(child2.get(),
4069 identity_matrix,
[email protected]a2566412014-06-05 03:14:204070 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324071 gfx::PointF(),
4072 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574073 true,
[email protected]fb661802013-03-25 01:59:324074 false);
4075
[email protected]989386c2013-07-18 21:37:234076 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534077 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4078 parent.get(), parent->bounds(), &render_surface_layer_list);
4079 inputs.can_adjust_raster_scales = true;
4080 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324081
4082 EXPECT_FALSE(child->render_surface());
4083 EXPECT_TRUE(animating_surface->render_surface());
4084 EXPECT_FALSE(child_of_animating_surface->render_surface());
4085 EXPECT_FALSE(animating_child->render_surface());
4086 EXPECT_FALSE(child2->render_surface());
4087
4088 // Verify that the animating_child and child_of_animating_surface were not
4089 // culled, but that child was.
4090 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234091 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4092 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324093
4094 // The non-animating child be culled from the layer list for the parent render
4095 // surface.
4096 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234097 3u,
4098 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4099 EXPECT_EQ(animating_surface->id(),
4100 render_surface_layer_list.at(0)
4101 ->render_surface()->layer_list().at(0)->id());
4102 EXPECT_EQ(animating_child->id(),
4103 render_surface_layer_list.at(0)
4104 ->render_surface()->layer_list().at(1)->id());
4105 EXPECT_EQ(child2->id(),
4106 render_surface_layer_list.at(0)
4107 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:324108
4109 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234110 2u,
4111 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4112 EXPECT_EQ(animating_surface->id(),
4113 render_surface_layer_list.at(1)
4114 ->render_surface()->layer_list().at(0)->id());
4115 EXPECT_EQ(child_of_animating_surface->id(),
4116 render_surface_layer_list.at(1)
4117 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324118
4119 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
4120
4121 // The animating layers should have a visible content rect that represents the
4122 // area of the front face that is within the viewport.
4123 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054124 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:324125 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054126 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324127 // And layers in the subtree of the animating layer should have valid visible
4128 // content rects also.
[email protected]989386c2013-07-18 21:37:234129 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
4130 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324131}
4132
[email protected]989386c2013-07-18 21:37:234133TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324134 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4135 // Verify the behavior of back-face culling for a render surface that is
4136 // created when it flattens its subtree, and its parent has preserves-3d.
4137
4138 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:444139 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:324140 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
loysoa6edaaff2015-05-25 03:26:444141 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324142 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
loysoa6edaaff2015-05-25 03:26:444143 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324144 scoped_refptr<LayerWithForcedDrawsContent> child1 =
loysoa6edaaff2015-05-25 03:26:444145 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324146 scoped_refptr<LayerWithForcedDrawsContent> child2 =
loysoa6edaaff2015-05-25 03:26:444147 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]fb661802013-03-25 01:59:324148
4149 parent->AddChild(front_facing_surface);
4150 parent->AddChild(back_facing_surface);
4151 front_facing_surface->AddChild(child1);
4152 back_facing_surface->AddChild(child2);
4153
enne2097cab2014-09-25 20:16:314154 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284155 host->SetRootLayer(parent);
4156
[email protected]fb661802013-03-25 01:59:324157 // RenderSurfaces are not double-sided
4158 front_facing_surface->SetDoubleSided(false);
4159 back_facing_surface->SetDoubleSided(false);
4160
4161 gfx::Transform backface_matrix;
4162 backface_matrix.Translate(50.0, 50.0);
4163 backface_matrix.RotateAboutYAxis(180.0);
4164 backface_matrix.Translate(-50.0, -50.0);
4165
4166 SetLayerPropertiesForTesting(parent.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 false,
4172 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:324173 SetLayerPropertiesForTesting(front_facing_surface.get(),
4174 identity_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,
4179 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324180 SetLayerPropertiesForTesting(back_facing_surface.get(),
4181 backface_matrix,
[email protected]a2566412014-06-05 03:14:204182 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324183 gfx::PointF(),
4184 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574185 true,
4186 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324187 SetLayerPropertiesForTesting(child1.get(),
4188 identity_matrix,
[email protected]a2566412014-06-05 03:14:204189 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324190 gfx::PointF(),
4191 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574192 true,
[email protected]fb661802013-03-25 01:59:324193 false);
4194 SetLayerPropertiesForTesting(child2.get(),
4195 identity_matrix,
[email protected]a2566412014-06-05 03:14:204196 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324197 gfx::PointF(),
4198 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574199 true,
[email protected]fb661802013-03-25 01:59:324200 false);
4201
[email protected]a9d4d4f2014-06-19 06:49:284202 front_facing_surface->Set3dSortingContextId(1);
4203 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574204
[email protected]989386c2013-07-18 21:37:234205 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534206 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4207 parent.get(), parent->bounds(), &render_surface_layer_list);
4208 inputs.can_adjust_raster_scales = true;
4209 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324210
awoloszyne83f28c2014-12-22 15:40:004211 // Verify which render surfaces were created and used.
[email protected]fb661802013-03-25 01:59:324212 EXPECT_TRUE(front_facing_surface->render_surface());
awoloszyne83f28c2014-12-22 15:40:004213
4214 // We expect the render surface to have been created, but remain unused.
4215 EXPECT_TRUE(back_facing_surface->render_surface());
4216 EXPECT_NE(back_facing_surface->render_target(),
4217 back_facing_surface); // because it should be culled
[email protected]fb661802013-03-25 01:59:324218 EXPECT_FALSE(child1->render_surface());
4219 EXPECT_FALSE(child2->render_surface());
4220
4221 // Verify the render_surface_layer_list. The back-facing surface should be
4222 // culled.
4223 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234224 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4225 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324226
4227 // Verify root surface's layer list.
4228 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234229 1u,
4230 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4231 EXPECT_EQ(front_facing_surface->id(),
4232 render_surface_layer_list.at(0)
4233 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324234
4235 // Verify front_facing_surface's layer list.
4236 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234237 2u,
4238 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4239 EXPECT_EQ(front_facing_surface->id(),
4240 render_surface_layer_list.at(1)
4241 ->render_surface()->layer_list().at(0)->id());
4242 EXPECT_EQ(child1->id(),
4243 render_surface_layer_list.at(1)
4244 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324245}
4246
[email protected]fb661802013-03-25 01:59:324247class NoScaleContentLayer : public ContentLayer {
4248 public:
loysoa6edaaff2015-05-25 03:26:444249 static scoped_refptr<NoScaleContentLayer> Create(
4250 const LayerSettings& settings,
4251 ContentLayerClient* client) {
4252 return make_scoped_refptr(new NoScaleContentLayer(settings, client));
[email protected]fb661802013-03-25 01:59:324253 }
[email protected]94f206c12012-08-25 00:09:144254
dcheng716bedf2014-10-21 09:51:084255 void CalculateContentsScale(float ideal_contents_scale,
4256 float* contents_scale_x,
4257 float* contents_scale_y,
4258 gfx::Size* content_bounds) override {
[email protected]fb661802013-03-25 01:59:324259 // Skip over the ContentLayer to the base Layer class.
4260 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]fb661802013-03-25 01:59:324261 contents_scale_x,
4262 contents_scale_y,
4263 content_bounds);
4264 }
[email protected]94f206c12012-08-25 00:09:144265
[email protected]fb661802013-03-25 01:59:324266 protected:
loysoa6edaaff2015-05-25 03:26:444267 NoScaleContentLayer(const LayerSettings& settings, ContentLayerClient* client)
4268 : ContentLayer(settings, client) {}
dcheng716bedf2014-10-21 09:51:084269 ~NoScaleContentLayer() override {}
[email protected]518ee582012-10-24 18:29:444270};
4271
[email protected]fb661802013-03-25 01:59:324272scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
loysoa6edaaff2015-05-25 03:26:444273 const LayerSettings& settings,
[email protected]fb661802013-03-25 01:59:324274 ContentLayerClient* delegate) {
4275 scoped_refptr<NoScaleContentLayer> to_return =
loysoa6edaaff2015-05-25 03:26:444276 NoScaleContentLayer::Create(settings, delegate);
[email protected]fb661802013-03-25 01:59:324277 to_return->SetIsDrawable(true);
4278 return to_return;
[email protected]518ee582012-10-24 18:29:444279}
4280
[email protected]989386c2013-07-18 21:37:234281TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324282 // Verify draw and screen space transforms of layers not in a surface.
4283 MockContentLayerClient delegate;
4284 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:144285
sohan.jyotie3bd6192014-10-13 07:13:594286 scoped_refptr<FakePictureLayer> parent =
loysoa6edaaff2015-05-25 03:26:444287 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324288 SetLayerPropertiesForTesting(parent.get(),
4289 identity_matrix,
[email protected]a2566412014-06-05 03:14:204290 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324291 gfx::PointF(),
4292 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574293 false,
[email protected]fb661802013-03-25 01:59:324294 true);
[email protected]94f206c12012-08-25 00:09:144295
loysoa6edaaff2015-05-25 03:26:444296 scoped_refptr<FakePictureLayer> child =
4297 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324298 SetLayerPropertiesForTesting(child.get(),
4299 identity_matrix,
[email protected]a2566412014-06-05 03:14:204300 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324301 gfx::PointF(2.f, 2.f),
4302 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574303 false,
[email protected]fb661802013-03-25 01:59:324304 true);
[email protected]94f206c12012-08-25 00:09:144305
sohan.jyotie3bd6192014-10-13 07:13:594306 scoped_refptr<FakePictureLayer> child_empty =
loysoa6edaaff2015-05-25 03:26:444307 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324308 SetLayerPropertiesForTesting(child_empty.get(),
4309 identity_matrix,
[email protected]a2566412014-06-05 03:14:204310 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324311 gfx::PointF(2.f, 2.f),
4312 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574313 false,
[email protected]fb661802013-03-25 01:59:324314 true);
[email protected]f89f5632012-11-14 23:34:454315
[email protected]fb661802013-03-25 01:59:324316 parent->AddChild(child);
4317 parent->AddChild(child_empty);
[email protected]94f206c12012-08-25 00:09:144318
enne2097cab2014-09-25 20:16:314319 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284320 host->SetRootLayer(parent);
4321
[email protected]fb661802013-03-25 01:59:324322 float device_scale_factor = 2.5f;
4323 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:144324
[email protected]7aad55f2013-07-26 11:25:534325 RenderSurfaceLayerList render_surface_layer_list;
4326 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4327 parent.get(), parent->bounds(), &render_surface_layer_list);
4328 inputs.device_scale_factor = device_scale_factor;
4329 inputs.page_scale_factor = page_scale_factor;
4330 inputs.can_adjust_raster_scales = true;
4331 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:444332
sohan.jyotie3bd6192014-10-13 07:13:594333 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4334 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child);
4335 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child_empty);
[email protected]94f206c12012-08-25 00:09:144336
[email protected]fb661802013-03-25 01:59:324337 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:144338
[email protected]fb661802013-03-25 01:59:324339 // Verify parent transforms
4340 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594341 expected_parent_transform.Scale(device_scale_factor * page_scale_factor,
4342 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324343 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4344 parent->screen_space_transform());
4345 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4346 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:144347
[email protected]fb661802013-03-25 01:59:324348 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:054349 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:144350
[email protected]fb661802013-03-25 01:59:324351 gfx::RectF parent_draw_rect =
4352 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
4353 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
4354 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:144355
[email protected]2c7c6702013-03-26 03:14:054356 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:324357 expected_parent_draw_rect.Scale(device_scale_factor);
4358 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4359 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144360
[email protected]fb661802013-03-25 01:59:324361 // Verify child and child_empty transforms. They should match.
4362 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594363 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4364 expected_child_transform.Translate(child->position().x(),
4365 child->position().y());
[email protected]fb661802013-03-25 01:59:324366 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4367 child->draw_transform());
4368 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4369 child->screen_space_transform());
4370 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4371 child_empty->draw_transform());
4372 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4373 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144374
[email protected]fb661802013-03-25 01:59:324375 // Verify results of transformed child and child_empty rects. They should
4376 // match.
[email protected]2c7c6702013-03-26 03:14:054377 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:144378
[email protected]fb661802013-03-25 01:59:324379 gfx::RectF child_draw_rect =
4380 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
4381 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
4382 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:144383
[email protected]fb661802013-03-25 01:59:324384 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
4385 child_empty->draw_transform(), child_content_bounds);
4386 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
4387 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:454388
[email protected]fb661802013-03-25 01:59:324389 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
4390 expected_child_draw_rect.Scale(device_scale_factor);
4391 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4392 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
4393 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
4394 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144395}
4396
[email protected]989386c2013-07-18 21:37:234397TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324398 // Verify draw and screen space transforms of layers in a surface.
4399 MockContentLayerClient delegate;
4400 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:094401
[email protected]fb661802013-03-25 01:59:324402 gfx::Transform perspective_matrix;
4403 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094404
[email protected]fb661802013-03-25 01:59:324405 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054406 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094407
loysoa6edaaff2015-05-25 03:26:444408 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]9781afa2013-07-17 23:15:324409
sohan.jyotie3bd6192014-10-13 07:13:594410 scoped_refptr<FakePictureLayer> parent =
loysoa6edaaff2015-05-25 03:26:444411 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324412 SetLayerPropertiesForTesting(parent.get(),
4413 identity_matrix,
[email protected]a2566412014-06-05 03:14:204414 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324415 gfx::PointF(),
4416 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574417 false,
[email protected]fb661802013-03-25 01:59:324418 true);
[email protected]1b30e8e2012-12-21 02:59:094419
sohan.jyotie3bd6192014-10-13 07:13:594420 scoped_refptr<FakePictureLayer> perspective_surface =
loysoa6edaaff2015-05-25 03:26:444421 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324422 SetLayerPropertiesForTesting(perspective_surface.get(),
4423 perspective_matrix * scale_small_matrix,
[email protected]a2566412014-06-05 03:14:204424 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324425 gfx::PointF(2.f, 2.f),
4426 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574427 false,
[email protected]fb661802013-03-25 01:59:324428 true);
[email protected]1b30e8e2012-12-21 02:59:094429
sohan.jyotie3bd6192014-10-13 07:13:594430 scoped_refptr<FakePictureLayer> scale_surface =
loysoa6edaaff2015-05-25 03:26:444431 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324432 SetLayerPropertiesForTesting(scale_surface.get(),
4433 scale_small_matrix,
[email protected]a2566412014-06-05 03:14:204434 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324435 gfx::PointF(2.f, 2.f),
4436 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574437 false,
[email protected]fb661802013-03-25 01:59:324438 true);
[email protected]1b30e8e2012-12-21 02:59:094439
[email protected]fb661802013-03-25 01:59:324440 perspective_surface->SetForceRenderSurface(true);
4441 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:094442
[email protected]fb661802013-03-25 01:59:324443 parent->AddChild(perspective_surface);
4444 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:324445 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:094446
enne2097cab2014-09-25 20:16:314447 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284448 host->SetRootLayer(root);
4449
[email protected]fb661802013-03-25 01:59:324450 float device_scale_factor = 2.5f;
4451 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:094452
[email protected]7aad55f2013-07-26 11:25:534453 RenderSurfaceLayerList render_surface_layer_list;
4454 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4455 root.get(), parent->bounds(), &render_surface_layer_list);
4456 inputs.device_scale_factor = device_scale_factor;
4457 inputs.page_scale_factor = page_scale_factor;
enne6394d5b42015-05-26 22:23:114458 inputs.page_scale_layer = root.get();
[email protected]7aad55f2013-07-26 11:25:534459 inputs.can_adjust_raster_scales = true;
4460 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:094461
sohan.jyotie3bd6192014-10-13 07:13:594462 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4463 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
4464 perspective_surface);
4465 // Ideal scale is the max 2d scale component of the combined transform up to
4466 // the nearest render target. Here this includes the layer transform as well
4467 // as the device and page scale factors.
4468 gfx::Transform transform = scale_small_matrix;
4469 transform.Scale(device_scale_factor * page_scale_factor,
4470 device_scale_factor * page_scale_factor);
4471 gfx::Vector2dF scales =
4472 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4473 float max_2d_scale = std::max(scales.x(), scales.y());
4474 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
4475
4476 // The ideal scale will draw 1:1 with its render target space along
4477 // the larger-scale axis.
4478 gfx::Vector2dF target_space_transform_scales =
4479 MathUtil::ComputeTransform2dScaleComponents(
4480 scale_surface->draw_properties().target_space_transform, 0.f);
4481 EXPECT_FLOAT_EQ(max_2d_scale,
4482 std::max(target_space_transform_scales.x(),
4483 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094484
[email protected]fb661802013-03-25 01:59:324485 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:094486
[email protected]fb661802013-03-25 01:59:324487 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594488 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4489 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324490 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
4491 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094492
[email protected]fb661802013-03-25 01:59:324493 // The scale for the perspective surface is not known, so it is rendered 1:1
4494 // with the screen, and then scaled during drawing.
4495 gfx::Transform expected_perspective_surface_draw_transform;
4496 expected_perspective_surface_draw_transform.Translate(
4497 device_scale_factor * page_scale_factor *
4498 perspective_surface->position().x(),
4499 device_scale_factor * page_scale_factor *
4500 perspective_surface->position().y());
4501 expected_perspective_surface_draw_transform.PreconcatTransform(
4502 perspective_matrix);
4503 expected_perspective_surface_draw_transform.PreconcatTransform(
4504 scale_small_matrix);
4505 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594506 expected_perspective_surface_layer_draw_transform.Scale(
4507 device_scale_factor * page_scale_factor,
4508 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324509 EXPECT_TRANSFORMATION_MATRIX_EQ(
4510 expected_perspective_surface_draw_transform,
4511 perspective_surface->render_surface()->draw_transform());
4512 EXPECT_TRANSFORMATION_MATRIX_EQ(
4513 expected_perspective_surface_layer_draw_transform,
4514 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094515}
4516
sohan.jyotie3bd6192014-10-13 07:13:594517// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234518TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324519 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
4520 // Verify draw and screen space transforms of layers not in a surface.
4521 MockContentLayerClient delegate;
4522 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:474523
loysoa6edaaff2015-05-25 03:26:444524 scoped_refptr<ContentLayer> parent =
4525 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324526 SetLayerPropertiesForTesting(parent.get(),
4527 identity_matrix,
[email protected]a2566412014-06-05 03:14:204528 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324529 gfx::PointF(),
4530 gfx::Size(133, 133),
[email protected]56fffdd2014-02-11 19:50:574531 false,
[email protected]fb661802013-03-25 01:59:324532 true);
[email protected]904e9132012-11-01 00:12:474533
loysoa6edaaff2015-05-25 03:26:444534 scoped_refptr<ContentLayer> child =
4535 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324536 SetLayerPropertiesForTesting(child.get(),
4537 identity_matrix,
[email protected]a2566412014-06-05 03:14:204538 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324539 gfx::PointF(),
4540 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:574541 false,
[email protected]fb661802013-03-25 01:59:324542 true);
[email protected]904e9132012-11-01 00:12:474543
[email protected]fb661802013-03-25 01:59:324544 scoped_refptr<NoScaleContentLayer> child_no_scale =
loysoa6edaaff2015-05-25 03:26:444545 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324546 SetLayerPropertiesForTesting(child_no_scale.get(),
4547 identity_matrix,
[email protected]a2566412014-06-05 03:14:204548 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324549 gfx::PointF(),
4550 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:574551 false,
[email protected]fb661802013-03-25 01:59:324552 true);
[email protected]904e9132012-11-01 00:12:474553
[email protected]fb661802013-03-25 01:59:324554 parent->AddChild(child);
4555 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:474556
enne2097cab2014-09-25 20:16:314557 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284558 host->SetRootLayer(parent);
4559
[email protected]fb661802013-03-25 01:59:324560 float device_scale_factor = 1.7f;
4561 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:474562
[email protected]7aad55f2013-07-26 11:25:534563 RenderSurfaceLayerList render_surface_layer_list;
4564 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4565 parent.get(), parent->bounds(), &render_surface_layer_list);
4566 inputs.device_scale_factor = device_scale_factor;
4567 inputs.page_scale_factor = page_scale_factor;
enne6394d5b42015-05-26 22:23:114568 inputs.page_scale_layer = parent.get();
[email protected]7aad55f2013-07-26 11:25:534569 inputs.can_adjust_raster_scales = true;
enne432edd02015-05-11 18:38:334570 inputs.verify_property_trees = false;
[email protected]7aad55f2013-07-26 11:25:534571 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:474572
[email protected]fb661802013-03-25 01:59:324573 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4574 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
4575 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:474576
[email protected]fb661802013-03-25 01:59:324577 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:474578
[email protected]fb661802013-03-25 01:59:324579 // Verify parent transforms
4580 gfx::Transform expected_parent_transform;
4581 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4582 parent->screen_space_transform());
4583 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4584 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:474585
[email protected]fb661802013-03-25 01:59:324586 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:054587 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:474588
[email protected]fb661802013-03-25 01:59:324589 gfx::RectF parent_draw_rect =
4590 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
4591 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
4592 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:474593
[email protected]2c7c6702013-03-26 03:14:054594 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:324595 expected_parent_draw_rect.Scale(device_scale_factor);
4596 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
4597 expected_parent_draw_rect.set_height(
4598 ceil(expected_parent_draw_rect.height()));
4599 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4600 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:474601
[email protected]fb661802013-03-25 01:59:324602 // Verify child transforms
4603 gfx::Transform expected_child_transform;
4604 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4605 child->draw_transform());
4606 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4607 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474608
[email protected]fb661802013-03-25 01:59:324609 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:054610 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:474611
[email protected]fb661802013-03-25 01:59:324612 gfx::RectF child_draw_rect =
4613 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
4614 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
4615 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:474616
[email protected]2c7c6702013-03-26 03:14:054617 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:324618 expected_child_draw_rect.Scale(device_scale_factor);
4619 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
4620 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
4621 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4622 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:474623
[email protected]fb661802013-03-25 01:59:324624 // Verify child_no_scale transforms
4625 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
4626 // All transforms operate on content rects. The child's content rect
4627 // incorporates device scale, but the child_no_scale does not; add it here.
4628 expected_child_no_scale_transform.Scale(device_scale_factor,
4629 device_scale_factor);
4630 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4631 child_no_scale->draw_transform());
4632 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4633 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474634}
4635
sohan.jyotie3bd6192014-10-13 07:13:594636// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234637TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:324638 MockContentLayerClient delegate;
4639 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:444640
[email protected]fb661802013-03-25 01:59:324641 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264642 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324643 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:444644
[email protected]fb661802013-03-25 01:59:324645 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264646 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324647 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:444648
loysoa6edaaff2015-05-25 03:26:444649 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]35a99a12013-05-09 23:52:294650 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:444651
loysoa6edaaff2015-05-25 03:26:444652 scoped_refptr<ContentLayer> parent =
4653 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324654 SetLayerPropertiesForTesting(parent.get(),
4655 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204656 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324657 gfx::PointF(),
4658 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574659 false,
[email protected]fb661802013-03-25 01:59:324660 true);
[email protected]518ee582012-10-24 18:29:444661
[email protected]fb661802013-03-25 01:59:324662 scoped_refptr<ContentLayer> child_scale =
loysoa6edaaff2015-05-25 03:26:444663 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324664 SetLayerPropertiesForTesting(child_scale.get(),
4665 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204666 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324667 gfx::PointF(2.f, 2.f),
4668 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574669 false,
[email protected]fb661802013-03-25 01:59:324670 true);
[email protected]518ee582012-10-24 18:29:444671
[email protected]fb661802013-03-25 01:59:324672 scoped_refptr<ContentLayer> child_empty =
loysoa6edaaff2015-05-25 03:26:444673 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324674 SetLayerPropertiesForTesting(child_empty.get(),
4675 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204676 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324677 gfx::PointF(2.f, 2.f),
4678 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574679 false,
[email protected]fb661802013-03-25 01:59:324680 true);
[email protected]f89f5632012-11-14 23:34:454681
[email protected]fb661802013-03-25 01:59:324682 scoped_refptr<NoScaleContentLayer> child_no_scale =
loysoa6edaaff2015-05-25 03:26:444683 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324684 SetLayerPropertiesForTesting(child_no_scale.get(),
4685 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204686 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324687 gfx::PointF(12.f, 12.f),
4688 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574689 false,
[email protected]fb661802013-03-25 01:59:324690 true);
[email protected]518ee582012-10-24 18:29:444691
[email protected]35a99a12013-05-09 23:52:294692 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:444693
[email protected]fb661802013-03-25 01:59:324694 parent->AddChild(child_scale);
4695 parent->AddChild(child_empty);
4696 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:444697
enne2097cab2014-09-25 20:16:314698 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284699 host->SetRootLayer(root);
4700
[email protected]fb661802013-03-25 01:59:324701 float device_scale_factor = 2.5f;
4702 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:444703
[email protected]989386c2013-07-18 21:37:234704 {
4705 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534706 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224707 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534708 inputs.device_scale_factor = device_scale_factor;
4709 inputs.page_scale_factor = page_scale_factor;
enne6394d5b42015-05-26 22:23:114710 inputs.page_scale_layer = root.get();
[email protected]7aad55f2013-07-26 11:25:534711 inputs.can_adjust_raster_scales = true;
enne432edd02015-05-11 18:38:334712 inputs.verify_property_trees = false;
[email protected]7aad55f2013-07-26 11:25:534713 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:444714
[email protected]989386c2013-07-18 21:37:234715 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4716 initial_parent_scale, parent);
4717 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4718 initial_parent_scale * initial_child_scale,
4719 child_scale);
4720 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4721 initial_parent_scale * initial_child_scale,
4722 child_empty);
4723 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:444724
[email protected]989386c2013-07-18 21:37:234725 // The parent is scaled up and shouldn't need to scale during draw. The
4726 // child that can scale its contents should also not need to scale during
4727 // draw. This shouldn't change if the child has empty bounds. The other
4728 // children should.
[email protected]803f6b52013-09-12 00:51:264729 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
4730 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
4731 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
4732 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
4733 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
4734 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:234735 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
4736 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264737 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]989386c2013-07-18 21:37:234738 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264739 initial_parent_scale * initial_child_scale,
4740 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:234741 }
[email protected]518ee582012-10-24 18:29:444742
[email protected]fb661802013-03-25 01:59:324743 // If the device_scale_factor or page_scale_factor changes, then it should be
4744 // updated using the initial transform as the raster scale.
4745 device_scale_factor = 2.25f;
4746 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:444747
[email protected]989386c2013-07-18 21:37:234748 {
4749 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534750 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224751 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534752 inputs.device_scale_factor = device_scale_factor;
4753 inputs.page_scale_factor = page_scale_factor;
enne6394d5b42015-05-26 22:23:114754 inputs.page_scale_layer = root.get();
[email protected]7aad55f2013-07-26 11:25:534755 inputs.can_adjust_raster_scales = true;
enne432edd02015-05-11 18:38:334756 inputs.verify_property_trees = false;
[email protected]7aad55f2013-07-26 11:25:534757 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4758
4759 EXPECT_CONTENTS_SCALE_EQ(
4760 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:234761 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:534762 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:234763 child_scale);
4764 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4765 initial_parent_scale * initial_child_scale,
4766 child_empty);
4767 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4768 }
[email protected]d0518202013-02-08 02:06:494769
[email protected]fb661802013-03-25 01:59:324770 // If the transform changes, we expect the raster scale to be reset to 1.0.
[email protected]803f6b52013-09-12 00:51:264771 SkMScalar second_child_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324772 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
4773 second_child_scale / initial_child_scale);
4774 child_scale->SetTransform(child_scale_matrix);
4775 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:494776
[email protected]989386c2013-07-18 21:37:234777 {
4778 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534779 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224780 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534781 inputs.device_scale_factor = device_scale_factor;
4782 inputs.page_scale_factor = page_scale_factor;
enne6394d5b42015-05-26 22:23:114783 inputs.page_scale_layer = root.get();
[email protected]7aad55f2013-07-26 11:25:534784 inputs.can_adjust_raster_scales = true;
enne432edd02015-05-11 18:38:334785 inputs.verify_property_trees = false;
[email protected]7aad55f2013-07-26 11:25:534786 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:494787
[email protected]989386c2013-07-18 21:37:234788 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4789 initial_parent_scale,
4790 parent);
4791 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4792 child_scale);
4793 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4794 child_empty);
4795 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4796 }
[email protected]d0518202013-02-08 02:06:494797
[email protected]fb661802013-03-25 01:59:324798 // If the device_scale_factor or page_scale_factor changes, then it should be
4799 // updated, but still using 1.0 as the raster scale.
4800 device_scale_factor = 2.75f;
4801 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:494802
[email protected]989386c2013-07-18 21:37:234803 {
4804 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534805 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224806 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534807 inputs.device_scale_factor = device_scale_factor;
4808 inputs.page_scale_factor = page_scale_factor;
enne6394d5b42015-05-26 22:23:114809 inputs.page_scale_layer = root.get();
[email protected]7aad55f2013-07-26 11:25:534810 inputs.can_adjust_raster_scales = true;
enne432edd02015-05-11 18:38:334811 inputs.verify_property_trees = false;
[email protected]7aad55f2013-07-26 11:25:534812 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:494813
[email protected]989386c2013-07-18 21:37:234814 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4815 initial_parent_scale,
4816 parent);
4817 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4818 child_scale);
4819 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4820 child_empty);
4821 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4822 }
[email protected]518ee582012-10-24 18:29:444823}
4824
sohan.jyotie3bd6192014-10-13 07:13:594825// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234826TEST_F(LayerTreeHostCommonTest,
sohan.jyotie3bd6192014-10-13 07:13:594827 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:324828 MockContentLayerClient delegate;
4829 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:214830
[email protected]fb661802013-03-25 01:59:324831 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264832 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324833 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:214834
[email protected]fb661802013-03-25 01:59:324835 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264836 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324837 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:214838
loysoa6edaaff2015-05-25 03:26:444839 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]35a99a12013-05-09 23:52:294840 root->SetBounds(gfx::Size(100, 100));
4841
loysoa6edaaff2015-05-25 03:26:444842 scoped_refptr<ContentLayer> parent =
4843 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324844 SetLayerPropertiesForTesting(parent.get(),
4845 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204846 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324847 gfx::PointF(),
4848 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574849 false,
[email protected]fb661802013-03-25 01:59:324850 true);
[email protected]11ec92972012-11-10 03:06:214851
[email protected]fb661802013-03-25 01:59:324852 scoped_refptr<ContentLayer> child_scale =
loysoa6edaaff2015-05-25 03:26:444853 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:324854 SetLayerPropertiesForTesting(child_scale.get(),
4855 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204856 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324857 gfx::PointF(2.f, 2.f),
4858 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574859 false,
[email protected]fb661802013-03-25 01:59:324860 true);
[email protected]11ec92972012-11-10 03:06:214861
[email protected]35a99a12013-05-09 23:52:294862 scoped_refptr<ContentLayer> child_empty =
loysoa6edaaff2015-05-25 03:26:444863 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]35a99a12013-05-09 23:52:294864 SetLayerPropertiesForTesting(child_empty.get(),
4865 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204866 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294867 gfx::PointF(2.f, 2.f),
4868 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574869 false,
[email protected]35a99a12013-05-09 23:52:294870 true);
4871
4872 scoped_refptr<NoScaleContentLayer> child_no_scale =
loysoa6edaaff2015-05-25 03:26:444873 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate);
[email protected]35a99a12013-05-09 23:52:294874 SetLayerPropertiesForTesting(child_no_scale.get(),
4875 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204876 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294877 gfx::PointF(12.f, 12.f),
4878 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574879 false,
[email protected]35a99a12013-05-09 23:52:294880 true);
4881
4882 root->AddChild(parent);
4883
4884 parent->AddChild(child_scale);
4885 parent->AddChild(child_empty);
4886 parent->AddChild(child_no_scale);
4887
enne2097cab2014-09-25 20:16:314888 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284889 host->SetRootLayer(root);
4890
[email protected]989386c2013-07-18 21:37:234891 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:294892
4893 float device_scale_factor = 2.5f;
4894 float page_scale_factor = 1.f;
4895
[email protected]7aad55f2013-07-26 11:25:534896 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224897 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534898 inputs.device_scale_factor = device_scale_factor;
4899 inputs.page_scale_factor = page_scale_factor;
enne6394d5b42015-05-26 22:23:114900 inputs.page_scale_layer = root.get();
enne432edd02015-05-11 18:38:334901 inputs.verify_property_trees = false;
[email protected]7aad55f2013-07-26 11:25:534902 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:294903
4904 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4905 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4906 child_scale);
4907 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4908 child_empty);
4909 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4910
4911 // Since the transform scale does not affect contents scale, it should affect
4912 // the draw transform instead.
4913 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:264914 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294915 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:264916 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294917 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264918 child_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294919 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264920 child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294921 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264922 child_empty->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294923 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264924 child_empty->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294925 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264926 initial_parent_scale * initial_child_scale,
4927 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294928 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264929 initial_parent_scale * initial_child_scale,
4930 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294931}
4932
sohan.jyotie3bd6192014-10-13 07:13:594933TEST_F(LayerTreeHostCommonTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294934 MockContentLayerClient delegate;
4935 gfx::Transform identity_matrix;
4936
4937 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264938 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294939 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4940
4941 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264942 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294943 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4944
loysoa6edaaff2015-05-25 03:26:444945 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]35a99a12013-05-09 23:52:294946 root->SetBounds(gfx::Size(100, 100));
4947
sohan.jyotie3bd6192014-10-13 07:13:594948 scoped_refptr<FakePictureLayer> parent =
loysoa6edaaff2015-05-25 03:26:444949 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]35a99a12013-05-09 23:52:294950 SetLayerPropertiesForTesting(parent.get(),
4951 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204952 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294953 gfx::PointF(),
4954 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574955 false,
[email protected]35a99a12013-05-09 23:52:294956 true);
4957
sohan.jyotie3bd6192014-10-13 07:13:594958 scoped_refptr<FakePictureLayer> child_scale =
loysoa6edaaff2015-05-25 03:26:444959 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]35a99a12013-05-09 23:52:294960 SetLayerPropertiesForTesting(child_scale.get(),
4961 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204962 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294963 gfx::PointF(2.f, 2.f),
4964 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574965 false,
[email protected]35a99a12013-05-09 23:52:294966 true);
4967
4968 root->AddChild(parent);
4969
[email protected]fb661802013-03-25 01:59:324970 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:214971
enne2097cab2014-09-25 20:16:314972 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284973 host->SetRootLayer(root);
4974
[email protected]fb661802013-03-25 01:59:324975 float device_scale_factor = 2.5f;
4976 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214977
[email protected]989386c2013-07-18 21:37:234978 {
4979 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534980 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224981 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534982 inputs.device_scale_factor = device_scale_factor;
4983 inputs.page_scale_factor = page_scale_factor;
enne6394d5b42015-05-26 22:23:114984 inputs.page_scale_layer = root.get();
[email protected]7aad55f2013-07-26 11:25:534985 inputs.can_adjust_raster_scales = true;
4986 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:214987
sohan.jyotie3bd6192014-10-13 07:13:594988 // The ideal scale is able to go below 1.
4989 float expected_ideal_scale =
4990 device_scale_factor * page_scale_factor * initial_parent_scale;
4991 EXPECT_LT(expected_ideal_scale, 1.f);
4992 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
[email protected]11ec92972012-11-10 03:06:214993
sohan.jyotie3bd6192014-10-13 07:13:594994 expected_ideal_scale = device_scale_factor * page_scale_factor *
4995 initial_parent_scale * initial_child_scale;
4996 EXPECT_LT(expected_ideal_scale, 1.f);
4997 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
[email protected]989386c2013-07-18 21:37:234998 }
[email protected]11ec92972012-11-10 03:06:214999}
5000
[email protected]989386c2013-07-18 21:37:235001TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:325002 MockContentLayerClient delegate;
5003 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:445004
[email protected]fb661802013-03-25 01:59:325005 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265006 SkMScalar initial_parent_scale = 2.0;
[email protected]fb661802013-03-25 01:59:325007 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:445008
[email protected]fb661802013-03-25 01:59:325009 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265010 SkMScalar initial_child_scale = 3.0;
[email protected]fb661802013-03-25 01:59:325011 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:445012
loysoa6edaaff2015-05-25 03:26:445013 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]35a99a12013-05-09 23:52:295014 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:445015
loysoa6edaaff2015-05-25 03:26:445016 scoped_refptr<ContentLayer> parent =
5017 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325018 SetLayerPropertiesForTesting(parent.get(),
5019 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205020 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325021 gfx::PointF(),
5022 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575023 false,
[email protected]fb661802013-03-25 01:59:325024 true);
[email protected]518ee582012-10-24 18:29:445025
[email protected]fb661802013-03-25 01:59:325026 scoped_refptr<ContentLayer> surface_scale =
loysoa6edaaff2015-05-25 03:26:445027 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325028 SetLayerPropertiesForTesting(surface_scale.get(),
5029 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205030 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325031 gfx::PointF(2.f, 2.f),
5032 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575033 false,
[email protected]fb661802013-03-25 01:59:325034 true);
[email protected]518ee582012-10-24 18:29:445035
[email protected]fb661802013-03-25 01:59:325036 scoped_refptr<ContentLayer> surface_scale_child_scale =
loysoa6edaaff2015-05-25 03:26:445037 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325038 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
5039 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205040 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325041 gfx::PointF(),
5042 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575043 false,
[email protected]fb661802013-03-25 01:59:325044 true);
[email protected]518ee582012-10-24 18:29:445045
[email protected]fb661802013-03-25 01:59:325046 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
loysoa6edaaff2015-05-25 03:26:445047 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325048 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
5049 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205050 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325051 gfx::PointF(),
5052 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575053 false,
[email protected]fb661802013-03-25 01:59:325054 true);
[email protected]518ee582012-10-24 18:29:445055
[email protected]fb661802013-03-25 01:59:325056 scoped_refptr<NoScaleContentLayer> surface_no_scale =
loysoa6edaaff2015-05-25 03:26:445057 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325058 SetLayerPropertiesForTesting(surface_no_scale.get(),
5059 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205060 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325061 gfx::PointF(12.f, 12.f),
5062 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575063 false,
[email protected]fb661802013-03-25 01:59:325064 true);
[email protected]518ee582012-10-24 18:29:445065
[email protected]fb661802013-03-25 01:59:325066 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
loysoa6edaaff2015-05-25 03:26:445067 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325068 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
5069 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205070 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325071 gfx::PointF(),
5072 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575073 false,
[email protected]fb661802013-03-25 01:59:325074 true);
[email protected]518ee582012-10-24 18:29:445075
[email protected]fb661802013-03-25 01:59:325076 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
loysoa6edaaff2015-05-25 03:26:445077 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325078 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
5079 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205080 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325081 gfx::PointF(),
5082 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575083 false,
[email protected]fb661802013-03-25 01:59:325084 true);
[email protected]518ee582012-10-24 18:29:445085
[email protected]35a99a12013-05-09 23:52:295086 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:445087
[email protected]fb661802013-03-25 01:59:325088 parent->AddChild(surface_scale);
5089 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:445090
[email protected]fb661802013-03-25 01:59:325091 surface_scale->SetForceRenderSurface(true);
5092 surface_scale->AddChild(surface_scale_child_scale);
5093 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:445094
[email protected]fb661802013-03-25 01:59:325095 surface_no_scale->SetForceRenderSurface(true);
5096 surface_no_scale->AddChild(surface_no_scale_child_scale);
5097 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:445098
enne2097cab2014-09-25 20:16:315099 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285100 host->SetRootLayer(root);
5101
[email protected]803f6b52013-09-12 00:51:265102 SkMScalar device_scale_factor = 5;
5103 SkMScalar page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:445104
[email protected]7aad55f2013-07-26 11:25:535105 RenderSurfaceLayerList render_surface_layer_list;
5106 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225107 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535108 inputs.device_scale_factor = device_scale_factor;
5109 inputs.page_scale_factor = page_scale_factor;
enne6394d5b42015-05-26 22:23:115110 inputs.page_scale_layer = root.get();
[email protected]7aad55f2013-07-26 11:25:535111 inputs.can_adjust_raster_scales = true;
enne432edd02015-05-11 18:38:335112 inputs.verify_property_trees = false;
[email protected]7aad55f2013-07-26 11:25:535113 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5114
5115 EXPECT_CONTENTS_SCALE_EQ(
5116 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:195117 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:535118 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:325119 surface_scale);
5120 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
5121 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:325122 device_scale_factor * page_scale_factor * initial_parent_scale *
5123 initial_child_scale * initial_child_scale,
5124 surface_scale_child_scale);
5125 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
5126 EXPECT_CONTENTS_SCALE_EQ(
5127 device_scale_factor * page_scale_factor * initial_parent_scale *
5128 initial_child_scale * initial_child_scale,
5129 surface_no_scale_child_scale);
5130 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:445131
[email protected]fb661802013-03-25 01:59:325132 // The parent is scaled up and shouldn't need to scale during draw.
[email protected]803f6b52013-09-12 00:51:265133 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
5134 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445135
[email protected]fb661802013-03-25 01:59:325136 // RenderSurfaces should always be 1:1 with their target.
5137 EXPECT_FLOAT_EQ(
5138 1.0,
[email protected]803f6b52013-09-12 00:51:265139 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325140 EXPECT_FLOAT_EQ(
5141 1.0,
[email protected]803f6b52013-09-12 00:51:265142 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445143
[email protected]fb661802013-03-25 01:59:325144 // The surface_scale can apply contents scale so the layer shouldn't need to
5145 // scale during draw.
[email protected]803f6b52013-09-12 00:51:265146 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
5147 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445148
[email protected]fb661802013-03-25 01:59:325149 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5150 // to scale during draw.
5151 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265152 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325153 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265154 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445155
[email protected]fb661802013-03-25 01:59:325156 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5157 // to be scaled during draw.
5158 EXPECT_FLOAT_EQ(
5159 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265160 initial_child_scale * initial_child_scale,
5161 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325162 EXPECT_FLOAT_EQ(
5163 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265164 initial_child_scale * initial_child_scale,
5165 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445166
[email protected]fb661802013-03-25 01:59:325167 // RenderSurfaces should always be 1:1 with their target.
5168 EXPECT_FLOAT_EQ(
5169 1.0,
[email protected]803f6b52013-09-12 00:51:265170 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325171 EXPECT_FLOAT_EQ(
5172 1.0,
[email protected]803f6b52013-09-12 00:51:265173 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445174
[email protected]fb661802013-03-25 01:59:325175 // The surface_no_scale layer can not apply contents scale, so it needs to be
5176 // scaled during draw.
5177 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:265178 initial_parent_scale * initial_child_scale,
5179 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325180 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:265181 initial_parent_scale * initial_child_scale,
5182 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445183
[email protected]fb661802013-03-25 01:59:325184 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5185 // to scale during draw.
5186 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265187 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325188 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265189 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445190
[email protected]fb661802013-03-25 01:59:325191 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5192 // to be scaled during draw.
5193 EXPECT_FLOAT_EQ(
5194 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265195 initial_child_scale * initial_child_scale,
5196 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325197 EXPECT_FLOAT_EQ(
5198 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265199 initial_child_scale * initial_child_scale,
5200 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295201}
[email protected]518ee582012-10-24 18:29:445202
sohan.jyotie3bd6192014-10-13 07:13:595203// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:235204TEST_F(LayerTreeHostCommonTest,
sohan.jyotie3bd6192014-10-13 07:13:595205 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
[email protected]35a99a12013-05-09 23:52:295206 MockContentLayerClient delegate;
5207 gfx::Transform identity_matrix;
5208
5209 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265210 SkMScalar initial_parent_scale = 2.0;
[email protected]35a99a12013-05-09 23:52:295211 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
5212
5213 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265214 SkMScalar initial_child_scale = 3.0;
[email protected]35a99a12013-05-09 23:52:295215 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
5216
loysoa6edaaff2015-05-25 03:26:445217 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]35a99a12013-05-09 23:52:295218 root->SetBounds(gfx::Size(100, 100));
5219
loysoa6edaaff2015-05-25 03:26:445220 scoped_refptr<ContentLayer> parent =
5221 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]35a99a12013-05-09 23:52:295222 SetLayerPropertiesForTesting(parent.get(),
5223 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205224 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295225 gfx::PointF(),
5226 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575227 false,
[email protected]35a99a12013-05-09 23:52:295228 true);
5229
5230 scoped_refptr<ContentLayer> surface_scale =
loysoa6edaaff2015-05-25 03:26:445231 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]35a99a12013-05-09 23:52:295232 SetLayerPropertiesForTesting(surface_scale.get(),
5233 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205234 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295235 gfx::PointF(2.f, 2.f),
5236 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575237 false,
[email protected]35a99a12013-05-09 23:52:295238 true);
5239
5240 scoped_refptr<ContentLayer> surface_scale_child_scale =
loysoa6edaaff2015-05-25 03:26:445241 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]35a99a12013-05-09 23:52:295242 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
5243 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205244 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295245 gfx::PointF(),
5246 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575247 false,
[email protected]35a99a12013-05-09 23:52:295248 true);
5249
5250 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
loysoa6edaaff2015-05-25 03:26:445251 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate);
[email protected]35a99a12013-05-09 23:52:295252 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
5253 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205254 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295255 gfx::PointF(),
5256 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575257 false,
[email protected]35a99a12013-05-09 23:52:295258 true);
5259
5260 scoped_refptr<NoScaleContentLayer> surface_no_scale =
loysoa6edaaff2015-05-25 03:26:445261 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate);
[email protected]35a99a12013-05-09 23:52:295262 SetLayerPropertiesForTesting(surface_no_scale.get(),
5263 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205264 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295265 gfx::PointF(12.f, 12.f),
5266 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575267 false,
[email protected]35a99a12013-05-09 23:52:295268 true);
5269
5270 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
loysoa6edaaff2015-05-25 03:26:445271 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]35a99a12013-05-09 23:52:295272 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
5273 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205274 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295275 gfx::PointF(),
5276 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575277 false,
[email protected]35a99a12013-05-09 23:52:295278 true);
5279
5280 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
loysoa6edaaff2015-05-25 03:26:445281 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate);
[email protected]35a99a12013-05-09 23:52:295282 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
5283 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205284 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295285 gfx::PointF(),
5286 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575287 false,
[email protected]35a99a12013-05-09 23:52:295288 true);
5289
5290 root->AddChild(parent);
5291
5292 parent->AddChild(surface_scale);
5293 parent->AddChild(surface_no_scale);
5294
5295 surface_scale->SetForceRenderSurface(true);
5296 surface_scale->AddChild(surface_scale_child_scale);
5297 surface_scale->AddChild(surface_scale_child_no_scale);
5298
5299 surface_no_scale->SetForceRenderSurface(true);
5300 surface_no_scale->AddChild(surface_no_scale_child_scale);
5301 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
5302
enne2097cab2014-09-25 20:16:315303 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285304 host->SetRootLayer(root);
5305
[email protected]989386c2013-07-18 21:37:235306 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:295307
[email protected]803f6b52013-09-12 00:51:265308 SkMScalar device_scale_factor = 5.0;
5309 SkMScalar page_scale_factor = 7.0;
[email protected]7aad55f2013-07-26 11:25:535310 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225311 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535312 inputs.device_scale_factor = device_scale_factor;
5313 inputs.page_scale_factor = page_scale_factor;
enne6394d5b42015-05-26 22:23:115314 inputs.page_scale_layer = root.get();
enne432edd02015-05-11 18:38:335315 inputs.verify_property_trees = false;
[email protected]7aad55f2013-07-26 11:25:535316 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:295317
[email protected]35a99a12013-05-09 23:52:295318 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5319 parent);
5320 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5321 surface_scale);
5322 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
5323 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5324 surface_scale_child_scale);
5325 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
5326 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5327 surface_no_scale_child_scale);
5328 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
5329
5330 // The parent is scaled up during draw, since its contents are not scaled by
5331 // the transform hierarchy.
5332 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265333 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295334 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265335 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295336
hendrikwc493d2682015-01-26 23:35:115337 // The child surface is not scaled up during draw since its subtree is scaled
[email protected]35a99a12013-05-09 23:52:295338 // by the transform hierarchy.
5339 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115340 1.f,
[email protected]803f6b52013-09-12 00:51:265341 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295342 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115343 1.f,
[email protected]803f6b52013-09-12 00:51:265344 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295345
hendrikwc493d2682015-01-26 23:35:115346 // The surface_scale's RenderSurface is not scaled during draw, so the layer
5347 // needs to be scaled when drawing into its surface.
5348 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
5349 surface_scale->draw_transform().matrix().get(0, 0));
5350 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
5351 surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445352
hendrikwc493d2682015-01-26 23:35:115353 // The surface_scale_child_scale is not scaled when drawing into its surface,
5354 // since its content bounds are scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:325355 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115356 initial_child_scale * initial_child_scale * initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265357 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325358 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115359 initial_child_scale * initial_child_scale * initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265360 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445361
hendrikwc493d2682015-01-26 23:35:115362 // The surface_scale_child_no_scale is scaled by the device scale, page scale
5363 // and transform hierarchy.
[email protected]fb661802013-03-25 01:59:325364 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115365 device_scale_factor * page_scale_factor * initial_parent_scale *
5366 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265367 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295368 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115369 device_scale_factor * page_scale_factor * initial_parent_scale *
5370 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265371 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295372
hendrikwc493d2682015-01-26 23:35:115373 // The child surface is not scaled up during draw since its subtree is scaled
[email protected]35a99a12013-05-09 23:52:295374 // by the transform hierarchy.
5375 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115376 1.f,
[email protected]803f6b52013-09-12 00:51:265377 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325378 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115379 1.f,
[email protected]803f6b52013-09-12 00:51:265380 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445381
[email protected]35a99a12013-05-09 23:52:295382 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
5383 // be scaled by the device and page scale factors. Its surface is already
5384 // scaled by the transform hierarchy so those don't need to scale the layer's
5385 // drawing.
hendrikwc493d2682015-01-26 23:35:115386 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale *
5387 device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:265388 surface_no_scale->draw_transform().matrix().get(0, 0));
hendrikwc493d2682015-01-26 23:35:115389 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale *
5390 device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:265391 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295392
5393 // The surface_no_scale_child_scale has its contents scaled by the page and
5394 // device scale factors, but needs to be scaled by the transform hierarchy
5395 // when drawing.
[email protected]fb661802013-03-25 01:59:325396 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115397 initial_parent_scale * initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265398 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325399 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115400 initial_parent_scale * initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265401 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295402
hendrikwc493d2682015-01-26 23:35:115403 // The surface_no_scale_child_no_scale needs to be scaled by the device and
5404 // page scale factors and by any transform heirarchy below its target surface.
[email protected]35a99a12013-05-09 23:52:295405 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115406 device_scale_factor * page_scale_factor * initial_parent_scale *
5407 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265408 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295409 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115410 device_scale_factor * page_scale_factor * initial_parent_scale *
5411 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265412 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445413}
5414
sohan.jyotie3bd6192014-10-13 07:13:595415TEST_F(LayerTreeHostCommonTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:325416 MockContentLayerClient delegate;
5417 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:265418
[email protected]fb661802013-03-25 01:59:325419 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265420 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:325421 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:265422
[email protected]fb661802013-03-25 01:59:325423 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265424 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:325425 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:265426
loysoa6edaaff2015-05-25 03:26:445427 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]35a99a12013-05-09 23:52:295428 root->SetBounds(gfx::Size(100, 100));
5429
sohan.jyotie3bd6192014-10-13 07:13:595430 scoped_refptr<FakePictureLayer> parent =
loysoa6edaaff2015-05-25 03:26:445431 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325432 SetLayerPropertiesForTesting(parent.get(),
5433 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205434 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325435 gfx::PointF(),
5436 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575437 false,
[email protected]fb661802013-03-25 01:59:325438 true);
[email protected]6a9cff92012-11-08 11:53:265439
sohan.jyotie3bd6192014-10-13 07:13:595440 scoped_refptr<FakePictureLayer> child_scale =
loysoa6edaaff2015-05-25 03:26:445441 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325442 SetLayerPropertiesForTesting(child_scale.get(),
5443 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205444 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325445 gfx::PointF(2.f, 2.f),
5446 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575447 false,
[email protected]fb661802013-03-25 01:59:325448 true);
[email protected]6a9cff92012-11-08 11:53:265449
[email protected]35a99a12013-05-09 23:52:295450 root->AddChild(parent);
5451
[email protected]fb661802013-03-25 01:59:325452 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:265453
enne2097cab2014-09-25 20:16:315454 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285455 host->SetRootLayer(root);
5456
[email protected]989386c2013-07-18 21:37:235457 {
5458 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535459 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225460 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535461 inputs.can_adjust_raster_scales = true;
5462 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:265463
sohan.jyotie3bd6192014-10-13 07:13:595464 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
5465 // Animating layers compute ideal scale in the same way as when
5466 // they are static.
5467 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
5468 child_scale);
[email protected]989386c2013-07-18 21:37:235469 }
[email protected]6a9cff92012-11-08 11:53:265470}
5471
sohan.jyotie3bd6192014-10-13 07:13:595472// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]7a5a9322014-02-25 12:54:575473TEST_F(LayerTreeHostCommonTest,
5474 ChangeInContentBoundsOrScaleTriggersPushProperties) {
5475 MockContentLayerClient delegate;
loysoa6edaaff2015-05-25 03:26:445476 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5477 scoped_refptr<Layer> child =
5478 CreateDrawableContentLayer(layer_settings(), &delegate);
[email protected]7a5a9322014-02-25 12:54:575479 root->AddChild(child);
5480
enne2097cab2014-09-25 20:16:315481 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]7a5a9322014-02-25 12:54:575482 host->SetRootLayer(root);
5483
5484 gfx::Transform identity_matrix;
5485 SetLayerPropertiesForTesting(root.get(),
5486 identity_matrix,
[email protected]a2566412014-06-05 03:14:205487 gfx::Point3F(),
[email protected]7a5a9322014-02-25 12:54:575488 gfx::PointF(),
5489 gfx::Size(100, 100),
5490 true,
5491 false);
5492 SetLayerPropertiesForTesting(child.get(),
5493 identity_matrix,
[email protected]a2566412014-06-05 03:14:205494 gfx::Point3F(),
[email protected]7a5a9322014-02-25 12:54:575495 gfx::PointF(),
5496 gfx::Size(100, 100),
5497 true,
5498 false);
5499
5500 root->reset_needs_push_properties_for_testing();
5501 child->reset_needs_push_properties_for_testing();
5502
enne432edd02015-05-11 18:38:335503 gfx::Size device_viewport_size = gfx::Size(100, 100);
5504 RenderSurfaceLayerList render_surface_layer_list;
5505 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5506 root.get(), device_viewport_size, &render_surface_layer_list);
5507 inputs.device_scale_factor = 1.f;
5508 inputs.can_adjust_raster_scales = true;
5509 inputs.verify_property_trees = false;
5510
[email protected]7a5a9322014-02-25 12:54:575511 // This will change both layers' content bounds.
enne432edd02015-05-11 18:38:335512 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]7a5a9322014-02-25 12:54:575513 EXPECT_TRUE(root->needs_push_properties());
5514 EXPECT_TRUE(child->needs_push_properties());
5515
5516 root->reset_needs_push_properties_for_testing();
5517 child->reset_needs_push_properties_for_testing();
5518
5519 // This will change only the child layer's contents scale and content bounds,
5520 // since the root layer is not a ContentsScalingLayer.
enne432edd02015-05-11 18:38:335521 inputs.device_scale_factor = 2.f;
5522 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]7a5a9322014-02-25 12:54:575523 EXPECT_FALSE(root->needs_push_properties());
5524 EXPECT_TRUE(child->needs_push_properties());
5525
5526 root->reset_needs_push_properties_for_testing();
5527 child->reset_needs_push_properties_for_testing();
5528
5529 // This will not change either layer's contents scale or content bounds.
enne432edd02015-05-11 18:38:335530 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]7a5a9322014-02-25 12:54:575531 EXPECT_FALSE(root->needs_push_properties());
5532 EXPECT_FALSE(child->needs_push_properties());
5533}
5534
[email protected]989386c2013-07-18 21:37:235535TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:325536 MockContentLayerClient delegate;
5537 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:265538
sohan.jyotie3bd6192014-10-13 07:13:595539 scoped_refptr<FakePictureLayer> parent =
loysoa6edaaff2015-05-25 03:26:445540 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325541 SetLayerPropertiesForTesting(parent.get(),
5542 identity_matrix,
[email protected]a2566412014-06-05 03:14:205543 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325544 gfx::PointF(),
5545 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:575546 false,
[email protected]fb661802013-03-25 01:59:325547 true);
[email protected]94f206c12012-08-25 00:09:145548
loysoa6edaaff2015-05-25 03:26:445549 scoped_refptr<FakePictureLayer> child =
5550 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325551 SetLayerPropertiesForTesting(child.get(),
5552 identity_matrix,
[email protected]a2566412014-06-05 03:14:205553 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325554 gfx::PointF(2.f, 2.f),
5555 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575556 false,
[email protected]fb661802013-03-25 01:59:325557 true);
[email protected]94f206c12012-08-25 00:09:145558
[email protected]fb661802013-03-25 01:59:325559 gfx::Transform replica_transform;
5560 replica_transform.Scale(1.0, -1.0);
sohan.jyotie3bd6192014-10-13 07:13:595561 scoped_refptr<FakePictureLayer> replica =
loysoa6edaaff2015-05-25 03:26:445562 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325563 SetLayerPropertiesForTesting(replica.get(),
5564 replica_transform,
[email protected]a2566412014-06-05 03:14:205565 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325566 gfx::PointF(2.f, 2.f),
5567 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575568 false,
[email protected]fb661802013-03-25 01:59:325569 true);
[email protected]94f206c12012-08-25 00:09:145570
[email protected]fb661802013-03-25 01:59:325571 // This layer should end up in the same surface as child, with the same draw
5572 // and screen space transforms.
sohan.jyotie3bd6192014-10-13 07:13:595573 scoped_refptr<FakePictureLayer> duplicate_child_non_owner =
loysoa6edaaff2015-05-25 03:26:445574 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325575 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
5576 identity_matrix,
[email protected]a2566412014-06-05 03:14:205577 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325578 gfx::PointF(),
5579 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575580 false,
[email protected]fb661802013-03-25 01:59:325581 true);
[email protected]94f206c12012-08-25 00:09:145582
[email protected]fb661802013-03-25 01:59:325583 parent->AddChild(child);
5584 child->AddChild(duplicate_child_non_owner);
5585 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:145586
enne2097cab2014-09-25 20:16:315587 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285588 host->SetRootLayer(parent);
5589
[email protected]989386c2013-07-18 21:37:235590 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145591
[email protected]fb661802013-03-25 01:59:325592 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:535593 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5594 parent.get(), parent->bounds(), &render_surface_layer_list);
5595 inputs.device_scale_factor = device_scale_factor;
5596 inputs.can_adjust_raster_scales = true;
5597 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145598
[email protected]fb661802013-03-25 01:59:325599 // We should have two render surfaces. The root's render surface and child's
5600 // render surface (it needs one because it has a replica layer).
5601 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:145602
[email protected]fb661802013-03-25 01:59:325603 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:595604 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:325605 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
5606 parent->screen_space_transform());
5607 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
5608 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:145609
[email protected]fb661802013-03-25 01:59:325610 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:595611 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:325612 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
5613 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:145614
[email protected]fb661802013-03-25 01:59:325615 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:595616 expected_screen_space_transform.Scale(device_scale_factor,
5617 device_scale_factor);
5618 expected_screen_space_transform.Translate(child->position().x(),
5619 child->position().y());
[email protected]fb661802013-03-25 01:59:325620 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
5621 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145622
[email protected]fb661802013-03-25 01:59:325623 gfx::Transform expected_duplicate_child_draw_transform =
5624 child->draw_transform();
5625 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
5626 duplicate_child_non_owner->draw_transform());
5627 EXPECT_TRANSFORMATION_MATRIX_EQ(
5628 child->screen_space_transform(),
5629 duplicate_child_non_owner->screen_space_transform());
hush6b614212014-12-04 22:37:325630 EXPECT_EQ(child->drawable_content_rect(),
5631 duplicate_child_non_owner->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:325632 EXPECT_EQ(child->content_bounds(),
5633 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:145634
[email protected]fb661802013-03-25 01:59:325635 gfx::Transform expected_render_surface_draw_transform;
5636 expected_render_surface_draw_transform.Translate(
5637 device_scale_factor * child->position().x(),
5638 device_scale_factor * child->position().y());
5639 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
5640 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145641
[email protected]fb661802013-03-25 01:59:325642 gfx::Transform expected_surface_draw_transform;
5643 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
5644 device_scale_factor * 2.f);
5645 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
5646 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145647
[email protected]fb661802013-03-25 01:59:325648 gfx::Transform expected_surface_screen_space_transform;
5649 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
5650 device_scale_factor * 2.f);
5651 EXPECT_TRANSFORMATION_MATRIX_EQ(
5652 expected_surface_screen_space_transform,
5653 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145654
[email protected]fb661802013-03-25 01:59:325655 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265656 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
5657 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
5658 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325659 EXPECT_TRANSFORMATION_MATRIX_EQ(
5660 expected_replica_draw_transform,
5661 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:145662
[email protected]fb661802013-03-25 01:59:325663 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265664 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
5665 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
5666 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325667 EXPECT_TRANSFORMATION_MATRIX_EQ(
5668 expected_replica_screen_space_transform,
5669 child->render_surface()->replica_screen_space_transform());
5670 EXPECT_TRANSFORMATION_MATRIX_EQ(
5671 expected_replica_screen_space_transform,
5672 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:475673}
5674
[email protected]989386c2013-07-18 21:37:235675TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325676 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
5677 MockContentLayerClient delegate;
5678 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:475679
sohan.jyotie3bd6192014-10-13 07:13:595680 scoped_refptr<FakePictureLayer> parent =
loysoa6edaaff2015-05-25 03:26:445681 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325682 SetLayerPropertiesForTesting(parent.get(),
5683 identity_matrix,
[email protected]a2566412014-06-05 03:14:205684 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325685 gfx::PointF(),
5686 gfx::Size(33, 31),
[email protected]56fffdd2014-02-11 19:50:575687 false,
[email protected]fb661802013-03-25 01:59:325688 true);
[email protected]904e9132012-11-01 00:12:475689
loysoa6edaaff2015-05-25 03:26:445690 scoped_refptr<FakePictureLayer> child =
5691 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325692 SetLayerPropertiesForTesting(child.get(),
5693 identity_matrix,
[email protected]a2566412014-06-05 03:14:205694 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325695 gfx::PointF(),
5696 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:575697 false,
[email protected]fb661802013-03-25 01:59:325698 true);
[email protected]904e9132012-11-01 00:12:475699
[email protected]fb661802013-03-25 01:59:325700 gfx::Transform replica_transform;
5701 replica_transform.Scale(1.0, -1.0);
sohan.jyotie3bd6192014-10-13 07:13:595702 scoped_refptr<FakePictureLayer> replica =
loysoa6edaaff2015-05-25 03:26:445703 CreateDrawablePictureLayer(layer_settings(), &delegate);
[email protected]fb661802013-03-25 01:59:325704 SetLayerPropertiesForTesting(replica.get(),
5705 replica_transform,
[email protected]a2566412014-06-05 03:14:205706 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325707 gfx::PointF(),
5708 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:575709 false,
[email protected]fb661802013-03-25 01:59:325710 true);
[email protected]904e9132012-11-01 00:12:475711
[email protected]fb661802013-03-25 01:59:325712 parent->AddChild(child);
[email protected]fb661802013-03-25 01:59:325713 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:475714
enne2097cab2014-09-25 20:16:315715 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285716 host->SetRootLayer(parent);
5717
[email protected]873639e2013-07-24 19:56:315718 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:535719
5720 RenderSurfaceLayerList render_surface_layer_list;
5721 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5722 parent.get(), parent->bounds(), &render_surface_layer_list);
5723 inputs.device_scale_factor = device_scale_factor;
5724 inputs.can_adjust_raster_scales = true;
5725 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:475726
[email protected]fb661802013-03-25 01:59:325727 // We should have two render surfaces. The root's render surface and child's
5728 // render surface (it needs one because it has a replica layer).
5729 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:475730
[email protected]fb661802013-03-25 01:59:325731 gfx::Transform identity_transform;
[email protected]fb661802013-03-25 01:59:325732 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5733 child->render_surface()->draw_transform());
5734 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5735 child->render_surface()->draw_transform());
5736 EXPECT_TRANSFORMATION_MATRIX_EQ(
5737 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:475738
[email protected]fb661802013-03-25 01:59:325739 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265740 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325741 EXPECT_TRANSFORMATION_MATRIX_EQ(
5742 expected_replica_draw_transform,
5743 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:475744
[email protected]fb661802013-03-25 01:59:325745 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265746 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325747 EXPECT_TRANSFORMATION_MATRIX_EQ(
5748 expected_replica_screen_space_transform,
5749 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145750}
5751
[email protected]989386c2013-07-18 21:37:235752TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
loysoa6edaaff2015-05-25 03:26:445753 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5754 scoped_refptr<Layer> child = Layer::Create(layer_settings());
5755 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
5756 scoped_refptr<Layer> mask_layer = Layer::Create(layer_settings());
5757 scoped_refptr<Layer> replica_layer = Layer::Create(layer_settings());
[email protected]94f206c12012-08-25 00:09:145758
[email protected]fb661802013-03-25 01:59:325759 grand_child->SetReplicaLayer(replica_layer.get());
5760 child->AddChild(grand_child.get());
5761 child->SetMaskLayer(mask_layer.get());
5762 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:145763
enne2097cab2014-09-25 20:16:315764 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285765 host->SetRootLayer(root);
5766
[email protected]fb661802013-03-25 01:59:325767 int nonexistent_id = -1;
Daniel Chengeea98042014-08-26 00:28:105768 EXPECT_EQ(root.get(),
[email protected]fb661802013-03-25 01:59:325769 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
Daniel Chengeea98042014-08-26 00:28:105770 EXPECT_EQ(child.get(),
[email protected]fb661802013-03-25 01:59:325771 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
5772 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105773 grand_child.get(),
[email protected]fb661802013-03-25 01:59:325774 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
5775 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105776 mask_layer.get(),
[email protected]fb661802013-03-25 01:59:325777 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
5778 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105779 replica_layer.get(),
[email protected]fb661802013-03-25 01:59:325780 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
5781 EXPECT_EQ(
5782 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:145783}
5784
[email protected]989386c2013-07-18 21:37:235785TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
loysoa6edaaff2015-05-25 03:26:445786 scoped_refptr<Layer> root = Layer::Create(layer_settings());
5787 scoped_refptr<Layer> child = Layer::Create(layer_settings());
[email protected]fb661802013-03-25 01:59:325788 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
loysoa6edaaff2015-05-25 03:26:445789 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]498ec6e0e2012-11-30 18:24:575790
[email protected]fb661802013-03-25 01:59:325791 const gfx::Transform identity_matrix;
5792 SetLayerPropertiesForTesting(root.get(),
5793 identity_matrix,
[email protected]a2566412014-06-05 03:14:205794 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325795 gfx::PointF(),
5796 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575797 true,
[email protected]fb661802013-03-25 01:59:325798 false);
5799 SetLayerPropertiesForTesting(child.get(),
5800 identity_matrix,
[email protected]a2566412014-06-05 03:14:205801 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325802 gfx::PointF(),
5803 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575804 true,
[email protected]fb661802013-03-25 01:59:325805 false);
5806 SetLayerPropertiesForTesting(grand_child.get(),
5807 identity_matrix,
[email protected]a2566412014-06-05 03:14:205808 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325809 gfx::PointF(),
5810 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575811 true,
[email protected]fb661802013-03-25 01:59:325812 false);
[email protected]498ec6e0e2012-11-30 18:24:575813
[email protected]fb661802013-03-25 01:59:325814 root->AddChild(child);
5815 child->AddChild(grand_child);
5816 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:575817
enne2097cab2014-09-25 20:16:315818 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285819 host->SetRootLayer(root);
5820
[email protected]fb661802013-03-25 01:59:325821 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:575822
[email protected]fb661802013-03-25 01:59:325823 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:575824}
5825
[email protected]989386c2013-07-18 21:37:235826TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:165827 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455828 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:475829 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]f90fc412013-03-30 20:13:165830 host_impl.CreatePendingTree();
5831 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5832
5833 const gfx::Transform identity_matrix;
awoloszyne83f28c2014-12-22 15:40:005834 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5835 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]f90fc412013-03-30 20:13:165836 false);
5837 root->SetDrawsContent(true);
5838
5839 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005840 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5841 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]f90fc412013-03-30 20:13:165842 false);
5843 child->SetDrawsContent(true);
5844 child->SetOpacity(0.0f);
5845
5846 // Add opacity animation.
5847 AddOpacityTransitionToController(
5848 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
5849
5850 root->AddChild(child.Pass());
awoloszyne83f28c2014-12-22 15:40:005851 root->SetHasRenderSurface(true);
[email protected]f90fc412013-03-30 20:13:165852
[email protected]c0ae06c12013-06-24 18:32:195853 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535854 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225855 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535856 inputs.can_adjust_raster_scales = true;
5857 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:165858
5859 // We should have one render surface and two layers. The child
5860 // layer should be included even though it is transparent.
5861 ASSERT_EQ(1u, render_surface_layer_list.size());
5862 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5863}
5864
danakj3f76ace2014-11-18 16:56:005865using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
[email protected]989386c2013-07-18 21:37:235866class LCDTextTest
5867 : public LayerTreeHostCommonTestBase,
5868 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:365869 public:
5870 LCDTextTest()
reveman34b7a1522015-03-23 20:27:475871 : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_),
enneaf5bda32015-02-19 01:27:365872 root_(nullptr),
5873 child_(nullptr),
5874 grand_child_(nullptr) {}
5875
[email protected]fb661802013-03-25 01:59:325876 protected:
dcheng93a52eb2014-12-23 02:14:235877 void SetUp() override {
[email protected]fb661802013-03-25 01:59:325878 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
danakj3f76ace2014-11-18 16:56:005879 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
[email protected]10aabcc32012-12-13 09:18:595880
enneaf5bda32015-02-19 01:27:365881 scoped_ptr<LayerImpl> root_ptr =
5882 LayerImpl::Create(host_impl_.active_tree(), 1);
5883 scoped_ptr<LayerImpl> child_ptr =
5884 LayerImpl::Create(host_impl_.active_tree(), 2);
5885 scoped_ptr<LayerImpl> grand_child_ptr =
5886 LayerImpl::Create(host_impl_.active_tree(), 3);
5887
5888 // Stash raw pointers to look at later.
5889 root_ = root_ptr.get();
5890 child_ = child_ptr.get();
5891 grand_child_ = grand_child_ptr.get();
5892
5893 child_->AddChild(grand_child_ptr.Pass());
5894 root_->AddChild(child_ptr.Pass());
5895 host_impl_.active_tree()->SetRootLayer(root_ptr.Pass());
[email protected]10aabcc32012-12-13 09:18:595896
fmalita51b5e202014-11-18 20:11:505897 root_->SetContentsOpaque(true);
5898 child_->SetContentsOpaque(true);
5899 grand_child_->SetContentsOpaque(true);
5900
[email protected]fb661802013-03-25 01:59:325901 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365902 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
5903 gfx::PointF(), gfx::Size(1, 1), true, false,
5904 true);
5905 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
5906 gfx::PointF(), gfx::Size(1, 1), true, false,
5907 std::tr1::get<2>(GetParam()));
5908 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
5909 gfx::PointF(), gfx::Size(1, 1), true, false,
[email protected]fb661802013-03-25 01:59:325910 false);
[email protected]fb661802013-03-25 01:59:325911 }
[email protected]10aabcc32012-12-13 09:18:595912
[email protected]fb661802013-03-25 01:59:325913 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005914 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:365915
5916 FakeImplProxy proxy_;
5917 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:475918 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:365919 FakeLayerTreeHostImpl host_impl_;
5920
5921 LayerImpl* root_;
5922 LayerImpl* child_;
5923 LayerImpl* grand_child_;
[email protected]10aabcc32012-12-13 09:18:595924};
5925
[email protected]fb661802013-03-25 01:59:325926TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005927 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5928 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5929
[email protected]fb661802013-03-25 01:59:325930 // Case 1: Identity transform.
5931 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365932 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005933 layers_always_allowed_lcd_text_);
5934 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5935 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5936 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595937
[email protected]fb661802013-03-25 01:59:325938 // Case 2: Integral translation.
5939 gfx::Transform integral_translation;
5940 integral_translation.Translate(1.0, 2.0);
5941 child_->SetTransform(integral_translation);
enneaf5bda32015-02-19 01:27:365942 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005943 layers_always_allowed_lcd_text_);
5944 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5945 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5946 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595947
[email protected]fb661802013-03-25 01:59:325948 // Case 3: Non-integral translation.
5949 gfx::Transform non_integral_translation;
5950 non_integral_translation.Translate(1.5, 2.5);
5951 child_->SetTransform(non_integral_translation);
enneaf5bda32015-02-19 01:27:365952 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005953 layers_always_allowed_lcd_text_);
5954 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5955 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5956 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595957
[email protected]fb661802013-03-25 01:59:325958 // Case 4: Rotation.
5959 gfx::Transform rotation;
5960 rotation.Rotate(10.0);
5961 child_->SetTransform(rotation);
enneaf5bda32015-02-19 01:27:365962 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005963 layers_always_allowed_lcd_text_);
5964 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5965 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5966 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595967
[email protected]fb661802013-03-25 01:59:325968 // Case 5: Scale.
5969 gfx::Transform scale;
5970 scale.Scale(2.0, 2.0);
5971 child_->SetTransform(scale);
enneaf5bda32015-02-19 01:27:365972 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005973 layers_always_allowed_lcd_text_);
5974 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5975 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5976 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595977
[email protected]fb661802013-03-25 01:59:325978 // Case 6: Skew.
5979 gfx::Transform skew;
5980 skew.SkewX(10.0);
5981 child_->SetTransform(skew);
enneaf5bda32015-02-19 01:27:365982 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005983 layers_always_allowed_lcd_text_);
5984 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5985 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5986 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595987
[email protected]fb661802013-03-25 01:59:325988 // Case 7: Translucent.
5989 child_->SetTransform(identity_matrix);
5990 child_->SetOpacity(0.5f);
enneaf5bda32015-02-19 01:27:365991 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005992 layers_always_allowed_lcd_text_);
5993 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5994 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5995 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595996
[email protected]fb661802013-03-25 01:59:325997 // Case 8: Sanity check: restore transform and opacity.
5998 child_->SetTransform(identity_matrix);
5999 child_->SetOpacity(1.f);
enneaf5bda32015-02-19 01:27:366000 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:006001 layers_always_allowed_lcd_text_);
6002 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
6003 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
6004 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalita51b5e202014-11-18 20:11:506005
6006 // Case 9: Non-opaque content.
6007 child_->SetContentsOpaque(false);
enneaf5bda32015-02-19 01:27:366008 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:506009 layers_always_allowed_lcd_text_);
6010 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
6011 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
6012 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
6013
6014 // Case 10: Sanity check: restore content opaqueness.
6015 child_->SetContentsOpaque(true);
enneaf5bda32015-02-19 01:27:366016 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:506017 layers_always_allowed_lcd_text_);
6018 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
6019 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
6020 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:596021}
6022
[email protected]fd9a3b6d2013-08-03 00:46:176023TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:006024 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
fmalitafcd926a2015-05-13 20:19:336025 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
danakj3f76ace2014-11-18 16:56:006026
[email protected]fb661802013-03-25 01:59:326027 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
enneaf5bda32015-02-19 01:27:366028 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:006029 layers_always_allowed_lcd_text_);
6030 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
6031 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
6032 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:596033
[email protected]fb661802013-03-25 01:59:326034 // Add opacity animation.
6035 child_->SetOpacity(0.9f);
6036 AddOpacityTransitionToController(
6037 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:596038
enneaf5bda32015-02-19 01:27:366039 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:006040 layers_always_allowed_lcd_text_);
fmalitafcd926a2015-05-13 20:19:336041 // Text LCD should be adjusted while animation is active.
6042 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
6043 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
6044 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
6045}
6046
6047TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) {
6048 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
6049 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
6050
6051 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
6052 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
6053 layers_always_allowed_lcd_text_);
danakj3f76ace2014-11-18 16:56:006054 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
6055 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
6056 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalitafcd926a2015-05-13 20:19:336057
6058 // Mark contents non-opaque within the first animation frame.
6059 child_->SetContentsOpaque(false);
6060 AddOpacityTransitionToController(child_->layer_animation_controller(), 10.0,
6061 0.9f, 0.1f, false);
6062
6063 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
6064 layers_always_allowed_lcd_text_);
6065 // LCD text should be disabled for non-opaque layers even during animations.
6066 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
6067 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
6068 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:596069}
6070
6071INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
6072 LCDTextTest,
danakj3f76ace2014-11-18 16:56:006073 testing::Combine(testing::Bool(),
6074 testing::Bool(),
6075 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:596076
[email protected]989386c2013-07-18 21:37:236077TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:196078 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456079 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476080 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]c0ae06c12013-06-24 18:32:196081 host_impl.CreatePendingTree();
6082 const gfx::Transform identity_matrix;
6083
loysoa6edaaff2015-05-25 03:26:446084 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]c0ae06c12013-06-24 18:32:196085 SetLayerPropertiesForTesting(root.get(),
6086 identity_matrix,
[email protected]a2566412014-06-05 03:14:206087 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196088 gfx::PointF(),
6089 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576090 true,
[email protected]c0ae06c12013-06-24 18:32:196091 false);
6092 root->SetIsDrawable(true);
6093
loysoa6edaaff2015-05-25 03:26:446094 scoped_refptr<Layer> child = Layer::Create(layer_settings());
[email protected]c0ae06c12013-06-24 18:32:196095 SetLayerPropertiesForTesting(child.get(),
6096 identity_matrix,
[email protected]a2566412014-06-05 03:14:206097 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196098 gfx::PointF(),
6099 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576100 true,
[email protected]c0ae06c12013-06-24 18:32:196101 false);
6102 child->SetIsDrawable(true);
6103
loysoa6edaaff2015-05-25 03:26:446104 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
[email protected]c0ae06c12013-06-24 18:32:196105 SetLayerPropertiesForTesting(grand_child.get(),
6106 identity_matrix,
[email protected]a2566412014-06-05 03:14:206107 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196108 gfx::PointF(),
6109 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576110 true,
[email protected]c0ae06c12013-06-24 18:32:196111 false);
6112 grand_child->SetIsDrawable(true);
6113 grand_child->SetHideLayerAndSubtree(true);
6114
6115 child->AddChild(grand_child);
6116 root->AddChild(child);
6117
enne2097cab2014-09-25 20:16:316118 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286119 host->SetRootLayer(root);
6120
[email protected]989386c2013-07-18 21:37:236121 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536122 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226123 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536124 inputs.can_adjust_raster_scales = true;
6125 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196126
6127 // We should have one render surface and two layers. The grand child has
6128 // hidden itself.
6129 ASSERT_EQ(1u, render_surface_layer_list.size());
6130 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236131 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
6132 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:196133}
6134
[email protected]989386c2013-07-18 21:37:236135TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:196136 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456137 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476138 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]c0ae06c12013-06-24 18:32:196139 host_impl.CreatePendingTree();
6140 const gfx::Transform identity_matrix;
6141
6142 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:006143 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6144 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]c0ae06c12013-06-24 18:32:196145 false);
6146 root->SetDrawsContent(true);
6147
6148 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:006149 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
6150 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:196151 false);
6152 child->SetDrawsContent(true);
6153
6154 scoped_ptr<LayerImpl> grand_child =
6155 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:006156 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
6157 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6158 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:196159 grand_child->SetDrawsContent(true);
6160 grand_child->SetHideLayerAndSubtree(true);
6161
6162 child->AddChild(grand_child.Pass());
6163 root->AddChild(child.Pass());
awoloszyne83f28c2014-12-22 15:40:006164 root->SetHasRenderSurface(true);
[email protected]c0ae06c12013-06-24 18:32:196165
6166 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536167 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226168 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536169 inputs.can_adjust_raster_scales = true;
6170 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196171
6172 // We should have one render surface and two layers. The grand child has
6173 // hidden itself.
6174 ASSERT_EQ(1u, render_surface_layer_list.size());
6175 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236176 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
6177 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:196178}
6179
[email protected]989386c2013-07-18 21:37:236180TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:196181 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456182 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476183 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]c0ae06c12013-06-24 18:32:196184 host_impl.CreatePendingTree();
6185 const gfx::Transform identity_matrix;
6186
loysoa6edaaff2015-05-25 03:26:446187 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]c0ae06c12013-06-24 18:32:196188 SetLayerPropertiesForTesting(root.get(),
6189 identity_matrix,
[email protected]a2566412014-06-05 03:14:206190 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196191 gfx::PointF(),
6192 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576193 true,
[email protected]c0ae06c12013-06-24 18:32:196194 false);
6195 root->SetIsDrawable(true);
6196
loysoa6edaaff2015-05-25 03:26:446197 scoped_refptr<Layer> child = Layer::Create(layer_settings());
[email protected]c0ae06c12013-06-24 18:32:196198 SetLayerPropertiesForTesting(child.get(),
6199 identity_matrix,
[email protected]a2566412014-06-05 03:14:206200 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196201 gfx::PointF(),
6202 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576203 true,
[email protected]c0ae06c12013-06-24 18:32:196204 false);
6205 child->SetIsDrawable(true);
6206 child->SetHideLayerAndSubtree(true);
6207
loysoa6edaaff2015-05-25 03:26:446208 scoped_refptr<Layer> grand_child = Layer::Create(layer_settings());
[email protected]c0ae06c12013-06-24 18:32:196209 SetLayerPropertiesForTesting(grand_child.get(),
6210 identity_matrix,
[email protected]a2566412014-06-05 03:14:206211 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196212 gfx::PointF(),
6213 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576214 true,
[email protected]c0ae06c12013-06-24 18:32:196215 false);
6216 grand_child->SetIsDrawable(true);
6217
6218 child->AddChild(grand_child);
6219 root->AddChild(child);
6220
enne2097cab2014-09-25 20:16:316221 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286222 host->SetRootLayer(root);
6223
[email protected]989386c2013-07-18 21:37:236224 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536225 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226226 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536227 inputs.can_adjust_raster_scales = true;
6228 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196229
6230 // We should have one render surface and one layers. The child has
6231 // hidden itself and the grand child.
6232 ASSERT_EQ(1u, render_surface_layer_list.size());
6233 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236234 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:196235}
6236
[email protected]989386c2013-07-18 21:37:236237TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[email protected]c0ae06c12013-06-24 18:32:196238 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456239 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476240 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]c0ae06c12013-06-24 18:32:196241 host_impl.CreatePendingTree();
6242 const gfx::Transform identity_matrix;
6243
6244 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:006245 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6246 gfx::PointF(), gfx::Size(50, 50), true, false,
6247 true);
[email protected]c0ae06c12013-06-24 18:32:196248 root->SetDrawsContent(true);
6249
6250 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:006251 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
6252 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:196253 false);
6254 child->SetDrawsContent(true);
6255 child->SetHideLayerAndSubtree(true);
6256
6257 scoped_ptr<LayerImpl> grand_child =
6258 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:006259 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
6260 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6261 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:196262 grand_child->SetDrawsContent(true);
6263
6264 child->AddChild(grand_child.Pass());
6265 root->AddChild(child.Pass());
6266
6267 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536268 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226269 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536270 inputs.can_adjust_raster_scales = true;
6271 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196272
6273 // We should have one render surface and one layers. The child has
6274 // hidden itself and the grand child.
6275 ASSERT_EQ(1u, render_surface_layer_list.size());
6276 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236277 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:196278}
6279
[email protected]30fe19ff2013-07-04 00:54:456280void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
6281
[email protected]989386c2013-07-18 21:37:236282TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:456283 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456284 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476285 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]30fe19ff2013-07-04 00:54:456286 host_impl.CreatePendingTree();
6287 const gfx::Transform identity_matrix;
6288
loysoa6edaaff2015-05-25 03:26:446289 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]30fe19ff2013-07-04 00:54:456290 SetLayerPropertiesForTesting(root.get(),
6291 identity_matrix,
[email protected]a2566412014-06-05 03:14:206292 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456293 gfx::PointF(),
6294 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576295 true,
[email protected]30fe19ff2013-07-04 00:54:456296 false);
6297 root->SetIsDrawable(true);
6298
loysoa6edaaff2015-05-25 03:26:446299 scoped_refptr<Layer> copy_grand_parent = Layer::Create(layer_settings());
[email protected]30fe19ff2013-07-04 00:54:456300 SetLayerPropertiesForTesting(copy_grand_parent.get(),
6301 identity_matrix,
[email protected]a2566412014-06-05 03:14:206302 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456303 gfx::PointF(),
6304 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576305 true,
[email protected]30fe19ff2013-07-04 00:54:456306 false);
6307 copy_grand_parent->SetIsDrawable(true);
6308
loysoa6edaaff2015-05-25 03:26:446309 scoped_refptr<Layer> copy_parent = Layer::Create(layer_settings());
[email protected]30fe19ff2013-07-04 00:54:456310 SetLayerPropertiesForTesting(copy_parent.get(),
6311 identity_matrix,
[email protected]a2566412014-06-05 03:14:206312 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456313 gfx::PointF(),
6314 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576315 true,
[email protected]30fe19ff2013-07-04 00:54:456316 false);
6317 copy_parent->SetIsDrawable(true);
6318 copy_parent->SetForceRenderSurface(true);
6319
loysoa6edaaff2015-05-25 03:26:446320 scoped_refptr<Layer> copy_layer = Layer::Create(layer_settings());
[email protected]30fe19ff2013-07-04 00:54:456321 SetLayerPropertiesForTesting(copy_layer.get(),
6322 identity_matrix,
[email protected]a2566412014-06-05 03:14:206323 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456324 gfx::PointF(),
6325 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576326 true,
[email protected]30fe19ff2013-07-04 00:54:456327 false);
6328 copy_layer->SetIsDrawable(true);
6329
loysoa6edaaff2015-05-25 03:26:446330 scoped_refptr<Layer> copy_child = Layer::Create(layer_settings());
[email protected]30fe19ff2013-07-04 00:54:456331 SetLayerPropertiesForTesting(copy_child.get(),
6332 identity_matrix,
[email protected]a2566412014-06-05 03:14:206333 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456334 gfx::PointF(),
6335 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576336 true,
[email protected]30fe19ff2013-07-04 00:54:456337 false);
6338 copy_child->SetIsDrawable(true);
6339
loysoa6edaaff2015-05-25 03:26:446340 scoped_refptr<Layer> copy_grand_parent_sibling_before =
6341 Layer::Create(layer_settings());
[email protected]ac020122013-07-12 23:45:536342 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
6343 identity_matrix,
[email protected]a2566412014-06-05 03:14:206344 gfx::Point3F(),
[email protected]ac020122013-07-12 23:45:536345 gfx::PointF(),
6346 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576347 true,
[email protected]ac020122013-07-12 23:45:536348 false);
6349 copy_grand_parent_sibling_before->SetIsDrawable(true);
6350
loysoa6edaaff2015-05-25 03:26:446351 scoped_refptr<Layer> copy_grand_parent_sibling_after =
6352 Layer::Create(layer_settings());
[email protected]ac020122013-07-12 23:45:536353 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
6354 identity_matrix,
[email protected]a2566412014-06-05 03:14:206355 gfx::Point3F(),
[email protected]ac020122013-07-12 23:45:536356 gfx::PointF(),
6357 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576358 true,
[email protected]ac020122013-07-12 23:45:536359 false);
6360 copy_grand_parent_sibling_after->SetIsDrawable(true);
6361
[email protected]30fe19ff2013-07-04 00:54:456362 copy_layer->AddChild(copy_child);
6363 copy_parent->AddChild(copy_layer);
6364 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:536365 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:456366 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:536367 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:456368
enne2097cab2014-09-25 20:16:316369 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286370 host->SetRootLayer(root);
6371
[email protected]30fe19ff2013-07-04 00:54:456372 // Hide the copy_grand_parent and its subtree. But make a copy request in that
6373 // hidden subtree on copy_layer.
6374 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:536375 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
6376 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:456377 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6378 base::Bind(&EmptyCopyOutputCallback)));
6379 EXPECT_TRUE(copy_layer->HasCopyRequest());
6380
[email protected]989386c2013-07-18 21:37:236381 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536382 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226383 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536384 inputs.can_adjust_raster_scales = true;
6385 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:456386
[email protected]ac020122013-07-12 23:45:536387 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
6388 EXPECT_TRUE(copy_grand_parent->draw_properties().
6389 layer_or_descendant_has_copy_request);
6390 EXPECT_TRUE(copy_parent->draw_properties().
6391 layer_or_descendant_has_copy_request);
6392 EXPECT_TRUE(copy_layer->draw_properties().
6393 layer_or_descendant_has_copy_request);
6394 EXPECT_FALSE(copy_child->draw_properties().
6395 layer_or_descendant_has_copy_request);
6396 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
6397 layer_or_descendant_has_copy_request);
6398 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
6399 layer_or_descendant_has_copy_request);
6400
[email protected]30fe19ff2013-07-04 00:54:456401 // We should have three render surfaces, one for the root, one for the parent
6402 // since it owns a surface, and one for the copy_layer.
6403 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:236404 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
6405 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
6406 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:456407
6408 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:536409 // copy_grand_parent is hidden along with its siblings, but the copy_parent
6410 // will appear since something in its subtree needs to be drawn for a copy
6411 // request.
[email protected]30fe19ff2013-07-04 00:54:456412 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236413 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
6414 EXPECT_EQ(copy_parent->id(),
6415 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:456416
[email protected]7392c7b2014-02-07 08:28:286417 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:456418 // appear in its list, since it needs to be drawn for the copy request.
6419 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
6420 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:236421 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456422
6423 // The copy_layer's render surface should have two contributing layers.
6424 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
6425 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:236426 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456427 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:236428 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:456429}
6430
[email protected]989386c2013-07-18 21:37:236431TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:456432 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456433 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476434 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]30fe19ff2013-07-04 00:54:456435 host_impl.CreatePendingTree();
6436 const gfx::Transform identity_matrix;
6437
loysoa6edaaff2015-05-25 03:26:446438 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]30fe19ff2013-07-04 00:54:456439 SetLayerPropertiesForTesting(root.get(),
6440 identity_matrix,
[email protected]a2566412014-06-05 03:14:206441 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456442 gfx::PointF(),
6443 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576444 true,
[email protected]30fe19ff2013-07-04 00:54:456445 false);
6446 root->SetIsDrawable(true);
6447
loysoa6edaaff2015-05-25 03:26:446448 scoped_refptr<Layer> copy_parent = Layer::Create(layer_settings());
[email protected]30fe19ff2013-07-04 00:54:456449 SetLayerPropertiesForTesting(copy_parent.get(),
6450 identity_matrix,
[email protected]a2566412014-06-05 03:14:206451 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456452 gfx::PointF(),
6453 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576454 true,
[email protected]30fe19ff2013-07-04 00:54:456455 false);
6456 copy_parent->SetIsDrawable(true);
6457 copy_parent->SetMasksToBounds(true);
6458
loysoa6edaaff2015-05-25 03:26:446459 scoped_refptr<Layer> copy_layer = Layer::Create(layer_settings());
[email protected]30fe19ff2013-07-04 00:54:456460 SetLayerPropertiesForTesting(copy_layer.get(),
6461 identity_matrix,
[email protected]a2566412014-06-05 03:14:206462 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456463 gfx::PointF(),
6464 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576465 true,
[email protected]30fe19ff2013-07-04 00:54:456466 false);
6467 copy_layer->SetIsDrawable(true);
6468
loysoa6edaaff2015-05-25 03:26:446469 scoped_refptr<Layer> copy_child = Layer::Create(layer_settings());
[email protected]30fe19ff2013-07-04 00:54:456470 SetLayerPropertiesForTesting(copy_child.get(),
6471 identity_matrix,
[email protected]a2566412014-06-05 03:14:206472 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456473 gfx::PointF(),
6474 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576475 true,
[email protected]30fe19ff2013-07-04 00:54:456476 false);
6477 copy_child->SetIsDrawable(true);
6478
6479 copy_layer->AddChild(copy_child);
6480 copy_parent->AddChild(copy_layer);
6481 root->AddChild(copy_parent);
6482
enne2097cab2014-09-25 20:16:316483 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286484 host->SetRootLayer(root);
6485
[email protected]30fe19ff2013-07-04 00:54:456486 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6487 base::Bind(&EmptyCopyOutputCallback)));
6488 EXPECT_TRUE(copy_layer->HasCopyRequest());
6489
[email protected]989386c2013-07-18 21:37:236490 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536491 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226492 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536493 inputs.can_adjust_raster_scales = true;
6494 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:456495
6496 // We should have one render surface, as the others are clipped out.
6497 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:236498 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456499
6500 // The root render surface should only have 1 contributing layer, since the
6501 // other layers are empty/clipped away.
6502 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236503 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456504}
6505
[email protected]11a07b102013-07-24 17:33:196506TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
6507 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456508 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476509 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]11a07b102013-07-24 17:33:196510 host_impl.CreatePendingTree();
6511 const gfx::Transform identity_matrix;
6512
loysoa6edaaff2015-05-25 03:26:446513 scoped_refptr<Layer> root = Layer::Create(layer_settings());
[email protected]11a07b102013-07-24 17:33:196514 SetLayerPropertiesForTesting(root.get(),
6515 identity_matrix,
[email protected]a2566412014-06-05 03:14:206516 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196517 gfx::PointF(),
6518 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576519 true,
[email protected]11a07b102013-07-24 17:33:196520 false);
6521 root->SetIsDrawable(true);
6522
6523 // The surface is moved slightly outside of the viewport.
loysoa6edaaff2015-05-25 03:26:446524 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
[email protected]11a07b102013-07-24 17:33:196525 SetLayerPropertiesForTesting(surface.get(),
6526 identity_matrix,
[email protected]a2566412014-06-05 03:14:206527 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196528 gfx::PointF(-10, -20),
6529 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576530 true,
[email protected]11a07b102013-07-24 17:33:196531 false);
6532 surface->SetForceRenderSurface(true);
6533
loysoa6edaaff2015-05-25 03:26:446534 scoped_refptr<Layer> surface_child = Layer::Create(layer_settings());
[email protected]11a07b102013-07-24 17:33:196535 SetLayerPropertiesForTesting(surface_child.get(),
6536 identity_matrix,
[email protected]a2566412014-06-05 03:14:206537 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196538 gfx::PointF(),
6539 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576540 true,
[email protected]11a07b102013-07-24 17:33:196541 false);
6542 surface_child->SetIsDrawable(true);
6543
6544 surface->AddChild(surface_child);
6545 root->AddChild(surface);
6546
enne2097cab2014-09-25 20:16:316547 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286548 host->SetRootLayer(root);
6549
[email protected]11a07b102013-07-24 17:33:196550 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536551 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226552 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536553 inputs.can_adjust_raster_scales = true;
6554 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:196555
6556 // The visible_content_rect for the |surface_child| should not be clipped by
6557 // the viewport.
6558 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
6559 surface_child->visible_content_rect().ToString());
6560}
6561
[email protected]420fdf6e2013-08-26 20:36:386562TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
6563 // Ensure that a transform between the layer and its render surface is not a
6564 // problem. Constructs the following layer tree.
6565 //
6566 // root (a render surface)
6567 // + render_surface
6568 // + clip_parent (scaled)
6569 // + intervening_clipping_layer
6570 // + clip_child
6571 //
6572 // The render surface should be resized correctly and the clip child should
6573 // inherit the right clip rect.
loysoa6edaaff2015-05-25 03:26:446574 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6575 scoped_refptr<Layer> render_surface = Layer::Create(layer_settings());
6576 scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings());
6577 scoped_refptr<Layer> intervening = Layer::Create(layer_settings());
[email protected]420fdf6e2013-08-26 20:36:386578 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
loysoa6edaaff2015-05-25 03:26:446579 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]420fdf6e2013-08-26 20:36:386580
6581 root->AddChild(render_surface);
6582 render_surface->AddChild(clip_parent);
6583 clip_parent->AddChild(intervening);
6584 intervening->AddChild(clip_child);
6585
6586 clip_child->SetClipParent(clip_parent.get());
6587
6588 intervening->SetMasksToBounds(true);
6589 clip_parent->SetMasksToBounds(true);
6590
6591 render_surface->SetForceRenderSurface(true);
6592
6593 gfx::Transform scale_transform;
6594 scale_transform.Scale(2, 2);
6595
6596 gfx::Transform identity_transform;
6597
6598 SetLayerPropertiesForTesting(root.get(),
6599 identity_transform,
[email protected]a2566412014-06-05 03:14:206600 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386601 gfx::PointF(),
6602 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576603 true,
[email protected]420fdf6e2013-08-26 20:36:386604 false);
6605 SetLayerPropertiesForTesting(render_surface.get(),
6606 identity_transform,
[email protected]a2566412014-06-05 03:14:206607 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386608 gfx::PointF(),
6609 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576610 true,
[email protected]420fdf6e2013-08-26 20:36:386611 false);
6612 SetLayerPropertiesForTesting(clip_parent.get(),
6613 scale_transform,
[email protected]a2566412014-06-05 03:14:206614 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386615 gfx::PointF(1.f, 1.f),
6616 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576617 true,
[email protected]420fdf6e2013-08-26 20:36:386618 false);
6619 SetLayerPropertiesForTesting(intervening.get(),
6620 identity_transform,
[email protected]a2566412014-06-05 03:14:206621 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386622 gfx::PointF(1.f, 1.f),
6623 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576624 true,
[email protected]420fdf6e2013-08-26 20:36:386625 false);
6626 SetLayerPropertiesForTesting(clip_child.get(),
6627 identity_transform,
[email protected]a2566412014-06-05 03:14:206628 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386629 gfx::PointF(1.f, 1.f),
6630 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576631 true,
[email protected]420fdf6e2013-08-26 20:36:386632 false);
6633
enne2097cab2014-09-25 20:16:316634 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386635 host->SetRootLayer(root);
6636
6637 ExecuteCalculateDrawProperties(root.get());
6638
6639 ASSERT_TRUE(root->render_surface());
6640 ASSERT_TRUE(render_surface->render_surface());
6641
6642 // Ensure that we've inherited our clip parent's clip and weren't affected
6643 // by the intervening clip layer.
6644 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
6645 clip_parent->clip_rect().ToString());
6646 ASSERT_EQ(clip_parent->clip_rect().ToString(),
6647 clip_child->clip_rect().ToString());
6648 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
6649 intervening->clip_rect().ToString());
6650
6651 // Ensure that the render surface reports a content rect that has been grown
6652 // to accomodate for the clip child.
6653 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
6654 render_surface->render_surface()->content_rect().ToString());
6655
6656 // The above check implies the two below, but they nicely demonstrate that
6657 // we've grown, despite the intervening layer's clip.
6658 ASSERT_TRUE(clip_parent->clip_rect().Contains(
6659 render_surface->render_surface()->content_rect()));
6660 ASSERT_FALSE(intervening->clip_rect().Contains(
6661 render_surface->render_surface()->content_rect()));
6662}
6663
6664TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
6665 // Ensure that intervening render surfaces are not a problem in the basic
6666 // case. In the following tree, both render surfaces should be resized to
6667 // accomodate for the clip child, despite an intervening clip.
6668 //
6669 // root (a render surface)
6670 // + clip_parent (masks to bounds)
6671 // + render_surface1 (sets opacity)
6672 // + intervening (masks to bounds)
6673 // + render_surface2 (also sets opacity)
6674 // + clip_child
6675 //
loysoa6edaaff2015-05-25 03:26:446676 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6677 scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings());
6678 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
6679 scoped_refptr<Layer> intervening = Layer::Create(layer_settings());
6680 scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings());
[email protected]420fdf6e2013-08-26 20:36:386681 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
loysoa6edaaff2015-05-25 03:26:446682 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]420fdf6e2013-08-26 20:36:386683
6684 root->AddChild(clip_parent);
6685 clip_parent->AddChild(render_surface1);
6686 render_surface1->AddChild(intervening);
6687 intervening->AddChild(render_surface2);
6688 render_surface2->AddChild(clip_child);
6689
6690 clip_child->SetClipParent(clip_parent.get());
6691
6692 intervening->SetMasksToBounds(true);
6693 clip_parent->SetMasksToBounds(true);
6694
6695 render_surface1->SetForceRenderSurface(true);
6696 render_surface2->SetForceRenderSurface(true);
6697
6698 gfx::Transform translation_transform;
6699 translation_transform.Translate(2, 2);
6700
6701 gfx::Transform identity_transform;
6702 SetLayerPropertiesForTesting(root.get(),
6703 identity_transform,
[email protected]a2566412014-06-05 03:14:206704 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386705 gfx::PointF(),
6706 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576707 true,
[email protected]420fdf6e2013-08-26 20:36:386708 false);
6709 SetLayerPropertiesForTesting(clip_parent.get(),
6710 translation_transform,
[email protected]a2566412014-06-05 03:14:206711 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386712 gfx::PointF(1.f, 1.f),
6713 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576714 true,
[email protected]420fdf6e2013-08-26 20:36:386715 false);
6716 SetLayerPropertiesForTesting(render_surface1.get(),
6717 identity_transform,
[email protected]a2566412014-06-05 03:14:206718 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386719 gfx::PointF(),
6720 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576721 true,
[email protected]420fdf6e2013-08-26 20:36:386722 false);
6723 SetLayerPropertiesForTesting(intervening.get(),
6724 identity_transform,
[email protected]a2566412014-06-05 03:14:206725 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386726 gfx::PointF(1.f, 1.f),
6727 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576728 true,
[email protected]420fdf6e2013-08-26 20:36:386729 false);
6730 SetLayerPropertiesForTesting(render_surface2.get(),
6731 identity_transform,
[email protected]a2566412014-06-05 03:14:206732 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386733 gfx::PointF(),
6734 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576735 true,
[email protected]420fdf6e2013-08-26 20:36:386736 false);
6737 SetLayerPropertiesForTesting(clip_child.get(),
6738 identity_transform,
[email protected]a2566412014-06-05 03:14:206739 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386740 gfx::PointF(-10.f, -10.f),
6741 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576742 true,
[email protected]420fdf6e2013-08-26 20:36:386743 false);
6744
enne2097cab2014-09-25 20:16:316745 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386746 host->SetRootLayer(root);
6747
6748 ExecuteCalculateDrawProperties(root.get());
6749
6750 EXPECT_TRUE(root->render_surface());
6751 EXPECT_TRUE(render_surface1->render_surface());
6752 EXPECT_TRUE(render_surface2->render_surface());
6753
6754 // Since the render surfaces could have expanded, they should not clip (their
6755 // bounds would no longer be reliable). We should resort to layer clipping
6756 // in this case.
6757 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6758 render_surface1->render_surface()->clip_rect().ToString());
6759 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6760 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6761 render_surface2->render_surface()->clip_rect().ToString());
6762 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6763
6764 // NB: clip rects are in target space.
6765 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6766 render_surface1->clip_rect().ToString());
6767 EXPECT_TRUE(render_surface1->is_clipped());
6768
6769 // This value is inherited from the clipping ancestor layer, 'intervening'.
6770 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6771 render_surface2->clip_rect().ToString());
6772 EXPECT_TRUE(render_surface2->is_clipped());
6773
6774 // The content rects of both render surfaces should both have expanded to
6775 // contain the clip child.
6776 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6777 render_surface1->render_surface()->content_rect().ToString());
6778 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6779 render_surface2->render_surface()->content_rect().ToString());
6780
6781 // The clip child should have inherited the clip parent's clip (projected to
6782 // the right space, of course), and should have the correctly sized visible
6783 // content rect.
6784 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6785 clip_child->clip_rect().ToString());
6786 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
6787 clip_child->visible_content_rect().ToString());
6788 EXPECT_TRUE(clip_child->is_clipped());
6789}
6790
6791TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
6792 // Ensure that intervening render surfaces are not a problem, even if there
6793 // is a scroll involved. Note, we do _not_ have to consider any other sort
6794 // of transform.
6795 //
6796 // root (a render surface)
6797 // + clip_parent (masks to bounds)
6798 // + render_surface1 (sets opacity)
6799 // + intervening (masks to bounds AND scrolls)
6800 // + render_surface2 (also sets opacity)
6801 // + clip_child
6802 //
loysoa6edaaff2015-05-25 03:26:446803 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6804 scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings());
6805 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
6806 scoped_refptr<Layer> intervening = Layer::Create(layer_settings());
6807 scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings());
[email protected]420fdf6e2013-08-26 20:36:386808 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
loysoa6edaaff2015-05-25 03:26:446809 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]420fdf6e2013-08-26 20:36:386810
6811 root->AddChild(clip_parent);
6812 clip_parent->AddChild(render_surface1);
6813 render_surface1->AddChild(intervening);
6814 intervening->AddChild(render_surface2);
6815 render_surface2->AddChild(clip_child);
6816
6817 clip_child->SetClipParent(clip_parent.get());
6818
6819 intervening->SetMasksToBounds(true);
6820 clip_parent->SetMasksToBounds(true);
[email protected]adeda572014-01-31 00:49:476821 intervening->SetScrollClipLayerId(clip_parent->id());
miletusf57925d2014-10-01 19:38:136822 intervening->SetScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:386823
6824 render_surface1->SetForceRenderSurface(true);
6825 render_surface2->SetForceRenderSurface(true);
6826
6827 gfx::Transform translation_transform;
6828 translation_transform.Translate(2, 2);
6829
6830 gfx::Transform identity_transform;
6831 SetLayerPropertiesForTesting(root.get(),
6832 identity_transform,
[email protected]a2566412014-06-05 03:14:206833 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386834 gfx::PointF(),
6835 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576836 true,
[email protected]420fdf6e2013-08-26 20:36:386837 false);
6838 SetLayerPropertiesForTesting(clip_parent.get(),
6839 translation_transform,
[email protected]a2566412014-06-05 03:14:206840 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386841 gfx::PointF(1.f, 1.f),
6842 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576843 true,
[email protected]420fdf6e2013-08-26 20:36:386844 false);
6845 SetLayerPropertiesForTesting(render_surface1.get(),
6846 identity_transform,
[email protected]a2566412014-06-05 03:14:206847 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386848 gfx::PointF(),
6849 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576850 true,
[email protected]420fdf6e2013-08-26 20:36:386851 false);
6852 SetLayerPropertiesForTesting(intervening.get(),
6853 identity_transform,
[email protected]a2566412014-06-05 03:14:206854 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386855 gfx::PointF(1.f, 1.f),
6856 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576857 true,
[email protected]420fdf6e2013-08-26 20:36:386858 false);
6859 SetLayerPropertiesForTesting(render_surface2.get(),
6860 identity_transform,
[email protected]a2566412014-06-05 03:14:206861 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386862 gfx::PointF(),
6863 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576864 true,
[email protected]420fdf6e2013-08-26 20:36:386865 false);
6866 SetLayerPropertiesForTesting(clip_child.get(),
6867 identity_transform,
[email protected]a2566412014-06-05 03:14:206868 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386869 gfx::PointF(-10.f, -10.f),
6870 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576871 true,
[email protected]420fdf6e2013-08-26 20:36:386872 false);
6873
enne2097cab2014-09-25 20:16:316874 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386875 host->SetRootLayer(root);
6876
6877 ExecuteCalculateDrawProperties(root.get());
6878
6879 EXPECT_TRUE(root->render_surface());
6880 EXPECT_TRUE(render_surface1->render_surface());
6881 EXPECT_TRUE(render_surface2->render_surface());
6882
6883 // Since the render surfaces could have expanded, they should not clip (their
6884 // bounds would no longer be reliable). We should resort to layer clipping
6885 // in this case.
6886 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6887 render_surface1->render_surface()->clip_rect().ToString());
6888 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6889 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6890 render_surface2->render_surface()->clip_rect().ToString());
6891 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6892
6893 // NB: clip rects are in target space.
6894 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6895 render_surface1->clip_rect().ToString());
6896 EXPECT_TRUE(render_surface1->is_clipped());
6897
6898 // This value is inherited from the clipping ancestor layer, 'intervening'.
6899 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6900 render_surface2->clip_rect().ToString());
6901 EXPECT_TRUE(render_surface2->is_clipped());
6902
6903 // The content rects of both render surfaces should both have expanded to
6904 // contain the clip child.
6905 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6906 render_surface1->render_surface()->content_rect().ToString());
6907 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6908 render_surface2->render_surface()->content_rect().ToString());
6909
6910 // The clip child should have inherited the clip parent's clip (projected to
6911 // the right space, of course), and should have the correctly sized visible
6912 // content rect.
6913 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6914 clip_child->clip_rect().ToString());
6915 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6916 clip_child->visible_content_rect().ToString());
6917 EXPECT_TRUE(clip_child->is_clipped());
6918}
6919
6920TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
6921 // Ensures that descendants of the clip child inherit the correct clip.
6922 //
6923 // root (a render surface)
6924 // + clip_parent (masks to bounds)
6925 // + intervening (masks to bounds)
6926 // + clip_child
6927 // + child
6928 //
loysoa6edaaff2015-05-25 03:26:446929 scoped_refptr<Layer> root = Layer::Create(layer_settings());
6930 scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings());
6931 scoped_refptr<Layer> intervening = Layer::Create(layer_settings());
6932 scoped_refptr<Layer> clip_child = Layer::Create(layer_settings());
[email protected]420fdf6e2013-08-26 20:36:386933 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:446934 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]420fdf6e2013-08-26 20:36:386935
6936 root->AddChild(clip_parent);
6937 clip_parent->AddChild(intervening);
6938 intervening->AddChild(clip_child);
6939 clip_child->AddChild(child);
6940
6941 clip_child->SetClipParent(clip_parent.get());
6942
6943 intervening->SetMasksToBounds(true);
6944 clip_parent->SetMasksToBounds(true);
6945
6946 gfx::Transform identity_transform;
6947 SetLayerPropertiesForTesting(root.get(),
6948 identity_transform,
[email protected]a2566412014-06-05 03:14:206949 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386950 gfx::PointF(),
6951 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576952 true,
[email protected]420fdf6e2013-08-26 20:36:386953 false);
6954 SetLayerPropertiesForTesting(clip_parent.get(),
6955 identity_transform,
[email protected]a2566412014-06-05 03:14:206956 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386957 gfx::PointF(),
6958 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576959 true,
[email protected]420fdf6e2013-08-26 20:36:386960 false);
6961 SetLayerPropertiesForTesting(intervening.get(),
6962 identity_transform,
[email protected]a2566412014-06-05 03:14:206963 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386964 gfx::PointF(),
6965 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576966 true,
[email protected]420fdf6e2013-08-26 20:36:386967 false);
6968 SetLayerPropertiesForTesting(clip_child.get(),
6969 identity_transform,
[email protected]a2566412014-06-05 03:14:206970 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386971 gfx::PointF(),
6972 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576973 true,
[email protected]420fdf6e2013-08-26 20:36:386974 false);
6975 SetLayerPropertiesForTesting(child.get(),
6976 identity_transform,
[email protected]a2566412014-06-05 03:14:206977 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386978 gfx::PointF(),
6979 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576980 true,
[email protected]420fdf6e2013-08-26 20:36:386981 false);
6982
enne2097cab2014-09-25 20:16:316983 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386984 host->SetRootLayer(root);
6985
6986 ExecuteCalculateDrawProperties(root.get());
6987
6988 EXPECT_TRUE(root->render_surface());
6989
6990 // Neither the clip child nor its descendant should have inherited the clip
6991 // from |intervening|.
6992 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6993 clip_child->clip_rect().ToString());
6994 EXPECT_TRUE(clip_child->is_clipped());
6995 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6996 child->visible_content_rect().ToString());
6997 EXPECT_TRUE(child->is_clipped());
6998}
6999
7000TEST_F(LayerTreeHostCommonTest,
7001 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
7002 // Ensures that non-descendant clip children in the tree do not affect
7003 // render surfaces.
7004 //
7005 // root (a render surface)
7006 // + clip_parent (masks to bounds)
7007 // + render_surface1
7008 // + clip_child
7009 // + render_surface2
7010 // + non_clip_child
7011 //
7012 // In this example render_surface2 should be unaffected by clip_child.
loysoa6edaaff2015-05-25 03:26:447013 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7014 scoped_refptr<Layer> clip_parent = Layer::Create(layer_settings());
7015 scoped_refptr<Layer> render_surface1 = Layer::Create(layer_settings());
[email protected]420fdf6e2013-08-26 20:36:387016 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
loysoa6edaaff2015-05-25 03:26:447017 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7018 scoped_refptr<Layer> render_surface2 = Layer::Create(layer_settings());
[email protected]420fdf6e2013-08-26 20:36:387019 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
loysoa6edaaff2015-05-25 03:26:447020 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]420fdf6e2013-08-26 20:36:387021
7022 root->AddChild(clip_parent);
7023 clip_parent->AddChild(render_surface1);
7024 render_surface1->AddChild(clip_child);
7025 clip_parent->AddChild(render_surface2);
7026 render_surface2->AddChild(non_clip_child);
7027
7028 clip_child->SetClipParent(clip_parent.get());
7029
7030 clip_parent->SetMasksToBounds(true);
7031 render_surface1->SetMasksToBounds(true);
7032
7033 gfx::Transform identity_transform;
7034 SetLayerPropertiesForTesting(root.get(),
7035 identity_transform,
[email protected]a2566412014-06-05 03:14:207036 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:387037 gfx::PointF(),
7038 gfx::Size(15, 15),
[email protected]56fffdd2014-02-11 19:50:577039 true,
[email protected]420fdf6e2013-08-26 20:36:387040 false);
7041 SetLayerPropertiesForTesting(clip_parent.get(),
7042 identity_transform,
[email protected]a2566412014-06-05 03:14:207043 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:387044 gfx::PointF(),
7045 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577046 true,
[email protected]420fdf6e2013-08-26 20:36:387047 false);
7048 SetLayerPropertiesForTesting(render_surface1.get(),
7049 identity_transform,
[email protected]a2566412014-06-05 03:14:207050 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:387051 gfx::PointF(5, 5),
7052 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:577053 true,
[email protected]420fdf6e2013-08-26 20:36:387054 false);
7055 SetLayerPropertiesForTesting(render_surface2.get(),
7056 identity_transform,
[email protected]a2566412014-06-05 03:14:207057 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:387058 gfx::PointF(),
7059 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:577060 true,
[email protected]420fdf6e2013-08-26 20:36:387061 false);
7062 SetLayerPropertiesForTesting(clip_child.get(),
7063 identity_transform,
[email protected]a2566412014-06-05 03:14:207064 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:387065 gfx::PointF(-1, 1),
7066 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:577067 true,
[email protected]420fdf6e2013-08-26 20:36:387068 false);
7069 SetLayerPropertiesForTesting(non_clip_child.get(),
7070 identity_transform,
[email protected]a2566412014-06-05 03:14:207071 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:387072 gfx::PointF(),
7073 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:577074 true,
[email protected]420fdf6e2013-08-26 20:36:387075 false);
7076
7077 render_surface1->SetForceRenderSurface(true);
7078 render_surface2->SetForceRenderSurface(true);
7079
enne2097cab2014-09-25 20:16:317080 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:387081 host->SetRootLayer(root);
7082
7083 ExecuteCalculateDrawProperties(root.get());
7084
7085 EXPECT_TRUE(root->render_surface());
7086 EXPECT_TRUE(render_surface1->render_surface());
7087 EXPECT_TRUE(render_surface2->render_surface());
7088
7089 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
7090 render_surface1->clip_rect().ToString());
7091 EXPECT_TRUE(render_surface1->is_clipped());
7092
7093 // The render surface should not clip (it has unclipped descendants), instead
7094 // it should rely on layer clipping.
7095 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
7096 render_surface1->render_surface()->clip_rect().ToString());
7097 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
7098
7099 // That said, it should have grown to accomodate the unclipped descendant.
7100 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
7101 render_surface1->render_surface()->content_rect().ToString());
7102
7103 // This render surface should clip. It has no unclipped descendants.
7104 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
7105 render_surface2->clip_rect().ToString());
7106 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
7107
7108 // It also shouldn't have grown to accomodate the clip child.
7109 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
7110 render_surface2->render_surface()->content_rect().ToString());
7111
7112 // Sanity check our num_unclipped_descendants values.
7113 EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
7114 EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
7115}
7116
[email protected]45948712013-09-27 02:46:487117TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
7118 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457119 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:477120 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]45948712013-09-27 02:46:487121 scoped_ptr<LayerImpl> root =
7122 LayerImpl::Create(host_impl.active_tree(), 12345);
7123 scoped_ptr<LayerImpl> child1 =
7124 LayerImpl::Create(host_impl.active_tree(), 123456);
7125 scoped_ptr<LayerImpl> child2 =
7126 LayerImpl::Create(host_impl.active_tree(), 1234567);
7127 scoped_ptr<LayerImpl> child3 =
7128 LayerImpl::Create(host_impl.active_tree(), 12345678);
7129
7130 gfx::Transform identity_matrix;
[email protected]a2566412014-06-05 03:14:207131 gfx::Point3F transform_origin;
[email protected]45948712013-09-27 02:46:487132 gfx::PointF position;
7133 gfx::Size bounds(100, 100);
awoloszyne83f28c2014-12-22 15:40:007134 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
7135 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:487136 root->SetDrawsContent(true);
7137
7138 // This layer structure normally forces render surface due to preserves3d
7139 // behavior.
awoloszyne83f28c2014-12-22 15:40:007140 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin,
7141 position, bounds, false, true, true);
[email protected]45948712013-09-27 02:46:487142 child1->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:007143 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin,
7144 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:487145 child2->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:007146 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin,
7147 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:487148 child3->SetDrawsContent(true);
7149
[email protected]a9d4d4f2014-06-19 06:49:287150 child2->Set3dSortingContextId(1);
7151 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:577152
[email protected]45948712013-09-27 02:46:487153 child2->AddChild(child3.Pass());
7154 child1->AddChild(child2.Pass());
7155 root->AddChild(child1.Pass());
7156
7157 {
7158 LayerImplList render_surface_layer_list;
[email protected]ad63b2f2014-08-11 17:39:547159 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get());
[email protected]45948712013-09-27 02:46:487160 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227161 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:487162 inputs.can_render_to_separate_surface = true;
7163 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7164
7165 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:027166
7167 int count_represents_target_render_surface = 0;
7168 int count_represents_contributing_render_surface = 0;
7169 int count_represents_itself = 0;
7170 auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list);
7171 for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list);
7172 it != end; ++it) {
7173 if (it.represents_target_render_surface())
7174 count_represents_target_render_surface++;
7175 if (it.represents_contributing_render_surface())
7176 count_represents_contributing_render_surface++;
7177 if (it.represents_itself())
7178 count_represents_itself++;
7179 }
7180
7181 // Two render surfaces.
7182 EXPECT_EQ(2, count_represents_target_render_surface);
7183 // Second render surface contributes to root render surface.
7184 EXPECT_EQ(1, count_represents_contributing_render_surface);
7185 // All 4 layers represent itself.
7186 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:487187 }
7188
7189 {
7190 LayerImplList render_surface_layer_list;
7191 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227192 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:487193 inputs.can_render_to_separate_surface = false;
7194 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7195
7196 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:027197
7198 int count_represents_target_render_surface = 0;
7199 int count_represents_contributing_render_surface = 0;
7200 int count_represents_itself = 0;
7201 auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list);
7202 for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list);
7203 it != end; ++it) {
7204 if (it.represents_target_render_surface())
7205 count_represents_target_render_surface++;
7206 if (it.represents_contributing_render_surface())
7207 count_represents_contributing_render_surface++;
7208 if (it.represents_itself())
7209 count_represents_itself++;
7210 }
7211
7212 // Only root layer has a render surface.
7213 EXPECT_EQ(1, count_represents_target_render_surface);
7214 // No layer contributes a render surface to root render surface.
7215 EXPECT_EQ(0, count_represents_contributing_render_surface);
7216 // All 4 layers represent itself.
7217 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:487218 }
7219}
7220
[email protected]a9aa60a82013-08-29 04:28:267221TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
loysoa6edaaff2015-05-25 03:26:447222 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7223 scoped_refptr<Layer> render_surface = Layer::Create(layer_settings());
[email protected]a9aa60a82013-08-29 04:28:267224 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:447225 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]a9aa60a82013-08-29 04:28:267226
7227 root->AddChild(render_surface);
7228 render_surface->AddChild(child);
7229
7230 gfx::Transform identity_transform;
7231 SetLayerPropertiesForTesting(root.get(),
7232 identity_transform,
[email protected]a2566412014-06-05 03:14:207233 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267234 gfx::PointF(),
7235 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577236 true,
[email protected]a9aa60a82013-08-29 04:28:267237 false);
7238 SetLayerPropertiesForTesting(render_surface.get(),
7239 identity_transform,
[email protected]a2566412014-06-05 03:14:207240 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267241 gfx::PointF(),
7242 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577243 false,
7244 true);
[email protected]a9aa60a82013-08-29 04:28:267245 SetLayerPropertiesForTesting(child.get(),
7246 identity_transform,
[email protected]a2566412014-06-05 03:14:207247 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267248 gfx::PointF(),
7249 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577250 true,
[email protected]a9aa60a82013-08-29 04:28:267251 false);
7252
[email protected]56fffdd2014-02-11 19:50:577253 root->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:287254 root->Set3dSortingContextId(1);
[email protected]a9aa60a82013-08-29 04:28:267255 render_surface->SetDoubleSided(false);
7256 render_surface->SetForceRenderSurface(true);
7257
enne2097cab2014-09-25 20:16:317258 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]a9aa60a82013-08-29 04:28:267259 host->SetRootLayer(root);
7260
7261 ExecuteCalculateDrawProperties(root.get());
7262
7263 EXPECT_EQ(2u, render_surface_layer_list()->size());
7264 EXPECT_EQ(1u,
7265 render_surface_layer_list()->at(0)
7266 ->render_surface()->layer_list().size());
7267 EXPECT_EQ(1u,
7268 render_surface_layer_list()->at(1)
7269 ->render_surface()->layer_list().size());
7270
7271 gfx::Transform rotation_transform = identity_transform;
7272 rotation_transform.RotateAboutXAxis(180.0);
7273
7274 render_surface->SetTransform(rotation_transform);
7275
7276 ExecuteCalculateDrawProperties(root.get());
7277
7278 EXPECT_EQ(1u, render_surface_layer_list()->size());
7279 EXPECT_EQ(0u,
7280 render_surface_layer_list()->at(0)
7281 ->render_surface()->layer_list().size());
7282}
7283
[email protected]995708c52013-10-17 20:52:597284TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
7285 // Checks that the simple case (being clipped by a scroll parent that would
7286 // have been processed before you anyhow) results in the right clips.
7287 //
7288 // + root
7289 // + scroll_parent_border
7290 // | + scroll_parent_clip
7291 // | + scroll_parent
7292 // + scroll_child
7293 //
loysoa6edaaff2015-05-25 03:26:447294 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7295 scoped_refptr<Layer> scroll_parent_border = Layer::Create(layer_settings());
7296 scoped_refptr<Layer> scroll_parent_clip = Layer::Create(layer_settings());
[email protected]995708c52013-10-17 20:52:597297 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
loysoa6edaaff2015-05-25 03:26:447298 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597299 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
loysoa6edaaff2015-05-25 03:26:447300 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597301
7302 root->AddChild(scroll_child);
7303
7304 root->AddChild(scroll_parent_border);
7305 scroll_parent_border->AddChild(scroll_parent_clip);
7306 scroll_parent_clip->AddChild(scroll_parent);
7307
7308 scroll_parent_clip->SetMasksToBounds(true);
7309
7310 scroll_child->SetScrollParent(scroll_parent.get());
7311
7312 gfx::Transform identity_transform;
7313 SetLayerPropertiesForTesting(root.get(),
7314 identity_transform,
[email protected]a2566412014-06-05 03:14:207315 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597316 gfx::PointF(),
7317 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577318 true,
[email protected]995708c52013-10-17 20:52:597319 false);
7320 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7321 identity_transform,
[email protected]a2566412014-06-05 03:14:207322 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597323 gfx::PointF(),
7324 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577325 true,
[email protected]995708c52013-10-17 20:52:597326 false);
7327 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7328 identity_transform,
[email protected]a2566412014-06-05 03:14:207329 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597330 gfx::PointF(),
7331 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577332 true,
[email protected]995708c52013-10-17 20:52:597333 false);
7334 SetLayerPropertiesForTesting(scroll_parent.get(),
7335 identity_transform,
[email protected]a2566412014-06-05 03:14:207336 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597337 gfx::PointF(),
7338 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577339 true,
[email protected]995708c52013-10-17 20:52:597340 false);
7341 SetLayerPropertiesForTesting(scroll_child.get(),
7342 identity_transform,
[email protected]a2566412014-06-05 03:14:207343 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597344 gfx::PointF(),
7345 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577346 true,
[email protected]995708c52013-10-17 20:52:597347 false);
7348
enne2097cab2014-09-25 20:16:317349 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597350 host->SetRootLayer(root);
7351
7352 ExecuteCalculateDrawProperties(root.get());
7353
7354 EXPECT_TRUE(root->render_surface());
7355
7356 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7357 scroll_child->clip_rect().ToString());
7358 EXPECT_TRUE(scroll_child->is_clipped());
7359}
7360
[email protected]08bdf1b2014-04-16 23:23:297361TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
7362 scoped_refptr<LayerWithForcedDrawsContent> root =
loysoa6edaaff2015-05-25 03:26:447363 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]08bdf1b2014-04-16 23:23:297364 scoped_refptr<LayerWithForcedDrawsContent> parent =
loysoa6edaaff2015-05-25 03:26:447365 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]08bdf1b2014-04-16 23:23:297366 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:447367 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]08bdf1b2014-04-16 23:23:297368
7369 root->AddChild(parent);
7370 parent->AddChild(child);
7371
7372 gfx::Transform identity_transform;
7373 SetLayerPropertiesForTesting(root.get(),
7374 identity_transform,
[email protected]a2566412014-06-05 03:14:207375 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297376 gfx::PointF(),
7377 gfx::Size(50, 50),
7378 true,
7379 true);
7380 root->SetForceRenderSurface(true);
7381 SetLayerPropertiesForTesting(parent.get(),
7382 identity_transform,
[email protected]a2566412014-06-05 03:14:207383 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297384 gfx::PointF(),
7385 gfx::Size(30, 30),
7386 true,
7387 true);
7388 parent->SetForceRenderSurface(true);
7389 SetLayerPropertiesForTesting(child.get(),
7390 identity_transform,
[email protected]a2566412014-06-05 03:14:207391 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297392 gfx::PointF(),
7393 gfx::Size(20, 20),
7394 true,
7395 true);
7396 child->SetForceRenderSurface(true);
7397
enne2097cab2014-09-25 20:16:317398 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]08bdf1b2014-04-16 23:23:297399 host->SetRootLayer(root);
7400
7401 ExecuteCalculateDrawProperties(root.get());
7402
7403 EXPECT_EQ(3u, render_surface_layer_list()->size());
7404
7405 gfx::Transform singular_transform;
7406 singular_transform.Scale3d(
7407 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
7408
7409 child->SetTransform(singular_transform);
7410
7411 ExecuteCalculateDrawProperties(root.get());
7412
7413 EXPECT_EQ(2u, render_surface_layer_list()->size());
7414
7415 // Ensure that the entire subtree under a layer with singular transform does
7416 // not get rendered.
7417 parent->SetTransform(singular_transform);
7418 child->SetTransform(identity_transform);
7419
7420 ExecuteCalculateDrawProperties(root.get());
7421
7422 EXPECT_EQ(1u, render_surface_layer_list()->size());
7423}
7424
[email protected]995708c52013-10-17 20:52:597425TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
7426 // Checks that clipping by a scroll parent that follows you in paint order
7427 // still results in correct clipping.
7428 //
7429 // + root
7430 // + scroll_child
7431 // + scroll_parent_border
7432 // + scroll_parent_clip
7433 // + scroll_parent
7434 //
loysoa6edaaff2015-05-25 03:26:447435 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7436 scoped_refptr<Layer> scroll_parent_border = Layer::Create(layer_settings());
7437 scoped_refptr<Layer> scroll_parent_clip = Layer::Create(layer_settings());
[email protected]995708c52013-10-17 20:52:597438 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
loysoa6edaaff2015-05-25 03:26:447439 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597440 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
loysoa6edaaff2015-05-25 03:26:447441 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597442
7443 root->AddChild(scroll_parent_border);
7444 scroll_parent_border->AddChild(scroll_parent_clip);
7445 scroll_parent_clip->AddChild(scroll_parent);
7446
7447 root->AddChild(scroll_child);
7448
7449 scroll_parent_clip->SetMasksToBounds(true);
7450
7451 scroll_child->SetScrollParent(scroll_parent.get());
7452
7453 gfx::Transform identity_transform;
7454 SetLayerPropertiesForTesting(root.get(),
7455 identity_transform,
[email protected]a2566412014-06-05 03:14:207456 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597457 gfx::PointF(),
7458 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577459 true,
[email protected]995708c52013-10-17 20:52:597460 false);
7461 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7462 identity_transform,
[email protected]a2566412014-06-05 03:14:207463 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597464 gfx::PointF(),
7465 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577466 true,
[email protected]995708c52013-10-17 20:52:597467 false);
7468 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7469 identity_transform,
[email protected]a2566412014-06-05 03:14:207470 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597471 gfx::PointF(),
7472 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577473 true,
[email protected]995708c52013-10-17 20:52:597474 false);
7475 SetLayerPropertiesForTesting(scroll_parent.get(),
7476 identity_transform,
[email protected]a2566412014-06-05 03:14:207477 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597478 gfx::PointF(),
7479 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577480 true,
[email protected]995708c52013-10-17 20:52:597481 false);
7482 SetLayerPropertiesForTesting(scroll_child.get(),
7483 identity_transform,
[email protected]a2566412014-06-05 03:14:207484 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597485 gfx::PointF(),
7486 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577487 true,
[email protected]995708c52013-10-17 20:52:597488 false);
7489
enne2097cab2014-09-25 20:16:317490 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597491 host->SetRootLayer(root);
7492
7493 ExecuteCalculateDrawProperties(root.get());
7494
7495 EXPECT_TRUE(root->render_surface());
7496
7497 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7498 scroll_child->clip_rect().ToString());
7499 EXPECT_TRUE(scroll_child->is_clipped());
7500}
7501
7502TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
7503 // Checks that clipping by a scroll parent and scroll grandparent that follow
7504 // you in paint order still results in correct clipping.
7505 //
7506 // + root
7507 // + scroll_child
7508 // + scroll_parent_border
7509 // | + scroll_parent_clip
7510 // | + scroll_parent
7511 // + scroll_grandparent_border
7512 // + scroll_grandparent_clip
7513 // + scroll_grandparent
7514 //
loysoa6edaaff2015-05-25 03:26:447515 scoped_refptr<Layer> root = Layer::Create(layer_settings());
7516 scoped_refptr<Layer> scroll_parent_border = Layer::Create(layer_settings());
7517 scoped_refptr<Layer> scroll_parent_clip = Layer::Create(layer_settings());
[email protected]995708c52013-10-17 20:52:597518 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
loysoa6edaaff2015-05-25 03:26:447519 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597520
loysoa6edaaff2015-05-25 03:26:447521 scoped_refptr<Layer> scroll_grandparent_border =
7522 Layer::Create(layer_settings());
7523 scoped_refptr<Layer> scroll_grandparent_clip =
7524 Layer::Create(layer_settings());
[email protected]995708c52013-10-17 20:52:597525 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
loysoa6edaaff2015-05-25 03:26:447526 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597527
7528 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
loysoa6edaaff2015-05-25 03:26:447529 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597530
7531 root->AddChild(scroll_child);
7532
7533 root->AddChild(scroll_parent_border);
7534 scroll_parent_border->AddChild(scroll_parent_clip);
7535 scroll_parent_clip->AddChild(scroll_parent);
7536
7537 root->AddChild(scroll_grandparent_border);
7538 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
7539 scroll_grandparent_clip->AddChild(scroll_grandparent);
7540
7541 scroll_parent_clip->SetMasksToBounds(true);
7542 scroll_grandparent_clip->SetMasksToBounds(true);
7543
7544 scroll_child->SetScrollParent(scroll_parent.get());
7545 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
7546
7547 gfx::Transform identity_transform;
7548 SetLayerPropertiesForTesting(root.get(),
7549 identity_transform,
[email protected]a2566412014-06-05 03:14:207550 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597551 gfx::PointF(),
7552 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577553 true,
[email protected]995708c52013-10-17 20:52:597554 false);
7555 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
7556 identity_transform,
[email protected]a2566412014-06-05 03:14:207557 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597558 gfx::PointF(),
7559 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577560 true,
[email protected]995708c52013-10-17 20:52:597561 false);
7562 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
7563 identity_transform,
[email protected]a2566412014-06-05 03:14:207564 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597565 gfx::PointF(),
7566 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577567 true,
[email protected]995708c52013-10-17 20:52:597568 false);
7569 SetLayerPropertiesForTesting(scroll_grandparent.get(),
7570 identity_transform,
[email protected]a2566412014-06-05 03:14:207571 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597572 gfx::PointF(),
7573 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577574 true,
[email protected]995708c52013-10-17 20:52:597575 false);
7576 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7577 identity_transform,
[email protected]a2566412014-06-05 03:14:207578 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597579 gfx::PointF(),
7580 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577581 true,
[email protected]995708c52013-10-17 20:52:597582 false);
7583 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7584 identity_transform,
[email protected]a2566412014-06-05 03:14:207585 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597586 gfx::PointF(),
7587 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577588 true,
[email protected]995708c52013-10-17 20:52:597589 false);
7590 SetLayerPropertiesForTesting(scroll_parent.get(),
7591 identity_transform,
[email protected]a2566412014-06-05 03:14:207592 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597593 gfx::PointF(),
7594 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577595 true,
[email protected]995708c52013-10-17 20:52:597596 false);
7597 SetLayerPropertiesForTesting(scroll_child.get(),
7598 identity_transform,
[email protected]a2566412014-06-05 03:14:207599 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597600 gfx::PointF(),
7601 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577602 true,
[email protected]995708c52013-10-17 20:52:597603 false);
7604
enne2097cab2014-09-25 20:16:317605 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597606 host->SetRootLayer(root);
7607
7608 ExecuteCalculateDrawProperties(root.get());
7609
7610 EXPECT_TRUE(root->render_surface());
7611
7612 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7613 scroll_child->clip_rect().ToString());
7614 EXPECT_TRUE(scroll_child->is_clipped());
7615
7616 // Despite the fact that we visited the above layers out of order to get the
7617 // correct clip, the layer lists should be unaffected.
7618 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
7619 EXPECT_EQ(scroll_child.get(),
Daniel Chengeea98042014-08-26 00:28:107620 root->render_surface()->layer_list().at(0).get());
[email protected]995708c52013-10-17 20:52:597621 EXPECT_EQ(scroll_parent.get(),
Daniel Chengeea98042014-08-26 00:28:107622 root->render_surface()->layer_list().at(1).get());
[email protected]995708c52013-10-17 20:52:597623 EXPECT_EQ(scroll_grandparent.get(),
Daniel Chengeea98042014-08-26 00:28:107624 root->render_surface()->layer_list().at(2).get());
[email protected]995708c52013-10-17 20:52:597625}
7626
7627TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
7628 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:227629 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:597630 // + root
7631 // + scroll_child
7632 // + scroll_parent_border
7633 // + scroll_parent_clip
7634 // + scroll_parent
7635 // + render_surface1
7636 // + scroll_grandparent_border
7637 // + scroll_grandparent_clip
7638 // + scroll_grandparent
7639 // + render_surface2
7640 //
[email protected]44d8e84c2013-10-19 19:13:227641 scoped_refptr<LayerWithForcedDrawsContent> root =
loysoa6edaaff2015-05-25 03:26:447642 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597643
loysoa6edaaff2015-05-25 03:26:447644 scoped_refptr<Layer> scroll_parent_border = Layer::Create(layer_settings());
7645 scoped_refptr<Layer> scroll_parent_clip = Layer::Create(layer_settings());
[email protected]995708c52013-10-17 20:52:597646 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
loysoa6edaaff2015-05-25 03:26:447647 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597648 scoped_refptr<LayerWithForcedDrawsContent> render_surface1 =
loysoa6edaaff2015-05-25 03:26:447649 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597650
loysoa6edaaff2015-05-25 03:26:447651 scoped_refptr<Layer> scroll_grandparent_border =
7652 Layer::Create(layer_settings());
7653 scoped_refptr<Layer> scroll_grandparent_clip =
7654 Layer::Create(layer_settings());
[email protected]995708c52013-10-17 20:52:597655 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
loysoa6edaaff2015-05-25 03:26:447656 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597657 scoped_refptr<LayerWithForcedDrawsContent> render_surface2 =
loysoa6edaaff2015-05-25 03:26:447658 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597659
7660 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
loysoa6edaaff2015-05-25 03:26:447661 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
[email protected]995708c52013-10-17 20:52:597662
7663 root->AddChild(scroll_child);
7664
7665 root->AddChild(scroll_parent_border);
7666 scroll_parent_border->AddChild(scroll_parent_clip);
7667 scroll_parent_clip->AddChild(scroll_parent);
7668 scroll_parent->AddChild(render_surface2);
7669
7670 root->AddChild(scroll_grandparent_border);
7671 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
7672 scroll_grandparent_clip->AddChild(scroll_grandparent);
7673 scroll_grandparent->AddChild(render_surface1);
7674
7675 scroll_parent_clip->SetMasksToBounds(true);
7676 scroll_grandparent_clip->SetMasksToBounds(true);
7677
7678 scroll_child->SetScrollParent(scroll_parent.get());
7679 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
7680
7681 render_surface1->SetForceRenderSurface(true);
7682 render_surface2->SetForceRenderSurface(true);
7683
7684 gfx::Transform identity_transform;
7685 SetLayerPropertiesForTesting(root.get(),
7686 identity_transform,
[email protected]a2566412014-06-05 03:14:207687 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597688 gfx::PointF(),
7689 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577690 true,
[email protected]995708c52013-10-17 20:52:597691 false);
7692 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
7693 identity_transform,
[email protected]a2566412014-06-05 03:14:207694 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597695 gfx::PointF(),
7696 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577697 true,
[email protected]995708c52013-10-17 20:52:597698 false);
7699 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
7700 identity_transform,
[email protected]a2566412014-06-05 03:14:207701 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597702 gfx::PointF(),
7703 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577704 true,
[email protected]995708c52013-10-17 20:52:597705 false);
7706 SetLayerPropertiesForTesting(scroll_grandparent.get(),
7707 identity_transform,
[email protected]a2566412014-06-05 03:14:207708 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597709 gfx::PointF(),
7710 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577711 true,
[email protected]995708c52013-10-17 20:52:597712 false);
7713 SetLayerPropertiesForTesting(render_surface1.get(),
7714 identity_transform,
[email protected]a2566412014-06-05 03:14:207715 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597716 gfx::PointF(),
7717 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577718 true,
[email protected]995708c52013-10-17 20:52:597719 false);
7720 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7721 identity_transform,
[email protected]a2566412014-06-05 03:14:207722 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597723 gfx::PointF(),
7724 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577725 true,
[email protected]995708c52013-10-17 20:52:597726 false);
7727 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7728 identity_transform,
[email protected]a2566412014-06-05 03:14:207729 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597730 gfx::PointF(),
7731 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577732 true,
[email protected]995708c52013-10-17 20:52:597733 false);
7734 SetLayerPropertiesForTesting(scroll_parent.get(),
7735 identity_transform,
[email protected]a2566412014-06-05 03:14:207736 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597737 gfx::PointF(),
7738 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577739 true,
[email protected]995708c52013-10-17 20:52:597740 false);
7741 SetLayerPropertiesForTesting(render_surface2.get(),
7742 identity_transform,
[email protected]a2566412014-06-05 03:14:207743 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597744 gfx::PointF(),
7745 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577746 true,
[email protected]995708c52013-10-17 20:52:597747 false);
7748 SetLayerPropertiesForTesting(scroll_child.get(),
7749 identity_transform,
[email protected]a2566412014-06-05 03:14:207750 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597751 gfx::PointF(),
7752 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577753 true,
[email protected]995708c52013-10-17 20:52:597754 false);
7755
enne2097cab2014-09-25 20:16:317756 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597757 host->SetRootLayer(root);
7758
7759 RenderSurfaceLayerList render_surface_layer_list;
7760 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7761 root.get(),
bokancccfde72014-10-08 15:15:227762 root->bounds(),
[email protected]995708c52013-10-17 20:52:597763 identity_transform,
7764 &render_surface_layer_list);
7765
7766 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7767
7768 EXPECT_TRUE(root->render_surface());
7769
7770 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7771 scroll_child->clip_rect().ToString());
7772 EXPECT_TRUE(scroll_child->is_clipped());
7773
7774 // Despite the fact that we had to process the layers out of order to get the
7775 // right clip, our render_surface_layer_list's order should be unaffected.
7776 EXPECT_EQ(3u, render_surface_layer_list.size());
7777 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
7778 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
7779 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
[email protected]44d8e84c2013-10-19 19:13:227780 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
7781 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
7782 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:597783}
7784
ajuma0b10f942015-03-21 07:45:537785TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
7786 // Ensures that when we have a render surface between a fixed position layer
7787 // and its container, we compute the fixed position layer's draw transform
7788 // with respect to that intervening render surface, not with respect to its
7789 // container's render target.
7790 //
7791 // + root
7792 // + render_surface
7793 // + fixed
ajuma737b2702015-05-06 01:18:377794 // + child
ajuma0b10f942015-03-21 07:45:537795 //
loysoa6edaaff2015-05-25 03:26:447796 scoped_refptr<Layer> root = Layer::Create(layer_settings());
ajuma0b10f942015-03-21 07:45:537797 scoped_refptr<LayerWithForcedDrawsContent> render_surface =
loysoa6edaaff2015-05-25 03:26:447798 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma0b10f942015-03-21 07:45:537799 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:447800 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma737b2702015-05-06 01:18:377801 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:447802 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajuma0b10f942015-03-21 07:45:537803
7804 root->AddChild(render_surface);
7805 render_surface->AddChild(fixed);
ajuma737b2702015-05-06 01:18:377806 fixed->AddChild(child);
ajuma0b10f942015-03-21 07:45:537807
7808 root->SetIsContainerForFixedPositionLayers(true);
7809 render_surface->SetForceRenderSurface(true);
7810
7811 LayerPositionConstraint constraint;
7812 constraint.set_is_fixed_position(true);
7813 fixed->SetPositionConstraint(constraint);
7814
7815 SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(),
7816 gfx::PointF(), gfx::Size(50, 50), true, false);
7817 SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(),
7818 gfx::Point3F(), gfx::PointF(7.f, 9.f),
7819 gfx::Size(50, 50), true, false);
7820 SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(),
7821 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true,
7822 false);
ajuma737b2702015-05-06 01:18:377823 SetLayerPropertiesForTesting(child.get(), gfx::Transform(), gfx::Point3F(),
7824 gfx::PointF(1.f, 2.f), gfx::Size(50, 50), true,
7825 false);
ajuma0b10f942015-03-21 07:45:537826
7827 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
7828 host->SetRootLayer(root);
7829
7830 ExecuteCalculateDrawProperties(root.get());
7831
ajuma737b2702015-05-06 01:18:377832 gfx::Transform expected_fixed_draw_transform;
7833 expected_fixed_draw_transform.Translate(10.f, 15.f);
7834 EXPECT_EQ(expected_fixed_draw_transform, fixed->draw_transform());
ajuma0b10f942015-03-21 07:45:537835
ajuma737b2702015-05-06 01:18:377836 gfx::Transform expected_fixed_screen_space_transform;
7837 expected_fixed_screen_space_transform.Translate(17.f, 24.f);
7838 EXPECT_EQ(expected_fixed_screen_space_transform,
7839 fixed->screen_space_transform());
7840
7841 gfx::Transform expected_child_draw_transform;
7842 expected_child_draw_transform.Translate(11.f, 17.f);
7843 EXPECT_EQ(expected_child_draw_transform, child->draw_transform());
7844
7845 gfx::Transform expected_child_screen_space_transform;
7846 expected_child_screen_space_transform.Translate(18.f, 26.f);
7847 EXPECT_EQ(expected_child_screen_space_transform,
7848 child->screen_space_transform());
ajuma0b10f942015-03-21 07:45:537849}
7850
[email protected]d81752b2013-10-25 08:32:237851TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
7852 // This test verifies that a scrolling layer that gets snapped to
7853 // integer coordinates doesn't move a fixed position child.
7854 //
7855 // + root
7856 // + container
7857 // + scroller
7858 // + fixed
7859 //
7860 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457861 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:477862 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]d81752b2013-10-25 08:32:237863 host_impl.CreatePendingTree();
7864 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7865 scoped_ptr<LayerImpl> container =
7866 LayerImpl::Create(host_impl.active_tree(), 2);
7867 LayerImpl* container_layer = container.get();
7868 scoped_ptr<LayerImpl> scroller =
7869 LayerImpl::Create(host_impl.active_tree(), 3);
7870 LayerImpl* scroll_layer = scroller.get();
7871 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7872 LayerImpl* fixed_layer = fixed.get();
7873
7874 container->SetIsContainerForFixedPositionLayers(true);
7875
7876 LayerPositionConstraint constraint;
7877 constraint.set_is_fixed_position(true);
7878 fixed->SetPositionConstraint(constraint);
7879
[email protected]adeda572014-01-31 00:49:477880 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:237881
7882 gfx::Transform identity_transform;
7883 gfx::Transform container_transform;
7884 container_transform.Translate3d(10.0, 20.0, 0.0);
7885 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7886
awoloszyne83f28c2014-12-22 15:40:007887 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7888 gfx::PointF(), gfx::Size(50, 50), true, false,
7889 true);
7890 SetLayerPropertiesForTesting(container.get(), container_transform,
7891 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7892 true, false, false);
7893 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7894 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7895 true, false, false);
7896 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7897 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]d81752b2013-10-25 08:32:237898 false);
7899
7900 scroller->AddChild(fixed.Pass());
7901 container->AddChild(scroller.Pass());
7902 root->AddChild(container.Pass());
7903
7904 // Rounded to integers already.
7905 {
7906 gfx::Vector2dF scroll_delta(3.0, 5.0);
7907 scroll_layer->SetScrollDelta(scroll_delta);
7908
7909 LayerImplList render_surface_layer_list;
7910 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227911 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]d81752b2013-10-25 08:32:237912 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7913
7914 EXPECT_TRANSFORMATION_MATRIX_EQ(
7915 container_layer->draw_properties().screen_space_transform,
7916 fixed_layer->draw_properties().screen_space_transform);
7917 EXPECT_VECTOR_EQ(
7918 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7919 container_offset);
7920 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7921 .screen_space_transform.To2dTranslation(),
7922 container_offset - scroll_delta);
7923 }
7924
7925 // Scroll delta requiring rounding.
7926 {
7927 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
7928 scroll_layer->SetScrollDelta(scroll_delta);
7929
7930 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
7931
7932 LayerImplList render_surface_layer_list;
7933 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227934 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]d81752b2013-10-25 08:32:237935 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7936
7937 EXPECT_TRANSFORMATION_MATRIX_EQ(
7938 container_layer->draw_properties().screen_space_transform,
7939 fixed_layer->draw_properties().screen_space_transform);
7940 EXPECT_VECTOR_EQ(
7941 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7942 container_offset);
7943 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7944 .screen_space_transform.To2dTranslation(),
7945 container_offset - rounded_scroll_delta);
7946 }
[email protected]cf15ad7b2014-04-02 03:59:267947
7948 // Scale is applied earlier in the tree.
7949 {
7950 gfx::Transform scaled_container_transform = container_transform;
7951 scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
7952 container_layer->SetTransform(scaled_container_transform);
7953
7954 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7955 scroll_layer->SetScrollDelta(scroll_delta);
7956
7957 LayerImplList render_surface_layer_list;
7958 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227959 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]cf15ad7b2014-04-02 03:59:267960 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7961
7962 EXPECT_TRANSFORMATION_MATRIX_EQ(
7963 container_layer->draw_properties().screen_space_transform,
7964 fixed_layer->draw_properties().screen_space_transform);
7965 EXPECT_VECTOR_EQ(
7966 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7967 container_offset);
7968
7969 container_layer->SetTransform(container_transform);
7970 }
7971
7972 // Scale is applied on the scroll layer itself.
7973 {
7974 gfx::Transform scale_transform;
7975 scale_transform.Scale3d(3.0, 3.0, 1.0);
7976 scroll_layer->SetTransform(scale_transform);
7977
7978 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7979 scroll_layer->SetScrollDelta(scroll_delta);
7980
7981 LayerImplList render_surface_layer_list;
7982 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227983 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]cf15ad7b2014-04-02 03:59:267984 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7985
7986 EXPECT_VECTOR_EQ(
7987 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7988 container_offset);
7989
7990 scroll_layer->SetTransform(identity_transform);
7991 }
[email protected]d81752b2013-10-25 08:32:237992}
7993
miletus2c78036b2015-01-29 20:52:377994TEST_F(LayerTreeHostCommonTest,
7995 ScrollCompensationMainScrollOffsetFractionalPart) {
7996 // This test verifies that a scrolling layer that has fractional scroll offset
7997 // from main doesn't move a fixed position child.
7998 //
7999 // + root
8000 // + container
8001 // + scroller
8002 // + fixed
8003 //
8004 FakeImplProxy proxy;
8005 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:478006 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
miletus2c78036b2015-01-29 20:52:378007 host_impl.CreatePendingTree();
8008 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
8009 scoped_ptr<LayerImpl> container =
8010 LayerImpl::Create(host_impl.active_tree(), 2);
8011 LayerImpl* container_layer = container.get();
8012 scoped_ptr<LayerImpl> scroller =
8013 LayerImpl::Create(host_impl.active_tree(), 3);
8014 LayerImpl* scroll_layer = scroller.get();
8015 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
8016 LayerImpl* fixed_layer = fixed.get();
8017
8018 container->SetIsContainerForFixedPositionLayers(true);
8019
8020 LayerPositionConstraint constraint;
8021 constraint.set_is_fixed_position(true);
8022 fixed->SetPositionConstraint(constraint);
8023
8024 scroller->SetScrollClipLayer(container->id());
8025
8026 gfx::Transform identity_transform;
8027 gfx::Transform container_transform;
8028 container_transform.Translate3d(10.0, 20.0, 0.0);
8029 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
8030
8031 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8032 gfx::PointF(), gfx::Size(50, 50), true, false,
8033 true);
8034 SetLayerPropertiesForTesting(container.get(), container_transform,
8035 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
8036 true, false, false);
8037 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
8038 gfx::Point3F(), gfx::PointF(0.0, 0.0),
8039 gfx::Size(30, 30), true, false, false);
8040
8041 gfx::ScrollOffset scroll_offset(3.3, 4.2);
8042 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f);
8043 gfx::Vector2dF scroll_delta(0.1f, 0.4f);
8044 // Blink only uses the integer part of the scroll_offset for fixed
8045 // position layer.
8046 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
8047 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true,
8048 false, false);
aeliasf998da82015-02-03 01:40:518049 scroll_layer->PushScrollOffsetFromMainThread(scroll_offset);
aeliasd0070ba2015-01-31 13:44:498050 scroll_layer->SetScrollDelta(scroll_delta);
miletusff93ab72015-01-30 04:30:448051 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part);
miletus2c78036b2015-01-29 20:52:378052
8053 scroller->AddChild(fixed.Pass());
8054 container->AddChild(scroller.Pass());
8055 root->AddChild(container.Pass());
8056
8057 LayerImplList render_surface_layer_list;
8058 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8059 root.get(), root->bounds(), &render_surface_layer_list);
8060 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8061
8062 EXPECT_TRANSFORMATION_MATRIX_EQ(
8063 container_layer->draw_properties().screen_space_transform,
8064 fixed_layer->draw_properties().screen_space_transform);
8065 EXPECT_VECTOR_EQ(
8066 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
8067 container_offset);
8068
8069 gfx::ScrollOffset effective_scroll_offset =
8070 ScrollOffsetWithDelta(scroll_offset, scroll_delta);
8071 gfx::Vector2d rounded_effective_scroll_offset =
8072 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset));
8073 EXPECT_VECTOR_EQ(
8074 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(),
8075 container_offset - rounded_effective_scroll_offset);
8076}
8077
[email protected]1c3626e2014-04-09 17:49:228078class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
8079 public:
8080 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
8081 LayerTreeImpl* tree_impl,
8082 int id) {
8083 return make_scoped_ptr(
8084 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
8085 }
8086
dcheng716bedf2014-10-21 09:51:088087 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:228088
[email protected]1c3626e2014-04-09 17:49:228089 private:
8090 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
8091 int id)
[email protected]a57cb8b12014-06-13 18:15:378092 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:228093 SetDrawsContent(true);
8094 }
[email protected]1c3626e2014-04-09 17:49:228095};
8096
8097TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
8098 FakeImplProxy proxy;
8099 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:478100 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]1c3626e2014-04-09 17:49:228101 gfx::Transform identity_matrix;
8102 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
8103 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
8104 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
8105 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
8106 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
8107 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
8108 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
8109 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
8110
8111 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
8112 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
8113 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
8114
danakjf446a072014-09-27 21:55:488115 child->AddChild(grand_child.Pass());
8116 parent->AddChild(child.Pass());
8117 grand_parent->AddChild(parent.Pass());
[email protected]1c3626e2014-04-09 17:49:228118
awoloszyne83f28c2014-12-22 15:40:008119 SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix,
8120 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8121 true, false, true);
8122 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
8123 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:228124 false);
awoloszyne83f28c2014-12-22 15:40:008125 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
8126 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:228127 false);
awoloszyne83f28c2014-12-22 15:40:008128
8129 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
8130 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:228131 false);
8132
8133 ExecuteCalculateDrawProperties(grand_parent.get());
8134
8135 // No layers have animations.
[email protected]a57cb8b12014-06-13 18:15:378136 EXPECT_EQ(0.f,
8137 grand_parent->draw_properties().maximum_animation_contents_scale);
8138 EXPECT_EQ(0.f,
8139 parent_raw->draw_properties().maximum_animation_contents_scale);
8140 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8141 EXPECT_EQ(
8142 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228143
8144 TransformOperations translation;
8145 translation.AppendTranslate(1.f, 2.f, 3.f);
8146
8147 AddAnimatedTransformToLayer(
8148 parent_raw, 1.0, TransformOperations(), translation);
8149
8150 // No layers have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:378151 EXPECT_EQ(0.f,
8152 grand_parent->draw_properties().maximum_animation_contents_scale);
8153 EXPECT_EQ(0.f,
8154 parent_raw->draw_properties().maximum_animation_contents_scale);
8155 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8156 EXPECT_EQ(
8157 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228158
8159 TransformOperations scale;
8160 scale.AppendScale(5.f, 4.f, 3.f);
8161
8162 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
8163 ExecuteCalculateDrawProperties(grand_parent.get());
8164
8165 // Only |child| has a scale-affecting animation.
[email protected]a57cb8b12014-06-13 18:15:378166 EXPECT_EQ(0.f,
8167 grand_parent->draw_properties().maximum_animation_contents_scale);
8168 EXPECT_EQ(0.f,
8169 parent_raw->draw_properties().maximum_animation_contents_scale);
8170 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
8171 EXPECT_EQ(
8172 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228173
8174 AddAnimatedTransformToLayer(
8175 grand_parent.get(), 1.0, TransformOperations(), scale);
8176 ExecuteCalculateDrawProperties(grand_parent.get());
8177
8178 // |grand_parent| and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:378179 EXPECT_EQ(5.f,
8180 grand_parent->draw_properties().maximum_animation_contents_scale);
8181 EXPECT_EQ(5.f,
8182 parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228183 // We don't support combining animated scales from two nodes; 0.f means
8184 // that the maximum scale could not be computed.
[email protected]a57cb8b12014-06-13 18:15:378185 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8186 EXPECT_EQ(
8187 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228188
8189 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
8190 ExecuteCalculateDrawProperties(grand_parent.get());
8191
8192 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:378193 EXPECT_EQ(5.f,
8194 grand_parent->draw_properties().maximum_animation_contents_scale);
8195 EXPECT_EQ(0.f,
8196 parent_raw->draw_properties().maximum_animation_contents_scale);
8197 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8198 EXPECT_EQ(
8199 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228200
8201 grand_parent->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388202 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228203 parent_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388204 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228205 child_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388206 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228207
8208 TransformOperations perspective;
8209 perspective.AppendPerspective(10.f);
8210
8211 AddAnimatedTransformToLayer(
8212 child_raw, 1.0, TransformOperations(), perspective);
8213 ExecuteCalculateDrawProperties(grand_parent.get());
8214
8215 // |child| has a scale-affecting animation but computing the maximum of this
8216 // animation is not supported.
[email protected]a57cb8b12014-06-13 18:15:378217 EXPECT_EQ(0.f,
8218 grand_parent->draw_properties().maximum_animation_contents_scale);
8219 EXPECT_EQ(0.f,
8220 parent_raw->draw_properties().maximum_animation_contents_scale);
8221 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8222 EXPECT_EQ(
8223 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228224
8225 child_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388226 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228227
8228 gfx::Transform scale_matrix;
8229 scale_matrix.Scale(1.f, 2.f);
8230 grand_parent->SetTransform(scale_matrix);
8231 parent_raw->SetTransform(scale_matrix);
8232 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
8233 ExecuteCalculateDrawProperties(grand_parent.get());
8234
8235 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
8236 // animation with maximum scale 5.f.
[email protected]a57cb8b12014-06-13 18:15:378237 EXPECT_EQ(0.f,
8238 grand_parent->draw_properties().maximum_animation_contents_scale);
8239 EXPECT_EQ(10.f,
8240 parent_raw->draw_properties().maximum_animation_contents_scale);
8241 EXPECT_EQ(10.f,
8242 child_raw->draw_properties().maximum_animation_contents_scale);
8243 EXPECT_EQ(
8244 10.f,
8245 grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228246
8247 gfx::Transform perspective_matrix;
8248 perspective_matrix.ApplyPerspectiveDepth(2.f);
8249 child_raw->SetTransform(perspective_matrix);
8250 ExecuteCalculateDrawProperties(grand_parent.get());
8251
8252 // |child| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:378253 EXPECT_EQ(0.f,
8254 grand_parent->draw_properties().maximum_animation_contents_scale);
8255 EXPECT_EQ(10.f,
8256 parent_raw->draw_properties().maximum_animation_contents_scale);
8257 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8258 EXPECT_EQ(
8259 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228260
8261 parent_raw->SetTransform(perspective_matrix);
8262 ExecuteCalculateDrawProperties(grand_parent.get());
8263
8264 // |parent| and |child| have transforms that are neither translations nor
8265 // scales.
[email protected]a57cb8b12014-06-13 18:15:378266 EXPECT_EQ(0.f,
8267 grand_parent->draw_properties().maximum_animation_contents_scale);
8268 EXPECT_EQ(0.f,
8269 parent_raw->draw_properties().maximum_animation_contents_scale);
8270 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8271 EXPECT_EQ(
8272 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228273
8274 parent_raw->SetTransform(identity_matrix);
8275 child_raw->SetTransform(identity_matrix);
8276 grand_parent->SetTransform(perspective_matrix);
8277
8278 ExecuteCalculateDrawProperties(grand_parent.get());
8279
8280 // |grand_parent| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:378281 EXPECT_EQ(0.f,
8282 grand_parent->draw_properties().maximum_animation_contents_scale);
8283 EXPECT_EQ(0.f,
8284 parent_raw->draw_properties().maximum_animation_contents_scale);
8285 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8286 EXPECT_EQ(
8287 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228288}
8289
[email protected]390bb1ff2014-05-09 17:14:408290static int membership_id(LayerImpl* layer) {
8291 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
8292}
8293
8294static void GatherDrawnLayers(LayerImplList* rsll,
8295 std::set<LayerImpl*>* drawn_layers) {
8296 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll),
8297 end = LayerIterator<LayerImpl>::End(rsll);
8298 it != end;
8299 ++it) {
8300 LayerImpl* layer = *it;
8301 if (it.represents_itself())
8302 drawn_layers->insert(layer);
8303
8304 if (!it.represents_contributing_render_surface())
8305 continue;
8306
8307 if (layer->mask_layer())
8308 drawn_layers->insert(layer->mask_layer());
8309 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
8310 drawn_layers->insert(layer->replica_layer()->mask_layer());
8311 }
8312}
8313
8314TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
8315 FakeImplProxy proxy;
8316 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:478317 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]390bb1ff2014-05-09 17:14:408318 gfx::Transform identity_matrix;
8319
8320 scoped_ptr<LayerImpl> grand_parent =
8321 LayerImpl::Create(host_impl.active_tree(), 1);
8322 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
8323 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
8324 scoped_ptr<LayerImpl> grand_child1 =
8325 LayerImpl::Create(host_impl.active_tree(), 7);
8326 scoped_ptr<LayerImpl> grand_child2 =
8327 LayerImpl::Create(host_impl.active_tree(), 9);
8328
8329 LayerImpl* grand_parent_raw = grand_parent.get();
8330 LayerImpl* parent_raw = parent.get();
8331 LayerImpl* child_raw = child.get();
8332 LayerImpl* grand_child1_raw = grand_child1.get();
8333 LayerImpl* grand_child2_raw = grand_child2.get();
8334
8335 child->AddChild(grand_child1.Pass());
8336 child->AddChild(grand_child2.Pass());
8337 parent->AddChild(child.Pass());
8338 grand_parent->AddChild(parent.Pass());
8339
awoloszyne83f28c2014-12-22 15:40:008340 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
8341 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8342 true, false, true);
8343 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
8344 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:408345 false);
awoloszyne83f28c2014-12-22 15:40:008346
8347 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
8348 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:408349 false);
awoloszyne83f28c2014-12-22 15:40:008350
8351 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
8352 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8353 true, false, false);
8354
8355 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
8356 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8357 true, false, false);
[email protected]390bb1ff2014-05-09 17:14:408358
8359 // Start with nothing being drawn.
8360 ExecuteCalculateDrawProperties(grand_parent_raw);
8361 int member_id = render_surface_layer_list_count();
8362
8363 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8364 EXPECT_NE(member_id, membership_id(parent_raw));
8365 EXPECT_NE(member_id, membership_id(child_raw));
8366 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8367 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8368
8369 std::set<LayerImpl*> expected;
8370 std::set<LayerImpl*> actual;
8371 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8372 EXPECT_EQ(expected, actual);
8373
8374 // If we force render surface, but none of the layers are in the layer list,
8375 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:008376 grand_child1_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:408377
8378 ExecuteCalculateDrawProperties(grand_parent_raw);
8379 member_id = render_surface_layer_list_count();
8380
8381 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8382 EXPECT_NE(member_id, membership_id(parent_raw));
8383 EXPECT_NE(member_id, membership_id(child_raw));
8384 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8385 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8386
8387 expected.clear();
8388 actual.clear();
8389 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8390 EXPECT_EQ(expected, actual);
8391
8392 // However, if we say that this layer also draws content, it will appear in
8393 // RSLL.
8394 grand_child1_raw->SetDrawsContent(true);
8395
8396 ExecuteCalculateDrawProperties(grand_parent_raw);
8397 member_id = render_surface_layer_list_count();
8398
8399 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8400 EXPECT_NE(member_id, membership_id(parent_raw));
8401 EXPECT_NE(member_id, membership_id(child_raw));
8402 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
8403 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8404
8405 expected.clear();
8406 expected.insert(grand_child1_raw);
8407
8408 actual.clear();
8409 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8410 EXPECT_EQ(expected, actual);
8411
8412 // Now child is forced to have a render surface, and one if its children draws
8413 // content.
8414 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:008415 grand_child1_raw->SetHasRenderSurface(false);
8416 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:408417 grand_child2_raw->SetDrawsContent(true);
8418
8419 ExecuteCalculateDrawProperties(grand_parent_raw);
8420 member_id = render_surface_layer_list_count();
8421
8422 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8423 EXPECT_NE(member_id, membership_id(parent_raw));
8424 EXPECT_NE(member_id, membership_id(child_raw));
8425 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8426 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8427
8428 expected.clear();
8429 expected.insert(grand_child2_raw);
8430
8431 actual.clear();
8432 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8433 EXPECT_EQ(expected, actual);
8434
8435 // Add a mask layer to child.
8436 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass());
8437
8438 ExecuteCalculateDrawProperties(grand_parent_raw);
8439 member_id = render_surface_layer_list_count();
8440
8441 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8442 EXPECT_NE(member_id, membership_id(parent_raw));
8443 EXPECT_NE(member_id, membership_id(child_raw));
8444 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8445 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8446 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8447
8448 expected.clear();
8449 expected.insert(grand_child2_raw);
8450 expected.insert(child_raw->mask_layer());
8451
8452 expected.clear();
8453 expected.insert(grand_child2_raw);
8454 expected.insert(child_raw->mask_layer());
8455
8456 actual.clear();
8457 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8458 EXPECT_EQ(expected, actual);
8459
8460 // Add replica mask layer.
8461 scoped_ptr<LayerImpl> replica_layer =
8462 LayerImpl::Create(host_impl.active_tree(), 20);
8463 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
8464 child_raw->SetReplicaLayer(replica_layer.Pass());
8465
8466 ExecuteCalculateDrawProperties(grand_parent_raw);
8467 member_id = render_surface_layer_list_count();
8468
8469 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8470 EXPECT_NE(member_id, membership_id(parent_raw));
8471 EXPECT_NE(member_id, membership_id(child_raw));
8472 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8473 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
8474 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8475 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8476
8477 expected.clear();
8478 expected.insert(grand_child2_raw);
8479 expected.insert(child_raw->mask_layer());
8480 expected.insert(child_raw->replica_layer()->mask_layer());
8481
8482 actual.clear();
8483 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8484 EXPECT_EQ(expected, actual);
8485
8486 child_raw->TakeReplicaLayer();
8487
8488 // With nothing drawing, we should have no layers.
8489 grand_child2_raw->SetDrawsContent(false);
8490
8491 ExecuteCalculateDrawProperties(grand_parent_raw);
8492 member_id = render_surface_layer_list_count();
8493
8494 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8495 EXPECT_NE(member_id, membership_id(parent_raw));
8496 EXPECT_NE(member_id, membership_id(child_raw));
8497 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
8498 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8499 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8500
8501 expected.clear();
8502 actual.clear();
8503 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8504 EXPECT_EQ(expected, actual);
8505
8506 // Child itself draws means that we should have the child and the mask in the
8507 // list.
8508 child_raw->SetDrawsContent(true);
8509
8510 ExecuteCalculateDrawProperties(grand_parent_raw);
8511 member_id = render_surface_layer_list_count();
8512
8513 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8514 EXPECT_NE(member_id, membership_id(parent_raw));
8515 EXPECT_EQ(member_id, membership_id(child_raw));
8516 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8517 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8518 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8519
8520 expected.clear();
8521 expected.insert(child_raw);
8522 expected.insert(child_raw->mask_layer());
8523 actual.clear();
8524 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8525 EXPECT_EQ(expected, actual);
8526
8527 child_raw->TakeMaskLayer();
8528
8529 // Now everyone's a member!
8530 grand_parent_raw->SetDrawsContent(true);
8531 parent_raw->SetDrawsContent(true);
8532 child_raw->SetDrawsContent(true);
8533 grand_child1_raw->SetDrawsContent(true);
8534 grand_child2_raw->SetDrawsContent(true);
8535
8536 ExecuteCalculateDrawProperties(grand_parent_raw);
8537 member_id = render_surface_layer_list_count();
8538
8539 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
8540 EXPECT_EQ(member_id, membership_id(parent_raw));
8541 EXPECT_EQ(member_id, membership_id(child_raw));
8542 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
8543 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8544
8545 expected.clear();
8546 expected.insert(grand_parent_raw);
8547 expected.insert(parent_raw);
8548 expected.insert(child_raw);
8549 expected.insert(grand_child1_raw);
8550 expected.insert(grand_child2_raw);
8551
8552 actual.clear();
8553 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8554 EXPECT_EQ(expected, actual);
8555}
[email protected]18e69652014-06-13 12:50:588556
8557TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
8558 FakeImplProxy proxy;
8559 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:478560 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]18e69652014-06-13 12:50:588561
8562 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
8563 LayerImpl* root_layer = root.get();
8564 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
8565 LayerImpl* child1_layer = child1.get();
8566 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
8567 LayerImpl* child2_layer = child2.get();
8568
8569 root->AddChild(child1.Pass());
8570 root->AddChild(child2.Pass());
awoloszyne83f28c2014-12-22 15:40:008571 root->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588572
8573 gfx::Transform identity_matrix, scale_transform_child1,
8574 scale_transform_child2;
8575 scale_transform_child1.Scale(2, 3);
8576 scale_transform_child2.Scale(4, 5);
8577
awoloszyne83f28c2014-12-22 15:40:008578 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
8579 gfx::PointF(), gfx::Size(1, 1), true, false,
8580 true);
8581 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
8582 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8583 false, false);
[email protected]18e69652014-06-13 12:50:588584
8585 child1_layer->SetMaskLayer(
8586 LayerImpl::Create(host_impl.active_tree(), 4).Pass());
8587
8588 scoped_ptr<LayerImpl> replica_layer =
8589 LayerImpl::Create(host_impl.active_tree(), 5);
awoloszyne83f28c2014-12-22 15:40:008590 replica_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588591 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
8592 child1_layer->SetReplicaLayer(replica_layer.Pass());
awoloszyne83f28c2014-12-22 15:40:008593 child1_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588594
8595 ExecuteCalculateDrawProperties(root_layer);
8596
8597 TransformOperations scale;
8598 scale.AppendScale(5.f, 8.f, 3.f);
8599
8600 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale);
awoloszyne83f28c2014-12-22 15:40:008601 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
8602 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8603 false, false);
[email protected]18e69652014-06-13 12:50:588604
8605 ExecuteCalculateDrawProperties(root_layer);
8606
8607 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale);
8608 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale);
8609 EXPECT_FLOAT_EQ(
8610 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8611 EXPECT_FLOAT_EQ(3.f,
8612 child1_layer->replica_layer()
8613 ->mask_layer()
8614 ->draw_properties()
8615 .ideal_contents_scale);
8616 EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale);
8617
8618 EXPECT_FLOAT_EQ(
8619 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8620 EXPECT_FLOAT_EQ(
8621 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8622 EXPECT_FLOAT_EQ(0.f,
8623 child1_layer->mask_layer()
8624 ->draw_properties()
8625 .maximum_animation_contents_scale);
8626 EXPECT_FLOAT_EQ(0.f,
8627 child1_layer->replica_layer()
8628 ->mask_layer()
8629 ->draw_properties()
8630 .maximum_animation_contents_scale);
8631 EXPECT_FLOAT_EQ(
8632 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8633
8634 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8635 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor);
8636 EXPECT_FLOAT_EQ(
8637 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8638 EXPECT_FLOAT_EQ(1.f,
8639 child1_layer->replica_layer()
8640 ->mask_layer()
8641 ->draw_properties()
8642 .page_scale_factor);
8643 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor);
8644
8645 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor);
8646 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor);
8647 EXPECT_FLOAT_EQ(
8648 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8649 EXPECT_FLOAT_EQ(1.f,
8650 child1_layer->replica_layer()
8651 ->mask_layer()
8652 ->draw_properties()
8653 .device_scale_factor);
8654 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor);
8655
8656 // Changing page-scale would affect ideal_contents_scale and
8657 // maximum_animation_contents_scale.
8658
8659 float page_scale_factor = 3.f;
8660 float device_scale_factor = 1.0f;
8661 std::vector<LayerImpl*> render_surface_layer_list;
8662 gfx::Size device_viewport_size =
8663 gfx::Size(root_layer->bounds().width() * device_scale_factor,
8664 root_layer->bounds().height() * device_scale_factor);
8665 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8666 root_layer, device_viewport_size, &render_surface_layer_list);
8667
8668 inputs.page_scale_factor = page_scale_factor;
8669 inputs.can_adjust_raster_scales = true;
enne6394d5b42015-05-26 22:23:118670 inputs.page_scale_layer = root_layer;
[email protected]18e69652014-06-13 12:50:588671 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8672
8673 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale);
8674 EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale);
8675 EXPECT_FLOAT_EQ(
8676 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8677 EXPECT_FLOAT_EQ(9.f,
8678 child1_layer->replica_layer()
8679 ->mask_layer()
8680 ->draw_properties()
8681 .ideal_contents_scale);
8682 EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale);
8683
8684 EXPECT_FLOAT_EQ(
8685 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8686 EXPECT_FLOAT_EQ(
8687 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8688 EXPECT_FLOAT_EQ(0.f,
8689 child1_layer->mask_layer()
8690 ->draw_properties()
8691 .maximum_animation_contents_scale);
8692 EXPECT_FLOAT_EQ(0.f,
8693 child1_layer->replica_layer()
8694 ->mask_layer()
8695 ->draw_properties()
8696 .maximum_animation_contents_scale);
8697 EXPECT_FLOAT_EQ(
8698 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8699
8700 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8701 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor);
8702 EXPECT_FLOAT_EQ(
8703 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8704 EXPECT_FLOAT_EQ(3.f,
8705 child1_layer->replica_layer()
8706 ->mask_layer()
8707 ->draw_properties()
8708 .page_scale_factor);
8709 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor);
8710
8711 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor);
8712 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor);
8713 EXPECT_FLOAT_EQ(
8714 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8715 EXPECT_FLOAT_EQ(1.f,
8716 child1_layer->replica_layer()
8717 ->mask_layer()
8718 ->draw_properties()
8719 .device_scale_factor);
8720 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor);
8721
8722 // Changing device-scale would affect ideal_contents_scale and
8723 // maximum_animation_contents_scale.
8724
8725 device_scale_factor = 4.0f;
8726 inputs.device_scale_factor = device_scale_factor;
8727 inputs.can_adjust_raster_scales = true;
8728 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8729
8730 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale);
8731 EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale);
8732 EXPECT_FLOAT_EQ(
8733 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8734 EXPECT_FLOAT_EQ(36.f,
8735 child1_layer->replica_layer()
8736 ->mask_layer()
8737 ->draw_properties()
8738 .ideal_contents_scale);
8739 EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale);
8740
8741 EXPECT_FLOAT_EQ(
8742 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8743 EXPECT_FLOAT_EQ(
8744 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8745 EXPECT_FLOAT_EQ(0.f,
8746 child1_layer->mask_layer()
8747 ->draw_properties()
8748 .maximum_animation_contents_scale);
8749 EXPECT_FLOAT_EQ(0.f,
8750 child1_layer->replica_layer()
8751 ->mask_layer()
8752 ->draw_properties()
8753 .maximum_animation_contents_scale);
8754 EXPECT_FLOAT_EQ(
8755 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8756
8757 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8758 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor);
8759 EXPECT_FLOAT_EQ(
8760 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8761 EXPECT_FLOAT_EQ(3.f,
8762 child1_layer->replica_layer()
8763 ->mask_layer()
8764 ->draw_properties()
8765 .page_scale_factor);
8766 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor);
8767
8768 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor);
8769 EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor);
8770 EXPECT_FLOAT_EQ(
8771 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8772 EXPECT_FLOAT_EQ(4.f,
8773 child1_layer->replica_layer()
8774 ->mask_layer()
8775 ->draw_properties()
8776 .device_scale_factor);
8777 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor);
8778}
8779
danakjf6069db2014-09-13 00:46:478780TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
loysoa6edaaff2015-05-25 03:26:448781 scoped_refptr<Layer> root = Layer::Create(layer_settings());
danakjf6069db2014-09-13 00:46:478782 SetLayerPropertiesForTesting(root.get(),
8783 gfx::Transform(),
8784 gfx::Point3F(),
8785 gfx::PointF(),
8786 gfx::Size(768 / 2, 3000),
8787 true,
8788 false);
8789 root->SetIsDrawable(true);
8790
loysoa6edaaff2015-05-25 03:26:448791 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
danakjf6069db2014-09-13 00:46:478792 SetLayerPropertiesForTesting(clip.get(),
8793 gfx::Transform(),
8794 gfx::Point3F(),
8795 gfx::PointF(),
8796 gfx::Size(768 / 2, 10000),
8797 true,
8798 false);
8799 clip->SetMasksToBounds(true);
8800
loysoa6edaaff2015-05-25 03:26:448801 scoped_refptr<Layer> content = Layer::Create(layer_settings());
danakjf6069db2014-09-13 00:46:478802 SetLayerPropertiesForTesting(content.get(),
8803 gfx::Transform(),
8804 gfx::Point3F(),
8805 gfx::PointF(),
8806 gfx::Size(768 / 2, 10000),
8807 true,
8808 false);
8809 content->SetIsDrawable(true);
8810 content->SetForceRenderSurface(true);
8811
8812 root->AddChild(clip);
8813 clip->AddChild(content);
8814
enne2097cab2014-09-25 20:16:318815 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
8816 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
danakjf6069db2014-09-13 00:46:478817 host->SetRootLayer(root);
8818
8819 gfx::Size device_viewport_size(768, 582);
8820 RenderSurfaceLayerList render_surface_layer_list;
8821 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8822 host->root_layer(), device_viewport_size, &render_surface_layer_list);
8823 inputs.device_scale_factor = 2.f;
8824 inputs.page_scale_factor = 1.f;
enne6394d5b42015-05-26 22:23:118825 inputs.page_scale_layer = NULL;
danakjf6069db2014-09-13 00:46:478826 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8827
8828 // Layers in the root render surface have their visible content rect clipped
8829 // by the viewport.
8830 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect());
8831
8832 // Layers drawing to a child render surface should still have their visible
8833 // content rect clipped by the viewport.
8834 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect());
8835}
8836
timav599f4359d2014-12-05 00:12:228837TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
8838 FakeImplProxy proxy;
8839 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:478840 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
timav599f4359d2014-12-05 00:12:228841
8842 // Set two layers: the root layer clips it's child,
8843 // the child draws its content.
8844
8845 gfx::Size root_size = gfx::Size(300, 500);
8846
8847 // Sublayer should be bigger than the root enlarged by bounds_delta.
8848 gfx::Size sublayer_size = gfx::Size(300, 1000);
8849
8850 // Device viewport accomidated the root and the top controls.
8851 gfx::Size device_viewport_size = gfx::Size(300, 600);
8852 gfx::Transform identity_matrix;
8853
8854 host_impl.active_tree()->SetRootLayer(
8855 LayerImpl::Create(host_impl.active_tree(), 1));
8856
8857 LayerImpl* root = host_impl.active_tree()->root_layer();
8858 SetLayerPropertiesForTesting(root,
8859 identity_matrix,
8860 gfx::Point3F(),
8861 gfx::PointF(),
8862 root_size,
8863 false,
awoloszyne83f28c2014-12-22 15:40:008864 false,
8865 true);
timav599f4359d2014-12-05 00:12:228866
8867 root->SetContentBounds(root_size);
8868 root->SetMasksToBounds(true);
8869
8870 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
8871
8872 LayerImpl* sublayer = root->child_at(0);
8873 SetLayerPropertiesForTesting(sublayer,
8874 identity_matrix,
8875 gfx::Point3F(),
8876 gfx::PointF(),
8877 sublayer_size,
8878 false,
awoloszyne83f28c2014-12-22 15:40:008879 false,
timav599f4359d2014-12-05 00:12:228880 false);
8881
8882 sublayer->SetContentBounds(sublayer_size);
8883 sublayer->SetDrawsContent(true);
8884
8885 LayerImplList layer_impl_list;
8886 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8887 root, device_viewport_size, &layer_impl_list);
8888
8889 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8890
8891 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_content_rect());
8892
8893 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
8894
8895 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8896
8897 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8898 root_size.height() + 50);
8899 EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect());
8900}
8901
vollick7d83b452015-02-24 20:18:068902TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
8903 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:448904 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick7d83b452015-02-24 20:18:068905 scoped_refptr<LayerWithForcedDrawsContent> animated =
loysoa6edaaff2015-05-25 03:26:448906 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick7d83b452015-02-24 20:18:068907
8908 root->AddChild(animated);
8909
8910 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8911 host->SetRootLayer(root);
8912
8913 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8914 gfx::PointF(), gfx::Size(100, 100), true, false);
8915 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
8916 gfx::PointF(), gfx::Size(20, 20), true, false);
8917
8918 root->SetMasksToBounds(true);
8919 root->SetForceRenderSurface(true);
8920 animated->SetOpacity(0.f);
8921
8922 AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0,
8923 0.f, 1.f, false);
8924
enne601f2ef12015-05-19 18:20:178925 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick7d83b452015-02-24 20:18:068926
8927 EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty());
8928}
8929
ajumaa92fdc12015-03-31 22:47:418930TEST_F(LayerTreeHostCommonTest,
8931 VisibleContentRectForAnimatedLayerWithSingularTransform) {
8932 const gfx::Transform identity_matrix;
loysoa6edaaff2015-05-25 03:26:448933 scoped_refptr<Layer> root = Layer::Create(layer_settings());
8934 scoped_refptr<Layer> clip = Layer::Create(layer_settings());
ajumaa92fdc12015-03-31 22:47:418935 scoped_refptr<LayerWithForcedDrawsContent> animated =
loysoa6edaaff2015-05-25 03:26:448936 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaa92fdc12015-03-31 22:47:418937 scoped_refptr<LayerWithForcedDrawsContent> surface =
loysoa6edaaff2015-05-25 03:26:448938 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaa92fdc12015-03-31 22:47:418939 scoped_refptr<LayerWithForcedDrawsContent> descendant_of_animation =
loysoa6edaaff2015-05-25 03:26:448940 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaa92fdc12015-03-31 22:47:418941
8942 root->AddChild(clip);
8943 clip->AddChild(animated);
8944 animated->AddChild(surface);
8945 surface->AddChild(descendant_of_animation);
8946
8947 clip->SetMasksToBounds(true);
8948 surface->SetForceRenderSurface(true);
8949
8950 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8951 host->SetRootLayer(root);
8952
8953 gfx::Transform uninvertible_matrix;
8954 uninvertible_matrix.Scale3d(6.f, 6.f, 0.f);
8955
8956 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8957 gfx::PointF(), gfx::Size(100, 100), true, false);
8958 SetLayerPropertiesForTesting(clip.get(), identity_matrix, gfx::Point3F(),
8959 gfx::PointF(), gfx::Size(10, 10), true, false);
8960 SetLayerPropertiesForTesting(animated.get(), uninvertible_matrix,
8961 gfx::Point3F(), gfx::PointF(),
8962 gfx::Size(120, 120), true, false);
8963 SetLayerPropertiesForTesting(surface.get(), identity_matrix, gfx::Point3F(),
8964 gfx::PointF(), gfx::Size(100, 100), true, false);
8965 SetLayerPropertiesForTesting(descendant_of_animation.get(), identity_matrix,
8966 gfx::Point3F(), gfx::PointF(),
8967 gfx::Size(200, 200), true, false);
8968
8969 TransformOperations start_transform_operations;
8970 start_transform_operations.AppendMatrix(uninvertible_matrix);
8971 TransformOperations end_transform_operations;
8972
8973 AddAnimatedTransformToLayer(animated.get(), 10.0, start_transform_operations,
8974 end_transform_operations);
8975
enne601f2ef12015-05-19 18:20:178976 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:418977
8978 // The animated layer has a singular transform and maps to a non-empty rect in
8979 // clipped target space, so is treated as fully visible.
8980 EXPECT_EQ(gfx::Rect(120, 120), animated->visible_rect_from_property_trees());
8981
8982 // The singular transform on |animated| is flattened when inherited by
8983 // |surface|, and this happens to make it invertible.
8984 EXPECT_EQ(gfx::Rect(2, 2), surface->visible_rect_from_property_trees());
8985 EXPECT_EQ(gfx::Rect(2, 2),
8986 descendant_of_animation->visible_rect_from_property_trees());
8987
8988 gfx::Transform zero_matrix;
8989 zero_matrix.Scale3d(0.f, 0.f, 0.f);
8990 SetLayerPropertiesForTesting(animated.get(), zero_matrix, gfx::Point3F(),
8991 gfx::PointF(), gfx::Size(120, 120), true, false);
8992
enne601f2ef12015-05-19 18:20:178993 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaa92fdc12015-03-31 22:47:418994
8995 // The animated layer maps to the empty rect in clipped target space, so is
8996 // treated as having an empty visible rect.
8997 EXPECT_EQ(gfx::Rect(), animated->visible_rect_from_property_trees());
8998
8999 // This time, flattening does not make |animated|'s transform invertible. This
9000 // means the clip cannot be projected into |surface|'s space, so we treat
9001 // |surface| and layers that draw into it as fully visible.
9002 EXPECT_EQ(gfx::Rect(100, 100), surface->visible_rect_from_property_trees());
9003 EXPECT_EQ(gfx::Rect(200, 200),
9004 descendant_of_animation->visible_rect_from_property_trees());
9005}
9006
enne92f2f6d92015-02-25 23:13:319007// Verify that having an animated filter (but no current filter, as these
9008// are mutually exclusive) correctly creates a render surface.
9009TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
loysoa6edaaff2015-05-25 03:26:449010 scoped_refptr<Layer> root = Layer::Create(layer_settings());
9011 scoped_refptr<Layer> child = Layer::Create(layer_settings());
9012 scoped_refptr<Layer> grandchild = Layer::Create(layer_settings());
enne92f2f6d92015-02-25 23:13:319013 root->AddChild(child);
9014 child->AddChild(grandchild);
9015
9016 gfx::Transform identity_transform;
9017 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
9018 gfx::PointF(), gfx::Size(50, 50), true, false);
9019 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
9020 gfx::PointF(), gfx::Size(50, 50), true, false);
9021 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
9022 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
9023 true, false);
9024 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9025 host->SetRootLayer(root);
9026
9027 AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f);
9028
9029 ExecuteCalculateDrawProperties(root.get());
9030
9031 EXPECT_TRUE(root->render_surface());
9032 EXPECT_TRUE(child->render_surface());
9033 EXPECT_FALSE(grandchild->render_surface());
9034
9035 EXPECT_TRUE(root->filters().IsEmpty());
9036 EXPECT_TRUE(child->filters().IsEmpty());
9037 EXPECT_TRUE(grandchild->filters().IsEmpty());
9038
9039 EXPECT_FALSE(root->FilterIsAnimating());
9040 EXPECT_TRUE(child->FilterIsAnimating());
9041 EXPECT_FALSE(grandchild->FilterIsAnimating());
9042}
9043
vollick0120eb22015-03-02 03:07:349044// Ensures that the property tree code accounts for offsets between fixed
9045// position layers and their respective containers.
9046TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
loysoa6edaaff2015-05-25 03:26:449047 scoped_refptr<Layer> root = Layer::Create(layer_settings());
9048 scoped_refptr<Layer> child = Layer::Create(layer_settings());
vollick0120eb22015-03-02 03:07:349049 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loysoa6edaaff2015-05-25 03:26:449050 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick0120eb22015-03-02 03:07:349051
9052 root->AddChild(child);
9053 child->AddChild(grandchild);
9054
9055 gfx::Transform identity_transform;
9056 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
9057 gfx::PointF(), gfx::Size(50, 50), true, false);
9058 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
9059 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
9060 false);
9061 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
9062 gfx::Point3F(), gfx::PointF(-1000, -1000),
9063 gfx::Size(50, 50), true, false);
9064
9065 root->SetMasksToBounds(true);
9066 root->SetIsContainerForFixedPositionLayers(true);
9067 LayerPositionConstraint constraint;
9068 constraint.set_is_fixed_position(true);
9069 grandchild->SetPositionConstraint(constraint);
9070
9071 root->SetIsContainerForFixedPositionLayers(true);
9072
9073 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9074 host->SetRootLayer(root);
9075
enne601f2ef12015-05-19 18:20:179076 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick0120eb22015-03-02 03:07:349077
9078 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
9079 grandchild->visible_rect_from_property_trees());
9080}
9081
vollick67394b42015-03-10 00:22:309082TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) {
9083 // In the following layer tree, the layer |box|'s render target is |surface|.
9084 // |surface| also creates a transform node. We want to combine clips for |box|
9085 // in the space of its target (i.e., |surface|), not its target's target. This
9086 // test ensures that happens.
9087
9088 gfx::Transform rotate;
9089 rotate.Rotate(5);
9090 gfx::Transform identity;
9091
loysoa6edaaff2015-05-25 03:26:449092 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:309093 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9094 gfx::PointF(), gfx::Size(2500, 1500), true,
9095 false);
9096
loysoa6edaaff2015-05-25 03:26:449097 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:309098 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
9099 gfx::PointF(), gfx::Size(2500, 1500), true,
9100 false);
9101 frame_clip->SetMasksToBounds(true);
9102
loysoa6edaaff2015-05-25 03:26:449103 scoped_refptr<Layer> rotated = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:309104 SetLayerPropertiesForTesting(rotated.get(), rotate,
9105 gfx::Point3F(1250, 250, 0), gfx::PointF(),
9106 gfx::Size(2500, 500), true, false);
9107
loysoa6edaaff2015-05-25 03:26:449108 scoped_refptr<Layer> surface = Layer::Create(layer_settings());
vollick67394b42015-03-10 00:22:309109 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(),
9110 gfx::PointF(), gfx::Size(2500, 500), true,
9111 false);
9112 surface->SetOpacity(0.5);
9113
9114 scoped_refptr<LayerWithForcedDrawsContent> container =
loysoa6edaaff2015-05-25 03:26:449115 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick67394b42015-03-10 00:22:309116 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(),
9117 gfx::PointF(), gfx::Size(300, 300), true, false);
9118
9119 scoped_refptr<LayerWithForcedDrawsContent> box =
loysoa6edaaff2015-05-25 03:26:449120 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick67394b42015-03-10 00:22:309121 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(),
9122 gfx::PointF(), gfx::Size(100, 100), true, false);
9123
9124 root->AddChild(frame_clip);
9125 frame_clip->AddChild(rotated);
9126 rotated->AddChild(surface);
9127 surface->AddChild(container);
9128 surface->AddChild(box);
9129
9130 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9131 host->SetRootLayer(root);
9132
9133 ExecuteCalculateDrawProperties(root.get());
9134}
9135
vollick8c824742015-03-20 22:21:089136TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
9137 gfx::Transform identity;
9138 gfx::Transform translate_z;
9139 translate_z.Translate3d(0, 0, 10);
9140
loysoa6edaaff2015-05-25 03:26:449141 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick8c824742015-03-20 22:21:089142 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9143 gfx::PointF(), gfx::Size(800, 800), true, false);
9144 root->SetIsContainerForFixedPositionLayers(true);
9145
loysoa6edaaff2015-05-25 03:26:449146 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollick8c824742015-03-20 22:21:089147 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
9148 gfx::PointF(500, 100), gfx::Size(100, 100), true,
9149 false);
9150 frame_clip->SetMasksToBounds(true);
9151
9152 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:449153 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick8c824742015-03-20 22:21:089154 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
9155 gfx::PointF(), gfx::Size(1000, 1000), true,
9156 false);
9157
9158 LayerPositionConstraint constraint;
9159 constraint.set_is_fixed_position(true);
9160 fixed->SetPositionConstraint(constraint);
9161
9162 root->AddChild(frame_clip);
9163 frame_clip->AddChild(fixed);
9164
9165 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9166 host->SetRootLayer(root);
9167
enne601f2ef12015-05-19 18:20:179168 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick8c824742015-03-20 22:21:089169
9170 gfx::Rect expected(0, 0, 100, 100);
9171 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
9172}
9173
vollickf6281c42015-03-30 21:44:419174TEST_F(LayerTreeHostCommonTest,
9175 PropertyTreesAccountForScrollCompensationAdjustment) {
9176 gfx::Transform identity;
9177 gfx::Transform translate_z;
9178 translate_z.Translate3d(0, 0, 10);
9179
loysoa6edaaff2015-05-25 03:26:449180 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollickf6281c42015-03-30 21:44:419181 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9182 gfx::PointF(), gfx::Size(800, 800), true, false);
9183 root->SetIsContainerForFixedPositionLayers(true);
9184
loysoa6edaaff2015-05-25 03:26:449185 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollickf6281c42015-03-30 21:44:419186 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
9187 gfx::PointF(500, 100), gfx::Size(100, 100), true,
9188 false);
9189 frame_clip->SetMasksToBounds(true);
9190
9191 scoped_refptr<LayerWithForcedDrawsContent> scroller =
loysoa6edaaff2015-05-25 03:26:449192 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollickf6281c42015-03-30 21:44:419193 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
9194 gfx::PointF(), gfx::Size(1000, 1000), true,
9195 false);
9196
9197 scroller->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f, 0.7f));
9198 scroller->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
9199 scroller->SetScrollClipLayerId(frame_clip->id());
9200
9201 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:449202 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollickf6281c42015-03-30 21:44:419203 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
9204 gfx::PointF(), gfx::Size(50, 50), true, false);
9205
9206 LayerPositionConstraint constraint;
9207 constraint.set_is_fixed_position(true);
9208 fixed->SetPositionConstraint(constraint);
9209
9210 scoped_refptr<LayerWithForcedDrawsContent> fixed_child =
loysoa6edaaff2015-05-25 03:26:449211 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollickf6281c42015-03-30 21:44:419212 SetLayerPropertiesForTesting(fixed_child.get(), identity, gfx::Point3F(),
9213 gfx::PointF(), gfx::Size(10, 10), true, false);
9214
9215 fixed_child->SetPositionConstraint(constraint);
9216
9217 root->AddChild(frame_clip);
9218 frame_clip->AddChild(scroller);
9219 scroller->AddChild(fixed);
9220 fixed->AddChild(fixed_child);
9221
9222 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9223 host->SetRootLayer(root);
9224
enne601f2ef12015-05-19 18:20:179225 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollickf6281c42015-03-30 21:44:419226
9227 gfx::Rect expected(0, 0, 50, 50);
9228 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
9229
9230 expected = gfx::Rect(0, 0, 10, 10);
9231 EXPECT_EQ(expected, fixed_child->visible_rect_from_property_trees());
9232}
9233
vollick06ca3e832015-03-31 19:37:129234TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) {
9235 gfx::Transform identity;
9236
loysoa6edaaff2015-05-25 03:26:449237 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick06ca3e832015-03-31 19:37:129238 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9239 gfx::PointF(), gfx::Size(800, 800), true, false);
9240 root->SetIsContainerForFixedPositionLayers(true);
9241
loysoa6edaaff2015-05-25 03:26:449242 scoped_refptr<Layer> frame_clip = Layer::Create(layer_settings());
vollick06ca3e832015-03-31 19:37:129243 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
9244 gfx::PointF(500, 100), gfx::Size(100, 100), true,
9245 false);
9246 frame_clip->SetMasksToBounds(true);
9247
9248 scoped_refptr<LayerWithForcedDrawsContent> scroller =
loysoa6edaaff2015-05-25 03:26:449249 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick06ca3e832015-03-31 19:37:129250 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(),
9251 gfx::PointF(), gfx::Size(1000, 1000), true,
9252 false);
9253
9254 scroller->SetScrollOffset(gfx::ScrollOffset(100, 100));
9255 scroller->SetScrollClipLayerId(frame_clip->id());
9256
9257 scoped_refptr<LayerWithForcedDrawsContent> fixed =
loysoa6edaaff2015-05-25 03:26:449258 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick06ca3e832015-03-31 19:37:129259 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
9260 gfx::PointF(100, 100), gfx::Size(50, 50), true,
9261 false);
9262
9263 LayerPositionConstraint constraint;
9264 constraint.set_is_fixed_position(true);
9265 fixed->SetPositionConstraint(constraint);
9266 fixed->SetForceRenderSurface(true);
9267 fixed->SetMasksToBounds(true);
9268
9269 root->AddChild(frame_clip);
9270 frame_clip->AddChild(scroller);
9271 scroller->AddChild(fixed);
9272
9273 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9274 host->SetRootLayer(root);
9275
enne601f2ef12015-05-19 18:20:179276 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick06ca3e832015-03-31 19:37:129277
9278 gfx::Rect expected(0, 0, 50, 50);
9279 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
9280}
9281
vollick5057e1e2015-04-17 19:12:329282TEST_F(LayerTreeHostCommonTest, ChangingAxisAlignmentTriggersRebuild) {
9283 gfx::Transform identity;
9284 gfx::Transform translate;
9285 gfx::Transform rotate;
9286
9287 translate.Translate(10, 10);
9288 rotate.Rotate(45);
9289
loysoa6edaaff2015-05-25 03:26:449290 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick5057e1e2015-04-17 19:12:329291 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9292 gfx::PointF(), gfx::Size(800, 800), true, false);
9293 root->SetIsContainerForFixedPositionLayers(true);
9294
9295 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9296 host->SetRootLayer(root);
9297
enne601f2ef12015-05-19 18:20:179298 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9299 EXPECT_FALSE(host->property_trees()->needs_rebuild);
vollick5057e1e2015-04-17 19:12:329300
9301 root->SetTransform(translate);
9302 EXPECT_FALSE(host->property_trees()->needs_rebuild);
9303
9304 root->SetTransform(rotate);
9305 EXPECT_TRUE(host->property_trees()->needs_rebuild);
9306}
9307
ajumab0e0c1c2015-04-23 00:29:239308TEST_F(LayerTreeHostCommonTest, ChangeTransformOrigin) {
loysoa6edaaff2015-05-25 03:26:449309 scoped_refptr<Layer> root = Layer::Create(layer_settings());
ajumab0e0c1c2015-04-23 00:29:239310 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:449311 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumab0e0c1c2015-04-23 00:29:239312 root->AddChild(child);
9313
9314 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9315 host->SetRootLayer(root);
9316
9317 gfx::Transform identity_matrix;
9318 gfx::Transform scale_matrix;
9319 scale_matrix.Scale(2.f, 2.f);
9320 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
9321 gfx::PointF(), gfx::Size(100, 100), true, false);
9322 SetLayerPropertiesForTesting(child.get(), scale_matrix, gfx::Point3F(),
9323 gfx::PointF(), gfx::Size(10, 10), true, false);
9324
enne601f2ef12015-05-19 18:20:179325 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumab0e0c1c2015-04-23 00:29:239326 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
9327
9328 child->SetTransformOrigin(gfx::Point3F(10.f, 10.f, 10.f));
9329
enne601f2ef12015-05-19 18:20:179330 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumab0e0c1c2015-04-23 00:29:239331 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child->visible_rect_from_property_trees());
9332}
9333
ajumaf09db8962015-04-24 21:55:349334TEST_F(LayerTreeHostCommonTest, UpdateScrollChildPosition) {
loysoa6edaaff2015-05-25 03:26:449335 scoped_refptr<Layer> root = Layer::Create(layer_settings());
ajumaf09db8962015-04-24 21:55:349336 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
loysoa6edaaff2015-05-25 03:26:449337 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaf09db8962015-04-24 21:55:349338 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
loysoa6edaaff2015-05-25 03:26:449339 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
ajumaf09db8962015-04-24 21:55:349340
9341 root->AddChild(scroll_child);
9342 root->AddChild(scroll_parent);
9343 scroll_child->SetScrollParent(scroll_parent.get());
9344 scroll_parent->SetScrollClipLayerId(root->id());
9345
9346 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9347 host->SetRootLayer(root);
9348
9349 gfx::Transform identity_transform;
9350 gfx::Transform scale;
9351 scale.Scale(2.f, 2.f);
9352 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
9353 gfx::PointF(), gfx::Size(50, 50), true, false);
9354 SetLayerPropertiesForTesting(scroll_child.get(), scale, gfx::Point3F(),
9355 gfx::PointF(), gfx::Size(40, 40), true, false);
9356 SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform,
9357 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
9358 true, false);
9359
enne601f2ef12015-05-19 18:20:179360 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaf09db8962015-04-24 21:55:349361 EXPECT_EQ(gfx::Rect(25, 25),
9362 scroll_child->visible_rect_from_property_trees());
9363
9364 scroll_child->SetPosition(gfx::PointF(0, -10.f));
9365 scroll_parent->SetScrollOffset(gfx::ScrollOffset(0.f, 10.f));
enne601f2ef12015-05-19 18:20:179366 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
ajumaf09db8962015-04-24 21:55:349367 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
9368 scroll_child->visible_rect_from_property_trees());
9369}
9370
vollick2175fae82015-04-27 21:18:129371static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {
9372}
9373
9374TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) {
9375 gfx::Transform identity;
9376 FakeContentLayerClient client;
loysoa6edaaff2015-05-25 03:26:449377 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick2175fae82015-04-27 21:18:129378 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:449379 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick2175fae82015-04-27 21:18:129380 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
loysoa6edaaff2015-05-25 03:26:449381 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick2175fae82015-04-27 21:18:129382 scoped_refptr<FakeContentLayer> greatgrandchild(
loysoa6edaaff2015-05-25 03:26:449383 FakeContentLayer::Create(layer_settings(), &client));
vollick2175fae82015-04-27 21:18:129384 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9385 gfx::PointF(), gfx::Size(100, 100), true, false);
9386 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9387 gfx::PointF(), gfx::Size(10, 10), true, false);
9388 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
9389 gfx::PointF(), gfx::Size(10, 10), true, false);
9390 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
9391 gfx::PointF(), gfx::Size(10, 10), true, false);
9392
9393 root->AddChild(child);
9394 child->AddChild(grandchild);
9395 grandchild->AddChild(greatgrandchild);
9396
9397 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9398 host->SetRootLayer(root);
9399
9400 // Check the non-skipped case.
enne601f2ef12015-05-19 18:20:179401 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129402 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
9403
9404 // Now we will reset the visible rect from property trees for the grandchild,
9405 // and we will configure |child| in several ways that should force the subtree
9406 // to be skipped. The visible content rect for |grandchild| should, therefore,
9407 // remain empty.
9408 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
9409 gfx::Transform singular;
9410 singular.matrix().set(0, 0, 0);
9411
9412 child->SetTransform(singular);
enne601f2ef12015-05-19 18:20:179413 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129414 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
9415 child->SetTransform(identity);
9416
9417 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:179418 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129419 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
9420 child->SetHideLayerAndSubtree(false);
9421
9422 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:179423 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129424 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
9425
9426 // Now, even though child has zero opacity, we will configure |grandchild| and
9427 // |greatgrandchild| in several ways that should force the subtree to be
9428 // processed anyhow.
9429 grandchild->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
enne601f2ef12015-05-19 18:20:179430 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129431 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
9432 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
9433 grandchild->SetTouchEventHandlerRegion(Region());
enne601f2ef12015-05-19 18:20:179434 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129435 EXPECT_EQ(gfx::Rect(0, 0), grandchild->visible_rect_from_property_trees());
9436 grandchild->set_visible_rect_from_property_trees(gfx::Rect());
9437
9438 greatgrandchild->RequestCopyOfOutput(
9439 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback)));
enne601f2ef12015-05-19 18:20:179440 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129441 EXPECT_EQ(gfx::Rect(10, 10), grandchild->visible_rect_from_property_trees());
9442}
9443
9444TEST_F(LayerTreeHostCommonTest, SkippingSubtreeImpl) {
9445 FakeImplProxy proxy;
9446 TestSharedBitmapManager shared_bitmap_manager;
9447 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
9448
9449 gfx::Transform identity;
9450 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
9451 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 2);
9452 scoped_ptr<LayerImpl> grandchild =
9453 LayerImpl::Create(host_impl.active_tree(), 3);
9454
9455 scoped_ptr<FakeContentLayerImpl> greatgrandchild(
9456 FakeContentLayerImpl::Create(host_impl.active_tree(), 4));
9457
9458 child->SetDrawsContent(true);
9459 grandchild->SetDrawsContent(true);
9460 greatgrandchild->SetDrawsContent(true);
9461
9462 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9463 gfx::PointF(), gfx::Size(100, 100), true, false,
9464 true);
9465 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9466 gfx::PointF(), gfx::Size(10, 10), true, false,
9467 false);
9468 SetLayerPropertiesForTesting(grandchild.get(), identity, gfx::Point3F(),
9469 gfx::PointF(), gfx::Size(10, 10), true, false,
9470 false);
9471 SetLayerPropertiesForTesting(greatgrandchild.get(), identity, gfx::Point3F(),
9472 gfx::PointF(), gfx::Size(10, 10), true, false,
9473 true);
9474
9475 LayerImpl* child_ptr = child.get();
9476 LayerImpl* grandchild_ptr = grandchild.get();
9477 LayerImpl* greatgrandchild_ptr = greatgrandchild.get();
9478
9479 grandchild->AddChild(greatgrandchild.Pass());
9480 child->AddChild(grandchild.Pass());
9481 root->AddChild(child.Pass());
9482
9483 // Check the non-skipped case.
enne601f2ef12015-05-19 18:20:179484 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129485 EXPECT_EQ(gfx::Rect(10, 10),
9486 grandchild_ptr->visible_rect_from_property_trees());
9487
9488 // Now we will reset the visible rect from property trees for the grandchild,
9489 // and we will configure |child| in several ways that should force the subtree
9490 // to be skipped. The visible content rect for |grandchild| should, therefore,
9491 // remain empty.
9492 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
9493 gfx::Transform singular;
9494 singular.matrix().set(0, 0, 0);
9495
9496 child_ptr->SetTransform(singular);
enne601f2ef12015-05-19 18:20:179497 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129498 EXPECT_EQ(gfx::Rect(0, 0),
9499 grandchild_ptr->visible_rect_from_property_trees());
9500 child_ptr->SetTransform(identity);
9501
9502 child_ptr->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:179503 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129504 EXPECT_EQ(gfx::Rect(0, 0),
9505 grandchild_ptr->visible_rect_from_property_trees());
9506 child_ptr->SetHideLayerAndSubtree(false);
9507
9508 child_ptr->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:179509 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129510 EXPECT_EQ(gfx::Rect(0, 0),
9511 grandchild_ptr->visible_rect_from_property_trees());
9512
9513 // Now, even though child has zero opacity, we will configure |grandchild| and
9514 // |greatgrandchild| in several ways that should force the subtree to be
9515 // processed anyhow.
9516 grandchild_ptr->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
enne601f2ef12015-05-19 18:20:179517 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129518 EXPECT_EQ(gfx::Rect(10, 10),
9519 grandchild_ptr->visible_rect_from_property_trees());
9520 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
9521 grandchild_ptr->SetTouchEventHandlerRegion(Region());
enne601f2ef12015-05-19 18:20:179522 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129523 EXPECT_EQ(gfx::Rect(0, 0),
9524 grandchild_ptr->visible_rect_from_property_trees());
9525 grandchild_ptr->set_visible_rect_from_property_trees(gfx::Rect());
9526
9527 ScopedPtrVector<CopyOutputRequest> requests;
9528 requests.push_back(CopyOutputRequest::CreateEmptyRequest());
9529
9530 greatgrandchild_ptr->PassCopyRequests(&requests);
enne601f2ef12015-05-19 18:20:179531 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129532 EXPECT_EQ(gfx::Rect(10, 10),
9533 grandchild_ptr->visible_rect_from_property_trees());
9534}
9535
9536TEST_F(LayerTreeHostCommonTest, SkippingLayer) {
9537 gfx::Transform identity;
9538 FakeContentLayerClient client;
loysoa6edaaff2015-05-25 03:26:449539 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick2175fae82015-04-27 21:18:129540 scoped_refptr<LayerWithForcedDrawsContent> child =
loysoa6edaaff2015-05-25 03:26:449541 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
vollick2175fae82015-04-27 21:18:129542 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9543 gfx::PointF(), gfx::Size(100, 100), true, false);
9544 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9545 gfx::PointF(), gfx::Size(10, 10), true, false);
9546 root->AddChild(child);
9547
9548 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9549 host->SetRootLayer(root);
9550
enne601f2ef12015-05-19 18:20:179551 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129552 EXPECT_EQ(gfx::Rect(10, 10), child->visible_rect_from_property_trees());
9553 child->set_visible_rect_from_property_trees(gfx::Rect());
9554
9555 child->SetHideLayerAndSubtree(true);
enne601f2ef12015-05-19 18:20:179556 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129557 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9558 child->SetHideLayerAndSubtree(false);
9559
9560 child->SetBounds(gfx::Size());
enne601f2ef12015-05-19 18:20:179561 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129562 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9563 child->SetBounds(gfx::Size(10, 10));
9564
9565 gfx::Transform rotate;
9566 child->SetDoubleSided(false);
9567 rotate.RotateAboutXAxis(180.f);
9568 child->SetTransform(rotate);
enne601f2ef12015-05-19 18:20:179569 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129570 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9571 child->SetDoubleSided(true);
9572 child->SetTransform(identity);
9573
9574 child->SetOpacity(0.f);
enne601f2ef12015-05-19 18:20:179575 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
vollick2175fae82015-04-27 21:18:129576 EXPECT_EQ(gfx::Rect(0, 0), child->visible_rect_from_property_trees());
9577}
9578
jaydasika3d10aa62015-05-06 17:50:449579TEST_F(LayerTreeHostCommonTest, LayerTreeRebuildTest) {
9580 // Ensure that the treewalk in LayerTreeHostCommom::
9581 // PreCalculateMetaInformation happens when its required.
loysoa6edaaff2015-05-25 03:26:449582 scoped_refptr<Layer> root = Layer::Create(layer_settings());
9583 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
9584 scoped_refptr<Layer> child = Layer::Create(layer_settings());
jaydasika3d10aa62015-05-06 17:50:449585
9586 root->AddChild(parent);
9587 parent->AddChild(child);
9588
9589 child->SetClipParent(root.get());
9590
9591 gfx::Transform identity;
9592
9593 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9594 gfx::PointF(), gfx::Size(100, 100), true, false);
9595 SetLayerPropertiesForTesting(parent.get(), identity, gfx::Point3F(),
9596 gfx::PointF(), gfx::Size(100, 100), true, false);
9597 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9598 gfx::PointF(), gfx::Size(100, 100), true, false);
9599
9600 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9601 host->SetRootLayer(root);
9602
9603 ExecuteCalculateDrawProperties(root.get());
9604 EXPECT_EQ(parent->draw_properties().num_unclipped_descendants, 1);
9605
9606 // Ensure the dynamic update to input handlers happens.
9607 child->SetHaveWheelEventHandlers(true);
9608 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_input_handler);
9609 ExecuteCalculateDrawProperties(root.get());
9610 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_input_handler);
9611
9612 child->SetHaveWheelEventHandlers(false);
9613 EXPECT_FALSE(root->draw_properties().layer_or_descendant_has_input_handler);
9614 ExecuteCalculateDrawProperties(root.get());
9615 EXPECT_FALSE(root->draw_properties().layer_or_descendant_has_input_handler);
9616
9617 child->RequestCopyOfOutput(
9618 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
9619 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
9620 ExecuteCalculateDrawProperties(root.get());
9621 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
9622}
9623
9624TEST_F(LayerTreeHostCommonTest, InputHandlersRecursiveUpdateTest) {
9625 // Ensure that the treewalk in LayertreeHostCommon::
9626 // PreCalculateMetaInformation updates input handlers correctly.
loysoa6edaaff2015-05-25 03:26:449627 scoped_refptr<Layer> root = Layer::Create(layer_settings());
9628 scoped_refptr<Layer> child = Layer::Create(layer_settings());
jaydasika3d10aa62015-05-06 17:50:449629
9630 root->AddChild(child);
9631
9632 child->SetHaveWheelEventHandlers(true);
9633
9634 gfx::Transform identity;
9635
9636 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9637 gfx::PointF(), gfx::Size(100, 100), true, false);
9638 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9639 gfx::PointF(), gfx::Size(100, 100), true, false);
9640
9641 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9642 host->SetRootLayer(root);
9643
9644 EXPECT_EQ(root->num_layer_or_descendants_with_input_handler(), 0);
9645 ExecuteCalculateDrawProperties(root.get());
9646 EXPECT_EQ(root->num_layer_or_descendants_with_input_handler(), 1);
9647 child->SetHaveWheelEventHandlers(false);
9648 EXPECT_EQ(root->num_layer_or_descendants_with_input_handler(), 0);
9649}
9650
vollick692444f2015-05-20 15:39:149651TEST_F(LayerTreeHostCommonTest, ResetPropertyTreeIndices) {
9652 gfx::Transform identity;
9653 gfx::Transform translate_z;
9654 translate_z.Translate3d(0, 0, 10);
9655
loysoa6edaaff2015-05-25 03:26:449656 scoped_refptr<Layer> root = Layer::Create(layer_settings());
vollick692444f2015-05-20 15:39:149657 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9658 gfx::PointF(), gfx::Size(800, 800), true, false);
9659
loysoa6edaaff2015-05-25 03:26:449660 scoped_refptr<Layer> child = Layer::Create(layer_settings());
vollick692444f2015-05-20 15:39:149661 SetLayerPropertiesForTesting(child.get(), translate_z, gfx::Point3F(),
9662 gfx::PointF(), gfx::Size(100, 100), true, false);
9663
9664 root->AddChild(child);
9665
9666 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9667 host->SetRootLayer(root);
9668
9669 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9670 EXPECT_NE(-1, child->transform_tree_index());
9671
9672 child->RemoveFromParent();
9673
9674 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get());
9675 EXPECT_EQ(-1, child->transform_tree_index());
9676}
9677
jaydasika976cd10b2015-05-26 15:45:249678TEST_F(LayerTreeHostCommonTest, ResetLayerDrawPropertiestest) {
9679 scoped_refptr<Layer> root = Layer::Create(layer_settings());
9680 scoped_refptr<Layer> child = Layer::Create(layer_settings());
9681
9682 root->AddChild(child);
9683 gfx::Transform identity;
9684
9685 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
9686 gfx::PointF(), gfx::Size(100, 100), true, false);
9687 SetLayerPropertiesForTesting(child.get(), identity, gfx::Point3F(),
9688 gfx::PointF(), gfx::Size(100, 100), true, false);
9689
9690 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
9691 host->SetRootLayer(root);
9692
9693 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
9694 EXPECT_FALSE(root->visited());
9695 EXPECT_FALSE(root->sorted_for_recursion());
9696 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
9697 EXPECT_FALSE(child->visited());
9698 EXPECT_FALSE(child->sorted_for_recursion());
9699
9700 root->set_layer_or_descendant_is_drawn(true);
9701 root->set_visited(true);
9702 root->set_sorted_for_recursion(true);
9703 child->set_layer_or_descendant_is_drawn(true);
9704 child->set_visited(true);
9705 child->set_sorted_for_recursion(true);
9706
9707 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root.get());
9708
9709 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
9710 EXPECT_FALSE(root->visited());
9711 EXPECT_FALSE(root->sorted_for_recursion());
9712 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
9713 EXPECT_FALSE(child->visited());
9714 EXPECT_FALSE(child->sorted_for_recursion());
9715}
9716
[email protected]ba565742012-11-10 09:29:489717} // namespace
9718} // namespace cc