blob: 0df2b47986e87b56c1481a2a344ee69a756f8e80 [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"
[email protected]586d51ed2012-12-07 20:31:4524#include "cc/test/fake_impl_proxy.h"
[email protected]d600df7d2013-08-03 02:34:2825#include "cc/test/fake_layer_tree_host.h"
[email protected]586d51ed2012-12-07 20:31:4526#include "cc/test/fake_layer_tree_host_impl.h"
sohan.jyotie3bd6192014-10-13 07:13:5927#include "cc/test/fake_picture_layer.h"
28#include "cc/test/fake_picture_layer_impl.h"
[email protected]101441ce2012-10-16 01:45:0329#include "cc/test/geometry_test_utils.h"
[email protected]28336d52014-05-12 19:07:2830#include "cc/test/layer_tree_host_common_test.h"
reveman34b7a1522015-03-23 20:27:4731#include "cc/test/test_task_graph_runner.h"
[email protected]556fd292013-03-18 08:03:0432#include "cc/trees/layer_tree_impl.h"
33#include "cc/trees/proxy.h"
34#include "cc/trees/single_thread_proxy.h"
[email protected]7f0c53db2012-10-02 00:23:1835#include "testing/gmock/include/gmock/gmock.h"
36#include "testing/gtest/include/gtest/gtest.h"
heejin.r.chungd28506ba2014-10-23 16:36:2037#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3738#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0039#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1440
[email protected]ba565742012-11-10 09:29:4841namespace cc {
[email protected]94f206c12012-08-25 00:09:1442namespace {
43
[email protected]96baf3e2012-10-22 23:09:5544class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:3245 public:
[email protected]35322352014-08-08 01:36:2046 LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:1447
dcheng716bedf2014-10-21 09:51:0848 bool DrawsContent() const override;
[email protected]d58499a2012-10-09 22:27:4749
[email protected]fb661802013-03-25 01:59:3250 private:
dcheng716bedf2014-10-21 09:51:0851 ~LayerWithForcedDrawsContent() override {}
[email protected]94f206c12012-08-25 00:09:1452};
53
[email protected]fb661802013-03-25 01:59:3254bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:4455
[email protected]96baf3e2012-10-22 23:09:5556class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:3257 public:
58 MockContentLayerClient() {}
dcheng716bedf2014-10-21 09:51:0859 ~MockContentLayerClient() override {}
schenney0154bfa2015-02-05 19:46:4960 void PaintContents(SkCanvas* canvas,
61 const gfx::Rect& clip,
62 PaintingControlSetting picture_control) override {}
ajuma5e77f7d42014-11-27 14:19:1463 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
64 const gfx::Rect& clip,
schenney0154bfa2015-02-05 19:46:4965 PaintingControlSetting picture_control) override {
ajuma5e77f7d42014-11-27 14:19:1466 NOTIMPLEMENTED();
67 return DisplayItemList::Create();
68 }
dcheng716bedf2014-10-21 09:51:0869 bool FillsBoundsCompletely() const override { return false; }
[email protected]f34a24232012-09-20 22:59:5570};
71
sohan.jyotie3bd6192014-10-13 07:13:5972scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer(
73 ContentLayerClient* delegate) {
74 scoped_refptr<FakePictureLayer> to_return =
75 FakePictureLayer::Create(delegate);
76 to_return->SetIsDrawable(true);
77 return to_return;
78}
79
[email protected]fb661802013-03-25 01:59:3280scoped_refptr<ContentLayer> CreateDrawableContentLayer(
81 ContentLayerClient* delegate) {
82 scoped_refptr<ContentLayer> to_return = ContentLayer::Create(delegate);
83 to_return->SetIsDrawable(true);
84 return to_return;
[email protected]f34a24232012-09-20 22:59:5585}
86
[email protected]989386c2013-07-18 21:37:2387#define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
88 do { \
89 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
90 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
[email protected]904e9132012-11-01 00:12:4791 } while (false)
92
sohan.jyotie3bd6192014-10-13 07:13:5993#define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
94 do { \
95 EXPECT_FLOAT_EQ(expected, layer->draw_properties().ideal_contents_scale); \
96 } while (false)
97
[email protected]989386c2013-07-18 21:37:2398TEST_F(LayerTreeHostCommonTest, TransformsForNoOpLayer) {
[email protected]fb661802013-03-25 01:59:3299 // Sanity check: For layers positioned at zero, with zero size,
100 // and with identity transforms, then the draw transform,
101 // screen space transform, and the hierarchy passed on to children
102 // layers should also be identity transforms.
[email protected]94f206c12012-08-25 00:09:14103
[email protected]fb661802013-03-25 01:59:32104 scoped_refptr<Layer> parent = Layer::Create();
105 scoped_refptr<Layer> child = Layer::Create();
106 scoped_refptr<Layer> grand_child = Layer::Create();
107 parent->AddChild(child);
108 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14109
enne2097cab2014-09-25 20:16:31110 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28111 host->SetRootLayer(parent);
112
[email protected]fb661802013-03-25 01:59:32113 gfx::Transform identity_matrix;
114 SetLayerPropertiesForTesting(parent.get(),
115 identity_matrix,
[email protected]a2566412014-06-05 03:14:20116 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32117 gfx::PointF(),
118 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:57119 true,
[email protected]fb661802013-03-25 01:59:32120 false);
121 SetLayerPropertiesForTesting(child.get(),
122 identity_matrix,
[email protected]a2566412014-06-05 03:14:20123 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32124 gfx::PointF(),
125 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57126 true,
[email protected]fb661802013-03-25 01:59:32127 false);
128 SetLayerPropertiesForTesting(grand_child.get(),
129 identity_matrix,
[email protected]a2566412014-06-05 03:14:20130 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32131 gfx::PointF(),
132 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57133 true,
[email protected]fb661802013-03-25 01:59:32134 false);
[email protected]94f206c12012-08-25 00:09:14135
[email protected]fb661802013-03-25 01:59:32136 ExecuteCalculateDrawProperties(parent.get());
[email protected]94f206c12012-08-25 00:09:14137
[email protected]fb661802013-03-25 01:59:32138 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
139 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
140 child->screen_space_transform());
141 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
142 grand_child->draw_transform());
143 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
144 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14145}
146
[email protected]f9e56702014-06-13 01:19:59147TEST_F(LayerTreeHostCommonTest, DoNotSkipLayersWithHandlers) {
148 scoped_refptr<Layer> parent = Layer::Create();
149 scoped_refptr<Layer> child = Layer::Create();
150 scoped_refptr<Layer> grand_child = Layer::Create();
151 parent->AddChild(child);
152 child->AddChild(grand_child);
153
enne2097cab2014-09-25 20:16:31154 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]f9e56702014-06-13 01:19:59155 host->SetRootLayer(parent);
156
157 gfx::Transform identity_matrix;
158 SetLayerPropertiesForTesting(parent.get(),
159 identity_matrix,
160 gfx::Point3F(),
161 gfx::PointF(),
162 gfx::Size(100, 100),
163 true,
164 false);
165 SetLayerPropertiesForTesting(child.get(),
166 identity_matrix,
167 gfx::Point3F(),
168 gfx::PointF(10, 10),
169 gfx::Size(100, 100),
170 true,
171 false);
172 // This would have previously caused us to skip our subtree, but this would be
173 // wrong; we need up-to-date draw properties to do hit testing on the layers
174 // with handlers.
175 child->SetOpacity(0.f);
176 SetLayerPropertiesForTesting(grand_child.get(),
177 identity_matrix,
178 gfx::Point3F(),
179 gfx::PointF(10, 10),
180 gfx::Size(100, 100),
181 true,
182 false);
183 grand_child->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
184
185 ExecuteCalculateDrawProperties(parent.get());
186
187 // Check that we've computed draw properties for the subtree rooted at
188 // |child|.
189 EXPECT_FALSE(child->draw_transform().IsIdentity());
190 EXPECT_FALSE(grand_child->draw_transform().IsIdentity());
191}
192
[email protected]989386c2013-07-18 21:37:23193TEST_F(LayerTreeHostCommonTest, TransformsForSingleLayer) {
[email protected]fb661802013-03-25 01:59:32194 gfx::Transform identity_matrix;
195 scoped_refptr<Layer> layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:14196
[email protected]fb661802013-03-25 01:59:32197 scoped_refptr<Layer> root = Layer::Create();
198 SetLayerPropertiesForTesting(root.get(),
199 identity_matrix,
[email protected]a2566412014-06-05 03:14:20200 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32201 gfx::PointF(),
202 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57203 true,
[email protected]fb661802013-03-25 01:59:32204 false);
205 root->AddChild(layer);
[email protected]ecc12622012-10-30 20:45:42206
enne2097cab2014-09-25 20:16:31207 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28208 host->SetRootLayer(root);
209
[email protected]fb661802013-03-25 01:59:32210 // Case 2: Setting the bounds of the layer should not affect either the draw
211 // transform or the screenspace transform.
212 gfx::Transform translation_to_center;
213 translation_to_center.Translate(5.0, 6.0);
214 SetLayerPropertiesForTesting(layer.get(),
215 identity_matrix,
[email protected]a2566412014-06-05 03:14:20216 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32217 gfx::PointF(),
218 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57219 true,
[email protected]fb661802013-03-25 01:59:32220 false);
221 ExecuteCalculateDrawProperties(root.get());
222 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
223 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
224 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14225
[email protected]fb661802013-03-25 01:59:32226 // Case 3: The anchor point by itself (without a layer transform) should have
227 // no effect on the transforms.
228 SetLayerPropertiesForTesting(layer.get(),
229 identity_matrix,
[email protected]a2566412014-06-05 03:14:20230 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32231 gfx::PointF(),
232 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57233 true,
[email protected]fb661802013-03-25 01:59:32234 false);
235 ExecuteCalculateDrawProperties(root.get());
236 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, layer->draw_transform());
237 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
238 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14239
[email protected]fb661802013-03-25 01:59:32240 // Case 4: A change in actual position affects both the draw transform and
241 // screen space transform.
242 gfx::Transform position_transform;
[email protected]6138db702013-09-25 03:25:05243 position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32244 SetLayerPropertiesForTesting(layer.get(),
245 identity_matrix,
[email protected]a2566412014-06-05 03:14:20246 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32247 gfx::PointF(0.f, 1.2f),
248 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57249 true,
[email protected]fb661802013-03-25 01:59:32250 false);
251 ExecuteCalculateDrawProperties(root.get());
252 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform, layer->draw_transform());
253 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform,
254 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14255
[email protected]fb661802013-03-25 01:59:32256 // Case 5: In the correct sequence of transforms, the layer transform should
257 // pre-multiply the translation_to_center. This is easily tested by using a
258 // scale transform, because scale and translation are not commutative.
259 gfx::Transform layer_transform;
260 layer_transform.Scale3d(2.0, 2.0, 1.0);
261 SetLayerPropertiesForTesting(layer.get(),
262 layer_transform,
[email protected]a2566412014-06-05 03:14:20263 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32264 gfx::PointF(),
265 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57266 true,
[email protected]fb661802013-03-25 01:59:32267 false);
268 ExecuteCalculateDrawProperties(root.get());
269 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform, layer->draw_transform());
270 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform,
271 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14272
[email protected]fb661802013-03-25 01:59:32273 // Case 6: The layer transform should occur with respect to the anchor point.
274 gfx::Transform translation_to_anchor;
275 translation_to_anchor.Translate(5.0, 0.0);
276 gfx::Transform expected_result =
277 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
278 SetLayerPropertiesForTesting(layer.get(),
279 layer_transform,
[email protected]a2566412014-06-05 03:14:20280 gfx::Point3F(5.0f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32281 gfx::PointF(),
282 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57283 true,
[email protected]fb661802013-03-25 01:59:32284 false);
285 ExecuteCalculateDrawProperties(root.get());
286 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
287 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
288 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14289
[email protected]fb661802013-03-25 01:59:32290 // Case 7: Verify that position pre-multiplies the layer transform. The
291 // current implementation of CalculateDrawProperties does this implicitly, but
292 // it is still worth testing to detect accidental regressions.
293 expected_result = position_transform * translation_to_anchor *
294 layer_transform * Inverse(translation_to_anchor);
295 SetLayerPropertiesForTesting(layer.get(),
296 layer_transform,
[email protected]a2566412014-06-05 03:14:20297 gfx::Point3F(5.0f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32298 gfx::PointF(0.f, 1.2f),
299 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57300 true,
[email protected]fb661802013-03-25 01:59:32301 false);
302 ExecuteCalculateDrawProperties(root.get());
303 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result, layer->draw_transform());
304 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result,
305 layer->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14306}
307
[email protected]989386c2013-07-18 21:37:23308TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) {
miletusf57925d2014-10-01 19:38:13309 const gfx::ScrollOffset kScrollOffset(50, 100);
[email protected]fb661802013-03-25 01:59:32310 const gfx::Vector2dF kScrollDelta(2.34f, 5.67f);
[email protected]d30700f12013-07-31 08:21:01311 const gfx::Vector2d kMaxScrollOffset(200, 200);
[email protected]fb661802013-03-25 01:59:32312 const gfx::PointF kScrollLayerPosition(-kScrollOffset.x(),
313 -kScrollOffset.y());
314 const float kPageScale = 0.888f;
315 const float kDeviceScale = 1.666f;
[email protected]657b24c2013-03-06 09:01:20316
[email protected]fb661802013-03-25 01:59:32317 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:45318 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:47319 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]657b24c2013-03-06 09:01:20320
[email protected]fb661802013-03-25 01:59:32321 gfx::Transform identity_matrix;
322 scoped_ptr<LayerImpl> sublayer_scoped_ptr(
323 LayerImpl::Create(host_impl.active_tree(), 1));
324 LayerImpl* sublayer = sublayer_scoped_ptr.get();
325 sublayer->SetContentsScale(kPageScale * kDeviceScale,
326 kPageScale * kDeviceScale);
awoloszyne83f28c2014-12-22 15:40:00327 SetLayerPropertiesForTesting(sublayer, identity_matrix, gfx::Point3F(),
328 gfx::PointF(), gfx::Size(500, 500), true, false,
[email protected]fb661802013-03-25 01:59:32329 false);
[email protected]657b24c2013-03-06 09:01:20330
[email protected]adeda572014-01-31 00:49:47331 scoped_ptr<LayerImpl> scroll_layer_scoped_ptr(
[email protected]fb661802013-03-25 01:59:32332 LayerImpl::Create(host_impl.active_tree(), 2));
[email protected]adeda572014-01-31 00:49:47333 LayerImpl* scroll_layer = scroll_layer_scoped_ptr.get();
awoloszyne83f28c2014-12-22 15:40:00334 SetLayerPropertiesForTesting(scroll_layer, identity_matrix, gfx::Point3F(),
335 gfx::PointF(), gfx::Size(10, 20), true, false,
[email protected]fb661802013-03-25 01:59:32336 false);
[email protected]adeda572014-01-31 00:49:47337 scoped_ptr<LayerImpl> clip_layer_scoped_ptr(
338 LayerImpl::Create(host_impl.active_tree(), 4));
339 LayerImpl* clip_layer = clip_layer_scoped_ptr.get();
340
341 scroll_layer->SetScrollClipLayer(clip_layer->id());
342 clip_layer->SetBounds(
343 gfx::Size(scroll_layer->bounds().width() + kMaxScrollOffset.x(),
344 scroll_layer->bounds().height() + kMaxScrollOffset.y()));
345 scroll_layer->SetScrollClipLayer(clip_layer->id());
[email protected]fb661802013-03-25 01:59:32346 scroll_layer->SetScrollDelta(kScrollDelta);
347 gfx::Transform impl_transform;
[email protected]fb661802013-03-25 01:59:32348 scroll_layer->AddChild(sublayer_scoped_ptr.Pass());
[email protected]adeda572014-01-31 00:49:47349 LayerImpl* scroll_layer_raw_ptr = scroll_layer_scoped_ptr.get();
350 clip_layer->AddChild(scroll_layer_scoped_ptr.Pass());
aeliasf998da82015-02-03 01:40:51351 scroll_layer_raw_ptr->PushScrollOffsetFromMainThread(kScrollOffset);
[email protected]657b24c2013-03-06 09:01:20352
[email protected]fb661802013-03-25 01:59:32353 scoped_ptr<LayerImpl> root(LayerImpl::Create(host_impl.active_tree(), 3));
awoloszyne83f28c2014-12-22 15:40:00354 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
355 gfx::PointF(), gfx::Size(3, 4), true, false,
[email protected]fb661802013-03-25 01:59:32356 false);
[email protected]adeda572014-01-31 00:49:47357 root->AddChild(clip_layer_scoped_ptr.Pass());
awoloszyne83f28c2014-12-22 15:40:00358 root->SetHasRenderSurface(true);
[email protected]657b24c2013-03-06 09:01:20359
[email protected]f2136262013-04-26 21:10:19360 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32361 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32362 gfx::Transform expected_transform = identity_matrix;
363 gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta;
364 sub_layer_screen_position.Scale(kPageScale * kDeviceScale);
365 expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x()),
366 MathUtil::Round(sub_layer_screen_position.y()));
367 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
368 sublayer->draw_transform());
369 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
370 sublayer->screen_space_transform());
[email protected]657b24c2013-03-06 09:01:20371
[email protected]fb661802013-03-25 01:59:32372 gfx::Transform arbitrary_translate;
373 const float kTranslateX = 10.6f;
374 const float kTranslateY = 20.6f;
375 arbitrary_translate.Translate(kTranslateX, kTranslateY);
awoloszyne83f28c2014-12-22 15:40:00376 SetLayerPropertiesForTesting(scroll_layer, arbitrary_translate,
377 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
378 true, false, false);
[email protected]f2136262013-04-26 21:10:19379 ExecuteCalculateDrawProperties(
[email protected]9781afa2013-07-17 23:15:32380 root.get(), kDeviceScale, kPageScale, scroll_layer->parent());
[email protected]fb661802013-03-25 01:59:32381 expected_transform.MakeIdentity();
382 expected_transform.Translate(
383 MathUtil::Round(kTranslateX * kPageScale * kDeviceScale +
384 sub_layer_screen_position.x()),
385 MathUtil::Round(kTranslateY * kPageScale * kDeviceScale +
386 sub_layer_screen_position.y()));
387 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform,
388 sublayer->draw_transform());
[email protected]657b24c2013-03-06 09:01:20389}
390
[email protected]989386c2013-07-18 21:37:23391TEST_F(LayerTreeHostCommonTest, TransformsForSimpleHierarchy) {
[email protected]fb661802013-03-25 01:59:32392 gfx::Transform identity_matrix;
393 scoped_refptr<Layer> root = Layer::Create();
394 scoped_refptr<Layer> parent = Layer::Create();
395 scoped_refptr<Layer> child = Layer::Create();
396 scoped_refptr<Layer> grand_child = Layer::Create();
397 root->AddChild(parent);
398 parent->AddChild(child);
399 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14400
enne2097cab2014-09-25 20:16:31401 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28402 host->SetRootLayer(root);
403
[email protected]fb661802013-03-25 01:59:32404 // One-time setup of root layer
405 SetLayerPropertiesForTesting(root.get(),
406 identity_matrix,
[email protected]a2566412014-06-05 03:14:20407 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32408 gfx::PointF(),
409 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57410 true,
[email protected]fb661802013-03-25 01:59:32411 false);
[email protected]ecc12622012-10-30 20:45:42412
[email protected]fb661802013-03-25 01:59:32413 // Case 1: parent's anchor point should not affect child or grand_child.
414 SetLayerPropertiesForTesting(parent.get(),
415 identity_matrix,
[email protected]a2566412014-06-05 03:14:20416 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32417 gfx::PointF(),
418 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57419 true,
[email protected]fb661802013-03-25 01:59:32420 false);
421 SetLayerPropertiesForTesting(child.get(),
422 identity_matrix,
[email protected]a2566412014-06-05 03:14:20423 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32424 gfx::PointF(),
425 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57426 true,
[email protected]fb661802013-03-25 01:59:32427 false);
428 SetLayerPropertiesForTesting(grand_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(76, 78),
[email protected]56fffdd2014-02-11 19:50:57433 true,
[email protected]fb661802013-03-25 01:59:32434 false);
435 ExecuteCalculateDrawProperties(root.get());
436 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
437 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
438 child->screen_space_transform());
439 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
440 grand_child->draw_transform());
441 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
442 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14443
[email protected]fb661802013-03-25 01:59:32444 // Case 2: parent's position affects child and grand_child.
445 gfx::Transform parent_position_transform;
[email protected]6138db702013-09-25 03:25:05446 parent_position_transform.Translate(0.f, 1.2f);
[email protected]fb661802013-03-25 01:59:32447 SetLayerPropertiesForTesting(parent.get(),
448 identity_matrix,
[email protected]a2566412014-06-05 03:14:20449 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32450 gfx::PointF(0.f, 1.2f),
451 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57452 true,
[email protected]fb661802013-03-25 01:59:32453 false);
454 SetLayerPropertiesForTesting(child.get(),
455 identity_matrix,
[email protected]a2566412014-06-05 03:14:20456 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32457 gfx::PointF(),
458 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57459 true,
[email protected]fb661802013-03-25 01:59:32460 false);
461 SetLayerPropertiesForTesting(grand_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(76, 78),
[email protected]56fffdd2014-02-11 19:50:57466 true,
[email protected]fb661802013-03-25 01:59:32467 false);
468 ExecuteCalculateDrawProperties(root.get());
469 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
470 child->draw_transform());
471 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
472 child->screen_space_transform());
473 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
474 grand_child->draw_transform());
475 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform,
476 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14477
[email protected]fb661802013-03-25 01:59:32478 // Case 3: parent's local transform affects child and grandchild
479 gfx::Transform parent_layer_transform;
480 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
481 gfx::Transform parent_translation_to_anchor;
482 parent_translation_to_anchor.Translate(2.5, 3.0);
483 gfx::Transform parent_composite_transform =
484 parent_translation_to_anchor * parent_layer_transform *
485 Inverse(parent_translation_to_anchor);
486 SetLayerPropertiesForTesting(parent.get(),
487 parent_layer_transform,
[email protected]a2566412014-06-05 03:14:20488 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32489 gfx::PointF(),
490 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57491 true,
[email protected]fb661802013-03-25 01:59:32492 false);
493 SetLayerPropertiesForTesting(child.get(),
494 identity_matrix,
[email protected]a2566412014-06-05 03:14:20495 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32496 gfx::PointF(),
497 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57498 true,
[email protected]fb661802013-03-25 01:59:32499 false);
500 SetLayerPropertiesForTesting(grand_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(76, 78),
[email protected]56fffdd2014-02-11 19:50:57505 true,
[email protected]fb661802013-03-25 01:59:32506 false);
507 ExecuteCalculateDrawProperties(root.get());
508 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
509 child->draw_transform());
510 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
511 child->screen_space_transform());
512 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
513 grand_child->draw_transform());
514 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
515 grand_child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14516}
517
[email protected]989386c2013-07-18 21:37:23518TEST_F(LayerTreeHostCommonTest, TransformsForSingleRenderSurface) {
[email protected]fb661802013-03-25 01:59:32519 scoped_refptr<Layer> root = Layer::Create();
520 scoped_refptr<Layer> parent = Layer::Create();
521 scoped_refptr<Layer> child = Layer::Create();
522 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
523 make_scoped_refptr(new LayerWithForcedDrawsContent());
524 root->AddChild(parent);
525 parent->AddChild(child);
526 child->AddChild(grand_child);
[email protected]94f206c12012-08-25 00:09:14527
enne2097cab2014-09-25 20:16:31528 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28529 host->SetRootLayer(root);
530
[email protected]fb661802013-03-25 01:59:32531 // One-time setup of root layer
532 gfx::Transform identity_matrix;
533 SetLayerPropertiesForTesting(root.get(),
534 identity_matrix,
[email protected]a2566412014-06-05 03:14:20535 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32536 gfx::PointF(),
537 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57538 true,
[email protected]fb661802013-03-25 01:59:32539 false);
[email protected]ecc12622012-10-30 20:45:42540
[email protected]fb661802013-03-25 01:59:32541 // Child is set up so that a new render surface should be created.
542 child->SetOpacity(0.5f);
543 child->SetForceRenderSurface(true);
[email protected]94f206c12012-08-25 00:09:14544
[email protected]fb661802013-03-25 01:59:32545 gfx::Transform parent_layer_transform;
[email protected]6138db702013-09-25 03:25:05546 parent_layer_transform.Scale3d(1.f, 0.9f, 1.f);
[email protected]fb661802013-03-25 01:59:32547 gfx::Transform parent_translation_to_anchor;
548 parent_translation_to_anchor.Translate(25.0, 30.0);
[email protected]aedf4e52013-01-09 23:24:44549
[email protected]fb661802013-03-25 01:59:32550 gfx::Transform parent_composite_transform =
551 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39552 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32553 gfx::Vector2dF parent_composite_scale =
554 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
555 1.f);
556 gfx::Transform surface_sublayer_transform;
557 surface_sublayer_transform.Scale(parent_composite_scale.x(),
558 parent_composite_scale.y());
559 gfx::Transform surface_sublayer_composite_transform =
560 parent_composite_transform * Inverse(surface_sublayer_transform);
[email protected]94f206c12012-08-25 00:09:14561
[email protected]fb661802013-03-25 01:59:32562 // Child's render surface should not exist yet.
563 ASSERT_FALSE(child->render_surface());
[email protected]94f206c12012-08-25 00:09:14564
[email protected]fb661802013-03-25 01:59:32565 SetLayerPropertiesForTesting(parent.get(),
566 parent_layer_transform,
[email protected]a2566412014-06-05 03:14:20567 gfx::Point3F(25.0f, 30.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32568 gfx::PointF(),
569 gfx::Size(100, 120),
[email protected]56fffdd2014-02-11 19:50:57570 true,
[email protected]fb661802013-03-25 01:59:32571 false);
572 SetLayerPropertiesForTesting(child.get(),
573 identity_matrix,
[email protected]a2566412014-06-05 03:14:20574 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32575 gfx::PointF(),
576 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57577 true,
[email protected]fb661802013-03-25 01:59:32578 false);
579 SetLayerPropertiesForTesting(grand_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(8, 10),
[email protected]56fffdd2014-02-11 19:50:57584 true,
[email protected]fb661802013-03-25 01:59:32585 false);
586 ExecuteCalculateDrawProperties(root.get());
[email protected]94f206c12012-08-25 00:09:14587
[email protected]fb661802013-03-25 01:59:32588 // Render surface should have been created now.
589 ASSERT_TRUE(child->render_surface());
Daniel Chengeea98042014-08-26 00:28:10590 ASSERT_EQ(child.get(), child->render_target());
[email protected]94f206c12012-08-25 00:09:14591
[email protected]fb661802013-03-25 01:59:32592 // The child layer's draw transform should refer to its new render surface.
593 // The screen-space transform, however, should still refer to the root.
594 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform,
595 child->draw_transform());
596 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform,
597 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14598
[email protected]fb661802013-03-25 01:59:32599 // Because the grand_child is the only drawable content, the child's render
600 // surface will tighten its bounds to the grand_child. The scale at which the
601 // surface's subtree is drawn must be removed from the composite transform.
602 EXPECT_TRANSFORMATION_MATRIX_EQ(
603 surface_sublayer_composite_transform,
604 child->render_target()->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:14605
[email protected]fb661802013-03-25 01:59:32606 // The screen space is the same as the target since the child surface draws
607 // into the root.
608 EXPECT_TRANSFORMATION_MATRIX_EQ(
609 surface_sublayer_composite_transform,
610 child->render_target()->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:14611}
612
[email protected]989386c2013-07-18 21:37:23613TEST_F(LayerTreeHostCommonTest, TransformsForReplica) {
[email protected]fb661802013-03-25 01:59:32614 scoped_refptr<Layer> root = Layer::Create();
615 scoped_refptr<Layer> parent = Layer::Create();
616 scoped_refptr<Layer> child = Layer::Create();
617 scoped_refptr<Layer> child_replica = Layer::Create();
618 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
619 make_scoped_refptr(new LayerWithForcedDrawsContent());
620 root->AddChild(parent);
621 parent->AddChild(child);
622 child->AddChild(grand_child);
623 child->SetReplicaLayer(child_replica.get());
624
enne2097cab2014-09-25 20:16:31625 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28626 host->SetRootLayer(root);
627
[email protected]fb661802013-03-25 01:59:32628 // One-time setup of root layer
629 gfx::Transform identity_matrix;
630 SetLayerPropertiesForTesting(root.get(),
631 identity_matrix,
[email protected]a2566412014-06-05 03:14:20632 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32633 gfx::PointF(),
634 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57635 true,
[email protected]fb661802013-03-25 01:59:32636 false);
637
638 // Child is set up so that a new render surface should be created.
639 child->SetOpacity(0.5f);
640
641 gfx::Transform parent_layer_transform;
642 parent_layer_transform.Scale3d(2.0, 2.0, 1.0);
643 gfx::Transform parent_translation_to_anchor;
644 parent_translation_to_anchor.Translate(2.5, 3.0);
[email protected]fb661802013-03-25 01:59:32645 gfx::Transform parent_composite_transform =
646 parent_translation_to_anchor * parent_layer_transform *
[email protected]baf64d062014-02-16 22:10:39647 Inverse(parent_translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32648 gfx::Transform replica_layer_transform;
649 replica_layer_transform.Scale3d(3.0, 3.0, 1.0);
650 gfx::Vector2dF parent_composite_scale =
651 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform,
652 1.f);
653 gfx::Transform surface_sublayer_transform;
654 surface_sublayer_transform.Scale(parent_composite_scale.x(),
655 parent_composite_scale.y());
656 gfx::Transform replica_composite_transform =
657 parent_composite_transform * replica_layer_transform *
658 Inverse(surface_sublayer_transform);
vollick51ed1a22014-12-17 02:03:00659 child_replica->SetIsDrawable(true);
[email protected]fb661802013-03-25 01:59:32660 // Child's render surface should not exist yet.
661 ASSERT_FALSE(child->render_surface());
662
663 SetLayerPropertiesForTesting(parent.get(),
664 parent_layer_transform,
[email protected]a2566412014-06-05 03:14:20665 gfx::Point3F(2.5f, 3.0f, 0.f),
[email protected]fb661802013-03-25 01:59:32666 gfx::PointF(),
667 gfx::Size(10, 12),
[email protected]56fffdd2014-02-11 19:50:57668 true,
[email protected]fb661802013-03-25 01:59:32669 false);
670 SetLayerPropertiesForTesting(child.get(),
671 identity_matrix,
[email protected]a2566412014-06-05 03:14:20672 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32673 gfx::PointF(),
674 gfx::Size(16, 18),
[email protected]56fffdd2014-02-11 19:50:57675 true,
[email protected]fb661802013-03-25 01:59:32676 false);
677 SetLayerPropertiesForTesting(grand_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(-0.5f, -0.5f),
681 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:57682 true,
[email protected]fb661802013-03-25 01:59:32683 false);
684 SetLayerPropertiesForTesting(child_replica.get(),
685 replica_layer_transform,
[email protected]a2566412014-06-05 03:14:20686 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32687 gfx::PointF(),
688 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:57689 true,
[email protected]fb661802013-03-25 01:59:32690 false);
691 ExecuteCalculateDrawProperties(root.get());
692
693 // Render surface should have been created now.
694 ASSERT_TRUE(child->render_surface());
Daniel Chengeea98042014-08-26 00:28:10695 ASSERT_EQ(child.get(), child->render_target());
[email protected]fb661802013-03-25 01:59:32696
697 EXPECT_TRANSFORMATION_MATRIX_EQ(
698 replica_composite_transform,
699 child->render_target()->render_surface()->replica_draw_transform());
700 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform,
[email protected]56fffdd2014-02-11 19:50:57701 child->render_target()
702 ->render_surface()
[email protected]fb661802013-03-25 01:59:32703 ->replica_screen_space_transform());
704}
705
[email protected]989386c2013-07-18 21:37:23706TEST_F(LayerTreeHostCommonTest, TransformsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:32707 // This test creates a more complex tree and verifies it all at once. This
708 // covers the following cases:
709 // - layers that are described w.r.t. a render surface: should have draw
710 // transforms described w.r.t. that surface
711 // - A render surface described w.r.t. an ancestor render surface: should
712 // have a draw transform described w.r.t. that ancestor surface
713 // - Replicas of a render surface are described w.r.t. the replica's
714 // transform around its anchor, along with the surface itself.
715 // - Sanity check on recursion: verify transforms of layers described w.r.t.
716 // a render surface that is described w.r.t. an ancestor render surface.
717 // - verifying that each layer has a reference to the correct render surface
718 // and render target values.
719
720 scoped_refptr<Layer> root = Layer::Create();
721 scoped_refptr<Layer> parent = Layer::Create();
722 scoped_refptr<Layer> render_surface1 = Layer::Create();
723 scoped_refptr<Layer> render_surface2 = Layer::Create();
724 scoped_refptr<Layer> child_of_root = Layer::Create();
725 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
726 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
727 scoped_refptr<Layer> replica_of_rs1 = Layer::Create();
728 scoped_refptr<Layer> replica_of_rs2 = Layer::Create();
729 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
730 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
731 make_scoped_refptr(new LayerWithForcedDrawsContent());
732 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
733 make_scoped_refptr(new LayerWithForcedDrawsContent());
734 root->AddChild(parent);
735 parent->AddChild(render_surface1);
736 parent->AddChild(child_of_root);
737 render_surface1->AddChild(child_of_rs1);
738 render_surface1->AddChild(render_surface2);
739 render_surface2->AddChild(child_of_rs2);
740 child_of_root->AddChild(grand_child_of_root);
741 child_of_rs1->AddChild(grand_child_of_rs1);
742 child_of_rs2->AddChild(grand_child_of_rs2);
743 render_surface1->SetReplicaLayer(replica_of_rs1.get());
744 render_surface2->SetReplicaLayer(replica_of_rs2.get());
745
enne2097cab2014-09-25 20:16:31746 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:28747 host->SetRootLayer(root);
748
[email protected]fb661802013-03-25 01:59:32749 // In combination with descendant draws content, opacity != 1 forces the layer
750 // to have a new render surface.
751 render_surface1->SetOpacity(0.5f);
752 render_surface2->SetOpacity(0.33f);
753
754 // One-time setup of root layer
755 gfx::Transform identity_matrix;
756 SetLayerPropertiesForTesting(root.get(),
757 identity_matrix,
[email protected]a2566412014-06-05 03:14:20758 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:32759 gfx::PointF(),
760 gfx::Size(1, 2),
[email protected]56fffdd2014-02-11 19:50:57761 true,
[email protected]fb661802013-03-25 01:59:32762 false);
763
764 // All layers in the tree are initialized with an anchor at .25 and a size of
765 // (10,10). matrix "A" is the composite layer transform used in all layers,
[email protected]baf64d062014-02-16 22:10:39766 // Matrix "R" is the composite replica transform used in all replica layers.
[email protected]fb661802013-03-25 01:59:32767 gfx::Transform translation_to_anchor;
768 translation_to_anchor.Translate(2.5, 0.0);
769 gfx::Transform layer_transform;
770 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:32771 gfx::Transform replica_layer_transform;
772 replica_layer_transform.Scale3d(-2.0, 5.0, 1.0);
773
774 gfx::Transform A =
775 translation_to_anchor * layer_transform * Inverse(translation_to_anchor);
[email protected]fb661802013-03-25 01:59:32776 gfx::Transform R = A * translation_to_anchor * replica_layer_transform *
777 Inverse(translation_to_anchor);
778
779 gfx::Vector2dF surface1_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39780 MathUtil::ComputeTransform2dScaleComponents(A, 1.f);
[email protected]fb661802013-03-25 01:59:32781 gfx::Transform surface1_sublayer_transform;
782 surface1_sublayer_transform.Scale(surface1_parent_transform_scale.x(),
783 surface1_parent_transform_scale.y());
784
785 // SS1 = transform given to the subtree of render_surface1
786 gfx::Transform SS1 = surface1_sublayer_transform;
787 // S1 = transform to move from render_surface1 pixels to the layer space of
788 // the owning layer
789 gfx::Transform S1 = Inverse(surface1_sublayer_transform);
790
791 gfx::Vector2dF surface2_parent_transform_scale =
[email protected]baf64d062014-02-16 22:10:39792 MathUtil::ComputeTransform2dScaleComponents(SS1 * A, 1.f);
[email protected]fb661802013-03-25 01:59:32793 gfx::Transform surface2_sublayer_transform;
794 surface2_sublayer_transform.Scale(surface2_parent_transform_scale.x(),
795 surface2_parent_transform_scale.y());
796
797 // SS2 = transform given to the subtree of render_surface2
798 gfx::Transform SS2 = surface2_sublayer_transform;
799 // S2 = transform to move from render_surface2 pixels to the layer space of
800 // the owning layer
801 gfx::Transform S2 = Inverse(surface2_sublayer_transform);
802
803 SetLayerPropertiesForTesting(parent.get(),
804 layer_transform,
[email protected]a2566412014-06-05 03:14:20805 gfx::Point3F(2.5f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:32806 gfx::PointF(),
807 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:57808 true,
[email protected]fb661802013-03-25 01:59:32809 false);
810 SetLayerPropertiesForTesting(render_surface1.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_surface2.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(child_of_root.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_rs1.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_rs2.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(grand_child_of_root.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_rs1.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_rs2.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(replica_of_rs1.get(),
867 replica_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(),
[email protected]56fffdd2014-02-11 19:50:57871 true,
[email protected]fb661802013-03-25 01:59:32872 false);
873 SetLayerPropertiesForTesting(replica_of_rs2.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
881 ExecuteCalculateDrawProperties(root.get());
882
883 // Only layers that are associated with render surfaces should have an actual
884 // RenderSurface() value.
885 ASSERT_TRUE(root->render_surface());
886 ASSERT_FALSE(child_of_root->render_surface());
887 ASSERT_FALSE(grand_child_of_root->render_surface());
888
889 ASSERT_TRUE(render_surface1->render_surface());
890 ASSERT_FALSE(child_of_rs1->render_surface());
891 ASSERT_FALSE(grand_child_of_rs1->render_surface());
892
893 ASSERT_TRUE(render_surface2->render_surface());
894 ASSERT_FALSE(child_of_rs2->render_surface());
895 ASSERT_FALSE(grand_child_of_rs2->render_surface());
896
897 // Verify all render target accessors
Daniel Chengeea98042014-08-26 00:28:10898 EXPECT_EQ(root.get(), parent->render_target());
899 EXPECT_EQ(root.get(), child_of_root->render_target());
900 EXPECT_EQ(root.get(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:32901
Daniel Chengeea98042014-08-26 00:28:10902 EXPECT_EQ(render_surface1.get(), render_surface1->render_target());
903 EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target());
904 EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:32905
Daniel Chengeea98042014-08-26 00:28:10906 EXPECT_EQ(render_surface2.get(), render_surface2->render_target());
907 EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target());
908 EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:32909
910 // Verify layer draw transforms note that draw transforms are described with
911 // respect to the nearest ancestor render surface but screen space transforms
912 // are described with respect to the root.
913 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->draw_transform());
[email protected]baf64d062014-02-16 22:10:39914 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A, child_of_root->draw_transform());
915 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32916 grand_child_of_root->draw_transform());
917
918 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1, render_surface1->draw_transform());
[email protected]baf64d062014-02-16 22:10:39919 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A, child_of_rs1->draw_transform());
920 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1 * A * A,
[email protected]fb661802013-03-25 01:59:32921 grand_child_of_rs1->draw_transform());
922
923 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2, render_surface2->draw_transform());
[email protected]baf64d062014-02-16 22:10:39924 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A, child_of_rs2->draw_transform());
925 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2 * A * A,
[email protected]fb661802013-03-25 01:59:32926 grand_child_of_rs2->draw_transform());
927
928 // Verify layer screen-space transforms
929 //
930 EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39931 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:32932 child_of_root->screen_space_transform());
933 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39934 A * A * A, grand_child_of_root->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32935
[email protected]baf64d062014-02-16 22:10:39936 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A,
[email protected]fb661802013-03-25 01:59:32937 render_surface1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39938 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32939 child_of_rs1->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39940 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:32941 grand_child_of_rs1->screen_space_transform());
942
[email protected]baf64d062014-02-16 22:10:39943 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A,
[email protected]fb661802013-03-25 01:59:32944 render_surface2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39945 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A,
[email protected]fb661802013-03-25 01:59:32946 child_of_rs2->screen_space_transform());
[email protected]baf64d062014-02-16 22:10:39947 EXPECT_TRANSFORMATION_MATRIX_EQ(A * A * A * A * A,
[email protected]fb661802013-03-25 01:59:32948 grand_child_of_rs2->screen_space_transform());
949
950 // Verify render surface transforms.
951 //
952 // Draw transform of render surface 1 is described with respect to root.
953 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39954 A * A * S1, render_surface1->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32955 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39956 A * R * S1, render_surface1->render_surface()->replica_draw_transform());
[email protected]fb661802013-03-25 01:59:32957 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39958 A * A * S1, render_surface1->render_surface()->screen_space_transform());
[email protected]fb661802013-03-25 01:59:32959 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39960 A * R * S1,
[email protected]fb661802013-03-25 01:59:32961 render_surface1->render_surface()->replica_screen_space_transform());
962 // Draw transform of render surface 2 is described with respect to render
963 // surface 1.
964 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39965 SS1 * A * S2, render_surface2->render_surface()->draw_transform());
[email protected]fb661802013-03-25 01:59:32966 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39967 SS1 * R * S2,
[email protected]fb661802013-03-25 01:59:32968 render_surface2->render_surface()->replica_draw_transform());
969 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39970 A * A * A * S2,
[email protected]fb661802013-03-25 01:59:32971 render_surface2->render_surface()->screen_space_transform());
972 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:39973 A * A * R * S2,
[email protected]fb661802013-03-25 01:59:32974 render_surface2->render_surface()->replica_screen_space_transform());
975
976 // Sanity check. If these fail there is probably a bug in the test itself. It
977 // is expected that we correctly set up transforms so that the y-component of
978 // the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:26979 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
980 EXPECT_FLOAT_EQ(2.0,
981 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32982 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:26983 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32984
[email protected]803f6b52013-09-12 00:51:26985 EXPECT_FLOAT_EQ(2.0,
986 render_surface1->screen_space_transform().matrix().get(1, 3));
987 EXPECT_FLOAT_EQ(3.0,
988 child_of_rs1->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 4.0, grand_child_of_rs1->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(3.0,
993 render_surface2->screen_space_transform().matrix().get(1, 3));
994 EXPECT_FLOAT_EQ(4.0,
995 child_of_rs2->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 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:32998}
999
[email protected]989386c2013-07-18 21:37:231000TEST_F(LayerTreeHostCommonTest, TransformsForFlatteningLayer) {
[email protected]fb661802013-03-25 01:59:321001 // For layers that flatten their subtree, there should be an orthographic
1002 // projection (for x and y values) in the middle of the transform sequence.
1003 // Note that the way the code is currently implemented, it is not expected to
1004 // use a canonical orthographic projection.
1005
1006 scoped_refptr<Layer> root = Layer::Create();
1007 scoped_refptr<Layer> child = Layer::Create();
1008 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1009 make_scoped_refptr(new LayerWithForcedDrawsContent());
ajumad0d64422015-03-14 04:20:081010 scoped_refptr<LayerWithForcedDrawsContent> great_grand_child =
1011 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:321012
1013 gfx::Transform rotation_about_y_axis;
1014 rotation_about_y_axis.RotateAboutYAxis(30.0);
1015
1016 const gfx::Transform identity_matrix;
1017 SetLayerPropertiesForTesting(root.get(),
1018 identity_matrix,
[email protected]a2566412014-06-05 03:14:201019 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321020 gfx::PointF(),
1021 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571022 true,
[email protected]fb661802013-03-25 01:59:321023 false);
1024 SetLayerPropertiesForTesting(child.get(),
1025 rotation_about_y_axis,
[email protected]a2566412014-06-05 03:14:201026 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321027 gfx::PointF(),
1028 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571029 true,
[email protected]fb661802013-03-25 01:59:321030 false);
1031 SetLayerPropertiesForTesting(grand_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);
ajumad0d64422015-03-14 04:20:081038 SetLayerPropertiesForTesting(great_grand_child.get(), identity_matrix,
1039 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1040 true, false);
[email protected]fb661802013-03-25 01:59:321041
1042 root->AddChild(child);
1043 child->AddChild(grand_child);
ajumad0d64422015-03-14 04:20:081044 grand_child->AddChild(great_grand_child);
[email protected]fb661802013-03-25 01:59:321045 child->SetForceRenderSurface(true);
1046
enne2097cab2014-09-25 20:16:311047 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281048 host->SetRootLayer(root);
1049
[email protected]fb661802013-03-25 01:59:321050 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:571051 ASSERT_TRUE(root->should_flatten_transform());
1052 ASSERT_TRUE(child->should_flatten_transform());
1053 ASSERT_TRUE(grand_child->should_flatten_transform());
ajumad0d64422015-03-14 04:20:081054 ASSERT_TRUE(great_grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:321055
1056 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1057 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1058 gfx::Transform expected_grand_child_draw_transform =
1059 rotation_about_y_axis; // draws onto child's render surface
1060 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1061 flattened_rotation_about_y.FlattenTo2d();
1062 gfx::Transform expected_grand_child_screen_space_transform =
1063 flattened_rotation_about_y * rotation_about_y_axis;
ajumad0d64422015-03-14 04:20:081064 gfx::Transform expected_great_grand_child_draw_transform =
1065 flattened_rotation_about_y;
1066 gfx::Transform expected_great_grand_child_screen_space_transform =
1067 flattened_rotation_about_y * flattened_rotation_about_y;
[email protected]fb661802013-03-25 01:59:321068
1069 ExecuteCalculateDrawProperties(root.get());
1070
1071 // The child's draw transform should have been taken by its surface.
1072 ASSERT_TRUE(child->render_surface());
1073 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1074 child->render_surface()->draw_transform());
1075 EXPECT_TRANSFORMATION_MATRIX_EQ(
1076 expected_child_screen_space_transform,
1077 child->render_surface()->screen_space_transform());
1078 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1079 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1080 child->screen_space_transform());
1081 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1082 grand_child->draw_transform());
1083 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1084 grand_child->screen_space_transform());
ajumad0d64422015-03-14 04:20:081085 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform,
1086 great_grand_child->draw_transform());
1087 EXPECT_TRANSFORMATION_MATRIX_EQ(
1088 expected_great_grand_child_screen_space_transform,
1089 great_grand_child->screen_space_transform());
[email protected]fb661802013-03-25 01:59:321090}
1091
[email protected]989386c2013-07-18 21:37:231092TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321093 // A layer that is empty in one axis, but not the other, was accidentally
1094 // skipping a necessary translation. Without that translation, the coordinate
1095 // space of the layer's draw transform is incorrect.
1096 //
1097 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1098 // but if that layer becomes a render surface, then its draw transform is
1099 // implicitly inherited by the rest of the subtree, which then is positioned
1100 // incorrectly as a result.
1101
1102 scoped_refptr<Layer> root = Layer::Create();
1103 scoped_refptr<Layer> child = Layer::Create();
1104 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1105 make_scoped_refptr(new LayerWithForcedDrawsContent());
1106
1107 // The child height is zero, but has non-zero width that should be accounted
1108 // for while computing draw transforms.
1109 const gfx::Transform identity_matrix;
1110 SetLayerPropertiesForTesting(root.get(),
1111 identity_matrix,
[email protected]a2566412014-06-05 03:14:201112 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321113 gfx::PointF(),
1114 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571115 true,
[email protected]fb661802013-03-25 01:59:321116 false);
1117 SetLayerPropertiesForTesting(child.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(10, 0),
[email protected]56fffdd2014-02-11 19:50:571122 true,
[email protected]fb661802013-03-25 01:59:321123 false);
1124 SetLayerPropertiesForTesting(grand_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, 10),
[email protected]56fffdd2014-02-11 19:50:571129 true,
[email protected]fb661802013-03-25 01:59:321130 false);
1131
1132 root->AddChild(child);
1133 child->AddChild(grand_child);
1134 child->SetForceRenderSurface(true);
1135
enne2097cab2014-09-25 20:16:311136 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281137 host->SetRootLayer(root);
1138
[email protected]fb661802013-03-25 01:59:321139 ExecuteCalculateDrawProperties(root.get());
1140
1141 ASSERT_TRUE(child->render_surface());
1142 // This is the real test, the rest are sanity checks.
1143 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1144 child->render_surface()->draw_transform());
1145 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1146 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1147 grand_child->draw_transform());
1148}
1149
[email protected]989386c2013-07-18 21:37:231150TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321151 // Transformations applied at the root of the tree should be forwarded
1152 // to child layers instead of applied to the root RenderSurface.
1153 const gfx::Transform identity_matrix;
[email protected]d5754282014-04-09 00:43:291154 scoped_refptr<LayerWithForcedDrawsContent> root =
1155 new LayerWithForcedDrawsContent;
1156 scoped_refptr<LayerWithForcedDrawsContent> child =
1157 new LayerWithForcedDrawsContent;
[email protected]adeda572014-01-31 00:49:471158 child->SetScrollClipLayerId(root->id());
[email protected]f224cc92013-06-06 23:23:321159 root->AddChild(child);
1160
enne2097cab2014-09-25 20:16:311161 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281162 host->SetRootLayer(root);
1163
[email protected]f224cc92013-06-06 23:23:321164 SetLayerPropertiesForTesting(root.get(),
1165 identity_matrix,
[email protected]a2566412014-06-05 03:14:201166 gfx::Point3F(),
[email protected]f224cc92013-06-06 23:23:321167 gfx::PointF(),
1168 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571169 true,
[email protected]f224cc92013-06-06 23:23:321170 false);
1171 SetLayerPropertiesForTesting(child.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
[email protected]f224cc92013-06-06 23:23:321179 gfx::Transform translate;
1180 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231181 {
1182 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531183 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221184 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531185 inputs.can_adjust_raster_scales = true;
1186 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231187 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1188 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1189 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201190 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1191 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231192 }
[email protected]f224cc92013-06-06 23:23:321193
1194 gfx::Transform scale;
1195 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231196 {
1197 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531198 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221199 root.get(), root->bounds(), scale, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531200 inputs.can_adjust_raster_scales = true;
1201 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231202 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1203 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1204 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201205 EXPECT_EQ(2.f, root->draw_properties().device_scale_factor);
1206 EXPECT_EQ(2.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231207 }
[email protected]f224cc92013-06-06 23:23:321208
1209 gfx::Transform rotate;
1210 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231211 {
1212 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531213 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221214 root.get(), root->bounds(), rotate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531215 inputs.can_adjust_raster_scales = true;
1216 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231217 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1218 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1219 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201220 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1221 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231222 }
[email protected]f224cc92013-06-06 23:23:321223
1224 gfx::Transform composite;
1225 composite.ConcatTransform(translate);
1226 composite.ConcatTransform(scale);
1227 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231228 {
1229 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531230 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221231 root.get(), root->bounds(), composite, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531232 inputs.can_adjust_raster_scales = true;
1233 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231234 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1235 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1236 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1237 }
[email protected]f224cc92013-06-06 23:23:321238
[email protected]9781afa2013-07-17 23:15:321239 // Verify it composes correctly with device scale.
1240 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231241
1242 {
1243 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531244 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221245 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531246 inputs.device_scale_factor = device_scale_factor;
1247 inputs.can_adjust_raster_scales = true;
1248 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231249 gfx::Transform device_scaled_translate = translate;
1250 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1251 EXPECT_EQ(device_scaled_translate,
1252 root->draw_properties().target_space_transform);
1253 EXPECT_EQ(device_scaled_translate,
1254 child->draw_properties().target_space_transform);
1255 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201256 EXPECT_EQ(device_scale_factor, root->draw_properties().device_scale_factor);
1257 EXPECT_EQ(device_scale_factor,
1258 child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231259 }
[email protected]9781afa2013-07-17 23:15:321260
1261 // Verify it composes correctly with page scale.
1262 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231263
1264 {
1265 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531266 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221267 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531268 inputs.page_scale_factor = page_scale_factor;
1269 inputs.page_scale_application_layer = root.get();
1270 inputs.can_adjust_raster_scales = true;
1271 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231272 gfx::Transform page_scaled_translate = translate;
1273 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1274 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1275 EXPECT_EQ(page_scaled_translate,
1276 child->draw_properties().target_space_transform);
1277 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201278 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1279 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231280 }
[email protected]9781afa2013-07-17 23:15:321281
[email protected]f224cc92013-06-06 23:23:321282 // Verify that it composes correctly with transforms directly on root layer.
1283 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231284
1285 {
1286 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531287 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221288 root.get(), root->bounds(), composite, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531289 inputs.can_adjust_raster_scales = true;
1290 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231291 gfx::Transform compositeSquared = composite;
1292 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261293 EXPECT_TRANSFORMATION_MATRIX_EQ(
1294 compositeSquared, root->draw_properties().target_space_transform);
1295 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391296 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231297 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1298 }
[email protected]f224cc92013-06-06 23:23:321299}
1300
[email protected]989386c2013-07-18 21:37:231301TEST_F(LayerTreeHostCommonTest,
1302 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
[email protected]fb661802013-03-25 01:59:321303 scoped_refptr<Layer> parent = Layer::Create();
1304 scoped_refptr<Layer> render_surface1 = Layer::Create();
1305 scoped_refptr<LayerWithForcedDrawsContent> child =
1306 make_scoped_refptr(new LayerWithForcedDrawsContent());
1307
enne2097cab2014-09-25 20:16:311308 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281309 host->SetRootLayer(parent);
1310
[email protected]fb661802013-03-25 01:59:321311 const gfx::Transform identity_matrix;
1312 SetLayerPropertiesForTesting(parent.get(),
1313 identity_matrix,
[email protected]a2566412014-06-05 03:14:201314 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321315 gfx::PointF(),
1316 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571317 true,
[email protected]fb661802013-03-25 01:59:321318 false);
1319 SetLayerPropertiesForTesting(render_surface1.get(),
1320 identity_matrix,
[email protected]a2566412014-06-05 03:14:201321 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321322 gfx::PointF(),
1323 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571324 true,
[email protected]fb661802013-03-25 01:59:321325 false);
1326 SetLayerPropertiesForTesting(child.get(),
1327 identity_matrix,
[email protected]a2566412014-06-05 03:14:201328 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321329 gfx::PointF(30.f, 30.f),
1330 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571331 true,
[email protected]fb661802013-03-25 01:59:321332 false);
1333
1334 parent->AddChild(render_surface1);
1335 parent->SetMasksToBounds(true);
1336 render_surface1->AddChild(child);
1337 render_surface1->SetForceRenderSurface(true);
1338
[email protected]989386c2013-07-18 21:37:231339 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531340 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1341 parent.get(),
1342 parent->bounds(),
1343 gfx::Transform(),
1344 &render_surface_layer_list);
1345 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321346
1347 // The child layer's content is entirely outside the parent's clip rect, so
1348 // the intermediate render surface should not be listed here, even if it was
1349 // forced to be created. Render surfaces without children or visible content
1350 // are unexpected at draw time (e.g. we might try to create a content texture
1351 // of size 0).
1352 ASSERT_TRUE(parent->render_surface());
[email protected]fb661802013-03-25 01:59:321353 EXPECT_EQ(1U, render_surface_layer_list.size());
1354}
1355
[email protected]989386c2013-07-18 21:37:231356TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
[email protected]fb661802013-03-25 01:59:321357 scoped_refptr<Layer> parent = Layer::Create();
1358 scoped_refptr<Layer> render_surface1 = Layer::Create();
1359 scoped_refptr<LayerWithForcedDrawsContent> child =
1360 make_scoped_refptr(new LayerWithForcedDrawsContent());
1361
enne2097cab2014-09-25 20:16:311362 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281363 host->SetRootLayer(parent);
1364
[email protected]fb661802013-03-25 01:59:321365 const gfx::Transform identity_matrix;
1366 SetLayerPropertiesForTesting(render_surface1.get(),
1367 identity_matrix,
[email protected]a2566412014-06-05 03:14:201368 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321369 gfx::PointF(),
1370 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571371 true,
[email protected]fb661802013-03-25 01:59:321372 false);
1373 SetLayerPropertiesForTesting(child.get(),
1374 identity_matrix,
[email protected]a2566412014-06-05 03:14:201375 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321376 gfx::PointF(),
1377 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571378 true,
[email protected]fb661802013-03-25 01:59:321379 false);
1380
1381 parent->AddChild(render_surface1);
1382 render_surface1->AddChild(child);
1383 render_surface1->SetForceRenderSurface(true);
1384 render_surface1->SetOpacity(0.f);
1385
[email protected]989386c2013-07-18 21:37:231386 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531387 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1388 parent.get(), parent->bounds(), &render_surface_layer_list);
1389 inputs.can_adjust_raster_scales = true;
1390 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321391
1392 // Since the layer is transparent, render_surface1->render_surface() should
1393 // not have gotten added anywhere. Also, the drawable content rect should not
1394 // have been extended by the children.
1395 ASSERT_TRUE(parent->render_surface());
1396 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1397 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231398 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321399 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1400}
1401
rosca948d29d2014-11-09 10:25:131402TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
1403 scoped_refptr<Layer> parent = Layer::Create();
1404 scoped_refptr<LayerWithForcedDrawsContent> child =
1405 make_scoped_refptr(new LayerWithForcedDrawsContent());
1406
1407 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
1408 host->SetRootLayer(parent);
1409
1410 const gfx::Transform identity_matrix;
1411 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
1412 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
1413 gfx::PointF(), gfx::Size(10, 10), true, false);
1414
1415 parent->AddChild(child);
1416 child->SetBlendMode(blend_mode);
1417
1418 RenderSurfaceLayerList render_surface_layer_list;
1419 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1420 parent.get(), parent->bounds(), &render_surface_layer_list);
1421 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1422
1423 // Since the child layer has a blend mode other than normal, it should get
1424 // its own render surface. Also, layer's draw_properties should contain the
1425 // default blend mode, since the render surface becomes responsible for
1426 // applying the blend mode.
1427 ASSERT_TRUE(child->render_surface());
1428 EXPECT_EQ(1U, child->render_surface()->layer_list().size());
1429 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_properties().blend_mode);
1430}
1431
[email protected]989386c2013-07-18 21:37:231432TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
[email protected]fb661802013-03-25 01:59:321433 scoped_refptr<Layer> parent = Layer::Create();
1434 scoped_refptr<Layer> render_surface1 = Layer::Create();
1435 scoped_refptr<LayerWithForcedDrawsContent> child =
1436 make_scoped_refptr(new LayerWithForcedDrawsContent());
1437 render_surface1->SetForceRenderSurface(true);
1438
enne2097cab2014-09-25 20:16:311439 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281440 host->SetRootLayer(parent);
1441
[email protected]fb661802013-03-25 01:59:321442 const gfx::Transform identity_matrix;
1443 SetLayerPropertiesForTesting(parent.get(),
1444 identity_matrix,
[email protected]a2566412014-06-05 03:14:201445 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321446 gfx::PointF(),
1447 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571448 true,
[email protected]fb661802013-03-25 01:59:321449 false);
1450 SetLayerPropertiesForTesting(render_surface1.get(),
1451 identity_matrix,
[email protected]a2566412014-06-05 03:14:201452 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321453 gfx::PointF(),
1454 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571455 true,
[email protected]fb661802013-03-25 01:59:321456 false);
1457 SetLayerPropertiesForTesting(child.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
1465 parent->AddChild(render_surface1);
1466 render_surface1->AddChild(child);
1467
1468 // Sanity check before the actual test
1469 EXPECT_FALSE(parent->render_surface());
1470 EXPECT_FALSE(render_surface1->render_surface());
1471
[email protected]989386c2013-07-18 21:37:231472 {
1473 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531474 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1475 parent.get(), parent->bounds(), &render_surface_layer_list);
1476 inputs.can_adjust_raster_scales = true;
1477 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321478
[email protected]989386c2013-07-18 21:37:231479 // The root layer always creates a render surface
1480 EXPECT_TRUE(parent->render_surface());
1481 EXPECT_TRUE(render_surface1->render_surface());
1482 EXPECT_EQ(2U, render_surface_layer_list.size());
1483 }
[email protected]fb661802013-03-25 01:59:321484
[email protected]989386c2013-07-18 21:37:231485 {
1486 RenderSurfaceLayerList render_surface_layer_list;
1487 render_surface1->SetForceRenderSurface(false);
[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]989386c2013-07-18 21:37:231492 EXPECT_TRUE(parent->render_surface());
1493 EXPECT_FALSE(render_surface1->render_surface());
1494 EXPECT_EQ(1U, render_surface_layer_list.size());
1495 }
[email protected]fb661802013-03-25 01:59:321496}
1497
ajuma246190a2015-03-11 20:56:031498TEST_F(LayerTreeHostCommonTest, RenderSurfacesFlattenScreenSpaceTransform) {
1499 // Render surfaces act as a flattening point for their subtree, so should
1500 // always flatten the target-to-screen space transform seen by descendants.
1501
1502 scoped_refptr<Layer> root = Layer::Create();
1503 scoped_refptr<Layer> parent = Layer::Create();
1504 scoped_refptr<LayerWithForcedDrawsContent> child =
1505 make_scoped_refptr(new LayerWithForcedDrawsContent());
1506 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1507 make_scoped_refptr(new LayerWithForcedDrawsContent());
1508
1509 gfx::Transform rotation_about_y_axis;
1510 rotation_about_y_axis.RotateAboutYAxis(30.0);
1511 // Make |parent| have a render surface.
1512 parent->SetOpacity(0.9f);
1513
1514 const gfx::Transform identity_matrix;
1515 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
1516 gfx::PointF(), gfx::Size(100, 100), true, false);
1517 SetLayerPropertiesForTesting(parent.get(), rotation_about_y_axis,
1518 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1519 true, false);
1520 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
1521 gfx::PointF(), gfx::Size(10, 10), true, false);
1522 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
1523 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1524 true, false);
1525
1526 root->AddChild(parent);
1527 parent->AddChild(child);
1528 child->AddChild(grand_child);
1529
1530 grand_child->SetShouldFlattenTransform(false);
1531
1532 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
1533 host->SetRootLayer(root);
1534
1535 // Only grand_child should preserve 3d.
1536 EXPECT_TRUE(root->should_flatten_transform());
1537 EXPECT_TRUE(parent->should_flatten_transform());
1538 EXPECT_TRUE(child->should_flatten_transform());
1539 EXPECT_FALSE(grand_child->should_flatten_transform());
1540
1541 gfx::Transform expected_child_draw_transform = identity_matrix;
1542 gfx::Transform expected_grand_child_draw_transform = identity_matrix;
1543
1544 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1545 flattened_rotation_about_y.FlattenTo2d();
1546
1547 ExecuteCalculateDrawProperties(root.get());
1548
1549 EXPECT_TRUE(parent->render_surface());
1550 EXPECT_FALSE(child->render_surface());
1551 EXPECT_FALSE(grand_child->render_surface());
1552
1553 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1554 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1555 grand_child->draw_transform());
1556
1557 // The screen-space transform inherited by |child| and |grand_child| should
1558 // have been flattened at their render target. In particular, the fact that
1559 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1560 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1561 child->screen_space_transform());
1562 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y,
1563 grand_child->screen_space_transform());
1564}
1565
[email protected]989386c2013-07-18 21:37:231566TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321567 // The entire subtree of layers that are outside the clip rect should be
1568 // culled away, and should not affect the render_surface_layer_list.
1569 //
1570 // The test tree is set up as follows:
1571 // - all layers except the leaf_nodes are forced to be a new render surface
1572 // that have something to draw.
1573 // - parent is a large container layer.
1574 // - child has masksToBounds=true to cause clipping.
1575 // - grand_child is positioned outside of the child's bounds
1576 // - great_grand_child is also kept outside child's bounds.
1577 //
1578 // In this configuration, grand_child and great_grand_child are completely
1579 // outside the clip rect, and they should never get scheduled on the list of
1580 // render surfaces.
1581 //
1582
1583 const gfx::Transform identity_matrix;
1584 scoped_refptr<Layer> parent = Layer::Create();
1585 scoped_refptr<Layer> child = Layer::Create();
1586 scoped_refptr<Layer> grand_child = Layer::Create();
1587 scoped_refptr<Layer> great_grand_child = Layer::Create();
1588 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1589 make_scoped_refptr(new LayerWithForcedDrawsContent());
1590 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1591 make_scoped_refptr(new LayerWithForcedDrawsContent());
1592 parent->AddChild(child);
1593 child->AddChild(grand_child);
1594 grand_child->AddChild(great_grand_child);
1595
enne2097cab2014-09-25 20:16:311596 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281597 host->SetRootLayer(parent);
1598
[email protected]fb661802013-03-25 01:59:321599 // leaf_node1 ensures that parent and child are kept on the
1600 // render_surface_layer_list, even though grand_child and great_grand_child
1601 // should be clipped.
1602 child->AddChild(leaf_node1);
1603 great_grand_child->AddChild(leaf_node2);
1604
1605 SetLayerPropertiesForTesting(parent.get(),
1606 identity_matrix,
[email protected]a2566412014-06-05 03:14:201607 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321608 gfx::PointF(),
1609 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571610 true,
[email protected]fb661802013-03-25 01:59:321611 false);
1612 SetLayerPropertiesForTesting(child.get(),
1613 identity_matrix,
[email protected]a2566412014-06-05 03:14:201614 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321615 gfx::PointF(),
1616 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571617 true,
[email protected]fb661802013-03-25 01:59:321618 false);
1619 SetLayerPropertiesForTesting(grand_child.get(),
1620 identity_matrix,
[email protected]a2566412014-06-05 03:14:201621 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321622 gfx::PointF(45.f, 45.f),
1623 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571624 true,
[email protected]fb661802013-03-25 01:59:321625 false);
1626 SetLayerPropertiesForTesting(great_grand_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(10, 10),
[email protected]56fffdd2014-02-11 19:50:571631 true,
[email protected]fb661802013-03-25 01:59:321632 false);
1633 SetLayerPropertiesForTesting(leaf_node1.get(),
1634 identity_matrix,
[email protected]a2566412014-06-05 03:14:201635 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321636 gfx::PointF(),
1637 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571638 true,
[email protected]fb661802013-03-25 01:59:321639 false);
1640 SetLayerPropertiesForTesting(leaf_node2.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(20, 20),
[email protected]56fffdd2014-02-11 19:50:571645 true,
[email protected]fb661802013-03-25 01:59:321646 false);
1647
1648 child->SetMasksToBounds(true);
1649 child->SetOpacity(0.4f);
1650 child->SetForceRenderSurface(true);
1651 grand_child->SetOpacity(0.5f);
1652 great_grand_child->SetOpacity(0.4f);
1653
[email protected]989386c2013-07-18 21:37:231654 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531655 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1656 parent.get(), parent->bounds(), &render_surface_layer_list);
1657 inputs.can_adjust_raster_scales = true;
1658 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321659
1660 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231661 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1662 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321663}
1664
[email protected]989386c2013-07-18 21:37:231665TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321666 // When a render surface has a clip rect, it is used to clip the content rect
1667 // of the surface. When the render surface is animating its transforms, then
1668 // the content rect's position in the clip rect is not defined on the main
1669 // thread, and its content rect should not be clipped.
1670
1671 // The test tree is set up as follows:
1672 // - parent is a container layer that masksToBounds=true to cause clipping.
1673 // - child is a render surface, which has a clip rect set to the bounds of
1674 // the parent.
1675 // - grand_child is a render surface, and the only visible content in child.
1676 // It is positioned outside of the clip rect from parent.
1677
1678 // In this configuration, grand_child should be outside the clipped
1679 // content rect of the child, making grand_child not appear in the
1680 // render_surface_layer_list. However, when we place an animation on the
1681 // child, this clipping should be avoided and we should keep the grand_child
1682 // in the render_surface_layer_list.
1683
1684 const gfx::Transform identity_matrix;
1685 scoped_refptr<Layer> parent = Layer::Create();
1686 scoped_refptr<Layer> child = Layer::Create();
1687 scoped_refptr<Layer> grand_child = Layer::Create();
1688 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1689 make_scoped_refptr(new LayerWithForcedDrawsContent());
1690 parent->AddChild(child);
1691 child->AddChild(grand_child);
1692 grand_child->AddChild(leaf_node);
1693
enne2097cab2014-09-25 20:16:311694 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281695 host->SetRootLayer(parent);
1696
[email protected]fb661802013-03-25 01:59:321697 SetLayerPropertiesForTesting(parent.get(),
1698 identity_matrix,
[email protected]a2566412014-06-05 03:14:201699 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321700 gfx::PointF(),
1701 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571702 true,
[email protected]fb661802013-03-25 01:59:321703 false);
1704 SetLayerPropertiesForTesting(child.get(),
1705 identity_matrix,
[email protected]a2566412014-06-05 03:14:201706 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321707 gfx::PointF(),
1708 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571709 true,
[email protected]fb661802013-03-25 01:59:321710 false);
1711 SetLayerPropertiesForTesting(grand_child.get(),
1712 identity_matrix,
[email protected]a2566412014-06-05 03:14:201713 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321714 gfx::PointF(200.f, 200.f),
1715 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571716 true,
[email protected]fb661802013-03-25 01:59:321717 false);
1718 SetLayerPropertiesForTesting(leaf_node.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(10, 10),
[email protected]56fffdd2014-02-11 19:50:571723 true,
[email protected]fb661802013-03-25 01:59:321724 false);
1725
1726 parent->SetMasksToBounds(true);
1727 child->SetOpacity(0.4f);
1728 child->SetForceRenderSurface(true);
1729 grand_child->SetOpacity(0.4f);
1730 grand_child->SetForceRenderSurface(true);
1731
[email protected]989386c2013-07-18 21:37:231732 {
1733 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531734 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1735 parent.get(), parent->bounds(), &render_surface_layer_list);
1736 inputs.can_adjust_raster_scales = true;
1737 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321738
[email protected]989386c2013-07-18 21:37:231739 // Without an animation, we should cull child and grand_child from the
1740 // render_surface_layer_list.
1741 ASSERT_EQ(1U, render_surface_layer_list.size());
1742 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1743 }
[email protected]fb661802013-03-25 01:59:321744
1745 // Now put an animating transform on child.
1746 AddAnimatedTransformToController(
1747 child->layer_animation_controller(), 10.0, 30, 0);
1748
[email protected]989386c2013-07-18 21:37:231749 {
1750 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531751 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1752 parent.get(), parent->bounds(), &render_surface_layer_list);
1753 inputs.can_adjust_raster_scales = true;
1754 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321755
[email protected]989386c2013-07-18 21:37:231756 // With an animating transform, we should keep child and grand_child in the
1757 // render_surface_layer_list.
1758 ASSERT_EQ(3U, render_surface_layer_list.size());
1759 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1760 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1761 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
1762 }
[email protected]fb661802013-03-25 01:59:321763}
1764
[email protected]989386c2013-07-18 21:37:231765TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:321766 // Layer's IsClipped() property is set to true when:
1767 // - the layer clips its subtree, e.g. masks to bounds,
1768 // - the layer is clipped by an ancestor that contributes to the same
1769 // render target,
1770 // - a surface is clipped by an ancestor that contributes to the same
1771 // render target.
1772 //
1773 // In particular, for a layer that owns a render surface:
1774 // - the render surface inherits any clip from ancestors, and does NOT
1775 // pass that clipped status to the layer itself.
1776 // - but if the layer itself masks to bounds, it is considered clipped
1777 // and propagates the clip to the subtree.
1778
1779 const gfx::Transform identity_matrix;
1780 scoped_refptr<Layer> root = Layer::Create();
1781 scoped_refptr<Layer> parent = Layer::Create();
1782 scoped_refptr<Layer> child1 = Layer::Create();
1783 scoped_refptr<Layer> child2 = Layer::Create();
1784 scoped_refptr<Layer> grand_child = Layer::Create();
1785 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1786 make_scoped_refptr(new LayerWithForcedDrawsContent());
1787 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1788 make_scoped_refptr(new LayerWithForcedDrawsContent());
1789 root->AddChild(parent);
1790 parent->AddChild(child1);
1791 parent->AddChild(child2);
1792 child1->AddChild(grand_child);
1793 child2->AddChild(leaf_node2);
1794 grand_child->AddChild(leaf_node1);
1795
enne2097cab2014-09-25 20:16:311796 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281797 host->SetRootLayer(root);
1798
[email protected]fb661802013-03-25 01:59:321799 child2->SetForceRenderSurface(true);
1800
1801 SetLayerPropertiesForTesting(root.get(),
1802 identity_matrix,
[email protected]a2566412014-06-05 03:14:201803 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321804 gfx::PointF(),
1805 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571806 true,
[email protected]fb661802013-03-25 01:59:321807 false);
1808 SetLayerPropertiesForTesting(parent.get(),
1809 identity_matrix,
[email protected]a2566412014-06-05 03:14:201810 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321811 gfx::PointF(),
1812 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571813 true,
[email protected]fb661802013-03-25 01:59:321814 false);
1815 SetLayerPropertiesForTesting(child1.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(child2.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(grand_child.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(leaf_node1.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(leaf_node2.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
[email protected]989386c2013-07-18 21:37:231851 // Case 1: nothing is clipped except the root render surface.
1852 {
1853 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531854 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1855 root.get(), parent->bounds(), &render_surface_layer_list);
1856 inputs.can_adjust_raster_scales = true;
1857 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321858
[email protected]989386c2013-07-18 21:37:231859 ASSERT_TRUE(root->render_surface());
1860 ASSERT_TRUE(child2->render_surface());
1861
1862 EXPECT_FALSE(root->is_clipped());
1863 EXPECT_TRUE(root->render_surface()->is_clipped());
1864 EXPECT_FALSE(parent->is_clipped());
1865 EXPECT_FALSE(child1->is_clipped());
1866 EXPECT_FALSE(child2->is_clipped());
1867 EXPECT_FALSE(child2->render_surface()->is_clipped());
1868 EXPECT_FALSE(grand_child->is_clipped());
1869 EXPECT_FALSE(leaf_node1->is_clipped());
1870 EXPECT_FALSE(leaf_node2->is_clipped());
1871 }
[email protected]fb661802013-03-25 01:59:321872
1873 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1874 // surface are clipped. But layers that contribute to child2's surface are
1875 // not clipped explicitly because child2's surface already accounts for
1876 // that clip.
[email protected]989386c2013-07-18 21:37:231877 {
1878 RenderSurfaceLayerList render_surface_layer_list;
1879 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531880 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1881 root.get(), parent->bounds(), &render_surface_layer_list);
1882 inputs.can_adjust_raster_scales = true;
1883 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321884
[email protected]989386c2013-07-18 21:37:231885 ASSERT_TRUE(root->render_surface());
1886 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321887
[email protected]989386c2013-07-18 21:37:231888 EXPECT_FALSE(root->is_clipped());
1889 EXPECT_TRUE(root->render_surface()->is_clipped());
1890 EXPECT_TRUE(parent->is_clipped());
1891 EXPECT_TRUE(child1->is_clipped());
1892 EXPECT_FALSE(child2->is_clipped());
1893 EXPECT_TRUE(child2->render_surface()->is_clipped());
1894 EXPECT_TRUE(grand_child->is_clipped());
1895 EXPECT_TRUE(leaf_node1->is_clipped());
1896 EXPECT_FALSE(leaf_node2->is_clipped());
1897 }
[email protected]fb661802013-03-25 01:59:321898
1899 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1900 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:231901 {
1902 RenderSurfaceLayerList render_surface_layer_list;
1903 parent->SetMasksToBounds(false);
1904 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531905 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1906 root.get(), parent->bounds(), &render_surface_layer_list);
1907 inputs.can_adjust_raster_scales = true;
1908 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321909
[email protected]989386c2013-07-18 21:37:231910 ASSERT_TRUE(root->render_surface());
1911 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321912
[email protected]989386c2013-07-18 21:37:231913 EXPECT_FALSE(root->is_clipped());
1914 EXPECT_TRUE(root->render_surface()->is_clipped());
1915 EXPECT_FALSE(parent->is_clipped());
1916 EXPECT_FALSE(child1->is_clipped());
1917 EXPECT_TRUE(child2->is_clipped());
1918 EXPECT_FALSE(child2->render_surface()->is_clipped());
1919 EXPECT_FALSE(grand_child->is_clipped());
1920 EXPECT_FALSE(leaf_node1->is_clipped());
1921 EXPECT_TRUE(leaf_node2->is_clipped());
1922 }
[email protected]fb661802013-03-25 01:59:321923}
1924
[email protected]fd9a3b6d2013-08-03 00:46:171925TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:321926 // Verify that layers get the appropriate DrawableContentRect when their
1927 // parent masksToBounds is true.
1928 //
1929 // grand_child1 - completely inside the region; DrawableContentRect should
1930 // be the layer rect expressed in target space.
1931 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1932 // will be the intersection of layer bounds and the mask region.
1933 // grand_child3 - partially clipped and masksToBounds; the
1934 // DrawableContentRect will still be the intersection of layer bounds and
1935 // the mask region.
1936 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1937 // be empty.
1938 //
1939
1940 const gfx::Transform identity_matrix;
1941 scoped_refptr<Layer> parent = Layer::Create();
1942 scoped_refptr<Layer> child = Layer::Create();
1943 scoped_refptr<Layer> grand_child1 = Layer::Create();
1944 scoped_refptr<Layer> grand_child2 = Layer::Create();
1945 scoped_refptr<Layer> grand_child3 = Layer::Create();
1946 scoped_refptr<Layer> grand_child4 = Layer::Create();
1947
1948 parent->AddChild(child);
1949 child->AddChild(grand_child1);
1950 child->AddChild(grand_child2);
1951 child->AddChild(grand_child3);
1952 child->AddChild(grand_child4);
1953
enne2097cab2014-09-25 20:16:311954 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281955 host->SetRootLayer(parent);
1956
[email protected]fb661802013-03-25 01:59:321957 SetLayerPropertiesForTesting(parent.get(),
1958 identity_matrix,
[email protected]a2566412014-06-05 03:14:201959 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321960 gfx::PointF(),
1961 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571962 true,
[email protected]fb661802013-03-25 01:59:321963 false);
1964 SetLayerPropertiesForTesting(child.get(),
1965 identity_matrix,
[email protected]a2566412014-06-05 03:14:201966 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321967 gfx::PointF(),
1968 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571969 true,
[email protected]fb661802013-03-25 01:59:321970 false);
1971 SetLayerPropertiesForTesting(grand_child1.get(),
1972 identity_matrix,
[email protected]a2566412014-06-05 03:14:201973 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321974 gfx::PointF(5.f, 5.f),
1975 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571976 true,
[email protected]fb661802013-03-25 01:59:321977 false);
1978 SetLayerPropertiesForTesting(grand_child2.get(),
1979 identity_matrix,
[email protected]a2566412014-06-05 03:14:201980 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321981 gfx::PointF(15.f, 15.f),
1982 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571983 true,
[email protected]fb661802013-03-25 01:59:321984 false);
1985 SetLayerPropertiesForTesting(grand_child3.get(),
1986 identity_matrix,
[email protected]a2566412014-06-05 03:14:201987 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321988 gfx::PointF(15.f, 15.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_child4.get(),
1993 identity_matrix,
[email protected]a2566412014-06-05 03:14:201994 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321995 gfx::PointF(45.f, 45.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
2000 child->SetMasksToBounds(true);
2001 grand_child3->SetMasksToBounds(true);
2002
2003 // Force everyone to be a render surface.
2004 child->SetOpacity(0.4f);
2005 grand_child1->SetOpacity(0.5f);
2006 grand_child2->SetOpacity(0.5f);
2007 grand_child3->SetOpacity(0.5f);
2008 grand_child4->SetOpacity(0.5f);
2009
[email protected]989386c2013-07-18 21:37:232010 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532011 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2012 parent.get(), parent->bounds(), &render_surface_layer_list);
2013 inputs.can_adjust_raster_scales = true;
2014 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322015
hush6b614212014-12-04 22:37:322016 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
2017 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
2018 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322019 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
2020}
2021
[email protected]989386c2013-07-18 21:37:232022TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:322023 // Verify that render surfaces (and their layers) get the appropriate
2024 // clip rects when their parent masksToBounds is true.
2025 //
2026 // Layers that own render surfaces (at least for now) do not inherit any
2027 // clipping; instead the surface will enforce the clip for the entire subtree.
2028 // They may still have a clip rect of their own layer bounds, however, if
2029 // masksToBounds was true.
2030 const gfx::Transform identity_matrix;
2031 scoped_refptr<Layer> parent = Layer::Create();
2032 scoped_refptr<Layer> child = Layer::Create();
2033 scoped_refptr<Layer> grand_child1 = Layer::Create();
2034 scoped_refptr<Layer> grand_child2 = Layer::Create();
2035 scoped_refptr<Layer> grand_child3 = Layer::Create();
2036 scoped_refptr<Layer> grand_child4 = Layer::Create();
2037 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
2038 make_scoped_refptr(new LayerWithForcedDrawsContent());
2039 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
2040 make_scoped_refptr(new LayerWithForcedDrawsContent());
2041 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
2042 make_scoped_refptr(new LayerWithForcedDrawsContent());
2043 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
2044 make_scoped_refptr(new LayerWithForcedDrawsContent());
2045
2046 parent->AddChild(child);
2047 child->AddChild(grand_child1);
2048 child->AddChild(grand_child2);
2049 child->AddChild(grand_child3);
2050 child->AddChild(grand_child4);
2051
enne2097cab2014-09-25 20:16:312052 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282053 host->SetRootLayer(parent);
2054
[email protected]fb661802013-03-25 01:59:322055 // the leaf nodes ensure that these grand_children become render surfaces for
2056 // this test.
2057 grand_child1->AddChild(leaf_node1);
2058 grand_child2->AddChild(leaf_node2);
2059 grand_child3->AddChild(leaf_node3);
2060 grand_child4->AddChild(leaf_node4);
2061
2062 SetLayerPropertiesForTesting(parent.get(),
2063 identity_matrix,
[email protected]a2566412014-06-05 03:14:202064 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322065 gfx::PointF(),
2066 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:572067 true,
[email protected]fb661802013-03-25 01:59:322068 false);
2069 SetLayerPropertiesForTesting(child.get(),
2070 identity_matrix,
[email protected]a2566412014-06-05 03:14:202071 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322072 gfx::PointF(),
2073 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:572074 true,
[email protected]fb661802013-03-25 01:59:322075 false);
2076 SetLayerPropertiesForTesting(grand_child1.get(),
2077 identity_matrix,
[email protected]a2566412014-06-05 03:14:202078 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322079 gfx::PointF(5.f, 5.f),
2080 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572081 true,
[email protected]fb661802013-03-25 01:59:322082 false);
2083 SetLayerPropertiesForTesting(grand_child2.get(),
2084 identity_matrix,
[email protected]a2566412014-06-05 03:14:202085 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322086 gfx::PointF(15.f, 15.f),
2087 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572088 true,
[email protected]fb661802013-03-25 01:59:322089 false);
2090 SetLayerPropertiesForTesting(grand_child3.get(),
2091 identity_matrix,
[email protected]a2566412014-06-05 03:14:202092 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322093 gfx::PointF(15.f, 15.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_child4.get(),
2098 identity_matrix,
[email protected]a2566412014-06-05 03:14:202099 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322100 gfx::PointF(45.f, 45.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(leaf_node1.get(),
2105 identity_matrix,
[email protected]a2566412014-06-05 03:14:202106 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322107 gfx::PointF(),
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(leaf_node2.get(),
2112 identity_matrix,
[email protected]a2566412014-06-05 03:14:202113 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322114 gfx::PointF(),
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_node3.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_node4.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
2133 child->SetMasksToBounds(true);
2134 grand_child3->SetMasksToBounds(true);
2135 grand_child4->SetMasksToBounds(true);
2136
2137 // Force everyone to be a render surface.
2138 child->SetOpacity(0.4f);
2139 child->SetForceRenderSurface(true);
2140 grand_child1->SetOpacity(0.5f);
2141 grand_child1->SetForceRenderSurface(true);
2142 grand_child2->SetOpacity(0.5f);
2143 grand_child2->SetForceRenderSurface(true);
2144 grand_child3->SetOpacity(0.5f);
2145 grand_child3->SetForceRenderSurface(true);
2146 grand_child4->SetOpacity(0.5f);
2147 grand_child4->SetForceRenderSurface(true);
2148
[email protected]989386c2013-07-18 21:37:232149 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532150 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2151 parent.get(), parent->bounds(), &render_surface_layer_list);
2152 inputs.can_adjust_raster_scales = true;
2153 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322154 ASSERT_TRUE(grand_child1->render_surface());
2155 ASSERT_TRUE(grand_child2->render_surface());
2156 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322157
2158 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2159 // masksToBounds.
hush6b614212014-12-04 22:37:322160 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2161 grand_child1->render_surface()->clip_rect());
2162 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2163 grand_child2->render_surface()->clip_rect());
2164 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2165 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322166}
2167
[email protected]989386c2013-07-18 21:37:232168TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:322169 scoped_refptr<Layer> parent = Layer::Create();
2170 scoped_refptr<Layer> render_surface1 = Layer::Create();
2171 scoped_refptr<Layer> render_surface2 = Layer::Create();
2172 scoped_refptr<Layer> child_of_root = Layer::Create();
2173 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
2174 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
2175 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
2176 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
2177 make_scoped_refptr(new LayerWithForcedDrawsContent());
2178 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
2179 make_scoped_refptr(new LayerWithForcedDrawsContent());
2180 parent->AddChild(render_surface1);
2181 parent->AddChild(child_of_root);
2182 render_surface1->AddChild(child_of_rs1);
2183 render_surface1->AddChild(render_surface2);
2184 render_surface2->AddChild(child_of_rs2);
2185 child_of_root->AddChild(grand_child_of_root);
2186 child_of_rs1->AddChild(grand_child_of_rs1);
2187 child_of_rs2->AddChild(grand_child_of_rs2);
2188
enne2097cab2014-09-25 20:16:312189 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282190 host->SetRootLayer(parent);
2191
[email protected]fb661802013-03-25 01:59:322192 // Make our render surfaces.
2193 render_surface1->SetForceRenderSurface(true);
2194 render_surface2->SetForceRenderSurface(true);
2195
2196 gfx::Transform layer_transform;
2197 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322198
2199 SetLayerPropertiesForTesting(parent.get(),
2200 layer_transform,
[email protected]a2566412014-06-05 03:14:202201 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322202 gfx::PointF(2.5f, 0.f),
2203 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572204 true,
[email protected]fb661802013-03-25 01:59:322205 false);
2206 SetLayerPropertiesForTesting(render_surface1.get(),
2207 layer_transform,
[email protected]a2566412014-06-05 03:14:202208 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322209 gfx::PointF(2.5f, 0.f),
2210 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572211 true,
[email protected]fb661802013-03-25 01:59:322212 false);
2213 SetLayerPropertiesForTesting(render_surface2.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(child_of_root.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(child_of_rs1.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_rs2.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(grand_child_of_root.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(grand_child_of_rs1.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_rs2.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
2263 // Put an animated opacity on the render surface.
2264 AddOpacityTransitionToController(
2265 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2266
2267 // Also put an animated opacity on a layer without descendants.
2268 AddOpacityTransitionToController(
2269 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2270
2271 // Put a transform animation on the render surface.
2272 AddAnimatedTransformToController(
2273 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2274
2275 // Also put transform animations on grand_child_of_root, and
2276 // grand_child_of_rs2
2277 AddAnimatedTransformToController(
2278 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2279 AddAnimatedTransformToController(
2280 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2281
2282 ExecuteCalculateDrawProperties(parent.get());
2283
2284 // Only layers that are associated with render surfaces should have an actual
2285 // RenderSurface() value.
2286 ASSERT_TRUE(parent->render_surface());
2287 ASSERT_FALSE(child_of_root->render_surface());
2288 ASSERT_FALSE(grand_child_of_root->render_surface());
2289
2290 ASSERT_TRUE(render_surface1->render_surface());
2291 ASSERT_FALSE(child_of_rs1->render_surface());
2292 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2293
2294 ASSERT_TRUE(render_surface2->render_surface());
2295 ASSERT_FALSE(child_of_rs2->render_surface());
2296 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2297
2298 // Verify all render target accessors
Daniel Chengeea98042014-08-26 00:28:102299 EXPECT_EQ(parent.get(), parent->render_target());
2300 EXPECT_EQ(parent.get(), child_of_root->render_target());
2301 EXPECT_EQ(parent.get(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322302
Daniel Chengeea98042014-08-26 00:28:102303 EXPECT_EQ(render_surface1.get(), render_surface1->render_target());
2304 EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target());
2305 EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322306
Daniel Chengeea98042014-08-26 00:28:102307 EXPECT_EQ(render_surface2.get(), render_surface2->render_target());
2308 EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target());
2309 EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322310
2311 // Verify draw_opacity_is_animating values
2312 EXPECT_FALSE(parent->draw_opacity_is_animating());
2313 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2314 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2315 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2316 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2317 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2318 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2319 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2320 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2321 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2322 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2323
2324 // Verify draw_transform_is_animating values
2325 EXPECT_FALSE(parent->draw_transform_is_animating());
2326 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2327 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2328 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2329 EXPECT_FALSE(render_surface1->render_surface()
2330 ->target_surface_transforms_are_animating());
2331 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2332 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2333 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2334 EXPECT_TRUE(render_surface2->render_surface()
2335 ->target_surface_transforms_are_animating());
2336 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2337 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2338
2339 // Verify screen_space_transform_is_animating values
2340 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2341 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2342 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2343 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2344 EXPECT_FALSE(render_surface1->render_surface()
2345 ->screen_space_transforms_are_animating());
2346 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2347 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2348 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2349 EXPECT_TRUE(render_surface2->render_surface()
2350 ->screen_space_transforms_are_animating());
2351 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2352 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2353
2354 // Sanity check. If these fail there is probably a bug in the test itself.
2355 // It is expected that we correctly set up transforms so that the y-component
2356 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262357 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2358 EXPECT_FLOAT_EQ(2.0,
2359 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322360 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262361 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322362
[email protected]803f6b52013-09-12 00:51:262363 EXPECT_FLOAT_EQ(2.0,
2364 render_surface1->screen_space_transform().matrix().get(1, 3));
2365 EXPECT_FLOAT_EQ(3.0,
2366 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322367 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262368 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322369
[email protected]803f6b52013-09-12 00:51:262370 EXPECT_FLOAT_EQ(3.0,
2371 render_surface2->screen_space_transform().matrix().get(1, 3));
2372 EXPECT_FLOAT_EQ(4.0,
2373 child_of_rs2->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 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322376}
2377
[email protected]989386c2013-07-18 21:37:232378TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322379 // Test the calculateVisibleRect() function works correctly for identity
2380 // transforms.
2381
[email protected]2c7c6702013-03-26 03:14:052382 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322383 gfx::Transform layer_to_surface_transform;
2384
2385 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232386 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052387 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322388 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2389 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322390 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322391
2392 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052393 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322394 actual = LayerTreeHostCommon::CalculateVisibleRect(
2395 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2396 EXPECT_TRUE(actual.IsEmpty());
2397
2398 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052399 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2400 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322401 actual = LayerTreeHostCommon::CalculateVisibleRect(
2402 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322403 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322404}
2405
[email protected]989386c2013-07-18 21:37:232406TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322407 // Test the calculateVisibleRect() function works correctly for scaling
2408 // transforms.
2409
[email protected]2c7c6702013-03-26 03:14:052410 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2411 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322412 gfx::Transform layer_to_surface_transform;
2413
2414 // Case 1: Layer is contained within the surface.
2415 layer_to_surface_transform.MakeIdentity();
2416 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052417 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322418 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2419 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322420 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322421
2422 // Case 2: Layer is outside the surface rect.
2423 layer_to_surface_transform.MakeIdentity();
2424 layer_to_surface_transform.Translate(120.0, 120.0);
2425 actual = LayerTreeHostCommon::CalculateVisibleRect(
2426 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2427 EXPECT_TRUE(actual.IsEmpty());
2428
2429 // Case 3: Layer is partially overlapping the surface rect.
2430 layer_to_surface_transform.MakeIdentity();
2431 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052432 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322433 actual = LayerTreeHostCommon::CalculateVisibleRect(
2434 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322435 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322436}
2437
[email protected]989386c2013-07-18 21:37:232438TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322439 // Test the calculateVisibleRect() function works correctly for rotations
2440 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2441 // should return the g in the layer's space.
2442
[email protected]2c7c6702013-03-26 03:14:052443 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2444 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322445 gfx::Transform layer_to_surface_transform;
2446
2447 // Case 1: Layer is contained within the surface.
2448 layer_to_surface_transform.MakeIdentity();
2449 layer_to_surface_transform.Translate(50.0, 50.0);
2450 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052451 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322452 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2453 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322454 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322455
2456 // Case 2: Layer is outside the surface rect.
2457 layer_to_surface_transform.MakeIdentity();
2458 layer_to_surface_transform.Translate(-50.0, 0.0);
2459 layer_to_surface_transform.Rotate(45.0);
2460 actual = LayerTreeHostCommon::CalculateVisibleRect(
2461 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2462 EXPECT_TRUE(actual.IsEmpty());
2463
2464 // Case 3: The layer is rotated about its top-left corner. In surface space,
2465 // the layer is oriented diagonally, with the left half outside of the render
2466 // surface. In this case, the g should still be the entire layer
2467 // (remember the g is computed in layer space); both the top-left
2468 // and bottom-right corners of the layer are still visible.
2469 layer_to_surface_transform.MakeIdentity();
2470 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052471 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322472 actual = LayerTreeHostCommon::CalculateVisibleRect(
2473 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322474 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322475
2476 // Case 4: The layer is rotated about its top-left corner, and translated
2477 // upwards. In surface space, the layer is oriented diagonally, with only the
2478 // top corner of the surface overlapping the layer. In layer space, the render
2479 // surface overlaps the right side of the layer. The g should be
2480 // the layer's right half.
2481 layer_to_surface_transform.MakeIdentity();
2482 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2483 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052484 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[email protected]fb661802013-03-25 01:59:322485 actual = LayerTreeHostCommon::CalculateVisibleRect(
2486 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322487 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322488}
2489
[email protected]989386c2013-07-18 21:37:232490TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322491 // Test that the calculateVisibleRect() function works correctly for 3d
2492 // transforms.
2493
[email protected]2c7c6702013-03-26 03:14:052494 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2495 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322496 gfx::Transform layer_to_surface_transform;
2497
2498 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2499 // degrees, should be fully contained in the render surface.
2500 layer_to_surface_transform.MakeIdentity();
2501 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052502 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322503 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2504 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322505 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322506
2507 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2508 // degrees, but shifted to the side so only the right-half the layer would be
2509 // visible on the surface.
2510 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262511 SkMScalar half_width_of_rotated_layer =
2512 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322513 layer_to_surface_transform.MakeIdentity();
2514 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232515 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2516 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052517 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322518 actual = LayerTreeHostCommon::CalculateVisibleRect(
2519 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322520 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322521}
2522
[email protected]989386c2013-07-18 21:37:232523TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322524 // Test the calculateVisibleRect() function works correctly when the layer has
2525 // a perspective projection onto the target surface.
2526
[email protected]2c7c6702013-03-26 03:14:052527 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2528 gfx::Rect layer_content_rect = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322529 gfx::Transform layer_to_surface_transform;
2530
2531 // Case 1: Even though the layer is twice as large as the surface, due to
2532 // perspective foreshortening, the layer will fit fully in the surface when
2533 // its translated more than the perspective amount.
2534 layer_to_surface_transform.MakeIdentity();
2535
2536 // The following sequence of transforms applies the perspective about the
2537 // center of the surface.
2538 layer_to_surface_transform.Translate(50.0, 50.0);
2539 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2540 layer_to_surface_transform.Translate(-50.0, -50.0);
2541
2542 // This translate places the layer in front of the surface's projection plane.
2543 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2544
[email protected]2c7c6702013-03-26 03:14:052545 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322546 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2547 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322548 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322549
2550 // Case 2: same projection as before, except that the layer is also translated
2551 // to the side, so that only the right half of the layer should be visible.
2552 //
2553 // Explanation of expected result: The perspective ratio is (z distance
2554 // between layer and camera origin) / (z distance between projection plane and
2555 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2556 // move a layer by translating -50 units in projected surface units (so that
2557 // only half of it is visible), then we would need to translate by (-36 / 9) *
2558 // -50 == -200 in the layer's units.
2559 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232560 expected = gfx::Rect(gfx::Point(50, -50),
2561 gfx::Size(100, 200)); // The right half of the layer's
2562 // bounding rect.
[email protected]fb661802013-03-25 01:59:322563 actual = LayerTreeHostCommon::CalculateVisibleRect(
2564 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322565 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322566}
2567
[email protected]989386c2013-07-18 21:37:232568TEST_F(LayerTreeHostCommonTest,
2569 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322570 // There is currently no explicit concept of an orthographic projection plane
2571 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2572 // are technically behind the surface in an orthographic world should not be
2573 // clipped when they are flattened to the surface.
2574
[email protected]2c7c6702013-03-26 03:14:052575 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2576 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322577 gfx::Transform layer_to_surface_transform;
2578
2579 // This sequence of transforms effectively rotates the layer about the y-axis
2580 // at the center of the layer.
2581 layer_to_surface_transform.MakeIdentity();
2582 layer_to_surface_transform.Translate(50.0, 0.0);
2583 layer_to_surface_transform.RotateAboutYAxis(45.0);
2584 layer_to_surface_transform.Translate(-50.0, 0.0);
2585
[email protected]2c7c6702013-03-26 03:14:052586 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322587 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2588 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322589 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322590}
2591
[email protected]989386c2013-07-18 21:37:232592TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322593 // Test the calculateVisibleRect() function works correctly when projecting a
2594 // surface onto a layer, but the layer is partially behind the camera (not
2595 // just behind the projection plane). In this case, the cartesian coordinates
2596 // may seem to be valid, but actually they are not. The visible rect needs to
2597 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2598 // converting to cartesian coordinates.
2599
[email protected]2c7c6702013-03-26 03:14:052600 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232601 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322602 gfx::Transform layer_to_surface_transform;
2603
2604 // The layer is positioned so that the right half of the layer should be in
2605 // front of the camera, while the other half is behind the surface's
2606 // projection plane. The following sequence of transforms applies the
2607 // perspective and rotation about the center of the layer.
2608 layer_to_surface_transform.MakeIdentity();
2609 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2610 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2611 layer_to_surface_transform.RotateAboutYAxis(45.0);
2612
2613 // Sanity check that this transform does indeed cause w < 0 when applying the
2614 // transform, otherwise this code is not testing the intended scenario.
2615 bool clipped;
2616 MathUtil::MapQuad(layer_to_surface_transform,
2617 gfx::QuadF(gfx::RectF(layer_content_rect)),
2618 &clipped);
2619 ASSERT_TRUE(clipped);
2620
2621 int expected_x_position = 0;
2622 int expected_width = 10;
2623 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2624 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2625 EXPECT_EQ(expected_x_position, actual.x());
2626 EXPECT_EQ(expected_width, actual.width());
2627}
2628
[email protected]989386c2013-07-18 21:37:232629TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322630 // To determine visible rect in layer space, there needs to be an
2631 // un-projection from surface space to layer space. When the original
2632 // transform was a perspective projection that was clipped, it returns a rect
2633 // that encloses the clipped bounds. Un-projecting this new rect may require
2634 // clipping again.
2635
2636 // This sequence of transforms causes one corner of the layer to protrude
2637 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232638 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2639 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322640 gfx::Transform layer_to_surface_transform;
2641 layer_to_surface_transform.MakeIdentity();
2642 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2643 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2644 layer_to_surface_transform.RotateAboutYAxis(45.0);
2645 layer_to_surface_transform.RotateAboutXAxis(80.0);
2646
2647 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2648 // code is not testing the intended scenario.
2649 bool clipped;
2650 gfx::RectF clipped_rect =
2651 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2652 MathUtil::ProjectQuad(
2653 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2654 ASSERT_TRUE(clipped);
2655
2656 // Only the corner of the layer is not visible on the surface because of being
2657 // clipped. But, the net result of rounding visible region to an axis-aligned
2658 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052659 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322660 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2661 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322662 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322663}
2664
[email protected]989386c2013-07-18 21:37:232665TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
[email protected]fb661802013-03-25 01:59:322666 scoped_refptr<Layer> root = Layer::Create();
2667 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2668 make_scoped_refptr(new LayerWithForcedDrawsContent());
2669 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2670 make_scoped_refptr(new LayerWithForcedDrawsContent());
2671 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2672 make_scoped_refptr(new LayerWithForcedDrawsContent());
2673 root->AddChild(child1);
2674 root->AddChild(child2);
2675 root->AddChild(child3);
2676
enne2097cab2014-09-25 20:16:312677 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282678 host->SetRootLayer(root);
2679
[email protected]fb661802013-03-25 01:59:322680 gfx::Transform identity_matrix;
2681 SetLayerPropertiesForTesting(root.get(),
2682 identity_matrix,
[email protected]a2566412014-06-05 03:14:202683 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322684 gfx::PointF(),
2685 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572686 true,
[email protected]fb661802013-03-25 01:59:322687 false);
2688 SetLayerPropertiesForTesting(child1.get(),
2689 identity_matrix,
[email protected]a2566412014-06-05 03:14:202690 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322691 gfx::PointF(),
2692 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572693 true,
[email protected]fb661802013-03-25 01:59:322694 false);
2695 SetLayerPropertiesForTesting(child2.get(),
2696 identity_matrix,
[email protected]a2566412014-06-05 03:14:202697 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322698 gfx::PointF(75.f, 75.f),
2699 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572700 true,
[email protected]fb661802013-03-25 01:59:322701 false);
2702 SetLayerPropertiesForTesting(child3.get(),
2703 identity_matrix,
[email protected]a2566412014-06-05 03:14:202704 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322705 gfx::PointF(125.f, 125.f),
2706 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572707 true,
[email protected]fb661802013-03-25 01:59:322708 false);
2709
2710 ExecuteCalculateDrawProperties(root.get());
2711
hush6b614212014-12-04 22:37:322712 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2713 root->render_surface()->DrawableContentRect());
2714 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322715
2716 // Layers that do not draw content should have empty visible_content_rects.
hush6b614212014-12-04 22:37:322717 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322718
2719 // layer visible_content_rects are clipped by their target surface.
hush6b614212014-12-04 22:37:322720 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2721 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322722 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
2723
2724 // layer drawable_content_rects are not clipped.
hush6b614212014-12-04 22:37:322725 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
2726 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2727 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322728}
2729
[email protected]989386c2013-07-18 21:37:232730TEST_F(LayerTreeHostCommonTest,
2731 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
[email protected]fb661802013-03-25 01:59:322732 scoped_refptr<Layer> root = Layer::Create();
2733 scoped_refptr<Layer> child = Layer::Create();
2734 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
2735 make_scoped_refptr(new LayerWithForcedDrawsContent());
2736 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
2737 make_scoped_refptr(new LayerWithForcedDrawsContent());
2738 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
2739 make_scoped_refptr(new LayerWithForcedDrawsContent());
2740 root->AddChild(child);
2741 child->AddChild(grand_child1);
2742 child->AddChild(grand_child2);
2743 child->AddChild(grand_child3);
2744
enne2097cab2014-09-25 20:16:312745 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282746 host->SetRootLayer(root);
2747
[email protected]fb661802013-03-25 01:59:322748 gfx::Transform identity_matrix;
2749 SetLayerPropertiesForTesting(root.get(),
2750 identity_matrix,
[email protected]a2566412014-06-05 03:14:202751 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322752 gfx::PointF(),
2753 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572754 true,
[email protected]fb661802013-03-25 01:59:322755 false);
2756 SetLayerPropertiesForTesting(child.get(),
2757 identity_matrix,
[email protected]a2566412014-06-05 03:14:202758 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322759 gfx::PointF(),
2760 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572761 true,
[email protected]fb661802013-03-25 01:59:322762 false);
2763 SetLayerPropertiesForTesting(grand_child1.get(),
2764 identity_matrix,
[email protected]a2566412014-06-05 03:14:202765 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322766 gfx::PointF(5.f, 5.f),
2767 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572768 true,
[email protected]fb661802013-03-25 01:59:322769 false);
2770 SetLayerPropertiesForTesting(grand_child2.get(),
2771 identity_matrix,
[email protected]a2566412014-06-05 03:14:202772 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322773 gfx::PointF(75.f, 75.f),
2774 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572775 true,
[email protected]fb661802013-03-25 01:59:322776 false);
2777 SetLayerPropertiesForTesting(grand_child3.get(),
2778 identity_matrix,
[email protected]a2566412014-06-05 03:14:202779 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322780 gfx::PointF(125.f, 125.f),
2781 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572782 true,
[email protected]fb661802013-03-25 01:59:322783 false);
2784
2785 child->SetMasksToBounds(true);
2786 ExecuteCalculateDrawProperties(root.get());
2787
2788 ASSERT_FALSE(child->render_surface());
2789
hush6b614212014-12-04 22:37:322790 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2791 root->render_surface()->DrawableContentRect());
2792 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322793
2794 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:322795 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2796 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322797
2798 // All grandchild visible content rects should be clipped by child.
hush6b614212014-12-04 22:37:322799 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
2800 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322801 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
2802
2803 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:322804 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
2805 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322806 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2807}
2808
ajuma27442dd2015-03-30 19:19:482809TEST_F(LayerTreeHostCommonTest, VisibleContentRectWithClippingAndScaling) {
2810 scoped_refptr<Layer> root = Layer::Create();
2811 scoped_refptr<Layer> child = Layer::Create();
2812 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
2813 make_scoped_refptr(new LayerWithForcedDrawsContent());
2814 root->AddChild(child);
2815 child->AddChild(grand_child);
2816
2817 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
2818 host->SetRootLayer(root);
2819
2820 gfx::Transform identity_matrix;
2821 gfx::Transform child_scale_matrix;
2822 child_scale_matrix.Scale(0.25f, 0.25f);
2823 gfx::Transform grand_child_scale_matrix;
2824 grand_child_scale_matrix.Scale(0.246f, 0.246f);
2825 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2826 gfx::PointF(), gfx::Size(100, 100), true, false);
2827 SetLayerPropertiesForTesting(child.get(), child_scale_matrix, gfx::Point3F(),
2828 gfx::PointF(), gfx::Size(10, 10), true, false);
2829 SetLayerPropertiesForTesting(grand_child.get(), grand_child_scale_matrix,
2830 gfx::Point3F(), gfx::PointF(),
2831 gfx::Size(100, 100), true, false);
2832
2833 child->SetMasksToBounds(true);
2834 ExecuteCalculateDrawProperties(root.get());
2835
2836 // The visible rect is expanded to integer coordinates in target space before
2837 // being projected back to layer space, where it is once again expanded to
2838 // integer coordinates.
2839 EXPECT_EQ(gfx::Rect(49, 49), grand_child->visible_rect_from_property_trees());
2840}
2841
[email protected]989386c2013-07-18 21:37:232842TEST_F(LayerTreeHostCommonTest,
2843 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322844 scoped_refptr<Layer> root = Layer::Create();
2845 scoped_refptr<Layer> render_surface1 = Layer::Create();
2846 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2847 make_scoped_refptr(new LayerWithForcedDrawsContent());
2848 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2849 make_scoped_refptr(new LayerWithForcedDrawsContent());
2850 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2851 make_scoped_refptr(new LayerWithForcedDrawsContent());
2852 root->AddChild(render_surface1);
2853 render_surface1->AddChild(child1);
2854 render_surface1->AddChild(child2);
2855 render_surface1->AddChild(child3);
2856
enne2097cab2014-09-25 20:16:312857 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282858 host->SetRootLayer(root);
2859
[email protected]fb661802013-03-25 01:59:322860 gfx::Transform identity_matrix;
2861 SetLayerPropertiesForTesting(root.get(),
2862 identity_matrix,
[email protected]a2566412014-06-05 03:14:202863 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322864 gfx::PointF(),
2865 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572866 true,
[email protected]fb661802013-03-25 01:59:322867 false);
2868 SetLayerPropertiesForTesting(render_surface1.get(),
2869 identity_matrix,
[email protected]a2566412014-06-05 03:14:202870 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322871 gfx::PointF(),
2872 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:572873 true,
[email protected]fb661802013-03-25 01:59:322874 false);
2875 SetLayerPropertiesForTesting(child1.get(),
2876 identity_matrix,
[email protected]a2566412014-06-05 03:14:202877 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322878 gfx::PointF(5.f, 5.f),
2879 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572880 true,
[email protected]fb661802013-03-25 01:59:322881 false);
2882 SetLayerPropertiesForTesting(child2.get(),
2883 identity_matrix,
[email protected]a2566412014-06-05 03:14:202884 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322885 gfx::PointF(75.f, 75.f),
2886 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572887 true,
[email protected]fb661802013-03-25 01:59:322888 false);
2889 SetLayerPropertiesForTesting(child3.get(),
2890 identity_matrix,
[email protected]a2566412014-06-05 03:14:202891 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322892 gfx::PointF(125.f, 125.f),
2893 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572894 true,
[email protected]fb661802013-03-25 01:59:322895 false);
2896
2897 render_surface1->SetForceRenderSurface(true);
2898 ExecuteCalculateDrawProperties(root.get());
2899
2900 ASSERT_TRUE(render_surface1->render_surface());
2901
hush6b614212014-12-04 22:37:322902 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2903 root->render_surface()->DrawableContentRect());
2904 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322905
2906 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:322907 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2908 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322909
2910 // An unclipped surface grows its DrawableContentRect to include all drawable
2911 // regions of the subtree.
hush6b614212014-12-04 22:37:322912 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2913 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322914
2915 // All layers that draw content into the unclipped surface are also unclipped.
hush6b614212014-12-04 22:37:322916 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2917 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
2918 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322919
hush6b614212014-12-04 22:37:322920 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2921 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2922 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322923}
2924
[email protected]989386c2013-07-18 21:37:232925TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:022926 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
2927 scoped_refptr<Layer> root = Layer::Create();
2928 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2929 make_scoped_refptr(new LayerWithForcedDrawsContent());
2930 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2931 make_scoped_refptr(new LayerWithForcedDrawsContent());
2932 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2933 make_scoped_refptr(new LayerWithForcedDrawsContent());
2934 root->AddChild(child1);
2935 root->AddChild(child2);
2936 root->AddChild(child3);
2937
2938 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
2939 host->SetRootLayer(root);
2940
2941 gfx::Transform identity_matrix;
2942 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2943 gfx::PointF(), gfx::Size(100, 100), true, false);
2944 SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(),
2945 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2946 false);
2947 SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(),
2948 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2949 false);
2950 SetLayerPropertiesForTesting(child3.get(), identity_matrix, gfx::Point3F(),
2951 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2952 true, false);
2953
2954 RenderSurfaceLayerList render_surface_layer_list;
2955 // Now set the root render surface an empty clip.
2956 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2957 root.get(), gfx::Size(), &render_surface_layer_list);
2958
2959 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
2960 ASSERT_TRUE(root->render_surface());
2961 EXPECT_FALSE(root->is_clipped());
2962
2963 gfx::Rect empty;
2964 EXPECT_EQ(empty, root->render_surface()->clip_rect());
2965 EXPECT_TRUE(root->render_surface()->is_clipped());
2966
2967 // Visible content rect calculation will check if the target surface is
2968 // clipped or not. An empty clip rect does not indicate the render surface
2969 // is unclipped.
2970 EXPECT_EQ(empty, child1->visible_content_rect());
2971 EXPECT_EQ(empty, child2->visible_content_rect());
2972 EXPECT_EQ(empty, child3->visible_content_rect());
2973}
2974
2975TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:232976 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
[email protected]451107a32013-04-10 05:12:472977 scoped_refptr<Layer> root = Layer::Create();
2978 scoped_refptr<LayerWithForcedDrawsContent> child =
2979 make_scoped_refptr(new LayerWithForcedDrawsContent());
2980 root->AddChild(child);
2981
enne2097cab2014-09-25 20:16:312982 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282983 host->SetRootLayer(root);
2984
[email protected]630ddad2013-08-16 03:01:322985 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:472986 gfx::Transform identity_matrix;
2987 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:322988 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:472989
2990 SetLayerPropertiesForTesting(root.get(),
2991 identity_matrix,
[email protected]a2566412014-06-05 03:14:202992 gfx::Point3F(),
[email protected]451107a32013-04-10 05:12:472993 gfx::PointF(),
2994 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572995 true,
[email protected]451107a32013-04-10 05:12:472996 false);
2997 SetLayerPropertiesForTesting(child.get(),
2998 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202999 gfx::Point3F(),
[email protected]451107a32013-04-10 05:12:473000 gfx::PointF(5.f, 5.f),
3001 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573002 true,
[email protected]451107a32013-04-10 05:12:473003 false);
3004
3005 ExecuteCalculateDrawProperties(root.get());
3006
3007 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
3008 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323009
[email protected]08bdf1b2014-04-16 23:23:293010 // Case 2: a matrix with flattened z, uninvertible and not visible according
3011 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:323012 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:263013 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323014 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3015
3016 SetLayerPropertiesForTesting(child.get(),
3017 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203018 gfx::Point3F(),
[email protected]630ddad2013-08-16 03:01:323019 gfx::PointF(5.f, 5.f),
3020 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573021 true,
[email protected]630ddad2013-08-16 03:01:323022 false);
3023
3024 ExecuteCalculateDrawProperties(root.get());
3025
[email protected]08bdf1b2014-04-16 23:23:293026 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
3027 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:323028
[email protected]08bdf1b2014-04-16 23:23:293029 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:323030 uninvertible_matrix.MakeIdentity();
3031 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:263032 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:323033 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3034
3035 SetLayerPropertiesForTesting(child.get(),
3036 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203037 gfx::Point3F(),
[email protected]630ddad2013-08-16 03:01:323038 gfx::PointF(5.f, 5.f),
3039 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573040 true,
[email protected]630ddad2013-08-16 03:01:323041 false);
3042
3043 ExecuteCalculateDrawProperties(root.get());
3044
3045 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:293046 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:473047}
3048
[email protected]989386c2013-07-18 21:37:233049TEST_F(LayerTreeHostCommonTest,
[email protected]e43c68b2014-05-01 05:10:363050 SingularTransformDoesNotPreventClearingDrawProperties) {
3051 scoped_refptr<Layer> root = Layer::Create();
3052 scoped_refptr<LayerWithForcedDrawsContent> child =
3053 make_scoped_refptr(new LayerWithForcedDrawsContent());
3054 root->AddChild(child);
3055
enne2097cab2014-09-25 20:16:313056 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]e43c68b2014-05-01 05:10:363057 host->SetRootLayer(root);
3058
3059 gfx::Transform identity_matrix;
3060 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3061 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3062
3063 SetLayerPropertiesForTesting(root.get(),
3064 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203065 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:363066 gfx::PointF(),
3067 gfx::Size(100, 100),
3068 true,
3069 false);
3070 SetLayerPropertiesForTesting(child.get(),
3071 identity_matrix,
[email protected]a2566412014-06-05 03:14:203072 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:363073 gfx::PointF(5.f, 5.f),
3074 gfx::Size(50, 50),
3075 true,
3076 false);
3077
vollickeb194942014-09-12 17:45:273078 child->draw_properties().sorted_for_recursion = true;
[email protected]e43c68b2014-05-01 05:10:363079
3080 TransformOperations start_transform_operations;
3081 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
3082
3083 TransformOperations end_transform_operations;
3084 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
3085
3086 AddAnimatedTransformToLayer(
3087 root.get(), 10.0, start_transform_operations, end_transform_operations);
3088
3089 EXPECT_TRUE(root->TransformIsAnimating());
3090
3091 ExecuteCalculateDrawProperties(root.get());
3092
vollickeb194942014-09-12 17:45:273093 EXPECT_FALSE(child->draw_properties().sorted_for_recursion);
[email protected]e43c68b2014-05-01 05:10:363094}
3095
[email protected]e43c68b2014-05-01 05:10:363096TEST_F(LayerTreeHostCommonTest,
[email protected]8dbc85c2014-05-03 03:21:063097 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
3098 scoped_refptr<Layer> root = Layer::Create();
3099
enne2097cab2014-09-25 20:16:313100 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]8dbc85c2014-05-03 03:21:063101 host->SetRootLayer(root);
3102
3103 gfx::Transform identity_matrix;
3104 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3105 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
3106
3107 SetLayerPropertiesForTesting(root.get(),
3108 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:203109 gfx::Point3F(),
[email protected]8dbc85c2014-05-03 03:21:063110 gfx::PointF(),
3111 gfx::Size(100, 100),
3112 true,
3113 false);
3114
vollickeb194942014-09-12 17:45:273115 root->draw_properties().sorted_for_recursion = true;
[email protected]8dbc85c2014-05-03 03:21:063116
3117 EXPECT_FALSE(root->TransformIsAnimating());
3118
3119 ExecuteCalculateDrawProperties(root.get());
3120
vollickeb194942014-09-12 17:45:273121 EXPECT_FALSE(root->draw_properties().sorted_for_recursion);
[email protected]8dbc85c2014-05-03 03:21:063122}
3123
3124TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233125 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:323126 scoped_refptr<Layer> root = Layer::Create();
3127 scoped_refptr<Layer> render_surface1 = Layer::Create();
3128 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3129 make_scoped_refptr(new LayerWithForcedDrawsContent());
3130 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3131 make_scoped_refptr(new LayerWithForcedDrawsContent());
3132 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3133 make_scoped_refptr(new LayerWithForcedDrawsContent());
3134 root->AddChild(render_surface1);
3135 render_surface1->AddChild(child1);
3136 render_surface1->AddChild(child2);
3137 render_surface1->AddChild(child3);
3138
enne2097cab2014-09-25 20:16:313139 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283140 host->SetRootLayer(root);
3141
[email protected]fb661802013-03-25 01:59:323142 gfx::Transform identity_matrix;
3143 SetLayerPropertiesForTesting(root.get(),
3144 identity_matrix,
[email protected]a2566412014-06-05 03:14:203145 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323146 gfx::PointF(),
3147 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573148 true,
[email protected]fb661802013-03-25 01:59:323149 false);
3150 SetLayerPropertiesForTesting(render_surface1.get(),
3151 identity_matrix,
[email protected]a2566412014-06-05 03:14:203152 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323153 gfx::PointF(),
3154 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573155 true,
[email protected]fb661802013-03-25 01:59:323156 false);
3157 SetLayerPropertiesForTesting(child1.get(),
3158 identity_matrix,
[email protected]a2566412014-06-05 03:14:203159 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323160 gfx::PointF(5.f, 5.f),
3161 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573162 true,
[email protected]fb661802013-03-25 01:59:323163 false);
3164 SetLayerPropertiesForTesting(child2.get(),
3165 identity_matrix,
[email protected]a2566412014-06-05 03:14:203166 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323167 gfx::PointF(75.f, 75.f),
3168 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573169 true,
[email protected]fb661802013-03-25 01:59:323170 false);
3171 SetLayerPropertiesForTesting(child3.get(),
3172 identity_matrix,
[email protected]a2566412014-06-05 03:14:203173 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323174 gfx::PointF(125.f, 125.f),
3175 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573176 true,
[email protected]fb661802013-03-25 01:59:323177 false);
3178
3179 root->SetMasksToBounds(true);
3180 render_surface1->SetForceRenderSurface(true);
3181 ExecuteCalculateDrawProperties(root.get());
3182
3183 ASSERT_TRUE(render_surface1->render_surface());
3184
hush6b614212014-12-04 22:37:323185 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3186 root->render_surface()->DrawableContentRect());
3187 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323188
3189 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323190 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3191 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323192
3193 // A clipped surface grows its DrawableContentRect to include all drawable
3194 // regions of the subtree, but also gets clamped by the ancestor's clip.
hush6b614212014-12-04 22:37:323195 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3196 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323197
3198 // All layers that draw content into the surface have their visible content
3199 // rect clipped by the surface clip rect.
hush6b614212014-12-04 22:37:323200 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3201 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323202 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3203
3204 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323205 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3206 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3207 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323208}
3209
[email protected]989386c2013-07-18 21:37:233210TEST_F(LayerTreeHostCommonTest,
3211 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323212 // Check that clipping does not propagate down surfaces.
3213 scoped_refptr<Layer> root = Layer::Create();
3214 scoped_refptr<Layer> render_surface1 = Layer::Create();
3215 scoped_refptr<Layer> render_surface2 = Layer::Create();
3216 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3217 make_scoped_refptr(new LayerWithForcedDrawsContent());
3218 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3219 make_scoped_refptr(new LayerWithForcedDrawsContent());
3220 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3221 make_scoped_refptr(new LayerWithForcedDrawsContent());
3222 root->AddChild(render_surface1);
3223 render_surface1->AddChild(render_surface2);
3224 render_surface2->AddChild(child1);
3225 render_surface2->AddChild(child2);
3226 render_surface2->AddChild(child3);
3227
enne2097cab2014-09-25 20:16:313228 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283229 host->SetRootLayer(root);
3230
[email protected]fb661802013-03-25 01:59:323231 gfx::Transform identity_matrix;
3232 SetLayerPropertiesForTesting(root.get(),
3233 identity_matrix,
[email protected]a2566412014-06-05 03:14:203234 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323235 gfx::PointF(),
3236 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573237 true,
[email protected]fb661802013-03-25 01:59:323238 false);
3239 SetLayerPropertiesForTesting(render_surface1.get(),
3240 identity_matrix,
[email protected]a2566412014-06-05 03:14:203241 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323242 gfx::PointF(),
3243 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573244 true,
[email protected]fb661802013-03-25 01:59:323245 false);
3246 SetLayerPropertiesForTesting(render_surface2.get(),
3247 identity_matrix,
[email protected]a2566412014-06-05 03:14:203248 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323249 gfx::PointF(),
3250 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573251 true,
[email protected]fb661802013-03-25 01:59:323252 false);
3253 SetLayerPropertiesForTesting(child1.get(),
3254 identity_matrix,
[email protected]a2566412014-06-05 03:14:203255 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323256 gfx::PointF(5.f, 5.f),
3257 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573258 true,
[email protected]fb661802013-03-25 01:59:323259 false);
3260 SetLayerPropertiesForTesting(child2.get(),
3261 identity_matrix,
[email protected]a2566412014-06-05 03:14:203262 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323263 gfx::PointF(75.f, 75.f),
3264 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573265 true,
[email protected]fb661802013-03-25 01:59:323266 false);
3267 SetLayerPropertiesForTesting(child3.get(),
3268 identity_matrix,
[email protected]a2566412014-06-05 03:14:203269 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323270 gfx::PointF(125.f, 125.f),
3271 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573272 true,
[email protected]fb661802013-03-25 01:59:323273 false);
3274
3275 root->SetMasksToBounds(true);
3276 render_surface1->SetForceRenderSurface(true);
3277 render_surface2->SetForceRenderSurface(true);
3278 ExecuteCalculateDrawProperties(root.get());
3279
3280 ASSERT_TRUE(render_surface1->render_surface());
3281 ASSERT_TRUE(render_surface2->render_surface());
3282
hush6b614212014-12-04 22:37:323283 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3284 root->render_surface()->DrawableContentRect());
3285 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323286
3287 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323288 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3289 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
3290 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323291
3292 // A clipped surface grows its DrawableContentRect to include all drawable
3293 // regions of the subtree, but also gets clamped by the ancestor's clip.
hush6b614212014-12-04 22:37:323294 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3295 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323296
3297 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3298 // is only implicitly clipped by render_surface1's content rect. So,
3299 // render_surface2 grows to enclose all drawable content of its subtree.
hush6b614212014-12-04 22:37:323300 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
3301 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323302
3303 // All layers that draw content into render_surface2 think they are unclipped.
hush6b614212014-12-04 22:37:323304 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3305 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3306 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323307
3308 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323309 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3310 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3311 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323312}
3313
[email protected]989386c2013-07-18 21:37:233314TEST_F(LayerTreeHostCommonTest,
3315 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323316 // Layers that have non-axis aligned bounds (due to transforms) have an
3317 // expanded, axis-aligned DrawableContentRect and visible content rect.
3318
3319 scoped_refptr<Layer> root = Layer::Create();
3320 scoped_refptr<Layer> render_surface1 = Layer::Create();
3321 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3322 make_scoped_refptr(new LayerWithForcedDrawsContent());
3323 root->AddChild(render_surface1);
3324 render_surface1->AddChild(child1);
3325
enne2097cab2014-09-25 20:16:313326 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283327 host->SetRootLayer(root);
3328
[email protected]fb661802013-03-25 01:59:323329 gfx::Transform identity_matrix;
3330 gfx::Transform child_rotation;
3331 child_rotation.Rotate(45.0);
3332 SetLayerPropertiesForTesting(root.get(),
3333 identity_matrix,
[email protected]a2566412014-06-05 03:14:203334 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323335 gfx::PointF(),
3336 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573337 true,
[email protected]fb661802013-03-25 01:59:323338 false);
3339 SetLayerPropertiesForTesting(render_surface1.get(),
3340 identity_matrix,
[email protected]a2566412014-06-05 03:14:203341 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323342 gfx::PointF(),
3343 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573344 true,
[email protected]fb661802013-03-25 01:59:323345 false);
3346 SetLayerPropertiesForTesting(child1.get(),
3347 child_rotation,
[email protected]a2566412014-06-05 03:14:203348 gfx::Point3F(25, 25, 0.f),
[email protected]fb661802013-03-25 01:59:323349 gfx::PointF(25.f, 25.f),
3350 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573351 true,
[email protected]fb661802013-03-25 01:59:323352 false);
3353
3354 render_surface1->SetForceRenderSurface(true);
3355 ExecuteCalculateDrawProperties(root.get());
3356
3357 ASSERT_TRUE(render_surface1->render_surface());
3358
hush6b614212014-12-04 22:37:323359 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3360 root->render_surface()->DrawableContentRect());
3361 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323362
3363 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323364 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3365 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323366
3367 // The unclipped surface grows its DrawableContentRect to include all drawable
3368 // regions of the subtree.
3369 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3370 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263371 gfx::Rect(50 - diagonal_radius,
3372 50 - diagonal_radius,
3373 diagonal_radius * 2,
3374 diagonal_radius * 2);
hush6b614212014-12-04 22:37:323375 EXPECT_EQ(expected_surface_drawable_content,
3376 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323377
3378 // All layers that draw content into the unclipped surface are also unclipped.
hush6b614212014-12-04 22:37:323379 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3380 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323381}
3382
[email protected]989386c2013-07-18 21:37:233383TEST_F(LayerTreeHostCommonTest,
3384 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323385 // Layers that have non-axis aligned bounds (due to transforms) have an
3386 // expanded, axis-aligned DrawableContentRect and visible content rect.
3387
3388 scoped_refptr<Layer> root = Layer::Create();
3389 scoped_refptr<Layer> render_surface1 = Layer::Create();
3390 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3391 make_scoped_refptr(new LayerWithForcedDrawsContent());
3392 root->AddChild(render_surface1);
3393 render_surface1->AddChild(child1);
3394
enne2097cab2014-09-25 20:16:313395 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283396 host->SetRootLayer(root);
3397
[email protected]fb661802013-03-25 01:59:323398 gfx::Transform identity_matrix;
3399 gfx::Transform child_rotation;
3400 child_rotation.Rotate(45.0);
3401 SetLayerPropertiesForTesting(root.get(),
3402 identity_matrix,
[email protected]a2566412014-06-05 03:14:203403 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323404 gfx::PointF(),
3405 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573406 true,
[email protected]fb661802013-03-25 01:59:323407 false);
3408 SetLayerPropertiesForTesting(render_surface1.get(),
3409 identity_matrix,
[email protected]a2566412014-06-05 03:14:203410 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323411 gfx::PointF(),
3412 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573413 true,
[email protected]fb661802013-03-25 01:59:323414 false);
[email protected]a2566412014-06-05 03:14:203415
[email protected]fb661802013-03-25 01:59:323416 SetLayerPropertiesForTesting(child1.get(),
3417 child_rotation,
[email protected]a2566412014-06-05 03:14:203418 gfx::Point3F(25, 25, 0.f),
[email protected]fb661802013-03-25 01:59:323419 gfx::PointF(25.f, 25.f),
3420 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573421 true,
[email protected]fb661802013-03-25 01:59:323422 false);
3423
3424 root->SetMasksToBounds(true);
3425 render_surface1->SetForceRenderSurface(true);
3426 ExecuteCalculateDrawProperties(root.get());
3427
3428 ASSERT_TRUE(render_surface1->render_surface());
3429
3430 // The clipped surface clamps the DrawableContentRect that encloses the
3431 // rotated layer.
3432 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263433 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3434 50 - diagonal_radius,
3435 diagonal_radius * 2,
3436 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323437 gfx::Rect expected_surface_drawable_content =
3438 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
hush6b614212014-12-04 22:37:323439 EXPECT_EQ(expected_surface_drawable_content,
3440 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323441
3442 // On the clipped surface, only a quarter of the child1 is visible, but when
3443 // rotating it back to child1's content space, the actual enclosing rect ends
3444 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263445 //
3446 // Given the floating point math, this number is a little bit fuzzy.
hush6b614212014-12-04 22:37:323447 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323448
3449 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:323450 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323451}
3452
[email protected]989386c2013-07-18 21:37:233453TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323454 MockContentLayerClient client;
3455
3456 scoped_refptr<Layer> root = Layer::Create();
sohan.jyotie3bd6192014-10-13 07:13:593457 scoped_refptr<FakePictureLayer> render_surface1 =
3458 CreateDrawablePictureLayer(&client);
3459 scoped_refptr<FakePictureLayer> render_surface2 =
3460 CreateDrawablePictureLayer(&client);
3461 scoped_refptr<FakePictureLayer> child1 = CreateDrawablePictureLayer(&client);
3462 scoped_refptr<FakePictureLayer> child2 = CreateDrawablePictureLayer(&client);
3463 scoped_refptr<FakePictureLayer> child3 = CreateDrawablePictureLayer(&client);
[email protected]fb661802013-03-25 01:59:323464 root->AddChild(render_surface1);
3465 render_surface1->AddChild(render_surface2);
3466 render_surface2->AddChild(child1);
3467 render_surface2->AddChild(child2);
3468 render_surface2->AddChild(child3);
3469
enne2097cab2014-09-25 20:16:313470 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283471 host->SetRootLayer(root);
3472
[email protected]fb661802013-03-25 01:59:323473 gfx::Transform identity_matrix;
3474 SetLayerPropertiesForTesting(root.get(),
3475 identity_matrix,
[email protected]a2566412014-06-05 03:14:203476 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323477 gfx::PointF(),
3478 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573479 true,
[email protected]fb661802013-03-25 01:59:323480 false);
3481 SetLayerPropertiesForTesting(render_surface1.get(),
3482 identity_matrix,
[email protected]a2566412014-06-05 03:14:203483 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323484 gfx::PointF(5.f, 5.f),
3485 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573486 true,
[email protected]fb661802013-03-25 01:59:323487 false);
3488 SetLayerPropertiesForTesting(render_surface2.get(),
3489 identity_matrix,
[email protected]a2566412014-06-05 03:14:203490 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323491 gfx::PointF(5.f, 5.f),
3492 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573493 true,
[email protected]fb661802013-03-25 01:59:323494 false);
3495 SetLayerPropertiesForTesting(child1.get(),
3496 identity_matrix,
[email protected]a2566412014-06-05 03:14:203497 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323498 gfx::PointF(5.f, 5.f),
3499 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573500 true,
[email protected]fb661802013-03-25 01:59:323501 false);
3502 SetLayerPropertiesForTesting(child2.get(),
3503 identity_matrix,
[email protected]a2566412014-06-05 03:14:203504 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323505 gfx::PointF(75.f, 75.f),
3506 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573507 true,
[email protected]fb661802013-03-25 01:59:323508 false);
3509 SetLayerPropertiesForTesting(child3.get(),
3510 identity_matrix,
[email protected]a2566412014-06-05 03:14:203511 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323512 gfx::PointF(125.f, 125.f),
3513 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573514 true,
[email protected]fb661802013-03-25 01:59:323515 false);
3516
3517 float device_scale_factor = 2.f;
3518
3519 root->SetMasksToBounds(true);
3520 render_surface1->SetForceRenderSurface(true);
3521 render_surface2->SetForceRenderSurface(true);
3522 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3523
3524 ASSERT_TRUE(render_surface1->render_surface());
3525 ASSERT_TRUE(render_surface2->render_surface());
3526
3527 // drawable_content_rects for all layers and surfaces are scaled by
3528 // device_scale_factor.
hush6b614212014-12-04 22:37:323529 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3530 root->render_surface()->DrawableContentRect());
3531 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3532 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3533 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323534
3535 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3536 // is only implicitly clipped by render_surface1.
hush6b614212014-12-04 22:37:323537 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3538 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323539
hush6b614212014-12-04 22:37:323540 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3541 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
3542 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323543
3544 // The root layer does not actually draw content of its own.
hush6b614212014-12-04 22:37:323545 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323546
sohan.jyotie3bd6192014-10-13 07:13:593547 // All layer visible content rects are not expressed in content space of each
3548 // layer, so they are not scaled by the device_scale_factor.
hush6b614212014-12-04 22:37:323549 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_content_rect());
3550 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_content_rect());
3551 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3552 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3553 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323554}
3555
[email protected]989386c2013-07-18 21:37:233556TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323557 // Verify the behavior of back-face culling when there are no preserve-3d
3558 // layers. Note that 3d transforms still apply in this case, but they are
3559 // "flattened" to each parent layer according to current W3C spec.
3560
3561 const gfx::Transform identity_matrix;
3562 scoped_refptr<Layer> parent = Layer::Create();
3563 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3564 make_scoped_refptr(new LayerWithForcedDrawsContent());
3565 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3566 make_scoped_refptr(new LayerWithForcedDrawsContent());
3567 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3568 make_scoped_refptr(new LayerWithForcedDrawsContent());
3569 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3570 make_scoped_refptr(new LayerWithForcedDrawsContent());
3571 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233572 front_facing_child_of_front_facing_surface =
3573 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323574 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233575 back_facing_child_of_front_facing_surface =
3576 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323577 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233578 front_facing_child_of_back_facing_surface =
3579 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323580 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233581 back_facing_child_of_back_facing_surface =
3582 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323583
3584 parent->AddChild(front_facing_child);
3585 parent->AddChild(back_facing_child);
3586 parent->AddChild(front_facing_surface);
3587 parent->AddChild(back_facing_surface);
3588 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3589 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3590 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3591 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3592
enne2097cab2014-09-25 20:16:313593 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283594 host->SetRootLayer(parent);
3595
[email protected]fb661802013-03-25 01:59:323596 // Nothing is double-sided
3597 front_facing_child->SetDoubleSided(false);
3598 back_facing_child->SetDoubleSided(false);
3599 front_facing_surface->SetDoubleSided(false);
3600 back_facing_surface->SetDoubleSided(false);
3601 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3602 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3603 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3604 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3605
3606 gfx::Transform backface_matrix;
3607 backface_matrix.Translate(50.0, 50.0);
3608 backface_matrix.RotateAboutYAxis(180.0);
3609 backface_matrix.Translate(-50.0, -50.0);
3610
3611 // Having a descendant and opacity will force these to have render surfaces.
3612 front_facing_surface->SetOpacity(0.5f);
3613 back_facing_surface->SetOpacity(0.5f);
3614
3615 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3616 // these layers should blindly use their own local transforms to determine
3617 // back-face culling.
3618 SetLayerPropertiesForTesting(parent.get(),
3619 identity_matrix,
[email protected]a2566412014-06-05 03:14:203620 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323621 gfx::PointF(),
3622 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573623 true,
[email protected]fb661802013-03-25 01:59:323624 false);
3625 SetLayerPropertiesForTesting(front_facing_child.get(),
3626 identity_matrix,
[email protected]a2566412014-06-05 03:14:203627 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323628 gfx::PointF(),
3629 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573630 true,
[email protected]fb661802013-03-25 01:59:323631 false);
3632 SetLayerPropertiesForTesting(back_facing_child.get(),
3633 backface_matrix,
[email protected]a2566412014-06-05 03:14:203634 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323635 gfx::PointF(),
3636 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573637 true,
[email protected]fb661802013-03-25 01:59:323638 false);
3639 SetLayerPropertiesForTesting(front_facing_surface.get(),
3640 identity_matrix,
[email protected]a2566412014-06-05 03:14:203641 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323642 gfx::PointF(),
3643 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573644 true,
[email protected]fb661802013-03-25 01:59:323645 false);
3646 SetLayerPropertiesForTesting(back_facing_surface.get(),
3647 backface_matrix,
[email protected]a2566412014-06-05 03:14:203648 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323649 gfx::PointF(),
3650 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573651 true,
[email protected]fb661802013-03-25 01:59:323652 false);
3653 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3654 identity_matrix,
[email protected]a2566412014-06-05 03:14:203655 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323656 gfx::PointF(),
3657 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573658 true,
[email protected]fb661802013-03-25 01:59:323659 false);
3660 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3661 backface_matrix,
[email protected]a2566412014-06-05 03:14:203662 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323663 gfx::PointF(),
3664 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573665 true,
[email protected]fb661802013-03-25 01:59:323666 false);
3667 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3668 identity_matrix,
[email protected]a2566412014-06-05 03:14:203669 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323670 gfx::PointF(),
3671 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573672 true,
[email protected]fb661802013-03-25 01:59:323673 false);
3674 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3675 backface_matrix,
[email protected]a2566412014-06-05 03:14:203676 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323677 gfx::PointF(),
3678 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573679 true,
[email protected]fb661802013-03-25 01:59:323680 false);
3681
[email protected]989386c2013-07-18 21:37:233682 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533683 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3684 parent.get(), parent->bounds(), &render_surface_layer_list);
3685 inputs.can_adjust_raster_scales = true;
3686 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323687
3688 // Verify which render surfaces were created.
3689 EXPECT_FALSE(front_facing_child->render_surface());
3690 EXPECT_FALSE(back_facing_child->render_surface());
3691 EXPECT_TRUE(front_facing_surface->render_surface());
3692 EXPECT_TRUE(back_facing_surface->render_surface());
3693 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3694 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3695 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3696 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3697
3698 // Verify the render_surface_layer_list.
3699 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233700 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3701 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323702 // Even though the back facing surface LAYER gets culled, the other
3703 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233704 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323705
3706 // Verify root surface's layer list.
3707 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233708 3u,
3709 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3710 EXPECT_EQ(front_facing_child->id(),
3711 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573712 ->render_surface()
3713 ->layer_list()
3714 .at(0)
3715 ->id());
[email protected]989386c2013-07-18 21:37:233716 EXPECT_EQ(front_facing_surface->id(),
3717 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573718 ->render_surface()
3719 ->layer_list()
3720 .at(1)
3721 ->id());
[email protected]989386c2013-07-18 21:37:233722 EXPECT_EQ(back_facing_surface->id(),
3723 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573724 ->render_surface()
3725 ->layer_list()
3726 .at(2)
3727 ->id());
[email protected]fb661802013-03-25 01:59:323728
3729 // Verify front_facing_surface's layer list.
3730 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233731 2u,
3732 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3733 EXPECT_EQ(front_facing_surface->id(),
3734 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573735 ->render_surface()
3736 ->layer_list()
3737 .at(0)
3738 ->id());
[email protected]989386c2013-07-18 21:37:233739 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3740 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573741 ->render_surface()
3742 ->layer_list()
3743 .at(1)
3744 ->id());
[email protected]fb661802013-03-25 01:59:323745
3746 // Verify back_facing_surface's layer list; its own layer should be culled
3747 // from the surface list.
3748 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233749 1u,
3750 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3751 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3752 render_surface_layer_list.at(2)
[email protected]56fffdd2014-02-11 19:50:573753 ->render_surface()
3754 ->layer_list()
3755 .at(0)
3756 ->id());
[email protected]fb661802013-03-25 01:59:323757}
3758
[email protected]989386c2013-07-18 21:37:233759TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323760 // Verify the behavior of back-face culling when preserves-3d transform style
3761 // is used.
3762
3763 const gfx::Transform identity_matrix;
3764 scoped_refptr<Layer> parent = Layer::Create();
3765 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3766 make_scoped_refptr(new LayerWithForcedDrawsContent());
3767 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3768 make_scoped_refptr(new LayerWithForcedDrawsContent());
3769 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3770 make_scoped_refptr(new LayerWithForcedDrawsContent());
3771 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3772 make_scoped_refptr(new LayerWithForcedDrawsContent());
3773 scoped_refptr<LayerWithForcedDrawsContent>
3774 front_facing_child_of_front_facing_surface =
3775 make_scoped_refptr(new LayerWithForcedDrawsContent());
3776 scoped_refptr<LayerWithForcedDrawsContent>
3777 back_facing_child_of_front_facing_surface =
3778 make_scoped_refptr(new LayerWithForcedDrawsContent());
3779 scoped_refptr<LayerWithForcedDrawsContent>
3780 front_facing_child_of_back_facing_surface =
3781 make_scoped_refptr(new LayerWithForcedDrawsContent());
3782 scoped_refptr<LayerWithForcedDrawsContent>
3783 back_facing_child_of_back_facing_surface =
3784 make_scoped_refptr(new LayerWithForcedDrawsContent());
3785 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3786 make_scoped_refptr(new LayerWithForcedDrawsContent());
3787 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3788 make_scoped_refptr(new LayerWithForcedDrawsContent());
3789
3790 parent->AddChild(front_facing_child);
3791 parent->AddChild(back_facing_child);
3792 parent->AddChild(front_facing_surface);
3793 parent->AddChild(back_facing_surface);
3794 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3795 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3796 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3797 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3798
enne2097cab2014-09-25 20:16:313799 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283800 host->SetRootLayer(parent);
3801
[email protected]fb661802013-03-25 01:59:323802 // Nothing is double-sided
3803 front_facing_child->SetDoubleSided(false);
3804 back_facing_child->SetDoubleSided(false);
3805 front_facing_surface->SetDoubleSided(false);
3806 back_facing_surface->SetDoubleSided(false);
3807 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3808 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3809 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3810 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3811
3812 gfx::Transform backface_matrix;
3813 backface_matrix.Translate(50.0, 50.0);
3814 backface_matrix.RotateAboutYAxis(180.0);
3815 backface_matrix.Translate(-50.0, -50.0);
3816
3817 // Opacity will not force creation of render surfaces in this case because of
3818 // the preserve-3d transform style. Instead, an example of when a surface
3819 // would be created with preserve-3d is when there is a replica layer.
3820 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3821 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3822
3823 // Each surface creates its own new 3d rendering context (as defined by W3C
3824 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3825 // rendering context should use the transform with respect to that context.
3826 // This 3d rendering context occurs when (a) parent's transform style is flat
3827 // and (b) the layer's transform style is preserve-3d.
3828 SetLayerPropertiesForTesting(parent.get(),
3829 identity_matrix,
[email protected]a2566412014-06-05 03:14:203830 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323831 gfx::PointF(),
3832 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573833 true,
[email protected]fb661802013-03-25 01:59:323834 false); // parent transform style is flat.
3835 SetLayerPropertiesForTesting(front_facing_child.get(),
3836 identity_matrix,
[email protected]a2566412014-06-05 03:14:203837 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323838 gfx::PointF(),
3839 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573840 true,
[email protected]fb661802013-03-25 01:59:323841 false);
3842 SetLayerPropertiesForTesting(back_facing_child.get(),
3843 backface_matrix,
[email protected]a2566412014-06-05 03:14:203844 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323845 gfx::PointF(),
3846 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573847 true,
[email protected]fb661802013-03-25 01:59:323848 false);
[email protected]56fffdd2014-02-11 19:50:573849 // surface transform style is preserve-3d.
3850 SetLayerPropertiesForTesting(front_facing_surface.get(),
3851 identity_matrix,
[email protected]a2566412014-06-05 03:14:203852 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:573853 gfx::PointF(),
3854 gfx::Size(100, 100),
3855 false,
3856 true);
3857 // surface transform style is preserve-3d.
3858 SetLayerPropertiesForTesting(back_facing_surface.get(),
3859 backface_matrix,
[email protected]a2566412014-06-05 03:14:203860 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:573861 gfx::PointF(),
3862 gfx::Size(100, 100),
3863 false,
3864 true);
[email protected]fb661802013-03-25 01:59:323865 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3866 identity_matrix,
[email protected]a2566412014-06-05 03:14:203867 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323868 gfx::PointF(),
3869 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573870 true,
3871 true);
[email protected]fb661802013-03-25 01:59:323872 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3873 backface_matrix,
[email protected]a2566412014-06-05 03:14:203874 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323875 gfx::PointF(),
3876 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573877 true,
3878 true);
[email protected]fb661802013-03-25 01:59:323879 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3880 identity_matrix,
[email protected]a2566412014-06-05 03:14:203881 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323882 gfx::PointF(),
3883 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573884 true,
3885 true);
[email protected]fb661802013-03-25 01:59:323886 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3887 backface_matrix,
[email protected]a2566412014-06-05 03:14:203888 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323889 gfx::PointF(),
3890 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573891 true,
3892 true);
[email protected]fb661802013-03-25 01:59:323893
[email protected]989386c2013-07-18 21:37:233894 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533895 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3896 parent.get(), parent->bounds(), &render_surface_layer_list);
3897 inputs.can_adjust_raster_scales = true;
3898 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323899
awoloszyne83f28c2014-12-22 15:40:003900 // Verify which render surfaces were created and used.
[email protected]fb661802013-03-25 01:59:323901 EXPECT_FALSE(front_facing_child->render_surface());
3902 EXPECT_FALSE(back_facing_child->render_surface());
3903 EXPECT_TRUE(front_facing_surface->render_surface());
awoloszyne83f28c2014-12-22 15:40:003904 EXPECT_NE(back_facing_surface->render_target(), back_facing_surface);
3905 // We expect that a render_surface was created but not used.
3906 EXPECT_TRUE(back_facing_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323907 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3908 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3909 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3910 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3911
3912 // Verify the render_surface_layer_list. The back-facing surface should be
3913 // culled.
3914 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233915 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3916 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323917
3918 // Verify root surface's layer list.
3919 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233920 2u,
3921 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3922 EXPECT_EQ(front_facing_child->id(),
3923 render_surface_layer_list.at(0)
3924 ->render_surface()->layer_list().at(0)->id());
3925 EXPECT_EQ(front_facing_surface->id(),
3926 render_surface_layer_list.at(0)
3927 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323928
3929 // Verify front_facing_surface's layer list.
3930 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233931 2u,
3932 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3933 EXPECT_EQ(front_facing_surface->id(),
3934 render_surface_layer_list.at(1)
3935 ->render_surface()->layer_list().at(0)->id());
3936 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3937 render_surface_layer_list.at(1)
3938 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323939}
3940
[email protected]989386c2013-07-18 21:37:233941TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:323942 // Verify that layers are appropriately culled when their back face is showing
3943 // and they are not double sided, while animations are going on.
3944 //
3945 // Layers that are animating do not get culled on the main thread, as their
3946 // transforms should be treated as "unknown" so we can not be sure that their
3947 // back face is really showing.
3948 const gfx::Transform identity_matrix;
3949 scoped_refptr<Layer> parent = Layer::Create();
3950 scoped_refptr<LayerWithForcedDrawsContent> child =
3951 make_scoped_refptr(new LayerWithForcedDrawsContent());
3952 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3953 make_scoped_refptr(new LayerWithForcedDrawsContent());
3954 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3955 make_scoped_refptr(new LayerWithForcedDrawsContent());
3956 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3957 make_scoped_refptr(new LayerWithForcedDrawsContent());
3958 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3959 make_scoped_refptr(new LayerWithForcedDrawsContent());
3960
3961 parent->AddChild(child);
3962 parent->AddChild(animating_surface);
3963 animating_surface->AddChild(child_of_animating_surface);
3964 parent->AddChild(animating_child);
3965 parent->AddChild(child2);
3966
enne2097cab2014-09-25 20:16:313967 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283968 host->SetRootLayer(parent);
3969
[email protected]fb661802013-03-25 01:59:323970 // Nothing is double-sided
3971 child->SetDoubleSided(false);
3972 child2->SetDoubleSided(false);
3973 animating_surface->SetDoubleSided(false);
3974 child_of_animating_surface->SetDoubleSided(false);
3975 animating_child->SetDoubleSided(false);
3976
3977 gfx::Transform backface_matrix;
3978 backface_matrix.Translate(50.0, 50.0);
3979 backface_matrix.RotateAboutYAxis(180.0);
3980 backface_matrix.Translate(-50.0, -50.0);
3981
3982 // Make our render surface.
3983 animating_surface->SetForceRenderSurface(true);
3984
3985 // Animate the transform on the render surface.
3986 AddAnimatedTransformToController(
3987 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3988 // This is just an animating layer, not a surface.
3989 AddAnimatedTransformToController(
3990 animating_child->layer_animation_controller(), 10.0, 30, 0);
3991
3992 SetLayerPropertiesForTesting(parent.get(),
3993 identity_matrix,
[email protected]a2566412014-06-05 03:14:203994 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323995 gfx::PointF(),
3996 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573997 true,
[email protected]fb661802013-03-25 01:59:323998 false);
3999 SetLayerPropertiesForTesting(child.get(),
4000 backface_matrix,
[email protected]a2566412014-06-05 03:14:204001 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324002 gfx::PointF(),
4003 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574004 true,
[email protected]fb661802013-03-25 01:59:324005 false);
4006 SetLayerPropertiesForTesting(animating_surface.get(),
4007 backface_matrix,
[email protected]a2566412014-06-05 03:14:204008 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324009 gfx::PointF(),
4010 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574011 true,
[email protected]fb661802013-03-25 01:59:324012 false);
4013 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
4014 backface_matrix,
[email protected]a2566412014-06-05 03:14:204015 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324016 gfx::PointF(),
4017 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574018 true,
[email protected]fb661802013-03-25 01:59:324019 false);
4020 SetLayerPropertiesForTesting(animating_child.get(),
4021 backface_matrix,
[email protected]a2566412014-06-05 03:14:204022 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324023 gfx::PointF(),
4024 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574025 true,
[email protected]fb661802013-03-25 01:59:324026 false);
4027 SetLayerPropertiesForTesting(child2.get(),
4028 identity_matrix,
[email protected]a2566412014-06-05 03:14:204029 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324030 gfx::PointF(),
4031 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574032 true,
[email protected]fb661802013-03-25 01:59:324033 false);
4034
[email protected]989386c2013-07-18 21:37:234035 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534036 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4037 parent.get(), parent->bounds(), &render_surface_layer_list);
4038 inputs.can_adjust_raster_scales = true;
4039 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324040
4041 EXPECT_FALSE(child->render_surface());
4042 EXPECT_TRUE(animating_surface->render_surface());
4043 EXPECT_FALSE(child_of_animating_surface->render_surface());
4044 EXPECT_FALSE(animating_child->render_surface());
4045 EXPECT_FALSE(child2->render_surface());
4046
4047 // Verify that the animating_child and child_of_animating_surface were not
4048 // culled, but that child was.
4049 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234050 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4051 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324052
4053 // The non-animating child be culled from the layer list for the parent render
4054 // surface.
4055 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234056 3u,
4057 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4058 EXPECT_EQ(animating_surface->id(),
4059 render_surface_layer_list.at(0)
4060 ->render_surface()->layer_list().at(0)->id());
4061 EXPECT_EQ(animating_child->id(),
4062 render_surface_layer_list.at(0)
4063 ->render_surface()->layer_list().at(1)->id());
4064 EXPECT_EQ(child2->id(),
4065 render_surface_layer_list.at(0)
4066 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:324067
4068 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234069 2u,
4070 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4071 EXPECT_EQ(animating_surface->id(),
4072 render_surface_layer_list.at(1)
4073 ->render_surface()->layer_list().at(0)->id());
4074 EXPECT_EQ(child_of_animating_surface->id(),
4075 render_surface_layer_list.at(1)
4076 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324077
4078 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
4079
4080 // The animating layers should have a visible content rect that represents the
4081 // area of the front face that is within the viewport.
4082 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054083 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:324084 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:054085 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324086 // And layers in the subtree of the animating layer should have valid visible
4087 // content rects also.
[email protected]989386c2013-07-18 21:37:234088 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
4089 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:324090}
4091
[email protected]989386c2013-07-18 21:37:234092TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324093 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4094 // Verify the behavior of back-face culling for a render surface that is
4095 // created when it flattens its subtree, and its parent has preserves-3d.
4096
4097 const gfx::Transform identity_matrix;
4098 scoped_refptr<Layer> parent = Layer::Create();
4099 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
4100 make_scoped_refptr(new LayerWithForcedDrawsContent());
4101 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
4102 make_scoped_refptr(new LayerWithForcedDrawsContent());
4103 scoped_refptr<LayerWithForcedDrawsContent> child1 =
4104 make_scoped_refptr(new LayerWithForcedDrawsContent());
4105 scoped_refptr<LayerWithForcedDrawsContent> child2 =
4106 make_scoped_refptr(new LayerWithForcedDrawsContent());
4107
4108 parent->AddChild(front_facing_surface);
4109 parent->AddChild(back_facing_surface);
4110 front_facing_surface->AddChild(child1);
4111 back_facing_surface->AddChild(child2);
4112
enne2097cab2014-09-25 20:16:314113 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284114 host->SetRootLayer(parent);
4115
[email protected]fb661802013-03-25 01:59:324116 // RenderSurfaces are not double-sided
4117 front_facing_surface->SetDoubleSided(false);
4118 back_facing_surface->SetDoubleSided(false);
4119
4120 gfx::Transform backface_matrix;
4121 backface_matrix.Translate(50.0, 50.0);
4122 backface_matrix.RotateAboutYAxis(180.0);
4123 backface_matrix.Translate(-50.0, -50.0);
4124
4125 SetLayerPropertiesForTesting(parent.get(),
4126 identity_matrix,
[email protected]a2566412014-06-05 03:14:204127 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324128 gfx::PointF(),
4129 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574130 false,
4131 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:324132 SetLayerPropertiesForTesting(front_facing_surface.get(),
4133 identity_matrix,
[email protected]a2566412014-06-05 03:14:204134 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324135 gfx::PointF(),
4136 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574137 true,
4138 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324139 SetLayerPropertiesForTesting(back_facing_surface.get(),
4140 backface_matrix,
[email protected]a2566412014-06-05 03:14:204141 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324142 gfx::PointF(),
4143 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574144 true,
4145 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324146 SetLayerPropertiesForTesting(child1.get(),
4147 identity_matrix,
[email protected]a2566412014-06-05 03:14:204148 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324149 gfx::PointF(),
4150 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574151 true,
[email protected]fb661802013-03-25 01:59:324152 false);
4153 SetLayerPropertiesForTesting(child2.get(),
4154 identity_matrix,
[email protected]a2566412014-06-05 03:14:204155 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324156 gfx::PointF(),
4157 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574158 true,
[email protected]fb661802013-03-25 01:59:324159 false);
4160
[email protected]a9d4d4f2014-06-19 06:49:284161 front_facing_surface->Set3dSortingContextId(1);
4162 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574163
[email protected]989386c2013-07-18 21:37:234164 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534165 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4166 parent.get(), parent->bounds(), &render_surface_layer_list);
4167 inputs.can_adjust_raster_scales = true;
4168 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324169
awoloszyne83f28c2014-12-22 15:40:004170 // Verify which render surfaces were created and used.
[email protected]fb661802013-03-25 01:59:324171 EXPECT_TRUE(front_facing_surface->render_surface());
awoloszyne83f28c2014-12-22 15:40:004172
4173 // We expect the render surface to have been created, but remain unused.
4174 EXPECT_TRUE(back_facing_surface->render_surface());
4175 EXPECT_NE(back_facing_surface->render_target(),
4176 back_facing_surface); // because it should be culled
[email protected]fb661802013-03-25 01:59:324177 EXPECT_FALSE(child1->render_surface());
4178 EXPECT_FALSE(child2->render_surface());
4179
4180 // Verify the render_surface_layer_list. The back-facing surface should be
4181 // culled.
4182 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234183 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4184 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324185
4186 // Verify root surface's layer list.
4187 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234188 1u,
4189 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4190 EXPECT_EQ(front_facing_surface->id(),
4191 render_surface_layer_list.at(0)
4192 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324193
4194 // Verify front_facing_surface's layer list.
4195 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234196 2u,
4197 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4198 EXPECT_EQ(front_facing_surface->id(),
4199 render_surface_layer_list.at(1)
4200 ->render_surface()->layer_list().at(0)->id());
4201 EXPECT_EQ(child1->id(),
4202 render_surface_layer_list.at(1)
4203 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324204}
4205
[email protected]fb661802013-03-25 01:59:324206class NoScaleContentLayer : public ContentLayer {
4207 public:
4208 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
4209 return make_scoped_refptr(new NoScaleContentLayer(client));
4210 }
[email protected]94f206c12012-08-25 00:09:144211
dcheng716bedf2014-10-21 09:51:084212 void CalculateContentsScale(float ideal_contents_scale,
4213 float* contents_scale_x,
4214 float* contents_scale_y,
4215 gfx::Size* content_bounds) override {
[email protected]fb661802013-03-25 01:59:324216 // Skip over the ContentLayer to the base Layer class.
4217 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]fb661802013-03-25 01:59:324218 contents_scale_x,
4219 contents_scale_y,
4220 content_bounds);
4221 }
[email protected]94f206c12012-08-25 00:09:144222
[email protected]fb661802013-03-25 01:59:324223 protected:
4224 explicit NoScaleContentLayer(ContentLayerClient* client)
4225 : ContentLayer(client) {}
dcheng716bedf2014-10-21 09:51:084226 ~NoScaleContentLayer() override {}
[email protected]518ee582012-10-24 18:29:444227};
4228
[email protected]fb661802013-03-25 01:59:324229scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
4230 ContentLayerClient* delegate) {
4231 scoped_refptr<NoScaleContentLayer> to_return =
4232 NoScaleContentLayer::Create(delegate);
4233 to_return->SetIsDrawable(true);
4234 return to_return;
[email protected]518ee582012-10-24 18:29:444235}
4236
[email protected]989386c2013-07-18 21:37:234237TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324238 // Verify draw and screen space transforms of layers not in a surface.
4239 MockContentLayerClient delegate;
4240 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:144241
sohan.jyotie3bd6192014-10-13 07:13:594242 scoped_refptr<FakePictureLayer> parent =
4243 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324244 SetLayerPropertiesForTesting(parent.get(),
4245 identity_matrix,
[email protected]a2566412014-06-05 03:14:204246 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324247 gfx::PointF(),
4248 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574249 false,
[email protected]fb661802013-03-25 01:59:324250 true);
[email protected]94f206c12012-08-25 00:09:144251
sohan.jyotie3bd6192014-10-13 07:13:594252 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324253 SetLayerPropertiesForTesting(child.get(),
4254 identity_matrix,
[email protected]a2566412014-06-05 03:14:204255 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324256 gfx::PointF(2.f, 2.f),
4257 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574258 false,
[email protected]fb661802013-03-25 01:59:324259 true);
[email protected]94f206c12012-08-25 00:09:144260
sohan.jyotie3bd6192014-10-13 07:13:594261 scoped_refptr<FakePictureLayer> child_empty =
4262 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324263 SetLayerPropertiesForTesting(child_empty.get(),
4264 identity_matrix,
[email protected]a2566412014-06-05 03:14:204265 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324266 gfx::PointF(2.f, 2.f),
4267 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574268 false,
[email protected]fb661802013-03-25 01:59:324269 true);
[email protected]f89f5632012-11-14 23:34:454270
[email protected]fb661802013-03-25 01:59:324271 parent->AddChild(child);
4272 parent->AddChild(child_empty);
[email protected]94f206c12012-08-25 00:09:144273
enne2097cab2014-09-25 20:16:314274 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284275 host->SetRootLayer(parent);
4276
[email protected]fb661802013-03-25 01:59:324277 float device_scale_factor = 2.5f;
4278 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:144279
[email protected]7aad55f2013-07-26 11:25:534280 RenderSurfaceLayerList render_surface_layer_list;
4281 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4282 parent.get(), parent->bounds(), &render_surface_layer_list);
4283 inputs.device_scale_factor = device_scale_factor;
4284 inputs.page_scale_factor = page_scale_factor;
4285 inputs.can_adjust_raster_scales = true;
4286 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:444287
sohan.jyotie3bd6192014-10-13 07:13:594288 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4289 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child);
4290 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child_empty);
[email protected]94f206c12012-08-25 00:09:144291
[email protected]fb661802013-03-25 01:59:324292 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:144293
[email protected]fb661802013-03-25 01:59:324294 // Verify parent transforms
4295 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594296 expected_parent_transform.Scale(device_scale_factor * page_scale_factor,
4297 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324298 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4299 parent->screen_space_transform());
4300 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4301 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:144302
[email protected]fb661802013-03-25 01:59:324303 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:054304 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:144305
[email protected]fb661802013-03-25 01:59:324306 gfx::RectF parent_draw_rect =
4307 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
4308 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
4309 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:144310
[email protected]2c7c6702013-03-26 03:14:054311 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:324312 expected_parent_draw_rect.Scale(device_scale_factor);
4313 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4314 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144315
[email protected]fb661802013-03-25 01:59:324316 // Verify child and child_empty transforms. They should match.
4317 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594318 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4319 expected_child_transform.Translate(child->position().x(),
4320 child->position().y());
[email protected]fb661802013-03-25 01:59:324321 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4322 child->draw_transform());
4323 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4324 child->screen_space_transform());
4325 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4326 child_empty->draw_transform());
4327 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4328 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144329
[email protected]fb661802013-03-25 01:59:324330 // Verify results of transformed child and child_empty rects. They should
4331 // match.
[email protected]2c7c6702013-03-26 03:14:054332 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:144333
[email protected]fb661802013-03-25 01:59:324334 gfx::RectF child_draw_rect =
4335 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
4336 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
4337 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:144338
[email protected]fb661802013-03-25 01:59:324339 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
4340 child_empty->draw_transform(), child_content_bounds);
4341 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
4342 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:454343
[email protected]fb661802013-03-25 01:59:324344 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
4345 expected_child_draw_rect.Scale(device_scale_factor);
4346 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4347 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
4348 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
4349 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144350}
4351
[email protected]989386c2013-07-18 21:37:234352TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324353 // Verify draw and screen space transforms of layers in a surface.
4354 MockContentLayerClient delegate;
4355 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:094356
[email protected]fb661802013-03-25 01:59:324357 gfx::Transform perspective_matrix;
4358 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094359
[email protected]fb661802013-03-25 01:59:324360 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054361 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094362
[email protected]9781afa2013-07-17 23:15:324363 scoped_refptr<Layer> root = Layer::Create();
4364
sohan.jyotie3bd6192014-10-13 07:13:594365 scoped_refptr<FakePictureLayer> parent =
4366 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324367 SetLayerPropertiesForTesting(parent.get(),
4368 identity_matrix,
[email protected]a2566412014-06-05 03:14:204369 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324370 gfx::PointF(),
4371 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574372 false,
[email protected]fb661802013-03-25 01:59:324373 true);
[email protected]1b30e8e2012-12-21 02:59:094374
sohan.jyotie3bd6192014-10-13 07:13:594375 scoped_refptr<FakePictureLayer> perspective_surface =
4376 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324377 SetLayerPropertiesForTesting(perspective_surface.get(),
4378 perspective_matrix * scale_small_matrix,
[email protected]a2566412014-06-05 03:14:204379 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324380 gfx::PointF(2.f, 2.f),
4381 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574382 false,
[email protected]fb661802013-03-25 01:59:324383 true);
[email protected]1b30e8e2012-12-21 02:59:094384
sohan.jyotie3bd6192014-10-13 07:13:594385 scoped_refptr<FakePictureLayer> scale_surface =
4386 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324387 SetLayerPropertiesForTesting(scale_surface.get(),
4388 scale_small_matrix,
[email protected]a2566412014-06-05 03:14:204389 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324390 gfx::PointF(2.f, 2.f),
4391 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574392 false,
[email protected]fb661802013-03-25 01:59:324393 true);
[email protected]1b30e8e2012-12-21 02:59:094394
[email protected]fb661802013-03-25 01:59:324395 perspective_surface->SetForceRenderSurface(true);
4396 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:094397
[email protected]fb661802013-03-25 01:59:324398 parent->AddChild(perspective_surface);
4399 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:324400 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:094401
enne2097cab2014-09-25 20:16:314402 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284403 host->SetRootLayer(root);
4404
[email protected]fb661802013-03-25 01:59:324405 float device_scale_factor = 2.5f;
4406 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:094407
[email protected]7aad55f2013-07-26 11:25:534408 RenderSurfaceLayerList render_surface_layer_list;
4409 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4410 root.get(), parent->bounds(), &render_surface_layer_list);
4411 inputs.device_scale_factor = device_scale_factor;
4412 inputs.page_scale_factor = page_scale_factor;
Daniel Chengeea98042014-08-26 00:28:104413 inputs.page_scale_application_layer = root.get();
[email protected]7aad55f2013-07-26 11:25:534414 inputs.can_adjust_raster_scales = true;
4415 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:094416
sohan.jyotie3bd6192014-10-13 07:13:594417 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4418 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
4419 perspective_surface);
4420 // Ideal scale is the max 2d scale component of the combined transform up to
4421 // the nearest render target. Here this includes the layer transform as well
4422 // as the device and page scale factors.
4423 gfx::Transform transform = scale_small_matrix;
4424 transform.Scale(device_scale_factor * page_scale_factor,
4425 device_scale_factor * page_scale_factor);
4426 gfx::Vector2dF scales =
4427 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4428 float max_2d_scale = std::max(scales.x(), scales.y());
4429 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
4430
4431 // The ideal scale will draw 1:1 with its render target space along
4432 // the larger-scale axis.
4433 gfx::Vector2dF target_space_transform_scales =
4434 MathUtil::ComputeTransform2dScaleComponents(
4435 scale_surface->draw_properties().target_space_transform, 0.f);
4436 EXPECT_FLOAT_EQ(max_2d_scale,
4437 std::max(target_space_transform_scales.x(),
4438 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094439
[email protected]fb661802013-03-25 01:59:324440 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:094441
[email protected]fb661802013-03-25 01:59:324442 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594443 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4444 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324445 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
4446 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094447
[email protected]fb661802013-03-25 01:59:324448 // The scale for the perspective surface is not known, so it is rendered 1:1
4449 // with the screen, and then scaled during drawing.
4450 gfx::Transform expected_perspective_surface_draw_transform;
4451 expected_perspective_surface_draw_transform.Translate(
4452 device_scale_factor * page_scale_factor *
4453 perspective_surface->position().x(),
4454 device_scale_factor * page_scale_factor *
4455 perspective_surface->position().y());
4456 expected_perspective_surface_draw_transform.PreconcatTransform(
4457 perspective_matrix);
4458 expected_perspective_surface_draw_transform.PreconcatTransform(
4459 scale_small_matrix);
4460 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594461 expected_perspective_surface_layer_draw_transform.Scale(
4462 device_scale_factor * page_scale_factor,
4463 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324464 EXPECT_TRANSFORMATION_MATRIX_EQ(
4465 expected_perspective_surface_draw_transform,
4466 perspective_surface->render_surface()->draw_transform());
4467 EXPECT_TRANSFORMATION_MATRIX_EQ(
4468 expected_perspective_surface_layer_draw_transform,
4469 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094470}
4471
sohan.jyotie3bd6192014-10-13 07:13:594472// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234473TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324474 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
4475 // Verify draw and screen space transforms of layers not in a surface.
4476 MockContentLayerClient delegate;
4477 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:474478
[email protected]fb661802013-03-25 01:59:324479 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4480 SetLayerPropertiesForTesting(parent.get(),
4481 identity_matrix,
[email protected]a2566412014-06-05 03:14:204482 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324483 gfx::PointF(),
4484 gfx::Size(133, 133),
[email protected]56fffdd2014-02-11 19:50:574485 false,
[email protected]fb661802013-03-25 01:59:324486 true);
[email protected]904e9132012-11-01 00:12:474487
[email protected]fb661802013-03-25 01:59:324488 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
4489 SetLayerPropertiesForTesting(child.get(),
4490 identity_matrix,
[email protected]a2566412014-06-05 03:14:204491 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324492 gfx::PointF(),
4493 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:574494 false,
[email protected]fb661802013-03-25 01:59:324495 true);
[email protected]904e9132012-11-01 00:12:474496
[email protected]fb661802013-03-25 01:59:324497 scoped_refptr<NoScaleContentLayer> child_no_scale =
4498 CreateNoScaleDrawableContentLayer(&delegate);
4499 SetLayerPropertiesForTesting(child_no_scale.get(),
4500 identity_matrix,
[email protected]a2566412014-06-05 03:14:204501 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324502 gfx::PointF(),
4503 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:574504 false,
[email protected]fb661802013-03-25 01:59:324505 true);
[email protected]904e9132012-11-01 00:12:474506
[email protected]fb661802013-03-25 01:59:324507 parent->AddChild(child);
4508 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:474509
enne2097cab2014-09-25 20:16:314510 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284511 host->SetRootLayer(parent);
4512
[email protected]fb661802013-03-25 01:59:324513 float device_scale_factor = 1.7f;
4514 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:474515
[email protected]7aad55f2013-07-26 11:25:534516 RenderSurfaceLayerList render_surface_layer_list;
4517 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4518 parent.get(), parent->bounds(), &render_surface_layer_list);
4519 inputs.device_scale_factor = device_scale_factor;
4520 inputs.page_scale_factor = page_scale_factor;
4521 inputs.page_scale_application_layer = parent.get();
4522 inputs.can_adjust_raster_scales = true;
4523 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:474524
[email protected]fb661802013-03-25 01:59:324525 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4526 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
4527 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:474528
[email protected]fb661802013-03-25 01:59:324529 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:474530
[email protected]fb661802013-03-25 01:59:324531 // Verify parent transforms
4532 gfx::Transform expected_parent_transform;
4533 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4534 parent->screen_space_transform());
4535 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4536 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:474537
[email protected]fb661802013-03-25 01:59:324538 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:054539 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:474540
[email protected]fb661802013-03-25 01:59:324541 gfx::RectF parent_draw_rect =
4542 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
4543 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
4544 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:474545
[email protected]2c7c6702013-03-26 03:14:054546 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:324547 expected_parent_draw_rect.Scale(device_scale_factor);
4548 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
4549 expected_parent_draw_rect.set_height(
4550 ceil(expected_parent_draw_rect.height()));
4551 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4552 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:474553
[email protected]fb661802013-03-25 01:59:324554 // Verify child transforms
4555 gfx::Transform expected_child_transform;
4556 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4557 child->draw_transform());
4558 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4559 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474560
[email protected]fb661802013-03-25 01:59:324561 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:054562 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:474563
[email protected]fb661802013-03-25 01:59:324564 gfx::RectF child_draw_rect =
4565 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
4566 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
4567 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:474568
[email protected]2c7c6702013-03-26 03:14:054569 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:324570 expected_child_draw_rect.Scale(device_scale_factor);
4571 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
4572 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
4573 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4574 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:474575
[email protected]fb661802013-03-25 01:59:324576 // Verify child_no_scale transforms
4577 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
4578 // All transforms operate on content rects. The child's content rect
4579 // incorporates device scale, but the child_no_scale does not; add it here.
4580 expected_child_no_scale_transform.Scale(device_scale_factor,
4581 device_scale_factor);
4582 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4583 child_no_scale->draw_transform());
4584 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4585 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474586}
4587
sohan.jyotie3bd6192014-10-13 07:13:594588// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234589TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:324590 MockContentLayerClient delegate;
4591 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:444592
[email protected]fb661802013-03-25 01:59:324593 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264594 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324595 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:444596
[email protected]fb661802013-03-25 01:59:324597 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264598 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324599 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:444600
[email protected]35a99a12013-05-09 23:52:294601 scoped_refptr<Layer> root = Layer::Create();
4602 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:444603
[email protected]fb661802013-03-25 01:59:324604 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4605 SetLayerPropertiesForTesting(parent.get(),
4606 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204607 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324608 gfx::PointF(),
4609 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574610 false,
[email protected]fb661802013-03-25 01:59:324611 true);
[email protected]518ee582012-10-24 18:29:444612
[email protected]fb661802013-03-25 01:59:324613 scoped_refptr<ContentLayer> child_scale =
4614 CreateDrawableContentLayer(&delegate);
4615 SetLayerPropertiesForTesting(child_scale.get(),
4616 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204617 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324618 gfx::PointF(2.f, 2.f),
4619 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574620 false,
[email protected]fb661802013-03-25 01:59:324621 true);
[email protected]518ee582012-10-24 18:29:444622
[email protected]fb661802013-03-25 01:59:324623 scoped_refptr<ContentLayer> child_empty =
4624 CreateDrawableContentLayer(&delegate);
4625 SetLayerPropertiesForTesting(child_empty.get(),
4626 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204627 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324628 gfx::PointF(2.f, 2.f),
4629 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574630 false,
[email protected]fb661802013-03-25 01:59:324631 true);
[email protected]f89f5632012-11-14 23:34:454632
[email protected]fb661802013-03-25 01:59:324633 scoped_refptr<NoScaleContentLayer> child_no_scale =
4634 CreateNoScaleDrawableContentLayer(&delegate);
4635 SetLayerPropertiesForTesting(child_no_scale.get(),
4636 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204637 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324638 gfx::PointF(12.f, 12.f),
4639 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574640 false,
[email protected]fb661802013-03-25 01:59:324641 true);
[email protected]518ee582012-10-24 18:29:444642
[email protected]35a99a12013-05-09 23:52:294643 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:444644
[email protected]fb661802013-03-25 01:59:324645 parent->AddChild(child_scale);
4646 parent->AddChild(child_empty);
4647 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:444648
enne2097cab2014-09-25 20:16:314649 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284650 host->SetRootLayer(root);
4651
[email protected]fb661802013-03-25 01:59:324652 float device_scale_factor = 2.5f;
4653 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:444654
[email protected]989386c2013-07-18 21:37:234655 {
4656 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534657 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224658 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534659 inputs.device_scale_factor = device_scale_factor;
4660 inputs.page_scale_factor = page_scale_factor;
4661 inputs.page_scale_application_layer = root.get();
4662 inputs.can_adjust_raster_scales = true;
4663 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:444664
[email protected]989386c2013-07-18 21:37:234665 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4666 initial_parent_scale, parent);
4667 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4668 initial_parent_scale * initial_child_scale,
4669 child_scale);
4670 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4671 initial_parent_scale * initial_child_scale,
4672 child_empty);
4673 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:444674
[email protected]989386c2013-07-18 21:37:234675 // The parent is scaled up and shouldn't need to scale during draw. The
4676 // child that can scale its contents should also not need to scale during
4677 // draw. This shouldn't change if the child has empty bounds. The other
4678 // children should.
[email protected]803f6b52013-09-12 00:51:264679 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
4680 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
4681 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
4682 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
4683 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
4684 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:234685 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
4686 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264687 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]989386c2013-07-18 21:37:234688 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264689 initial_parent_scale * initial_child_scale,
4690 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:234691 }
[email protected]518ee582012-10-24 18:29:444692
[email protected]fb661802013-03-25 01:59:324693 // If the device_scale_factor or page_scale_factor changes, then it should be
4694 // updated using the initial transform as the raster scale.
4695 device_scale_factor = 2.25f;
4696 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:444697
[email protected]989386c2013-07-18 21:37:234698 {
4699 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534700 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224701 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534702 inputs.device_scale_factor = device_scale_factor;
4703 inputs.page_scale_factor = page_scale_factor;
4704 inputs.page_scale_application_layer = root.get();
4705 inputs.can_adjust_raster_scales = true;
4706 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4707
4708 EXPECT_CONTENTS_SCALE_EQ(
4709 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:234710 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:534711 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:234712 child_scale);
4713 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4714 initial_parent_scale * initial_child_scale,
4715 child_empty);
4716 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4717 }
[email protected]d0518202013-02-08 02:06:494718
[email protected]fb661802013-03-25 01:59:324719 // If the transform changes, we expect the raster scale to be reset to 1.0.
[email protected]803f6b52013-09-12 00:51:264720 SkMScalar second_child_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324721 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
4722 second_child_scale / initial_child_scale);
4723 child_scale->SetTransform(child_scale_matrix);
4724 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:494725
[email protected]989386c2013-07-18 21:37:234726 {
4727 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534728 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224729 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534730 inputs.device_scale_factor = device_scale_factor;
4731 inputs.page_scale_factor = page_scale_factor;
4732 inputs.page_scale_application_layer = root.get();
4733 inputs.can_adjust_raster_scales = true;
4734 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:494735
[email protected]989386c2013-07-18 21:37:234736 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4737 initial_parent_scale,
4738 parent);
4739 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4740 child_scale);
4741 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4742 child_empty);
4743 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4744 }
[email protected]d0518202013-02-08 02:06:494745
[email protected]fb661802013-03-25 01:59:324746 // If the device_scale_factor or page_scale_factor changes, then it should be
4747 // updated, but still using 1.0 as the raster scale.
4748 device_scale_factor = 2.75f;
4749 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:494750
[email protected]989386c2013-07-18 21:37:234751 {
4752 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534753 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224754 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534755 inputs.device_scale_factor = device_scale_factor;
4756 inputs.page_scale_factor = page_scale_factor;
4757 inputs.page_scale_application_layer = root.get();
4758 inputs.can_adjust_raster_scales = true;
4759 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:494760
[email protected]989386c2013-07-18 21:37:234761 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4762 initial_parent_scale,
4763 parent);
4764 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4765 child_scale);
4766 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4767 child_empty);
4768 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4769 }
[email protected]518ee582012-10-24 18:29:444770}
4771
sohan.jyotie3bd6192014-10-13 07:13:594772// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234773TEST_F(LayerTreeHostCommonTest,
sohan.jyotie3bd6192014-10-13 07:13:594774 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:324775 MockContentLayerClient delegate;
4776 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:214777
[email protected]fb661802013-03-25 01:59:324778 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264779 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324780 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:214781
[email protected]fb661802013-03-25 01:59:324782 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264783 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324784 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:214785
[email protected]35a99a12013-05-09 23:52:294786 scoped_refptr<Layer> root = Layer::Create();
4787 root->SetBounds(gfx::Size(100, 100));
4788
[email protected]fb661802013-03-25 01:59:324789 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4790 SetLayerPropertiesForTesting(parent.get(),
4791 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204792 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324793 gfx::PointF(),
4794 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574795 false,
[email protected]fb661802013-03-25 01:59:324796 true);
[email protected]11ec92972012-11-10 03:06:214797
[email protected]fb661802013-03-25 01:59:324798 scoped_refptr<ContentLayer> child_scale =
4799 CreateDrawableContentLayer(&delegate);
4800 SetLayerPropertiesForTesting(child_scale.get(),
4801 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204802 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324803 gfx::PointF(2.f, 2.f),
4804 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574805 false,
[email protected]fb661802013-03-25 01:59:324806 true);
[email protected]11ec92972012-11-10 03:06:214807
[email protected]35a99a12013-05-09 23:52:294808 scoped_refptr<ContentLayer> child_empty =
4809 CreateDrawableContentLayer(&delegate);
4810 SetLayerPropertiesForTesting(child_empty.get(),
4811 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204812 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294813 gfx::PointF(2.f, 2.f),
4814 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574815 false,
[email protected]35a99a12013-05-09 23:52:294816 true);
4817
4818 scoped_refptr<NoScaleContentLayer> child_no_scale =
4819 CreateNoScaleDrawableContentLayer(&delegate);
4820 SetLayerPropertiesForTesting(child_no_scale.get(),
4821 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204822 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294823 gfx::PointF(12.f, 12.f),
4824 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574825 false,
[email protected]35a99a12013-05-09 23:52:294826 true);
4827
4828 root->AddChild(parent);
4829
4830 parent->AddChild(child_scale);
4831 parent->AddChild(child_empty);
4832 parent->AddChild(child_no_scale);
4833
enne2097cab2014-09-25 20:16:314834 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284835 host->SetRootLayer(root);
4836
[email protected]989386c2013-07-18 21:37:234837 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:294838
4839 float device_scale_factor = 2.5f;
4840 float page_scale_factor = 1.f;
4841
[email protected]7aad55f2013-07-26 11:25:534842 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224843 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534844 inputs.device_scale_factor = device_scale_factor;
4845 inputs.page_scale_factor = page_scale_factor;
4846 inputs.page_scale_application_layer = root.get(),
4847 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:294848
4849 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4850 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4851 child_scale);
4852 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4853 child_empty);
4854 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4855
4856 // Since the transform scale does not affect contents scale, it should affect
4857 // the draw transform instead.
4858 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:264859 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294860 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:264861 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294862 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264863 child_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294864 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264865 child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294866 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264867 child_empty->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294868 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264869 child_empty->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294870 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264871 initial_parent_scale * initial_child_scale,
4872 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294873 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264874 initial_parent_scale * initial_child_scale,
4875 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294876}
4877
sohan.jyotie3bd6192014-10-13 07:13:594878TEST_F(LayerTreeHostCommonTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294879 MockContentLayerClient delegate;
4880 gfx::Transform identity_matrix;
4881
4882 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264883 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294884 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4885
4886 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264887 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294888 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4889
4890 scoped_refptr<Layer> root = Layer::Create();
4891 root->SetBounds(gfx::Size(100, 100));
4892
sohan.jyotie3bd6192014-10-13 07:13:594893 scoped_refptr<FakePictureLayer> parent =
4894 CreateDrawablePictureLayer(&delegate);
[email protected]35a99a12013-05-09 23:52:294895 SetLayerPropertiesForTesting(parent.get(),
4896 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204897 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294898 gfx::PointF(),
4899 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574900 false,
[email protected]35a99a12013-05-09 23:52:294901 true);
4902
sohan.jyotie3bd6192014-10-13 07:13:594903 scoped_refptr<FakePictureLayer> child_scale =
4904 CreateDrawablePictureLayer(&delegate);
[email protected]35a99a12013-05-09 23:52:294905 SetLayerPropertiesForTesting(child_scale.get(),
4906 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204907 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294908 gfx::PointF(2.f, 2.f),
4909 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574910 false,
[email protected]35a99a12013-05-09 23:52:294911 true);
4912
4913 root->AddChild(parent);
4914
[email protected]fb661802013-03-25 01:59:324915 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:214916
enne2097cab2014-09-25 20:16:314917 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284918 host->SetRootLayer(root);
4919
[email protected]fb661802013-03-25 01:59:324920 float device_scale_factor = 2.5f;
4921 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214922
[email protected]989386c2013-07-18 21:37:234923 {
4924 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534925 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224926 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534927 inputs.device_scale_factor = device_scale_factor;
4928 inputs.page_scale_factor = page_scale_factor;
4929 inputs.page_scale_application_layer = root.get();
4930 inputs.can_adjust_raster_scales = true;
4931 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:214932
sohan.jyotie3bd6192014-10-13 07:13:594933 // The ideal scale is able to go below 1.
4934 float expected_ideal_scale =
4935 device_scale_factor * page_scale_factor * initial_parent_scale;
4936 EXPECT_LT(expected_ideal_scale, 1.f);
4937 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
[email protected]11ec92972012-11-10 03:06:214938
sohan.jyotie3bd6192014-10-13 07:13:594939 expected_ideal_scale = device_scale_factor * page_scale_factor *
4940 initial_parent_scale * initial_child_scale;
4941 EXPECT_LT(expected_ideal_scale, 1.f);
4942 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
[email protected]989386c2013-07-18 21:37:234943 }
[email protected]11ec92972012-11-10 03:06:214944}
4945
[email protected]989386c2013-07-18 21:37:234946TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:324947 MockContentLayerClient delegate;
4948 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:444949
[email protected]fb661802013-03-25 01:59:324950 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264951 SkMScalar initial_parent_scale = 2.0;
[email protected]fb661802013-03-25 01:59:324952 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:444953
[email protected]fb661802013-03-25 01:59:324954 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264955 SkMScalar initial_child_scale = 3.0;
[email protected]fb661802013-03-25 01:59:324956 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:444957
[email protected]35a99a12013-05-09 23:52:294958 scoped_refptr<Layer> root = Layer::Create();
4959 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:444960
[email protected]fb661802013-03-25 01:59:324961 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4962 SetLayerPropertiesForTesting(parent.get(),
4963 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204964 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324965 gfx::PointF(),
4966 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574967 false,
[email protected]fb661802013-03-25 01:59:324968 true);
[email protected]518ee582012-10-24 18:29:444969
[email protected]fb661802013-03-25 01:59:324970 scoped_refptr<ContentLayer> surface_scale =
4971 CreateDrawableContentLayer(&delegate);
4972 SetLayerPropertiesForTesting(surface_scale.get(),
4973 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204974 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324975 gfx::PointF(2.f, 2.f),
4976 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574977 false,
[email protected]fb661802013-03-25 01:59:324978 true);
[email protected]518ee582012-10-24 18:29:444979
[email protected]fb661802013-03-25 01:59:324980 scoped_refptr<ContentLayer> surface_scale_child_scale =
4981 CreateDrawableContentLayer(&delegate);
4982 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
4983 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204984 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324985 gfx::PointF(),
4986 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574987 false,
[email protected]fb661802013-03-25 01:59:324988 true);
[email protected]518ee582012-10-24 18:29:444989
[email protected]fb661802013-03-25 01:59:324990 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
4991 CreateNoScaleDrawableContentLayer(&delegate);
4992 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
4993 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204994 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324995 gfx::PointF(),
4996 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574997 false,
[email protected]fb661802013-03-25 01:59:324998 true);
[email protected]518ee582012-10-24 18:29:444999
[email protected]fb661802013-03-25 01:59:325000 scoped_refptr<NoScaleContentLayer> surface_no_scale =
5001 CreateNoScaleDrawableContentLayer(&delegate);
5002 SetLayerPropertiesForTesting(surface_no_scale.get(),
5003 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205004 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325005 gfx::PointF(12.f, 12.f),
5006 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575007 false,
[email protected]fb661802013-03-25 01:59:325008 true);
[email protected]518ee582012-10-24 18:29:445009
[email protected]fb661802013-03-25 01:59:325010 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
5011 CreateDrawableContentLayer(&delegate);
5012 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
5013 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205014 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325015 gfx::PointF(),
5016 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575017 false,
[email protected]fb661802013-03-25 01:59:325018 true);
[email protected]518ee582012-10-24 18:29:445019
[email protected]fb661802013-03-25 01:59:325020 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
5021 CreateNoScaleDrawableContentLayer(&delegate);
5022 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
5023 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205024 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325025 gfx::PointF(),
5026 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575027 false,
[email protected]fb661802013-03-25 01:59:325028 true);
[email protected]518ee582012-10-24 18:29:445029
[email protected]35a99a12013-05-09 23:52:295030 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:445031
[email protected]fb661802013-03-25 01:59:325032 parent->AddChild(surface_scale);
5033 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:445034
[email protected]fb661802013-03-25 01:59:325035 surface_scale->SetForceRenderSurface(true);
5036 surface_scale->AddChild(surface_scale_child_scale);
5037 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:445038
[email protected]fb661802013-03-25 01:59:325039 surface_no_scale->SetForceRenderSurface(true);
5040 surface_no_scale->AddChild(surface_no_scale_child_scale);
5041 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:445042
enne2097cab2014-09-25 20:16:315043 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285044 host->SetRootLayer(root);
5045
[email protected]803f6b52013-09-12 00:51:265046 SkMScalar device_scale_factor = 5;
5047 SkMScalar page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:445048
[email protected]7aad55f2013-07-26 11:25:535049 RenderSurfaceLayerList render_surface_layer_list;
5050 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225051 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535052 inputs.device_scale_factor = device_scale_factor;
5053 inputs.page_scale_factor = page_scale_factor;
5054 inputs.page_scale_application_layer = root.get();
5055 inputs.can_adjust_raster_scales = true;
5056 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5057
5058 EXPECT_CONTENTS_SCALE_EQ(
5059 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:195060 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:535061 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:325062 surface_scale);
5063 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
5064 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:325065 device_scale_factor * page_scale_factor * initial_parent_scale *
5066 initial_child_scale * initial_child_scale,
5067 surface_scale_child_scale);
5068 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
5069 EXPECT_CONTENTS_SCALE_EQ(
5070 device_scale_factor * page_scale_factor * initial_parent_scale *
5071 initial_child_scale * initial_child_scale,
5072 surface_no_scale_child_scale);
5073 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:445074
[email protected]fb661802013-03-25 01:59:325075 // The parent is scaled up and shouldn't need to scale during draw.
[email protected]803f6b52013-09-12 00:51:265076 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
5077 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445078
[email protected]fb661802013-03-25 01:59:325079 // RenderSurfaces should always be 1:1 with their target.
5080 EXPECT_FLOAT_EQ(
5081 1.0,
[email protected]803f6b52013-09-12 00:51:265082 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325083 EXPECT_FLOAT_EQ(
5084 1.0,
[email protected]803f6b52013-09-12 00:51:265085 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445086
[email protected]fb661802013-03-25 01:59:325087 // The surface_scale can apply contents scale so the layer shouldn't need to
5088 // scale during draw.
[email protected]803f6b52013-09-12 00:51:265089 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
5090 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445091
[email protected]fb661802013-03-25 01:59:325092 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5093 // to scale during draw.
5094 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265095 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325096 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265097 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445098
[email protected]fb661802013-03-25 01:59:325099 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5100 // to be scaled during draw.
5101 EXPECT_FLOAT_EQ(
5102 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265103 initial_child_scale * initial_child_scale,
5104 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325105 EXPECT_FLOAT_EQ(
5106 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265107 initial_child_scale * initial_child_scale,
5108 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445109
[email protected]fb661802013-03-25 01:59:325110 // RenderSurfaces should always be 1:1 with their target.
5111 EXPECT_FLOAT_EQ(
5112 1.0,
[email protected]803f6b52013-09-12 00:51:265113 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325114 EXPECT_FLOAT_EQ(
5115 1.0,
[email protected]803f6b52013-09-12 00:51:265116 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445117
[email protected]fb661802013-03-25 01:59:325118 // The surface_no_scale layer can not apply contents scale, so it needs to be
5119 // scaled during draw.
5120 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:265121 initial_parent_scale * initial_child_scale,
5122 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325123 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:265124 initial_parent_scale * initial_child_scale,
5125 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445126
[email protected]fb661802013-03-25 01:59:325127 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5128 // to scale during draw.
5129 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265130 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325131 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265132 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445133
[email protected]fb661802013-03-25 01:59:325134 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5135 // to be scaled during draw.
5136 EXPECT_FLOAT_EQ(
5137 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265138 initial_child_scale * initial_child_scale,
5139 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325140 EXPECT_FLOAT_EQ(
5141 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265142 initial_child_scale * initial_child_scale,
5143 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295144}
[email protected]518ee582012-10-24 18:29:445145
sohan.jyotie3bd6192014-10-13 07:13:595146// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:235147TEST_F(LayerTreeHostCommonTest,
sohan.jyotie3bd6192014-10-13 07:13:595148 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
[email protected]35a99a12013-05-09 23:52:295149 MockContentLayerClient delegate;
5150 gfx::Transform identity_matrix;
5151
5152 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265153 SkMScalar initial_parent_scale = 2.0;
[email protected]35a99a12013-05-09 23:52:295154 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
5155
5156 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265157 SkMScalar initial_child_scale = 3.0;
[email protected]35a99a12013-05-09 23:52:295158 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
5159
5160 scoped_refptr<Layer> root = Layer::Create();
5161 root->SetBounds(gfx::Size(100, 100));
5162
5163 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
5164 SetLayerPropertiesForTesting(parent.get(),
5165 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205166 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295167 gfx::PointF(),
5168 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575169 false,
[email protected]35a99a12013-05-09 23:52:295170 true);
5171
5172 scoped_refptr<ContentLayer> surface_scale =
5173 CreateDrawableContentLayer(&delegate);
5174 SetLayerPropertiesForTesting(surface_scale.get(),
5175 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205176 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295177 gfx::PointF(2.f, 2.f),
5178 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575179 false,
[email protected]35a99a12013-05-09 23:52:295180 true);
5181
5182 scoped_refptr<ContentLayer> surface_scale_child_scale =
5183 CreateDrawableContentLayer(&delegate);
5184 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
5185 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205186 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295187 gfx::PointF(),
5188 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575189 false,
[email protected]35a99a12013-05-09 23:52:295190 true);
5191
5192 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
5193 CreateNoScaleDrawableContentLayer(&delegate);
5194 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
5195 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205196 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295197 gfx::PointF(),
5198 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575199 false,
[email protected]35a99a12013-05-09 23:52:295200 true);
5201
5202 scoped_refptr<NoScaleContentLayer> surface_no_scale =
5203 CreateNoScaleDrawableContentLayer(&delegate);
5204 SetLayerPropertiesForTesting(surface_no_scale.get(),
5205 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205206 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295207 gfx::PointF(12.f, 12.f),
5208 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575209 false,
[email protected]35a99a12013-05-09 23:52:295210 true);
5211
5212 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
5213 CreateDrawableContentLayer(&delegate);
5214 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
5215 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205216 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295217 gfx::PointF(),
5218 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575219 false,
[email protected]35a99a12013-05-09 23:52:295220 true);
5221
5222 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
5223 CreateNoScaleDrawableContentLayer(&delegate);
5224 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
5225 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205226 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295227 gfx::PointF(),
5228 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575229 false,
[email protected]35a99a12013-05-09 23:52:295230 true);
5231
5232 root->AddChild(parent);
5233
5234 parent->AddChild(surface_scale);
5235 parent->AddChild(surface_no_scale);
5236
5237 surface_scale->SetForceRenderSurface(true);
5238 surface_scale->AddChild(surface_scale_child_scale);
5239 surface_scale->AddChild(surface_scale_child_no_scale);
5240
5241 surface_no_scale->SetForceRenderSurface(true);
5242 surface_no_scale->AddChild(surface_no_scale_child_scale);
5243 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
5244
enne2097cab2014-09-25 20:16:315245 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285246 host->SetRootLayer(root);
5247
[email protected]989386c2013-07-18 21:37:235248 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:295249
[email protected]803f6b52013-09-12 00:51:265250 SkMScalar device_scale_factor = 5.0;
5251 SkMScalar page_scale_factor = 7.0;
[email protected]7aad55f2013-07-26 11:25:535252 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225253 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535254 inputs.device_scale_factor = device_scale_factor;
5255 inputs.page_scale_factor = page_scale_factor;
5256 inputs.page_scale_application_layer = root.get();
5257 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:295258
[email protected]35a99a12013-05-09 23:52:295259 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5260 parent);
5261 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5262 surface_scale);
5263 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
5264 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5265 surface_scale_child_scale);
5266 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
5267 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5268 surface_no_scale_child_scale);
5269 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
5270
5271 // The parent is scaled up during draw, since its contents are not scaled by
5272 // the transform hierarchy.
5273 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265274 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295275 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265276 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295277
hendrikwc493d2682015-01-26 23:35:115278 // The child surface is not scaled up during draw since its subtree is scaled
[email protected]35a99a12013-05-09 23:52:295279 // by the transform hierarchy.
5280 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115281 1.f,
[email protected]803f6b52013-09-12 00:51:265282 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295283 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115284 1.f,
[email protected]803f6b52013-09-12 00:51:265285 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295286
hendrikwc493d2682015-01-26 23:35:115287 // The surface_scale's RenderSurface is not scaled during draw, so the layer
5288 // needs to be scaled when drawing into its surface.
5289 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
5290 surface_scale->draw_transform().matrix().get(0, 0));
5291 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
5292 surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445293
hendrikwc493d2682015-01-26 23:35:115294 // The surface_scale_child_scale is not scaled when drawing into its surface,
5295 // since its content bounds are scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:325296 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115297 initial_child_scale * initial_child_scale * initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265298 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325299 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115300 initial_child_scale * initial_child_scale * initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265301 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445302
hendrikwc493d2682015-01-26 23:35:115303 // The surface_scale_child_no_scale is scaled by the device scale, page scale
5304 // and transform hierarchy.
[email protected]fb661802013-03-25 01:59:325305 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115306 device_scale_factor * page_scale_factor * initial_parent_scale *
5307 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265308 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295309 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115310 device_scale_factor * page_scale_factor * initial_parent_scale *
5311 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265312 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295313
hendrikwc493d2682015-01-26 23:35:115314 // The child surface is not scaled up during draw since its subtree is scaled
[email protected]35a99a12013-05-09 23:52:295315 // by the transform hierarchy.
5316 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115317 1.f,
[email protected]803f6b52013-09-12 00:51:265318 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325319 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115320 1.f,
[email protected]803f6b52013-09-12 00:51:265321 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445322
[email protected]35a99a12013-05-09 23:52:295323 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
5324 // be scaled by the device and page scale factors. Its surface is already
5325 // scaled by the transform hierarchy so those don't need to scale the layer's
5326 // drawing.
hendrikwc493d2682015-01-26 23:35:115327 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale *
5328 device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:265329 surface_no_scale->draw_transform().matrix().get(0, 0));
hendrikwc493d2682015-01-26 23:35:115330 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale *
5331 device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:265332 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295333
5334 // The surface_no_scale_child_scale has its contents scaled by the page and
5335 // device scale factors, but needs to be scaled by the transform hierarchy
5336 // when drawing.
[email protected]fb661802013-03-25 01:59:325337 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115338 initial_parent_scale * initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265339 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325340 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115341 initial_parent_scale * initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265342 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295343
hendrikwc493d2682015-01-26 23:35:115344 // The surface_no_scale_child_no_scale needs to be scaled by the device and
5345 // page scale factors and by any transform heirarchy below its target surface.
[email protected]35a99a12013-05-09 23:52:295346 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115347 device_scale_factor * page_scale_factor * initial_parent_scale *
5348 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265349 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295350 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115351 device_scale_factor * page_scale_factor * initial_parent_scale *
5352 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265353 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445354}
5355
sohan.jyotie3bd6192014-10-13 07:13:595356TEST_F(LayerTreeHostCommonTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:325357 MockContentLayerClient delegate;
5358 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:265359
[email protected]fb661802013-03-25 01:59:325360 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265361 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:325362 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:265363
[email protected]fb661802013-03-25 01:59:325364 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265365 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:325366 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:265367
[email protected]35a99a12013-05-09 23:52:295368 scoped_refptr<Layer> root = Layer::Create();
5369 root->SetBounds(gfx::Size(100, 100));
5370
sohan.jyotie3bd6192014-10-13 07:13:595371 scoped_refptr<FakePictureLayer> parent =
5372 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325373 SetLayerPropertiesForTesting(parent.get(),
5374 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205375 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325376 gfx::PointF(),
5377 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575378 false,
[email protected]fb661802013-03-25 01:59:325379 true);
[email protected]6a9cff92012-11-08 11:53:265380
sohan.jyotie3bd6192014-10-13 07:13:595381 scoped_refptr<FakePictureLayer> child_scale =
5382 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325383 SetLayerPropertiesForTesting(child_scale.get(),
5384 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205385 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325386 gfx::PointF(2.f, 2.f),
5387 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575388 false,
[email protected]fb661802013-03-25 01:59:325389 true);
[email protected]6a9cff92012-11-08 11:53:265390
[email protected]35a99a12013-05-09 23:52:295391 root->AddChild(parent);
5392
[email protected]fb661802013-03-25 01:59:325393 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:265394
enne2097cab2014-09-25 20:16:315395 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285396 host->SetRootLayer(root);
5397
[email protected]989386c2013-07-18 21:37:235398 {
5399 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535400 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225401 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535402 inputs.can_adjust_raster_scales = true;
5403 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:265404
sohan.jyotie3bd6192014-10-13 07:13:595405 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
5406 // Animating layers compute ideal scale in the same way as when
5407 // they are static.
5408 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
5409 child_scale);
[email protected]989386c2013-07-18 21:37:235410 }
[email protected]6a9cff92012-11-08 11:53:265411}
5412
sohan.jyotie3bd6192014-10-13 07:13:595413// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]7a5a9322014-02-25 12:54:575414TEST_F(LayerTreeHostCommonTest,
5415 ChangeInContentBoundsOrScaleTriggersPushProperties) {
5416 MockContentLayerClient delegate;
5417 scoped_refptr<Layer> root = Layer::Create();
5418 scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate);
5419 root->AddChild(child);
5420
enne2097cab2014-09-25 20:16:315421 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]7a5a9322014-02-25 12:54:575422 host->SetRootLayer(root);
5423
5424 gfx::Transform identity_matrix;
5425 SetLayerPropertiesForTesting(root.get(),
5426 identity_matrix,
[email protected]a2566412014-06-05 03:14:205427 gfx::Point3F(),
[email protected]7a5a9322014-02-25 12:54:575428 gfx::PointF(),
5429 gfx::Size(100, 100),
5430 true,
5431 false);
5432 SetLayerPropertiesForTesting(child.get(),
5433 identity_matrix,
[email protected]a2566412014-06-05 03:14:205434 gfx::Point3F(),
[email protected]7a5a9322014-02-25 12:54:575435 gfx::PointF(),
5436 gfx::Size(100, 100),
5437 true,
5438 false);
5439
5440 root->reset_needs_push_properties_for_testing();
5441 child->reset_needs_push_properties_for_testing();
5442
5443 // This will change both layers' content bounds.
5444 ExecuteCalculateDrawProperties(root.get());
5445 EXPECT_TRUE(root->needs_push_properties());
5446 EXPECT_TRUE(child->needs_push_properties());
5447
5448 root->reset_needs_push_properties_for_testing();
5449 child->reset_needs_push_properties_for_testing();
5450
5451 // This will change only the child layer's contents scale and content bounds,
5452 // since the root layer is not a ContentsScalingLayer.
5453 ExecuteCalculateDrawProperties(root.get(), 2.f);
5454 EXPECT_FALSE(root->needs_push_properties());
5455 EXPECT_TRUE(child->needs_push_properties());
5456
5457 root->reset_needs_push_properties_for_testing();
5458 child->reset_needs_push_properties_for_testing();
5459
5460 // This will not change either layer's contents scale or content bounds.
5461 ExecuteCalculateDrawProperties(root.get(), 2.f);
5462 EXPECT_FALSE(root->needs_push_properties());
5463 EXPECT_FALSE(child->needs_push_properties());
5464}
5465
[email protected]989386c2013-07-18 21:37:235466TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:325467 MockContentLayerClient delegate;
5468 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:265469
sohan.jyotie3bd6192014-10-13 07:13:595470 scoped_refptr<FakePictureLayer> parent =
5471 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325472 SetLayerPropertiesForTesting(parent.get(),
5473 identity_matrix,
[email protected]a2566412014-06-05 03:14:205474 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325475 gfx::PointF(),
5476 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:575477 false,
[email protected]fb661802013-03-25 01:59:325478 true);
[email protected]94f206c12012-08-25 00:09:145479
sohan.jyotie3bd6192014-10-13 07:13:595480 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325481 SetLayerPropertiesForTesting(child.get(),
5482 identity_matrix,
[email protected]a2566412014-06-05 03:14:205483 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325484 gfx::PointF(2.f, 2.f),
5485 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575486 false,
[email protected]fb661802013-03-25 01:59:325487 true);
[email protected]94f206c12012-08-25 00:09:145488
[email protected]fb661802013-03-25 01:59:325489 gfx::Transform replica_transform;
5490 replica_transform.Scale(1.0, -1.0);
sohan.jyotie3bd6192014-10-13 07:13:595491 scoped_refptr<FakePictureLayer> replica =
5492 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325493 SetLayerPropertiesForTesting(replica.get(),
5494 replica_transform,
[email protected]a2566412014-06-05 03:14:205495 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325496 gfx::PointF(2.f, 2.f),
5497 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575498 false,
[email protected]fb661802013-03-25 01:59:325499 true);
[email protected]94f206c12012-08-25 00:09:145500
[email protected]fb661802013-03-25 01:59:325501 // This layer should end up in the same surface as child, with the same draw
5502 // and screen space transforms.
sohan.jyotie3bd6192014-10-13 07:13:595503 scoped_refptr<FakePictureLayer> duplicate_child_non_owner =
5504 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325505 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
5506 identity_matrix,
[email protected]a2566412014-06-05 03:14:205507 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325508 gfx::PointF(),
5509 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575510 false,
[email protected]fb661802013-03-25 01:59:325511 true);
[email protected]94f206c12012-08-25 00:09:145512
[email protected]fb661802013-03-25 01:59:325513 parent->AddChild(child);
5514 child->AddChild(duplicate_child_non_owner);
5515 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:145516
enne2097cab2014-09-25 20:16:315517 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285518 host->SetRootLayer(parent);
5519
[email protected]989386c2013-07-18 21:37:235520 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145521
[email protected]fb661802013-03-25 01:59:325522 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:535523 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5524 parent.get(), parent->bounds(), &render_surface_layer_list);
5525 inputs.device_scale_factor = device_scale_factor;
5526 inputs.can_adjust_raster_scales = true;
5527 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145528
[email protected]fb661802013-03-25 01:59:325529 // We should have two render surfaces. The root's render surface and child's
5530 // render surface (it needs one because it has a replica layer).
5531 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:145532
[email protected]fb661802013-03-25 01:59:325533 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:595534 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:325535 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
5536 parent->screen_space_transform());
5537 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
5538 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:145539
[email protected]fb661802013-03-25 01:59:325540 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:595541 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:325542 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
5543 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:145544
[email protected]fb661802013-03-25 01:59:325545 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:595546 expected_screen_space_transform.Scale(device_scale_factor,
5547 device_scale_factor);
5548 expected_screen_space_transform.Translate(child->position().x(),
5549 child->position().y());
[email protected]fb661802013-03-25 01:59:325550 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
5551 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145552
[email protected]fb661802013-03-25 01:59:325553 gfx::Transform expected_duplicate_child_draw_transform =
5554 child->draw_transform();
5555 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
5556 duplicate_child_non_owner->draw_transform());
5557 EXPECT_TRANSFORMATION_MATRIX_EQ(
5558 child->screen_space_transform(),
5559 duplicate_child_non_owner->screen_space_transform());
hush6b614212014-12-04 22:37:325560 EXPECT_EQ(child->drawable_content_rect(),
5561 duplicate_child_non_owner->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:325562 EXPECT_EQ(child->content_bounds(),
5563 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:145564
[email protected]fb661802013-03-25 01:59:325565 gfx::Transform expected_render_surface_draw_transform;
5566 expected_render_surface_draw_transform.Translate(
5567 device_scale_factor * child->position().x(),
5568 device_scale_factor * child->position().y());
5569 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
5570 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145571
[email protected]fb661802013-03-25 01:59:325572 gfx::Transform expected_surface_draw_transform;
5573 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
5574 device_scale_factor * 2.f);
5575 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
5576 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145577
[email protected]fb661802013-03-25 01:59:325578 gfx::Transform expected_surface_screen_space_transform;
5579 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
5580 device_scale_factor * 2.f);
5581 EXPECT_TRANSFORMATION_MATRIX_EQ(
5582 expected_surface_screen_space_transform,
5583 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145584
[email protected]fb661802013-03-25 01:59:325585 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265586 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
5587 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
5588 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325589 EXPECT_TRANSFORMATION_MATRIX_EQ(
5590 expected_replica_draw_transform,
5591 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:145592
[email protected]fb661802013-03-25 01:59:325593 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265594 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
5595 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
5596 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325597 EXPECT_TRANSFORMATION_MATRIX_EQ(
5598 expected_replica_screen_space_transform,
5599 child->render_surface()->replica_screen_space_transform());
5600 EXPECT_TRANSFORMATION_MATRIX_EQ(
5601 expected_replica_screen_space_transform,
5602 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:475603}
5604
[email protected]989386c2013-07-18 21:37:235605TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325606 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
5607 MockContentLayerClient delegate;
5608 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:475609
sohan.jyotie3bd6192014-10-13 07:13:595610 scoped_refptr<FakePictureLayer> parent =
5611 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325612 SetLayerPropertiesForTesting(parent.get(),
5613 identity_matrix,
[email protected]a2566412014-06-05 03:14:205614 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325615 gfx::PointF(),
5616 gfx::Size(33, 31),
[email protected]56fffdd2014-02-11 19:50:575617 false,
[email protected]fb661802013-03-25 01:59:325618 true);
[email protected]904e9132012-11-01 00:12:475619
sohan.jyotie3bd6192014-10-13 07:13:595620 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325621 SetLayerPropertiesForTesting(child.get(),
5622 identity_matrix,
[email protected]a2566412014-06-05 03:14:205623 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325624 gfx::PointF(),
5625 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:575626 false,
[email protected]fb661802013-03-25 01:59:325627 true);
[email protected]904e9132012-11-01 00:12:475628
[email protected]fb661802013-03-25 01:59:325629 gfx::Transform replica_transform;
5630 replica_transform.Scale(1.0, -1.0);
sohan.jyotie3bd6192014-10-13 07:13:595631 scoped_refptr<FakePictureLayer> replica =
5632 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325633 SetLayerPropertiesForTesting(replica.get(),
5634 replica_transform,
[email protected]a2566412014-06-05 03:14:205635 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325636 gfx::PointF(),
5637 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:575638 false,
[email protected]fb661802013-03-25 01:59:325639 true);
[email protected]904e9132012-11-01 00:12:475640
[email protected]fb661802013-03-25 01:59:325641 parent->AddChild(child);
[email protected]fb661802013-03-25 01:59:325642 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:475643
enne2097cab2014-09-25 20:16:315644 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285645 host->SetRootLayer(parent);
5646
[email protected]873639e2013-07-24 19:56:315647 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:535648
5649 RenderSurfaceLayerList render_surface_layer_list;
5650 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5651 parent.get(), parent->bounds(), &render_surface_layer_list);
5652 inputs.device_scale_factor = device_scale_factor;
5653 inputs.can_adjust_raster_scales = true;
5654 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:475655
[email protected]fb661802013-03-25 01:59:325656 // We should have two render surfaces. The root's render surface and child's
5657 // render surface (it needs one because it has a replica layer).
5658 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:475659
[email protected]fb661802013-03-25 01:59:325660 gfx::Transform identity_transform;
[email protected]fb661802013-03-25 01:59:325661 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5662 child->render_surface()->draw_transform());
5663 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5664 child->render_surface()->draw_transform());
5665 EXPECT_TRANSFORMATION_MATRIX_EQ(
5666 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:475667
[email protected]fb661802013-03-25 01:59:325668 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265669 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325670 EXPECT_TRANSFORMATION_MATRIX_EQ(
5671 expected_replica_draw_transform,
5672 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:475673
[email protected]fb661802013-03-25 01:59:325674 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265675 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325676 EXPECT_TRANSFORMATION_MATRIX_EQ(
5677 expected_replica_screen_space_transform,
5678 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145679}
5680
[email protected]989386c2013-07-18 21:37:235681TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
[email protected]fb661802013-03-25 01:59:325682 scoped_refptr<Layer> root = Layer::Create();
5683 scoped_refptr<Layer> child = Layer::Create();
5684 scoped_refptr<Layer> grand_child = Layer::Create();
5685 scoped_refptr<Layer> mask_layer = Layer::Create();
5686 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:145687
[email protected]fb661802013-03-25 01:59:325688 grand_child->SetReplicaLayer(replica_layer.get());
5689 child->AddChild(grand_child.get());
5690 child->SetMaskLayer(mask_layer.get());
5691 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:145692
enne2097cab2014-09-25 20:16:315693 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285694 host->SetRootLayer(root);
5695
[email protected]fb661802013-03-25 01:59:325696 int nonexistent_id = -1;
Daniel Chengeea98042014-08-26 00:28:105697 EXPECT_EQ(root.get(),
[email protected]fb661802013-03-25 01:59:325698 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
Daniel Chengeea98042014-08-26 00:28:105699 EXPECT_EQ(child.get(),
[email protected]fb661802013-03-25 01:59:325700 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
5701 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105702 grand_child.get(),
[email protected]fb661802013-03-25 01:59:325703 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
5704 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105705 mask_layer.get(),
[email protected]fb661802013-03-25 01:59:325706 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
5707 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105708 replica_layer.get(),
[email protected]fb661802013-03-25 01:59:325709 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
5710 EXPECT_EQ(
5711 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:145712}
5713
[email protected]989386c2013-07-18 21:37:235714TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
[email protected]fb661802013-03-25 01:59:325715 scoped_refptr<Layer> root = Layer::Create();
5716 scoped_refptr<Layer> child = Layer::Create();
5717 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
5718 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:575719
[email protected]fb661802013-03-25 01:59:325720 const gfx::Transform identity_matrix;
5721 SetLayerPropertiesForTesting(root.get(),
5722 identity_matrix,
[email protected]a2566412014-06-05 03:14:205723 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325724 gfx::PointF(),
5725 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575726 true,
[email protected]fb661802013-03-25 01:59:325727 false);
5728 SetLayerPropertiesForTesting(child.get(),
5729 identity_matrix,
[email protected]a2566412014-06-05 03:14:205730 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325731 gfx::PointF(),
5732 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575733 true,
[email protected]fb661802013-03-25 01:59:325734 false);
5735 SetLayerPropertiesForTesting(grand_child.get(),
5736 identity_matrix,
[email protected]a2566412014-06-05 03:14:205737 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325738 gfx::PointF(),
5739 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575740 true,
[email protected]fb661802013-03-25 01:59:325741 false);
[email protected]498ec6e0e2012-11-30 18:24:575742
[email protected]fb661802013-03-25 01:59:325743 root->AddChild(child);
5744 child->AddChild(grand_child);
5745 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:575746
enne2097cab2014-09-25 20:16:315747 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285748 host->SetRootLayer(root);
5749
[email protected]fb661802013-03-25 01:59:325750 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:575751
[email protected]fb661802013-03-25 01:59:325752 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:575753}
5754
[email protected]989386c2013-07-18 21:37:235755TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:165756 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455757 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:475758 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]f90fc412013-03-30 20:13:165759 host_impl.CreatePendingTree();
5760 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5761
5762 const gfx::Transform identity_matrix;
awoloszyne83f28c2014-12-22 15:40:005763 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5764 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]f90fc412013-03-30 20:13:165765 false);
5766 root->SetDrawsContent(true);
5767
5768 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005769 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5770 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]f90fc412013-03-30 20:13:165771 false);
5772 child->SetDrawsContent(true);
5773 child->SetOpacity(0.0f);
5774
5775 // Add opacity animation.
5776 AddOpacityTransitionToController(
5777 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
5778
5779 root->AddChild(child.Pass());
awoloszyne83f28c2014-12-22 15:40:005780 root->SetHasRenderSurface(true);
[email protected]f90fc412013-03-30 20:13:165781
[email protected]c0ae06c12013-06-24 18:32:195782 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535783 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225784 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535785 inputs.can_adjust_raster_scales = true;
5786 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:165787
5788 // We should have one render surface and two layers. The child
5789 // layer should be included even though it is transparent.
5790 ASSERT_EQ(1u, render_surface_layer_list.size());
5791 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5792}
5793
danakj3f76ace2014-11-18 16:56:005794using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
[email protected]989386c2013-07-18 21:37:235795class LCDTextTest
5796 : public LayerTreeHostCommonTestBase,
5797 public testing::TestWithParam<LCDTextTestParam> {
enneaf5bda32015-02-19 01:27:365798 public:
5799 LCDTextTest()
reveman34b7a1522015-03-23 20:27:475800 : host_impl_(&proxy_, &shared_bitmap_manager_, &task_graph_runner_),
enneaf5bda32015-02-19 01:27:365801 root_(nullptr),
5802 child_(nullptr),
5803 grand_child_(nullptr) {}
5804
[email protected]fb661802013-03-25 01:59:325805 protected:
dcheng93a52eb2014-12-23 02:14:235806 void SetUp() override {
[email protected]fb661802013-03-25 01:59:325807 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
danakj3f76ace2014-11-18 16:56:005808 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
[email protected]10aabcc32012-12-13 09:18:595809
enneaf5bda32015-02-19 01:27:365810 scoped_ptr<LayerImpl> root_ptr =
5811 LayerImpl::Create(host_impl_.active_tree(), 1);
5812 scoped_ptr<LayerImpl> child_ptr =
5813 LayerImpl::Create(host_impl_.active_tree(), 2);
5814 scoped_ptr<LayerImpl> grand_child_ptr =
5815 LayerImpl::Create(host_impl_.active_tree(), 3);
5816
5817 // Stash raw pointers to look at later.
5818 root_ = root_ptr.get();
5819 child_ = child_ptr.get();
5820 grand_child_ = grand_child_ptr.get();
5821
5822 child_->AddChild(grand_child_ptr.Pass());
5823 root_->AddChild(child_ptr.Pass());
5824 host_impl_.active_tree()->SetRootLayer(root_ptr.Pass());
[email protected]10aabcc32012-12-13 09:18:595825
fmalita51b5e202014-11-18 20:11:505826 root_->SetContentsOpaque(true);
5827 child_->SetContentsOpaque(true);
5828 grand_child_->SetContentsOpaque(true);
5829
[email protected]fb661802013-03-25 01:59:325830 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365831 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
5832 gfx::PointF(), gfx::Size(1, 1), true, false,
5833 true);
5834 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
5835 gfx::PointF(), gfx::Size(1, 1), true, false,
5836 std::tr1::get<2>(GetParam()));
5837 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
5838 gfx::PointF(), gfx::Size(1, 1), true, false,
[email protected]fb661802013-03-25 01:59:325839 false);
[email protected]fb661802013-03-25 01:59:325840 }
[email protected]10aabcc32012-12-13 09:18:595841
[email protected]fb661802013-03-25 01:59:325842 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005843 bool layers_always_allowed_lcd_text_;
enneaf5bda32015-02-19 01:27:365844
5845 FakeImplProxy proxy_;
5846 TestSharedBitmapManager shared_bitmap_manager_;
reveman34b7a1522015-03-23 20:27:475847 TestTaskGraphRunner task_graph_runner_;
enneaf5bda32015-02-19 01:27:365848 FakeLayerTreeHostImpl host_impl_;
5849
5850 LayerImpl* root_;
5851 LayerImpl* child_;
5852 LayerImpl* grand_child_;
[email protected]10aabcc32012-12-13 09:18:595853};
5854
[email protected]fb661802013-03-25 01:59:325855TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005856 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5857 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5858
[email protected]fb661802013-03-25 01:59:325859 // Case 1: Identity transform.
5860 gfx::Transform identity_matrix;
enneaf5bda32015-02-19 01:27:365861 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005862 layers_always_allowed_lcd_text_);
5863 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5864 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5865 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595866
[email protected]fb661802013-03-25 01:59:325867 // Case 2: Integral translation.
5868 gfx::Transform integral_translation;
5869 integral_translation.Translate(1.0, 2.0);
5870 child_->SetTransform(integral_translation);
enneaf5bda32015-02-19 01:27:365871 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005872 layers_always_allowed_lcd_text_);
5873 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5874 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5875 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595876
[email protected]fb661802013-03-25 01:59:325877 // Case 3: Non-integral translation.
5878 gfx::Transform non_integral_translation;
5879 non_integral_translation.Translate(1.5, 2.5);
5880 child_->SetTransform(non_integral_translation);
enneaf5bda32015-02-19 01:27:365881 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005882 layers_always_allowed_lcd_text_);
5883 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5884 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5885 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595886
[email protected]fb661802013-03-25 01:59:325887 // Case 4: Rotation.
5888 gfx::Transform rotation;
5889 rotation.Rotate(10.0);
5890 child_->SetTransform(rotation);
enneaf5bda32015-02-19 01:27:365891 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005892 layers_always_allowed_lcd_text_);
5893 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5894 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5895 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595896
[email protected]fb661802013-03-25 01:59:325897 // Case 5: Scale.
5898 gfx::Transform scale;
5899 scale.Scale(2.0, 2.0);
5900 child_->SetTransform(scale);
enneaf5bda32015-02-19 01:27:365901 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005902 layers_always_allowed_lcd_text_);
5903 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5904 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5905 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595906
[email protected]fb661802013-03-25 01:59:325907 // Case 6: Skew.
5908 gfx::Transform skew;
5909 skew.SkewX(10.0);
5910 child_->SetTransform(skew);
enneaf5bda32015-02-19 01:27:365911 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005912 layers_always_allowed_lcd_text_);
5913 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5914 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5915 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595916
[email protected]fb661802013-03-25 01:59:325917 // Case 7: Translucent.
5918 child_->SetTransform(identity_matrix);
5919 child_->SetOpacity(0.5f);
enneaf5bda32015-02-19 01:27:365920 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005921 layers_always_allowed_lcd_text_);
5922 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5923 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5924 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595925
[email protected]fb661802013-03-25 01:59:325926 // Case 8: Sanity check: restore transform and opacity.
5927 child_->SetTransform(identity_matrix);
5928 child_->SetOpacity(1.f);
enneaf5bda32015-02-19 01:27:365929 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005930 layers_always_allowed_lcd_text_);
5931 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5932 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5933 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalita51b5e202014-11-18 20:11:505934
5935 // Case 9: Non-opaque content.
5936 child_->SetContentsOpaque(false);
enneaf5bda32015-02-19 01:27:365937 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505938 layers_always_allowed_lcd_text_);
5939 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5940 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5941 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5942
5943 // Case 10: Sanity check: restore content opaqueness.
5944 child_->SetContentsOpaque(true);
enneaf5bda32015-02-19 01:27:365945 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
fmalita51b5e202014-11-18 20:11:505946 layers_always_allowed_lcd_text_);
5947 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5948 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5949 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595950}
5951
[email protected]fd9a3b6d2013-08-03 00:46:175952TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005953 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5954
[email protected]fb661802013-03-25 01:59:325955 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
enneaf5bda32015-02-19 01:27:365956 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005957 layers_always_allowed_lcd_text_);
5958 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5959 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5960 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595961
[email protected]fb661802013-03-25 01:59:325962 // Add opacity animation.
5963 child_->SetOpacity(0.9f);
5964 AddOpacityTransitionToController(
5965 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:595966
enneaf5bda32015-02-19 01:27:365967 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
danakj3f76ace2014-11-18 16:56:005968 layers_always_allowed_lcd_text_);
[email protected]fb661802013-03-25 01:59:325969 // Text AA should not be adjusted while animation is active.
5970 // Make sure LCD text AA setting remains unchanged.
danakj3f76ace2014-11-18 16:56:005971 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5972 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5973 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595974}
5975
5976INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5977 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005978 testing::Combine(testing::Bool(),
5979 testing::Bool(),
5980 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595981
[email protected]989386c2013-07-18 21:37:235982TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:195983 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455984 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:475985 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]c0ae06c12013-06-24 18:32:195986 host_impl.CreatePendingTree();
5987 const gfx::Transform identity_matrix;
5988
5989 scoped_refptr<Layer> root = Layer::Create();
5990 SetLayerPropertiesForTesting(root.get(),
5991 identity_matrix,
[email protected]a2566412014-06-05 03:14:205992 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195993 gfx::PointF(),
5994 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575995 true,
[email protected]c0ae06c12013-06-24 18:32:195996 false);
5997 root->SetIsDrawable(true);
5998
5999 scoped_refptr<Layer> child = Layer::Create();
6000 SetLayerPropertiesForTesting(child.get(),
6001 identity_matrix,
[email protected]a2566412014-06-05 03:14:206002 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196003 gfx::PointF(),
6004 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576005 true,
[email protected]c0ae06c12013-06-24 18:32:196006 false);
6007 child->SetIsDrawable(true);
6008
6009 scoped_refptr<Layer> grand_child = Layer::Create();
6010 SetLayerPropertiesForTesting(grand_child.get(),
6011 identity_matrix,
[email protected]a2566412014-06-05 03:14:206012 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196013 gfx::PointF(),
6014 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576015 true,
[email protected]c0ae06c12013-06-24 18:32:196016 false);
6017 grand_child->SetIsDrawable(true);
6018 grand_child->SetHideLayerAndSubtree(true);
6019
6020 child->AddChild(grand_child);
6021 root->AddChild(child);
6022
enne2097cab2014-09-25 20:16:316023 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286024 host->SetRootLayer(root);
6025
[email protected]989386c2013-07-18 21:37:236026 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536027 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226028 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536029 inputs.can_adjust_raster_scales = true;
6030 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196031
6032 // We should have one render surface and two layers. The grand child has
6033 // hidden itself.
6034 ASSERT_EQ(1u, render_surface_layer_list.size());
6035 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236036 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
6037 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:196038}
6039
[email protected]989386c2013-07-18 21:37:236040TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:196041 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456042 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476043 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]c0ae06c12013-06-24 18:32:196044 host_impl.CreatePendingTree();
6045 const gfx::Transform identity_matrix;
6046
6047 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:006048 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6049 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]c0ae06c12013-06-24 18:32:196050 false);
6051 root->SetDrawsContent(true);
6052
6053 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:006054 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
6055 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:196056 false);
6057 child->SetDrawsContent(true);
6058
6059 scoped_ptr<LayerImpl> grand_child =
6060 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:006061 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
6062 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6063 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:196064 grand_child->SetDrawsContent(true);
6065 grand_child->SetHideLayerAndSubtree(true);
6066
6067 child->AddChild(grand_child.Pass());
6068 root->AddChild(child.Pass());
awoloszyne83f28c2014-12-22 15:40:006069 root->SetHasRenderSurface(true);
[email protected]c0ae06c12013-06-24 18:32:196070
6071 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536072 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226073 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536074 inputs.can_adjust_raster_scales = true;
6075 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196076
6077 // We should have one render surface and two layers. The grand child has
6078 // hidden itself.
6079 ASSERT_EQ(1u, render_surface_layer_list.size());
6080 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236081 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
6082 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:196083}
6084
[email protected]989386c2013-07-18 21:37:236085TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:196086 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456087 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476088 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]c0ae06c12013-06-24 18:32:196089 host_impl.CreatePendingTree();
6090 const gfx::Transform identity_matrix;
6091
6092 scoped_refptr<Layer> root = Layer::Create();
6093 SetLayerPropertiesForTesting(root.get(),
6094 identity_matrix,
[email protected]a2566412014-06-05 03:14:206095 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196096 gfx::PointF(),
6097 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576098 true,
[email protected]c0ae06c12013-06-24 18:32:196099 false);
6100 root->SetIsDrawable(true);
6101
6102 scoped_refptr<Layer> child = Layer::Create();
6103 SetLayerPropertiesForTesting(child.get(),
6104 identity_matrix,
[email protected]a2566412014-06-05 03:14:206105 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196106 gfx::PointF(),
6107 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576108 true,
[email protected]c0ae06c12013-06-24 18:32:196109 false);
6110 child->SetIsDrawable(true);
6111 child->SetHideLayerAndSubtree(true);
6112
6113 scoped_refptr<Layer> grand_child = Layer::Create();
6114 SetLayerPropertiesForTesting(grand_child.get(),
6115 identity_matrix,
[email protected]a2566412014-06-05 03:14:206116 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:196117 gfx::PointF(),
6118 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576119 true,
[email protected]c0ae06c12013-06-24 18:32:196120 false);
6121 grand_child->SetIsDrawable(true);
6122
6123 child->AddChild(grand_child);
6124 root->AddChild(child);
6125
enne2097cab2014-09-25 20:16:316126 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286127 host->SetRootLayer(root);
6128
[email protected]989386c2013-07-18 21:37:236129 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536130 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226131 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536132 inputs.can_adjust_raster_scales = true;
6133 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196134
6135 // We should have one render surface and one layers. The child has
6136 // hidden itself and the grand child.
6137 ASSERT_EQ(1u, render_surface_layer_list.size());
6138 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236139 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:196140}
6141
[email protected]989386c2013-07-18 21:37:236142TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[email protected]c0ae06c12013-06-24 18:32:196143 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456144 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476145 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]c0ae06c12013-06-24 18:32:196146 host_impl.CreatePendingTree();
6147 const gfx::Transform identity_matrix;
6148
6149 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:006150 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6151 gfx::PointF(), gfx::Size(50, 50), true, false,
6152 true);
[email protected]c0ae06c12013-06-24 18:32:196153 root->SetDrawsContent(true);
6154
6155 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:006156 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
6157 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:196158 false);
6159 child->SetDrawsContent(true);
6160 child->SetHideLayerAndSubtree(true);
6161
6162 scoped_ptr<LayerImpl> grand_child =
6163 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:006164 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
6165 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6166 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:196167 grand_child->SetDrawsContent(true);
6168
6169 child->AddChild(grand_child.Pass());
6170 root->AddChild(child.Pass());
6171
6172 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536173 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226174 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536175 inputs.can_adjust_raster_scales = true;
6176 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196177
6178 // We should have one render surface and one layers. The child has
6179 // hidden itself and the grand child.
6180 ASSERT_EQ(1u, render_surface_layer_list.size());
6181 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236182 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:196183}
6184
[email protected]30fe19ff2013-07-04 00:54:456185void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
6186
[email protected]989386c2013-07-18 21:37:236187TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:456188 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456189 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476190 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]30fe19ff2013-07-04 00:54:456191 host_impl.CreatePendingTree();
6192 const gfx::Transform identity_matrix;
6193
6194 scoped_refptr<Layer> root = Layer::Create();
6195 SetLayerPropertiesForTesting(root.get(),
6196 identity_matrix,
[email protected]a2566412014-06-05 03:14:206197 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456198 gfx::PointF(),
6199 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576200 true,
[email protected]30fe19ff2013-07-04 00:54:456201 false);
6202 root->SetIsDrawable(true);
6203
6204 scoped_refptr<Layer> copy_grand_parent = Layer::Create();
6205 SetLayerPropertiesForTesting(copy_grand_parent.get(),
6206 identity_matrix,
[email protected]a2566412014-06-05 03:14:206207 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456208 gfx::PointF(),
6209 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576210 true,
[email protected]30fe19ff2013-07-04 00:54:456211 false);
6212 copy_grand_parent->SetIsDrawable(true);
6213
6214 scoped_refptr<Layer> copy_parent = Layer::Create();
6215 SetLayerPropertiesForTesting(copy_parent.get(),
6216 identity_matrix,
[email protected]a2566412014-06-05 03:14:206217 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456218 gfx::PointF(),
6219 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576220 true,
[email protected]30fe19ff2013-07-04 00:54:456221 false);
6222 copy_parent->SetIsDrawable(true);
6223 copy_parent->SetForceRenderSurface(true);
6224
6225 scoped_refptr<Layer> copy_layer = Layer::Create();
6226 SetLayerPropertiesForTesting(copy_layer.get(),
6227 identity_matrix,
[email protected]a2566412014-06-05 03:14:206228 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456229 gfx::PointF(),
6230 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576231 true,
[email protected]30fe19ff2013-07-04 00:54:456232 false);
6233 copy_layer->SetIsDrawable(true);
6234
6235 scoped_refptr<Layer> copy_child = Layer::Create();
6236 SetLayerPropertiesForTesting(copy_child.get(),
6237 identity_matrix,
[email protected]a2566412014-06-05 03:14:206238 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456239 gfx::PointF(),
6240 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576241 true,
[email protected]30fe19ff2013-07-04 00:54:456242 false);
6243 copy_child->SetIsDrawable(true);
6244
[email protected]ac020122013-07-12 23:45:536245 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
6246 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
6247 identity_matrix,
[email protected]a2566412014-06-05 03:14:206248 gfx::Point3F(),
[email protected]ac020122013-07-12 23:45:536249 gfx::PointF(),
6250 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576251 true,
[email protected]ac020122013-07-12 23:45:536252 false);
6253 copy_grand_parent_sibling_before->SetIsDrawable(true);
6254
6255 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
6256 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
6257 identity_matrix,
[email protected]a2566412014-06-05 03:14:206258 gfx::Point3F(),
[email protected]ac020122013-07-12 23:45:536259 gfx::PointF(),
6260 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576261 true,
[email protected]ac020122013-07-12 23:45:536262 false);
6263 copy_grand_parent_sibling_after->SetIsDrawable(true);
6264
[email protected]30fe19ff2013-07-04 00:54:456265 copy_layer->AddChild(copy_child);
6266 copy_parent->AddChild(copy_layer);
6267 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:536268 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:456269 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:536270 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:456271
enne2097cab2014-09-25 20:16:316272 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286273 host->SetRootLayer(root);
6274
[email protected]30fe19ff2013-07-04 00:54:456275 // Hide the copy_grand_parent and its subtree. But make a copy request in that
6276 // hidden subtree on copy_layer.
6277 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:536278 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
6279 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:456280 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6281 base::Bind(&EmptyCopyOutputCallback)));
6282 EXPECT_TRUE(copy_layer->HasCopyRequest());
6283
[email protected]989386c2013-07-18 21:37:236284 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536285 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226286 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536287 inputs.can_adjust_raster_scales = true;
6288 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:456289
[email protected]ac020122013-07-12 23:45:536290 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
6291 EXPECT_TRUE(copy_grand_parent->draw_properties().
6292 layer_or_descendant_has_copy_request);
6293 EXPECT_TRUE(copy_parent->draw_properties().
6294 layer_or_descendant_has_copy_request);
6295 EXPECT_TRUE(copy_layer->draw_properties().
6296 layer_or_descendant_has_copy_request);
6297 EXPECT_FALSE(copy_child->draw_properties().
6298 layer_or_descendant_has_copy_request);
6299 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
6300 layer_or_descendant_has_copy_request);
6301 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
6302 layer_or_descendant_has_copy_request);
6303
[email protected]30fe19ff2013-07-04 00:54:456304 // We should have three render surfaces, one for the root, one for the parent
6305 // since it owns a surface, and one for the copy_layer.
6306 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:236307 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
6308 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
6309 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:456310
6311 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:536312 // copy_grand_parent is hidden along with its siblings, but the copy_parent
6313 // will appear since something in its subtree needs to be drawn for a copy
6314 // request.
[email protected]30fe19ff2013-07-04 00:54:456315 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236316 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
6317 EXPECT_EQ(copy_parent->id(),
6318 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:456319
[email protected]7392c7b2014-02-07 08:28:286320 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:456321 // appear in its list, since it needs to be drawn for the copy request.
6322 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
6323 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:236324 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456325
6326 // The copy_layer's render surface should have two contributing layers.
6327 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
6328 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:236329 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456330 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:236331 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:456332}
6333
[email protected]989386c2013-07-18 21:37:236334TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:456335 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456336 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476337 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]30fe19ff2013-07-04 00:54:456338 host_impl.CreatePendingTree();
6339 const gfx::Transform identity_matrix;
6340
6341 scoped_refptr<Layer> root = Layer::Create();
6342 SetLayerPropertiesForTesting(root.get(),
6343 identity_matrix,
[email protected]a2566412014-06-05 03:14:206344 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456345 gfx::PointF(),
6346 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576347 true,
[email protected]30fe19ff2013-07-04 00:54:456348 false);
6349 root->SetIsDrawable(true);
6350
6351 scoped_refptr<Layer> copy_parent = Layer::Create();
6352 SetLayerPropertiesForTesting(copy_parent.get(),
6353 identity_matrix,
[email protected]a2566412014-06-05 03:14:206354 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456355 gfx::PointF(),
6356 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576357 true,
[email protected]30fe19ff2013-07-04 00:54:456358 false);
6359 copy_parent->SetIsDrawable(true);
6360 copy_parent->SetMasksToBounds(true);
6361
6362 scoped_refptr<Layer> copy_layer = Layer::Create();
6363 SetLayerPropertiesForTesting(copy_layer.get(),
6364 identity_matrix,
[email protected]a2566412014-06-05 03:14:206365 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456366 gfx::PointF(),
6367 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576368 true,
[email protected]30fe19ff2013-07-04 00:54:456369 false);
6370 copy_layer->SetIsDrawable(true);
6371
6372 scoped_refptr<Layer> copy_child = Layer::Create();
6373 SetLayerPropertiesForTesting(copy_child.get(),
6374 identity_matrix,
[email protected]a2566412014-06-05 03:14:206375 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456376 gfx::PointF(),
6377 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576378 true,
[email protected]30fe19ff2013-07-04 00:54:456379 false);
6380 copy_child->SetIsDrawable(true);
6381
6382 copy_layer->AddChild(copy_child);
6383 copy_parent->AddChild(copy_layer);
6384 root->AddChild(copy_parent);
6385
enne2097cab2014-09-25 20:16:316386 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286387 host->SetRootLayer(root);
6388
[email protected]30fe19ff2013-07-04 00:54:456389 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6390 base::Bind(&EmptyCopyOutputCallback)));
6391 EXPECT_TRUE(copy_layer->HasCopyRequest());
6392
[email protected]989386c2013-07-18 21:37:236393 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536394 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226395 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536396 inputs.can_adjust_raster_scales = true;
6397 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:456398
6399 // We should have one render surface, as the others are clipped out.
6400 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:236401 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456402
6403 // The root render surface should only have 1 contributing layer, since the
6404 // other layers are empty/clipped away.
6405 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236406 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456407}
6408
[email protected]11a07b102013-07-24 17:33:196409TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
6410 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456411 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:476412 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]11a07b102013-07-24 17:33:196413 host_impl.CreatePendingTree();
6414 const gfx::Transform identity_matrix;
6415
6416 scoped_refptr<Layer> root = Layer::Create();
6417 SetLayerPropertiesForTesting(root.get(),
6418 identity_matrix,
[email protected]a2566412014-06-05 03:14:206419 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196420 gfx::PointF(),
6421 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576422 true,
[email protected]11a07b102013-07-24 17:33:196423 false);
6424 root->SetIsDrawable(true);
6425
6426 // The surface is moved slightly outside of the viewport.
6427 scoped_refptr<Layer> surface = Layer::Create();
6428 SetLayerPropertiesForTesting(surface.get(),
6429 identity_matrix,
[email protected]a2566412014-06-05 03:14:206430 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196431 gfx::PointF(-10, -20),
6432 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576433 true,
[email protected]11a07b102013-07-24 17:33:196434 false);
6435 surface->SetForceRenderSurface(true);
6436
6437 scoped_refptr<Layer> surface_child = Layer::Create();
6438 SetLayerPropertiesForTesting(surface_child.get(),
6439 identity_matrix,
[email protected]a2566412014-06-05 03:14:206440 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196441 gfx::PointF(),
6442 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576443 true,
[email protected]11a07b102013-07-24 17:33:196444 false);
6445 surface_child->SetIsDrawable(true);
6446
6447 surface->AddChild(surface_child);
6448 root->AddChild(surface);
6449
enne2097cab2014-09-25 20:16:316450 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286451 host->SetRootLayer(root);
6452
[email protected]11a07b102013-07-24 17:33:196453 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536454 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226455 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536456 inputs.can_adjust_raster_scales = true;
6457 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:196458
6459 // The visible_content_rect for the |surface_child| should not be clipped by
6460 // the viewport.
6461 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
6462 surface_child->visible_content_rect().ToString());
6463}
6464
[email protected]420fdf6e2013-08-26 20:36:386465TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
6466 // Ensure that a transform between the layer and its render surface is not a
6467 // problem. Constructs the following layer tree.
6468 //
6469 // root (a render surface)
6470 // + render_surface
6471 // + clip_parent (scaled)
6472 // + intervening_clipping_layer
6473 // + clip_child
6474 //
6475 // The render surface should be resized correctly and the clip child should
6476 // inherit the right clip rect.
6477 scoped_refptr<Layer> root = Layer::Create();
6478 scoped_refptr<Layer> render_surface = Layer::Create();
6479 scoped_refptr<Layer> clip_parent = Layer::Create();
6480 scoped_refptr<Layer> intervening = Layer::Create();
6481 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6482 make_scoped_refptr(new LayerWithForcedDrawsContent);
6483
6484 root->AddChild(render_surface);
6485 render_surface->AddChild(clip_parent);
6486 clip_parent->AddChild(intervening);
6487 intervening->AddChild(clip_child);
6488
6489 clip_child->SetClipParent(clip_parent.get());
6490
6491 intervening->SetMasksToBounds(true);
6492 clip_parent->SetMasksToBounds(true);
6493
6494 render_surface->SetForceRenderSurface(true);
6495
6496 gfx::Transform scale_transform;
6497 scale_transform.Scale(2, 2);
6498
6499 gfx::Transform identity_transform;
6500
6501 SetLayerPropertiesForTesting(root.get(),
6502 identity_transform,
[email protected]a2566412014-06-05 03:14:206503 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386504 gfx::PointF(),
6505 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576506 true,
[email protected]420fdf6e2013-08-26 20:36:386507 false);
6508 SetLayerPropertiesForTesting(render_surface.get(),
6509 identity_transform,
[email protected]a2566412014-06-05 03:14:206510 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386511 gfx::PointF(),
6512 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576513 true,
[email protected]420fdf6e2013-08-26 20:36:386514 false);
6515 SetLayerPropertiesForTesting(clip_parent.get(),
6516 scale_transform,
[email protected]a2566412014-06-05 03:14:206517 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386518 gfx::PointF(1.f, 1.f),
6519 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576520 true,
[email protected]420fdf6e2013-08-26 20:36:386521 false);
6522 SetLayerPropertiesForTesting(intervening.get(),
6523 identity_transform,
[email protected]a2566412014-06-05 03:14:206524 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386525 gfx::PointF(1.f, 1.f),
6526 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576527 true,
[email protected]420fdf6e2013-08-26 20:36:386528 false);
6529 SetLayerPropertiesForTesting(clip_child.get(),
6530 identity_transform,
[email protected]a2566412014-06-05 03:14:206531 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386532 gfx::PointF(1.f, 1.f),
6533 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576534 true,
[email protected]420fdf6e2013-08-26 20:36:386535 false);
6536
enne2097cab2014-09-25 20:16:316537 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386538 host->SetRootLayer(root);
6539
6540 ExecuteCalculateDrawProperties(root.get());
6541
6542 ASSERT_TRUE(root->render_surface());
6543 ASSERT_TRUE(render_surface->render_surface());
6544
6545 // Ensure that we've inherited our clip parent's clip and weren't affected
6546 // by the intervening clip layer.
6547 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
6548 clip_parent->clip_rect().ToString());
6549 ASSERT_EQ(clip_parent->clip_rect().ToString(),
6550 clip_child->clip_rect().ToString());
6551 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
6552 intervening->clip_rect().ToString());
6553
6554 // Ensure that the render surface reports a content rect that has been grown
6555 // to accomodate for the clip child.
6556 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
6557 render_surface->render_surface()->content_rect().ToString());
6558
6559 // The above check implies the two below, but they nicely demonstrate that
6560 // we've grown, despite the intervening layer's clip.
6561 ASSERT_TRUE(clip_parent->clip_rect().Contains(
6562 render_surface->render_surface()->content_rect()));
6563 ASSERT_FALSE(intervening->clip_rect().Contains(
6564 render_surface->render_surface()->content_rect()));
6565}
6566
6567TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
6568 // Ensure that intervening render surfaces are not a problem in the basic
6569 // case. In the following tree, both render surfaces should be resized to
6570 // accomodate for the clip child, despite an intervening clip.
6571 //
6572 // root (a render surface)
6573 // + clip_parent (masks to bounds)
6574 // + render_surface1 (sets opacity)
6575 // + intervening (masks to bounds)
6576 // + render_surface2 (also sets opacity)
6577 // + clip_child
6578 //
6579 scoped_refptr<Layer> root = Layer::Create();
6580 scoped_refptr<Layer> clip_parent = Layer::Create();
6581 scoped_refptr<Layer> render_surface1 = Layer::Create();
6582 scoped_refptr<Layer> intervening = Layer::Create();
6583 scoped_refptr<Layer> render_surface2 = Layer::Create();
6584 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6585 make_scoped_refptr(new LayerWithForcedDrawsContent);
6586
6587 root->AddChild(clip_parent);
6588 clip_parent->AddChild(render_surface1);
6589 render_surface1->AddChild(intervening);
6590 intervening->AddChild(render_surface2);
6591 render_surface2->AddChild(clip_child);
6592
6593 clip_child->SetClipParent(clip_parent.get());
6594
6595 intervening->SetMasksToBounds(true);
6596 clip_parent->SetMasksToBounds(true);
6597
6598 render_surface1->SetForceRenderSurface(true);
6599 render_surface2->SetForceRenderSurface(true);
6600
6601 gfx::Transform translation_transform;
6602 translation_transform.Translate(2, 2);
6603
6604 gfx::Transform identity_transform;
6605 SetLayerPropertiesForTesting(root.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(50, 50),
[email protected]56fffdd2014-02-11 19:50:576610 true,
[email protected]420fdf6e2013-08-26 20:36:386611 false);
6612 SetLayerPropertiesForTesting(clip_parent.get(),
6613 translation_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(40, 40),
[email protected]56fffdd2014-02-11 19:50:576617 true,
[email protected]420fdf6e2013-08-26 20:36:386618 false);
6619 SetLayerPropertiesForTesting(render_surface1.get(),
6620 identity_transform,
[email protected]a2566412014-06-05 03:14:206621 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386622 gfx::PointF(),
6623 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576624 true,
[email protected]420fdf6e2013-08-26 20:36:386625 false);
6626 SetLayerPropertiesForTesting(intervening.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(5, 5),
[email protected]56fffdd2014-02-11 19:50:576631 true,
[email protected]420fdf6e2013-08-26 20:36:386632 false);
6633 SetLayerPropertiesForTesting(render_surface2.get(),
6634 identity_transform,
[email protected]a2566412014-06-05 03:14:206635 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386636 gfx::PointF(),
6637 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576638 true,
[email protected]420fdf6e2013-08-26 20:36:386639 false);
6640 SetLayerPropertiesForTesting(clip_child.get(),
6641 identity_transform,
[email protected]a2566412014-06-05 03:14:206642 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386643 gfx::PointF(-10.f, -10.f),
6644 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576645 true,
[email protected]420fdf6e2013-08-26 20:36:386646 false);
6647
enne2097cab2014-09-25 20:16:316648 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386649 host->SetRootLayer(root);
6650
6651 ExecuteCalculateDrawProperties(root.get());
6652
6653 EXPECT_TRUE(root->render_surface());
6654 EXPECT_TRUE(render_surface1->render_surface());
6655 EXPECT_TRUE(render_surface2->render_surface());
6656
6657 // Since the render surfaces could have expanded, they should not clip (their
6658 // bounds would no longer be reliable). We should resort to layer clipping
6659 // in this case.
6660 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6661 render_surface1->render_surface()->clip_rect().ToString());
6662 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6663 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6664 render_surface2->render_surface()->clip_rect().ToString());
6665 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6666
6667 // NB: clip rects are in target space.
6668 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6669 render_surface1->clip_rect().ToString());
6670 EXPECT_TRUE(render_surface1->is_clipped());
6671
6672 // This value is inherited from the clipping ancestor layer, 'intervening'.
6673 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6674 render_surface2->clip_rect().ToString());
6675 EXPECT_TRUE(render_surface2->is_clipped());
6676
6677 // The content rects of both render surfaces should both have expanded to
6678 // contain the clip child.
6679 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6680 render_surface1->render_surface()->content_rect().ToString());
6681 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6682 render_surface2->render_surface()->content_rect().ToString());
6683
6684 // The clip child should have inherited the clip parent's clip (projected to
6685 // the right space, of course), and should have the correctly sized visible
6686 // content rect.
6687 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6688 clip_child->clip_rect().ToString());
6689 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
6690 clip_child->visible_content_rect().ToString());
6691 EXPECT_TRUE(clip_child->is_clipped());
6692}
6693
6694TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
6695 // Ensure that intervening render surfaces are not a problem, even if there
6696 // is a scroll involved. Note, we do _not_ have to consider any other sort
6697 // of transform.
6698 //
6699 // root (a render surface)
6700 // + clip_parent (masks to bounds)
6701 // + render_surface1 (sets opacity)
6702 // + intervening (masks to bounds AND scrolls)
6703 // + render_surface2 (also sets opacity)
6704 // + clip_child
6705 //
6706 scoped_refptr<Layer> root = Layer::Create();
6707 scoped_refptr<Layer> clip_parent = Layer::Create();
6708 scoped_refptr<Layer> render_surface1 = Layer::Create();
6709 scoped_refptr<Layer> intervening = Layer::Create();
6710 scoped_refptr<Layer> render_surface2 = Layer::Create();
6711 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6712 make_scoped_refptr(new LayerWithForcedDrawsContent);
6713
6714 root->AddChild(clip_parent);
6715 clip_parent->AddChild(render_surface1);
6716 render_surface1->AddChild(intervening);
6717 intervening->AddChild(render_surface2);
6718 render_surface2->AddChild(clip_child);
6719
6720 clip_child->SetClipParent(clip_parent.get());
6721
6722 intervening->SetMasksToBounds(true);
6723 clip_parent->SetMasksToBounds(true);
[email protected]adeda572014-01-31 00:49:476724 intervening->SetScrollClipLayerId(clip_parent->id());
miletusf57925d2014-10-01 19:38:136725 intervening->SetScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:386726
6727 render_surface1->SetForceRenderSurface(true);
6728 render_surface2->SetForceRenderSurface(true);
6729
6730 gfx::Transform translation_transform;
6731 translation_transform.Translate(2, 2);
6732
6733 gfx::Transform identity_transform;
6734 SetLayerPropertiesForTesting(root.get(),
6735 identity_transform,
[email protected]a2566412014-06-05 03:14:206736 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386737 gfx::PointF(),
6738 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576739 true,
[email protected]420fdf6e2013-08-26 20:36:386740 false);
6741 SetLayerPropertiesForTesting(clip_parent.get(),
6742 translation_transform,
[email protected]a2566412014-06-05 03:14:206743 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386744 gfx::PointF(1.f, 1.f),
6745 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576746 true,
[email protected]420fdf6e2013-08-26 20:36:386747 false);
6748 SetLayerPropertiesForTesting(render_surface1.get(),
6749 identity_transform,
[email protected]a2566412014-06-05 03:14:206750 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386751 gfx::PointF(),
6752 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576753 true,
[email protected]420fdf6e2013-08-26 20:36:386754 false);
6755 SetLayerPropertiesForTesting(intervening.get(),
6756 identity_transform,
[email protected]a2566412014-06-05 03:14:206757 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386758 gfx::PointF(1.f, 1.f),
6759 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576760 true,
[email protected]420fdf6e2013-08-26 20:36:386761 false);
6762 SetLayerPropertiesForTesting(render_surface2.get(),
6763 identity_transform,
[email protected]a2566412014-06-05 03:14:206764 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386765 gfx::PointF(),
6766 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576767 true,
[email protected]420fdf6e2013-08-26 20:36:386768 false);
6769 SetLayerPropertiesForTesting(clip_child.get(),
6770 identity_transform,
[email protected]a2566412014-06-05 03:14:206771 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386772 gfx::PointF(-10.f, -10.f),
6773 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576774 true,
[email protected]420fdf6e2013-08-26 20:36:386775 false);
6776
enne2097cab2014-09-25 20:16:316777 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386778 host->SetRootLayer(root);
6779
6780 ExecuteCalculateDrawProperties(root.get());
6781
6782 EXPECT_TRUE(root->render_surface());
6783 EXPECT_TRUE(render_surface1->render_surface());
6784 EXPECT_TRUE(render_surface2->render_surface());
6785
6786 // Since the render surfaces could have expanded, they should not clip (their
6787 // bounds would no longer be reliable). We should resort to layer clipping
6788 // in this case.
6789 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6790 render_surface1->render_surface()->clip_rect().ToString());
6791 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6792 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6793 render_surface2->render_surface()->clip_rect().ToString());
6794 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6795
6796 // NB: clip rects are in target space.
6797 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6798 render_surface1->clip_rect().ToString());
6799 EXPECT_TRUE(render_surface1->is_clipped());
6800
6801 // This value is inherited from the clipping ancestor layer, 'intervening'.
6802 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6803 render_surface2->clip_rect().ToString());
6804 EXPECT_TRUE(render_surface2->is_clipped());
6805
6806 // The content rects of both render surfaces should both have expanded to
6807 // contain the clip child.
6808 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6809 render_surface1->render_surface()->content_rect().ToString());
6810 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6811 render_surface2->render_surface()->content_rect().ToString());
6812
6813 // The clip child should have inherited the clip parent's clip (projected to
6814 // the right space, of course), and should have the correctly sized visible
6815 // content rect.
6816 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6817 clip_child->clip_rect().ToString());
6818 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6819 clip_child->visible_content_rect().ToString());
6820 EXPECT_TRUE(clip_child->is_clipped());
6821}
6822
6823TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
6824 // Ensures that descendants of the clip child inherit the correct clip.
6825 //
6826 // root (a render surface)
6827 // + clip_parent (masks to bounds)
6828 // + intervening (masks to bounds)
6829 // + clip_child
6830 // + child
6831 //
6832 scoped_refptr<Layer> root = Layer::Create();
6833 scoped_refptr<Layer> clip_parent = Layer::Create();
6834 scoped_refptr<Layer> intervening = Layer::Create();
6835 scoped_refptr<Layer> clip_child = Layer::Create();
6836 scoped_refptr<LayerWithForcedDrawsContent> child =
6837 make_scoped_refptr(new LayerWithForcedDrawsContent);
6838
6839 root->AddChild(clip_parent);
6840 clip_parent->AddChild(intervening);
6841 intervening->AddChild(clip_child);
6842 clip_child->AddChild(child);
6843
6844 clip_child->SetClipParent(clip_parent.get());
6845
6846 intervening->SetMasksToBounds(true);
6847 clip_parent->SetMasksToBounds(true);
6848
6849 gfx::Transform identity_transform;
6850 SetLayerPropertiesForTesting(root.get(),
6851 identity_transform,
[email protected]a2566412014-06-05 03:14:206852 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386853 gfx::PointF(),
6854 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576855 true,
[email protected]420fdf6e2013-08-26 20:36:386856 false);
6857 SetLayerPropertiesForTesting(clip_parent.get(),
6858 identity_transform,
[email protected]a2566412014-06-05 03:14:206859 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386860 gfx::PointF(),
6861 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576862 true,
[email protected]420fdf6e2013-08-26 20:36:386863 false);
6864 SetLayerPropertiesForTesting(intervening.get(),
6865 identity_transform,
[email protected]a2566412014-06-05 03:14:206866 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386867 gfx::PointF(),
6868 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576869 true,
[email protected]420fdf6e2013-08-26 20:36:386870 false);
6871 SetLayerPropertiesForTesting(clip_child.get(),
6872 identity_transform,
[email protected]a2566412014-06-05 03:14:206873 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386874 gfx::PointF(),
6875 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576876 true,
[email protected]420fdf6e2013-08-26 20:36:386877 false);
6878 SetLayerPropertiesForTesting(child.get(),
6879 identity_transform,
[email protected]a2566412014-06-05 03:14:206880 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386881 gfx::PointF(),
6882 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576883 true,
[email protected]420fdf6e2013-08-26 20:36:386884 false);
6885
enne2097cab2014-09-25 20:16:316886 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386887 host->SetRootLayer(root);
6888
6889 ExecuteCalculateDrawProperties(root.get());
6890
6891 EXPECT_TRUE(root->render_surface());
6892
6893 // Neither the clip child nor its descendant should have inherited the clip
6894 // from |intervening|.
6895 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6896 clip_child->clip_rect().ToString());
6897 EXPECT_TRUE(clip_child->is_clipped());
6898 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6899 child->visible_content_rect().ToString());
6900 EXPECT_TRUE(child->is_clipped());
6901}
6902
6903TEST_F(LayerTreeHostCommonTest,
6904 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
6905 // Ensures that non-descendant clip children in the tree do not affect
6906 // render surfaces.
6907 //
6908 // root (a render surface)
6909 // + clip_parent (masks to bounds)
6910 // + render_surface1
6911 // + clip_child
6912 // + render_surface2
6913 // + non_clip_child
6914 //
6915 // In this example render_surface2 should be unaffected by clip_child.
6916 scoped_refptr<Layer> root = Layer::Create();
6917 scoped_refptr<Layer> clip_parent = Layer::Create();
6918 scoped_refptr<Layer> render_surface1 = Layer::Create();
6919 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6920 make_scoped_refptr(new LayerWithForcedDrawsContent);
6921 scoped_refptr<Layer> render_surface2 = Layer::Create();
6922 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
6923 make_scoped_refptr(new LayerWithForcedDrawsContent);
6924
6925 root->AddChild(clip_parent);
6926 clip_parent->AddChild(render_surface1);
6927 render_surface1->AddChild(clip_child);
6928 clip_parent->AddChild(render_surface2);
6929 render_surface2->AddChild(non_clip_child);
6930
6931 clip_child->SetClipParent(clip_parent.get());
6932
6933 clip_parent->SetMasksToBounds(true);
6934 render_surface1->SetMasksToBounds(true);
6935
6936 gfx::Transform identity_transform;
6937 SetLayerPropertiesForTesting(root.get(),
6938 identity_transform,
[email protected]a2566412014-06-05 03:14:206939 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386940 gfx::PointF(),
6941 gfx::Size(15, 15),
[email protected]56fffdd2014-02-11 19:50:576942 true,
[email protected]420fdf6e2013-08-26 20:36:386943 false);
6944 SetLayerPropertiesForTesting(clip_parent.get(),
6945 identity_transform,
[email protected]a2566412014-06-05 03:14:206946 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386947 gfx::PointF(),
6948 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576949 true,
[email protected]420fdf6e2013-08-26 20:36:386950 false);
6951 SetLayerPropertiesForTesting(render_surface1.get(),
6952 identity_transform,
[email protected]a2566412014-06-05 03:14:206953 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386954 gfx::PointF(5, 5),
6955 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576956 true,
[email protected]420fdf6e2013-08-26 20:36:386957 false);
6958 SetLayerPropertiesForTesting(render_surface2.get(),
6959 identity_transform,
[email protected]a2566412014-06-05 03:14:206960 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386961 gfx::PointF(),
6962 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576963 true,
[email protected]420fdf6e2013-08-26 20:36:386964 false);
6965 SetLayerPropertiesForTesting(clip_child.get(),
6966 identity_transform,
[email protected]a2566412014-06-05 03:14:206967 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386968 gfx::PointF(-1, 1),
6969 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576970 true,
[email protected]420fdf6e2013-08-26 20:36:386971 false);
6972 SetLayerPropertiesForTesting(non_clip_child.get(),
6973 identity_transform,
[email protected]a2566412014-06-05 03:14:206974 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386975 gfx::PointF(),
6976 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576977 true,
[email protected]420fdf6e2013-08-26 20:36:386978 false);
6979
6980 render_surface1->SetForceRenderSurface(true);
6981 render_surface2->SetForceRenderSurface(true);
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 EXPECT_TRUE(render_surface1->render_surface());
6990 EXPECT_TRUE(render_surface2->render_surface());
6991
6992 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6993 render_surface1->clip_rect().ToString());
6994 EXPECT_TRUE(render_surface1->is_clipped());
6995
6996 // The render surface should not clip (it has unclipped descendants), instead
6997 // it should rely on layer clipping.
6998 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6999 render_surface1->render_surface()->clip_rect().ToString());
7000 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
7001
7002 // That said, it should have grown to accomodate the unclipped descendant.
7003 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
7004 render_surface1->render_surface()->content_rect().ToString());
7005
7006 // This render surface should clip. It has no unclipped descendants.
7007 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
7008 render_surface2->clip_rect().ToString());
7009 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
7010
7011 // It also shouldn't have grown to accomodate the clip child.
7012 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
7013 render_surface2->render_surface()->content_rect().ToString());
7014
7015 // Sanity check our num_unclipped_descendants values.
7016 EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
7017 EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
7018}
7019
[email protected]45948712013-09-27 02:46:487020TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
7021 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457022 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:477023 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]45948712013-09-27 02:46:487024 scoped_ptr<LayerImpl> root =
7025 LayerImpl::Create(host_impl.active_tree(), 12345);
7026 scoped_ptr<LayerImpl> child1 =
7027 LayerImpl::Create(host_impl.active_tree(), 123456);
7028 scoped_ptr<LayerImpl> child2 =
7029 LayerImpl::Create(host_impl.active_tree(), 1234567);
7030 scoped_ptr<LayerImpl> child3 =
7031 LayerImpl::Create(host_impl.active_tree(), 12345678);
7032
7033 gfx::Transform identity_matrix;
[email protected]a2566412014-06-05 03:14:207034 gfx::Point3F transform_origin;
[email protected]45948712013-09-27 02:46:487035 gfx::PointF position;
7036 gfx::Size bounds(100, 100);
awoloszyne83f28c2014-12-22 15:40:007037 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
7038 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:487039 root->SetDrawsContent(true);
7040
7041 // This layer structure normally forces render surface due to preserves3d
7042 // behavior.
awoloszyne83f28c2014-12-22 15:40:007043 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin,
7044 position, bounds, false, true, true);
[email protected]45948712013-09-27 02:46:487045 child1->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:007046 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin,
7047 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:487048 child2->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:007049 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin,
7050 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:487051 child3->SetDrawsContent(true);
7052
[email protected]a9d4d4f2014-06-19 06:49:287053 child2->Set3dSortingContextId(1);
7054 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:577055
[email protected]45948712013-09-27 02:46:487056 child2->AddChild(child3.Pass());
7057 child1->AddChild(child2.Pass());
7058 root->AddChild(child1.Pass());
7059
7060 {
7061 LayerImplList render_surface_layer_list;
[email protected]ad63b2f2014-08-11 17:39:547062 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get());
[email protected]45948712013-09-27 02:46:487063 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227064 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:487065 inputs.can_render_to_separate_surface = true;
7066 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7067
7068 EXPECT_EQ(2u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:027069
7070 int count_represents_target_render_surface = 0;
7071 int count_represents_contributing_render_surface = 0;
7072 int count_represents_itself = 0;
7073 auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list);
7074 for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list);
7075 it != end; ++it) {
7076 if (it.represents_target_render_surface())
7077 count_represents_target_render_surface++;
7078 if (it.represents_contributing_render_surface())
7079 count_represents_contributing_render_surface++;
7080 if (it.represents_itself())
7081 count_represents_itself++;
7082 }
7083
7084 // Two render surfaces.
7085 EXPECT_EQ(2, count_represents_target_render_surface);
7086 // Second render surface contributes to root render surface.
7087 EXPECT_EQ(1, count_represents_contributing_render_surface);
7088 // All 4 layers represent itself.
7089 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:487090 }
7091
7092 {
7093 LayerImplList render_surface_layer_list;
7094 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227095 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:487096 inputs.can_render_to_separate_surface = false;
7097 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7098
7099 EXPECT_EQ(1u, render_surface_layer_list.size());
boliu13185ca2015-03-16 23:20:027100
7101 int count_represents_target_render_surface = 0;
7102 int count_represents_contributing_render_surface = 0;
7103 int count_represents_itself = 0;
7104 auto end = LayerIterator<LayerImpl>::End(&render_surface_layer_list);
7105 for (auto it = LayerIterator<LayerImpl>::Begin(&render_surface_layer_list);
7106 it != end; ++it) {
7107 if (it.represents_target_render_surface())
7108 count_represents_target_render_surface++;
7109 if (it.represents_contributing_render_surface())
7110 count_represents_contributing_render_surface++;
7111 if (it.represents_itself())
7112 count_represents_itself++;
7113 }
7114
7115 // Only root layer has a render surface.
7116 EXPECT_EQ(1, count_represents_target_render_surface);
7117 // No layer contributes a render surface to root render surface.
7118 EXPECT_EQ(0, count_represents_contributing_render_surface);
7119 // All 4 layers represent itself.
7120 EXPECT_EQ(4, count_represents_itself);
[email protected]45948712013-09-27 02:46:487121 }
7122}
7123
[email protected]a9aa60a82013-08-29 04:28:267124TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
7125 scoped_refptr<Layer> root = Layer::Create();
7126 scoped_refptr<Layer> render_surface = Layer::Create();
7127 scoped_refptr<LayerWithForcedDrawsContent> child =
7128 make_scoped_refptr(new LayerWithForcedDrawsContent);
7129
7130 root->AddChild(render_surface);
7131 render_surface->AddChild(child);
7132
7133 gfx::Transform identity_transform;
7134 SetLayerPropertiesForTesting(root.get(),
7135 identity_transform,
[email protected]a2566412014-06-05 03:14:207136 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267137 gfx::PointF(),
7138 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577139 true,
[email protected]a9aa60a82013-08-29 04:28:267140 false);
7141 SetLayerPropertiesForTesting(render_surface.get(),
7142 identity_transform,
[email protected]a2566412014-06-05 03:14:207143 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267144 gfx::PointF(),
7145 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577146 false,
7147 true);
[email protected]a9aa60a82013-08-29 04:28:267148 SetLayerPropertiesForTesting(child.get(),
7149 identity_transform,
[email protected]a2566412014-06-05 03:14:207150 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:267151 gfx::PointF(),
7152 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577153 true,
[email protected]a9aa60a82013-08-29 04:28:267154 false);
7155
[email protected]56fffdd2014-02-11 19:50:577156 root->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:287157 root->Set3dSortingContextId(1);
[email protected]a9aa60a82013-08-29 04:28:267158 render_surface->SetDoubleSided(false);
7159 render_surface->SetForceRenderSurface(true);
7160
enne2097cab2014-09-25 20:16:317161 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]a9aa60a82013-08-29 04:28:267162 host->SetRootLayer(root);
7163
7164 ExecuteCalculateDrawProperties(root.get());
7165
7166 EXPECT_EQ(2u, render_surface_layer_list()->size());
7167 EXPECT_EQ(1u,
7168 render_surface_layer_list()->at(0)
7169 ->render_surface()->layer_list().size());
7170 EXPECT_EQ(1u,
7171 render_surface_layer_list()->at(1)
7172 ->render_surface()->layer_list().size());
7173
7174 gfx::Transform rotation_transform = identity_transform;
7175 rotation_transform.RotateAboutXAxis(180.0);
7176
7177 render_surface->SetTransform(rotation_transform);
7178
7179 ExecuteCalculateDrawProperties(root.get());
7180
7181 EXPECT_EQ(1u, render_surface_layer_list()->size());
7182 EXPECT_EQ(0u,
7183 render_surface_layer_list()->at(0)
7184 ->render_surface()->layer_list().size());
7185}
7186
[email protected]995708c52013-10-17 20:52:597187TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
7188 // Checks that the simple case (being clipped by a scroll parent that would
7189 // have been processed before you anyhow) results in the right clips.
7190 //
7191 // + root
7192 // + scroll_parent_border
7193 // | + scroll_parent_clip
7194 // | + scroll_parent
7195 // + scroll_child
7196 //
7197 scoped_refptr<Layer> root = Layer::Create();
7198 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7199 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7200 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7201 make_scoped_refptr(new LayerWithForcedDrawsContent);
7202 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7203 make_scoped_refptr(new LayerWithForcedDrawsContent);
7204
7205 root->AddChild(scroll_child);
7206
7207 root->AddChild(scroll_parent_border);
7208 scroll_parent_border->AddChild(scroll_parent_clip);
7209 scroll_parent_clip->AddChild(scroll_parent);
7210
7211 scroll_parent_clip->SetMasksToBounds(true);
7212
7213 scroll_child->SetScrollParent(scroll_parent.get());
7214
7215 gfx::Transform identity_transform;
7216 SetLayerPropertiesForTesting(root.get(),
7217 identity_transform,
[email protected]a2566412014-06-05 03:14:207218 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597219 gfx::PointF(),
7220 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577221 true,
[email protected]995708c52013-10-17 20:52:597222 false);
7223 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7224 identity_transform,
[email protected]a2566412014-06-05 03:14:207225 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597226 gfx::PointF(),
7227 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577228 true,
[email protected]995708c52013-10-17 20:52:597229 false);
7230 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7231 identity_transform,
[email protected]a2566412014-06-05 03:14:207232 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597233 gfx::PointF(),
7234 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577235 true,
[email protected]995708c52013-10-17 20:52:597236 false);
7237 SetLayerPropertiesForTesting(scroll_parent.get(),
7238 identity_transform,
[email protected]a2566412014-06-05 03:14:207239 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597240 gfx::PointF(),
7241 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577242 true,
[email protected]995708c52013-10-17 20:52:597243 false);
7244 SetLayerPropertiesForTesting(scroll_child.get(),
7245 identity_transform,
[email protected]a2566412014-06-05 03:14:207246 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597247 gfx::PointF(),
7248 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577249 true,
[email protected]995708c52013-10-17 20:52:597250 false);
7251
enne2097cab2014-09-25 20:16:317252 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597253 host->SetRootLayer(root);
7254
7255 ExecuteCalculateDrawProperties(root.get());
7256
7257 EXPECT_TRUE(root->render_surface());
7258
7259 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7260 scroll_child->clip_rect().ToString());
7261 EXPECT_TRUE(scroll_child->is_clipped());
7262}
7263
[email protected]08bdf1b2014-04-16 23:23:297264TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
7265 scoped_refptr<LayerWithForcedDrawsContent> root =
7266 make_scoped_refptr(new LayerWithForcedDrawsContent);
7267 scoped_refptr<LayerWithForcedDrawsContent> parent =
7268 make_scoped_refptr(new LayerWithForcedDrawsContent);
7269 scoped_refptr<LayerWithForcedDrawsContent> child =
7270 make_scoped_refptr(new LayerWithForcedDrawsContent);
7271
7272 root->AddChild(parent);
7273 parent->AddChild(child);
7274
7275 gfx::Transform identity_transform;
7276 SetLayerPropertiesForTesting(root.get(),
7277 identity_transform,
[email protected]a2566412014-06-05 03:14:207278 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297279 gfx::PointF(),
7280 gfx::Size(50, 50),
7281 true,
7282 true);
7283 root->SetForceRenderSurface(true);
7284 SetLayerPropertiesForTesting(parent.get(),
7285 identity_transform,
[email protected]a2566412014-06-05 03:14:207286 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297287 gfx::PointF(),
7288 gfx::Size(30, 30),
7289 true,
7290 true);
7291 parent->SetForceRenderSurface(true);
7292 SetLayerPropertiesForTesting(child.get(),
7293 identity_transform,
[email protected]a2566412014-06-05 03:14:207294 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297295 gfx::PointF(),
7296 gfx::Size(20, 20),
7297 true,
7298 true);
7299 child->SetForceRenderSurface(true);
7300
enne2097cab2014-09-25 20:16:317301 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]08bdf1b2014-04-16 23:23:297302 host->SetRootLayer(root);
7303
7304 ExecuteCalculateDrawProperties(root.get());
7305
7306 EXPECT_EQ(3u, render_surface_layer_list()->size());
7307
7308 gfx::Transform singular_transform;
7309 singular_transform.Scale3d(
7310 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
7311
7312 child->SetTransform(singular_transform);
7313
7314 ExecuteCalculateDrawProperties(root.get());
7315
7316 EXPECT_EQ(2u, render_surface_layer_list()->size());
7317
7318 // Ensure that the entire subtree under a layer with singular transform does
7319 // not get rendered.
7320 parent->SetTransform(singular_transform);
7321 child->SetTransform(identity_transform);
7322
7323 ExecuteCalculateDrawProperties(root.get());
7324
7325 EXPECT_EQ(1u, render_surface_layer_list()->size());
7326}
7327
[email protected]995708c52013-10-17 20:52:597328TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
7329 // Checks that clipping by a scroll parent that follows you in paint order
7330 // still results in correct clipping.
7331 //
7332 // + root
7333 // + scroll_child
7334 // + scroll_parent_border
7335 // + scroll_parent_clip
7336 // + scroll_parent
7337 //
7338 scoped_refptr<Layer> root = Layer::Create();
7339 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7340 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7341 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7342 make_scoped_refptr(new LayerWithForcedDrawsContent);
7343 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7344 make_scoped_refptr(new LayerWithForcedDrawsContent);
7345
7346 root->AddChild(scroll_parent_border);
7347 scroll_parent_border->AddChild(scroll_parent_clip);
7348 scroll_parent_clip->AddChild(scroll_parent);
7349
7350 root->AddChild(scroll_child);
7351
7352 scroll_parent_clip->SetMasksToBounds(true);
7353
7354 scroll_child->SetScrollParent(scroll_parent.get());
7355
7356 gfx::Transform identity_transform;
7357 SetLayerPropertiesForTesting(root.get(),
7358 identity_transform,
[email protected]a2566412014-06-05 03:14:207359 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597360 gfx::PointF(),
7361 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577362 true,
[email protected]995708c52013-10-17 20:52:597363 false);
7364 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7365 identity_transform,
[email protected]a2566412014-06-05 03:14:207366 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597367 gfx::PointF(),
7368 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577369 true,
[email protected]995708c52013-10-17 20:52:597370 false);
7371 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7372 identity_transform,
[email protected]a2566412014-06-05 03:14:207373 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597374 gfx::PointF(),
7375 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577376 true,
[email protected]995708c52013-10-17 20:52:597377 false);
7378 SetLayerPropertiesForTesting(scroll_parent.get(),
7379 identity_transform,
[email protected]a2566412014-06-05 03:14:207380 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597381 gfx::PointF(),
7382 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577383 true,
[email protected]995708c52013-10-17 20:52:597384 false);
7385 SetLayerPropertiesForTesting(scroll_child.get(),
7386 identity_transform,
[email protected]a2566412014-06-05 03:14:207387 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597388 gfx::PointF(),
7389 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577390 true,
[email protected]995708c52013-10-17 20:52:597391 false);
7392
enne2097cab2014-09-25 20:16:317393 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597394 host->SetRootLayer(root);
7395
7396 ExecuteCalculateDrawProperties(root.get());
7397
7398 EXPECT_TRUE(root->render_surface());
7399
7400 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7401 scroll_child->clip_rect().ToString());
7402 EXPECT_TRUE(scroll_child->is_clipped());
7403}
7404
7405TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
7406 // Checks that clipping by a scroll parent and scroll grandparent that follow
7407 // you in paint order still results in correct clipping.
7408 //
7409 // + root
7410 // + scroll_child
7411 // + scroll_parent_border
7412 // | + scroll_parent_clip
7413 // | + scroll_parent
7414 // + scroll_grandparent_border
7415 // + scroll_grandparent_clip
7416 // + scroll_grandparent
7417 //
7418 scoped_refptr<Layer> root = Layer::Create();
7419 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7420 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7421 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7422 make_scoped_refptr(new LayerWithForcedDrawsContent);
7423
7424 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
7425 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
7426 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
7427 make_scoped_refptr(new LayerWithForcedDrawsContent);
7428
7429 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7430 make_scoped_refptr(new LayerWithForcedDrawsContent);
7431
7432 root->AddChild(scroll_child);
7433
7434 root->AddChild(scroll_parent_border);
7435 scroll_parent_border->AddChild(scroll_parent_clip);
7436 scroll_parent_clip->AddChild(scroll_parent);
7437
7438 root->AddChild(scroll_grandparent_border);
7439 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
7440 scroll_grandparent_clip->AddChild(scroll_grandparent);
7441
7442 scroll_parent_clip->SetMasksToBounds(true);
7443 scroll_grandparent_clip->SetMasksToBounds(true);
7444
7445 scroll_child->SetScrollParent(scroll_parent.get());
7446 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
7447
7448 gfx::Transform identity_transform;
7449 SetLayerPropertiesForTesting(root.get(),
7450 identity_transform,
[email protected]a2566412014-06-05 03:14:207451 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597452 gfx::PointF(),
7453 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577454 true,
[email protected]995708c52013-10-17 20:52:597455 false);
7456 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
7457 identity_transform,
[email protected]a2566412014-06-05 03:14:207458 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597459 gfx::PointF(),
7460 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577461 true,
[email protected]995708c52013-10-17 20:52:597462 false);
7463 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
7464 identity_transform,
[email protected]a2566412014-06-05 03:14:207465 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597466 gfx::PointF(),
7467 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577468 true,
[email protected]995708c52013-10-17 20:52:597469 false);
7470 SetLayerPropertiesForTesting(scroll_grandparent.get(),
7471 identity_transform,
[email protected]a2566412014-06-05 03:14:207472 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597473 gfx::PointF(),
7474 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577475 true,
[email protected]995708c52013-10-17 20:52:597476 false);
7477 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7478 identity_transform,
[email protected]a2566412014-06-05 03:14:207479 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597480 gfx::PointF(),
7481 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577482 true,
[email protected]995708c52013-10-17 20:52:597483 false);
7484 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7485 identity_transform,
[email protected]a2566412014-06-05 03:14:207486 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597487 gfx::PointF(),
7488 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577489 true,
[email protected]995708c52013-10-17 20:52:597490 false);
7491 SetLayerPropertiesForTesting(scroll_parent.get(),
7492 identity_transform,
[email protected]a2566412014-06-05 03:14:207493 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597494 gfx::PointF(),
7495 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577496 true,
[email protected]995708c52013-10-17 20:52:597497 false);
7498 SetLayerPropertiesForTesting(scroll_child.get(),
7499 identity_transform,
[email protected]a2566412014-06-05 03:14:207500 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597501 gfx::PointF(),
7502 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577503 true,
[email protected]995708c52013-10-17 20:52:597504 false);
7505
enne2097cab2014-09-25 20:16:317506 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597507 host->SetRootLayer(root);
7508
7509 ExecuteCalculateDrawProperties(root.get());
7510
7511 EXPECT_TRUE(root->render_surface());
7512
7513 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7514 scroll_child->clip_rect().ToString());
7515 EXPECT_TRUE(scroll_child->is_clipped());
7516
7517 // Despite the fact that we visited the above layers out of order to get the
7518 // correct clip, the layer lists should be unaffected.
7519 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
7520 EXPECT_EQ(scroll_child.get(),
Daniel Chengeea98042014-08-26 00:28:107521 root->render_surface()->layer_list().at(0).get());
[email protected]995708c52013-10-17 20:52:597522 EXPECT_EQ(scroll_parent.get(),
Daniel Chengeea98042014-08-26 00:28:107523 root->render_surface()->layer_list().at(1).get());
[email protected]995708c52013-10-17 20:52:597524 EXPECT_EQ(scroll_grandparent.get(),
Daniel Chengeea98042014-08-26 00:28:107525 root->render_surface()->layer_list().at(2).get());
[email protected]995708c52013-10-17 20:52:597526}
7527
7528TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
7529 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:227530 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:597531 // + root
7532 // + scroll_child
7533 // + scroll_parent_border
7534 // + scroll_parent_clip
7535 // + scroll_parent
7536 // + render_surface1
7537 // + scroll_grandparent_border
7538 // + scroll_grandparent_clip
7539 // + scroll_grandparent
7540 // + render_surface2
7541 //
[email protected]44d8e84c2013-10-19 19:13:227542 scoped_refptr<LayerWithForcedDrawsContent> root =
7543 make_scoped_refptr(new LayerWithForcedDrawsContent);
[email protected]995708c52013-10-17 20:52:597544
7545 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7546 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7547 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7548 make_scoped_refptr(new LayerWithForcedDrawsContent);
7549 scoped_refptr<LayerWithForcedDrawsContent> render_surface1 =
7550 make_scoped_refptr(new LayerWithForcedDrawsContent);
7551
7552 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
7553 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
7554 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
7555 make_scoped_refptr(new LayerWithForcedDrawsContent);
7556 scoped_refptr<LayerWithForcedDrawsContent> render_surface2 =
7557 make_scoped_refptr(new LayerWithForcedDrawsContent);
7558
7559 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7560 make_scoped_refptr(new LayerWithForcedDrawsContent);
7561
7562 root->AddChild(scroll_child);
7563
7564 root->AddChild(scroll_parent_border);
7565 scroll_parent_border->AddChild(scroll_parent_clip);
7566 scroll_parent_clip->AddChild(scroll_parent);
7567 scroll_parent->AddChild(render_surface2);
7568
7569 root->AddChild(scroll_grandparent_border);
7570 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
7571 scroll_grandparent_clip->AddChild(scroll_grandparent);
7572 scroll_grandparent->AddChild(render_surface1);
7573
7574 scroll_parent_clip->SetMasksToBounds(true);
7575 scroll_grandparent_clip->SetMasksToBounds(true);
7576
7577 scroll_child->SetScrollParent(scroll_parent.get());
7578 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
7579
7580 render_surface1->SetForceRenderSurface(true);
7581 render_surface2->SetForceRenderSurface(true);
7582
7583 gfx::Transform identity_transform;
7584 SetLayerPropertiesForTesting(root.get(),
7585 identity_transform,
[email protected]a2566412014-06-05 03:14:207586 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597587 gfx::PointF(),
7588 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577589 true,
[email protected]995708c52013-10-17 20:52:597590 false);
7591 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
7592 identity_transform,
[email protected]a2566412014-06-05 03:14:207593 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597594 gfx::PointF(),
7595 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577596 true,
[email protected]995708c52013-10-17 20:52:597597 false);
7598 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
7599 identity_transform,
[email protected]a2566412014-06-05 03:14:207600 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597601 gfx::PointF(),
7602 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577603 true,
[email protected]995708c52013-10-17 20:52:597604 false);
7605 SetLayerPropertiesForTesting(scroll_grandparent.get(),
7606 identity_transform,
[email protected]a2566412014-06-05 03:14:207607 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597608 gfx::PointF(),
7609 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577610 true,
[email protected]995708c52013-10-17 20:52:597611 false);
7612 SetLayerPropertiesForTesting(render_surface1.get(),
7613 identity_transform,
[email protected]a2566412014-06-05 03:14:207614 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597615 gfx::PointF(),
7616 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577617 true,
[email protected]995708c52013-10-17 20:52:597618 false);
7619 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7620 identity_transform,
[email protected]a2566412014-06-05 03:14:207621 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597622 gfx::PointF(),
7623 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577624 true,
[email protected]995708c52013-10-17 20:52:597625 false);
7626 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7627 identity_transform,
[email protected]a2566412014-06-05 03:14:207628 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597629 gfx::PointF(),
7630 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577631 true,
[email protected]995708c52013-10-17 20:52:597632 false);
7633 SetLayerPropertiesForTesting(scroll_parent.get(),
7634 identity_transform,
[email protected]a2566412014-06-05 03:14:207635 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597636 gfx::PointF(),
7637 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577638 true,
[email protected]995708c52013-10-17 20:52:597639 false);
7640 SetLayerPropertiesForTesting(render_surface2.get(),
7641 identity_transform,
[email protected]a2566412014-06-05 03:14:207642 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597643 gfx::PointF(),
7644 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577645 true,
[email protected]995708c52013-10-17 20:52:597646 false);
7647 SetLayerPropertiesForTesting(scroll_child.get(),
7648 identity_transform,
[email protected]a2566412014-06-05 03:14:207649 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597650 gfx::PointF(),
7651 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577652 true,
[email protected]995708c52013-10-17 20:52:597653 false);
7654
enne2097cab2014-09-25 20:16:317655 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597656 host->SetRootLayer(root);
7657
7658 RenderSurfaceLayerList render_surface_layer_list;
7659 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7660 root.get(),
bokancccfde72014-10-08 15:15:227661 root->bounds(),
[email protected]995708c52013-10-17 20:52:597662 identity_transform,
7663 &render_surface_layer_list);
7664
7665 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7666
7667 EXPECT_TRUE(root->render_surface());
7668
7669 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7670 scroll_child->clip_rect().ToString());
7671 EXPECT_TRUE(scroll_child->is_clipped());
7672
7673 // Despite the fact that we had to process the layers out of order to get the
7674 // right clip, our render_surface_layer_list's order should be unaffected.
7675 EXPECT_EQ(3u, render_surface_layer_list.size());
7676 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
7677 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
7678 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
[email protected]44d8e84c2013-10-19 19:13:227679 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
7680 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
7681 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:597682}
7683
ajuma0b10f942015-03-21 07:45:537684TEST_F(LayerTreeHostCommonTest, FixedPositionWithInterveningRenderSurface) {
7685 // Ensures that when we have a render surface between a fixed position layer
7686 // and its container, we compute the fixed position layer's draw transform
7687 // with respect to that intervening render surface, not with respect to its
7688 // container's render target.
7689 //
7690 // + root
7691 // + render_surface
7692 // + fixed
7693 //
7694 scoped_refptr<Layer> root = Layer::Create();
7695 scoped_refptr<LayerWithForcedDrawsContent> render_surface =
7696 make_scoped_refptr(new LayerWithForcedDrawsContent());
7697 scoped_refptr<LayerWithForcedDrawsContent> fixed =
7698 make_scoped_refptr(new LayerWithForcedDrawsContent());
7699
7700 root->AddChild(render_surface);
7701 render_surface->AddChild(fixed);
7702
7703 root->SetIsContainerForFixedPositionLayers(true);
7704 render_surface->SetForceRenderSurface(true);
7705
7706 LayerPositionConstraint constraint;
7707 constraint.set_is_fixed_position(true);
7708 fixed->SetPositionConstraint(constraint);
7709
7710 SetLayerPropertiesForTesting(root.get(), gfx::Transform(), gfx::Point3F(),
7711 gfx::PointF(), gfx::Size(50, 50), true, false);
7712 SetLayerPropertiesForTesting(render_surface.get(), gfx::Transform(),
7713 gfx::Point3F(), gfx::PointF(7.f, 9.f),
7714 gfx::Size(50, 50), true, false);
7715 SetLayerPropertiesForTesting(fixed.get(), gfx::Transform(), gfx::Point3F(),
7716 gfx::PointF(10.f, 15.f), gfx::Size(50, 50), true,
7717 false);
7718
7719 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
7720 host->SetRootLayer(root);
7721
7722 ExecuteCalculateDrawProperties(root.get());
7723
7724 gfx::Transform expected_draw_transform;
7725 expected_draw_transform.Translate(10.f, 15.f);
7726 EXPECT_EQ(expected_draw_transform, fixed->draw_transform());
7727
7728 gfx::Transform expected_screen_space_transform;
7729 expected_screen_space_transform.Translate(17.f, 24.f);
7730 EXPECT_EQ(expected_screen_space_transform, fixed->screen_space_transform());
7731}
7732
[email protected]d81752b2013-10-25 08:32:237733TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
7734 // This test verifies that a scrolling layer that gets snapped to
7735 // integer coordinates doesn't move a fixed position child.
7736 //
7737 // + root
7738 // + container
7739 // + scroller
7740 // + fixed
7741 //
7742 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457743 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:477744 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]d81752b2013-10-25 08:32:237745 host_impl.CreatePendingTree();
7746 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7747 scoped_ptr<LayerImpl> container =
7748 LayerImpl::Create(host_impl.active_tree(), 2);
7749 LayerImpl* container_layer = container.get();
7750 scoped_ptr<LayerImpl> scroller =
7751 LayerImpl::Create(host_impl.active_tree(), 3);
7752 LayerImpl* scroll_layer = scroller.get();
7753 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7754 LayerImpl* fixed_layer = fixed.get();
7755
7756 container->SetIsContainerForFixedPositionLayers(true);
7757
7758 LayerPositionConstraint constraint;
7759 constraint.set_is_fixed_position(true);
7760 fixed->SetPositionConstraint(constraint);
7761
[email protected]adeda572014-01-31 00:49:477762 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:237763
7764 gfx::Transform identity_transform;
7765 gfx::Transform container_transform;
7766 container_transform.Translate3d(10.0, 20.0, 0.0);
7767 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7768
awoloszyne83f28c2014-12-22 15:40:007769 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7770 gfx::PointF(), gfx::Size(50, 50), true, false,
7771 true);
7772 SetLayerPropertiesForTesting(container.get(), container_transform,
7773 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7774 true, false, false);
7775 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7776 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7777 true, false, false);
7778 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7779 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]d81752b2013-10-25 08:32:237780 false);
7781
7782 scroller->AddChild(fixed.Pass());
7783 container->AddChild(scroller.Pass());
7784 root->AddChild(container.Pass());
7785
7786 // Rounded to integers already.
7787 {
7788 gfx::Vector2dF scroll_delta(3.0, 5.0);
7789 scroll_layer->SetScrollDelta(scroll_delta);
7790
7791 LayerImplList render_surface_layer_list;
7792 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227793 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]d81752b2013-10-25 08:32:237794 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7795
7796 EXPECT_TRANSFORMATION_MATRIX_EQ(
7797 container_layer->draw_properties().screen_space_transform,
7798 fixed_layer->draw_properties().screen_space_transform);
7799 EXPECT_VECTOR_EQ(
7800 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7801 container_offset);
7802 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7803 .screen_space_transform.To2dTranslation(),
7804 container_offset - scroll_delta);
7805 }
7806
7807 // Scroll delta requiring rounding.
7808 {
7809 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
7810 scroll_layer->SetScrollDelta(scroll_delta);
7811
7812 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
7813
7814 LayerImplList render_surface_layer_list;
7815 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227816 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]d81752b2013-10-25 08:32:237817 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7818
7819 EXPECT_TRANSFORMATION_MATRIX_EQ(
7820 container_layer->draw_properties().screen_space_transform,
7821 fixed_layer->draw_properties().screen_space_transform);
7822 EXPECT_VECTOR_EQ(
7823 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7824 container_offset);
7825 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7826 .screen_space_transform.To2dTranslation(),
7827 container_offset - rounded_scroll_delta);
7828 }
[email protected]cf15ad7b2014-04-02 03:59:267829
7830 // Scale is applied earlier in the tree.
7831 {
7832 gfx::Transform scaled_container_transform = container_transform;
7833 scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
7834 container_layer->SetTransform(scaled_container_transform);
7835
7836 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7837 scroll_layer->SetScrollDelta(scroll_delta);
7838
7839 LayerImplList render_surface_layer_list;
7840 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227841 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]cf15ad7b2014-04-02 03:59:267842 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7843
7844 EXPECT_TRANSFORMATION_MATRIX_EQ(
7845 container_layer->draw_properties().screen_space_transform,
7846 fixed_layer->draw_properties().screen_space_transform);
7847 EXPECT_VECTOR_EQ(
7848 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7849 container_offset);
7850
7851 container_layer->SetTransform(container_transform);
7852 }
7853
7854 // Scale is applied on the scroll layer itself.
7855 {
7856 gfx::Transform scale_transform;
7857 scale_transform.Scale3d(3.0, 3.0, 1.0);
7858 scroll_layer->SetTransform(scale_transform);
7859
7860 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7861 scroll_layer->SetScrollDelta(scroll_delta);
7862
7863 LayerImplList render_surface_layer_list;
7864 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227865 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]cf15ad7b2014-04-02 03:59:267866 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7867
7868 EXPECT_VECTOR_EQ(
7869 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7870 container_offset);
7871
7872 scroll_layer->SetTransform(identity_transform);
7873 }
[email protected]d81752b2013-10-25 08:32:237874}
7875
miletus2c78036b2015-01-29 20:52:377876TEST_F(LayerTreeHostCommonTest,
7877 ScrollCompensationMainScrollOffsetFractionalPart) {
7878 // This test verifies that a scrolling layer that has fractional scroll offset
7879 // from main doesn't move a fixed position child.
7880 //
7881 // + root
7882 // + container
7883 // + scroller
7884 // + fixed
7885 //
7886 FakeImplProxy proxy;
7887 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:477888 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
miletus2c78036b2015-01-29 20:52:377889 host_impl.CreatePendingTree();
7890 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7891 scoped_ptr<LayerImpl> container =
7892 LayerImpl::Create(host_impl.active_tree(), 2);
7893 LayerImpl* container_layer = container.get();
7894 scoped_ptr<LayerImpl> scroller =
7895 LayerImpl::Create(host_impl.active_tree(), 3);
7896 LayerImpl* scroll_layer = scroller.get();
7897 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7898 LayerImpl* fixed_layer = fixed.get();
7899
7900 container->SetIsContainerForFixedPositionLayers(true);
7901
7902 LayerPositionConstraint constraint;
7903 constraint.set_is_fixed_position(true);
7904 fixed->SetPositionConstraint(constraint);
7905
7906 scroller->SetScrollClipLayer(container->id());
7907
7908 gfx::Transform identity_transform;
7909 gfx::Transform container_transform;
7910 container_transform.Translate3d(10.0, 20.0, 0.0);
7911 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7912
7913 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7914 gfx::PointF(), gfx::Size(50, 50), true, false,
7915 true);
7916 SetLayerPropertiesForTesting(container.get(), container_transform,
7917 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7918 true, false, false);
7919 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7920 gfx::Point3F(), gfx::PointF(0.0, 0.0),
7921 gfx::Size(30, 30), true, false, false);
7922
7923 gfx::ScrollOffset scroll_offset(3.3, 4.2);
7924 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f);
7925 gfx::Vector2dF scroll_delta(0.1f, 0.4f);
7926 // Blink only uses the integer part of the scroll_offset for fixed
7927 // position layer.
7928 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7929 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true,
7930 false, false);
aeliasf998da82015-02-03 01:40:517931 scroll_layer->PushScrollOffsetFromMainThread(scroll_offset);
aeliasd0070ba2015-01-31 13:44:497932 scroll_layer->SetScrollDelta(scroll_delta);
miletusff93ab72015-01-30 04:30:447933 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part);
miletus2c78036b2015-01-29 20:52:377934
7935 scroller->AddChild(fixed.Pass());
7936 container->AddChild(scroller.Pass());
7937 root->AddChild(container.Pass());
7938
7939 LayerImplList render_surface_layer_list;
7940 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7941 root.get(), root->bounds(), &render_surface_layer_list);
7942 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7943
7944 EXPECT_TRANSFORMATION_MATRIX_EQ(
7945 container_layer->draw_properties().screen_space_transform,
7946 fixed_layer->draw_properties().screen_space_transform);
7947 EXPECT_VECTOR_EQ(
7948 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7949 container_offset);
7950
7951 gfx::ScrollOffset effective_scroll_offset =
7952 ScrollOffsetWithDelta(scroll_offset, scroll_delta);
7953 gfx::Vector2d rounded_effective_scroll_offset =
7954 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset));
7955 EXPECT_VECTOR_EQ(
7956 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(),
7957 container_offset - rounded_effective_scroll_offset);
7958}
7959
[email protected]1c3626e2014-04-09 17:49:227960class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7961 public:
7962 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
7963 LayerTreeImpl* tree_impl,
7964 int id) {
7965 return make_scoped_ptr(
7966 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7967 }
7968
dcheng716bedf2014-10-21 09:51:087969 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227970
[email protected]1c3626e2014-04-09 17:49:227971 private:
7972 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7973 int id)
[email protected]a57cb8b12014-06-13 18:15:377974 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227975 SetDrawsContent(true);
7976 }
[email protected]1c3626e2014-04-09 17:49:227977};
7978
7979TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
7980 FakeImplProxy proxy;
7981 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:477982 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]1c3626e2014-04-09 17:49:227983 gfx::Transform identity_matrix;
7984 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
7985 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
7986 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
7987 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
7988 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
7989 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
7990 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
7991 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7992
7993 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7994 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7995 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
7996
danakjf446a072014-09-27 21:55:487997 child->AddChild(grand_child.Pass());
7998 parent->AddChild(child.Pass());
7999 grand_parent->AddChild(parent.Pass());
[email protected]1c3626e2014-04-09 17:49:228000
awoloszyne83f28c2014-12-22 15:40:008001 SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix,
8002 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8003 true, false, true);
8004 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
8005 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:228006 false);
awoloszyne83f28c2014-12-22 15:40:008007 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
8008 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:228009 false);
awoloszyne83f28c2014-12-22 15:40:008010
8011 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
8012 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:228013 false);
8014
8015 ExecuteCalculateDrawProperties(grand_parent.get());
8016
8017 // No layers have animations.
[email protected]a57cb8b12014-06-13 18:15:378018 EXPECT_EQ(0.f,
8019 grand_parent->draw_properties().maximum_animation_contents_scale);
8020 EXPECT_EQ(0.f,
8021 parent_raw->draw_properties().maximum_animation_contents_scale);
8022 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8023 EXPECT_EQ(
8024 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228025
8026 TransformOperations translation;
8027 translation.AppendTranslate(1.f, 2.f, 3.f);
8028
8029 AddAnimatedTransformToLayer(
8030 parent_raw, 1.0, TransformOperations(), translation);
8031
8032 // No layers have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:378033 EXPECT_EQ(0.f,
8034 grand_parent->draw_properties().maximum_animation_contents_scale);
8035 EXPECT_EQ(0.f,
8036 parent_raw->draw_properties().maximum_animation_contents_scale);
8037 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8038 EXPECT_EQ(
8039 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228040
8041 TransformOperations scale;
8042 scale.AppendScale(5.f, 4.f, 3.f);
8043
8044 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
8045 ExecuteCalculateDrawProperties(grand_parent.get());
8046
8047 // Only |child| has a scale-affecting animation.
[email protected]a57cb8b12014-06-13 18:15:378048 EXPECT_EQ(0.f,
8049 grand_parent->draw_properties().maximum_animation_contents_scale);
8050 EXPECT_EQ(0.f,
8051 parent_raw->draw_properties().maximum_animation_contents_scale);
8052 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
8053 EXPECT_EQ(
8054 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228055
8056 AddAnimatedTransformToLayer(
8057 grand_parent.get(), 1.0, TransformOperations(), scale);
8058 ExecuteCalculateDrawProperties(grand_parent.get());
8059
8060 // |grand_parent| and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:378061 EXPECT_EQ(5.f,
8062 grand_parent->draw_properties().maximum_animation_contents_scale);
8063 EXPECT_EQ(5.f,
8064 parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228065 // We don't support combining animated scales from two nodes; 0.f means
8066 // that the maximum scale could not be computed.
[email protected]a57cb8b12014-06-13 18:15:378067 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8068 EXPECT_EQ(
8069 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228070
8071 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
8072 ExecuteCalculateDrawProperties(grand_parent.get());
8073
8074 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:378075 EXPECT_EQ(5.f,
8076 grand_parent->draw_properties().maximum_animation_contents_scale);
8077 EXPECT_EQ(0.f,
8078 parent_raw->draw_properties().maximum_animation_contents_scale);
8079 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8080 EXPECT_EQ(
8081 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228082
8083 grand_parent->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388084 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228085 parent_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388086 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228087 child_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388088 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228089
8090 TransformOperations perspective;
8091 perspective.AppendPerspective(10.f);
8092
8093 AddAnimatedTransformToLayer(
8094 child_raw, 1.0, TransformOperations(), perspective);
8095 ExecuteCalculateDrawProperties(grand_parent.get());
8096
8097 // |child| has a scale-affecting animation but computing the maximum of this
8098 // animation is not supported.
[email protected]a57cb8b12014-06-13 18:15:378099 EXPECT_EQ(0.f,
8100 grand_parent->draw_properties().maximum_animation_contents_scale);
8101 EXPECT_EQ(0.f,
8102 parent_raw->draw_properties().maximum_animation_contents_scale);
8103 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8104 EXPECT_EQ(
8105 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228106
8107 child_raw->layer_animation_controller()->AbortAnimations(
ericrk7c030992015-02-20 01:39:388108 Animation::TRANSFORM);
[email protected]1c3626e2014-04-09 17:49:228109
8110 gfx::Transform scale_matrix;
8111 scale_matrix.Scale(1.f, 2.f);
8112 grand_parent->SetTransform(scale_matrix);
8113 parent_raw->SetTransform(scale_matrix);
8114 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
8115 ExecuteCalculateDrawProperties(grand_parent.get());
8116
8117 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
8118 // animation with maximum scale 5.f.
[email protected]a57cb8b12014-06-13 18:15:378119 EXPECT_EQ(0.f,
8120 grand_parent->draw_properties().maximum_animation_contents_scale);
8121 EXPECT_EQ(10.f,
8122 parent_raw->draw_properties().maximum_animation_contents_scale);
8123 EXPECT_EQ(10.f,
8124 child_raw->draw_properties().maximum_animation_contents_scale);
8125 EXPECT_EQ(
8126 10.f,
8127 grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228128
8129 gfx::Transform perspective_matrix;
8130 perspective_matrix.ApplyPerspectiveDepth(2.f);
8131 child_raw->SetTransform(perspective_matrix);
8132 ExecuteCalculateDrawProperties(grand_parent.get());
8133
8134 // |child| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:378135 EXPECT_EQ(0.f,
8136 grand_parent->draw_properties().maximum_animation_contents_scale);
8137 EXPECT_EQ(10.f,
8138 parent_raw->draw_properties().maximum_animation_contents_scale);
8139 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8140 EXPECT_EQ(
8141 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228142
8143 parent_raw->SetTransform(perspective_matrix);
8144 ExecuteCalculateDrawProperties(grand_parent.get());
8145
8146 // |parent| and |child| have transforms that are neither translations nor
8147 // scales.
[email protected]a57cb8b12014-06-13 18:15:378148 EXPECT_EQ(0.f,
8149 grand_parent->draw_properties().maximum_animation_contents_scale);
8150 EXPECT_EQ(0.f,
8151 parent_raw->draw_properties().maximum_animation_contents_scale);
8152 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8153 EXPECT_EQ(
8154 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228155
8156 parent_raw->SetTransform(identity_matrix);
8157 child_raw->SetTransform(identity_matrix);
8158 grand_parent->SetTransform(perspective_matrix);
8159
8160 ExecuteCalculateDrawProperties(grand_parent.get());
8161
8162 // |grand_parent| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:378163 EXPECT_EQ(0.f,
8164 grand_parent->draw_properties().maximum_animation_contents_scale);
8165 EXPECT_EQ(0.f,
8166 parent_raw->draw_properties().maximum_animation_contents_scale);
8167 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8168 EXPECT_EQ(
8169 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228170}
8171
[email protected]390bb1ff2014-05-09 17:14:408172static int membership_id(LayerImpl* layer) {
8173 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
8174}
8175
8176static void GatherDrawnLayers(LayerImplList* rsll,
8177 std::set<LayerImpl*>* drawn_layers) {
8178 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll),
8179 end = LayerIterator<LayerImpl>::End(rsll);
8180 it != end;
8181 ++it) {
8182 LayerImpl* layer = *it;
8183 if (it.represents_itself())
8184 drawn_layers->insert(layer);
8185
8186 if (!it.represents_contributing_render_surface())
8187 continue;
8188
8189 if (layer->mask_layer())
8190 drawn_layers->insert(layer->mask_layer());
8191 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
8192 drawn_layers->insert(layer->replica_layer()->mask_layer());
8193 }
8194}
8195
8196TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
8197 FakeImplProxy proxy;
8198 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:478199 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]390bb1ff2014-05-09 17:14:408200 gfx::Transform identity_matrix;
8201
8202 scoped_ptr<LayerImpl> grand_parent =
8203 LayerImpl::Create(host_impl.active_tree(), 1);
8204 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
8205 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
8206 scoped_ptr<LayerImpl> grand_child1 =
8207 LayerImpl::Create(host_impl.active_tree(), 7);
8208 scoped_ptr<LayerImpl> grand_child2 =
8209 LayerImpl::Create(host_impl.active_tree(), 9);
8210
8211 LayerImpl* grand_parent_raw = grand_parent.get();
8212 LayerImpl* parent_raw = parent.get();
8213 LayerImpl* child_raw = child.get();
8214 LayerImpl* grand_child1_raw = grand_child1.get();
8215 LayerImpl* grand_child2_raw = grand_child2.get();
8216
8217 child->AddChild(grand_child1.Pass());
8218 child->AddChild(grand_child2.Pass());
8219 parent->AddChild(child.Pass());
8220 grand_parent->AddChild(parent.Pass());
8221
awoloszyne83f28c2014-12-22 15:40:008222 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
8223 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8224 true, false, true);
8225 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
8226 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:408227 false);
awoloszyne83f28c2014-12-22 15:40:008228
8229 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
8230 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:408231 false);
awoloszyne83f28c2014-12-22 15:40:008232
8233 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
8234 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8235 true, false, false);
8236
8237 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
8238 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8239 true, false, false);
[email protected]390bb1ff2014-05-09 17:14:408240
8241 // Start with nothing being drawn.
8242 ExecuteCalculateDrawProperties(grand_parent_raw);
8243 int member_id = render_surface_layer_list_count();
8244
8245 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8246 EXPECT_NE(member_id, membership_id(parent_raw));
8247 EXPECT_NE(member_id, membership_id(child_raw));
8248 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8249 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8250
8251 std::set<LayerImpl*> expected;
8252 std::set<LayerImpl*> actual;
8253 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8254 EXPECT_EQ(expected, actual);
8255
8256 // If we force render surface, but none of the layers are in the layer list,
8257 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:008258 grand_child1_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:408259
8260 ExecuteCalculateDrawProperties(grand_parent_raw);
8261 member_id = render_surface_layer_list_count();
8262
8263 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8264 EXPECT_NE(member_id, membership_id(parent_raw));
8265 EXPECT_NE(member_id, membership_id(child_raw));
8266 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8267 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8268
8269 expected.clear();
8270 actual.clear();
8271 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8272 EXPECT_EQ(expected, actual);
8273
8274 // However, if we say that this layer also draws content, it will appear in
8275 // RSLL.
8276 grand_child1_raw->SetDrawsContent(true);
8277
8278 ExecuteCalculateDrawProperties(grand_parent_raw);
8279 member_id = render_surface_layer_list_count();
8280
8281 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8282 EXPECT_NE(member_id, membership_id(parent_raw));
8283 EXPECT_NE(member_id, membership_id(child_raw));
8284 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
8285 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8286
8287 expected.clear();
8288 expected.insert(grand_child1_raw);
8289
8290 actual.clear();
8291 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8292 EXPECT_EQ(expected, actual);
8293
8294 // Now child is forced to have a render surface, and one if its children draws
8295 // content.
8296 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:008297 grand_child1_raw->SetHasRenderSurface(false);
8298 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:408299 grand_child2_raw->SetDrawsContent(true);
8300
8301 ExecuteCalculateDrawProperties(grand_parent_raw);
8302 member_id = render_surface_layer_list_count();
8303
8304 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8305 EXPECT_NE(member_id, membership_id(parent_raw));
8306 EXPECT_NE(member_id, membership_id(child_raw));
8307 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8308 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8309
8310 expected.clear();
8311 expected.insert(grand_child2_raw);
8312
8313 actual.clear();
8314 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8315 EXPECT_EQ(expected, actual);
8316
8317 // Add a mask layer to child.
8318 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass());
8319
8320 ExecuteCalculateDrawProperties(grand_parent_raw);
8321 member_id = render_surface_layer_list_count();
8322
8323 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8324 EXPECT_NE(member_id, membership_id(parent_raw));
8325 EXPECT_NE(member_id, membership_id(child_raw));
8326 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8327 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8328 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8329
8330 expected.clear();
8331 expected.insert(grand_child2_raw);
8332 expected.insert(child_raw->mask_layer());
8333
8334 expected.clear();
8335 expected.insert(grand_child2_raw);
8336 expected.insert(child_raw->mask_layer());
8337
8338 actual.clear();
8339 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8340 EXPECT_EQ(expected, actual);
8341
8342 // Add replica mask layer.
8343 scoped_ptr<LayerImpl> replica_layer =
8344 LayerImpl::Create(host_impl.active_tree(), 20);
8345 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
8346 child_raw->SetReplicaLayer(replica_layer.Pass());
8347
8348 ExecuteCalculateDrawProperties(grand_parent_raw);
8349 member_id = render_surface_layer_list_count();
8350
8351 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8352 EXPECT_NE(member_id, membership_id(parent_raw));
8353 EXPECT_NE(member_id, membership_id(child_raw));
8354 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8355 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
8356 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8357 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8358
8359 expected.clear();
8360 expected.insert(grand_child2_raw);
8361 expected.insert(child_raw->mask_layer());
8362 expected.insert(child_raw->replica_layer()->mask_layer());
8363
8364 actual.clear();
8365 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8366 EXPECT_EQ(expected, actual);
8367
8368 child_raw->TakeReplicaLayer();
8369
8370 // With nothing drawing, we should have no layers.
8371 grand_child2_raw->SetDrawsContent(false);
8372
8373 ExecuteCalculateDrawProperties(grand_parent_raw);
8374 member_id = render_surface_layer_list_count();
8375
8376 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8377 EXPECT_NE(member_id, membership_id(parent_raw));
8378 EXPECT_NE(member_id, membership_id(child_raw));
8379 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
8380 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8381 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8382
8383 expected.clear();
8384 actual.clear();
8385 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8386 EXPECT_EQ(expected, actual);
8387
8388 // Child itself draws means that we should have the child and the mask in the
8389 // list.
8390 child_raw->SetDrawsContent(true);
8391
8392 ExecuteCalculateDrawProperties(grand_parent_raw);
8393 member_id = render_surface_layer_list_count();
8394
8395 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8396 EXPECT_NE(member_id, membership_id(parent_raw));
8397 EXPECT_EQ(member_id, membership_id(child_raw));
8398 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8399 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8400 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8401
8402 expected.clear();
8403 expected.insert(child_raw);
8404 expected.insert(child_raw->mask_layer());
8405 actual.clear();
8406 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8407 EXPECT_EQ(expected, actual);
8408
8409 child_raw->TakeMaskLayer();
8410
8411 // Now everyone's a member!
8412 grand_parent_raw->SetDrawsContent(true);
8413 parent_raw->SetDrawsContent(true);
8414 child_raw->SetDrawsContent(true);
8415 grand_child1_raw->SetDrawsContent(true);
8416 grand_child2_raw->SetDrawsContent(true);
8417
8418 ExecuteCalculateDrawProperties(grand_parent_raw);
8419 member_id = render_surface_layer_list_count();
8420
8421 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
8422 EXPECT_EQ(member_id, membership_id(parent_raw));
8423 EXPECT_EQ(member_id, membership_id(child_raw));
8424 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
8425 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8426
8427 expected.clear();
8428 expected.insert(grand_parent_raw);
8429 expected.insert(parent_raw);
8430 expected.insert(child_raw);
8431 expected.insert(grand_child1_raw);
8432 expected.insert(grand_child2_raw);
8433
8434 actual.clear();
8435 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8436 EXPECT_EQ(expected, actual);
8437}
[email protected]18e69652014-06-13 12:50:588438
8439TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
8440 FakeImplProxy proxy;
8441 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:478442 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
[email protected]18e69652014-06-13 12:50:588443
8444 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
8445 LayerImpl* root_layer = root.get();
8446 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
8447 LayerImpl* child1_layer = child1.get();
8448 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
8449 LayerImpl* child2_layer = child2.get();
8450
8451 root->AddChild(child1.Pass());
8452 root->AddChild(child2.Pass());
awoloszyne83f28c2014-12-22 15:40:008453 root->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588454
8455 gfx::Transform identity_matrix, scale_transform_child1,
8456 scale_transform_child2;
8457 scale_transform_child1.Scale(2, 3);
8458 scale_transform_child2.Scale(4, 5);
8459
awoloszyne83f28c2014-12-22 15:40:008460 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
8461 gfx::PointF(), gfx::Size(1, 1), true, false,
8462 true);
8463 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
8464 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8465 false, false);
[email protected]18e69652014-06-13 12:50:588466
8467 child1_layer->SetMaskLayer(
8468 LayerImpl::Create(host_impl.active_tree(), 4).Pass());
8469
8470 scoped_ptr<LayerImpl> replica_layer =
8471 LayerImpl::Create(host_impl.active_tree(), 5);
awoloszyne83f28c2014-12-22 15:40:008472 replica_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588473 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
8474 child1_layer->SetReplicaLayer(replica_layer.Pass());
awoloszyne83f28c2014-12-22 15:40:008475 child1_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588476
8477 ExecuteCalculateDrawProperties(root_layer);
8478
8479 TransformOperations scale;
8480 scale.AppendScale(5.f, 8.f, 3.f);
8481
8482 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale);
awoloszyne83f28c2014-12-22 15:40:008483 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
8484 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8485 false, false);
[email protected]18e69652014-06-13 12:50:588486
8487 ExecuteCalculateDrawProperties(root_layer);
8488
8489 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale);
8490 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale);
8491 EXPECT_FLOAT_EQ(
8492 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8493 EXPECT_FLOAT_EQ(3.f,
8494 child1_layer->replica_layer()
8495 ->mask_layer()
8496 ->draw_properties()
8497 .ideal_contents_scale);
8498 EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale);
8499
8500 EXPECT_FLOAT_EQ(
8501 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8502 EXPECT_FLOAT_EQ(
8503 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8504 EXPECT_FLOAT_EQ(0.f,
8505 child1_layer->mask_layer()
8506 ->draw_properties()
8507 .maximum_animation_contents_scale);
8508 EXPECT_FLOAT_EQ(0.f,
8509 child1_layer->replica_layer()
8510 ->mask_layer()
8511 ->draw_properties()
8512 .maximum_animation_contents_scale);
8513 EXPECT_FLOAT_EQ(
8514 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8515
8516 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8517 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor);
8518 EXPECT_FLOAT_EQ(
8519 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8520 EXPECT_FLOAT_EQ(1.f,
8521 child1_layer->replica_layer()
8522 ->mask_layer()
8523 ->draw_properties()
8524 .page_scale_factor);
8525 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor);
8526
8527 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor);
8528 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor);
8529 EXPECT_FLOAT_EQ(
8530 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8531 EXPECT_FLOAT_EQ(1.f,
8532 child1_layer->replica_layer()
8533 ->mask_layer()
8534 ->draw_properties()
8535 .device_scale_factor);
8536 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor);
8537
8538 // Changing page-scale would affect ideal_contents_scale and
8539 // maximum_animation_contents_scale.
8540
8541 float page_scale_factor = 3.f;
8542 float device_scale_factor = 1.0f;
8543 std::vector<LayerImpl*> render_surface_layer_list;
8544 gfx::Size device_viewport_size =
8545 gfx::Size(root_layer->bounds().width() * device_scale_factor,
8546 root_layer->bounds().height() * device_scale_factor);
8547 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8548 root_layer, device_viewport_size, &render_surface_layer_list);
8549
8550 inputs.page_scale_factor = page_scale_factor;
8551 inputs.can_adjust_raster_scales = true;
8552 inputs.page_scale_application_layer = root_layer;
8553 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8554
8555 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale);
8556 EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale);
8557 EXPECT_FLOAT_EQ(
8558 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8559 EXPECT_FLOAT_EQ(9.f,
8560 child1_layer->replica_layer()
8561 ->mask_layer()
8562 ->draw_properties()
8563 .ideal_contents_scale);
8564 EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale);
8565
8566 EXPECT_FLOAT_EQ(
8567 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8568 EXPECT_FLOAT_EQ(
8569 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8570 EXPECT_FLOAT_EQ(0.f,
8571 child1_layer->mask_layer()
8572 ->draw_properties()
8573 .maximum_animation_contents_scale);
8574 EXPECT_FLOAT_EQ(0.f,
8575 child1_layer->replica_layer()
8576 ->mask_layer()
8577 ->draw_properties()
8578 .maximum_animation_contents_scale);
8579 EXPECT_FLOAT_EQ(
8580 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8581
8582 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8583 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor);
8584 EXPECT_FLOAT_EQ(
8585 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8586 EXPECT_FLOAT_EQ(3.f,
8587 child1_layer->replica_layer()
8588 ->mask_layer()
8589 ->draw_properties()
8590 .page_scale_factor);
8591 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor);
8592
8593 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor);
8594 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor);
8595 EXPECT_FLOAT_EQ(
8596 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8597 EXPECT_FLOAT_EQ(1.f,
8598 child1_layer->replica_layer()
8599 ->mask_layer()
8600 ->draw_properties()
8601 .device_scale_factor);
8602 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor);
8603
8604 // Changing device-scale would affect ideal_contents_scale and
8605 // maximum_animation_contents_scale.
8606
8607 device_scale_factor = 4.0f;
8608 inputs.device_scale_factor = device_scale_factor;
8609 inputs.can_adjust_raster_scales = true;
8610 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8611
8612 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale);
8613 EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale);
8614 EXPECT_FLOAT_EQ(
8615 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8616 EXPECT_FLOAT_EQ(36.f,
8617 child1_layer->replica_layer()
8618 ->mask_layer()
8619 ->draw_properties()
8620 .ideal_contents_scale);
8621 EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale);
8622
8623 EXPECT_FLOAT_EQ(
8624 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8625 EXPECT_FLOAT_EQ(
8626 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8627 EXPECT_FLOAT_EQ(0.f,
8628 child1_layer->mask_layer()
8629 ->draw_properties()
8630 .maximum_animation_contents_scale);
8631 EXPECT_FLOAT_EQ(0.f,
8632 child1_layer->replica_layer()
8633 ->mask_layer()
8634 ->draw_properties()
8635 .maximum_animation_contents_scale);
8636 EXPECT_FLOAT_EQ(
8637 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8638
8639 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8640 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor);
8641 EXPECT_FLOAT_EQ(
8642 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8643 EXPECT_FLOAT_EQ(3.f,
8644 child1_layer->replica_layer()
8645 ->mask_layer()
8646 ->draw_properties()
8647 .page_scale_factor);
8648 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor);
8649
8650 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor);
8651 EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor);
8652 EXPECT_FLOAT_EQ(
8653 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8654 EXPECT_FLOAT_EQ(4.f,
8655 child1_layer->replica_layer()
8656 ->mask_layer()
8657 ->draw_properties()
8658 .device_scale_factor);
8659 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor);
8660}
8661
danakjf6069db2014-09-13 00:46:478662TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
8663 scoped_refptr<Layer> root = Layer::Create();
8664 SetLayerPropertiesForTesting(root.get(),
8665 gfx::Transform(),
8666 gfx::Point3F(),
8667 gfx::PointF(),
8668 gfx::Size(768 / 2, 3000),
8669 true,
8670 false);
8671 root->SetIsDrawable(true);
8672
8673 scoped_refptr<Layer> clip = Layer::Create();
8674 SetLayerPropertiesForTesting(clip.get(),
8675 gfx::Transform(),
8676 gfx::Point3F(),
8677 gfx::PointF(),
8678 gfx::Size(768 / 2, 10000),
8679 true,
8680 false);
8681 clip->SetMasksToBounds(true);
8682
8683 scoped_refptr<Layer> content = Layer::Create();
8684 SetLayerPropertiesForTesting(content.get(),
8685 gfx::Transform(),
8686 gfx::Point3F(),
8687 gfx::PointF(),
8688 gfx::Size(768 / 2, 10000),
8689 true,
8690 false);
8691 content->SetIsDrawable(true);
8692 content->SetForceRenderSurface(true);
8693
8694 root->AddChild(clip);
8695 clip->AddChild(content);
8696
enne2097cab2014-09-25 20:16:318697 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
8698 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
danakjf6069db2014-09-13 00:46:478699 host->SetRootLayer(root);
8700
8701 gfx::Size device_viewport_size(768, 582);
8702 RenderSurfaceLayerList render_surface_layer_list;
8703 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8704 host->root_layer(), device_viewport_size, &render_surface_layer_list);
8705 inputs.device_scale_factor = 2.f;
8706 inputs.page_scale_factor = 1.f;
8707 inputs.page_scale_application_layer = NULL;
8708 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8709
8710 // Layers in the root render surface have their visible content rect clipped
8711 // by the viewport.
8712 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect());
8713
8714 // Layers drawing to a child render surface should still have their visible
8715 // content rect clipped by the viewport.
8716 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect());
8717}
8718
timav599f4359d2014-12-05 00:12:228719TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
8720 FakeImplProxy proxy;
8721 TestSharedBitmapManager shared_bitmap_manager;
reveman34b7a1522015-03-23 20:27:478722 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager, nullptr);
timav599f4359d2014-12-05 00:12:228723
8724 // Set two layers: the root layer clips it's child,
8725 // the child draws its content.
8726
8727 gfx::Size root_size = gfx::Size(300, 500);
8728
8729 // Sublayer should be bigger than the root enlarged by bounds_delta.
8730 gfx::Size sublayer_size = gfx::Size(300, 1000);
8731
8732 // Device viewport accomidated the root and the top controls.
8733 gfx::Size device_viewport_size = gfx::Size(300, 600);
8734 gfx::Transform identity_matrix;
8735
8736 host_impl.active_tree()->SetRootLayer(
8737 LayerImpl::Create(host_impl.active_tree(), 1));
8738
8739 LayerImpl* root = host_impl.active_tree()->root_layer();
8740 SetLayerPropertiesForTesting(root,
8741 identity_matrix,
8742 gfx::Point3F(),
8743 gfx::PointF(),
8744 root_size,
8745 false,
awoloszyne83f28c2014-12-22 15:40:008746 false,
8747 true);
timav599f4359d2014-12-05 00:12:228748
8749 root->SetContentBounds(root_size);
8750 root->SetMasksToBounds(true);
8751
8752 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
8753
8754 LayerImpl* sublayer = root->child_at(0);
8755 SetLayerPropertiesForTesting(sublayer,
8756 identity_matrix,
8757 gfx::Point3F(),
8758 gfx::PointF(),
8759 sublayer_size,
8760 false,
awoloszyne83f28c2014-12-22 15:40:008761 false,
timav599f4359d2014-12-05 00:12:228762 false);
8763
8764 sublayer->SetContentBounds(sublayer_size);
8765 sublayer->SetDrawsContent(true);
8766
8767 LayerImplList layer_impl_list;
8768 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8769 root, device_viewport_size, &layer_impl_list);
8770
8771 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8772
8773 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_content_rect());
8774
8775 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
8776
8777 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8778
8779 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8780 root_size.height() + 50);
8781 EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect());
8782}
8783
vollick7d83b452015-02-24 20:18:068784TEST_F(LayerTreeHostCommonTest, VisibleContentRectForAnimatedLayer) {
8785 const gfx::Transform identity_matrix;
8786 scoped_refptr<Layer> root = Layer::Create();
8787 scoped_refptr<LayerWithForcedDrawsContent> animated =
8788 make_scoped_refptr(new LayerWithForcedDrawsContent());
8789
8790 root->AddChild(animated);
8791
8792 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8793 host->SetRootLayer(root);
8794
8795 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
8796 gfx::PointF(), gfx::Size(100, 100), true, false);
8797 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(),
8798 gfx::PointF(), gfx::Size(20, 20), true, false);
8799
8800 root->SetMasksToBounds(true);
8801 root->SetForceRenderSurface(true);
8802 animated->SetOpacity(0.f);
8803
8804 AddOpacityTransitionToController(animated->layer_animation_controller(), 10.0,
8805 0.f, 1.f, false);
8806
8807 ExecuteCalculateDrawProperties(root.get());
8808
8809 EXPECT_FALSE(animated->visible_rect_from_property_trees().IsEmpty());
8810}
8811
enne92f2f6d92015-02-25 23:13:318812// Verify that having an animated filter (but no current filter, as these
8813// are mutually exclusive) correctly creates a render surface.
8814TEST_F(LayerTreeHostCommonTest, AnimatedFilterCreatesRenderSurface) {
8815 scoped_refptr<Layer> root = Layer::Create();
8816 scoped_refptr<Layer> child = Layer::Create();
8817 scoped_refptr<Layer> grandchild = Layer::Create();
8818 root->AddChild(child);
8819 child->AddChild(grandchild);
8820
8821 gfx::Transform identity_transform;
8822 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8823 gfx::PointF(), gfx::Size(50, 50), true, false);
8824 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8825 gfx::PointF(), gfx::Size(50, 50), true, false);
8826 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8827 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
8828 true, false);
8829 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8830 host->SetRootLayer(root);
8831
8832 AddAnimatedFilterToLayer(child.get(), 10.0, 0.1f, 0.2f);
8833
8834 ExecuteCalculateDrawProperties(root.get());
8835
8836 EXPECT_TRUE(root->render_surface());
8837 EXPECT_TRUE(child->render_surface());
8838 EXPECT_FALSE(grandchild->render_surface());
8839
8840 EXPECT_TRUE(root->filters().IsEmpty());
8841 EXPECT_TRUE(child->filters().IsEmpty());
8842 EXPECT_TRUE(grandchild->filters().IsEmpty());
8843
8844 EXPECT_FALSE(root->FilterIsAnimating());
8845 EXPECT_TRUE(child->FilterIsAnimating());
8846 EXPECT_FALSE(grandchild->FilterIsAnimating());
8847}
8848
vollick0120eb22015-03-02 03:07:348849// Ensures that the property tree code accounts for offsets between fixed
8850// position layers and their respective containers.
8851TEST_F(LayerTreeHostCommonTest, PropertyTreesAccountForFixedParentOffset) {
8852 scoped_refptr<Layer> root = Layer::Create();
8853 scoped_refptr<Layer> child = Layer::Create();
8854 scoped_refptr<LayerWithForcedDrawsContent> grandchild =
8855 make_scoped_refptr(new LayerWithForcedDrawsContent());
8856
8857 root->AddChild(child);
8858 child->AddChild(grandchild);
8859
8860 gfx::Transform identity_transform;
8861 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
8862 gfx::PointF(), gfx::Size(50, 50), true, false);
8863 SetLayerPropertiesForTesting(child.get(), identity_transform, gfx::Point3F(),
8864 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
8865 false);
8866 SetLayerPropertiesForTesting(grandchild.get(), identity_transform,
8867 gfx::Point3F(), gfx::PointF(-1000, -1000),
8868 gfx::Size(50, 50), true, false);
8869
8870 root->SetMasksToBounds(true);
8871 root->SetIsContainerForFixedPositionLayers(true);
8872 LayerPositionConstraint constraint;
8873 constraint.set_is_fixed_position(true);
8874 grandchild->SetPositionConstraint(constraint);
8875
8876 root->SetIsContainerForFixedPositionLayers(true);
8877
8878 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8879 host->SetRootLayer(root);
8880
8881 ExecuteCalculateDrawProperties(root.get());
8882
8883 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
8884 grandchild->visible_rect_from_property_trees());
8885}
8886
vollick67394b42015-03-10 00:22:308887TEST_F(LayerTreeHostCommonTest, CombineClipsUsingContentTarget) {
8888 // In the following layer tree, the layer |box|'s render target is |surface|.
8889 // |surface| also creates a transform node. We want to combine clips for |box|
8890 // in the space of its target (i.e., |surface|), not its target's target. This
8891 // test ensures that happens.
8892
8893 gfx::Transform rotate;
8894 rotate.Rotate(5);
8895 gfx::Transform identity;
8896
8897 scoped_refptr<Layer> root = Layer::Create();
8898 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8899 gfx::PointF(), gfx::Size(2500, 1500), true,
8900 false);
8901
8902 scoped_refptr<Layer> frame_clip = Layer::Create();
8903 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(),
8904 gfx::PointF(), gfx::Size(2500, 1500), true,
8905 false);
8906 frame_clip->SetMasksToBounds(true);
8907
8908 scoped_refptr<Layer> rotated = Layer::Create();
8909 SetLayerPropertiesForTesting(rotated.get(), rotate,
8910 gfx::Point3F(1250, 250, 0), gfx::PointF(),
8911 gfx::Size(2500, 500), true, false);
8912
8913 scoped_refptr<Layer> surface = Layer::Create();
8914 SetLayerPropertiesForTesting(surface.get(), rotate, gfx::Point3F(),
8915 gfx::PointF(), gfx::Size(2500, 500), true,
8916 false);
8917 surface->SetOpacity(0.5);
8918
8919 scoped_refptr<LayerWithForcedDrawsContent> container =
8920 make_scoped_refptr(new LayerWithForcedDrawsContent());
8921 SetLayerPropertiesForTesting(container.get(), identity, gfx::Point3F(),
8922 gfx::PointF(), gfx::Size(300, 300), true, false);
8923
8924 scoped_refptr<LayerWithForcedDrawsContent> box =
8925 make_scoped_refptr(new LayerWithForcedDrawsContent());
8926 SetLayerPropertiesForTesting(box.get(), identity, gfx::Point3F(),
8927 gfx::PointF(), gfx::Size(100, 100), true, false);
8928
8929 root->AddChild(frame_clip);
8930 frame_clip->AddChild(rotated);
8931 rotated->AddChild(surface);
8932 surface->AddChild(container);
8933 surface->AddChild(box);
8934
8935 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8936 host->SetRootLayer(root);
8937
8938 ExecuteCalculateDrawProperties(root.get());
8939}
8940
vollick8c824742015-03-20 22:21:088941TEST_F(LayerTreeHostCommonTest, OnlyApplyFixedPositioningOnce) {
8942 gfx::Transform identity;
8943 gfx::Transform translate_z;
8944 translate_z.Translate3d(0, 0, 10);
8945
8946 scoped_refptr<Layer> root = Layer::Create();
8947 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(),
8948 gfx::PointF(), gfx::Size(800, 800), true, false);
8949 root->SetIsContainerForFixedPositionLayers(true);
8950
8951 scoped_refptr<Layer> frame_clip = Layer::Create();
8952 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(),
8953 gfx::PointF(500, 100), gfx::Size(100, 100), true,
8954 false);
8955 frame_clip->SetMasksToBounds(true);
8956
8957 scoped_refptr<LayerWithForcedDrawsContent> fixed =
8958 make_scoped_refptr(new LayerWithForcedDrawsContent());
8959 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(),
8960 gfx::PointF(), gfx::Size(1000, 1000), true,
8961 false);
8962
8963 LayerPositionConstraint constraint;
8964 constraint.set_is_fixed_position(true);
8965 fixed->SetPositionConstraint(constraint);
8966
8967 root->AddChild(frame_clip);
8968 frame_clip->AddChild(fixed);
8969
8970 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
8971 host->SetRootLayer(root);
8972
8973 ExecuteCalculateDrawProperties(root.get());
8974
8975 gfx::Rect expected(0, 0, 100, 100);
8976 EXPECT_EQ(expected, fixed->visible_rect_from_property_trees());
8977}
8978
[email protected]ba565742012-11-10 09:29:488979} // namespace
8980} // namespace cc