blob: daf7d5b97415390111cc18fbca29dba752a86279 [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"
[email protected]556fd292013-03-18 08:03:0431#include "cc/trees/layer_tree_impl.h"
32#include "cc/trees/proxy.h"
33#include "cc/trees/single_thread_proxy.h"
[email protected]7f0c53db2012-10-02 00:23:1834#include "testing/gmock/include/gmock/gmock.h"
35#include "testing/gtest/include/gtest/gtest.h"
heejin.r.chungd28506ba2014-10-23 16:36:2036#include "ui/gfx/geometry/quad_f.h"
miletus2c78036b2015-01-29 20:52:3737#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]c8686a02012-11-27 08:29:0038#include "ui/gfx/transform.h"
[email protected]94f206c12012-08-25 00:09:1439
[email protected]ba565742012-11-10 09:29:4840namespace cc {
[email protected]94f206c12012-08-25 00:09:1441namespace {
42
[email protected]96baf3e2012-10-22 23:09:5543class LayerWithForcedDrawsContent : public Layer {
[email protected]fb661802013-03-25 01:59:3244 public:
[email protected]35322352014-08-08 01:36:2045 LayerWithForcedDrawsContent() {}
[email protected]94f206c12012-08-25 00:09:1446
dcheng716bedf2014-10-21 09:51:0847 bool DrawsContent() const override;
[email protected]d58499a2012-10-09 22:27:4748
[email protected]fb661802013-03-25 01:59:3249 private:
dcheng716bedf2014-10-21 09:51:0850 ~LayerWithForcedDrawsContent() override {}
[email protected]94f206c12012-08-25 00:09:1451};
52
[email protected]fb661802013-03-25 01:59:3253bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
[email protected]aedf4e52013-01-09 23:24:4454
[email protected]96baf3e2012-10-22 23:09:5555class MockContentLayerClient : public ContentLayerClient {
[email protected]fb661802013-03-25 01:59:3256 public:
57 MockContentLayerClient() {}
dcheng716bedf2014-10-21 09:51:0858 ~MockContentLayerClient() override {}
59 void PaintContents(
[email protected]276172b2014-05-02 21:03:0360 SkCanvas* canvas,
61 const gfx::Rect& clip,
mostynbf68776d82014-10-06 18:07:3762 ContentLayerClient::GraphicsContextStatus gc_status) override {}
ajuma5e77f7d42014-11-27 14:19:1463 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
64 const gfx::Rect& clip,
65 GraphicsContextStatus gc_status) override {
66 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;
319 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[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());
351 scroll_layer_raw_ptr->SetScrollOffset(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());
1010
1011 gfx::Transform rotation_about_y_axis;
1012 rotation_about_y_axis.RotateAboutYAxis(30.0);
1013
1014 const gfx::Transform identity_matrix;
1015 SetLayerPropertiesForTesting(root.get(),
1016 identity_matrix,
[email protected]a2566412014-06-05 03:14:201017 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321018 gfx::PointF(),
1019 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571020 true,
[email protected]fb661802013-03-25 01:59:321021 false);
1022 SetLayerPropertiesForTesting(child.get(),
1023 rotation_about_y_axis,
[email protected]a2566412014-06-05 03:14:201024 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321025 gfx::PointF(),
1026 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571027 true,
[email protected]fb661802013-03-25 01:59:321028 false);
1029 SetLayerPropertiesForTesting(grand_child.get(),
1030 rotation_about_y_axis,
[email protected]a2566412014-06-05 03:14:201031 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321032 gfx::PointF(),
1033 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571034 true,
[email protected]fb661802013-03-25 01:59:321035 false);
1036
1037 root->AddChild(child);
1038 child->AddChild(grand_child);
1039 child->SetForceRenderSurface(true);
1040
enne2097cab2014-09-25 20:16:311041 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281042 host->SetRootLayer(root);
1043
[email protected]fb661802013-03-25 01:59:321044 // No layers in this test should preserve 3d.
[email protected]56fffdd2014-02-11 19:50:571045 ASSERT_TRUE(root->should_flatten_transform());
1046 ASSERT_TRUE(child->should_flatten_transform());
1047 ASSERT_TRUE(grand_child->should_flatten_transform());
[email protected]fb661802013-03-25 01:59:321048
1049 gfx::Transform expected_child_draw_transform = rotation_about_y_axis;
1050 gfx::Transform expected_child_screen_space_transform = rotation_about_y_axis;
1051 gfx::Transform expected_grand_child_draw_transform =
1052 rotation_about_y_axis; // draws onto child's render surface
1053 gfx::Transform flattened_rotation_about_y = rotation_about_y_axis;
1054 flattened_rotation_about_y.FlattenTo2d();
1055 gfx::Transform expected_grand_child_screen_space_transform =
1056 flattened_rotation_about_y * rotation_about_y_axis;
1057
1058 ExecuteCalculateDrawProperties(root.get());
1059
1060 // The child's draw transform should have been taken by its surface.
1061 ASSERT_TRUE(child->render_surface());
1062 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform,
1063 child->render_surface()->draw_transform());
1064 EXPECT_TRANSFORMATION_MATRIX_EQ(
1065 expected_child_screen_space_transform,
1066 child->render_surface()->screen_space_transform());
1067 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1068 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform,
1069 child->screen_space_transform());
1070 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform,
1071 grand_child->draw_transform());
1072 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform,
1073 grand_child->screen_space_transform());
1074}
1075
[email protected]989386c2013-07-18 21:37:231076TEST_F(LayerTreeHostCommonTest, TransformsForDegenerateIntermediateLayer) {
[email protected]fb661802013-03-25 01:59:321077 // A layer that is empty in one axis, but not the other, was accidentally
1078 // skipping a necessary translation. Without that translation, the coordinate
1079 // space of the layer's draw transform is incorrect.
1080 //
1081 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1082 // but if that layer becomes a render surface, then its draw transform is
1083 // implicitly inherited by the rest of the subtree, which then is positioned
1084 // incorrectly as a result.
1085
1086 scoped_refptr<Layer> root = Layer::Create();
1087 scoped_refptr<Layer> child = Layer::Create();
1088 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
1089 make_scoped_refptr(new LayerWithForcedDrawsContent());
1090
1091 // The child height is zero, but has non-zero width that should be accounted
1092 // for while computing draw transforms.
1093 const gfx::Transform identity_matrix;
1094 SetLayerPropertiesForTesting(root.get(),
1095 identity_matrix,
[email protected]a2566412014-06-05 03:14:201096 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321097 gfx::PointF(),
1098 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571099 true,
[email protected]fb661802013-03-25 01:59:321100 false);
1101 SetLayerPropertiesForTesting(child.get(),
1102 identity_matrix,
[email protected]a2566412014-06-05 03:14:201103 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321104 gfx::PointF(),
1105 gfx::Size(10, 0),
[email protected]56fffdd2014-02-11 19:50:571106 true,
[email protected]fb661802013-03-25 01:59:321107 false);
1108 SetLayerPropertiesForTesting(grand_child.get(),
1109 identity_matrix,
[email protected]a2566412014-06-05 03:14:201110 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321111 gfx::PointF(),
1112 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571113 true,
[email protected]fb661802013-03-25 01:59:321114 false);
1115
1116 root->AddChild(child);
1117 child->AddChild(grand_child);
1118 child->SetForceRenderSurface(true);
1119
enne2097cab2014-09-25 20:16:311120 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281121 host->SetRootLayer(root);
1122
[email protected]fb661802013-03-25 01:59:321123 ExecuteCalculateDrawProperties(root.get());
1124
1125 ASSERT_TRUE(child->render_surface());
1126 // This is the real test, the rest are sanity checks.
1127 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1128 child->render_surface()->draw_transform());
1129 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform());
1130 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix,
1131 grand_child->draw_transform());
1132}
1133
[email protected]989386c2013-07-18 21:37:231134TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) {
[email protected]f224cc92013-06-06 23:23:321135 // Transformations applied at the root of the tree should be forwarded
1136 // to child layers instead of applied to the root RenderSurface.
1137 const gfx::Transform identity_matrix;
[email protected]d5754282014-04-09 00:43:291138 scoped_refptr<LayerWithForcedDrawsContent> root =
1139 new LayerWithForcedDrawsContent;
1140 scoped_refptr<LayerWithForcedDrawsContent> child =
1141 new LayerWithForcedDrawsContent;
[email protected]adeda572014-01-31 00:49:471142 child->SetScrollClipLayerId(root->id());
[email protected]f224cc92013-06-06 23:23:321143 root->AddChild(child);
1144
enne2097cab2014-09-25 20:16:311145 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281146 host->SetRootLayer(root);
1147
[email protected]f224cc92013-06-06 23:23:321148 SetLayerPropertiesForTesting(root.get(),
1149 identity_matrix,
[email protected]a2566412014-06-05 03:14:201150 gfx::Point3F(),
[email protected]f224cc92013-06-06 23:23:321151 gfx::PointF(),
1152 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571153 true,
[email protected]f224cc92013-06-06 23:23:321154 false);
1155 SetLayerPropertiesForTesting(child.get(),
1156 identity_matrix,
[email protected]a2566412014-06-05 03:14:201157 gfx::Point3F(),
[email protected]f224cc92013-06-06 23:23:321158 gfx::PointF(),
1159 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571160 true,
[email protected]f224cc92013-06-06 23:23:321161 false);
1162
[email protected]f224cc92013-06-06 23:23:321163 gfx::Transform translate;
1164 translate.Translate(50, 50);
[email protected]989386c2013-07-18 21:37:231165 {
1166 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531167 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221168 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531169 inputs.can_adjust_raster_scales = true;
1170 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231171 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1172 EXPECT_EQ(translate, child->draw_properties().target_space_transform);
1173 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201174 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1175 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231176 }
[email protected]f224cc92013-06-06 23:23:321177
1178 gfx::Transform scale;
1179 scale.Scale(2, 2);
[email protected]989386c2013-07-18 21:37:231180 {
1181 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531182 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221183 root.get(), root->bounds(), scale, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531184 inputs.can_adjust_raster_scales = true;
1185 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231186 EXPECT_EQ(scale, root->draw_properties().target_space_transform);
1187 EXPECT_EQ(scale, child->draw_properties().target_space_transform);
1188 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201189 EXPECT_EQ(2.f, root->draw_properties().device_scale_factor);
1190 EXPECT_EQ(2.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231191 }
[email protected]f224cc92013-06-06 23:23:321192
1193 gfx::Transform rotate;
1194 rotate.Rotate(2);
[email protected]989386c2013-07-18 21:37:231195 {
1196 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531197 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221198 root.get(), root->bounds(), rotate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531199 inputs.can_adjust_raster_scales = true;
1200 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231201 EXPECT_EQ(rotate, root->draw_properties().target_space_transform);
1202 EXPECT_EQ(rotate, child->draw_properties().target_space_transform);
1203 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201204 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1205 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231206 }
[email protected]f224cc92013-06-06 23:23:321207
1208 gfx::Transform composite;
1209 composite.ConcatTransform(translate);
1210 composite.ConcatTransform(scale);
1211 composite.ConcatTransform(rotate);
[email protected]989386c2013-07-18 21:37:231212 {
1213 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531214 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221215 root.get(), root->bounds(), composite, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531216 inputs.can_adjust_raster_scales = true;
1217 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231218 EXPECT_EQ(composite, root->draw_properties().target_space_transform);
1219 EXPECT_EQ(composite, child->draw_properties().target_space_transform);
1220 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1221 }
[email protected]f224cc92013-06-06 23:23:321222
[email protected]9781afa2013-07-17 23:15:321223 // Verify it composes correctly with device scale.
1224 float device_scale_factor = 1.5f;
[email protected]989386c2013-07-18 21:37:231225
1226 {
1227 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531228 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221229 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531230 inputs.device_scale_factor = device_scale_factor;
1231 inputs.can_adjust_raster_scales = true;
1232 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231233 gfx::Transform device_scaled_translate = translate;
1234 device_scaled_translate.Scale(device_scale_factor, device_scale_factor);
1235 EXPECT_EQ(device_scaled_translate,
1236 root->draw_properties().target_space_transform);
1237 EXPECT_EQ(device_scaled_translate,
1238 child->draw_properties().target_space_transform);
1239 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201240 EXPECT_EQ(device_scale_factor, root->draw_properties().device_scale_factor);
1241 EXPECT_EQ(device_scale_factor,
1242 child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231243 }
[email protected]9781afa2013-07-17 23:15:321244
1245 // Verify it composes correctly with page scale.
1246 float page_scale_factor = 2.f;
[email protected]989386c2013-07-18 21:37:231247
1248 {
1249 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531250 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221251 root.get(), root->bounds(), translate, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531252 inputs.page_scale_factor = page_scale_factor;
1253 inputs.page_scale_application_layer = root.get();
1254 inputs.can_adjust_raster_scales = true;
1255 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231256 gfx::Transform page_scaled_translate = translate;
1257 page_scaled_translate.Scale(page_scale_factor, page_scale_factor);
1258 EXPECT_EQ(translate, root->draw_properties().target_space_transform);
1259 EXPECT_EQ(page_scaled_translate,
1260 child->draw_properties().target_space_transform);
1261 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
[email protected]35322352014-08-08 01:36:201262 EXPECT_EQ(1.f, root->draw_properties().device_scale_factor);
1263 EXPECT_EQ(1.f, child->draw_properties().device_scale_factor);
[email protected]989386c2013-07-18 21:37:231264 }
[email protected]9781afa2013-07-17 23:15:321265
[email protected]f224cc92013-06-06 23:23:321266 // Verify that it composes correctly with transforms directly on root layer.
1267 root->SetTransform(composite);
[email protected]989386c2013-07-18 21:37:231268
1269 {
1270 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531271 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:221272 root.get(), root->bounds(), composite, &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:531273 inputs.can_adjust_raster_scales = true;
1274 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231275 gfx::Transform compositeSquared = composite;
1276 compositeSquared.ConcatTransform(composite);
[email protected]803f6b52013-09-12 00:51:261277 EXPECT_TRANSFORMATION_MATRIX_EQ(
1278 compositeSquared, root->draw_properties().target_space_transform);
1279 EXPECT_TRANSFORMATION_MATRIX_EQ(
[email protected]baf64d062014-02-16 22:10:391280 compositeSquared, child->draw_properties().target_space_transform);
[email protected]989386c2013-07-18 21:37:231281 EXPECT_EQ(identity_matrix, root->render_surface()->draw_transform());
1282 }
[email protected]f224cc92013-06-06 23:23:321283}
1284
[email protected]989386c2013-07-18 21:37:231285TEST_F(LayerTreeHostCommonTest,
1286 RenderSurfaceListForRenderSurfaceWithClippedLayer) {
[email protected]fb661802013-03-25 01:59:321287 scoped_refptr<Layer> parent = Layer::Create();
1288 scoped_refptr<Layer> render_surface1 = Layer::Create();
1289 scoped_refptr<LayerWithForcedDrawsContent> child =
1290 make_scoped_refptr(new LayerWithForcedDrawsContent());
1291
enne2097cab2014-09-25 20:16:311292 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281293 host->SetRootLayer(parent);
1294
[email protected]fb661802013-03-25 01:59:321295 const gfx::Transform identity_matrix;
1296 SetLayerPropertiesForTesting(parent.get(),
1297 identity_matrix,
[email protected]a2566412014-06-05 03:14:201298 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321299 gfx::PointF(),
1300 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571301 true,
[email protected]fb661802013-03-25 01:59:321302 false);
1303 SetLayerPropertiesForTesting(render_surface1.get(),
1304 identity_matrix,
[email protected]a2566412014-06-05 03:14:201305 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321306 gfx::PointF(),
1307 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571308 true,
[email protected]fb661802013-03-25 01:59:321309 false);
1310 SetLayerPropertiesForTesting(child.get(),
1311 identity_matrix,
[email protected]a2566412014-06-05 03:14:201312 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321313 gfx::PointF(30.f, 30.f),
1314 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571315 true,
[email protected]fb661802013-03-25 01:59:321316 false);
1317
1318 parent->AddChild(render_surface1);
1319 parent->SetMasksToBounds(true);
1320 render_surface1->AddChild(child);
1321 render_surface1->SetForceRenderSurface(true);
1322
[email protected]989386c2013-07-18 21:37:231323 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531324 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1325 parent.get(),
1326 parent->bounds(),
1327 gfx::Transform(),
1328 &render_surface_layer_list);
1329 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321330
1331 // The child layer's content is entirely outside the parent's clip rect, so
1332 // the intermediate render surface should not be listed here, even if it was
1333 // forced to be created. Render surfaces without children or visible content
1334 // are unexpected at draw time (e.g. we might try to create a content texture
1335 // of size 0).
1336 ASSERT_TRUE(parent->render_surface());
[email protected]fb661802013-03-25 01:59:321337 EXPECT_EQ(1U, render_surface_layer_list.size());
1338}
1339
[email protected]989386c2013-07-18 21:37:231340TEST_F(LayerTreeHostCommonTest, RenderSurfaceListForTransparentChild) {
[email protected]fb661802013-03-25 01:59:321341 scoped_refptr<Layer> parent = Layer::Create();
1342 scoped_refptr<Layer> render_surface1 = Layer::Create();
1343 scoped_refptr<LayerWithForcedDrawsContent> child =
1344 make_scoped_refptr(new LayerWithForcedDrawsContent());
1345
enne2097cab2014-09-25 20:16:311346 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281347 host->SetRootLayer(parent);
1348
[email protected]fb661802013-03-25 01:59:321349 const gfx::Transform identity_matrix;
1350 SetLayerPropertiesForTesting(render_surface1.get(),
1351 identity_matrix,
[email protected]a2566412014-06-05 03:14:201352 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321353 gfx::PointF(),
1354 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571355 true,
[email protected]fb661802013-03-25 01:59:321356 false);
1357 SetLayerPropertiesForTesting(child.get(),
1358 identity_matrix,
[email protected]a2566412014-06-05 03:14:201359 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321360 gfx::PointF(),
1361 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571362 true,
[email protected]fb661802013-03-25 01:59:321363 false);
1364
1365 parent->AddChild(render_surface1);
1366 render_surface1->AddChild(child);
1367 render_surface1->SetForceRenderSurface(true);
1368 render_surface1->SetOpacity(0.f);
1369
[email protected]989386c2013-07-18 21:37:231370 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531371 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1372 parent.get(), parent->bounds(), &render_surface_layer_list);
1373 inputs.can_adjust_raster_scales = true;
1374 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321375
1376 // Since the layer is transparent, render_surface1->render_surface() should
1377 // not have gotten added anywhere. Also, the drawable content rect should not
1378 // have been extended by the children.
1379 ASSERT_TRUE(parent->render_surface());
1380 EXPECT_EQ(0U, parent->render_surface()->layer_list().size());
1381 EXPECT_EQ(1U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231382 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
[email protected]fb661802013-03-25 01:59:321383 EXPECT_EQ(gfx::Rect(), parent->drawable_content_rect());
1384}
1385
rosca948d29d2014-11-09 10:25:131386TEST_F(LayerTreeHostCommonTest, RenderSurfaceForBlendMode) {
1387 scoped_refptr<Layer> parent = Layer::Create();
1388 scoped_refptr<LayerWithForcedDrawsContent> child =
1389 make_scoped_refptr(new LayerWithForcedDrawsContent());
1390
1391 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
1392 host->SetRootLayer(parent);
1393
1394 const gfx::Transform identity_matrix;
1395 const SkXfermode::Mode blend_mode = SkXfermode::kMultiply_Mode;
1396 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
1397 gfx::PointF(), gfx::Size(10, 10), true, false);
1398
1399 parent->AddChild(child);
1400 child->SetBlendMode(blend_mode);
1401
1402 RenderSurfaceLayerList render_surface_layer_list;
1403 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1404 parent.get(), parent->bounds(), &render_surface_layer_list);
1405 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
1406
1407 // Since the child layer has a blend mode other than normal, it should get
1408 // its own render surface. Also, layer's draw_properties should contain the
1409 // default blend mode, since the render surface becomes responsible for
1410 // applying the blend mode.
1411 ASSERT_TRUE(child->render_surface());
1412 EXPECT_EQ(1U, child->render_surface()->layer_list().size());
1413 EXPECT_EQ(SkXfermode::kSrcOver_Mode, child->draw_properties().blend_mode);
1414}
1415
[email protected]989386c2013-07-18 21:37:231416TEST_F(LayerTreeHostCommonTest, ForceRenderSurface) {
[email protected]fb661802013-03-25 01:59:321417 scoped_refptr<Layer> parent = Layer::Create();
1418 scoped_refptr<Layer> render_surface1 = Layer::Create();
1419 scoped_refptr<LayerWithForcedDrawsContent> child =
1420 make_scoped_refptr(new LayerWithForcedDrawsContent());
1421 render_surface1->SetForceRenderSurface(true);
1422
enne2097cab2014-09-25 20:16:311423 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281424 host->SetRootLayer(parent);
1425
[email protected]fb661802013-03-25 01:59:321426 const gfx::Transform identity_matrix;
1427 SetLayerPropertiesForTesting(parent.get(),
1428 identity_matrix,
[email protected]a2566412014-06-05 03:14:201429 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321430 gfx::PointF(),
1431 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571432 true,
[email protected]fb661802013-03-25 01:59:321433 false);
1434 SetLayerPropertiesForTesting(render_surface1.get(),
1435 identity_matrix,
[email protected]a2566412014-06-05 03:14:201436 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321437 gfx::PointF(),
1438 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571439 true,
[email protected]fb661802013-03-25 01:59:321440 false);
1441 SetLayerPropertiesForTesting(child.get(),
1442 identity_matrix,
[email protected]a2566412014-06-05 03:14:201443 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321444 gfx::PointF(),
1445 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571446 true,
[email protected]fb661802013-03-25 01:59:321447 false);
1448
1449 parent->AddChild(render_surface1);
1450 render_surface1->AddChild(child);
1451
1452 // Sanity check before the actual test
1453 EXPECT_FALSE(parent->render_surface());
1454 EXPECT_FALSE(render_surface1->render_surface());
1455
[email protected]989386c2013-07-18 21:37:231456 {
1457 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531458 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1459 parent.get(), parent->bounds(), &render_surface_layer_list);
1460 inputs.can_adjust_raster_scales = true;
1461 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321462
[email protected]989386c2013-07-18 21:37:231463 // The root layer always creates a render surface
1464 EXPECT_TRUE(parent->render_surface());
1465 EXPECT_TRUE(render_surface1->render_surface());
1466 EXPECT_EQ(2U, render_surface_layer_list.size());
1467 }
[email protected]fb661802013-03-25 01:59:321468
[email protected]989386c2013-07-18 21:37:231469 {
1470 RenderSurfaceLayerList render_surface_layer_list;
1471 render_surface1->SetForceRenderSurface(false);
[email protected]7aad55f2013-07-26 11:25:531472 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1473 parent.get(), parent->bounds(), &render_surface_layer_list);
1474 inputs.can_adjust_raster_scales = true;
1475 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]989386c2013-07-18 21:37:231476 EXPECT_TRUE(parent->render_surface());
1477 EXPECT_FALSE(render_surface1->render_surface());
1478 EXPECT_EQ(1U, render_surface_layer_list.size());
1479 }
[email protected]fb661802013-03-25 01:59:321480}
1481
[email protected]989386c2013-07-18 21:37:231482TEST_F(LayerTreeHostCommonTest, ClipRectCullsRenderSurfaces) {
[email protected]fb661802013-03-25 01:59:321483 // The entire subtree of layers that are outside the clip rect should be
1484 // culled away, and should not affect the render_surface_layer_list.
1485 //
1486 // The test tree is set up as follows:
1487 // - all layers except the leaf_nodes are forced to be a new render surface
1488 // that have something to draw.
1489 // - parent is a large container layer.
1490 // - child has masksToBounds=true to cause clipping.
1491 // - grand_child is positioned outside of the child's bounds
1492 // - great_grand_child is also kept outside child's bounds.
1493 //
1494 // In this configuration, grand_child and great_grand_child are completely
1495 // outside the clip rect, and they should never get scheduled on the list of
1496 // render surfaces.
1497 //
1498
1499 const gfx::Transform identity_matrix;
1500 scoped_refptr<Layer> parent = Layer::Create();
1501 scoped_refptr<Layer> child = Layer::Create();
1502 scoped_refptr<Layer> grand_child = Layer::Create();
1503 scoped_refptr<Layer> great_grand_child = Layer::Create();
1504 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1505 make_scoped_refptr(new LayerWithForcedDrawsContent());
1506 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1507 make_scoped_refptr(new LayerWithForcedDrawsContent());
1508 parent->AddChild(child);
1509 child->AddChild(grand_child);
1510 grand_child->AddChild(great_grand_child);
1511
enne2097cab2014-09-25 20:16:311512 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281513 host->SetRootLayer(parent);
1514
[email protected]fb661802013-03-25 01:59:321515 // leaf_node1 ensures that parent and child are kept on the
1516 // render_surface_layer_list, even though grand_child and great_grand_child
1517 // should be clipped.
1518 child->AddChild(leaf_node1);
1519 great_grand_child->AddChild(leaf_node2);
1520
1521 SetLayerPropertiesForTesting(parent.get(),
1522 identity_matrix,
[email protected]a2566412014-06-05 03:14:201523 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321524 gfx::PointF(),
1525 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571526 true,
[email protected]fb661802013-03-25 01:59:321527 false);
1528 SetLayerPropertiesForTesting(child.get(),
1529 identity_matrix,
[email protected]a2566412014-06-05 03:14:201530 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321531 gfx::PointF(),
1532 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571533 true,
[email protected]fb661802013-03-25 01:59:321534 false);
1535 SetLayerPropertiesForTesting(grand_child.get(),
1536 identity_matrix,
[email protected]a2566412014-06-05 03:14:201537 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321538 gfx::PointF(45.f, 45.f),
1539 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571540 true,
[email protected]fb661802013-03-25 01:59:321541 false);
1542 SetLayerPropertiesForTesting(great_grand_child.get(),
1543 identity_matrix,
[email protected]a2566412014-06-05 03:14:201544 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321545 gfx::PointF(),
1546 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571547 true,
[email protected]fb661802013-03-25 01:59:321548 false);
1549 SetLayerPropertiesForTesting(leaf_node1.get(),
1550 identity_matrix,
[email protected]a2566412014-06-05 03:14:201551 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321552 gfx::PointF(),
1553 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571554 true,
[email protected]fb661802013-03-25 01:59:321555 false);
1556 SetLayerPropertiesForTesting(leaf_node2.get(),
1557 identity_matrix,
[email protected]a2566412014-06-05 03:14:201558 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321559 gfx::PointF(),
1560 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571561 true,
[email protected]fb661802013-03-25 01:59:321562 false);
1563
1564 child->SetMasksToBounds(true);
1565 child->SetOpacity(0.4f);
1566 child->SetForceRenderSurface(true);
1567 grand_child->SetOpacity(0.5f);
1568 great_grand_child->SetOpacity(0.4f);
1569
[email protected]989386c2013-07-18 21:37:231570 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531571 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1572 parent.get(), parent->bounds(), &render_surface_layer_list);
1573 inputs.can_adjust_raster_scales = true;
1574 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321575
1576 ASSERT_EQ(2U, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:231577 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1578 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:321579}
1580
[email protected]989386c2013-07-18 21:37:231581TEST_F(LayerTreeHostCommonTest, ClipRectCullsSurfaceWithoutVisibleContent) {
[email protected]fb661802013-03-25 01:59:321582 // When a render surface has a clip rect, it is used to clip the content rect
1583 // of the surface. When the render surface is animating its transforms, then
1584 // the content rect's position in the clip rect is not defined on the main
1585 // thread, and its content rect should not be clipped.
1586
1587 // The test tree is set up as follows:
1588 // - parent is a container layer that masksToBounds=true to cause clipping.
1589 // - child is a render surface, which has a clip rect set to the bounds of
1590 // the parent.
1591 // - grand_child is a render surface, and the only visible content in child.
1592 // It is positioned outside of the clip rect from parent.
1593
1594 // In this configuration, grand_child should be outside the clipped
1595 // content rect of the child, making grand_child not appear in the
1596 // render_surface_layer_list. However, when we place an animation on the
1597 // child, this clipping should be avoided and we should keep the grand_child
1598 // in the render_surface_layer_list.
1599
1600 const gfx::Transform identity_matrix;
1601 scoped_refptr<Layer> parent = Layer::Create();
1602 scoped_refptr<Layer> child = Layer::Create();
1603 scoped_refptr<Layer> grand_child = Layer::Create();
1604 scoped_refptr<LayerWithForcedDrawsContent> leaf_node =
1605 make_scoped_refptr(new LayerWithForcedDrawsContent());
1606 parent->AddChild(child);
1607 child->AddChild(grand_child);
1608 grand_child->AddChild(leaf_node);
1609
enne2097cab2014-09-25 20:16:311610 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281611 host->SetRootLayer(parent);
1612
[email protected]fb661802013-03-25 01:59:321613 SetLayerPropertiesForTesting(parent.get(),
1614 identity_matrix,
[email protected]a2566412014-06-05 03:14:201615 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321616 gfx::PointF(),
1617 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571618 true,
[email protected]fb661802013-03-25 01:59:321619 false);
1620 SetLayerPropertiesForTesting(child.get(),
1621 identity_matrix,
[email protected]a2566412014-06-05 03:14:201622 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321623 gfx::PointF(),
1624 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571625 true,
[email protected]fb661802013-03-25 01:59:321626 false);
1627 SetLayerPropertiesForTesting(grand_child.get(),
1628 identity_matrix,
[email protected]a2566412014-06-05 03:14:201629 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321630 gfx::PointF(200.f, 200.f),
1631 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571632 true,
[email protected]fb661802013-03-25 01:59:321633 false);
1634 SetLayerPropertiesForTesting(leaf_node.get(),
1635 identity_matrix,
[email protected]a2566412014-06-05 03:14:201636 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321637 gfx::PointF(),
1638 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571639 true,
[email protected]fb661802013-03-25 01:59:321640 false);
1641
1642 parent->SetMasksToBounds(true);
1643 child->SetOpacity(0.4f);
1644 child->SetForceRenderSurface(true);
1645 grand_child->SetOpacity(0.4f);
1646 grand_child->SetForceRenderSurface(true);
1647
[email protected]989386c2013-07-18 21:37:231648 {
1649 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531650 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1651 parent.get(), parent->bounds(), &render_surface_layer_list);
1652 inputs.can_adjust_raster_scales = true;
1653 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321654
[email protected]989386c2013-07-18 21:37:231655 // Without an animation, we should cull child and grand_child from the
1656 // render_surface_layer_list.
1657 ASSERT_EQ(1U, render_surface_layer_list.size());
1658 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1659 }
[email protected]fb661802013-03-25 01:59:321660
1661 // Now put an animating transform on child.
1662 AddAnimatedTransformToController(
1663 child->layer_animation_controller(), 10.0, 30, 0);
1664
[email protected]989386c2013-07-18 21:37:231665 {
1666 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531667 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1668 parent.get(), parent->bounds(), &render_surface_layer_list);
1669 inputs.can_adjust_raster_scales = true;
1670 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321671
[email protected]989386c2013-07-18 21:37:231672 // With an animating transform, we should keep child and grand_child in the
1673 // render_surface_layer_list.
1674 ASSERT_EQ(3U, render_surface_layer_list.size());
1675 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
1676 EXPECT_EQ(child->id(), render_surface_layer_list.at(1)->id());
1677 EXPECT_EQ(grand_child->id(), render_surface_layer_list.at(2)->id());
1678 }
[email protected]fb661802013-03-25 01:59:321679}
1680
[email protected]989386c2013-07-18 21:37:231681TEST_F(LayerTreeHostCommonTest, IsClippedIsSetCorrectly) {
[email protected]fb661802013-03-25 01:59:321682 // Layer's IsClipped() property is set to true when:
1683 // - the layer clips its subtree, e.g. masks to bounds,
1684 // - the layer is clipped by an ancestor that contributes to the same
1685 // render target,
1686 // - a surface is clipped by an ancestor that contributes to the same
1687 // render target.
1688 //
1689 // In particular, for a layer that owns a render surface:
1690 // - the render surface inherits any clip from ancestors, and does NOT
1691 // pass that clipped status to the layer itself.
1692 // - but if the layer itself masks to bounds, it is considered clipped
1693 // and propagates the clip to the subtree.
1694
1695 const gfx::Transform identity_matrix;
1696 scoped_refptr<Layer> root = Layer::Create();
1697 scoped_refptr<Layer> parent = Layer::Create();
1698 scoped_refptr<Layer> child1 = Layer::Create();
1699 scoped_refptr<Layer> child2 = Layer::Create();
1700 scoped_refptr<Layer> grand_child = Layer::Create();
1701 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1702 make_scoped_refptr(new LayerWithForcedDrawsContent());
1703 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1704 make_scoped_refptr(new LayerWithForcedDrawsContent());
1705 root->AddChild(parent);
1706 parent->AddChild(child1);
1707 parent->AddChild(child2);
1708 child1->AddChild(grand_child);
1709 child2->AddChild(leaf_node2);
1710 grand_child->AddChild(leaf_node1);
1711
enne2097cab2014-09-25 20:16:311712 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281713 host->SetRootLayer(root);
1714
[email protected]fb661802013-03-25 01:59:321715 child2->SetForceRenderSurface(true);
1716
1717 SetLayerPropertiesForTesting(root.get(),
1718 identity_matrix,
[email protected]a2566412014-06-05 03:14:201719 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321720 gfx::PointF(),
1721 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571722 true,
[email protected]fb661802013-03-25 01:59:321723 false);
1724 SetLayerPropertiesForTesting(parent.get(),
1725 identity_matrix,
[email protected]a2566412014-06-05 03:14:201726 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321727 gfx::PointF(),
1728 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571729 true,
[email protected]fb661802013-03-25 01:59:321730 false);
1731 SetLayerPropertiesForTesting(child1.get(),
1732 identity_matrix,
[email protected]a2566412014-06-05 03:14:201733 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321734 gfx::PointF(),
1735 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571736 true,
[email protected]fb661802013-03-25 01:59:321737 false);
1738 SetLayerPropertiesForTesting(child2.get(),
1739 identity_matrix,
[email protected]a2566412014-06-05 03:14:201740 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321741 gfx::PointF(),
1742 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571743 true,
[email protected]fb661802013-03-25 01:59:321744 false);
1745 SetLayerPropertiesForTesting(grand_child.get(),
1746 identity_matrix,
[email protected]a2566412014-06-05 03:14:201747 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321748 gfx::PointF(),
1749 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571750 true,
[email protected]fb661802013-03-25 01:59:321751 false);
1752 SetLayerPropertiesForTesting(leaf_node1.get(),
1753 identity_matrix,
[email protected]a2566412014-06-05 03:14:201754 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321755 gfx::PointF(),
1756 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571757 true,
[email protected]fb661802013-03-25 01:59:321758 false);
1759 SetLayerPropertiesForTesting(leaf_node2.get(),
1760 identity_matrix,
[email protected]a2566412014-06-05 03:14:201761 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321762 gfx::PointF(),
1763 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:571764 true,
[email protected]fb661802013-03-25 01:59:321765 false);
1766
[email protected]989386c2013-07-18 21:37:231767 // Case 1: nothing is clipped except the root render surface.
1768 {
1769 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531770 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1771 root.get(), parent->bounds(), &render_surface_layer_list);
1772 inputs.can_adjust_raster_scales = true;
1773 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321774
[email protected]989386c2013-07-18 21:37:231775 ASSERT_TRUE(root->render_surface());
1776 ASSERT_TRUE(child2->render_surface());
1777
1778 EXPECT_FALSE(root->is_clipped());
1779 EXPECT_TRUE(root->render_surface()->is_clipped());
1780 EXPECT_FALSE(parent->is_clipped());
1781 EXPECT_FALSE(child1->is_clipped());
1782 EXPECT_FALSE(child2->is_clipped());
1783 EXPECT_FALSE(child2->render_surface()->is_clipped());
1784 EXPECT_FALSE(grand_child->is_clipped());
1785 EXPECT_FALSE(leaf_node1->is_clipped());
1786 EXPECT_FALSE(leaf_node2->is_clipped());
1787 }
[email protected]fb661802013-03-25 01:59:321788
1789 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1790 // surface are clipped. But layers that contribute to child2's surface are
1791 // not clipped explicitly because child2's surface already accounts for
1792 // that clip.
[email protected]989386c2013-07-18 21:37:231793 {
1794 RenderSurfaceLayerList render_surface_layer_list;
1795 parent->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531796 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1797 root.get(), parent->bounds(), &render_surface_layer_list);
1798 inputs.can_adjust_raster_scales = true;
1799 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321800
[email protected]989386c2013-07-18 21:37:231801 ASSERT_TRUE(root->render_surface());
1802 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321803
[email protected]989386c2013-07-18 21:37:231804 EXPECT_FALSE(root->is_clipped());
1805 EXPECT_TRUE(root->render_surface()->is_clipped());
1806 EXPECT_TRUE(parent->is_clipped());
1807 EXPECT_TRUE(child1->is_clipped());
1808 EXPECT_FALSE(child2->is_clipped());
1809 EXPECT_TRUE(child2->render_surface()->is_clipped());
1810 EXPECT_TRUE(grand_child->is_clipped());
1811 EXPECT_TRUE(leaf_node1->is_clipped());
1812 EXPECT_FALSE(leaf_node2->is_clipped());
1813 }
[email protected]fb661802013-03-25 01:59:321814
1815 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1816 // child2's render surface is not clipped.
[email protected]989386c2013-07-18 21:37:231817 {
1818 RenderSurfaceLayerList render_surface_layer_list;
1819 parent->SetMasksToBounds(false);
1820 child2->SetMasksToBounds(true);
[email protected]7aad55f2013-07-26 11:25:531821 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1822 root.get(), parent->bounds(), &render_surface_layer_list);
1823 inputs.can_adjust_raster_scales = true;
1824 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321825
[email protected]989386c2013-07-18 21:37:231826 ASSERT_TRUE(root->render_surface());
1827 ASSERT_TRUE(child2->render_surface());
[email protected]fb661802013-03-25 01:59:321828
[email protected]989386c2013-07-18 21:37:231829 EXPECT_FALSE(root->is_clipped());
1830 EXPECT_TRUE(root->render_surface()->is_clipped());
1831 EXPECT_FALSE(parent->is_clipped());
1832 EXPECT_FALSE(child1->is_clipped());
1833 EXPECT_TRUE(child2->is_clipped());
1834 EXPECT_FALSE(child2->render_surface()->is_clipped());
1835 EXPECT_FALSE(grand_child->is_clipped());
1836 EXPECT_FALSE(leaf_node1->is_clipped());
1837 EXPECT_TRUE(leaf_node2->is_clipped());
1838 }
[email protected]fb661802013-03-25 01:59:321839}
1840
[email protected]fd9a3b6d2013-08-03 00:46:171841TEST_F(LayerTreeHostCommonTest, DrawableContentRectForLayers) {
[email protected]fb661802013-03-25 01:59:321842 // Verify that layers get the appropriate DrawableContentRect when their
1843 // parent masksToBounds is true.
1844 //
1845 // grand_child1 - completely inside the region; DrawableContentRect should
1846 // be the layer rect expressed in target space.
1847 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1848 // will be the intersection of layer bounds and the mask region.
1849 // grand_child3 - partially clipped and masksToBounds; the
1850 // DrawableContentRect will still be the intersection of layer bounds and
1851 // the mask region.
1852 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1853 // be empty.
1854 //
1855
1856 const gfx::Transform identity_matrix;
1857 scoped_refptr<Layer> parent = Layer::Create();
1858 scoped_refptr<Layer> child = Layer::Create();
1859 scoped_refptr<Layer> grand_child1 = Layer::Create();
1860 scoped_refptr<Layer> grand_child2 = Layer::Create();
1861 scoped_refptr<Layer> grand_child3 = Layer::Create();
1862 scoped_refptr<Layer> grand_child4 = Layer::Create();
1863
1864 parent->AddChild(child);
1865 child->AddChild(grand_child1);
1866 child->AddChild(grand_child2);
1867 child->AddChild(grand_child3);
1868 child->AddChild(grand_child4);
1869
enne2097cab2014-09-25 20:16:311870 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281871 host->SetRootLayer(parent);
1872
[email protected]fb661802013-03-25 01:59:321873 SetLayerPropertiesForTesting(parent.get(),
1874 identity_matrix,
[email protected]a2566412014-06-05 03:14:201875 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321876 gfx::PointF(),
1877 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571878 true,
[email protected]fb661802013-03-25 01:59:321879 false);
1880 SetLayerPropertiesForTesting(child.get(),
1881 identity_matrix,
[email protected]a2566412014-06-05 03:14:201882 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321883 gfx::PointF(),
1884 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571885 true,
[email protected]fb661802013-03-25 01:59:321886 false);
1887 SetLayerPropertiesForTesting(grand_child1.get(),
1888 identity_matrix,
[email protected]a2566412014-06-05 03:14:201889 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321890 gfx::PointF(5.f, 5.f),
1891 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571892 true,
[email protected]fb661802013-03-25 01:59:321893 false);
1894 SetLayerPropertiesForTesting(grand_child2.get(),
1895 identity_matrix,
[email protected]a2566412014-06-05 03:14:201896 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321897 gfx::PointF(15.f, 15.f),
1898 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571899 true,
[email protected]fb661802013-03-25 01:59:321900 false);
1901 SetLayerPropertiesForTesting(grand_child3.get(),
1902 identity_matrix,
[email protected]a2566412014-06-05 03:14:201903 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321904 gfx::PointF(15.f, 15.f),
1905 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571906 true,
[email protected]fb661802013-03-25 01:59:321907 false);
1908 SetLayerPropertiesForTesting(grand_child4.get(),
1909 identity_matrix,
[email protected]a2566412014-06-05 03:14:201910 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321911 gfx::PointF(45.f, 45.f),
1912 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571913 true,
[email protected]fb661802013-03-25 01:59:321914 false);
1915
1916 child->SetMasksToBounds(true);
1917 grand_child3->SetMasksToBounds(true);
1918
1919 // Force everyone to be a render surface.
1920 child->SetOpacity(0.4f);
1921 grand_child1->SetOpacity(0.5f);
1922 grand_child2->SetOpacity(0.5f);
1923 grand_child3->SetOpacity(0.5f);
1924 grand_child4->SetOpacity(0.5f);
1925
[email protected]989386c2013-07-18 21:37:231926 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:531927 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
1928 parent.get(), parent->bounds(), &render_surface_layer_list);
1929 inputs.can_adjust_raster_scales = true;
1930 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:321931
hush6b614212014-12-04 22:37:321932 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1->drawable_content_rect());
1933 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
1934 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:321935 EXPECT_TRUE(grand_child4->drawable_content_rect().IsEmpty());
1936}
1937
[email protected]989386c2013-07-18 21:37:231938TEST_F(LayerTreeHostCommonTest, ClipRectIsPropagatedCorrectlyToSurfaces) {
[email protected]fb661802013-03-25 01:59:321939 // Verify that render surfaces (and their layers) get the appropriate
1940 // clip rects when their parent masksToBounds is true.
1941 //
1942 // Layers that own render surfaces (at least for now) do not inherit any
1943 // clipping; instead the surface will enforce the clip for the entire subtree.
1944 // They may still have a clip rect of their own layer bounds, however, if
1945 // masksToBounds was true.
1946 const gfx::Transform identity_matrix;
1947 scoped_refptr<Layer> parent = Layer::Create();
1948 scoped_refptr<Layer> child = Layer::Create();
1949 scoped_refptr<Layer> grand_child1 = Layer::Create();
1950 scoped_refptr<Layer> grand_child2 = Layer::Create();
1951 scoped_refptr<Layer> grand_child3 = Layer::Create();
1952 scoped_refptr<Layer> grand_child4 = Layer::Create();
1953 scoped_refptr<LayerWithForcedDrawsContent> leaf_node1 =
1954 make_scoped_refptr(new LayerWithForcedDrawsContent());
1955 scoped_refptr<LayerWithForcedDrawsContent> leaf_node2 =
1956 make_scoped_refptr(new LayerWithForcedDrawsContent());
1957 scoped_refptr<LayerWithForcedDrawsContent> leaf_node3 =
1958 make_scoped_refptr(new LayerWithForcedDrawsContent());
1959 scoped_refptr<LayerWithForcedDrawsContent> leaf_node4 =
1960 make_scoped_refptr(new LayerWithForcedDrawsContent());
1961
1962 parent->AddChild(child);
1963 child->AddChild(grand_child1);
1964 child->AddChild(grand_child2);
1965 child->AddChild(grand_child3);
1966 child->AddChild(grand_child4);
1967
enne2097cab2014-09-25 20:16:311968 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:281969 host->SetRootLayer(parent);
1970
[email protected]fb661802013-03-25 01:59:321971 // the leaf nodes ensure that these grand_children become render surfaces for
1972 // this test.
1973 grand_child1->AddChild(leaf_node1);
1974 grand_child2->AddChild(leaf_node2);
1975 grand_child3->AddChild(leaf_node3);
1976 grand_child4->AddChild(leaf_node4);
1977
1978 SetLayerPropertiesForTesting(parent.get(),
1979 identity_matrix,
[email protected]a2566412014-06-05 03:14:201980 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321981 gfx::PointF(),
1982 gfx::Size(500, 500),
[email protected]56fffdd2014-02-11 19:50:571983 true,
[email protected]fb661802013-03-25 01:59:321984 false);
1985 SetLayerPropertiesForTesting(child.get(),
1986 identity_matrix,
[email protected]a2566412014-06-05 03:14:201987 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321988 gfx::PointF(),
1989 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:571990 true,
[email protected]fb661802013-03-25 01:59:321991 false);
1992 SetLayerPropertiesForTesting(grand_child1.get(),
1993 identity_matrix,
[email protected]a2566412014-06-05 03:14:201994 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:321995 gfx::PointF(5.f, 5.f),
1996 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:571997 true,
[email protected]fb661802013-03-25 01:59:321998 false);
1999 SetLayerPropertiesForTesting(grand_child2.get(),
2000 identity_matrix,
[email protected]a2566412014-06-05 03:14:202001 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322002 gfx::PointF(15.f, 15.f),
2003 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572004 true,
[email protected]fb661802013-03-25 01:59:322005 false);
2006 SetLayerPropertiesForTesting(grand_child3.get(),
2007 identity_matrix,
[email protected]a2566412014-06-05 03:14:202008 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322009 gfx::PointF(15.f, 15.f),
2010 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572011 true,
[email protected]fb661802013-03-25 01:59:322012 false);
2013 SetLayerPropertiesForTesting(grand_child4.get(),
2014 identity_matrix,
[email protected]a2566412014-06-05 03:14:202015 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322016 gfx::PointF(45.f, 45.f),
2017 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572018 true,
[email protected]fb661802013-03-25 01:59:322019 false);
2020 SetLayerPropertiesForTesting(leaf_node1.get(),
2021 identity_matrix,
[email protected]a2566412014-06-05 03:14:202022 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322023 gfx::PointF(),
2024 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572025 true,
[email protected]fb661802013-03-25 01:59:322026 false);
2027 SetLayerPropertiesForTesting(leaf_node2.get(),
2028 identity_matrix,
[email protected]a2566412014-06-05 03:14:202029 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322030 gfx::PointF(),
2031 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572032 true,
[email protected]fb661802013-03-25 01:59:322033 false);
2034 SetLayerPropertiesForTesting(leaf_node3.get(),
2035 identity_matrix,
[email protected]a2566412014-06-05 03:14:202036 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322037 gfx::PointF(),
2038 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572039 true,
[email protected]fb661802013-03-25 01:59:322040 false);
2041 SetLayerPropertiesForTesting(leaf_node4.get(),
2042 identity_matrix,
[email protected]a2566412014-06-05 03:14:202043 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322044 gfx::PointF(),
2045 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572046 true,
[email protected]fb661802013-03-25 01:59:322047 false);
2048
2049 child->SetMasksToBounds(true);
2050 grand_child3->SetMasksToBounds(true);
2051 grand_child4->SetMasksToBounds(true);
2052
2053 // Force everyone to be a render surface.
2054 child->SetOpacity(0.4f);
2055 child->SetForceRenderSurface(true);
2056 grand_child1->SetOpacity(0.5f);
2057 grand_child1->SetForceRenderSurface(true);
2058 grand_child2->SetOpacity(0.5f);
2059 grand_child2->SetForceRenderSurface(true);
2060 grand_child3->SetOpacity(0.5f);
2061 grand_child3->SetForceRenderSurface(true);
2062 grand_child4->SetOpacity(0.5f);
2063 grand_child4->SetForceRenderSurface(true);
2064
[email protected]989386c2013-07-18 21:37:232065 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:532066 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2067 parent.get(), parent->bounds(), &render_surface_layer_list);
2068 inputs.can_adjust_raster_scales = true;
2069 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:322070 ASSERT_TRUE(grand_child1->render_surface());
2071 ASSERT_TRUE(grand_child2->render_surface());
2072 ASSERT_TRUE(grand_child3->render_surface());
[email protected]fb661802013-03-25 01:59:322073
2074 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2075 // masksToBounds.
hush6b614212014-12-04 22:37:322076 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2077 grand_child1->render_surface()->clip_rect());
2078 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2079 grand_child2->render_surface()->clip_rect());
2080 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2081 grand_child3->render_surface()->clip_rect());
[email protected]fb661802013-03-25 01:59:322082}
2083
[email protected]989386c2013-07-18 21:37:232084TEST_F(LayerTreeHostCommonTest, AnimationsForRenderSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:322085 scoped_refptr<Layer> parent = Layer::Create();
2086 scoped_refptr<Layer> render_surface1 = Layer::Create();
2087 scoped_refptr<Layer> render_surface2 = Layer::Create();
2088 scoped_refptr<Layer> child_of_root = Layer::Create();
2089 scoped_refptr<Layer> child_of_rs1 = Layer::Create();
2090 scoped_refptr<Layer> child_of_rs2 = Layer::Create();
2091 scoped_refptr<Layer> grand_child_of_root = Layer::Create();
2092 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs1 =
2093 make_scoped_refptr(new LayerWithForcedDrawsContent());
2094 scoped_refptr<LayerWithForcedDrawsContent> grand_child_of_rs2 =
2095 make_scoped_refptr(new LayerWithForcedDrawsContent());
2096 parent->AddChild(render_surface1);
2097 parent->AddChild(child_of_root);
2098 render_surface1->AddChild(child_of_rs1);
2099 render_surface1->AddChild(render_surface2);
2100 render_surface2->AddChild(child_of_rs2);
2101 child_of_root->AddChild(grand_child_of_root);
2102 child_of_rs1->AddChild(grand_child_of_rs1);
2103 child_of_rs2->AddChild(grand_child_of_rs2);
2104
enne2097cab2014-09-25 20:16:312105 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282106 host->SetRootLayer(parent);
2107
[email protected]fb661802013-03-25 01:59:322108 // Make our render surfaces.
2109 render_surface1->SetForceRenderSurface(true);
2110 render_surface2->SetForceRenderSurface(true);
2111
2112 gfx::Transform layer_transform;
2113 layer_transform.Translate(1.0, 1.0);
[email protected]fb661802013-03-25 01:59:322114
2115 SetLayerPropertiesForTesting(parent.get(),
2116 layer_transform,
[email protected]a2566412014-06-05 03:14:202117 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322118 gfx::PointF(2.5f, 0.f),
2119 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572120 true,
[email protected]fb661802013-03-25 01:59:322121 false);
2122 SetLayerPropertiesForTesting(render_surface1.get(),
2123 layer_transform,
[email protected]a2566412014-06-05 03:14:202124 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322125 gfx::PointF(2.5f, 0.f),
2126 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572127 true,
[email protected]fb661802013-03-25 01:59:322128 false);
2129 SetLayerPropertiesForTesting(render_surface2.get(),
2130 layer_transform,
[email protected]a2566412014-06-05 03:14:202131 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322132 gfx::PointF(2.5f, 0.f),
2133 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572134 true,
[email protected]fb661802013-03-25 01:59:322135 false);
2136 SetLayerPropertiesForTesting(child_of_root.get(),
2137 layer_transform,
[email protected]a2566412014-06-05 03:14:202138 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322139 gfx::PointF(2.5f, 0.f),
2140 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572141 true,
[email protected]fb661802013-03-25 01:59:322142 false);
2143 SetLayerPropertiesForTesting(child_of_rs1.get(),
2144 layer_transform,
[email protected]a2566412014-06-05 03:14:202145 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322146 gfx::PointF(2.5f, 0.f),
2147 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572148 true,
[email protected]fb661802013-03-25 01:59:322149 false);
2150 SetLayerPropertiesForTesting(child_of_rs2.get(),
2151 layer_transform,
[email protected]a2566412014-06-05 03:14:202152 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322153 gfx::PointF(2.5f, 0.f),
2154 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572155 true,
[email protected]fb661802013-03-25 01:59:322156 false);
2157 SetLayerPropertiesForTesting(grand_child_of_root.get(),
2158 layer_transform,
[email protected]a2566412014-06-05 03:14:202159 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322160 gfx::PointF(2.5f, 0.f),
2161 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572162 true,
[email protected]fb661802013-03-25 01:59:322163 false);
2164 SetLayerPropertiesForTesting(grand_child_of_rs1.get(),
2165 layer_transform,
[email protected]a2566412014-06-05 03:14:202166 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322167 gfx::PointF(2.5f, 0.f),
2168 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572169 true,
[email protected]fb661802013-03-25 01:59:322170 false);
2171 SetLayerPropertiesForTesting(grand_child_of_rs2.get(),
2172 layer_transform,
[email protected]a2566412014-06-05 03:14:202173 gfx::Point3F(0.25f, 0.f, 0.f),
[email protected]fb661802013-03-25 01:59:322174 gfx::PointF(2.5f, 0.f),
2175 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:572176 true,
[email protected]fb661802013-03-25 01:59:322177 false);
2178
2179 // Put an animated opacity on the render surface.
2180 AddOpacityTransitionToController(
2181 render_surface1->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2182
2183 // Also put an animated opacity on a layer without descendants.
2184 AddOpacityTransitionToController(
2185 grand_child_of_root->layer_animation_controller(), 10.0, 1.f, 0.f, false);
2186
2187 // Put a transform animation on the render surface.
2188 AddAnimatedTransformToController(
2189 render_surface2->layer_animation_controller(), 10.0, 30, 0);
2190
2191 // Also put transform animations on grand_child_of_root, and
2192 // grand_child_of_rs2
2193 AddAnimatedTransformToController(
2194 grand_child_of_root->layer_animation_controller(), 10.0, 30, 0);
2195 AddAnimatedTransformToController(
2196 grand_child_of_rs2->layer_animation_controller(), 10.0, 30, 0);
2197
2198 ExecuteCalculateDrawProperties(parent.get());
2199
2200 // Only layers that are associated with render surfaces should have an actual
2201 // RenderSurface() value.
2202 ASSERT_TRUE(parent->render_surface());
2203 ASSERT_FALSE(child_of_root->render_surface());
2204 ASSERT_FALSE(grand_child_of_root->render_surface());
2205
2206 ASSERT_TRUE(render_surface1->render_surface());
2207 ASSERT_FALSE(child_of_rs1->render_surface());
2208 ASSERT_FALSE(grand_child_of_rs1->render_surface());
2209
2210 ASSERT_TRUE(render_surface2->render_surface());
2211 ASSERT_FALSE(child_of_rs2->render_surface());
2212 ASSERT_FALSE(grand_child_of_rs2->render_surface());
2213
2214 // Verify all render target accessors
Daniel Chengeea98042014-08-26 00:28:102215 EXPECT_EQ(parent.get(), parent->render_target());
2216 EXPECT_EQ(parent.get(), child_of_root->render_target());
2217 EXPECT_EQ(parent.get(), grand_child_of_root->render_target());
[email protected]fb661802013-03-25 01:59:322218
Daniel Chengeea98042014-08-26 00:28:102219 EXPECT_EQ(render_surface1.get(), render_surface1->render_target());
2220 EXPECT_EQ(render_surface1.get(), child_of_rs1->render_target());
2221 EXPECT_EQ(render_surface1.get(), grand_child_of_rs1->render_target());
[email protected]fb661802013-03-25 01:59:322222
Daniel Chengeea98042014-08-26 00:28:102223 EXPECT_EQ(render_surface2.get(), render_surface2->render_target());
2224 EXPECT_EQ(render_surface2.get(), child_of_rs2->render_target());
2225 EXPECT_EQ(render_surface2.get(), grand_child_of_rs2->render_target());
[email protected]fb661802013-03-25 01:59:322226
2227 // Verify draw_opacity_is_animating values
2228 EXPECT_FALSE(parent->draw_opacity_is_animating());
2229 EXPECT_FALSE(child_of_root->draw_opacity_is_animating());
2230 EXPECT_TRUE(grand_child_of_root->draw_opacity_is_animating());
2231 EXPECT_FALSE(render_surface1->draw_opacity_is_animating());
2232 EXPECT_TRUE(render_surface1->render_surface()->draw_opacity_is_animating());
2233 EXPECT_FALSE(child_of_rs1->draw_opacity_is_animating());
2234 EXPECT_FALSE(grand_child_of_rs1->draw_opacity_is_animating());
2235 EXPECT_FALSE(render_surface2->draw_opacity_is_animating());
2236 EXPECT_FALSE(render_surface2->render_surface()->draw_opacity_is_animating());
2237 EXPECT_FALSE(child_of_rs2->draw_opacity_is_animating());
2238 EXPECT_FALSE(grand_child_of_rs2->draw_opacity_is_animating());
2239
2240 // Verify draw_transform_is_animating values
2241 EXPECT_FALSE(parent->draw_transform_is_animating());
2242 EXPECT_FALSE(child_of_root->draw_transform_is_animating());
2243 EXPECT_TRUE(grand_child_of_root->draw_transform_is_animating());
2244 EXPECT_FALSE(render_surface1->draw_transform_is_animating());
2245 EXPECT_FALSE(render_surface1->render_surface()
2246 ->target_surface_transforms_are_animating());
2247 EXPECT_FALSE(child_of_rs1->draw_transform_is_animating());
2248 EXPECT_FALSE(grand_child_of_rs1->draw_transform_is_animating());
2249 EXPECT_FALSE(render_surface2->draw_transform_is_animating());
2250 EXPECT_TRUE(render_surface2->render_surface()
2251 ->target_surface_transforms_are_animating());
2252 EXPECT_FALSE(child_of_rs2->draw_transform_is_animating());
2253 EXPECT_TRUE(grand_child_of_rs2->draw_transform_is_animating());
2254
2255 // Verify screen_space_transform_is_animating values
2256 EXPECT_FALSE(parent->screen_space_transform_is_animating());
2257 EXPECT_FALSE(child_of_root->screen_space_transform_is_animating());
2258 EXPECT_TRUE(grand_child_of_root->screen_space_transform_is_animating());
2259 EXPECT_FALSE(render_surface1->screen_space_transform_is_animating());
2260 EXPECT_FALSE(render_surface1->render_surface()
2261 ->screen_space_transforms_are_animating());
2262 EXPECT_FALSE(child_of_rs1->screen_space_transform_is_animating());
2263 EXPECT_FALSE(grand_child_of_rs1->screen_space_transform_is_animating());
2264 EXPECT_TRUE(render_surface2->screen_space_transform_is_animating());
2265 EXPECT_TRUE(render_surface2->render_surface()
2266 ->screen_space_transforms_are_animating());
2267 EXPECT_TRUE(child_of_rs2->screen_space_transform_is_animating());
2268 EXPECT_TRUE(grand_child_of_rs2->screen_space_transform_is_animating());
2269
2270 // Sanity check. If these fail there is probably a bug in the test itself.
2271 // It is expected that we correctly set up transforms so that the y-component
2272 // of the screen-space transform encodes the "depth" of the layer in the tree.
[email protected]803f6b52013-09-12 00:51:262273 EXPECT_FLOAT_EQ(1.0, parent->screen_space_transform().matrix().get(1, 3));
2274 EXPECT_FLOAT_EQ(2.0,
2275 child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322276 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262277 3.0, grand_child_of_root->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322278
[email protected]803f6b52013-09-12 00:51:262279 EXPECT_FLOAT_EQ(2.0,
2280 render_surface1->screen_space_transform().matrix().get(1, 3));
2281 EXPECT_FLOAT_EQ(3.0,
2282 child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322283 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262284 4.0, grand_child_of_rs1->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322285
[email protected]803f6b52013-09-12 00:51:262286 EXPECT_FLOAT_EQ(3.0,
2287 render_surface2->screen_space_transform().matrix().get(1, 3));
2288 EXPECT_FLOAT_EQ(4.0,
2289 child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322290 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:262291 5.0, grand_child_of_rs2->screen_space_transform().matrix().get(1, 3));
[email protected]fb661802013-03-25 01:59:322292}
2293
[email protected]989386c2013-07-18 21:37:232294TEST_F(LayerTreeHostCommonTest, VisibleRectForIdentityTransform) {
[email protected]fb661802013-03-25 01:59:322295 // Test the calculateVisibleRect() function works correctly for identity
2296 // transforms.
2297
[email protected]2c7c6702013-03-26 03:14:052298 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322299 gfx::Transform layer_to_surface_transform;
2300
2301 // Case 1: Layer is contained within the surface.
[email protected]989386c2013-07-18 21:37:232302 gfx::Rect layer_content_rect = gfx::Rect(10, 10, 30, 30);
[email protected]2c7c6702013-03-26 03:14:052303 gfx::Rect expected = gfx::Rect(10, 10, 30, 30);
[email protected]fb661802013-03-25 01:59:322304 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2305 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322306 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322307
2308 // Case 2: Layer is outside the surface rect.
[email protected]2c7c6702013-03-26 03:14:052309 layer_content_rect = gfx::Rect(120, 120, 30, 30);
[email protected]fb661802013-03-25 01:59:322310 actual = LayerTreeHostCommon::CalculateVisibleRect(
2311 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2312 EXPECT_TRUE(actual.IsEmpty());
2313
2314 // Case 3: Layer is partially overlapping the surface rect.
[email protected]2c7c6702013-03-26 03:14:052315 layer_content_rect = gfx::Rect(80, 80, 30, 30);
2316 expected = gfx::Rect(80, 80, 20, 20);
[email protected]fb661802013-03-25 01:59:322317 actual = LayerTreeHostCommon::CalculateVisibleRect(
2318 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322319 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322320}
2321
[email protected]989386c2013-07-18 21:37:232322TEST_F(LayerTreeHostCommonTest, VisibleRectForTranslations) {
[email protected]fb661802013-03-25 01:59:322323 // Test the calculateVisibleRect() function works correctly for scaling
2324 // transforms.
2325
[email protected]2c7c6702013-03-26 03:14:052326 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2327 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322328 gfx::Transform layer_to_surface_transform;
2329
2330 // Case 1: Layer is contained within the surface.
2331 layer_to_surface_transform.MakeIdentity();
2332 layer_to_surface_transform.Translate(10.0, 10.0);
[email protected]2c7c6702013-03-26 03:14:052333 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322334 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2335 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322336 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322337
2338 // Case 2: Layer is outside the surface rect.
2339 layer_to_surface_transform.MakeIdentity();
2340 layer_to_surface_transform.Translate(120.0, 120.0);
2341 actual = LayerTreeHostCommon::CalculateVisibleRect(
2342 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2343 EXPECT_TRUE(actual.IsEmpty());
2344
2345 // Case 3: Layer is partially overlapping the surface rect.
2346 layer_to_surface_transform.MakeIdentity();
2347 layer_to_surface_transform.Translate(80.0, 80.0);
[email protected]2c7c6702013-03-26 03:14:052348 expected = gfx::Rect(0, 0, 20, 20);
[email protected]fb661802013-03-25 01:59:322349 actual = LayerTreeHostCommon::CalculateVisibleRect(
2350 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322351 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322352}
2353
[email protected]989386c2013-07-18 21:37:232354TEST_F(LayerTreeHostCommonTest, VisibleRectFor2DRotations) {
[email protected]fb661802013-03-25 01:59:322355 // Test the calculateVisibleRect() function works correctly for rotations
2356 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2357 // should return the g in the layer's space.
2358
[email protected]2c7c6702013-03-26 03:14:052359 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2360 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322361 gfx::Transform layer_to_surface_transform;
2362
2363 // Case 1: Layer is contained within the surface.
2364 layer_to_surface_transform.MakeIdentity();
2365 layer_to_surface_transform.Translate(50.0, 50.0);
2366 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052367 gfx::Rect expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322368 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2369 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322370 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322371
2372 // Case 2: Layer is outside the surface rect.
2373 layer_to_surface_transform.MakeIdentity();
2374 layer_to_surface_transform.Translate(-50.0, 0.0);
2375 layer_to_surface_transform.Rotate(45.0);
2376 actual = LayerTreeHostCommon::CalculateVisibleRect(
2377 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2378 EXPECT_TRUE(actual.IsEmpty());
2379
2380 // Case 3: The layer is rotated about its top-left corner. In surface space,
2381 // the layer is oriented diagonally, with the left half outside of the render
2382 // surface. In this case, the g should still be the entire layer
2383 // (remember the g is computed in layer space); both the top-left
2384 // and bottom-right corners of the layer are still visible.
2385 layer_to_surface_transform.MakeIdentity();
2386 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052387 expected = gfx::Rect(0, 0, 30, 30);
[email protected]fb661802013-03-25 01:59:322388 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 4: The layer is rotated about its top-left corner, and translated
2393 // upwards. In surface space, the layer is oriented diagonally, with only the
2394 // top corner of the surface overlapping the layer. In layer space, the render
2395 // surface overlaps the right side of the layer. The g should be
2396 // the layer's right half.
2397 layer_to_surface_transform.MakeIdentity();
2398 layer_to_surface_transform.Translate(0.0, -sqrt(2.0) * 15.0);
2399 layer_to_surface_transform.Rotate(45.0);
[email protected]2c7c6702013-03-26 03:14:052400 expected = gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
[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, VisibleRectFor3dOrthographicTransform) {
[email protected]fb661802013-03-25 01:59:322407 // Test that the calculateVisibleRect() function works correctly for 3d
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, 100, 100);
[email protected]fb661802013-03-25 01:59:322412 gfx::Transform layer_to_surface_transform;
2413
2414 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2415 // degrees, should be fully contained in the render surface.
2416 layer_to_surface_transform.MakeIdentity();
2417 layer_to_surface_transform.RotateAboutYAxis(45.0);
[email protected]2c7c6702013-03-26 03:14:052418 gfx::Rect expected = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322419 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2420 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322421 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322422
2423 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2424 // degrees, but shifted to the side so only the right-half the layer would be
2425 // visible on the surface.
2426 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
[email protected]803f6b52013-09-12 00:51:262427 SkMScalar half_width_of_rotated_layer =
2428 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
[email protected]fb661802013-03-25 01:59:322429 layer_to_surface_transform.MakeIdentity();
2430 layer_to_surface_transform.Translate(-half_width_of_rotated_layer, 0.0);
[email protected]989386c2013-07-18 21:37:232431 layer_to_surface_transform.RotateAboutYAxis(45.0); // Rotates about the left
2432 // edge of the layer.
[email protected]2c7c6702013-03-26 03:14:052433 expected = gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
[email protected]fb661802013-03-25 01:59:322434 actual = LayerTreeHostCommon::CalculateVisibleRect(
2435 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322436 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322437}
2438
[email protected]989386c2013-07-18 21:37:232439TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveTransform) {
[email protected]fb661802013-03-25 01:59:322440 // Test the calculateVisibleRect() function works correctly when the layer has
2441 // a perspective projection onto the target surface.
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(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322445 gfx::Transform layer_to_surface_transform;
2446
2447 // Case 1: Even though the layer is twice as large as the surface, due to
2448 // perspective foreshortening, the layer will fit fully in the surface when
2449 // its translated more than the perspective amount.
2450 layer_to_surface_transform.MakeIdentity();
2451
2452 // The following sequence of transforms applies the perspective about the
2453 // center of the surface.
2454 layer_to_surface_transform.Translate(50.0, 50.0);
2455 layer_to_surface_transform.ApplyPerspectiveDepth(9.0);
2456 layer_to_surface_transform.Translate(-50.0, -50.0);
2457
2458 // This translate places the layer in front of the surface's projection plane.
2459 layer_to_surface_transform.Translate3d(0.0, 0.0, -27.0);
2460
[email protected]2c7c6702013-03-26 03:14:052461 gfx::Rect expected = gfx::Rect(-50, -50, 200, 200);
[email protected]fb661802013-03-25 01:59:322462 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2463 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322464 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322465
2466 // Case 2: same projection as before, except that the layer is also translated
2467 // to the side, so that only the right half of the layer should be visible.
2468 //
2469 // Explanation of expected result: The perspective ratio is (z distance
2470 // between layer and camera origin) / (z distance between projection plane and
2471 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2472 // move a layer by translating -50 units in projected surface units (so that
2473 // only half of it is visible), then we would need to translate by (-36 / 9) *
2474 // -50 == -200 in the layer's units.
2475 layer_to_surface_transform.Translate3d(-200.0, 0.0, 0.0);
[email protected]989386c2013-07-18 21:37:232476 expected = gfx::Rect(gfx::Point(50, -50),
2477 gfx::Size(100, 200)); // The right half of the layer's
2478 // bounding rect.
[email protected]fb661802013-03-25 01:59:322479 actual = LayerTreeHostCommon::CalculateVisibleRect(
2480 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322481 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322482}
2483
[email protected]989386c2013-07-18 21:37:232484TEST_F(LayerTreeHostCommonTest,
2485 VisibleRectFor3dOrthographicIsNotClippedBehindSurface) {
[email protected]fb661802013-03-25 01:59:322486 // There is currently no explicit concept of an orthographic projection plane
2487 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2488 // are technically behind the surface in an orthographic world should not be
2489 // clipped when they are flattened to the surface.
2490
[email protected]2c7c6702013-03-26 03:14:052491 gfx::Rect target_surface_rect = gfx::Rect(0, 0, 100, 100);
2492 gfx::Rect layer_content_rect = gfx::Rect(0, 0, 100, 100);
[email protected]fb661802013-03-25 01:59:322493 gfx::Transform layer_to_surface_transform;
2494
2495 // This sequence of transforms effectively rotates the layer about the y-axis
2496 // at the center of the layer.
2497 layer_to_surface_transform.MakeIdentity();
2498 layer_to_surface_transform.Translate(50.0, 0.0);
2499 layer_to_surface_transform.RotateAboutYAxis(45.0);
2500 layer_to_surface_transform.Translate(-50.0, 0.0);
2501
[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
[email protected]989386c2013-07-18 21:37:232508TEST_F(LayerTreeHostCommonTest, VisibleRectFor3dPerspectiveWhenClippedByW) {
[email protected]fb661802013-03-25 01:59:322509 // Test the calculateVisibleRect() function works correctly when projecting a
2510 // surface onto a layer, but the layer is partially behind the camera (not
2511 // just behind the projection plane). In this case, the cartesian coordinates
2512 // may seem to be valid, but actually they are not. The visible rect needs to
2513 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2514 // converting to cartesian coordinates.
2515
[email protected]2c7c6702013-03-26 03:14:052516 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
[email protected]989386c2013-07-18 21:37:232517 gfx::Rect layer_content_rect = gfx::Rect(-10, -1, 20, 2);
[email protected]fb661802013-03-25 01:59:322518 gfx::Transform layer_to_surface_transform;
2519
2520 // The layer is positioned so that the right half of the layer should be in
2521 // front of the camera, while the other half is behind the surface's
2522 // projection plane. The following sequence of transforms applies the
2523 // perspective and rotation about the center of the layer.
2524 layer_to_surface_transform.MakeIdentity();
2525 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2526 layer_to_surface_transform.Translate3d(-2.0, 0.0, 1.0);
2527 layer_to_surface_transform.RotateAboutYAxis(45.0);
2528
2529 // Sanity check that this transform does indeed cause w < 0 when applying the
2530 // transform, otherwise this code is not testing the intended scenario.
2531 bool clipped;
2532 MathUtil::MapQuad(layer_to_surface_transform,
2533 gfx::QuadF(gfx::RectF(layer_content_rect)),
2534 &clipped);
2535 ASSERT_TRUE(clipped);
2536
2537 int expected_x_position = 0;
2538 int expected_width = 10;
2539 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2540 target_surface_rect, layer_content_rect, layer_to_surface_transform);
2541 EXPECT_EQ(expected_x_position, actual.x());
2542 EXPECT_EQ(expected_width, actual.width());
2543}
2544
[email protected]989386c2013-07-18 21:37:232545TEST_F(LayerTreeHostCommonTest, VisibleRectForPerspectiveUnprojection) {
[email protected]fb661802013-03-25 01:59:322546 // To determine visible rect in layer space, there needs to be an
2547 // un-projection from surface space to layer space. When the original
2548 // transform was a perspective projection that was clipped, it returns a rect
2549 // that encloses the clipped bounds. Un-projecting this new rect may require
2550 // clipping again.
2551
2552 // This sequence of transforms causes one corner of the layer to protrude
2553 // across the w = 0 plane, and should be clipped.
[email protected]989386c2013-07-18 21:37:232554 gfx::Rect target_surface_rect = gfx::Rect(-50, -50, 100, 100);
2555 gfx::Rect layer_content_rect = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322556 gfx::Transform layer_to_surface_transform;
2557 layer_to_surface_transform.MakeIdentity();
2558 layer_to_surface_transform.ApplyPerspectiveDepth(1.0);
2559 layer_to_surface_transform.Translate3d(0.0, 0.0, -5.0);
2560 layer_to_surface_transform.RotateAboutYAxis(45.0);
2561 layer_to_surface_transform.RotateAboutXAxis(80.0);
2562
2563 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2564 // code is not testing the intended scenario.
2565 bool clipped;
2566 gfx::RectF clipped_rect =
2567 MathUtil::MapClippedRect(layer_to_surface_transform, layer_content_rect);
2568 MathUtil::ProjectQuad(
2569 Inverse(layer_to_surface_transform), gfx::QuadF(clipped_rect), &clipped);
2570 ASSERT_TRUE(clipped);
2571
2572 // Only the corner of the layer is not visible on the surface because of being
2573 // clipped. But, the net result of rounding visible region to an axis-aligned
2574 // rect is that the entire layer should still be considered visible.
[email protected]2c7c6702013-03-26 03:14:052575 gfx::Rect expected = gfx::Rect(-10, -10, 20, 20);
[email protected]fb661802013-03-25 01:59:322576 gfx::Rect actual = LayerTreeHostCommon::CalculateVisibleRect(
2577 target_surface_rect, layer_content_rect, layer_to_surface_transform);
hush6b614212014-12-04 22:37:322578 EXPECT_EQ(expected, actual);
[email protected]fb661802013-03-25 01:59:322579}
2580
[email protected]989386c2013-07-18 21:37:232581TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsForSimpleLayers) {
[email protected]fb661802013-03-25 01:59:322582 scoped_refptr<Layer> root = Layer::Create();
2583 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2584 make_scoped_refptr(new LayerWithForcedDrawsContent());
2585 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2586 make_scoped_refptr(new LayerWithForcedDrawsContent());
2587 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2588 make_scoped_refptr(new LayerWithForcedDrawsContent());
2589 root->AddChild(child1);
2590 root->AddChild(child2);
2591 root->AddChild(child3);
2592
enne2097cab2014-09-25 20:16:312593 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282594 host->SetRootLayer(root);
2595
[email protected]fb661802013-03-25 01:59:322596 gfx::Transform identity_matrix;
2597 SetLayerPropertiesForTesting(root.get(),
2598 identity_matrix,
[email protected]a2566412014-06-05 03:14:202599 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322600 gfx::PointF(),
2601 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572602 true,
[email protected]fb661802013-03-25 01:59:322603 false);
2604 SetLayerPropertiesForTesting(child1.get(),
2605 identity_matrix,
[email protected]a2566412014-06-05 03:14:202606 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322607 gfx::PointF(),
2608 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572609 true,
[email protected]fb661802013-03-25 01:59:322610 false);
2611 SetLayerPropertiesForTesting(child2.get(),
2612 identity_matrix,
[email protected]a2566412014-06-05 03:14:202613 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322614 gfx::PointF(75.f, 75.f),
2615 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572616 true,
[email protected]fb661802013-03-25 01:59:322617 false);
2618 SetLayerPropertiesForTesting(child3.get(),
2619 identity_matrix,
[email protected]a2566412014-06-05 03:14:202620 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322621 gfx::PointF(125.f, 125.f),
2622 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572623 true,
[email protected]fb661802013-03-25 01:59:322624 false);
2625
2626 ExecuteCalculateDrawProperties(root.get());
2627
hush6b614212014-12-04 22:37:322628 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2629 root->render_surface()->DrawableContentRect());
2630 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322631
2632 // Layers that do not draw content should have empty visible_content_rects.
hush6b614212014-12-04 22:37:322633 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322634
2635 // layer visible_content_rects are clipped by their target surface.
hush6b614212014-12-04 22:37:322636 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2637 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322638 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
2639
2640 // layer drawable_content_rects are not clipped.
hush6b614212014-12-04 22:37:322641 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->drawable_content_rect());
2642 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2643 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322644}
2645
[email protected]989386c2013-07-18 21:37:232646TEST_F(LayerTreeHostCommonTest,
2647 DrawableAndVisibleContentRectsForLayersClippedByLayer) {
[email protected]fb661802013-03-25 01:59:322648 scoped_refptr<Layer> root = Layer::Create();
2649 scoped_refptr<Layer> child = Layer::Create();
2650 scoped_refptr<LayerWithForcedDrawsContent> grand_child1 =
2651 make_scoped_refptr(new LayerWithForcedDrawsContent());
2652 scoped_refptr<LayerWithForcedDrawsContent> grand_child2 =
2653 make_scoped_refptr(new LayerWithForcedDrawsContent());
2654 scoped_refptr<LayerWithForcedDrawsContent> grand_child3 =
2655 make_scoped_refptr(new LayerWithForcedDrawsContent());
2656 root->AddChild(child);
2657 child->AddChild(grand_child1);
2658 child->AddChild(grand_child2);
2659 child->AddChild(grand_child3);
2660
enne2097cab2014-09-25 20:16:312661 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282662 host->SetRootLayer(root);
2663
[email protected]fb661802013-03-25 01:59:322664 gfx::Transform identity_matrix;
2665 SetLayerPropertiesForTesting(root.get(),
2666 identity_matrix,
[email protected]a2566412014-06-05 03:14:202667 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322668 gfx::PointF(),
2669 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572670 true,
[email protected]fb661802013-03-25 01:59:322671 false);
2672 SetLayerPropertiesForTesting(child.get(),
2673 identity_matrix,
[email protected]a2566412014-06-05 03:14:202674 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322675 gfx::PointF(),
2676 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572677 true,
[email protected]fb661802013-03-25 01:59:322678 false);
2679 SetLayerPropertiesForTesting(grand_child1.get(),
2680 identity_matrix,
[email protected]a2566412014-06-05 03:14:202681 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322682 gfx::PointF(5.f, 5.f),
2683 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572684 true,
[email protected]fb661802013-03-25 01:59:322685 false);
2686 SetLayerPropertiesForTesting(grand_child2.get(),
2687 identity_matrix,
[email protected]a2566412014-06-05 03:14:202688 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322689 gfx::PointF(75.f, 75.f),
2690 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572691 true,
[email protected]fb661802013-03-25 01:59:322692 false);
2693 SetLayerPropertiesForTesting(grand_child3.get(),
2694 identity_matrix,
[email protected]a2566412014-06-05 03:14:202695 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322696 gfx::PointF(125.f, 125.f),
2697 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572698 true,
[email protected]fb661802013-03-25 01:59:322699 false);
2700
2701 child->SetMasksToBounds(true);
2702 ExecuteCalculateDrawProperties(root.get());
2703
2704 ASSERT_FALSE(child->render_surface());
2705
hush6b614212014-12-04 22:37:322706 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2707 root->render_surface()->DrawableContentRect());
2708 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322709
2710 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:322711 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2712 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322713
2714 // All grandchild visible content rects should be clipped by child.
hush6b614212014-12-04 22:37:322715 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1->visible_content_rect());
2716 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322717 EXPECT_TRUE(grand_child3->visible_content_rect().IsEmpty());
2718
2719 // All grandchild DrawableContentRects should also be clipped by child.
hush6b614212014-12-04 22:37:322720 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1->drawable_content_rect());
2721 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322722 EXPECT_TRUE(grand_child3->drawable_content_rect().IsEmpty());
2723}
2724
[email protected]989386c2013-07-18 21:37:232725TEST_F(LayerTreeHostCommonTest,
2726 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:322727 scoped_refptr<Layer> root = Layer::Create();
2728 scoped_refptr<Layer> render_surface1 = Layer::Create();
2729 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2730 make_scoped_refptr(new LayerWithForcedDrawsContent());
2731 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2732 make_scoped_refptr(new LayerWithForcedDrawsContent());
2733 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2734 make_scoped_refptr(new LayerWithForcedDrawsContent());
2735 root->AddChild(render_surface1);
2736 render_surface1->AddChild(child1);
2737 render_surface1->AddChild(child2);
2738 render_surface1->AddChild(child3);
2739
enne2097cab2014-09-25 20:16:312740 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282741 host->SetRootLayer(root);
2742
[email protected]fb661802013-03-25 01:59:322743 gfx::Transform identity_matrix;
2744 SetLayerPropertiesForTesting(root.get(),
2745 identity_matrix,
[email protected]a2566412014-06-05 03:14:202746 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322747 gfx::PointF(),
2748 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572749 true,
[email protected]fb661802013-03-25 01:59:322750 false);
2751 SetLayerPropertiesForTesting(render_surface1.get(),
2752 identity_matrix,
[email protected]a2566412014-06-05 03:14:202753 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322754 gfx::PointF(),
2755 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:572756 true,
[email protected]fb661802013-03-25 01:59:322757 false);
2758 SetLayerPropertiesForTesting(child1.get(),
2759 identity_matrix,
[email protected]a2566412014-06-05 03:14:202760 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322761 gfx::PointF(5.f, 5.f),
2762 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572763 true,
[email protected]fb661802013-03-25 01:59:322764 false);
2765 SetLayerPropertiesForTesting(child2.get(),
2766 identity_matrix,
[email protected]a2566412014-06-05 03:14:202767 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322768 gfx::PointF(75.f, 75.f),
2769 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572770 true,
[email protected]fb661802013-03-25 01:59:322771 false);
2772 SetLayerPropertiesForTesting(child3.get(),
2773 identity_matrix,
[email protected]a2566412014-06-05 03:14:202774 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:322775 gfx::PointF(125.f, 125.f),
2776 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572777 true,
[email protected]fb661802013-03-25 01:59:322778 false);
2779
2780 render_surface1->SetForceRenderSurface(true);
2781 ExecuteCalculateDrawProperties(root.get());
2782
2783 ASSERT_TRUE(render_surface1->render_surface());
2784
hush6b614212014-12-04 22:37:322785 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2786 root->render_surface()->DrawableContentRect());
2787 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322788
2789 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:322790 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
2791 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322792
2793 // An unclipped surface grows its DrawableContentRect to include all drawable
2794 // regions of the subtree.
hush6b614212014-12-04 22:37:322795 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2796 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:322797
2798 // All layers that draw content into the unclipped surface are also unclipped.
hush6b614212014-12-04 22:37:322799 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
2800 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
2801 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:322802
hush6b614212014-12-04 22:37:322803 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
2804 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
2805 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:322806}
2807
[email protected]989386c2013-07-18 21:37:232808TEST_F(LayerTreeHostCommonTest,
hush887bb542014-12-02 22:49:022809 VisibleContentRectsForClippedSurfaceWithEmptyClip) {
2810 scoped_refptr<Layer> root = Layer::Create();
2811 scoped_refptr<LayerWithForcedDrawsContent> child1 =
2812 make_scoped_refptr(new LayerWithForcedDrawsContent());
2813 scoped_refptr<LayerWithForcedDrawsContent> child2 =
2814 make_scoped_refptr(new LayerWithForcedDrawsContent());
2815 scoped_refptr<LayerWithForcedDrawsContent> child3 =
2816 make_scoped_refptr(new LayerWithForcedDrawsContent());
2817 root->AddChild(child1);
2818 root->AddChild(child2);
2819 root->AddChild(child3);
2820
2821 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
2822 host->SetRootLayer(root);
2823
2824 gfx::Transform identity_matrix;
2825 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
2826 gfx::PointF(), gfx::Size(100, 100), true, false);
2827 SetLayerPropertiesForTesting(child1.get(), identity_matrix, gfx::Point3F(),
2828 gfx::PointF(5.f, 5.f), gfx::Size(50, 50), true,
2829 false);
2830 SetLayerPropertiesForTesting(child2.get(), identity_matrix, gfx::Point3F(),
2831 gfx::PointF(75.f, 75.f), gfx::Size(50, 50), true,
2832 false);
2833 SetLayerPropertiesForTesting(child3.get(), identity_matrix, gfx::Point3F(),
2834 gfx::PointF(125.f, 125.f), gfx::Size(50, 50),
2835 true, false);
2836
2837 RenderSurfaceLayerList render_surface_layer_list;
2838 // Now set the root render surface an empty clip.
2839 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
2840 root.get(), gfx::Size(), &render_surface_layer_list);
2841
2842 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
2843 ASSERT_TRUE(root->render_surface());
2844 EXPECT_FALSE(root->is_clipped());
2845
2846 gfx::Rect empty;
2847 EXPECT_EQ(empty, root->render_surface()->clip_rect());
2848 EXPECT_TRUE(root->render_surface()->is_clipped());
2849
2850 // Visible content rect calculation will check if the target surface is
2851 // clipped or not. An empty clip rect does not indicate the render surface
2852 // is unclipped.
2853 EXPECT_EQ(empty, child1->visible_content_rect());
2854 EXPECT_EQ(empty, child2->visible_content_rect());
2855 EXPECT_EQ(empty, child3->visible_content_rect());
2856}
2857
2858TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:232859 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform) {
[email protected]451107a32013-04-10 05:12:472860 scoped_refptr<Layer> root = Layer::Create();
2861 scoped_refptr<LayerWithForcedDrawsContent> child =
2862 make_scoped_refptr(new LayerWithForcedDrawsContent());
2863 root->AddChild(child);
2864
enne2097cab2014-09-25 20:16:312865 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:282866 host->SetRootLayer(root);
2867
[email protected]630ddad2013-08-16 03:01:322868 // Case 1: a truly degenerate matrix
[email protected]451107a32013-04-10 05:12:472869 gfx::Transform identity_matrix;
2870 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
[email protected]630ddad2013-08-16 03:01:322871 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
[email protected]451107a32013-04-10 05:12:472872
2873 SetLayerPropertiesForTesting(root.get(),
2874 identity_matrix,
[email protected]a2566412014-06-05 03:14:202875 gfx::Point3F(),
[email protected]451107a32013-04-10 05:12:472876 gfx::PointF(),
2877 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:572878 true,
[email protected]451107a32013-04-10 05:12:472879 false);
2880 SetLayerPropertiesForTesting(child.get(),
2881 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202882 gfx::Point3F(),
[email protected]451107a32013-04-10 05:12:472883 gfx::PointF(5.f, 5.f),
2884 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572885 true,
[email protected]451107a32013-04-10 05:12:472886 false);
2887
2888 ExecuteCalculateDrawProperties(root.get());
2889
2890 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2891 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322892
[email protected]08bdf1b2014-04-16 23:23:292893 // Case 2: a matrix with flattened z, uninvertible and not visible according
2894 // to the CSS spec.
[email protected]630ddad2013-08-16 03:01:322895 uninvertible_matrix.MakeIdentity();
[email protected]803f6b52013-09-12 00:51:262896 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322897 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2898
2899 SetLayerPropertiesForTesting(child.get(),
2900 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202901 gfx::Point3F(),
[email protected]630ddad2013-08-16 03:01:322902 gfx::PointF(5.f, 5.f),
2903 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572904 true,
[email protected]630ddad2013-08-16 03:01:322905 false);
2906
2907 ExecuteCalculateDrawProperties(root.get());
2908
[email protected]08bdf1b2014-04-16 23:23:292909 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
2910 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]630ddad2013-08-16 03:01:322911
[email protected]08bdf1b2014-04-16 23:23:292912 // Case 3: a matrix with flattened z, also uninvertible and not visible.
[email protected]630ddad2013-08-16 03:01:322913 uninvertible_matrix.MakeIdentity();
2914 uninvertible_matrix.Translate(500.0, 0.0);
[email protected]803f6b52013-09-12 00:51:262915 uninvertible_matrix.matrix().set(2, 2, 0.0);
[email protected]630ddad2013-08-16 03:01:322916 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2917
2918 SetLayerPropertiesForTesting(child.get(),
2919 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202920 gfx::Point3F(),
[email protected]630ddad2013-08-16 03:01:322921 gfx::PointF(5.f, 5.f),
2922 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:572923 true,
[email protected]630ddad2013-08-16 03:01:322924 false);
2925
2926 ExecuteCalculateDrawProperties(root.get());
2927
2928 EXPECT_TRUE(child->visible_content_rect().IsEmpty());
[email protected]08bdf1b2014-04-16 23:23:292929 EXPECT_TRUE(child->drawable_content_rect().IsEmpty());
[email protected]451107a32013-04-10 05:12:472930}
2931
[email protected]989386c2013-07-18 21:37:232932TEST_F(LayerTreeHostCommonTest,
[email protected]e43c68b2014-05-01 05:10:362933 SingularTransformDoesNotPreventClearingDrawProperties) {
2934 scoped_refptr<Layer> root = Layer::Create();
2935 scoped_refptr<LayerWithForcedDrawsContent> child =
2936 make_scoped_refptr(new LayerWithForcedDrawsContent());
2937 root->AddChild(child);
2938
enne2097cab2014-09-25 20:16:312939 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]e43c68b2014-05-01 05:10:362940 host->SetRootLayer(root);
2941
2942 gfx::Transform identity_matrix;
2943 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2944 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2945
2946 SetLayerPropertiesForTesting(root.get(),
2947 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202948 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:362949 gfx::PointF(),
2950 gfx::Size(100, 100),
2951 true,
2952 false);
2953 SetLayerPropertiesForTesting(child.get(),
2954 identity_matrix,
[email protected]a2566412014-06-05 03:14:202955 gfx::Point3F(),
[email protected]e43c68b2014-05-01 05:10:362956 gfx::PointF(5.f, 5.f),
2957 gfx::Size(50, 50),
2958 true,
2959 false);
2960
vollickeb194942014-09-12 17:45:272961 child->draw_properties().sorted_for_recursion = true;
[email protected]e43c68b2014-05-01 05:10:362962
2963 TransformOperations start_transform_operations;
2964 start_transform_operations.AppendScale(1.f, 0.f, 0.f);
2965
2966 TransformOperations end_transform_operations;
2967 end_transform_operations.AppendScale(1.f, 1.f, 0.f);
2968
2969 AddAnimatedTransformToLayer(
2970 root.get(), 10.0, start_transform_operations, end_transform_operations);
2971
2972 EXPECT_TRUE(root->TransformIsAnimating());
2973
2974 ExecuteCalculateDrawProperties(root.get());
2975
vollickeb194942014-09-12 17:45:272976 EXPECT_FALSE(child->draw_properties().sorted_for_recursion);
[email protected]e43c68b2014-05-01 05:10:362977}
2978
2979TEST_F(LayerTreeHostCommonTest,
[email protected]8dbc85c2014-05-03 03:21:062980 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) {
2981 scoped_refptr<Layer> root = Layer::Create();
2982
enne2097cab2014-09-25 20:16:312983 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]8dbc85c2014-05-03 03:21:062984 host->SetRootLayer(root);
2985
2986 gfx::Transform identity_matrix;
2987 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2988 ASSERT_FALSE(uninvertible_matrix.IsInvertible());
2989
2990 SetLayerPropertiesForTesting(root.get(),
2991 uninvertible_matrix,
[email protected]a2566412014-06-05 03:14:202992 gfx::Point3F(),
[email protected]8dbc85c2014-05-03 03:21:062993 gfx::PointF(),
2994 gfx::Size(100, 100),
2995 true,
2996 false);
2997
vollickeb194942014-09-12 17:45:272998 root->draw_properties().sorted_for_recursion = true;
[email protected]8dbc85c2014-05-03 03:21:062999
3000 EXPECT_FALSE(root->TransformIsAnimating());
3001
3002 ExecuteCalculateDrawProperties(root.get());
3003
vollickeb194942014-09-12 17:45:273004 EXPECT_FALSE(root->draw_properties().sorted_for_recursion);
[email protected]8dbc85c2014-05-03 03:21:063005}
3006
3007TEST_F(LayerTreeHostCommonTest,
[email protected]989386c2013-07-18 21:37:233008 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface) {
[email protected]fb661802013-03-25 01:59:323009 scoped_refptr<Layer> root = Layer::Create();
3010 scoped_refptr<Layer> render_surface1 = Layer::Create();
3011 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3012 make_scoped_refptr(new LayerWithForcedDrawsContent());
3013 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3014 make_scoped_refptr(new LayerWithForcedDrawsContent());
3015 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3016 make_scoped_refptr(new LayerWithForcedDrawsContent());
3017 root->AddChild(render_surface1);
3018 render_surface1->AddChild(child1);
3019 render_surface1->AddChild(child2);
3020 render_surface1->AddChild(child3);
3021
enne2097cab2014-09-25 20:16:313022 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283023 host->SetRootLayer(root);
3024
[email protected]fb661802013-03-25 01:59:323025 gfx::Transform identity_matrix;
3026 SetLayerPropertiesForTesting(root.get(),
3027 identity_matrix,
[email protected]a2566412014-06-05 03:14:203028 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323029 gfx::PointF(),
3030 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573031 true,
[email protected]fb661802013-03-25 01:59:323032 false);
3033 SetLayerPropertiesForTesting(render_surface1.get(),
3034 identity_matrix,
[email protected]a2566412014-06-05 03:14:203035 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323036 gfx::PointF(),
3037 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573038 true,
[email protected]fb661802013-03-25 01:59:323039 false);
3040 SetLayerPropertiesForTesting(child1.get(),
3041 identity_matrix,
[email protected]a2566412014-06-05 03:14:203042 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323043 gfx::PointF(5.f, 5.f),
3044 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573045 true,
[email protected]fb661802013-03-25 01:59:323046 false);
3047 SetLayerPropertiesForTesting(child2.get(),
3048 identity_matrix,
[email protected]a2566412014-06-05 03:14:203049 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323050 gfx::PointF(75.f, 75.f),
3051 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573052 true,
[email protected]fb661802013-03-25 01:59:323053 false);
3054 SetLayerPropertiesForTesting(child3.get(),
3055 identity_matrix,
[email protected]a2566412014-06-05 03:14:203056 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323057 gfx::PointF(125.f, 125.f),
3058 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573059 true,
[email protected]fb661802013-03-25 01:59:323060 false);
3061
3062 root->SetMasksToBounds(true);
3063 render_surface1->SetForceRenderSurface(true);
3064 ExecuteCalculateDrawProperties(root.get());
3065
3066 ASSERT_TRUE(render_surface1->render_surface());
3067
hush6b614212014-12-04 22:37:323068 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3069 root->render_surface()->DrawableContentRect());
3070 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323071
3072 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323073 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3074 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323075
3076 // A clipped surface grows its DrawableContentRect to include all drawable
3077 // regions of the subtree, but also gets clamped by the ancestor's clip.
hush6b614212014-12-04 22:37:323078 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3079 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323080
3081 // All layers that draw content into the surface have their visible content
3082 // rect clipped by the surface clip rect.
hush6b614212014-12-04 22:37:323083 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3084 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323085 EXPECT_TRUE(child3->visible_content_rect().IsEmpty());
3086
3087 // But the DrawableContentRects are unclipped.
hush6b614212014-12-04 22:37:323088 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3089 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3090 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323091}
3092
[email protected]989386c2013-07-18 21:37:233093TEST_F(LayerTreeHostCommonTest,
3094 DrawableAndVisibleContentRectsForSurfaceHierarchy) {
[email protected]fb661802013-03-25 01:59:323095 // Check that clipping does not propagate down surfaces.
3096 scoped_refptr<Layer> root = Layer::Create();
3097 scoped_refptr<Layer> render_surface1 = Layer::Create();
3098 scoped_refptr<Layer> render_surface2 = Layer::Create();
3099 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3100 make_scoped_refptr(new LayerWithForcedDrawsContent());
3101 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3102 make_scoped_refptr(new LayerWithForcedDrawsContent());
3103 scoped_refptr<LayerWithForcedDrawsContent> child3 =
3104 make_scoped_refptr(new LayerWithForcedDrawsContent());
3105 root->AddChild(render_surface1);
3106 render_surface1->AddChild(render_surface2);
3107 render_surface2->AddChild(child1);
3108 render_surface2->AddChild(child2);
3109 render_surface2->AddChild(child3);
3110
enne2097cab2014-09-25 20:16:313111 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283112 host->SetRootLayer(root);
3113
[email protected]fb661802013-03-25 01:59:323114 gfx::Transform identity_matrix;
3115 SetLayerPropertiesForTesting(root.get(),
3116 identity_matrix,
[email protected]a2566412014-06-05 03:14:203117 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323118 gfx::PointF(),
3119 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573120 true,
[email protected]fb661802013-03-25 01:59:323121 false);
3122 SetLayerPropertiesForTesting(render_surface1.get(),
3123 identity_matrix,
[email protected]a2566412014-06-05 03:14:203124 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323125 gfx::PointF(),
3126 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573127 true,
[email protected]fb661802013-03-25 01:59:323128 false);
3129 SetLayerPropertiesForTesting(render_surface2.get(),
3130 identity_matrix,
[email protected]a2566412014-06-05 03:14:203131 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323132 gfx::PointF(),
3133 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573134 true,
[email protected]fb661802013-03-25 01:59:323135 false);
3136 SetLayerPropertiesForTesting(child1.get(),
3137 identity_matrix,
[email protected]a2566412014-06-05 03:14:203138 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323139 gfx::PointF(5.f, 5.f),
3140 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573141 true,
[email protected]fb661802013-03-25 01:59:323142 false);
3143 SetLayerPropertiesForTesting(child2.get(),
3144 identity_matrix,
[email protected]a2566412014-06-05 03:14:203145 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323146 gfx::PointF(75.f, 75.f),
3147 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573148 true,
[email protected]fb661802013-03-25 01:59:323149 false);
3150 SetLayerPropertiesForTesting(child3.get(),
3151 identity_matrix,
[email protected]a2566412014-06-05 03:14:203152 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323153 gfx::PointF(125.f, 125.f),
3154 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573155 true,
[email protected]fb661802013-03-25 01:59:323156 false);
3157
3158 root->SetMasksToBounds(true);
3159 render_surface1->SetForceRenderSurface(true);
3160 render_surface2->SetForceRenderSurface(true);
3161 ExecuteCalculateDrawProperties(root.get());
3162
3163 ASSERT_TRUE(render_surface1->render_surface());
3164 ASSERT_TRUE(render_surface2->render_surface());
3165
hush6b614212014-12-04 22:37:323166 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3167 root->render_surface()->DrawableContentRect());
3168 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323169
3170 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323171 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3172 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
3173 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323174
3175 // A clipped surface grows its DrawableContentRect to include all drawable
3176 // regions of the subtree, but also gets clamped by the ancestor's clip.
hush6b614212014-12-04 22:37:323177 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3178 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323179
3180 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3181 // is only implicitly clipped by render_surface1's content rect. So,
3182 // render_surface2 grows to enclose all drawable content of its subtree.
hush6b614212014-12-04 22:37:323183 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
3184 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323185
3186 // All layers that draw content into render_surface2 think they are unclipped.
hush6b614212014-12-04 22:37:323187 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3188 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3189 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323190
3191 // DrawableContentRects are also unclipped.
hush6b614212014-12-04 22:37:323192 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1->drawable_content_rect());
3193 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2->drawable_content_rect());
3194 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323195}
3196
[email protected]989386c2013-07-18 21:37:233197TEST_F(LayerTreeHostCommonTest,
3198 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface) {
[email protected]fb661802013-03-25 01:59:323199 // Layers that have non-axis aligned bounds (due to transforms) have an
3200 // expanded, axis-aligned DrawableContentRect and visible content rect.
3201
3202 scoped_refptr<Layer> root = Layer::Create();
3203 scoped_refptr<Layer> render_surface1 = Layer::Create();
3204 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3205 make_scoped_refptr(new LayerWithForcedDrawsContent());
3206 root->AddChild(render_surface1);
3207 render_surface1->AddChild(child1);
3208
enne2097cab2014-09-25 20:16:313209 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283210 host->SetRootLayer(root);
3211
[email protected]fb661802013-03-25 01:59:323212 gfx::Transform identity_matrix;
3213 gfx::Transform child_rotation;
3214 child_rotation.Rotate(45.0);
3215 SetLayerPropertiesForTesting(root.get(),
3216 identity_matrix,
[email protected]a2566412014-06-05 03:14:203217 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323218 gfx::PointF(),
3219 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573220 true,
[email protected]fb661802013-03-25 01:59:323221 false);
3222 SetLayerPropertiesForTesting(render_surface1.get(),
3223 identity_matrix,
[email protected]a2566412014-06-05 03:14:203224 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323225 gfx::PointF(),
3226 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573227 true,
[email protected]fb661802013-03-25 01:59:323228 false);
3229 SetLayerPropertiesForTesting(child1.get(),
3230 child_rotation,
[email protected]a2566412014-06-05 03:14:203231 gfx::Point3F(25, 25, 0.f),
[email protected]fb661802013-03-25 01:59:323232 gfx::PointF(25.f, 25.f),
3233 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573234 true,
[email protected]fb661802013-03-25 01:59:323235 false);
3236
3237 render_surface1->SetForceRenderSurface(true);
3238 ExecuteCalculateDrawProperties(root.get());
3239
3240 ASSERT_TRUE(render_surface1->render_surface());
3241
hush6b614212014-12-04 22:37:323242 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3243 root->render_surface()->DrawableContentRect());
3244 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323245
3246 // Layers that do not draw content should have empty visible content rects.
hush6b614212014-12-04 22:37:323247 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
3248 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323249
3250 // The unclipped surface grows its DrawableContentRect to include all drawable
3251 // regions of the subtree.
3252 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
3253 gfx::Rect expected_surface_drawable_content =
[email protected]803f6b52013-09-12 00:51:263254 gfx::Rect(50 - diagonal_radius,
3255 50 - diagonal_radius,
3256 diagonal_radius * 2,
3257 diagonal_radius * 2);
hush6b614212014-12-04 22:37:323258 EXPECT_EQ(expected_surface_drawable_content,
3259 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323260
3261 // All layers that draw content into the unclipped surface are also unclipped.
hush6b614212014-12-04 22:37:323262 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3263 EXPECT_EQ(expected_surface_drawable_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323264}
3265
[email protected]989386c2013-07-18 21:37:233266TEST_F(LayerTreeHostCommonTest,
3267 DrawableAndVisibleContentRectsWithTransformOnClippedSurface) {
[email protected]fb661802013-03-25 01:59:323268 // Layers that have non-axis aligned bounds (due to transforms) have an
3269 // expanded, axis-aligned DrawableContentRect and visible content rect.
3270
3271 scoped_refptr<Layer> root = Layer::Create();
3272 scoped_refptr<Layer> render_surface1 = Layer::Create();
3273 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3274 make_scoped_refptr(new LayerWithForcedDrawsContent());
3275 root->AddChild(render_surface1);
3276 render_surface1->AddChild(child1);
3277
enne2097cab2014-09-25 20:16:313278 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283279 host->SetRootLayer(root);
3280
[email protected]fb661802013-03-25 01:59:323281 gfx::Transform identity_matrix;
3282 gfx::Transform child_rotation;
3283 child_rotation.Rotate(45.0);
3284 SetLayerPropertiesForTesting(root.get(),
3285 identity_matrix,
[email protected]a2566412014-06-05 03:14:203286 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323287 gfx::PointF(),
3288 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573289 true,
[email protected]fb661802013-03-25 01:59:323290 false);
3291 SetLayerPropertiesForTesting(render_surface1.get(),
3292 identity_matrix,
[email protected]a2566412014-06-05 03:14:203293 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323294 gfx::PointF(),
3295 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573296 true,
[email protected]fb661802013-03-25 01:59:323297 false);
[email protected]a2566412014-06-05 03:14:203298
[email protected]fb661802013-03-25 01:59:323299 SetLayerPropertiesForTesting(child1.get(),
3300 child_rotation,
[email protected]a2566412014-06-05 03:14:203301 gfx::Point3F(25, 25, 0.f),
[email protected]fb661802013-03-25 01:59:323302 gfx::PointF(25.f, 25.f),
3303 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573304 true,
[email protected]fb661802013-03-25 01:59:323305 false);
3306
3307 root->SetMasksToBounds(true);
3308 render_surface1->SetForceRenderSurface(true);
3309 ExecuteCalculateDrawProperties(root.get());
3310
3311 ASSERT_TRUE(render_surface1->render_surface());
3312
3313 // The clipped surface clamps the DrawableContentRect that encloses the
3314 // rotated layer.
3315 int diagonal_radius = ceil(sqrt(2.0) * 25.0);
[email protected]803f6b52013-09-12 00:51:263316 gfx::Rect unclipped_surface_content = gfx::Rect(50 - diagonal_radius,
3317 50 - diagonal_radius,
3318 diagonal_radius * 2,
3319 diagonal_radius * 2);
[email protected]fb661802013-03-25 01:59:323320 gfx::Rect expected_surface_drawable_content =
3321 gfx::IntersectRects(unclipped_surface_content, gfx::Rect(0, 0, 50, 50));
hush6b614212014-12-04 22:37:323322 EXPECT_EQ(expected_surface_drawable_content,
3323 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323324
3325 // On the clipped surface, only a quarter of the child1 is visible, but when
3326 // rotating it back to child1's content space, the actual enclosing rect ends
3327 // up covering the full left half of child1.
[email protected]803f6b52013-09-12 00:51:263328 //
3329 // Given the floating point math, this number is a little bit fuzzy.
hush6b614212014-12-04 22:37:323330 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323331
3332 // The child's DrawableContentRect is unclipped.
hush6b614212014-12-04 22:37:323333 EXPECT_EQ(unclipped_surface_content, child1->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323334}
3335
[email protected]989386c2013-07-18 21:37:233336TEST_F(LayerTreeHostCommonTest, DrawableAndVisibleContentRectsInHighDPI) {
[email protected]fb661802013-03-25 01:59:323337 MockContentLayerClient client;
3338
3339 scoped_refptr<Layer> root = Layer::Create();
sohan.jyotie3bd6192014-10-13 07:13:593340 scoped_refptr<FakePictureLayer> render_surface1 =
3341 CreateDrawablePictureLayer(&client);
3342 scoped_refptr<FakePictureLayer> render_surface2 =
3343 CreateDrawablePictureLayer(&client);
3344 scoped_refptr<FakePictureLayer> child1 = CreateDrawablePictureLayer(&client);
3345 scoped_refptr<FakePictureLayer> child2 = CreateDrawablePictureLayer(&client);
3346 scoped_refptr<FakePictureLayer> child3 = CreateDrawablePictureLayer(&client);
[email protected]fb661802013-03-25 01:59:323347 root->AddChild(render_surface1);
3348 render_surface1->AddChild(render_surface2);
3349 render_surface2->AddChild(child1);
3350 render_surface2->AddChild(child2);
3351 render_surface2->AddChild(child3);
3352
enne2097cab2014-09-25 20:16:313353 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283354 host->SetRootLayer(root);
3355
[email protected]fb661802013-03-25 01:59:323356 gfx::Transform identity_matrix;
3357 SetLayerPropertiesForTesting(root.get(),
3358 identity_matrix,
[email protected]a2566412014-06-05 03:14:203359 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323360 gfx::PointF(),
3361 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573362 true,
[email protected]fb661802013-03-25 01:59:323363 false);
3364 SetLayerPropertiesForTesting(render_surface1.get(),
3365 identity_matrix,
[email protected]a2566412014-06-05 03:14:203366 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323367 gfx::PointF(5.f, 5.f),
3368 gfx::Size(3, 4),
[email protected]56fffdd2014-02-11 19:50:573369 true,
[email protected]fb661802013-03-25 01:59:323370 false);
3371 SetLayerPropertiesForTesting(render_surface2.get(),
3372 identity_matrix,
[email protected]a2566412014-06-05 03:14:203373 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323374 gfx::PointF(5.f, 5.f),
3375 gfx::Size(7, 13),
[email protected]56fffdd2014-02-11 19:50:573376 true,
[email protected]fb661802013-03-25 01:59:323377 false);
3378 SetLayerPropertiesForTesting(child1.get(),
3379 identity_matrix,
[email protected]a2566412014-06-05 03:14:203380 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323381 gfx::PointF(5.f, 5.f),
3382 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573383 true,
[email protected]fb661802013-03-25 01:59:323384 false);
3385 SetLayerPropertiesForTesting(child2.get(),
3386 identity_matrix,
[email protected]a2566412014-06-05 03:14:203387 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323388 gfx::PointF(75.f, 75.f),
3389 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573390 true,
[email protected]fb661802013-03-25 01:59:323391 false);
3392 SetLayerPropertiesForTesting(child3.get(),
3393 identity_matrix,
[email protected]a2566412014-06-05 03:14:203394 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323395 gfx::PointF(125.f, 125.f),
3396 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:573397 true,
[email protected]fb661802013-03-25 01:59:323398 false);
3399
3400 float device_scale_factor = 2.f;
3401
3402 root->SetMasksToBounds(true);
3403 render_surface1->SetForceRenderSurface(true);
3404 render_surface2->SetForceRenderSurface(true);
3405 ExecuteCalculateDrawProperties(root.get(), device_scale_factor);
3406
3407 ASSERT_TRUE(render_surface1->render_surface());
3408 ASSERT_TRUE(render_surface2->render_surface());
3409
3410 // drawable_content_rects for all layers and surfaces are scaled by
3411 // device_scale_factor.
hush6b614212014-12-04 22:37:323412 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3413 root->render_surface()->DrawableContentRect());
3414 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root->drawable_content_rect());
3415 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3416 render_surface1->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323417
3418 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3419 // is only implicitly clipped by render_surface1.
hush6b614212014-12-04 22:37:323420 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3421 render_surface2->render_surface()->DrawableContentRect());
[email protected]fb661802013-03-25 01:59:323422
hush6b614212014-12-04 22:37:323423 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1->drawable_content_rect());
3424 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2->drawable_content_rect());
3425 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:323426
3427 // The root layer does not actually draw content of its own.
hush6b614212014-12-04 22:37:323428 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323429
sohan.jyotie3bd6192014-10-13 07:13:593430 // All layer visible content rects are not expressed in content space of each
3431 // layer, so they are not scaled by the device_scale_factor.
hush6b614212014-12-04 22:37:323432 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1->visible_content_rect());
3433 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2->visible_content_rect());
3434 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1->visible_content_rect());
3435 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2->visible_content_rect());
3436 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3->visible_content_rect());
[email protected]fb661802013-03-25 01:59:323437}
3438
[email protected]989386c2013-07-18 21:37:233439TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) {
[email protected]fb661802013-03-25 01:59:323440 // Verify the behavior of back-face culling when there are no preserve-3d
3441 // layers. Note that 3d transforms still apply in this case, but they are
3442 // "flattened" to each parent layer according to current W3C spec.
3443
3444 const gfx::Transform identity_matrix;
3445 scoped_refptr<Layer> parent = Layer::Create();
3446 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3447 make_scoped_refptr(new LayerWithForcedDrawsContent());
3448 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3449 make_scoped_refptr(new LayerWithForcedDrawsContent());
3450 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3451 make_scoped_refptr(new LayerWithForcedDrawsContent());
3452 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3453 make_scoped_refptr(new LayerWithForcedDrawsContent());
3454 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233455 front_facing_child_of_front_facing_surface =
3456 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323457 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233458 back_facing_child_of_front_facing_surface =
3459 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323460 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233461 front_facing_child_of_back_facing_surface =
3462 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323463 scoped_refptr<LayerWithForcedDrawsContent>
[email protected]989386c2013-07-18 21:37:233464 back_facing_child_of_back_facing_surface =
3465 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]fb661802013-03-25 01:59:323466
3467 parent->AddChild(front_facing_child);
3468 parent->AddChild(back_facing_child);
3469 parent->AddChild(front_facing_surface);
3470 parent->AddChild(back_facing_surface);
3471 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3472 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3473 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3474 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3475
enne2097cab2014-09-25 20:16:313476 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283477 host->SetRootLayer(parent);
3478
[email protected]fb661802013-03-25 01:59:323479 // Nothing is double-sided
3480 front_facing_child->SetDoubleSided(false);
3481 back_facing_child->SetDoubleSided(false);
3482 front_facing_surface->SetDoubleSided(false);
3483 back_facing_surface->SetDoubleSided(false);
3484 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3485 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3486 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3487 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3488
3489 gfx::Transform backface_matrix;
3490 backface_matrix.Translate(50.0, 50.0);
3491 backface_matrix.RotateAboutYAxis(180.0);
3492 backface_matrix.Translate(-50.0, -50.0);
3493
3494 // Having a descendant and opacity will force these to have render surfaces.
3495 front_facing_surface->SetOpacity(0.5f);
3496 back_facing_surface->SetOpacity(0.5f);
3497
3498 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3499 // these layers should blindly use their own local transforms to determine
3500 // back-face culling.
3501 SetLayerPropertiesForTesting(parent.get(),
3502 identity_matrix,
[email protected]a2566412014-06-05 03:14:203503 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323504 gfx::PointF(),
3505 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573506 true,
[email protected]fb661802013-03-25 01:59:323507 false);
3508 SetLayerPropertiesForTesting(front_facing_child.get(),
3509 identity_matrix,
[email protected]a2566412014-06-05 03:14:203510 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323511 gfx::PointF(),
3512 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573513 true,
[email protected]fb661802013-03-25 01:59:323514 false);
3515 SetLayerPropertiesForTesting(back_facing_child.get(),
3516 backface_matrix,
[email protected]a2566412014-06-05 03:14:203517 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323518 gfx::PointF(),
3519 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573520 true,
[email protected]fb661802013-03-25 01:59:323521 false);
3522 SetLayerPropertiesForTesting(front_facing_surface.get(),
3523 identity_matrix,
[email protected]a2566412014-06-05 03:14:203524 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323525 gfx::PointF(),
3526 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573527 true,
[email protected]fb661802013-03-25 01:59:323528 false);
3529 SetLayerPropertiesForTesting(back_facing_surface.get(),
3530 backface_matrix,
[email protected]a2566412014-06-05 03:14:203531 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323532 gfx::PointF(),
3533 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573534 true,
[email protected]fb661802013-03-25 01:59:323535 false);
3536 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3537 identity_matrix,
[email protected]a2566412014-06-05 03:14:203538 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323539 gfx::PointF(),
3540 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573541 true,
[email protected]fb661802013-03-25 01:59:323542 false);
3543 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3544 backface_matrix,
[email protected]a2566412014-06-05 03:14:203545 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323546 gfx::PointF(),
3547 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573548 true,
[email protected]fb661802013-03-25 01:59:323549 false);
3550 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3551 identity_matrix,
[email protected]a2566412014-06-05 03:14:203552 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323553 gfx::PointF(),
3554 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573555 true,
[email protected]fb661802013-03-25 01:59:323556 false);
3557 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3558 backface_matrix,
[email protected]a2566412014-06-05 03:14:203559 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323560 gfx::PointF(),
3561 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573562 true,
[email protected]fb661802013-03-25 01:59:323563 false);
3564
[email protected]989386c2013-07-18 21:37:233565 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533566 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3567 parent.get(), parent->bounds(), &render_surface_layer_list);
3568 inputs.can_adjust_raster_scales = true;
3569 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323570
3571 // Verify which render surfaces were created.
3572 EXPECT_FALSE(front_facing_child->render_surface());
3573 EXPECT_FALSE(back_facing_child->render_surface());
3574 EXPECT_TRUE(front_facing_surface->render_surface());
3575 EXPECT_TRUE(back_facing_surface->render_surface());
3576 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3577 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3578 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3579 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3580
3581 // Verify the render_surface_layer_list.
3582 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233583 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3584 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323585 // Even though the back facing surface LAYER gets culled, the other
3586 // descendants should still be added, so the SURFACE should not be culled.
[email protected]989386c2013-07-18 21:37:233587 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id());
[email protected]fb661802013-03-25 01:59:323588
3589 // Verify root surface's layer list.
3590 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233591 3u,
3592 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3593 EXPECT_EQ(front_facing_child->id(),
3594 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573595 ->render_surface()
3596 ->layer_list()
3597 .at(0)
3598 ->id());
[email protected]989386c2013-07-18 21:37:233599 EXPECT_EQ(front_facing_surface->id(),
3600 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573601 ->render_surface()
3602 ->layer_list()
3603 .at(1)
3604 ->id());
[email protected]989386c2013-07-18 21:37:233605 EXPECT_EQ(back_facing_surface->id(),
3606 render_surface_layer_list.at(0)
[email protected]56fffdd2014-02-11 19:50:573607 ->render_surface()
3608 ->layer_list()
3609 .at(2)
3610 ->id());
[email protected]fb661802013-03-25 01:59:323611
3612 // Verify front_facing_surface's layer list.
3613 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233614 2u,
3615 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3616 EXPECT_EQ(front_facing_surface->id(),
3617 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573618 ->render_surface()
3619 ->layer_list()
3620 .at(0)
3621 ->id());
[email protected]989386c2013-07-18 21:37:233622 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3623 render_surface_layer_list.at(1)
[email protected]56fffdd2014-02-11 19:50:573624 ->render_surface()
3625 ->layer_list()
3626 .at(1)
3627 ->id());
[email protected]fb661802013-03-25 01:59:323628
3629 // Verify back_facing_surface's layer list; its own layer should be culled
3630 // from the surface list.
3631 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233632 1u,
3633 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3634 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3635 render_surface_layer_list.at(2)
[email protected]56fffdd2014-02-11 19:50:573636 ->render_surface()
3637 ->layer_list()
3638 .at(0)
3639 ->id());
[email protected]fb661802013-03-25 01:59:323640}
3641
[email protected]989386c2013-07-18 21:37:233642TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
[email protected]fb661802013-03-25 01:59:323643 // Verify the behavior of back-face culling when preserves-3d transform style
3644 // is used.
3645
3646 const gfx::Transform identity_matrix;
3647 scoped_refptr<Layer> parent = Layer::Create();
3648 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3649 make_scoped_refptr(new LayerWithForcedDrawsContent());
3650 scoped_refptr<LayerWithForcedDrawsContent> back_facing_child =
3651 make_scoped_refptr(new LayerWithForcedDrawsContent());
3652 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3653 make_scoped_refptr(new LayerWithForcedDrawsContent());
3654 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3655 make_scoped_refptr(new LayerWithForcedDrawsContent());
3656 scoped_refptr<LayerWithForcedDrawsContent>
3657 front_facing_child_of_front_facing_surface =
3658 make_scoped_refptr(new LayerWithForcedDrawsContent());
3659 scoped_refptr<LayerWithForcedDrawsContent>
3660 back_facing_child_of_front_facing_surface =
3661 make_scoped_refptr(new LayerWithForcedDrawsContent());
3662 scoped_refptr<LayerWithForcedDrawsContent>
3663 front_facing_child_of_back_facing_surface =
3664 make_scoped_refptr(new LayerWithForcedDrawsContent());
3665 scoped_refptr<LayerWithForcedDrawsContent>
3666 back_facing_child_of_back_facing_surface =
3667 make_scoped_refptr(new LayerWithForcedDrawsContent());
3668 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer1 =
3669 make_scoped_refptr(new LayerWithForcedDrawsContent());
3670 scoped_refptr<LayerWithForcedDrawsContent> dummy_replica_layer2 =
3671 make_scoped_refptr(new LayerWithForcedDrawsContent());
3672
3673 parent->AddChild(front_facing_child);
3674 parent->AddChild(back_facing_child);
3675 parent->AddChild(front_facing_surface);
3676 parent->AddChild(back_facing_surface);
3677 front_facing_surface->AddChild(front_facing_child_of_front_facing_surface);
3678 front_facing_surface->AddChild(back_facing_child_of_front_facing_surface);
3679 back_facing_surface->AddChild(front_facing_child_of_back_facing_surface);
3680 back_facing_surface->AddChild(back_facing_child_of_back_facing_surface);
3681
enne2097cab2014-09-25 20:16:313682 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283683 host->SetRootLayer(parent);
3684
[email protected]fb661802013-03-25 01:59:323685 // Nothing is double-sided
3686 front_facing_child->SetDoubleSided(false);
3687 back_facing_child->SetDoubleSided(false);
3688 front_facing_surface->SetDoubleSided(false);
3689 back_facing_surface->SetDoubleSided(false);
3690 front_facing_child_of_front_facing_surface->SetDoubleSided(false);
3691 back_facing_child_of_front_facing_surface->SetDoubleSided(false);
3692 front_facing_child_of_back_facing_surface->SetDoubleSided(false);
3693 back_facing_child_of_back_facing_surface->SetDoubleSided(false);
3694
3695 gfx::Transform backface_matrix;
3696 backface_matrix.Translate(50.0, 50.0);
3697 backface_matrix.RotateAboutYAxis(180.0);
3698 backface_matrix.Translate(-50.0, -50.0);
3699
3700 // Opacity will not force creation of render surfaces in this case because of
3701 // the preserve-3d transform style. Instead, an example of when a surface
3702 // would be created with preserve-3d is when there is a replica layer.
3703 front_facing_surface->SetReplicaLayer(dummy_replica_layer1.get());
3704 back_facing_surface->SetReplicaLayer(dummy_replica_layer2.get());
3705
3706 // Each surface creates its own new 3d rendering context (as defined by W3C
3707 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3708 // rendering context should use the transform with respect to that context.
3709 // This 3d rendering context occurs when (a) parent's transform style is flat
3710 // and (b) the layer's transform style is preserve-3d.
3711 SetLayerPropertiesForTesting(parent.get(),
3712 identity_matrix,
[email protected]a2566412014-06-05 03:14:203713 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323714 gfx::PointF(),
3715 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573716 true,
[email protected]fb661802013-03-25 01:59:323717 false); // parent transform style is flat.
3718 SetLayerPropertiesForTesting(front_facing_child.get(),
3719 identity_matrix,
[email protected]a2566412014-06-05 03:14:203720 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323721 gfx::PointF(),
3722 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573723 true,
[email protected]fb661802013-03-25 01:59:323724 false);
3725 SetLayerPropertiesForTesting(back_facing_child.get(),
3726 backface_matrix,
[email protected]a2566412014-06-05 03:14:203727 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323728 gfx::PointF(),
3729 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573730 true,
[email protected]fb661802013-03-25 01:59:323731 false);
[email protected]56fffdd2014-02-11 19:50:573732 // surface transform style is preserve-3d.
3733 SetLayerPropertiesForTesting(front_facing_surface.get(),
3734 identity_matrix,
[email protected]a2566412014-06-05 03:14:203735 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:573736 gfx::PointF(),
3737 gfx::Size(100, 100),
3738 false,
3739 true);
3740 // surface transform style is preserve-3d.
3741 SetLayerPropertiesForTesting(back_facing_surface.get(),
3742 backface_matrix,
[email protected]a2566412014-06-05 03:14:203743 gfx::Point3F(),
[email protected]56fffdd2014-02-11 19:50:573744 gfx::PointF(),
3745 gfx::Size(100, 100),
3746 false,
3747 true);
[email protected]fb661802013-03-25 01:59:323748 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface.get(),
3749 identity_matrix,
[email protected]a2566412014-06-05 03:14:203750 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323751 gfx::PointF(),
3752 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573753 true,
3754 true);
[email protected]fb661802013-03-25 01:59:323755 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface.get(),
3756 backface_matrix,
[email protected]a2566412014-06-05 03:14:203757 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323758 gfx::PointF(),
3759 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573760 true,
3761 true);
[email protected]fb661802013-03-25 01:59:323762 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface.get(),
3763 identity_matrix,
[email protected]a2566412014-06-05 03:14:203764 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323765 gfx::PointF(),
3766 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573767 true,
3768 true);
[email protected]fb661802013-03-25 01:59:323769 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3770 backface_matrix,
[email protected]a2566412014-06-05 03:14:203771 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323772 gfx::PointF(),
3773 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573774 true,
3775 true);
[email protected]fb661802013-03-25 01:59:323776
[email protected]989386c2013-07-18 21:37:233777 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533778 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3779 parent.get(), parent->bounds(), &render_surface_layer_list);
3780 inputs.can_adjust_raster_scales = true;
3781 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323782
awoloszyne83f28c2014-12-22 15:40:003783 // Verify which render surfaces were created and used.
[email protected]fb661802013-03-25 01:59:323784 EXPECT_FALSE(front_facing_child->render_surface());
3785 EXPECT_FALSE(back_facing_child->render_surface());
3786 EXPECT_TRUE(front_facing_surface->render_surface());
awoloszyne83f28c2014-12-22 15:40:003787 EXPECT_NE(back_facing_surface->render_target(), back_facing_surface);
3788 // We expect that a render_surface was created but not used.
3789 EXPECT_TRUE(back_facing_surface->render_surface());
[email protected]fb661802013-03-25 01:59:323790 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3791 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3792 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3793 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3794
3795 // Verify the render_surface_layer_list. The back-facing surface should be
3796 // culled.
3797 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233798 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3799 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323800
3801 // Verify root surface's layer list.
3802 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233803 2u,
3804 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3805 EXPECT_EQ(front_facing_child->id(),
3806 render_surface_layer_list.at(0)
3807 ->render_surface()->layer_list().at(0)->id());
3808 EXPECT_EQ(front_facing_surface->id(),
3809 render_surface_layer_list.at(0)
3810 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323811
3812 // Verify front_facing_surface's layer list.
3813 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233814 2u,
3815 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3816 EXPECT_EQ(front_facing_surface->id(),
3817 render_surface_layer_list.at(1)
3818 ->render_surface()->layer_list().at(0)->id());
3819 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3820 render_surface_layer_list.at(1)
3821 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323822}
3823
[email protected]989386c2013-07-18 21:37:233824TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
[email protected]fb661802013-03-25 01:59:323825 // Verify that layers are appropriately culled when their back face is showing
3826 // and they are not double sided, while animations are going on.
3827 //
3828 // Layers that are animating do not get culled on the main thread, as their
3829 // transforms should be treated as "unknown" so we can not be sure that their
3830 // back face is really showing.
3831 const gfx::Transform identity_matrix;
3832 scoped_refptr<Layer> parent = Layer::Create();
3833 scoped_refptr<LayerWithForcedDrawsContent> child =
3834 make_scoped_refptr(new LayerWithForcedDrawsContent());
3835 scoped_refptr<LayerWithForcedDrawsContent> animating_surface =
3836 make_scoped_refptr(new LayerWithForcedDrawsContent());
3837 scoped_refptr<LayerWithForcedDrawsContent> child_of_animating_surface =
3838 make_scoped_refptr(new LayerWithForcedDrawsContent());
3839 scoped_refptr<LayerWithForcedDrawsContent> animating_child =
3840 make_scoped_refptr(new LayerWithForcedDrawsContent());
3841 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3842 make_scoped_refptr(new LayerWithForcedDrawsContent());
3843
3844 parent->AddChild(child);
3845 parent->AddChild(animating_surface);
3846 animating_surface->AddChild(child_of_animating_surface);
3847 parent->AddChild(animating_child);
3848 parent->AddChild(child2);
3849
enne2097cab2014-09-25 20:16:313850 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283851 host->SetRootLayer(parent);
3852
[email protected]fb661802013-03-25 01:59:323853 // Nothing is double-sided
3854 child->SetDoubleSided(false);
3855 child2->SetDoubleSided(false);
3856 animating_surface->SetDoubleSided(false);
3857 child_of_animating_surface->SetDoubleSided(false);
3858 animating_child->SetDoubleSided(false);
3859
3860 gfx::Transform backface_matrix;
3861 backface_matrix.Translate(50.0, 50.0);
3862 backface_matrix.RotateAboutYAxis(180.0);
3863 backface_matrix.Translate(-50.0, -50.0);
3864
3865 // Make our render surface.
3866 animating_surface->SetForceRenderSurface(true);
3867
3868 // Animate the transform on the render surface.
3869 AddAnimatedTransformToController(
3870 animating_surface->layer_animation_controller(), 10.0, 30, 0);
3871 // This is just an animating layer, not a surface.
3872 AddAnimatedTransformToController(
3873 animating_child->layer_animation_controller(), 10.0, 30, 0);
3874
3875 SetLayerPropertiesForTesting(parent.get(),
3876 identity_matrix,
[email protected]a2566412014-06-05 03:14:203877 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323878 gfx::PointF(),
3879 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573880 true,
[email protected]fb661802013-03-25 01:59:323881 false);
3882 SetLayerPropertiesForTesting(child.get(),
3883 backface_matrix,
[email protected]a2566412014-06-05 03:14:203884 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323885 gfx::PointF(),
3886 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573887 true,
[email protected]fb661802013-03-25 01:59:323888 false);
3889 SetLayerPropertiesForTesting(animating_surface.get(),
3890 backface_matrix,
[email protected]a2566412014-06-05 03:14:203891 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323892 gfx::PointF(),
3893 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573894 true,
[email protected]fb661802013-03-25 01:59:323895 false);
3896 SetLayerPropertiesForTesting(child_of_animating_surface.get(),
3897 backface_matrix,
[email protected]a2566412014-06-05 03:14:203898 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323899 gfx::PointF(),
3900 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573901 true,
[email protected]fb661802013-03-25 01:59:323902 false);
3903 SetLayerPropertiesForTesting(animating_child.get(),
3904 backface_matrix,
[email protected]a2566412014-06-05 03:14:203905 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323906 gfx::PointF(),
3907 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573908 true,
[email protected]fb661802013-03-25 01:59:323909 false);
3910 SetLayerPropertiesForTesting(child2.get(),
3911 identity_matrix,
[email protected]a2566412014-06-05 03:14:203912 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:323913 gfx::PointF(),
3914 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:573915 true,
[email protected]fb661802013-03-25 01:59:323916 false);
3917
[email protected]989386c2013-07-18 21:37:233918 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:533919 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3920 parent.get(), parent->bounds(), &render_surface_layer_list);
3921 inputs.can_adjust_raster_scales = true;
3922 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:323923
3924 EXPECT_FALSE(child->render_surface());
3925 EXPECT_TRUE(animating_surface->render_surface());
3926 EXPECT_FALSE(child_of_animating_surface->render_surface());
3927 EXPECT_FALSE(animating_child->render_surface());
3928 EXPECT_FALSE(child2->render_surface());
3929
3930 // Verify that the animating_child and child_of_animating_surface were not
3931 // culled, but that child was.
3932 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:233933 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3934 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:323935
3936 // The non-animating child be culled from the layer list for the parent render
3937 // surface.
3938 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233939 3u,
3940 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3941 EXPECT_EQ(animating_surface->id(),
3942 render_surface_layer_list.at(0)
3943 ->render_surface()->layer_list().at(0)->id());
3944 EXPECT_EQ(animating_child->id(),
3945 render_surface_layer_list.at(0)
3946 ->render_surface()->layer_list().at(1)->id());
3947 EXPECT_EQ(child2->id(),
3948 render_surface_layer_list.at(0)
3949 ->render_surface()->layer_list().at(2)->id());
[email protected]fb661802013-03-25 01:59:323950
3951 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:233952 2u,
3953 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3954 EXPECT_EQ(animating_surface->id(),
3955 render_surface_layer_list.at(1)
3956 ->render_surface()->layer_list().at(0)->id());
3957 EXPECT_EQ(child_of_animating_surface->id(),
3958 render_surface_layer_list.at(1)
3959 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:323960
3961 EXPECT_FALSE(child2->visible_content_rect().IsEmpty());
3962
3963 // The animating layers should have a visible content rect that represents the
3964 // area of the front face that is within the viewport.
3965 EXPECT_EQ(animating_child->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:053966 gfx::Rect(animating_child->content_bounds()));
[email protected]fb661802013-03-25 01:59:323967 EXPECT_EQ(animating_surface->visible_content_rect(),
[email protected]2c7c6702013-03-26 03:14:053968 gfx::Rect(animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:323969 // And layers in the subtree of the animating layer should have valid visible
3970 // content rects also.
[email protected]989386c2013-07-18 21:37:233971 EXPECT_EQ(child_of_animating_surface->visible_content_rect(),
3972 gfx::Rect(child_of_animating_surface->content_bounds()));
[email protected]fb661802013-03-25 01:59:323973}
3974
[email protected]989386c2013-07-18 21:37:233975TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:323976 BackFaceCullingWithPreserves3dForFlatteningSurface) {
3977 // Verify the behavior of back-face culling for a render surface that is
3978 // created when it flattens its subtree, and its parent has preserves-3d.
3979
3980 const gfx::Transform identity_matrix;
3981 scoped_refptr<Layer> parent = Layer::Create();
3982 scoped_refptr<LayerWithForcedDrawsContent> front_facing_surface =
3983 make_scoped_refptr(new LayerWithForcedDrawsContent());
3984 scoped_refptr<LayerWithForcedDrawsContent> back_facing_surface =
3985 make_scoped_refptr(new LayerWithForcedDrawsContent());
3986 scoped_refptr<LayerWithForcedDrawsContent> child1 =
3987 make_scoped_refptr(new LayerWithForcedDrawsContent());
3988 scoped_refptr<LayerWithForcedDrawsContent> child2 =
3989 make_scoped_refptr(new LayerWithForcedDrawsContent());
3990
3991 parent->AddChild(front_facing_surface);
3992 parent->AddChild(back_facing_surface);
3993 front_facing_surface->AddChild(child1);
3994 back_facing_surface->AddChild(child2);
3995
enne2097cab2014-09-25 20:16:313996 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:283997 host->SetRootLayer(parent);
3998
[email protected]fb661802013-03-25 01:59:323999 // RenderSurfaces are not double-sided
4000 front_facing_surface->SetDoubleSided(false);
4001 back_facing_surface->SetDoubleSided(false);
4002
4003 gfx::Transform backface_matrix;
4004 backface_matrix.Translate(50.0, 50.0);
4005 backface_matrix.RotateAboutYAxis(180.0);
4006 backface_matrix.Translate(-50.0, -50.0);
4007
4008 SetLayerPropertiesForTesting(parent.get(),
4009 identity_matrix,
[email protected]a2566412014-06-05 03:14:204010 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324011 gfx::PointF(),
4012 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574013 false,
4014 true); // parent transform style is preserve3d.
[email protected]fb661802013-03-25 01:59:324015 SetLayerPropertiesForTesting(front_facing_surface.get(),
4016 identity_matrix,
[email protected]a2566412014-06-05 03:14:204017 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324018 gfx::PointF(),
4019 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574020 true,
4021 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324022 SetLayerPropertiesForTesting(back_facing_surface.get(),
4023 backface_matrix,
[email protected]a2566412014-06-05 03:14:204024 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324025 gfx::PointF(),
4026 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574027 true,
4028 true); // surface transform style is flat.
[email protected]fb661802013-03-25 01:59:324029 SetLayerPropertiesForTesting(child1.get(),
4030 identity_matrix,
[email protected]a2566412014-06-05 03:14:204031 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324032 gfx::PointF(),
4033 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574034 true,
[email protected]fb661802013-03-25 01:59:324035 false);
4036 SetLayerPropertiesForTesting(child2.get(),
4037 identity_matrix,
[email protected]a2566412014-06-05 03:14:204038 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324039 gfx::PointF(),
4040 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574041 true,
[email protected]fb661802013-03-25 01:59:324042 false);
4043
[email protected]a9d4d4f2014-06-19 06:49:284044 front_facing_surface->Set3dSortingContextId(1);
4045 back_facing_surface->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:574046
[email protected]989386c2013-07-18 21:37:234047 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534048 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4049 parent.get(), parent->bounds(), &render_surface_layer_list);
4050 inputs.can_adjust_raster_scales = true;
4051 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]fb661802013-03-25 01:59:324052
awoloszyne83f28c2014-12-22 15:40:004053 // Verify which render surfaces were created and used.
[email protected]fb661802013-03-25 01:59:324054 EXPECT_TRUE(front_facing_surface->render_surface());
awoloszyne83f28c2014-12-22 15:40:004055
4056 // We expect the render surface to have been created, but remain unused.
4057 EXPECT_TRUE(back_facing_surface->render_surface());
4058 EXPECT_NE(back_facing_surface->render_target(),
4059 back_facing_surface); // because it should be culled
[email protected]fb661802013-03-25 01:59:324060 EXPECT_FALSE(child1->render_surface());
4061 EXPECT_FALSE(child2->render_surface());
4062
4063 // Verify the render_surface_layer_list. The back-facing surface should be
4064 // culled.
4065 ASSERT_EQ(2u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:234066 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4067 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
[email protected]fb661802013-03-25 01:59:324068
4069 // Verify root surface's layer list.
4070 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234071 1u,
4072 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4073 EXPECT_EQ(front_facing_surface->id(),
4074 render_surface_layer_list.at(0)
4075 ->render_surface()->layer_list().at(0)->id());
[email protected]fb661802013-03-25 01:59:324076
4077 // Verify front_facing_surface's layer list.
4078 ASSERT_EQ(
[email protected]989386c2013-07-18 21:37:234079 2u,
4080 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4081 EXPECT_EQ(front_facing_surface->id(),
4082 render_surface_layer_list.at(1)
4083 ->render_surface()->layer_list().at(0)->id());
4084 EXPECT_EQ(child1->id(),
4085 render_surface_layer_list.at(1)
4086 ->render_surface()->layer_list().at(1)->id());
[email protected]fb661802013-03-25 01:59:324087}
4088
[email protected]fb661802013-03-25 01:59:324089class NoScaleContentLayer : public ContentLayer {
4090 public:
4091 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) {
4092 return make_scoped_refptr(new NoScaleContentLayer(client));
4093 }
[email protected]94f206c12012-08-25 00:09:144094
dcheng716bedf2014-10-21 09:51:084095 void CalculateContentsScale(float ideal_contents_scale,
4096 float* contents_scale_x,
4097 float* contents_scale_y,
4098 gfx::Size* content_bounds) override {
[email protected]fb661802013-03-25 01:59:324099 // Skip over the ContentLayer to the base Layer class.
4100 Layer::CalculateContentsScale(ideal_contents_scale,
[email protected]fb661802013-03-25 01:59:324101 contents_scale_x,
4102 contents_scale_y,
4103 content_bounds);
4104 }
[email protected]94f206c12012-08-25 00:09:144105
[email protected]fb661802013-03-25 01:59:324106 protected:
4107 explicit NoScaleContentLayer(ContentLayerClient* client)
4108 : ContentLayer(client) {}
dcheng716bedf2014-10-21 09:51:084109 ~NoScaleContentLayer() override {}
[email protected]518ee582012-10-24 18:29:444110};
4111
[email protected]fb661802013-03-25 01:59:324112scoped_refptr<NoScaleContentLayer> CreateNoScaleDrawableContentLayer(
4113 ContentLayerClient* delegate) {
4114 scoped_refptr<NoScaleContentLayer> to_return =
4115 NoScaleContentLayer::Create(delegate);
4116 to_return->SetIsDrawable(true);
4117 return to_return;
[email protected]518ee582012-10-24 18:29:444118}
4119
[email protected]989386c2013-07-18 21:37:234120TEST_F(LayerTreeHostCommonTest, LayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324121 // Verify draw and screen space transforms of layers not in a surface.
4122 MockContentLayerClient delegate;
4123 gfx::Transform identity_matrix;
[email protected]94f206c12012-08-25 00:09:144124
sohan.jyotie3bd6192014-10-13 07:13:594125 scoped_refptr<FakePictureLayer> parent =
4126 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324127 SetLayerPropertiesForTesting(parent.get(),
4128 identity_matrix,
[email protected]a2566412014-06-05 03:14:204129 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324130 gfx::PointF(),
4131 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574132 false,
[email protected]fb661802013-03-25 01:59:324133 true);
[email protected]94f206c12012-08-25 00:09:144134
sohan.jyotie3bd6192014-10-13 07:13:594135 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324136 SetLayerPropertiesForTesting(child.get(),
4137 identity_matrix,
[email protected]a2566412014-06-05 03:14:204138 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324139 gfx::PointF(2.f, 2.f),
4140 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574141 false,
[email protected]fb661802013-03-25 01:59:324142 true);
[email protected]94f206c12012-08-25 00:09:144143
sohan.jyotie3bd6192014-10-13 07:13:594144 scoped_refptr<FakePictureLayer> child_empty =
4145 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324146 SetLayerPropertiesForTesting(child_empty.get(),
4147 identity_matrix,
[email protected]a2566412014-06-05 03:14:204148 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324149 gfx::PointF(2.f, 2.f),
4150 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574151 false,
[email protected]fb661802013-03-25 01:59:324152 true);
[email protected]f89f5632012-11-14 23:34:454153
[email protected]fb661802013-03-25 01:59:324154 parent->AddChild(child);
4155 parent->AddChild(child_empty);
[email protected]94f206c12012-08-25 00:09:144156
enne2097cab2014-09-25 20:16:314157 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284158 host->SetRootLayer(parent);
4159
[email protected]fb661802013-03-25 01:59:324160 float device_scale_factor = 2.5f;
4161 float page_scale_factor = 1.f;
[email protected]94f206c12012-08-25 00:09:144162
[email protected]7aad55f2013-07-26 11:25:534163 RenderSurfaceLayerList render_surface_layer_list;
4164 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4165 parent.get(), parent->bounds(), &render_surface_layer_list);
4166 inputs.device_scale_factor = device_scale_factor;
4167 inputs.page_scale_factor = page_scale_factor;
4168 inputs.can_adjust_raster_scales = true;
4169 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:444170
sohan.jyotie3bd6192014-10-13 07:13:594171 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4172 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child);
4173 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, child_empty);
[email protected]94f206c12012-08-25 00:09:144174
[email protected]fb661802013-03-25 01:59:324175 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:144176
[email protected]fb661802013-03-25 01:59:324177 // Verify parent transforms
4178 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:594179 expected_parent_transform.Scale(device_scale_factor * page_scale_factor,
4180 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324181 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4182 parent->screen_space_transform());
4183 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4184 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:144185
[email protected]fb661802013-03-25 01:59:324186 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:054187 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]94f206c12012-08-25 00:09:144188
[email protected]fb661802013-03-25 01:59:324189 gfx::RectF parent_draw_rect =
4190 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
4191 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
4192 parent->screen_space_transform(), parent_content_bounds);
[email protected]94f206c12012-08-25 00:09:144193
[email protected]2c7c6702013-03-26 03:14:054194 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:324195 expected_parent_draw_rect.Scale(device_scale_factor);
4196 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4197 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144198
[email protected]fb661802013-03-25 01:59:324199 // Verify child and child_empty transforms. They should match.
4200 gfx::Transform expected_child_transform;
sohan.jyotie3bd6192014-10-13 07:13:594201 expected_child_transform.Scale(device_scale_factor, device_scale_factor);
4202 expected_child_transform.Translate(child->position().x(),
4203 child->position().y());
[email protected]fb661802013-03-25 01:59:324204 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4205 child->draw_transform());
4206 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4207 child->screen_space_transform());
4208 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4209 child_empty->draw_transform());
4210 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4211 child_empty->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:144212
[email protected]fb661802013-03-25 01:59:324213 // Verify results of transformed child and child_empty rects. They should
4214 // match.
[email protected]2c7c6702013-03-26 03:14:054215 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]94f206c12012-08-25 00:09:144216
[email protected]fb661802013-03-25 01:59:324217 gfx::RectF child_draw_rect =
4218 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
4219 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
4220 child->screen_space_transform(), child_content_bounds);
[email protected]94f206c12012-08-25 00:09:144221
[email protected]fb661802013-03-25 01:59:324222 gfx::RectF child_empty_draw_rect = MathUtil::MapClippedRect(
4223 child_empty->draw_transform(), child_content_bounds);
4224 gfx::RectF child_empty_screen_space_rect = MathUtil::MapClippedRect(
4225 child_empty->screen_space_transform(), child_content_bounds);
[email protected]f89f5632012-11-14 23:34:454226
[email protected]fb661802013-03-25 01:59:324227 gfx::RectF expected_child_draw_rect(child->position(), child->bounds());
4228 expected_child_draw_rect.Scale(device_scale_factor);
4229 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4230 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
4231 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_draw_rect);
4232 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_empty_screen_space_rect);
[email protected]94f206c12012-08-25 00:09:144233}
4234
[email protected]989386c2013-07-18 21:37:234235TEST_F(LayerTreeHostCommonTest, SurfaceLayerTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:324236 // Verify draw and screen space transforms of layers in a surface.
4237 MockContentLayerClient delegate;
4238 gfx::Transform identity_matrix;
[email protected]1b30e8e2012-12-21 02:59:094239
[email protected]fb661802013-03-25 01:59:324240 gfx::Transform perspective_matrix;
4241 perspective_matrix.ApplyPerspectiveDepth(2.0);
[email protected]1b30e8e2012-12-21 02:59:094242
[email protected]fb661802013-03-25 01:59:324243 gfx::Transform scale_small_matrix;
[email protected]6138db702013-09-25 03:25:054244 scale_small_matrix.Scale(SK_MScalar1 / 10.f, SK_MScalar1 / 12.f);
[email protected]1b30e8e2012-12-21 02:59:094245
[email protected]9781afa2013-07-17 23:15:324246 scoped_refptr<Layer> root = Layer::Create();
4247
sohan.jyotie3bd6192014-10-13 07:13:594248 scoped_refptr<FakePictureLayer> parent =
4249 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324250 SetLayerPropertiesForTesting(parent.get(),
4251 identity_matrix,
[email protected]a2566412014-06-05 03:14:204252 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324253 gfx::PointF(),
4254 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574255 false,
[email protected]fb661802013-03-25 01:59:324256 true);
[email protected]1b30e8e2012-12-21 02:59:094257
sohan.jyotie3bd6192014-10-13 07:13:594258 scoped_refptr<FakePictureLayer> perspective_surface =
4259 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324260 SetLayerPropertiesForTesting(perspective_surface.get(),
4261 perspective_matrix * scale_small_matrix,
[email protected]a2566412014-06-05 03:14:204262 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324263 gfx::PointF(2.f, 2.f),
4264 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574265 false,
[email protected]fb661802013-03-25 01:59:324266 true);
[email protected]1b30e8e2012-12-21 02:59:094267
sohan.jyotie3bd6192014-10-13 07:13:594268 scoped_refptr<FakePictureLayer> scale_surface =
4269 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:324270 SetLayerPropertiesForTesting(scale_surface.get(),
4271 scale_small_matrix,
[email protected]a2566412014-06-05 03:14:204272 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324273 gfx::PointF(2.f, 2.f),
4274 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574275 false,
[email protected]fb661802013-03-25 01:59:324276 true);
[email protected]1b30e8e2012-12-21 02:59:094277
[email protected]fb661802013-03-25 01:59:324278 perspective_surface->SetForceRenderSurface(true);
4279 scale_surface->SetForceRenderSurface(true);
[email protected]1b30e8e2012-12-21 02:59:094280
[email protected]fb661802013-03-25 01:59:324281 parent->AddChild(perspective_surface);
4282 parent->AddChild(scale_surface);
[email protected]9781afa2013-07-17 23:15:324283 root->AddChild(parent);
[email protected]1b30e8e2012-12-21 02:59:094284
enne2097cab2014-09-25 20:16:314285 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284286 host->SetRootLayer(root);
4287
[email protected]fb661802013-03-25 01:59:324288 float device_scale_factor = 2.5f;
4289 float page_scale_factor = 3.f;
[email protected]1b30e8e2012-12-21 02:59:094290
[email protected]7aad55f2013-07-26 11:25:534291 RenderSurfaceLayerList render_surface_layer_list;
4292 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4293 root.get(), parent->bounds(), &render_surface_layer_list);
4294 inputs.device_scale_factor = device_scale_factor;
4295 inputs.page_scale_factor = page_scale_factor;
Daniel Chengeea98042014-08-26 00:28:104296 inputs.page_scale_application_layer = root.get();
[email protected]7aad55f2013-07-26 11:25:534297 inputs.can_adjust_raster_scales = true;
4298 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]1b30e8e2012-12-21 02:59:094299
sohan.jyotie3bd6192014-10-13 07:13:594300 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4301 EXPECT_IDEAL_SCALE_EQ(device_scale_factor * page_scale_factor,
4302 perspective_surface);
4303 // Ideal scale is the max 2d scale component of the combined transform up to
4304 // the nearest render target. Here this includes the layer transform as well
4305 // as the device and page scale factors.
4306 gfx::Transform transform = scale_small_matrix;
4307 transform.Scale(device_scale_factor * page_scale_factor,
4308 device_scale_factor * page_scale_factor);
4309 gfx::Vector2dF scales =
4310 MathUtil::ComputeTransform2dScaleComponents(transform, 0.f);
4311 float max_2d_scale = std::max(scales.x(), scales.y());
4312 EXPECT_IDEAL_SCALE_EQ(max_2d_scale, scale_surface);
4313
4314 // The ideal scale will draw 1:1 with its render target space along
4315 // the larger-scale axis.
4316 gfx::Vector2dF target_space_transform_scales =
4317 MathUtil::ComputeTransform2dScaleComponents(
4318 scale_surface->draw_properties().target_space_transform, 0.f);
4319 EXPECT_FLOAT_EQ(max_2d_scale,
4320 std::max(target_space_transform_scales.x(),
4321 target_space_transform_scales.y()));
[email protected]1b30e8e2012-12-21 02:59:094322
[email protected]fb661802013-03-25 01:59:324323 EXPECT_EQ(3u, render_surface_layer_list.size());
[email protected]1b30e8e2012-12-21 02:59:094324
[email protected]fb661802013-03-25 01:59:324325 gfx::Transform expected_parent_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594326 expected_parent_draw_transform.Scale(device_scale_factor * page_scale_factor,
4327 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324328 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform,
4329 parent->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094330
[email protected]fb661802013-03-25 01:59:324331 // The scale for the perspective surface is not known, so it is rendered 1:1
4332 // with the screen, and then scaled during drawing.
4333 gfx::Transform expected_perspective_surface_draw_transform;
4334 expected_perspective_surface_draw_transform.Translate(
4335 device_scale_factor * page_scale_factor *
4336 perspective_surface->position().x(),
4337 device_scale_factor * page_scale_factor *
4338 perspective_surface->position().y());
4339 expected_perspective_surface_draw_transform.PreconcatTransform(
4340 perspective_matrix);
4341 expected_perspective_surface_draw_transform.PreconcatTransform(
4342 scale_small_matrix);
4343 gfx::Transform expected_perspective_surface_layer_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:594344 expected_perspective_surface_layer_draw_transform.Scale(
4345 device_scale_factor * page_scale_factor,
4346 device_scale_factor * page_scale_factor);
[email protected]fb661802013-03-25 01:59:324347 EXPECT_TRANSFORMATION_MATRIX_EQ(
4348 expected_perspective_surface_draw_transform,
4349 perspective_surface->render_surface()->draw_transform());
4350 EXPECT_TRANSFORMATION_MATRIX_EQ(
4351 expected_perspective_surface_layer_draw_transform,
4352 perspective_surface->draw_transform());
[email protected]1b30e8e2012-12-21 02:59:094353}
4354
sohan.jyotie3bd6192014-10-13 07:13:594355// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234356TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:324357 LayerTransformsInHighDPIAccurateScaleZeroChildPosition) {
4358 // Verify draw and screen space transforms of layers not in a surface.
4359 MockContentLayerClient delegate;
4360 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:474361
[email protected]fb661802013-03-25 01:59:324362 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4363 SetLayerPropertiesForTesting(parent.get(),
4364 identity_matrix,
[email protected]a2566412014-06-05 03:14:204365 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324366 gfx::PointF(),
4367 gfx::Size(133, 133),
[email protected]56fffdd2014-02-11 19:50:574368 false,
[email protected]fb661802013-03-25 01:59:324369 true);
[email protected]904e9132012-11-01 00:12:474370
[email protected]fb661802013-03-25 01:59:324371 scoped_refptr<ContentLayer> child = CreateDrawableContentLayer(&delegate);
4372 SetLayerPropertiesForTesting(child.get(),
4373 identity_matrix,
[email protected]a2566412014-06-05 03:14:204374 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324375 gfx::PointF(),
4376 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:574377 false,
[email protected]fb661802013-03-25 01:59:324378 true);
[email protected]904e9132012-11-01 00:12:474379
[email protected]fb661802013-03-25 01:59:324380 scoped_refptr<NoScaleContentLayer> child_no_scale =
4381 CreateNoScaleDrawableContentLayer(&delegate);
4382 SetLayerPropertiesForTesting(child_no_scale.get(),
4383 identity_matrix,
[email protected]a2566412014-06-05 03:14:204384 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324385 gfx::PointF(),
4386 gfx::Size(13, 13),
[email protected]56fffdd2014-02-11 19:50:574387 false,
[email protected]fb661802013-03-25 01:59:324388 true);
[email protected]904e9132012-11-01 00:12:474389
[email protected]fb661802013-03-25 01:59:324390 parent->AddChild(child);
4391 parent->AddChild(child_no_scale);
[email protected]904e9132012-11-01 00:12:474392
enne2097cab2014-09-25 20:16:314393 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284394 host->SetRootLayer(parent);
4395
[email protected]fb661802013-03-25 01:59:324396 float device_scale_factor = 1.7f;
4397 float page_scale_factor = 1.f;
[email protected]904e9132012-11-01 00:12:474398
[email protected]7aad55f2013-07-26 11:25:534399 RenderSurfaceLayerList render_surface_layer_list;
4400 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4401 parent.get(), parent->bounds(), &render_surface_layer_list);
4402 inputs.device_scale_factor = device_scale_factor;
4403 inputs.page_scale_factor = page_scale_factor;
4404 inputs.page_scale_application_layer = parent.get();
4405 inputs.can_adjust_raster_scales = true;
4406 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:474407
[email protected]fb661802013-03-25 01:59:324408 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4409 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, child);
4410 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]904e9132012-11-01 00:12:474411
[email protected]fb661802013-03-25 01:59:324412 EXPECT_EQ(1u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:474413
[email protected]fb661802013-03-25 01:59:324414 // Verify parent transforms
4415 gfx::Transform expected_parent_transform;
4416 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4417 parent->screen_space_transform());
4418 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
4419 parent->draw_transform());
[email protected]904e9132012-11-01 00:12:474420
[email protected]fb661802013-03-25 01:59:324421 // Verify results of transformed parent rects
[email protected]2c7c6702013-03-26 03:14:054422 gfx::RectF parent_content_bounds(parent->content_bounds());
[email protected]904e9132012-11-01 00:12:474423
[email protected]fb661802013-03-25 01:59:324424 gfx::RectF parent_draw_rect =
4425 MathUtil::MapClippedRect(parent->draw_transform(), parent_content_bounds);
4426 gfx::RectF parent_screen_space_rect = MathUtil::MapClippedRect(
4427 parent->screen_space_transform(), parent_content_bounds);
[email protected]904e9132012-11-01 00:12:474428
[email protected]2c7c6702013-03-26 03:14:054429 gfx::RectF expected_parent_draw_rect(parent->bounds());
[email protected]fb661802013-03-25 01:59:324430 expected_parent_draw_rect.Scale(device_scale_factor);
4431 expected_parent_draw_rect.set_width(ceil(expected_parent_draw_rect.width()));
4432 expected_parent_draw_rect.set_height(
4433 ceil(expected_parent_draw_rect.height()));
4434 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_draw_rect);
4435 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect, parent_screen_space_rect);
[email protected]904e9132012-11-01 00:12:474436
[email protected]fb661802013-03-25 01:59:324437 // Verify child transforms
4438 gfx::Transform expected_child_transform;
4439 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4440 child->draw_transform());
4441 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform,
4442 child->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474443
[email protected]fb661802013-03-25 01:59:324444 // Verify results of transformed child rects
[email protected]2c7c6702013-03-26 03:14:054445 gfx::RectF child_content_bounds(child->content_bounds());
[email protected]904e9132012-11-01 00:12:474446
[email protected]fb661802013-03-25 01:59:324447 gfx::RectF child_draw_rect =
4448 MathUtil::MapClippedRect(child->draw_transform(), child_content_bounds);
4449 gfx::RectF child_screen_space_rect = MathUtil::MapClippedRect(
4450 child->screen_space_transform(), child_content_bounds);
[email protected]904e9132012-11-01 00:12:474451
[email protected]2c7c6702013-03-26 03:14:054452 gfx::RectF expected_child_draw_rect(child->bounds());
[email protected]fb661802013-03-25 01:59:324453 expected_child_draw_rect.Scale(device_scale_factor);
4454 expected_child_draw_rect.set_width(ceil(expected_child_draw_rect.width()));
4455 expected_child_draw_rect.set_height(ceil(expected_child_draw_rect.height()));
4456 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_draw_rect);
4457 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect, child_screen_space_rect);
[email protected]904e9132012-11-01 00:12:474458
[email protected]fb661802013-03-25 01:59:324459 // Verify child_no_scale transforms
4460 gfx::Transform expected_child_no_scale_transform = child->draw_transform();
4461 // All transforms operate on content rects. The child's content rect
4462 // incorporates device scale, but the child_no_scale does not; add it here.
4463 expected_child_no_scale_transform.Scale(device_scale_factor,
4464 device_scale_factor);
4465 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4466 child_no_scale->draw_transform());
4467 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform,
4468 child_no_scale->screen_space_transform());
[email protected]904e9132012-11-01 00:12:474469}
4470
sohan.jyotie3bd6192014-10-13 07:13:594471// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234472TEST_F(LayerTreeHostCommonTest, ContentsScale) {
[email protected]fb661802013-03-25 01:59:324473 MockContentLayerClient delegate;
4474 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:444475
[email protected]fb661802013-03-25 01:59:324476 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264477 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324478 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:444479
[email protected]fb661802013-03-25 01:59:324480 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264481 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324482 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:444483
[email protected]35a99a12013-05-09 23:52:294484 scoped_refptr<Layer> root = Layer::Create();
4485 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:444486
[email protected]fb661802013-03-25 01:59:324487 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4488 SetLayerPropertiesForTesting(parent.get(),
4489 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204490 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324491 gfx::PointF(),
4492 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574493 false,
[email protected]fb661802013-03-25 01:59:324494 true);
[email protected]518ee582012-10-24 18:29:444495
[email protected]fb661802013-03-25 01:59:324496 scoped_refptr<ContentLayer> child_scale =
4497 CreateDrawableContentLayer(&delegate);
4498 SetLayerPropertiesForTesting(child_scale.get(),
4499 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204500 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324501 gfx::PointF(2.f, 2.f),
4502 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574503 false,
[email protected]fb661802013-03-25 01:59:324504 true);
[email protected]518ee582012-10-24 18:29:444505
[email protected]fb661802013-03-25 01:59:324506 scoped_refptr<ContentLayer> child_empty =
4507 CreateDrawableContentLayer(&delegate);
4508 SetLayerPropertiesForTesting(child_empty.get(),
4509 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204510 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324511 gfx::PointF(2.f, 2.f),
4512 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574513 false,
[email protected]fb661802013-03-25 01:59:324514 true);
[email protected]f89f5632012-11-14 23:34:454515
[email protected]fb661802013-03-25 01:59:324516 scoped_refptr<NoScaleContentLayer> child_no_scale =
4517 CreateNoScaleDrawableContentLayer(&delegate);
4518 SetLayerPropertiesForTesting(child_no_scale.get(),
4519 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204520 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324521 gfx::PointF(12.f, 12.f),
4522 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574523 false,
[email protected]fb661802013-03-25 01:59:324524 true);
[email protected]518ee582012-10-24 18:29:444525
[email protected]35a99a12013-05-09 23:52:294526 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:444527
[email protected]fb661802013-03-25 01:59:324528 parent->AddChild(child_scale);
4529 parent->AddChild(child_empty);
4530 parent->AddChild(child_no_scale);
[email protected]518ee582012-10-24 18:29:444531
enne2097cab2014-09-25 20:16:314532 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284533 host->SetRootLayer(root);
4534
[email protected]fb661802013-03-25 01:59:324535 float device_scale_factor = 2.5f;
4536 float page_scale_factor = 1.f;
[email protected]518ee582012-10-24 18:29:444537
[email protected]989386c2013-07-18 21:37:234538 {
4539 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534540 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224541 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534542 inputs.device_scale_factor = device_scale_factor;
4543 inputs.page_scale_factor = page_scale_factor;
4544 inputs.page_scale_application_layer = root.get();
4545 inputs.can_adjust_raster_scales = true;
4546 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]518ee582012-10-24 18:29:444547
[email protected]989386c2013-07-18 21:37:234548 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4549 initial_parent_scale, parent);
4550 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4551 initial_parent_scale * initial_child_scale,
4552 child_scale);
4553 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4554 initial_parent_scale * initial_child_scale,
4555 child_empty);
4556 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
[email protected]518ee582012-10-24 18:29:444557
[email protected]989386c2013-07-18 21:37:234558 // The parent is scaled up and shouldn't need to scale during draw. The
4559 // child that can scale its contents should also not need to scale during
4560 // draw. This shouldn't change if the child has empty bounds. The other
4561 // children should.
[email protected]803f6b52013-09-12 00:51:264562 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
4563 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
4564 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(0, 0));
4565 EXPECT_FLOAT_EQ(1.0, child_scale->draw_transform().matrix().get(1, 1));
4566 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(0, 0));
4567 EXPECT_FLOAT_EQ(1.0, child_empty->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:234568 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
4569 initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264570 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]989386c2013-07-18 21:37:234571 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264572 initial_parent_scale * initial_child_scale,
4573 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]989386c2013-07-18 21:37:234574 }
[email protected]518ee582012-10-24 18:29:444575
[email protected]fb661802013-03-25 01:59:324576 // If the device_scale_factor or page_scale_factor changes, then it should be
4577 // updated using the initial transform as the raster scale.
4578 device_scale_factor = 2.25f;
4579 page_scale_factor = 1.25f;
[email protected]518ee582012-10-24 18:29:444580
[email protected]989386c2013-07-18 21:37:234581 {
4582 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534583 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224584 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534585 inputs.device_scale_factor = device_scale_factor;
4586 inputs.page_scale_factor = page_scale_factor;
4587 inputs.page_scale_application_layer = root.get();
4588 inputs.can_adjust_raster_scales = true;
4589 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4590
4591 EXPECT_CONTENTS_SCALE_EQ(
4592 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]989386c2013-07-18 21:37:234593 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:534594 initial_parent_scale * initial_child_scale,
[email protected]989386c2013-07-18 21:37:234595 child_scale);
4596 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4597 initial_parent_scale * initial_child_scale,
4598 child_empty);
4599 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4600 }
[email protected]d0518202013-02-08 02:06:494601
[email protected]fb661802013-03-25 01:59:324602 // If the transform changes, we expect the raster scale to be reset to 1.0.
[email protected]803f6b52013-09-12 00:51:264603 SkMScalar second_child_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324604 child_scale_matrix.Scale(second_child_scale / initial_child_scale,
4605 second_child_scale / initial_child_scale);
4606 child_scale->SetTransform(child_scale_matrix);
4607 child_empty->SetTransform(child_scale_matrix);
[email protected]d0518202013-02-08 02:06:494608
[email protected]989386c2013-07-18 21:37:234609 {
4610 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534611 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224612 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534613 inputs.device_scale_factor = device_scale_factor;
4614 inputs.page_scale_factor = page_scale_factor;
4615 inputs.page_scale_application_layer = root.get();
4616 inputs.can_adjust_raster_scales = true;
4617 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:494618
[email protected]989386c2013-07-18 21:37:234619 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4620 initial_parent_scale,
4621 parent);
4622 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4623 child_scale);
4624 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4625 child_empty);
4626 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4627 }
[email protected]d0518202013-02-08 02:06:494628
[email protected]fb661802013-03-25 01:59:324629 // If the device_scale_factor or page_scale_factor changes, then it should be
4630 // updated, but still using 1.0 as the raster scale.
4631 device_scale_factor = 2.75f;
4632 page_scale_factor = 1.75f;
[email protected]d0518202013-02-08 02:06:494633
[email protected]989386c2013-07-18 21:37:234634 {
4635 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534636 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224637 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534638 inputs.device_scale_factor = device_scale_factor;
4639 inputs.page_scale_factor = page_scale_factor;
4640 inputs.page_scale_application_layer = root.get();
4641 inputs.can_adjust_raster_scales = true;
4642 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]d0518202013-02-08 02:06:494643
[email protected]989386c2013-07-18 21:37:234644 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
4645 initial_parent_scale,
4646 parent);
4647 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4648 child_scale);
4649 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4650 child_empty);
4651 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4652 }
[email protected]518ee582012-10-24 18:29:444653}
4654
sohan.jyotie3bd6192014-10-13 07:13:594655// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:234656TEST_F(LayerTreeHostCommonTest,
sohan.jyotie3bd6192014-10-13 07:13:594657 ContentsScale_LayerTransformsDontAffectContentsScale) {
[email protected]fb661802013-03-25 01:59:324658 MockContentLayerClient delegate;
4659 gfx::Transform identity_matrix;
[email protected]11ec92972012-11-10 03:06:214660
[email protected]fb661802013-03-25 01:59:324661 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264662 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:324663 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]11ec92972012-11-10 03:06:214664
[email protected]fb661802013-03-25 01:59:324665 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264666 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:324667 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]11ec92972012-11-10 03:06:214668
[email protected]35a99a12013-05-09 23:52:294669 scoped_refptr<Layer> root = Layer::Create();
4670 root->SetBounds(gfx::Size(100, 100));
4671
[email protected]fb661802013-03-25 01:59:324672 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4673 SetLayerPropertiesForTesting(parent.get(),
4674 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204675 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324676 gfx::PointF(),
4677 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574678 false,
[email protected]fb661802013-03-25 01:59:324679 true);
[email protected]11ec92972012-11-10 03:06:214680
[email protected]fb661802013-03-25 01:59:324681 scoped_refptr<ContentLayer> child_scale =
4682 CreateDrawableContentLayer(&delegate);
4683 SetLayerPropertiesForTesting(child_scale.get(),
4684 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204685 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324686 gfx::PointF(2.f, 2.f),
4687 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574688 false,
[email protected]fb661802013-03-25 01:59:324689 true);
[email protected]11ec92972012-11-10 03:06:214690
[email protected]35a99a12013-05-09 23:52:294691 scoped_refptr<ContentLayer> child_empty =
4692 CreateDrawableContentLayer(&delegate);
4693 SetLayerPropertiesForTesting(child_empty.get(),
4694 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204695 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294696 gfx::PointF(2.f, 2.f),
4697 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:574698 false,
[email protected]35a99a12013-05-09 23:52:294699 true);
4700
4701 scoped_refptr<NoScaleContentLayer> child_no_scale =
4702 CreateNoScaleDrawableContentLayer(&delegate);
4703 SetLayerPropertiesForTesting(child_no_scale.get(),
4704 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204705 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294706 gfx::PointF(12.f, 12.f),
4707 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574708 false,
[email protected]35a99a12013-05-09 23:52:294709 true);
4710
4711 root->AddChild(parent);
4712
4713 parent->AddChild(child_scale);
4714 parent->AddChild(child_empty);
4715 parent->AddChild(child_no_scale);
4716
enne2097cab2014-09-25 20:16:314717 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284718 host->SetRootLayer(root);
4719
[email protected]989386c2013-07-18 21:37:234720 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:294721
4722 float device_scale_factor = 2.5f;
4723 float page_scale_factor = 1.f;
4724
[email protected]7aad55f2013-07-26 11:25:534725 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224726 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534727 inputs.device_scale_factor = device_scale_factor;
4728 inputs.page_scale_factor = page_scale_factor;
4729 inputs.page_scale_application_layer = root.get(),
4730 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:294731
4732 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor, parent);
4733 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4734 child_scale);
4735 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
4736 child_empty);
4737 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale);
4738
4739 // Since the transform scale does not affect contents scale, it should affect
4740 // the draw transform instead.
4741 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:264742 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294743 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:264744 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294745 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264746 child_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294747 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264748 child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294749 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264750 child_empty->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294751 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:264752 child_empty->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294753 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264754 initial_parent_scale * initial_child_scale,
4755 child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:294756 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:264757 initial_parent_scale * initial_child_scale,
4758 child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:294759}
4760
sohan.jyotie3bd6192014-10-13 07:13:594761TEST_F(LayerTreeHostCommonTest, SmallIdealScale) {
[email protected]35a99a12013-05-09 23:52:294762 MockContentLayerClient delegate;
4763 gfx::Transform identity_matrix;
4764
4765 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264766 SkMScalar initial_parent_scale = 1.75;
[email protected]35a99a12013-05-09 23:52:294767 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
4768
4769 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264770 SkMScalar initial_child_scale = 0.25;
[email protected]35a99a12013-05-09 23:52:294771 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
4772
4773 scoped_refptr<Layer> root = Layer::Create();
4774 root->SetBounds(gfx::Size(100, 100));
4775
sohan.jyotie3bd6192014-10-13 07:13:594776 scoped_refptr<FakePictureLayer> parent =
4777 CreateDrawablePictureLayer(&delegate);
[email protected]35a99a12013-05-09 23:52:294778 SetLayerPropertiesForTesting(parent.get(),
4779 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204780 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294781 gfx::PointF(),
4782 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574783 false,
[email protected]35a99a12013-05-09 23:52:294784 true);
4785
sohan.jyotie3bd6192014-10-13 07:13:594786 scoped_refptr<FakePictureLayer> child_scale =
4787 CreateDrawablePictureLayer(&delegate);
[email protected]35a99a12013-05-09 23:52:294788 SetLayerPropertiesForTesting(child_scale.get(),
4789 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204790 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:294791 gfx::PointF(2.f, 2.f),
4792 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574793 false,
[email protected]35a99a12013-05-09 23:52:294794 true);
4795
4796 root->AddChild(parent);
4797
[email protected]fb661802013-03-25 01:59:324798 parent->AddChild(child_scale);
[email protected]11ec92972012-11-10 03:06:214799
enne2097cab2014-09-25 20:16:314800 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284801 host->SetRootLayer(root);
4802
[email protected]fb661802013-03-25 01:59:324803 float device_scale_factor = 2.5f;
4804 float page_scale_factor = 0.01f;
[email protected]11ec92972012-11-10 03:06:214805
[email protected]989386c2013-07-18 21:37:234806 {
4807 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:534808 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224809 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534810 inputs.device_scale_factor = device_scale_factor;
4811 inputs.page_scale_factor = page_scale_factor;
4812 inputs.page_scale_application_layer = root.get();
4813 inputs.can_adjust_raster_scales = true;
4814 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11ec92972012-11-10 03:06:214815
sohan.jyotie3bd6192014-10-13 07:13:594816 // The ideal scale is able to go below 1.
4817 float expected_ideal_scale =
4818 device_scale_factor * page_scale_factor * initial_parent_scale;
4819 EXPECT_LT(expected_ideal_scale, 1.f);
4820 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, parent);
[email protected]11ec92972012-11-10 03:06:214821
sohan.jyotie3bd6192014-10-13 07:13:594822 expected_ideal_scale = device_scale_factor * page_scale_factor *
4823 initial_parent_scale * initial_child_scale;
4824 EXPECT_LT(expected_ideal_scale, 1.f);
4825 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale, child_scale);
[email protected]989386c2013-07-18 21:37:234826 }
[email protected]11ec92972012-11-10 03:06:214827}
4828
[email protected]989386c2013-07-18 21:37:234829TEST_F(LayerTreeHostCommonTest, ContentsScaleForSurfaces) {
[email protected]fb661802013-03-25 01:59:324830 MockContentLayerClient delegate;
4831 gfx::Transform identity_matrix;
[email protected]518ee582012-10-24 18:29:444832
[email protected]fb661802013-03-25 01:59:324833 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264834 SkMScalar initial_parent_scale = 2.0;
[email protected]fb661802013-03-25 01:59:324835 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]518ee582012-10-24 18:29:444836
[email protected]fb661802013-03-25 01:59:324837 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:264838 SkMScalar initial_child_scale = 3.0;
[email protected]fb661802013-03-25 01:59:324839 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]518ee582012-10-24 18:29:444840
[email protected]35a99a12013-05-09 23:52:294841 scoped_refptr<Layer> root = Layer::Create();
4842 root->SetBounds(gfx::Size(100, 100));
[email protected]518ee582012-10-24 18:29:444843
[email protected]fb661802013-03-25 01:59:324844 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
4845 SetLayerPropertiesForTesting(parent.get(),
4846 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:204847 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324848 gfx::PointF(),
4849 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:574850 false,
[email protected]fb661802013-03-25 01:59:324851 true);
[email protected]518ee582012-10-24 18:29:444852
[email protected]fb661802013-03-25 01:59:324853 scoped_refptr<ContentLayer> surface_scale =
4854 CreateDrawableContentLayer(&delegate);
4855 SetLayerPropertiesForTesting(surface_scale.get(),
4856 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204857 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324858 gfx::PointF(2.f, 2.f),
4859 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574860 false,
[email protected]fb661802013-03-25 01:59:324861 true);
[email protected]518ee582012-10-24 18:29:444862
[email protected]fb661802013-03-25 01:59:324863 scoped_refptr<ContentLayer> surface_scale_child_scale =
4864 CreateDrawableContentLayer(&delegate);
4865 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
4866 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204867 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324868 gfx::PointF(),
4869 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574870 false,
[email protected]fb661802013-03-25 01:59:324871 true);
[email protected]518ee582012-10-24 18:29:444872
[email protected]fb661802013-03-25 01:59:324873 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
4874 CreateNoScaleDrawableContentLayer(&delegate);
4875 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
4876 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204877 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324878 gfx::PointF(),
4879 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574880 false,
[email protected]fb661802013-03-25 01:59:324881 true);
[email protected]518ee582012-10-24 18:29:444882
[email protected]fb661802013-03-25 01:59:324883 scoped_refptr<NoScaleContentLayer> surface_no_scale =
4884 CreateNoScaleDrawableContentLayer(&delegate);
4885 SetLayerPropertiesForTesting(surface_no_scale.get(),
4886 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204887 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324888 gfx::PointF(12.f, 12.f),
4889 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574890 false,
[email protected]fb661802013-03-25 01:59:324891 true);
[email protected]518ee582012-10-24 18:29:444892
[email protected]fb661802013-03-25 01:59:324893 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
4894 CreateDrawableContentLayer(&delegate);
4895 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
4896 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204897 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324898 gfx::PointF(),
4899 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574900 false,
[email protected]fb661802013-03-25 01:59:324901 true);
[email protected]518ee582012-10-24 18:29:444902
[email protected]fb661802013-03-25 01:59:324903 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
4904 CreateNoScaleDrawableContentLayer(&delegate);
4905 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
4906 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:204907 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:324908 gfx::PointF(),
4909 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:574910 false,
[email protected]fb661802013-03-25 01:59:324911 true);
[email protected]518ee582012-10-24 18:29:444912
[email protected]35a99a12013-05-09 23:52:294913 root->AddChild(parent);
[email protected]518ee582012-10-24 18:29:444914
[email protected]fb661802013-03-25 01:59:324915 parent->AddChild(surface_scale);
4916 parent->AddChild(surface_no_scale);
[email protected]518ee582012-10-24 18:29:444917
[email protected]fb661802013-03-25 01:59:324918 surface_scale->SetForceRenderSurface(true);
4919 surface_scale->AddChild(surface_scale_child_scale);
4920 surface_scale->AddChild(surface_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:444921
[email protected]fb661802013-03-25 01:59:324922 surface_no_scale->SetForceRenderSurface(true);
4923 surface_no_scale->AddChild(surface_no_scale_child_scale);
4924 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:444925
enne2097cab2014-09-25 20:16:314926 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:284927 host->SetRootLayer(root);
4928
[email protected]803f6b52013-09-12 00:51:264929 SkMScalar device_scale_factor = 5;
4930 SkMScalar page_scale_factor = 7;
[email protected]518ee582012-10-24 18:29:444931
[email protected]7aad55f2013-07-26 11:25:534932 RenderSurfaceLayerList render_surface_layer_list;
4933 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:224934 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:534935 inputs.device_scale_factor = device_scale_factor;
4936 inputs.page_scale_factor = page_scale_factor;
4937 inputs.page_scale_application_layer = root.get();
4938 inputs.can_adjust_raster_scales = true;
4939 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4940
4941 EXPECT_CONTENTS_SCALE_EQ(
4942 device_scale_factor * page_scale_factor * initial_parent_scale, parent);
[email protected]f2136262013-04-26 21:10:194943 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor *
[email protected]7aad55f2013-07-26 11:25:534944 initial_parent_scale * initial_child_scale,
[email protected]fb661802013-03-25 01:59:324945 surface_scale);
4946 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale);
4947 EXPECT_CONTENTS_SCALE_EQ(
[email protected]fb661802013-03-25 01:59:324948 device_scale_factor * page_scale_factor * initial_parent_scale *
4949 initial_child_scale * initial_child_scale,
4950 surface_scale_child_scale);
4951 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale);
4952 EXPECT_CONTENTS_SCALE_EQ(
4953 device_scale_factor * page_scale_factor * initial_parent_scale *
4954 initial_child_scale * initial_child_scale,
4955 surface_no_scale_child_scale);
4956 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale);
[email protected]518ee582012-10-24 18:29:444957
[email protected]fb661802013-03-25 01:59:324958 // The parent is scaled up and shouldn't need to scale during draw.
[email protected]803f6b52013-09-12 00:51:264959 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(0, 0));
4960 EXPECT_FLOAT_EQ(1.0, parent->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:444961
[email protected]fb661802013-03-25 01:59:324962 // RenderSurfaces should always be 1:1 with their target.
4963 EXPECT_FLOAT_EQ(
4964 1.0,
[email protected]803f6b52013-09-12 00:51:264965 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:324966 EXPECT_FLOAT_EQ(
4967 1.0,
[email protected]803f6b52013-09-12 00:51:264968 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:444969
[email protected]fb661802013-03-25 01:59:324970 // The surface_scale can apply contents scale so the layer shouldn't need to
4971 // scale during draw.
[email protected]803f6b52013-09-12 00:51:264972 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(0, 0));
4973 EXPECT_FLOAT_EQ(1.0, surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:444974
[email protected]fb661802013-03-25 01:59:324975 // The surface_scale_child_scale can apply contents scale so it shouldn't need
4976 // to scale during draw.
4977 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:264978 1.0, surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:324979 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:264980 1.0, surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:444981
[email protected]fb661802013-03-25 01:59:324982 // The surface_scale_child_no_scale can not apply contents scale, so it needs
4983 // to be scaled during draw.
4984 EXPECT_FLOAT_EQ(
4985 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:264986 initial_child_scale * initial_child_scale,
4987 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:324988 EXPECT_FLOAT_EQ(
4989 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:264990 initial_child_scale * initial_child_scale,
4991 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:444992
[email protected]fb661802013-03-25 01:59:324993 // RenderSurfaces should always be 1:1 with their target.
4994 EXPECT_FLOAT_EQ(
4995 1.0,
[email protected]803f6b52013-09-12 00:51:264996 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:324997 EXPECT_FLOAT_EQ(
4998 1.0,
[email protected]803f6b52013-09-12 00:51:264999 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445000
[email protected]fb661802013-03-25 01:59:325001 // The surface_no_scale layer can not apply contents scale, so it needs to be
5002 // scaled during draw.
5003 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:265004 initial_parent_scale * initial_child_scale,
5005 surface_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325006 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor *
[email protected]803f6b52013-09-12 00:51:265007 initial_parent_scale * initial_child_scale,
5008 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445009
[email protected]fb661802013-03-25 01:59:325010 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5011 // to scale during draw.
5012 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265013 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325014 EXPECT_FLOAT_EQ(
[email protected]803f6b52013-09-12 00:51:265015 1.0, surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445016
[email protected]fb661802013-03-25 01:59:325017 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5018 // to be scaled during draw.
5019 EXPECT_FLOAT_EQ(
5020 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265021 initial_child_scale * initial_child_scale,
5022 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325023 EXPECT_FLOAT_EQ(
5024 device_scale_factor * page_scale_factor * initial_parent_scale *
[email protected]803f6b52013-09-12 00:51:265025 initial_child_scale * initial_child_scale,
5026 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295027}
[email protected]518ee582012-10-24 18:29:445028
sohan.jyotie3bd6192014-10-13 07:13:595029// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]989386c2013-07-18 21:37:235030TEST_F(LayerTreeHostCommonTest,
sohan.jyotie3bd6192014-10-13 07:13:595031 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale) {
[email protected]35a99a12013-05-09 23:52:295032 MockContentLayerClient delegate;
5033 gfx::Transform identity_matrix;
5034
5035 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265036 SkMScalar initial_parent_scale = 2.0;
[email protected]35a99a12013-05-09 23:52:295037 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
5038
5039 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265040 SkMScalar initial_child_scale = 3.0;
[email protected]35a99a12013-05-09 23:52:295041 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
5042
5043 scoped_refptr<Layer> root = Layer::Create();
5044 root->SetBounds(gfx::Size(100, 100));
5045
5046 scoped_refptr<ContentLayer> parent = CreateDrawableContentLayer(&delegate);
5047 SetLayerPropertiesForTesting(parent.get(),
5048 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205049 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295050 gfx::PointF(),
5051 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575052 false,
[email protected]35a99a12013-05-09 23:52:295053 true);
5054
5055 scoped_refptr<ContentLayer> surface_scale =
5056 CreateDrawableContentLayer(&delegate);
5057 SetLayerPropertiesForTesting(surface_scale.get(),
5058 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205059 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295060 gfx::PointF(2.f, 2.f),
5061 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575062 false,
[email protected]35a99a12013-05-09 23:52:295063 true);
5064
5065 scoped_refptr<ContentLayer> surface_scale_child_scale =
5066 CreateDrawableContentLayer(&delegate);
5067 SetLayerPropertiesForTesting(surface_scale_child_scale.get(),
5068 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205069 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295070 gfx::PointF(),
5071 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575072 false,
[email protected]35a99a12013-05-09 23:52:295073 true);
5074
5075 scoped_refptr<NoScaleContentLayer> surface_scale_child_no_scale =
5076 CreateNoScaleDrawableContentLayer(&delegate);
5077 SetLayerPropertiesForTesting(surface_scale_child_no_scale.get(),
5078 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205079 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295080 gfx::PointF(),
5081 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575082 false,
[email protected]35a99a12013-05-09 23:52:295083 true);
5084
5085 scoped_refptr<NoScaleContentLayer> surface_no_scale =
5086 CreateNoScaleDrawableContentLayer(&delegate);
5087 SetLayerPropertiesForTesting(surface_no_scale.get(),
5088 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205089 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295090 gfx::PointF(12.f, 12.f),
5091 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575092 false,
[email protected]35a99a12013-05-09 23:52:295093 true);
5094
5095 scoped_refptr<ContentLayer> surface_no_scale_child_scale =
5096 CreateDrawableContentLayer(&delegate);
5097 SetLayerPropertiesForTesting(surface_no_scale_child_scale.get(),
5098 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205099 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295100 gfx::PointF(),
5101 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575102 false,
[email protected]35a99a12013-05-09 23:52:295103 true);
5104
5105 scoped_refptr<NoScaleContentLayer> surface_no_scale_child_no_scale =
5106 CreateNoScaleDrawableContentLayer(&delegate);
5107 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale.get(),
5108 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205109 gfx::Point3F(),
[email protected]35a99a12013-05-09 23:52:295110 gfx::PointF(),
5111 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575112 false,
[email protected]35a99a12013-05-09 23:52:295113 true);
5114
5115 root->AddChild(parent);
5116
5117 parent->AddChild(surface_scale);
5118 parent->AddChild(surface_no_scale);
5119
5120 surface_scale->SetForceRenderSurface(true);
5121 surface_scale->AddChild(surface_scale_child_scale);
5122 surface_scale->AddChild(surface_scale_child_no_scale);
5123
5124 surface_no_scale->SetForceRenderSurface(true);
5125 surface_no_scale->AddChild(surface_no_scale_child_scale);
5126 surface_no_scale->AddChild(surface_no_scale_child_no_scale);
5127
enne2097cab2014-09-25 20:16:315128 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285129 host->SetRootLayer(root);
5130
[email protected]989386c2013-07-18 21:37:235131 RenderSurfaceLayerList render_surface_layer_list;
[email protected]35a99a12013-05-09 23:52:295132
[email protected]803f6b52013-09-12 00:51:265133 SkMScalar device_scale_factor = 5.0;
5134 SkMScalar page_scale_factor = 7.0;
[email protected]7aad55f2013-07-26 11:25:535135 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225136 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535137 inputs.device_scale_factor = device_scale_factor;
5138 inputs.page_scale_factor = page_scale_factor;
5139 inputs.page_scale_application_layer = root.get();
5140 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]35a99a12013-05-09 23:52:295141
[email protected]35a99a12013-05-09 23:52:295142 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5143 parent);
5144 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5145 surface_scale);
5146 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale);
5147 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5148 surface_scale_child_scale);
5149 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_scale_child_no_scale);
5150 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor * page_scale_factor,
5151 surface_no_scale_child_scale);
5152 EXPECT_CONTENTS_SCALE_EQ(1.f, surface_no_scale_child_no_scale);
5153
5154 // The parent is scaled up during draw, since its contents are not scaled by
5155 // the transform hierarchy.
5156 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265157 parent->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295158 EXPECT_FLOAT_EQ(initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265159 parent->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295160
hendrikwc493d2682015-01-26 23:35:115161 // The child surface is not scaled up during draw since its subtree is scaled
[email protected]35a99a12013-05-09 23:52:295162 // by the transform hierarchy.
5163 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115164 1.f,
[email protected]803f6b52013-09-12 00:51:265165 surface_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295166 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115167 1.f,
[email protected]803f6b52013-09-12 00:51:265168 surface_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295169
hendrikwc493d2682015-01-26 23:35:115170 // The surface_scale's RenderSurface is not scaled during draw, so the layer
5171 // needs to be scaled when drawing into its surface.
5172 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
5173 surface_scale->draw_transform().matrix().get(0, 0));
5174 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale,
5175 surface_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445176
hendrikwc493d2682015-01-26 23:35:115177 // The surface_scale_child_scale is not scaled when drawing into its surface,
5178 // since its content bounds are scaled by the transform hierarchy.
[email protected]fb661802013-03-25 01:59:325179 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115180 initial_child_scale * initial_child_scale * initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265181 surface_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325182 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115183 initial_child_scale * initial_child_scale * initial_parent_scale,
[email protected]803f6b52013-09-12 00:51:265184 surface_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445185
hendrikwc493d2682015-01-26 23:35:115186 // The surface_scale_child_no_scale is scaled by the device scale, page scale
5187 // and transform hierarchy.
[email protected]fb661802013-03-25 01:59:325188 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115189 device_scale_factor * page_scale_factor * initial_parent_scale *
5190 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265191 surface_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295192 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115193 device_scale_factor * page_scale_factor * initial_parent_scale *
5194 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265195 surface_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295196
hendrikwc493d2682015-01-26 23:35:115197 // The child surface is not scaled up during draw since its subtree is scaled
[email protected]35a99a12013-05-09 23:52:295198 // by the transform hierarchy.
5199 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115200 1.f,
[email protected]803f6b52013-09-12 00:51:265201 surface_no_scale->render_surface()->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325202 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115203 1.f,
[email protected]803f6b52013-09-12 00:51:265204 surface_no_scale->render_surface()->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445205
[email protected]35a99a12013-05-09 23:52:295206 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
5207 // be scaled by the device and page scale factors. Its surface is already
5208 // scaled by the transform hierarchy so those don't need to scale the layer's
5209 // drawing.
hendrikwc493d2682015-01-26 23:35:115210 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale *
5211 device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:265212 surface_no_scale->draw_transform().matrix().get(0, 0));
hendrikwc493d2682015-01-26 23:35:115213 EXPECT_FLOAT_EQ(initial_parent_scale * initial_child_scale *
5214 device_scale_factor * page_scale_factor,
[email protected]803f6b52013-09-12 00:51:265215 surface_no_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295216
5217 // The surface_no_scale_child_scale has its contents scaled by the page and
5218 // device scale factors, but needs to be scaled by the transform hierarchy
5219 // when drawing.
[email protected]fb661802013-03-25 01:59:325220 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115221 initial_parent_scale * initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265222 surface_no_scale_child_scale->draw_transform().matrix().get(0, 0));
[email protected]fb661802013-03-25 01:59:325223 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115224 initial_parent_scale * initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265225 surface_no_scale_child_scale->draw_transform().matrix().get(1, 1));
[email protected]35a99a12013-05-09 23:52:295226
hendrikwc493d2682015-01-26 23:35:115227 // The surface_no_scale_child_no_scale needs to be scaled by the device and
5228 // page scale factors and by any transform heirarchy below its target surface.
[email protected]35a99a12013-05-09 23:52:295229 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115230 device_scale_factor * page_scale_factor * initial_parent_scale *
5231 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265232 surface_no_scale_child_no_scale->draw_transform().matrix().get(0, 0));
[email protected]35a99a12013-05-09 23:52:295233 EXPECT_FLOAT_EQ(
hendrikwc493d2682015-01-26 23:35:115234 device_scale_factor * page_scale_factor * initial_parent_scale *
5235 initial_child_scale * initial_child_scale,
[email protected]803f6b52013-09-12 00:51:265236 surface_no_scale_child_no_scale->draw_transform().matrix().get(1, 1));
[email protected]518ee582012-10-24 18:29:445237}
5238
sohan.jyotie3bd6192014-10-13 07:13:595239TEST_F(LayerTreeHostCommonTest, IdealScaleForAnimatingLayer) {
[email protected]fb661802013-03-25 01:59:325240 MockContentLayerClient delegate;
5241 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:265242
[email protected]fb661802013-03-25 01:59:325243 gfx::Transform parent_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265244 SkMScalar initial_parent_scale = 1.75;
[email protected]fb661802013-03-25 01:59:325245 parent_scale_matrix.Scale(initial_parent_scale, initial_parent_scale);
[email protected]6a9cff92012-11-08 11:53:265246
[email protected]fb661802013-03-25 01:59:325247 gfx::Transform child_scale_matrix;
[email protected]803f6b52013-09-12 00:51:265248 SkMScalar initial_child_scale = 1.25;
[email protected]fb661802013-03-25 01:59:325249 child_scale_matrix.Scale(initial_child_scale, initial_child_scale);
[email protected]6a9cff92012-11-08 11:53:265250
[email protected]35a99a12013-05-09 23:52:295251 scoped_refptr<Layer> root = Layer::Create();
5252 root->SetBounds(gfx::Size(100, 100));
5253
sohan.jyotie3bd6192014-10-13 07:13:595254 scoped_refptr<FakePictureLayer> parent =
5255 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325256 SetLayerPropertiesForTesting(parent.get(),
5257 parent_scale_matrix,
[email protected]a2566412014-06-05 03:14:205258 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325259 gfx::PointF(),
5260 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575261 false,
[email protected]fb661802013-03-25 01:59:325262 true);
[email protected]6a9cff92012-11-08 11:53:265263
sohan.jyotie3bd6192014-10-13 07:13:595264 scoped_refptr<FakePictureLayer> child_scale =
5265 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325266 SetLayerPropertiesForTesting(child_scale.get(),
5267 child_scale_matrix,
[email protected]a2566412014-06-05 03:14:205268 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325269 gfx::PointF(2.f, 2.f),
5270 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575271 false,
[email protected]fb661802013-03-25 01:59:325272 true);
[email protected]6a9cff92012-11-08 11:53:265273
[email protected]35a99a12013-05-09 23:52:295274 root->AddChild(parent);
5275
[email protected]fb661802013-03-25 01:59:325276 parent->AddChild(child_scale);
[email protected]6a9cff92012-11-08 11:53:265277
enne2097cab2014-09-25 20:16:315278 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285279 host->SetRootLayer(root);
5280
[email protected]989386c2013-07-18 21:37:235281 {
5282 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535283 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225284 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535285 inputs.can_adjust_raster_scales = true;
5286 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]6a9cff92012-11-08 11:53:265287
sohan.jyotie3bd6192014-10-13 07:13:595288 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale, parent);
5289 // Animating layers compute ideal scale in the same way as when
5290 // they are static.
5291 EXPECT_IDEAL_SCALE_EQ(initial_child_scale * initial_parent_scale,
5292 child_scale);
[email protected]989386c2013-07-18 21:37:235293 }
[email protected]6a9cff92012-11-08 11:53:265294}
5295
sohan.jyotie3bd6192014-10-13 07:13:595296// TODO(sohanjg): Remove this test when ContentLayer is removed.
[email protected]7a5a9322014-02-25 12:54:575297TEST_F(LayerTreeHostCommonTest,
5298 ChangeInContentBoundsOrScaleTriggersPushProperties) {
5299 MockContentLayerClient delegate;
5300 scoped_refptr<Layer> root = Layer::Create();
5301 scoped_refptr<Layer> child = CreateDrawableContentLayer(&delegate);
5302 root->AddChild(child);
5303
enne2097cab2014-09-25 20:16:315304 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]7a5a9322014-02-25 12:54:575305 host->SetRootLayer(root);
5306
5307 gfx::Transform identity_matrix;
5308 SetLayerPropertiesForTesting(root.get(),
5309 identity_matrix,
[email protected]a2566412014-06-05 03:14:205310 gfx::Point3F(),
[email protected]7a5a9322014-02-25 12:54:575311 gfx::PointF(),
5312 gfx::Size(100, 100),
5313 true,
5314 false);
5315 SetLayerPropertiesForTesting(child.get(),
5316 identity_matrix,
[email protected]a2566412014-06-05 03:14:205317 gfx::Point3F(),
[email protected]7a5a9322014-02-25 12:54:575318 gfx::PointF(),
5319 gfx::Size(100, 100),
5320 true,
5321 false);
5322
5323 root->reset_needs_push_properties_for_testing();
5324 child->reset_needs_push_properties_for_testing();
5325
5326 // This will change both layers' content bounds.
5327 ExecuteCalculateDrawProperties(root.get());
5328 EXPECT_TRUE(root->needs_push_properties());
5329 EXPECT_TRUE(child->needs_push_properties());
5330
5331 root->reset_needs_push_properties_for_testing();
5332 child->reset_needs_push_properties_for_testing();
5333
5334 // This will change only the child layer's contents scale and content bounds,
5335 // since the root layer is not a ContentsScalingLayer.
5336 ExecuteCalculateDrawProperties(root.get(), 2.f);
5337 EXPECT_FALSE(root->needs_push_properties());
5338 EXPECT_TRUE(child->needs_push_properties());
5339
5340 root->reset_needs_push_properties_for_testing();
5341 child->reset_needs_push_properties_for_testing();
5342
5343 // This will not change either layer's contents scale or content bounds.
5344 ExecuteCalculateDrawProperties(root.get(), 2.f);
5345 EXPECT_FALSE(root->needs_push_properties());
5346 EXPECT_FALSE(child->needs_push_properties());
5347}
5348
[email protected]989386c2013-07-18 21:37:235349TEST_F(LayerTreeHostCommonTest, RenderSurfaceTransformsInHighDPI) {
[email protected]fb661802013-03-25 01:59:325350 MockContentLayerClient delegate;
5351 gfx::Transform identity_matrix;
[email protected]6a9cff92012-11-08 11:53:265352
sohan.jyotie3bd6192014-10-13 07:13:595353 scoped_refptr<FakePictureLayer> parent =
5354 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325355 SetLayerPropertiesForTesting(parent.get(),
5356 identity_matrix,
[email protected]a2566412014-06-05 03:14:205357 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325358 gfx::PointF(),
5359 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:575360 false,
[email protected]fb661802013-03-25 01:59:325361 true);
[email protected]94f206c12012-08-25 00:09:145362
sohan.jyotie3bd6192014-10-13 07:13:595363 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325364 SetLayerPropertiesForTesting(child.get(),
5365 identity_matrix,
[email protected]a2566412014-06-05 03:14:205366 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325367 gfx::PointF(2.f, 2.f),
5368 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575369 false,
[email protected]fb661802013-03-25 01:59:325370 true);
[email protected]94f206c12012-08-25 00:09:145371
[email protected]fb661802013-03-25 01:59:325372 gfx::Transform replica_transform;
5373 replica_transform.Scale(1.0, -1.0);
sohan.jyotie3bd6192014-10-13 07:13:595374 scoped_refptr<FakePictureLayer> replica =
5375 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325376 SetLayerPropertiesForTesting(replica.get(),
5377 replica_transform,
[email protected]a2566412014-06-05 03:14:205378 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325379 gfx::PointF(2.f, 2.f),
5380 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575381 false,
[email protected]fb661802013-03-25 01:59:325382 true);
[email protected]94f206c12012-08-25 00:09:145383
[email protected]fb661802013-03-25 01:59:325384 // This layer should end up in the same surface as child, with the same draw
5385 // and screen space transforms.
sohan.jyotie3bd6192014-10-13 07:13:595386 scoped_refptr<FakePictureLayer> duplicate_child_non_owner =
5387 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325388 SetLayerPropertiesForTesting(duplicate_child_non_owner.get(),
5389 identity_matrix,
[email protected]a2566412014-06-05 03:14:205390 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325391 gfx::PointF(),
5392 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575393 false,
[email protected]fb661802013-03-25 01:59:325394 true);
[email protected]94f206c12012-08-25 00:09:145395
[email protected]fb661802013-03-25 01:59:325396 parent->AddChild(child);
5397 child->AddChild(duplicate_child_non_owner);
5398 child->SetReplicaLayer(replica.get());
[email protected]94f206c12012-08-25 00:09:145399
enne2097cab2014-09-25 20:16:315400 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285401 host->SetRootLayer(parent);
5402
[email protected]989386c2013-07-18 21:37:235403 RenderSurfaceLayerList render_surface_layer_list;
[email protected]94f206c12012-08-25 00:09:145404
[email protected]fb661802013-03-25 01:59:325405 float device_scale_factor = 1.5f;
[email protected]7aad55f2013-07-26 11:25:535406 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5407 parent.get(), parent->bounds(), &render_surface_layer_list);
5408 inputs.device_scale_factor = device_scale_factor;
5409 inputs.can_adjust_raster_scales = true;
5410 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]94f206c12012-08-25 00:09:145411
[email protected]fb661802013-03-25 01:59:325412 // We should have two render surfaces. The root's render surface and child's
5413 // render surface (it needs one because it has a replica layer).
5414 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]94f206c12012-08-25 00:09:145415
[email protected]fb661802013-03-25 01:59:325416 gfx::Transform expected_parent_transform;
sohan.jyotie3bd6192014-10-13 07:13:595417 expected_parent_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:325418 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
5419 parent->screen_space_transform());
5420 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform,
5421 parent->draw_transform());
[email protected]94f206c12012-08-25 00:09:145422
[email protected]fb661802013-03-25 01:59:325423 gfx::Transform expected_draw_transform;
sohan.jyotie3bd6192014-10-13 07:13:595424 expected_draw_transform.Scale(device_scale_factor, device_scale_factor);
[email protected]fb661802013-03-25 01:59:325425 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform,
5426 child->draw_transform());
[email protected]94f206c12012-08-25 00:09:145427
[email protected]fb661802013-03-25 01:59:325428 gfx::Transform expected_screen_space_transform;
sohan.jyotie3bd6192014-10-13 07:13:595429 expected_screen_space_transform.Scale(device_scale_factor,
5430 device_scale_factor);
5431 expected_screen_space_transform.Translate(child->position().x(),
5432 child->position().y());
[email protected]fb661802013-03-25 01:59:325433 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform,
5434 child->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145435
[email protected]fb661802013-03-25 01:59:325436 gfx::Transform expected_duplicate_child_draw_transform =
5437 child->draw_transform();
5438 EXPECT_TRANSFORMATION_MATRIX_EQ(child->draw_transform(),
5439 duplicate_child_non_owner->draw_transform());
5440 EXPECT_TRANSFORMATION_MATRIX_EQ(
5441 child->screen_space_transform(),
5442 duplicate_child_non_owner->screen_space_transform());
hush6b614212014-12-04 22:37:325443 EXPECT_EQ(child->drawable_content_rect(),
5444 duplicate_child_non_owner->drawable_content_rect());
[email protected]fb661802013-03-25 01:59:325445 EXPECT_EQ(child->content_bounds(),
5446 duplicate_child_non_owner->content_bounds());
[email protected]94f206c12012-08-25 00:09:145447
[email protected]fb661802013-03-25 01:59:325448 gfx::Transform expected_render_surface_draw_transform;
5449 expected_render_surface_draw_transform.Translate(
5450 device_scale_factor * child->position().x(),
5451 device_scale_factor * child->position().y());
5452 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform,
5453 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145454
[email protected]fb661802013-03-25 01:59:325455 gfx::Transform expected_surface_draw_transform;
5456 expected_surface_draw_transform.Translate(device_scale_factor * 2.f,
5457 device_scale_factor * 2.f);
5458 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform,
5459 child->render_surface()->draw_transform());
[email protected]94f206c12012-08-25 00:09:145460
[email protected]fb661802013-03-25 01:59:325461 gfx::Transform expected_surface_screen_space_transform;
5462 expected_surface_screen_space_transform.Translate(device_scale_factor * 2.f,
5463 device_scale_factor * 2.f);
5464 EXPECT_TRANSFORMATION_MATRIX_EQ(
5465 expected_surface_screen_space_transform,
5466 child->render_surface()->screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145467
[email protected]fb661802013-03-25 01:59:325468 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265469 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
5470 expected_replica_draw_transform.matrix().set(0, 3, 6.0);
5471 expected_replica_draw_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325472 EXPECT_TRANSFORMATION_MATRIX_EQ(
5473 expected_replica_draw_transform,
5474 child->render_surface()->replica_draw_transform());
[email protected]94f206c12012-08-25 00:09:145475
[email protected]fb661802013-03-25 01:59:325476 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265477 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
5478 expected_replica_screen_space_transform.matrix().set(0, 3, 6.0);
5479 expected_replica_screen_space_transform.matrix().set(1, 3, 6.0);
[email protected]fb661802013-03-25 01:59:325480 EXPECT_TRANSFORMATION_MATRIX_EQ(
5481 expected_replica_screen_space_transform,
5482 child->render_surface()->replica_screen_space_transform());
5483 EXPECT_TRANSFORMATION_MATRIX_EQ(
5484 expected_replica_screen_space_transform,
5485 child->render_surface()->replica_screen_space_transform());
[email protected]904e9132012-11-01 00:12:475486}
5487
[email protected]989386c2013-07-18 21:37:235488TEST_F(LayerTreeHostCommonTest,
[email protected]fb661802013-03-25 01:59:325489 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition) {
5490 MockContentLayerClient delegate;
5491 gfx::Transform identity_matrix;
[email protected]904e9132012-11-01 00:12:475492
sohan.jyotie3bd6192014-10-13 07:13:595493 scoped_refptr<FakePictureLayer> parent =
5494 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325495 SetLayerPropertiesForTesting(parent.get(),
5496 identity_matrix,
[email protected]a2566412014-06-05 03:14:205497 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325498 gfx::PointF(),
5499 gfx::Size(33, 31),
[email protected]56fffdd2014-02-11 19:50:575500 false,
[email protected]fb661802013-03-25 01:59:325501 true);
[email protected]904e9132012-11-01 00:12:475502
sohan.jyotie3bd6192014-10-13 07:13:595503 scoped_refptr<FakePictureLayer> child = CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325504 SetLayerPropertiesForTesting(child.get(),
5505 identity_matrix,
[email protected]a2566412014-06-05 03:14:205506 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325507 gfx::PointF(),
5508 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:575509 false,
[email protected]fb661802013-03-25 01:59:325510 true);
[email protected]904e9132012-11-01 00:12:475511
[email protected]fb661802013-03-25 01:59:325512 gfx::Transform replica_transform;
5513 replica_transform.Scale(1.0, -1.0);
sohan.jyotie3bd6192014-10-13 07:13:595514 scoped_refptr<FakePictureLayer> replica =
5515 CreateDrawablePictureLayer(&delegate);
[email protected]fb661802013-03-25 01:59:325516 SetLayerPropertiesForTesting(replica.get(),
5517 replica_transform,
[email protected]a2566412014-06-05 03:14:205518 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325519 gfx::PointF(),
5520 gfx::Size(13, 11),
[email protected]56fffdd2014-02-11 19:50:575521 false,
[email protected]fb661802013-03-25 01:59:325522 true);
[email protected]904e9132012-11-01 00:12:475523
[email protected]fb661802013-03-25 01:59:325524 parent->AddChild(child);
[email protected]fb661802013-03-25 01:59:325525 child->SetReplicaLayer(replica.get());
[email protected]904e9132012-11-01 00:12:475526
enne2097cab2014-09-25 20:16:315527 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285528 host->SetRootLayer(parent);
5529
[email protected]873639e2013-07-24 19:56:315530 float device_scale_factor = 1.7f;
[email protected]7aad55f2013-07-26 11:25:535531
5532 RenderSurfaceLayerList render_surface_layer_list;
5533 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
5534 parent.get(), parent->bounds(), &render_surface_layer_list);
5535 inputs.device_scale_factor = device_scale_factor;
5536 inputs.can_adjust_raster_scales = true;
5537 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]904e9132012-11-01 00:12:475538
[email protected]fb661802013-03-25 01:59:325539 // We should have two render surfaces. The root's render surface and child's
5540 // render surface (it needs one because it has a replica layer).
5541 EXPECT_EQ(2u, render_surface_layer_list.size());
[email protected]904e9132012-11-01 00:12:475542
[email protected]fb661802013-03-25 01:59:325543 gfx::Transform identity_transform;
[email protected]fb661802013-03-25 01:59:325544 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5545 child->render_surface()->draw_transform());
5546 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform,
5547 child->render_surface()->draw_transform());
5548 EXPECT_TRANSFORMATION_MATRIX_EQ(
5549 identity_transform, child->render_surface()->screen_space_transform());
[email protected]904e9132012-11-01 00:12:475550
[email protected]fb661802013-03-25 01:59:325551 gfx::Transform expected_replica_draw_transform;
[email protected]803f6b52013-09-12 00:51:265552 expected_replica_draw_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325553 EXPECT_TRANSFORMATION_MATRIX_EQ(
5554 expected_replica_draw_transform,
5555 child->render_surface()->replica_draw_transform());
[email protected]904e9132012-11-01 00:12:475556
[email protected]fb661802013-03-25 01:59:325557 gfx::Transform expected_replica_screen_space_transform;
[email protected]803f6b52013-09-12 00:51:265558 expected_replica_screen_space_transform.matrix().set(1, 1, -1.0);
[email protected]fb661802013-03-25 01:59:325559 EXPECT_TRANSFORMATION_MATRIX_EQ(
5560 expected_replica_screen_space_transform,
5561 child->render_surface()->replica_screen_space_transform());
[email protected]94f206c12012-08-25 00:09:145562}
5563
[email protected]989386c2013-07-18 21:37:235564TEST_F(LayerTreeHostCommonTest, SubtreeSearch) {
[email protected]fb661802013-03-25 01:59:325565 scoped_refptr<Layer> root = Layer::Create();
5566 scoped_refptr<Layer> child = Layer::Create();
5567 scoped_refptr<Layer> grand_child = Layer::Create();
5568 scoped_refptr<Layer> mask_layer = Layer::Create();
5569 scoped_refptr<Layer> replica_layer = Layer::Create();
[email protected]94f206c12012-08-25 00:09:145570
[email protected]fb661802013-03-25 01:59:325571 grand_child->SetReplicaLayer(replica_layer.get());
5572 child->AddChild(grand_child.get());
5573 child->SetMaskLayer(mask_layer.get());
5574 root->AddChild(child.get());
[email protected]94f206c12012-08-25 00:09:145575
enne2097cab2014-09-25 20:16:315576 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285577 host->SetRootLayer(root);
5578
[email protected]fb661802013-03-25 01:59:325579 int nonexistent_id = -1;
Daniel Chengeea98042014-08-26 00:28:105580 EXPECT_EQ(root.get(),
[email protected]fb661802013-03-25 01:59:325581 LayerTreeHostCommon::FindLayerInSubtree(root.get(), root->id()));
Daniel Chengeea98042014-08-26 00:28:105582 EXPECT_EQ(child.get(),
[email protected]fb661802013-03-25 01:59:325583 LayerTreeHostCommon::FindLayerInSubtree(root.get(), child->id()));
5584 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105585 grand_child.get(),
[email protected]fb661802013-03-25 01:59:325586 LayerTreeHostCommon::FindLayerInSubtree(root.get(), grand_child->id()));
5587 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105588 mask_layer.get(),
[email protected]fb661802013-03-25 01:59:325589 LayerTreeHostCommon::FindLayerInSubtree(root.get(), mask_layer->id()));
5590 EXPECT_EQ(
Daniel Chengeea98042014-08-26 00:28:105591 replica_layer.get(),
[email protected]fb661802013-03-25 01:59:325592 LayerTreeHostCommon::FindLayerInSubtree(root.get(), replica_layer->id()));
5593 EXPECT_EQ(
5594 0, LayerTreeHostCommon::FindLayerInSubtree(root.get(), nonexistent_id));
[email protected]94f206c12012-08-25 00:09:145595}
5596
[email protected]989386c2013-07-18 21:37:235597TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) {
[email protected]fb661802013-03-25 01:59:325598 scoped_refptr<Layer> root = Layer::Create();
5599 scoped_refptr<Layer> child = Layer::Create();
5600 scoped_refptr<LayerWithForcedDrawsContent> grand_child =
5601 make_scoped_refptr(new LayerWithForcedDrawsContent());
[email protected]498ec6e0e2012-11-30 18:24:575602
[email protected]fb661802013-03-25 01:59:325603 const gfx::Transform identity_matrix;
5604 SetLayerPropertiesForTesting(root.get(),
5605 identity_matrix,
[email protected]a2566412014-06-05 03:14:205606 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325607 gfx::PointF(),
5608 gfx::Size(100, 100),
[email protected]56fffdd2014-02-11 19:50:575609 true,
[email protected]fb661802013-03-25 01:59:325610 false);
5611 SetLayerPropertiesForTesting(child.get(),
5612 identity_matrix,
[email protected]a2566412014-06-05 03:14:205613 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325614 gfx::PointF(),
5615 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575616 true,
[email protected]fb661802013-03-25 01:59:325617 false);
5618 SetLayerPropertiesForTesting(grand_child.get(),
5619 identity_matrix,
[email protected]a2566412014-06-05 03:14:205620 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325621 gfx::PointF(),
5622 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:575623 true,
[email protected]fb661802013-03-25 01:59:325624 false);
[email protected]498ec6e0e2012-11-30 18:24:575625
[email protected]fb661802013-03-25 01:59:325626 root->AddChild(child);
5627 child->AddChild(grand_child);
5628 child->SetOpacity(0.5f);
[email protected]498ec6e0e2012-11-30 18:24:575629
enne2097cab2014-09-25 20:16:315630 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285631 host->SetRootLayer(root);
5632
[email protected]fb661802013-03-25 01:59:325633 ExecuteCalculateDrawProperties(root.get());
[email protected]498ec6e0e2012-11-30 18:24:575634
[email protected]fb661802013-03-25 01:59:325635 EXPECT_FALSE(child->render_surface());
[email protected]498ec6e0e2012-11-30 18:24:575636}
5637
[email protected]989386c2013-07-18 21:37:235638TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) {
[email protected]f90fc412013-03-30 20:13:165639 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455640 TestSharedBitmapManager shared_bitmap_manager;
5641 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]f90fc412013-03-30 20:13:165642 host_impl.CreatePendingTree();
5643 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
5644
5645 const gfx::Transform identity_matrix;
awoloszyne83f28c2014-12-22 15:40:005646 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5647 gfx::PointF(), gfx::Size(100, 100), true, false,
[email protected]f90fc412013-03-30 20:13:165648 false);
5649 root->SetDrawsContent(true);
5650
5651 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005652 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5653 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]f90fc412013-03-30 20:13:165654 false);
5655 child->SetDrawsContent(true);
5656 child->SetOpacity(0.0f);
5657
5658 // Add opacity animation.
5659 AddOpacityTransitionToController(
5660 child->layer_animation_controller(), 10.0, 0.0f, 1.0f, false);
5661
5662 root->AddChild(child.Pass());
awoloszyne83f28c2014-12-22 15:40:005663 root->SetHasRenderSurface(true);
[email protected]f90fc412013-03-30 20:13:165664
[email protected]c0ae06c12013-06-24 18:32:195665 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535666 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225667 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535668 inputs.can_adjust_raster_scales = true;
5669 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]f90fc412013-03-30 20:13:165670
5671 // We should have one render surface and two layers. The child
5672 // layer should be included even though it is transparent.
5673 ASSERT_EQ(1u, render_surface_layer_list.size());
5674 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5675}
5676
danakj3f76ace2014-11-18 16:56:005677using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
[email protected]989386c2013-07-18 21:37:235678class LCDTextTest
5679 : public LayerTreeHostCommonTestBase,
5680 public testing::TestWithParam<LCDTextTestParam> {
[email protected]fb661802013-03-25 01:59:325681 protected:
dcheng93a52eb2014-12-23 02:14:235682 void SetUp() override {
[email protected]fb661802013-03-25 01:59:325683 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
danakj3f76ace2014-11-18 16:56:005684 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
[email protected]10aabcc32012-12-13 09:18:595685
[email protected]fb661802013-03-25 01:59:325686 root_ = Layer::Create();
5687 child_ = Layer::Create();
5688 grand_child_ = Layer::Create();
5689 child_->AddChild(grand_child_.get());
5690 root_->AddChild(child_.get());
[email protected]10aabcc32012-12-13 09:18:595691
fmalita51b5e202014-11-18 20:11:505692 root_->SetContentsOpaque(true);
5693 child_->SetContentsOpaque(true);
5694 grand_child_->SetContentsOpaque(true);
5695
[email protected]fb661802013-03-25 01:59:325696 gfx::Transform identity_matrix;
[email protected]22898ed2013-06-01 04:52:305697 SetLayerPropertiesForTesting(root_.get(),
[email protected]fb661802013-03-25 01:59:325698 identity_matrix,
[email protected]a2566412014-06-05 03:14:205699 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325700 gfx::PointF(),
5701 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:575702 true,
[email protected]fb661802013-03-25 01:59:325703 false);
[email protected]22898ed2013-06-01 04:52:305704 SetLayerPropertiesForTesting(child_.get(),
[email protected]fb661802013-03-25 01:59:325705 identity_matrix,
[email protected]a2566412014-06-05 03:14:205706 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325707 gfx::PointF(),
5708 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:575709 true,
[email protected]fb661802013-03-25 01:59:325710 false);
[email protected]22898ed2013-06-01 04:52:305711 SetLayerPropertiesForTesting(grand_child_.get(),
[email protected]fb661802013-03-25 01:59:325712 identity_matrix,
[email protected]a2566412014-06-05 03:14:205713 gfx::Point3F(),
[email protected]fb661802013-03-25 01:59:325714 gfx::PointF(),
5715 gfx::Size(1, 1),
[email protected]56fffdd2014-02-11 19:50:575716 true,
[email protected]fb661802013-03-25 01:59:325717 false);
[email protected]10aabcc32012-12-13 09:18:595718
danakj3f76ace2014-11-18 16:56:005719 child_->SetForceRenderSurface(std::tr1::get<2>(GetParam()));
[email protected]d600df7d2013-08-03 02:34:285720
enne2097cab2014-09-25 20:16:315721 host_ = CreateFakeLayerTreeHost();
[email protected]d600df7d2013-08-03 02:34:285722 host_->SetRootLayer(root_);
[email protected]fb661802013-03-25 01:59:325723 }
[email protected]10aabcc32012-12-13 09:18:595724
[email protected]fb661802013-03-25 01:59:325725 bool can_use_lcd_text_;
danakj3f76ace2014-11-18 16:56:005726 bool layers_always_allowed_lcd_text_;
[email protected]d600df7d2013-08-03 02:34:285727 scoped_ptr<FakeLayerTreeHost> host_;
[email protected]fb661802013-03-25 01:59:325728 scoped_refptr<Layer> root_;
5729 scoped_refptr<Layer> child_;
5730 scoped_refptr<Layer> grand_child_;
[email protected]10aabcc32012-12-13 09:18:595731};
5732
[email protected]fb661802013-03-25 01:59:325733TEST_P(LCDTextTest, CanUseLCDText) {
danakj3f76ace2014-11-18 16:56:005734 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5735 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5736
[email protected]fb661802013-03-25 01:59:325737 // Case 1: Identity transform.
5738 gfx::Transform identity_matrix;
danakj3f76ace2014-11-18 16:56:005739 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5740 layers_always_allowed_lcd_text_);
5741 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5742 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5743 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595744
[email protected]fb661802013-03-25 01:59:325745 // Case 2: Integral translation.
5746 gfx::Transform integral_translation;
5747 integral_translation.Translate(1.0, 2.0);
5748 child_->SetTransform(integral_translation);
danakj3f76ace2014-11-18 16:56:005749 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5750 layers_always_allowed_lcd_text_);
5751 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5752 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5753 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595754
[email protected]fb661802013-03-25 01:59:325755 // Case 3: Non-integral translation.
5756 gfx::Transform non_integral_translation;
5757 non_integral_translation.Translate(1.5, 2.5);
5758 child_->SetTransform(non_integral_translation);
danakj3f76ace2014-11-18 16:56:005759 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5760 layers_always_allowed_lcd_text_);
5761 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5762 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5763 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595764
[email protected]fb661802013-03-25 01:59:325765 // Case 4: Rotation.
5766 gfx::Transform rotation;
5767 rotation.Rotate(10.0);
5768 child_->SetTransform(rotation);
danakj3f76ace2014-11-18 16:56:005769 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5770 layers_always_allowed_lcd_text_);
5771 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5772 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5773 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595774
[email protected]fb661802013-03-25 01:59:325775 // Case 5: Scale.
5776 gfx::Transform scale;
5777 scale.Scale(2.0, 2.0);
5778 child_->SetTransform(scale);
danakj3f76ace2014-11-18 16:56:005779 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5780 layers_always_allowed_lcd_text_);
5781 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5782 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5783 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595784
[email protected]fb661802013-03-25 01:59:325785 // Case 6: Skew.
5786 gfx::Transform skew;
5787 skew.SkewX(10.0);
5788 child_->SetTransform(skew);
danakj3f76ace2014-11-18 16:56:005789 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5790 layers_always_allowed_lcd_text_);
5791 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5792 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5793 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595794
[email protected]fb661802013-03-25 01:59:325795 // Case 7: Translucent.
5796 child_->SetTransform(identity_matrix);
5797 child_->SetOpacity(0.5f);
danakj3f76ace2014-11-18 16:56:005798 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5799 layers_always_allowed_lcd_text_);
5800 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5801 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5802 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595803
[email protected]fb661802013-03-25 01:59:325804 // Case 8: Sanity check: restore transform and opacity.
5805 child_->SetTransform(identity_matrix);
5806 child_->SetOpacity(1.f);
danakj3f76ace2014-11-18 16:56:005807 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5808 layers_always_allowed_lcd_text_);
5809 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5810 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5811 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
fmalita51b5e202014-11-18 20:11:505812
5813 // Case 9: Non-opaque content.
5814 child_->SetContentsOpaque(false);
5815 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5816 layers_always_allowed_lcd_text_);
5817 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5818 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5819 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5820
5821 // Case 10: Sanity check: restore content opaqueness.
5822 child_->SetContentsOpaque(true);
5823 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5824 layers_always_allowed_lcd_text_);
5825 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5826 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5827 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595828}
5829
[email protected]fd9a3b6d2013-08-03 00:46:175830TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
danakj3f76ace2014-11-18 16:56:005831 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5832
[email protected]fb661802013-03-25 01:59:325833 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
danakj3f76ace2014-11-18 16:56:005834 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5835 layers_always_allowed_lcd_text_);
5836 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5837 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5838 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595839
[email protected]fb661802013-03-25 01:59:325840 // Add opacity animation.
5841 child_->SetOpacity(0.9f);
5842 AddOpacityTransitionToController(
5843 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
[email protected]10aabcc32012-12-13 09:18:595844
danakj3f76ace2014-11-18 16:56:005845 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5846 layers_always_allowed_lcd_text_);
[email protected]fb661802013-03-25 01:59:325847 // Text AA should not be adjusted while animation is active.
5848 // Make sure LCD text AA setting remains unchanged.
danakj3f76ace2014-11-18 16:56:005849 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5850 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5851 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
[email protected]10aabcc32012-12-13 09:18:595852}
5853
5854INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5855 LCDTextTest,
danakj3f76ace2014-11-18 16:56:005856 testing::Combine(testing::Bool(),
5857 testing::Bool(),
5858 testing::Bool()));
[email protected]10aabcc32012-12-13 09:18:595859
[email protected]989386c2013-07-18 21:37:235860TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
[email protected]c0ae06c12013-06-24 18:32:195861 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455862 TestSharedBitmapManager shared_bitmap_manager;
5863 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:195864 host_impl.CreatePendingTree();
5865 const gfx::Transform identity_matrix;
5866
5867 scoped_refptr<Layer> root = Layer::Create();
5868 SetLayerPropertiesForTesting(root.get(),
5869 identity_matrix,
[email protected]a2566412014-06-05 03:14:205870 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195871 gfx::PointF(),
5872 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575873 true,
[email protected]c0ae06c12013-06-24 18:32:195874 false);
5875 root->SetIsDrawable(true);
5876
5877 scoped_refptr<Layer> child = Layer::Create();
5878 SetLayerPropertiesForTesting(child.get(),
5879 identity_matrix,
[email protected]a2566412014-06-05 03:14:205880 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195881 gfx::PointF(),
5882 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:575883 true,
[email protected]c0ae06c12013-06-24 18:32:195884 false);
5885 child->SetIsDrawable(true);
5886
5887 scoped_refptr<Layer> grand_child = Layer::Create();
5888 SetLayerPropertiesForTesting(grand_child.get(),
5889 identity_matrix,
[email protected]a2566412014-06-05 03:14:205890 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195891 gfx::PointF(),
5892 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:575893 true,
[email protected]c0ae06c12013-06-24 18:32:195894 false);
5895 grand_child->SetIsDrawable(true);
5896 grand_child->SetHideLayerAndSubtree(true);
5897
5898 child->AddChild(grand_child);
5899 root->AddChild(child);
5900
enne2097cab2014-09-25 20:16:315901 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:285902 host->SetRootLayer(root);
5903
[email protected]989386c2013-07-18 21:37:235904 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535905 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225906 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535907 inputs.can_adjust_raster_scales = true;
5908 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195909
5910 // We should have one render surface and two layers. The grand child has
5911 // hidden itself.
5912 ASSERT_EQ(1u, render_surface_layer_list.size());
5913 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235914 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
5915 EXPECT_EQ(child->id(), root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195916}
5917
[email protected]989386c2013-07-18 21:37:235918TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) {
[email protected]c0ae06c12013-06-24 18:32:195919 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455920 TestSharedBitmapManager shared_bitmap_manager;
5921 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:195922 host_impl.CreatePendingTree();
5923 const gfx::Transform identity_matrix;
5924
5925 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:005926 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
5927 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]c0ae06c12013-06-24 18:32:195928 false);
5929 root->SetDrawsContent(true);
5930
5931 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:005932 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
5933 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:195934 false);
5935 child->SetDrawsContent(true);
5936
5937 scoped_ptr<LayerImpl> grand_child =
5938 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:005939 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
5940 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5941 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:195942 grand_child->SetDrawsContent(true);
5943 grand_child->SetHideLayerAndSubtree(true);
5944
5945 child->AddChild(grand_child.Pass());
5946 root->AddChild(child.Pass());
awoloszyne83f28c2014-12-22 15:40:005947 root->SetHasRenderSurface(true);
[email protected]c0ae06c12013-06-24 18:32:195948
5949 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:535950 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:225951 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:535952 inputs.can_adjust_raster_scales = true;
5953 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:195954
5955 // We should have one render surface and two layers. The grand child has
5956 // hidden itself.
5957 ASSERT_EQ(1u, render_surface_layer_list.size());
5958 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:235959 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
5960 EXPECT_EQ(2, root->render_surface()->layer_list().at(1)->id());
[email protected]c0ae06c12013-06-24 18:32:195961}
5962
[email protected]989386c2013-07-18 21:37:235963TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayers) {
[email protected]c0ae06c12013-06-24 18:32:195964 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:455965 TestSharedBitmapManager shared_bitmap_manager;
5966 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:195967 host_impl.CreatePendingTree();
5968 const gfx::Transform identity_matrix;
5969
5970 scoped_refptr<Layer> root = Layer::Create();
5971 SetLayerPropertiesForTesting(root.get(),
5972 identity_matrix,
[email protected]a2566412014-06-05 03:14:205973 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195974 gfx::PointF(),
5975 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:575976 true,
[email protected]c0ae06c12013-06-24 18:32:195977 false);
5978 root->SetIsDrawable(true);
5979
5980 scoped_refptr<Layer> child = Layer::Create();
5981 SetLayerPropertiesForTesting(child.get(),
5982 identity_matrix,
[email protected]a2566412014-06-05 03:14:205983 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195984 gfx::PointF(),
5985 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:575986 true,
[email protected]c0ae06c12013-06-24 18:32:195987 false);
5988 child->SetIsDrawable(true);
5989 child->SetHideLayerAndSubtree(true);
5990
5991 scoped_refptr<Layer> grand_child = Layer::Create();
5992 SetLayerPropertiesForTesting(grand_child.get(),
5993 identity_matrix,
[email protected]a2566412014-06-05 03:14:205994 gfx::Point3F(),
[email protected]c0ae06c12013-06-24 18:32:195995 gfx::PointF(),
5996 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:575997 true,
[email protected]c0ae06c12013-06-24 18:32:195998 false);
5999 grand_child->SetIsDrawable(true);
6000
6001 child->AddChild(grand_child);
6002 root->AddChild(child);
6003
enne2097cab2014-09-25 20:16:316004 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286005 host->SetRootLayer(root);
6006
[email protected]989386c2013-07-18 21:37:236007 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536008 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226009 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536010 inputs.can_adjust_raster_scales = true;
6011 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196012
6013 // We should have one render surface and one layers. The child has
6014 // hidden itself and the grand child.
6015 ASSERT_EQ(1u, render_surface_layer_list.size());
6016 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236017 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:196018}
6019
[email protected]989386c2013-07-18 21:37:236020TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) {
[email protected]c0ae06c12013-06-24 18:32:196021 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456022 TestSharedBitmapManager shared_bitmap_manager;
6023 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]c0ae06c12013-06-24 18:32:196024 host_impl.CreatePendingTree();
6025 const gfx::Transform identity_matrix;
6026
6027 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1);
awoloszyne83f28c2014-12-22 15:40:006028 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(),
6029 gfx::PointF(), gfx::Size(50, 50), true, false,
6030 true);
[email protected]c0ae06c12013-06-24 18:32:196031 root->SetDrawsContent(true);
6032
6033 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.pending_tree(), 2);
awoloszyne83f28c2014-12-22 15:40:006034 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(),
6035 gfx::PointF(), gfx::Size(40, 40), true, false,
[email protected]c0ae06c12013-06-24 18:32:196036 false);
6037 child->SetDrawsContent(true);
6038 child->SetHideLayerAndSubtree(true);
6039
6040 scoped_ptr<LayerImpl> grand_child =
6041 LayerImpl::Create(host_impl.pending_tree(), 3);
awoloszyne83f28c2014-12-22 15:40:006042 SetLayerPropertiesForTesting(grand_child.get(), identity_matrix,
6043 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6044 true, false, false);
[email protected]c0ae06c12013-06-24 18:32:196045 grand_child->SetDrawsContent(true);
6046
6047 child->AddChild(grand_child.Pass());
6048 root->AddChild(child.Pass());
6049
6050 LayerImplList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536051 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226052 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536053 inputs.can_adjust_raster_scales = true;
6054 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]c0ae06c12013-06-24 18:32:196055
6056 // We should have one render surface and one layers. The child has
6057 // hidden itself and the grand child.
6058 ASSERT_EQ(1u, render_surface_layer_list.size());
6059 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236060 EXPECT_EQ(1, root->render_surface()->layer_list().at(0)->id());
[email protected]c0ae06c12013-06-24 18:32:196061}
6062
[email protected]30fe19ff2013-07-04 00:54:456063void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}
6064
[email protected]989386c2013-07-18 21:37:236065TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:456066 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456067 TestSharedBitmapManager shared_bitmap_manager;
6068 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:456069 host_impl.CreatePendingTree();
6070 const gfx::Transform identity_matrix;
6071
6072 scoped_refptr<Layer> root = Layer::Create();
6073 SetLayerPropertiesForTesting(root.get(),
6074 identity_matrix,
[email protected]a2566412014-06-05 03:14:206075 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456076 gfx::PointF(),
6077 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576078 true,
[email protected]30fe19ff2013-07-04 00:54:456079 false);
6080 root->SetIsDrawable(true);
6081
6082 scoped_refptr<Layer> copy_grand_parent = Layer::Create();
6083 SetLayerPropertiesForTesting(copy_grand_parent.get(),
6084 identity_matrix,
[email protected]a2566412014-06-05 03:14:206085 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456086 gfx::PointF(),
6087 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576088 true,
[email protected]30fe19ff2013-07-04 00:54:456089 false);
6090 copy_grand_parent->SetIsDrawable(true);
6091
6092 scoped_refptr<Layer> copy_parent = Layer::Create();
6093 SetLayerPropertiesForTesting(copy_parent.get(),
6094 identity_matrix,
[email protected]a2566412014-06-05 03:14:206095 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456096 gfx::PointF(),
6097 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576098 true,
[email protected]30fe19ff2013-07-04 00:54:456099 false);
6100 copy_parent->SetIsDrawable(true);
6101 copy_parent->SetForceRenderSurface(true);
6102
6103 scoped_refptr<Layer> copy_layer = Layer::Create();
6104 SetLayerPropertiesForTesting(copy_layer.get(),
6105 identity_matrix,
[email protected]a2566412014-06-05 03:14:206106 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456107 gfx::PointF(),
6108 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576109 true,
[email protected]30fe19ff2013-07-04 00:54:456110 false);
6111 copy_layer->SetIsDrawable(true);
6112
6113 scoped_refptr<Layer> copy_child = Layer::Create();
6114 SetLayerPropertiesForTesting(copy_child.get(),
6115 identity_matrix,
[email protected]a2566412014-06-05 03:14:206116 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456117 gfx::PointF(),
6118 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576119 true,
[email protected]30fe19ff2013-07-04 00:54:456120 false);
6121 copy_child->SetIsDrawable(true);
6122
[email protected]ac020122013-07-12 23:45:536123 scoped_refptr<Layer> copy_grand_parent_sibling_before = Layer::Create();
6124 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before.get(),
6125 identity_matrix,
[email protected]a2566412014-06-05 03:14:206126 gfx::Point3F(),
[email protected]ac020122013-07-12 23:45:536127 gfx::PointF(),
6128 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576129 true,
[email protected]ac020122013-07-12 23:45:536130 false);
6131 copy_grand_parent_sibling_before->SetIsDrawable(true);
6132
6133 scoped_refptr<Layer> copy_grand_parent_sibling_after = Layer::Create();
6134 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after.get(),
6135 identity_matrix,
[email protected]a2566412014-06-05 03:14:206136 gfx::Point3F(),
[email protected]ac020122013-07-12 23:45:536137 gfx::PointF(),
6138 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576139 true,
[email protected]ac020122013-07-12 23:45:536140 false);
6141 copy_grand_parent_sibling_after->SetIsDrawable(true);
6142
[email protected]30fe19ff2013-07-04 00:54:456143 copy_layer->AddChild(copy_child);
6144 copy_parent->AddChild(copy_layer);
6145 copy_grand_parent->AddChild(copy_parent);
[email protected]ac020122013-07-12 23:45:536146 root->AddChild(copy_grand_parent_sibling_before);
[email protected]30fe19ff2013-07-04 00:54:456147 root->AddChild(copy_grand_parent);
[email protected]ac020122013-07-12 23:45:536148 root->AddChild(copy_grand_parent_sibling_after);
[email protected]30fe19ff2013-07-04 00:54:456149
enne2097cab2014-09-25 20:16:316150 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286151 host->SetRootLayer(root);
6152
[email protected]30fe19ff2013-07-04 00:54:456153 // Hide the copy_grand_parent and its subtree. But make a copy request in that
6154 // hidden subtree on copy_layer.
6155 copy_grand_parent->SetHideLayerAndSubtree(true);
[email protected]ac020122013-07-12 23:45:536156 copy_grand_parent_sibling_before->SetHideLayerAndSubtree(true);
6157 copy_grand_parent_sibling_after->SetHideLayerAndSubtree(true);
[email protected]30fe19ff2013-07-04 00:54:456158 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6159 base::Bind(&EmptyCopyOutputCallback)));
6160 EXPECT_TRUE(copy_layer->HasCopyRequest());
6161
[email protected]989386c2013-07-18 21:37:236162 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536163 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226164 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536165 inputs.can_adjust_raster_scales = true;
6166 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:456167
[email protected]ac020122013-07-12 23:45:536168 EXPECT_TRUE(root->draw_properties().layer_or_descendant_has_copy_request);
6169 EXPECT_TRUE(copy_grand_parent->draw_properties().
6170 layer_or_descendant_has_copy_request);
6171 EXPECT_TRUE(copy_parent->draw_properties().
6172 layer_or_descendant_has_copy_request);
6173 EXPECT_TRUE(copy_layer->draw_properties().
6174 layer_or_descendant_has_copy_request);
6175 EXPECT_FALSE(copy_child->draw_properties().
6176 layer_or_descendant_has_copy_request);
6177 EXPECT_FALSE(copy_grand_parent_sibling_before->draw_properties().
6178 layer_or_descendant_has_copy_request);
6179 EXPECT_FALSE(copy_grand_parent_sibling_after->draw_properties().
6180 layer_or_descendant_has_copy_request);
6181
[email protected]30fe19ff2013-07-04 00:54:456182 // We should have three render surfaces, one for the root, one for the parent
6183 // since it owns a surface, and one for the copy_layer.
6184 ASSERT_EQ(3u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:236185 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
6186 EXPECT_EQ(copy_parent->id(), render_surface_layer_list.at(1)->id());
6187 EXPECT_EQ(copy_layer->id(), render_surface_layer_list.at(2)->id());
[email protected]30fe19ff2013-07-04 00:54:456188
6189 // The root render surface should have 2 contributing layers. The
[email protected]ac020122013-07-12 23:45:536190 // copy_grand_parent is hidden along with its siblings, but the copy_parent
6191 // will appear since something in its subtree needs to be drawn for a copy
6192 // request.
[email protected]30fe19ff2013-07-04 00:54:456193 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236194 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
6195 EXPECT_EQ(copy_parent->id(),
6196 root->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:456197
[email protected]7392c7b2014-02-07 08:28:286198 // Nothing actually draws into the copy parent, so only the copy_layer will
[email protected]30fe19ff2013-07-04 00:54:456199 // appear in its list, since it needs to be drawn for the copy request.
6200 ASSERT_EQ(1u, copy_parent->render_surface()->layer_list().size());
6201 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:236202 copy_parent->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456203
6204 // The copy_layer's render surface should have two contributing layers.
6205 ASSERT_EQ(2u, copy_layer->render_surface()->layer_list().size());
6206 EXPECT_EQ(copy_layer->id(),
[email protected]989386c2013-07-18 21:37:236207 copy_layer->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456208 EXPECT_EQ(copy_child->id(),
[email protected]989386c2013-07-18 21:37:236209 copy_layer->render_surface()->layer_list().at(1)->id());
[email protected]30fe19ff2013-07-04 00:54:456210}
6211
[email protected]989386c2013-07-18 21:37:236212TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) {
[email protected]30fe19ff2013-07-04 00:54:456213 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456214 TestSharedBitmapManager shared_bitmap_manager;
6215 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]30fe19ff2013-07-04 00:54:456216 host_impl.CreatePendingTree();
6217 const gfx::Transform identity_matrix;
6218
6219 scoped_refptr<Layer> root = Layer::Create();
6220 SetLayerPropertiesForTesting(root.get(),
6221 identity_matrix,
[email protected]a2566412014-06-05 03:14:206222 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456223 gfx::PointF(),
6224 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576225 true,
[email protected]30fe19ff2013-07-04 00:54:456226 false);
6227 root->SetIsDrawable(true);
6228
6229 scoped_refptr<Layer> copy_parent = Layer::Create();
6230 SetLayerPropertiesForTesting(copy_parent.get(),
6231 identity_matrix,
[email protected]a2566412014-06-05 03:14:206232 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456233 gfx::PointF(),
6234 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576235 true,
[email protected]30fe19ff2013-07-04 00:54:456236 false);
6237 copy_parent->SetIsDrawable(true);
6238 copy_parent->SetMasksToBounds(true);
6239
6240 scoped_refptr<Layer> copy_layer = Layer::Create();
6241 SetLayerPropertiesForTesting(copy_layer.get(),
6242 identity_matrix,
[email protected]a2566412014-06-05 03:14:206243 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456244 gfx::PointF(),
6245 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576246 true,
[email protected]30fe19ff2013-07-04 00:54:456247 false);
6248 copy_layer->SetIsDrawable(true);
6249
6250 scoped_refptr<Layer> copy_child = Layer::Create();
6251 SetLayerPropertiesForTesting(copy_child.get(),
6252 identity_matrix,
[email protected]a2566412014-06-05 03:14:206253 gfx::Point3F(),
[email protected]30fe19ff2013-07-04 00:54:456254 gfx::PointF(),
6255 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576256 true,
[email protected]30fe19ff2013-07-04 00:54:456257 false);
6258 copy_child->SetIsDrawable(true);
6259
6260 copy_layer->AddChild(copy_child);
6261 copy_parent->AddChild(copy_layer);
6262 root->AddChild(copy_parent);
6263
enne2097cab2014-09-25 20:16:316264 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286265 host->SetRootLayer(root);
6266
[email protected]30fe19ff2013-07-04 00:54:456267 copy_layer->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6268 base::Bind(&EmptyCopyOutputCallback)));
6269 EXPECT_TRUE(copy_layer->HasCopyRequest());
6270
[email protected]989386c2013-07-18 21:37:236271 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536272 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226273 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536274 inputs.can_adjust_raster_scales = true;
6275 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]30fe19ff2013-07-04 00:54:456276
6277 // We should have one render surface, as the others are clipped out.
6278 ASSERT_EQ(1u, render_surface_layer_list.size());
[email protected]989386c2013-07-18 21:37:236279 EXPECT_EQ(root->id(), render_surface_layer_list.at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456280
6281 // The root render surface should only have 1 contributing layer, since the
6282 // other layers are empty/clipped away.
6283 ASSERT_EQ(1u, root->render_surface()->layer_list().size());
[email protected]989386c2013-07-18 21:37:236284 EXPECT_EQ(root->id(), root->render_surface()->layer_list().at(0)->id());
[email protected]30fe19ff2013-07-04 00:54:456285}
6286
[email protected]11a07b102013-07-24 17:33:196287TEST_F(LayerTreeHostCommonTest, VisibleContentRectInsideSurface) {
6288 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456289 TestSharedBitmapManager shared_bitmap_manager;
6290 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]11a07b102013-07-24 17:33:196291 host_impl.CreatePendingTree();
6292 const gfx::Transform identity_matrix;
6293
6294 scoped_refptr<Layer> root = Layer::Create();
6295 SetLayerPropertiesForTesting(root.get(),
6296 identity_matrix,
[email protected]a2566412014-06-05 03:14:206297 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196298 gfx::PointF(),
6299 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576300 true,
[email protected]11a07b102013-07-24 17:33:196301 false);
6302 root->SetIsDrawable(true);
6303
6304 // The surface is moved slightly outside of the viewport.
6305 scoped_refptr<Layer> surface = Layer::Create();
6306 SetLayerPropertiesForTesting(surface.get(),
6307 identity_matrix,
[email protected]a2566412014-06-05 03:14:206308 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196309 gfx::PointF(-10, -20),
6310 gfx::Size(),
[email protected]56fffdd2014-02-11 19:50:576311 true,
[email protected]11a07b102013-07-24 17:33:196312 false);
6313 surface->SetForceRenderSurface(true);
6314
6315 scoped_refptr<Layer> surface_child = Layer::Create();
6316 SetLayerPropertiesForTesting(surface_child.get(),
6317 identity_matrix,
[email protected]a2566412014-06-05 03:14:206318 gfx::Point3F(),
[email protected]11a07b102013-07-24 17:33:196319 gfx::PointF(),
6320 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576321 true,
[email protected]11a07b102013-07-24 17:33:196322 false);
6323 surface_child->SetIsDrawable(true);
6324
6325 surface->AddChild(surface_child);
6326 root->AddChild(surface);
6327
enne2097cab2014-09-25 20:16:316328 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]d600df7d2013-08-03 02:34:286329 host->SetRootLayer(root);
6330
[email protected]11a07b102013-07-24 17:33:196331 RenderSurfaceLayerList render_surface_layer_list;
[email protected]7aad55f2013-07-26 11:25:536332 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226333 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]7aad55f2013-07-26 11:25:536334 inputs.can_adjust_raster_scales = true;
6335 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]11a07b102013-07-24 17:33:196336
6337 // The visible_content_rect for the |surface_child| should not be clipped by
6338 // the viewport.
6339 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
6340 surface_child->visible_content_rect().ToString());
6341}
6342
[email protected]420fdf6e2013-08-26 20:36:386343TEST_F(LayerTreeHostCommonTest, TransformedClipParent) {
6344 // Ensure that a transform between the layer and its render surface is not a
6345 // problem. Constructs the following layer tree.
6346 //
6347 // root (a render surface)
6348 // + render_surface
6349 // + clip_parent (scaled)
6350 // + intervening_clipping_layer
6351 // + clip_child
6352 //
6353 // The render surface should be resized correctly and the clip child should
6354 // inherit the right clip rect.
6355 scoped_refptr<Layer> root = Layer::Create();
6356 scoped_refptr<Layer> render_surface = Layer::Create();
6357 scoped_refptr<Layer> clip_parent = Layer::Create();
6358 scoped_refptr<Layer> intervening = Layer::Create();
6359 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6360 make_scoped_refptr(new LayerWithForcedDrawsContent);
6361
6362 root->AddChild(render_surface);
6363 render_surface->AddChild(clip_parent);
6364 clip_parent->AddChild(intervening);
6365 intervening->AddChild(clip_child);
6366
6367 clip_child->SetClipParent(clip_parent.get());
6368
6369 intervening->SetMasksToBounds(true);
6370 clip_parent->SetMasksToBounds(true);
6371
6372 render_surface->SetForceRenderSurface(true);
6373
6374 gfx::Transform scale_transform;
6375 scale_transform.Scale(2, 2);
6376
6377 gfx::Transform identity_transform;
6378
6379 SetLayerPropertiesForTesting(root.get(),
6380 identity_transform,
[email protected]a2566412014-06-05 03:14:206381 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386382 gfx::PointF(),
6383 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576384 true,
[email protected]420fdf6e2013-08-26 20:36:386385 false);
6386 SetLayerPropertiesForTesting(render_surface.get(),
6387 identity_transform,
[email protected]a2566412014-06-05 03:14:206388 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386389 gfx::PointF(),
6390 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576391 true,
[email protected]420fdf6e2013-08-26 20:36:386392 false);
6393 SetLayerPropertiesForTesting(clip_parent.get(),
6394 scale_transform,
[email protected]a2566412014-06-05 03:14:206395 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386396 gfx::PointF(1.f, 1.f),
6397 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576398 true,
[email protected]420fdf6e2013-08-26 20:36:386399 false);
6400 SetLayerPropertiesForTesting(intervening.get(),
6401 identity_transform,
[email protected]a2566412014-06-05 03:14:206402 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386403 gfx::PointF(1.f, 1.f),
6404 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576405 true,
[email protected]420fdf6e2013-08-26 20:36:386406 false);
6407 SetLayerPropertiesForTesting(clip_child.get(),
6408 identity_transform,
[email protected]a2566412014-06-05 03:14:206409 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386410 gfx::PointF(1.f, 1.f),
6411 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576412 true,
[email protected]420fdf6e2013-08-26 20:36:386413 false);
6414
enne2097cab2014-09-25 20:16:316415 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386416 host->SetRootLayer(root);
6417
6418 ExecuteCalculateDrawProperties(root.get());
6419
6420 ASSERT_TRUE(root->render_surface());
6421 ASSERT_TRUE(render_surface->render_surface());
6422
6423 // Ensure that we've inherited our clip parent's clip and weren't affected
6424 // by the intervening clip layer.
6425 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
6426 clip_parent->clip_rect().ToString());
6427 ASSERT_EQ(clip_parent->clip_rect().ToString(),
6428 clip_child->clip_rect().ToString());
6429 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
6430 intervening->clip_rect().ToString());
6431
6432 // Ensure that the render surface reports a content rect that has been grown
6433 // to accomodate for the clip child.
6434 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
6435 render_surface->render_surface()->content_rect().ToString());
6436
6437 // The above check implies the two below, but they nicely demonstrate that
6438 // we've grown, despite the intervening layer's clip.
6439 ASSERT_TRUE(clip_parent->clip_rect().Contains(
6440 render_surface->render_surface()->content_rect()));
6441 ASSERT_FALSE(intervening->clip_rect().Contains(
6442 render_surface->render_surface()->content_rect()));
6443}
6444
6445TEST_F(LayerTreeHostCommonTest, ClipParentWithInterveningRenderSurface) {
6446 // Ensure that intervening render surfaces are not a problem in the basic
6447 // case. In the following tree, both render surfaces should be resized to
6448 // accomodate for the clip child, despite an intervening clip.
6449 //
6450 // root (a render surface)
6451 // + clip_parent (masks to bounds)
6452 // + render_surface1 (sets opacity)
6453 // + intervening (masks to bounds)
6454 // + render_surface2 (also sets opacity)
6455 // + clip_child
6456 //
6457 scoped_refptr<Layer> root = Layer::Create();
6458 scoped_refptr<Layer> clip_parent = Layer::Create();
6459 scoped_refptr<Layer> render_surface1 = Layer::Create();
6460 scoped_refptr<Layer> intervening = Layer::Create();
6461 scoped_refptr<Layer> render_surface2 = Layer::Create();
6462 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6463 make_scoped_refptr(new LayerWithForcedDrawsContent);
6464
6465 root->AddChild(clip_parent);
6466 clip_parent->AddChild(render_surface1);
6467 render_surface1->AddChild(intervening);
6468 intervening->AddChild(render_surface2);
6469 render_surface2->AddChild(clip_child);
6470
6471 clip_child->SetClipParent(clip_parent.get());
6472
6473 intervening->SetMasksToBounds(true);
6474 clip_parent->SetMasksToBounds(true);
6475
6476 render_surface1->SetForceRenderSurface(true);
6477 render_surface2->SetForceRenderSurface(true);
6478
6479 gfx::Transform translation_transform;
6480 translation_transform.Translate(2, 2);
6481
6482 gfx::Transform identity_transform;
6483 SetLayerPropertiesForTesting(root.get(),
6484 identity_transform,
[email protected]a2566412014-06-05 03:14:206485 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386486 gfx::PointF(),
6487 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576488 true,
[email protected]420fdf6e2013-08-26 20:36:386489 false);
6490 SetLayerPropertiesForTesting(clip_parent.get(),
6491 translation_transform,
[email protected]a2566412014-06-05 03:14:206492 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386493 gfx::PointF(1.f, 1.f),
6494 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576495 true,
[email protected]420fdf6e2013-08-26 20:36:386496 false);
6497 SetLayerPropertiesForTesting(render_surface1.get(),
6498 identity_transform,
[email protected]a2566412014-06-05 03:14:206499 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386500 gfx::PointF(),
6501 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576502 true,
[email protected]420fdf6e2013-08-26 20:36:386503 false);
6504 SetLayerPropertiesForTesting(intervening.get(),
6505 identity_transform,
[email protected]a2566412014-06-05 03:14:206506 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386507 gfx::PointF(1.f, 1.f),
6508 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576509 true,
[email protected]420fdf6e2013-08-26 20:36:386510 false);
6511 SetLayerPropertiesForTesting(render_surface2.get(),
6512 identity_transform,
[email protected]a2566412014-06-05 03:14:206513 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386514 gfx::PointF(),
6515 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576516 true,
[email protected]420fdf6e2013-08-26 20:36:386517 false);
6518 SetLayerPropertiesForTesting(clip_child.get(),
6519 identity_transform,
[email protected]a2566412014-06-05 03:14:206520 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386521 gfx::PointF(-10.f, -10.f),
6522 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576523 true,
[email protected]420fdf6e2013-08-26 20:36:386524 false);
6525
enne2097cab2014-09-25 20:16:316526 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386527 host->SetRootLayer(root);
6528
6529 ExecuteCalculateDrawProperties(root.get());
6530
6531 EXPECT_TRUE(root->render_surface());
6532 EXPECT_TRUE(render_surface1->render_surface());
6533 EXPECT_TRUE(render_surface2->render_surface());
6534
6535 // Since the render surfaces could have expanded, they should not clip (their
6536 // bounds would no longer be reliable). We should resort to layer clipping
6537 // in this case.
6538 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6539 render_surface1->render_surface()->clip_rect().ToString());
6540 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6541 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6542 render_surface2->render_surface()->clip_rect().ToString());
6543 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6544
6545 // NB: clip rects are in target space.
6546 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6547 render_surface1->clip_rect().ToString());
6548 EXPECT_TRUE(render_surface1->is_clipped());
6549
6550 // This value is inherited from the clipping ancestor layer, 'intervening'.
6551 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6552 render_surface2->clip_rect().ToString());
6553 EXPECT_TRUE(render_surface2->is_clipped());
6554
6555 // The content rects of both render surfaces should both have expanded to
6556 // contain the clip child.
6557 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6558 render_surface1->render_surface()->content_rect().ToString());
6559 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6560 render_surface2->render_surface()->content_rect().ToString());
6561
6562 // The clip child should have inherited the clip parent's clip (projected to
6563 // the right space, of course), and should have the correctly sized visible
6564 // content rect.
6565 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6566 clip_child->clip_rect().ToString());
6567 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
6568 clip_child->visible_content_rect().ToString());
6569 EXPECT_TRUE(clip_child->is_clipped());
6570}
6571
6572TEST_F(LayerTreeHostCommonTest, ClipParentScrolledInterveningLayer) {
6573 // Ensure that intervening render surfaces are not a problem, even if there
6574 // is a scroll involved. Note, we do _not_ have to consider any other sort
6575 // of transform.
6576 //
6577 // root (a render surface)
6578 // + clip_parent (masks to bounds)
6579 // + render_surface1 (sets opacity)
6580 // + intervening (masks to bounds AND scrolls)
6581 // + render_surface2 (also sets opacity)
6582 // + clip_child
6583 //
6584 scoped_refptr<Layer> root = Layer::Create();
6585 scoped_refptr<Layer> clip_parent = Layer::Create();
6586 scoped_refptr<Layer> render_surface1 = Layer::Create();
6587 scoped_refptr<Layer> intervening = Layer::Create();
6588 scoped_refptr<Layer> render_surface2 = Layer::Create();
6589 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6590 make_scoped_refptr(new LayerWithForcedDrawsContent);
6591
6592 root->AddChild(clip_parent);
6593 clip_parent->AddChild(render_surface1);
6594 render_surface1->AddChild(intervening);
6595 intervening->AddChild(render_surface2);
6596 render_surface2->AddChild(clip_child);
6597
6598 clip_child->SetClipParent(clip_parent.get());
6599
6600 intervening->SetMasksToBounds(true);
6601 clip_parent->SetMasksToBounds(true);
[email protected]adeda572014-01-31 00:49:476602 intervening->SetScrollClipLayerId(clip_parent->id());
miletusf57925d2014-10-01 19:38:136603 intervening->SetScrollOffset(gfx::ScrollOffset(3, 3));
[email protected]420fdf6e2013-08-26 20:36:386604
6605 render_surface1->SetForceRenderSurface(true);
6606 render_surface2->SetForceRenderSurface(true);
6607
6608 gfx::Transform translation_transform;
6609 translation_transform.Translate(2, 2);
6610
6611 gfx::Transform identity_transform;
6612 SetLayerPropertiesForTesting(root.get(),
6613 identity_transform,
[email protected]a2566412014-06-05 03:14:206614 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386615 gfx::PointF(),
6616 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576617 true,
[email protected]420fdf6e2013-08-26 20:36:386618 false);
6619 SetLayerPropertiesForTesting(clip_parent.get(),
6620 translation_transform,
[email protected]a2566412014-06-05 03:14:206621 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386622 gfx::PointF(1.f, 1.f),
6623 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576624 true,
[email protected]420fdf6e2013-08-26 20:36:386625 false);
6626 SetLayerPropertiesForTesting(render_surface1.get(),
6627 identity_transform,
[email protected]a2566412014-06-05 03:14:206628 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386629 gfx::PointF(),
6630 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576631 true,
[email protected]420fdf6e2013-08-26 20:36:386632 false);
6633 SetLayerPropertiesForTesting(intervening.get(),
6634 identity_transform,
[email protected]a2566412014-06-05 03:14:206635 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386636 gfx::PointF(1.f, 1.f),
6637 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576638 true,
[email protected]420fdf6e2013-08-26 20:36:386639 false);
6640 SetLayerPropertiesForTesting(render_surface2.get(),
6641 identity_transform,
[email protected]a2566412014-06-05 03:14:206642 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386643 gfx::PointF(),
6644 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576645 true,
[email protected]420fdf6e2013-08-26 20:36:386646 false);
6647 SetLayerPropertiesForTesting(clip_child.get(),
6648 identity_transform,
[email protected]a2566412014-06-05 03:14:206649 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386650 gfx::PointF(-10.f, -10.f),
6651 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576652 true,
[email protected]420fdf6e2013-08-26 20:36:386653 false);
6654
enne2097cab2014-09-25 20:16:316655 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386656 host->SetRootLayer(root);
6657
6658 ExecuteCalculateDrawProperties(root.get());
6659
6660 EXPECT_TRUE(root->render_surface());
6661 EXPECT_TRUE(render_surface1->render_surface());
6662 EXPECT_TRUE(render_surface2->render_surface());
6663
6664 // Since the render surfaces could have expanded, they should not clip (their
6665 // bounds would no longer be reliable). We should resort to layer clipping
6666 // in this case.
6667 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6668 render_surface1->render_surface()->clip_rect().ToString());
6669 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6670 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6671 render_surface2->render_surface()->clip_rect().ToString());
6672 EXPECT_FALSE(render_surface2->render_surface()->is_clipped());
6673
6674 // NB: clip rects are in target space.
6675 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6676 render_surface1->clip_rect().ToString());
6677 EXPECT_TRUE(render_surface1->is_clipped());
6678
6679 // This value is inherited from the clipping ancestor layer, 'intervening'.
6680 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6681 render_surface2->clip_rect().ToString());
6682 EXPECT_TRUE(render_surface2->is_clipped());
6683
6684 // The content rects of both render surfaces should both have expanded to
6685 // contain the clip child.
6686 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6687 render_surface1->render_surface()->content_rect().ToString());
6688 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6689 render_surface2->render_surface()->content_rect().ToString());
6690
6691 // The clip child should have inherited the clip parent's clip (projected to
6692 // the right space, of course), and should have the correctly sized visible
6693 // content rect.
6694 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6695 clip_child->clip_rect().ToString());
6696 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6697 clip_child->visible_content_rect().ToString());
6698 EXPECT_TRUE(clip_child->is_clipped());
6699}
6700
6701TEST_F(LayerTreeHostCommonTest, DescendantsOfClipChildren) {
6702 // Ensures that descendants of the clip child inherit the correct clip.
6703 //
6704 // root (a render surface)
6705 // + clip_parent (masks to bounds)
6706 // + intervening (masks to bounds)
6707 // + clip_child
6708 // + child
6709 //
6710 scoped_refptr<Layer> root = Layer::Create();
6711 scoped_refptr<Layer> clip_parent = Layer::Create();
6712 scoped_refptr<Layer> intervening = Layer::Create();
6713 scoped_refptr<Layer> clip_child = Layer::Create();
6714 scoped_refptr<LayerWithForcedDrawsContent> child =
6715 make_scoped_refptr(new LayerWithForcedDrawsContent);
6716
6717 root->AddChild(clip_parent);
6718 clip_parent->AddChild(intervening);
6719 intervening->AddChild(clip_child);
6720 clip_child->AddChild(child);
6721
6722 clip_child->SetClipParent(clip_parent.get());
6723
6724 intervening->SetMasksToBounds(true);
6725 clip_parent->SetMasksToBounds(true);
6726
6727 gfx::Transform identity_transform;
6728 SetLayerPropertiesForTesting(root.get(),
6729 identity_transform,
[email protected]a2566412014-06-05 03:14:206730 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386731 gfx::PointF(),
6732 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576733 true,
[email protected]420fdf6e2013-08-26 20:36:386734 false);
6735 SetLayerPropertiesForTesting(clip_parent.get(),
6736 identity_transform,
[email protected]a2566412014-06-05 03:14:206737 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386738 gfx::PointF(),
6739 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:576740 true,
[email protected]420fdf6e2013-08-26 20:36:386741 false);
6742 SetLayerPropertiesForTesting(intervening.get(),
6743 identity_transform,
[email protected]a2566412014-06-05 03:14:206744 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386745 gfx::PointF(),
6746 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576747 true,
[email protected]420fdf6e2013-08-26 20:36:386748 false);
6749 SetLayerPropertiesForTesting(clip_child.get(),
6750 identity_transform,
[email protected]a2566412014-06-05 03:14:206751 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386752 gfx::PointF(),
6753 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576754 true,
[email protected]420fdf6e2013-08-26 20:36:386755 false);
6756 SetLayerPropertiesForTesting(child.get(),
6757 identity_transform,
[email protected]a2566412014-06-05 03:14:206758 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386759 gfx::PointF(),
6760 gfx::Size(60, 60),
[email protected]56fffdd2014-02-11 19:50:576761 true,
[email protected]420fdf6e2013-08-26 20:36:386762 false);
6763
enne2097cab2014-09-25 20:16:316764 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386765 host->SetRootLayer(root);
6766
6767 ExecuteCalculateDrawProperties(root.get());
6768
6769 EXPECT_TRUE(root->render_surface());
6770
6771 // Neither the clip child nor its descendant should have inherited the clip
6772 // from |intervening|.
6773 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6774 clip_child->clip_rect().ToString());
6775 EXPECT_TRUE(clip_child->is_clipped());
6776 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6777 child->visible_content_rect().ToString());
6778 EXPECT_TRUE(child->is_clipped());
6779}
6780
6781TEST_F(LayerTreeHostCommonTest,
6782 SurfacesShouldBeUnaffectedByNonDescendantClipChildren) {
6783 // Ensures that non-descendant clip children in the tree do not affect
6784 // render surfaces.
6785 //
6786 // root (a render surface)
6787 // + clip_parent (masks to bounds)
6788 // + render_surface1
6789 // + clip_child
6790 // + render_surface2
6791 // + non_clip_child
6792 //
6793 // In this example render_surface2 should be unaffected by clip_child.
6794 scoped_refptr<Layer> root = Layer::Create();
6795 scoped_refptr<Layer> clip_parent = Layer::Create();
6796 scoped_refptr<Layer> render_surface1 = Layer::Create();
6797 scoped_refptr<LayerWithForcedDrawsContent> clip_child =
6798 make_scoped_refptr(new LayerWithForcedDrawsContent);
6799 scoped_refptr<Layer> render_surface2 = Layer::Create();
6800 scoped_refptr<LayerWithForcedDrawsContent> non_clip_child =
6801 make_scoped_refptr(new LayerWithForcedDrawsContent);
6802
6803 root->AddChild(clip_parent);
6804 clip_parent->AddChild(render_surface1);
6805 render_surface1->AddChild(clip_child);
6806 clip_parent->AddChild(render_surface2);
6807 render_surface2->AddChild(non_clip_child);
6808
6809 clip_child->SetClipParent(clip_parent.get());
6810
6811 clip_parent->SetMasksToBounds(true);
6812 render_surface1->SetMasksToBounds(true);
6813
6814 gfx::Transform identity_transform;
6815 SetLayerPropertiesForTesting(root.get(),
6816 identity_transform,
[email protected]a2566412014-06-05 03:14:206817 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386818 gfx::PointF(),
6819 gfx::Size(15, 15),
[email protected]56fffdd2014-02-11 19:50:576820 true,
[email protected]420fdf6e2013-08-26 20:36:386821 false);
6822 SetLayerPropertiesForTesting(clip_parent.get(),
6823 identity_transform,
[email protected]a2566412014-06-05 03:14:206824 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386825 gfx::PointF(),
6826 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576827 true,
[email protected]420fdf6e2013-08-26 20:36:386828 false);
6829 SetLayerPropertiesForTesting(render_surface1.get(),
6830 identity_transform,
[email protected]a2566412014-06-05 03:14:206831 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386832 gfx::PointF(5, 5),
6833 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576834 true,
[email protected]420fdf6e2013-08-26 20:36:386835 false);
6836 SetLayerPropertiesForTesting(render_surface2.get(),
6837 identity_transform,
[email protected]a2566412014-06-05 03:14:206838 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386839 gfx::PointF(),
6840 gfx::Size(5, 5),
[email protected]56fffdd2014-02-11 19:50:576841 true,
[email protected]420fdf6e2013-08-26 20:36:386842 false);
6843 SetLayerPropertiesForTesting(clip_child.get(),
6844 identity_transform,
[email protected]a2566412014-06-05 03:14:206845 gfx::Point3F(),
[email protected]420fdf6e2013-08-26 20:36:386846 gfx::PointF(-1, 1),
6847 gfx::Size(10, 10),
[email protected]56fffdd2014-02-11 19:50:576848 true,
[email protected]420fdf6e2013-08-26 20:36:386849 false);
6850 SetLayerPropertiesForTesting(non_clip_child.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(5, 5),
[email protected]56fffdd2014-02-11 19:50:576855 true,
[email protected]420fdf6e2013-08-26 20:36:386856 false);
6857
6858 render_surface1->SetForceRenderSurface(true);
6859 render_surface2->SetForceRenderSurface(true);
6860
enne2097cab2014-09-25 20:16:316861 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]420fdf6e2013-08-26 20:36:386862 host->SetRootLayer(root);
6863
6864 ExecuteCalculateDrawProperties(root.get());
6865
6866 EXPECT_TRUE(root->render_surface());
6867 EXPECT_TRUE(render_surface1->render_surface());
6868 EXPECT_TRUE(render_surface2->render_surface());
6869
6870 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6871 render_surface1->clip_rect().ToString());
6872 EXPECT_TRUE(render_surface1->is_clipped());
6873
6874 // The render surface should not clip (it has unclipped descendants), instead
6875 // it should rely on layer clipping.
6876 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6877 render_surface1->render_surface()->clip_rect().ToString());
6878 EXPECT_FALSE(render_surface1->render_surface()->is_clipped());
6879
6880 // That said, it should have grown to accomodate the unclipped descendant.
6881 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
6882 render_surface1->render_surface()->content_rect().ToString());
6883
6884 // This render surface should clip. It has no unclipped descendants.
6885 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6886 render_surface2->clip_rect().ToString());
6887 EXPECT_TRUE(render_surface2->render_surface()->is_clipped());
6888
6889 // It also shouldn't have grown to accomodate the clip child.
6890 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6891 render_surface2->render_surface()->content_rect().ToString());
6892
6893 // Sanity check our num_unclipped_descendants values.
6894 EXPECT_EQ(1, render_surface1->num_unclipped_descendants());
6895 EXPECT_EQ(0, render_surface2->num_unclipped_descendants());
6896}
6897
[email protected]45948712013-09-27 02:46:486898TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) {
6899 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:456900 TestSharedBitmapManager shared_bitmap_manager;
6901 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]45948712013-09-27 02:46:486902 scoped_ptr<LayerImpl> root =
6903 LayerImpl::Create(host_impl.active_tree(), 12345);
6904 scoped_ptr<LayerImpl> child1 =
6905 LayerImpl::Create(host_impl.active_tree(), 123456);
6906 scoped_ptr<LayerImpl> child2 =
6907 LayerImpl::Create(host_impl.active_tree(), 1234567);
6908 scoped_ptr<LayerImpl> child3 =
6909 LayerImpl::Create(host_impl.active_tree(), 12345678);
6910
6911 gfx::Transform identity_matrix;
[email protected]a2566412014-06-05 03:14:206912 gfx::Point3F transform_origin;
[email protected]45948712013-09-27 02:46:486913 gfx::PointF position;
6914 gfx::Size bounds(100, 100);
awoloszyne83f28c2014-12-22 15:40:006915 SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin,
6916 position, bounds, true, false, true);
[email protected]45948712013-09-27 02:46:486917 root->SetDrawsContent(true);
6918
6919 // This layer structure normally forces render surface due to preserves3d
6920 // behavior.
awoloszyne83f28c2014-12-22 15:40:006921 SetLayerPropertiesForTesting(child1.get(), identity_matrix, transform_origin,
6922 position, bounds, false, true, true);
[email protected]45948712013-09-27 02:46:486923 child1->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:006924 SetLayerPropertiesForTesting(child2.get(), identity_matrix, transform_origin,
6925 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:486926 child2->SetDrawsContent(true);
awoloszyne83f28c2014-12-22 15:40:006927 SetLayerPropertiesForTesting(child3.get(), identity_matrix, transform_origin,
6928 position, bounds, true, false, false);
[email protected]45948712013-09-27 02:46:486929 child3->SetDrawsContent(true);
6930
[email protected]a9d4d4f2014-06-19 06:49:286931 child2->Set3dSortingContextId(1);
6932 child3->Set3dSortingContextId(1);
[email protected]56fffdd2014-02-11 19:50:576933
[email protected]45948712013-09-27 02:46:486934 child2->AddChild(child3.Pass());
6935 child1->AddChild(child2.Pass());
6936 root->AddChild(child1.Pass());
6937
6938 {
6939 LayerImplList render_surface_layer_list;
[email protected]ad63b2f2014-08-11 17:39:546940 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root.get());
[email protected]45948712013-09-27 02:46:486941 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226942 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:486943 inputs.can_render_to_separate_surface = true;
6944 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6945
6946 EXPECT_EQ(2u, render_surface_layer_list.size());
6947 }
6948
6949 {
6950 LayerImplList render_surface_layer_list;
6951 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:226952 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]45948712013-09-27 02:46:486953 inputs.can_render_to_separate_surface = false;
6954 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
6955
6956 EXPECT_EQ(1u, render_surface_layer_list.size());
6957 }
6958}
6959
[email protected]a9aa60a82013-08-29 04:28:266960TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) {
6961 scoped_refptr<Layer> root = Layer::Create();
6962 scoped_refptr<Layer> render_surface = Layer::Create();
6963 scoped_refptr<LayerWithForcedDrawsContent> child =
6964 make_scoped_refptr(new LayerWithForcedDrawsContent);
6965
6966 root->AddChild(render_surface);
6967 render_surface->AddChild(child);
6968
6969 gfx::Transform identity_transform;
6970 SetLayerPropertiesForTesting(root.get(),
6971 identity_transform,
[email protected]a2566412014-06-05 03:14:206972 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:266973 gfx::PointF(),
6974 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:576975 true,
[email protected]a9aa60a82013-08-29 04:28:266976 false);
6977 SetLayerPropertiesForTesting(render_surface.get(),
6978 identity_transform,
[email protected]a2566412014-06-05 03:14:206979 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:266980 gfx::PointF(),
6981 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:576982 false,
6983 true);
[email protected]a9aa60a82013-08-29 04:28:266984 SetLayerPropertiesForTesting(child.get(),
6985 identity_transform,
[email protected]a2566412014-06-05 03:14:206986 gfx::Point3F(),
[email protected]a9aa60a82013-08-29 04:28:266987 gfx::PointF(),
6988 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:576989 true,
[email protected]a9aa60a82013-08-29 04:28:266990 false);
6991
[email protected]56fffdd2014-02-11 19:50:576992 root->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:286993 root->Set3dSortingContextId(1);
[email protected]a9aa60a82013-08-29 04:28:266994 render_surface->SetDoubleSided(false);
6995 render_surface->SetForceRenderSurface(true);
6996
enne2097cab2014-09-25 20:16:316997 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]a9aa60a82013-08-29 04:28:266998 host->SetRootLayer(root);
6999
7000 ExecuteCalculateDrawProperties(root.get());
7001
7002 EXPECT_EQ(2u, render_surface_layer_list()->size());
7003 EXPECT_EQ(1u,
7004 render_surface_layer_list()->at(0)
7005 ->render_surface()->layer_list().size());
7006 EXPECT_EQ(1u,
7007 render_surface_layer_list()->at(1)
7008 ->render_surface()->layer_list().size());
7009
7010 gfx::Transform rotation_transform = identity_transform;
7011 rotation_transform.RotateAboutXAxis(180.0);
7012
7013 render_surface->SetTransform(rotation_transform);
7014
7015 ExecuteCalculateDrawProperties(root.get());
7016
7017 EXPECT_EQ(1u, render_surface_layer_list()->size());
7018 EXPECT_EQ(0u,
7019 render_surface_layer_list()->at(0)
7020 ->render_surface()->layer_list().size());
7021}
7022
[email protected]995708c52013-10-17 20:52:597023TEST_F(LayerTreeHostCommonTest, ClippedByScrollParent) {
7024 // Checks that the simple case (being clipped by a scroll parent that would
7025 // have been processed before you anyhow) results in the right clips.
7026 //
7027 // + root
7028 // + scroll_parent_border
7029 // | + scroll_parent_clip
7030 // | + scroll_parent
7031 // + scroll_child
7032 //
7033 scoped_refptr<Layer> root = Layer::Create();
7034 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7035 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7036 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7037 make_scoped_refptr(new LayerWithForcedDrawsContent);
7038 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7039 make_scoped_refptr(new LayerWithForcedDrawsContent);
7040
7041 root->AddChild(scroll_child);
7042
7043 root->AddChild(scroll_parent_border);
7044 scroll_parent_border->AddChild(scroll_parent_clip);
7045 scroll_parent_clip->AddChild(scroll_parent);
7046
7047 scroll_parent_clip->SetMasksToBounds(true);
7048
7049 scroll_child->SetScrollParent(scroll_parent.get());
7050
7051 gfx::Transform identity_transform;
7052 SetLayerPropertiesForTesting(root.get(),
7053 identity_transform,
[email protected]a2566412014-06-05 03:14:207054 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597055 gfx::PointF(),
7056 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577057 true,
[email protected]995708c52013-10-17 20:52:597058 false);
7059 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7060 identity_transform,
[email protected]a2566412014-06-05 03:14:207061 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597062 gfx::PointF(),
7063 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577064 true,
[email protected]995708c52013-10-17 20:52:597065 false);
7066 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7067 identity_transform,
[email protected]a2566412014-06-05 03:14:207068 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597069 gfx::PointF(),
7070 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577071 true,
[email protected]995708c52013-10-17 20:52:597072 false);
7073 SetLayerPropertiesForTesting(scroll_parent.get(),
7074 identity_transform,
[email protected]a2566412014-06-05 03:14:207075 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597076 gfx::PointF(),
7077 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577078 true,
[email protected]995708c52013-10-17 20:52:597079 false);
7080 SetLayerPropertiesForTesting(scroll_child.get(),
7081 identity_transform,
[email protected]a2566412014-06-05 03:14:207082 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597083 gfx::PointF(),
7084 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577085 true,
[email protected]995708c52013-10-17 20:52:597086 false);
7087
enne2097cab2014-09-25 20:16:317088 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597089 host->SetRootLayer(root);
7090
7091 ExecuteCalculateDrawProperties(root.get());
7092
7093 EXPECT_TRUE(root->render_surface());
7094
7095 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7096 scroll_child->clip_rect().ToString());
7097 EXPECT_TRUE(scroll_child->is_clipped());
7098}
7099
[email protected]08bdf1b2014-04-16 23:23:297100TEST_F(LayerTreeHostCommonTest, SingularTransformSubtreesDoNotDraw) {
7101 scoped_refptr<LayerWithForcedDrawsContent> root =
7102 make_scoped_refptr(new LayerWithForcedDrawsContent);
7103 scoped_refptr<LayerWithForcedDrawsContent> parent =
7104 make_scoped_refptr(new LayerWithForcedDrawsContent);
7105 scoped_refptr<LayerWithForcedDrawsContent> child =
7106 make_scoped_refptr(new LayerWithForcedDrawsContent);
7107
7108 root->AddChild(parent);
7109 parent->AddChild(child);
7110
7111 gfx::Transform identity_transform;
7112 SetLayerPropertiesForTesting(root.get(),
7113 identity_transform,
[email protected]a2566412014-06-05 03:14:207114 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297115 gfx::PointF(),
7116 gfx::Size(50, 50),
7117 true,
7118 true);
7119 root->SetForceRenderSurface(true);
7120 SetLayerPropertiesForTesting(parent.get(),
7121 identity_transform,
[email protected]a2566412014-06-05 03:14:207122 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297123 gfx::PointF(),
7124 gfx::Size(30, 30),
7125 true,
7126 true);
7127 parent->SetForceRenderSurface(true);
7128 SetLayerPropertiesForTesting(child.get(),
7129 identity_transform,
[email protected]a2566412014-06-05 03:14:207130 gfx::Point3F(),
[email protected]08bdf1b2014-04-16 23:23:297131 gfx::PointF(),
7132 gfx::Size(20, 20),
7133 true,
7134 true);
7135 child->SetForceRenderSurface(true);
7136
enne2097cab2014-09-25 20:16:317137 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]08bdf1b2014-04-16 23:23:297138 host->SetRootLayer(root);
7139
7140 ExecuteCalculateDrawProperties(root.get());
7141
7142 EXPECT_EQ(3u, render_surface_layer_list()->size());
7143
7144 gfx::Transform singular_transform;
7145 singular_transform.Scale3d(
7146 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
7147
7148 child->SetTransform(singular_transform);
7149
7150 ExecuteCalculateDrawProperties(root.get());
7151
7152 EXPECT_EQ(2u, render_surface_layer_list()->size());
7153
7154 // Ensure that the entire subtree under a layer with singular transform does
7155 // not get rendered.
7156 parent->SetTransform(singular_transform);
7157 child->SetTransform(identity_transform);
7158
7159 ExecuteCalculateDrawProperties(root.get());
7160
7161 EXPECT_EQ(1u, render_surface_layer_list()->size());
7162}
7163
[email protected]995708c52013-10-17 20:52:597164TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollParent) {
7165 // Checks that clipping by a scroll parent that follows you in paint order
7166 // still results in correct clipping.
7167 //
7168 // + root
7169 // + scroll_child
7170 // + scroll_parent_border
7171 // + scroll_parent_clip
7172 // + scroll_parent
7173 //
7174 scoped_refptr<Layer> root = Layer::Create();
7175 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7176 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7177 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7178 make_scoped_refptr(new LayerWithForcedDrawsContent);
7179 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7180 make_scoped_refptr(new LayerWithForcedDrawsContent);
7181
7182 root->AddChild(scroll_parent_border);
7183 scroll_parent_border->AddChild(scroll_parent_clip);
7184 scroll_parent_clip->AddChild(scroll_parent);
7185
7186 root->AddChild(scroll_child);
7187
7188 scroll_parent_clip->SetMasksToBounds(true);
7189
7190 scroll_child->SetScrollParent(scroll_parent.get());
7191
7192 gfx::Transform identity_transform;
7193 SetLayerPropertiesForTesting(root.get(),
7194 identity_transform,
[email protected]a2566412014-06-05 03:14:207195 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597196 gfx::PointF(),
7197 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577198 true,
[email protected]995708c52013-10-17 20:52:597199 false);
7200 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7201 identity_transform,
[email protected]a2566412014-06-05 03:14:207202 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597203 gfx::PointF(),
7204 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577205 true,
[email protected]995708c52013-10-17 20:52:597206 false);
7207 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7208 identity_transform,
[email protected]a2566412014-06-05 03:14:207209 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597210 gfx::PointF(),
7211 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577212 true,
[email protected]995708c52013-10-17 20:52:597213 false);
7214 SetLayerPropertiesForTesting(scroll_parent.get(),
7215 identity_transform,
[email protected]a2566412014-06-05 03:14:207216 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597217 gfx::PointF(),
7218 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577219 true,
[email protected]995708c52013-10-17 20:52:597220 false);
7221 SetLayerPropertiesForTesting(scroll_child.get(),
7222 identity_transform,
[email protected]a2566412014-06-05 03:14:207223 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597224 gfx::PointF(),
7225 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577226 true,
[email protected]995708c52013-10-17 20:52:597227 false);
7228
enne2097cab2014-09-25 20:16:317229 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597230 host->SetRootLayer(root);
7231
7232 ExecuteCalculateDrawProperties(root.get());
7233
7234 EXPECT_TRUE(root->render_surface());
7235
7236 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7237 scroll_child->clip_rect().ToString());
7238 EXPECT_TRUE(scroll_child->is_clipped());
7239}
7240
7241TEST_F(LayerTreeHostCommonTest, ClippedByOutOfOrderScrollGrandparent) {
7242 // Checks that clipping by a scroll parent and scroll grandparent that follow
7243 // you in paint order still results in correct clipping.
7244 //
7245 // + root
7246 // + scroll_child
7247 // + scroll_parent_border
7248 // | + scroll_parent_clip
7249 // | + scroll_parent
7250 // + scroll_grandparent_border
7251 // + scroll_grandparent_clip
7252 // + scroll_grandparent
7253 //
7254 scoped_refptr<Layer> root = Layer::Create();
7255 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7256 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7257 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7258 make_scoped_refptr(new LayerWithForcedDrawsContent);
7259
7260 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
7261 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
7262 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
7263 make_scoped_refptr(new LayerWithForcedDrawsContent);
7264
7265 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7266 make_scoped_refptr(new LayerWithForcedDrawsContent);
7267
7268 root->AddChild(scroll_child);
7269
7270 root->AddChild(scroll_parent_border);
7271 scroll_parent_border->AddChild(scroll_parent_clip);
7272 scroll_parent_clip->AddChild(scroll_parent);
7273
7274 root->AddChild(scroll_grandparent_border);
7275 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
7276 scroll_grandparent_clip->AddChild(scroll_grandparent);
7277
7278 scroll_parent_clip->SetMasksToBounds(true);
7279 scroll_grandparent_clip->SetMasksToBounds(true);
7280
7281 scroll_child->SetScrollParent(scroll_parent.get());
7282 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
7283
7284 gfx::Transform identity_transform;
7285 SetLayerPropertiesForTesting(root.get(),
7286 identity_transform,
[email protected]a2566412014-06-05 03:14:207287 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597288 gfx::PointF(),
7289 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577290 true,
[email protected]995708c52013-10-17 20:52:597291 false);
7292 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
7293 identity_transform,
[email protected]a2566412014-06-05 03:14:207294 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597295 gfx::PointF(),
7296 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577297 true,
[email protected]995708c52013-10-17 20:52:597298 false);
7299 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
7300 identity_transform,
[email protected]a2566412014-06-05 03:14:207301 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597302 gfx::PointF(),
7303 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577304 true,
[email protected]995708c52013-10-17 20:52:597305 false);
7306 SetLayerPropertiesForTesting(scroll_grandparent.get(),
7307 identity_transform,
[email protected]a2566412014-06-05 03:14:207308 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597309 gfx::PointF(),
7310 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577311 true,
[email protected]995708c52013-10-17 20:52:597312 false);
7313 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7314 identity_transform,
[email protected]a2566412014-06-05 03:14:207315 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597316 gfx::PointF(),
7317 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577318 true,
[email protected]995708c52013-10-17 20:52:597319 false);
7320 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7321 identity_transform,
[email protected]a2566412014-06-05 03:14:207322 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597323 gfx::PointF(),
7324 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577325 true,
[email protected]995708c52013-10-17 20:52:597326 false);
7327 SetLayerPropertiesForTesting(scroll_parent.get(),
7328 identity_transform,
[email protected]a2566412014-06-05 03:14:207329 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597330 gfx::PointF(),
7331 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577332 true,
[email protected]995708c52013-10-17 20:52:597333 false);
7334 SetLayerPropertiesForTesting(scroll_child.get(),
7335 identity_transform,
[email protected]a2566412014-06-05 03:14:207336 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597337 gfx::PointF(),
7338 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577339 true,
[email protected]995708c52013-10-17 20:52:597340 false);
7341
enne2097cab2014-09-25 20:16:317342 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597343 host->SetRootLayer(root);
7344
7345 ExecuteCalculateDrawProperties(root.get());
7346
7347 EXPECT_TRUE(root->render_surface());
7348
7349 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7350 scroll_child->clip_rect().ToString());
7351 EXPECT_TRUE(scroll_child->is_clipped());
7352
7353 // Despite the fact that we visited the above layers out of order to get the
7354 // correct clip, the layer lists should be unaffected.
7355 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
7356 EXPECT_EQ(scroll_child.get(),
Daniel Chengeea98042014-08-26 00:28:107357 root->render_surface()->layer_list().at(0).get());
[email protected]995708c52013-10-17 20:52:597358 EXPECT_EQ(scroll_parent.get(),
Daniel Chengeea98042014-08-26 00:28:107359 root->render_surface()->layer_list().at(1).get());
[email protected]995708c52013-10-17 20:52:597360 EXPECT_EQ(scroll_grandparent.get(),
Daniel Chengeea98042014-08-26 00:28:107361 root->render_surface()->layer_list().at(2).get());
[email protected]995708c52013-10-17 20:52:597362}
7363
7364TEST_F(LayerTreeHostCommonTest, OutOfOrderClippingRequiresRSLLSorting) {
7365 // Ensures that even if we visit layers out of order, we still produce a
[email protected]44d8e84c2013-10-19 19:13:227366 // correctly ordered render surface layer list.
[email protected]995708c52013-10-17 20:52:597367 // + root
7368 // + scroll_child
7369 // + scroll_parent_border
7370 // + scroll_parent_clip
7371 // + scroll_parent
7372 // + render_surface1
7373 // + scroll_grandparent_border
7374 // + scroll_grandparent_clip
7375 // + scroll_grandparent
7376 // + render_surface2
7377 //
[email protected]44d8e84c2013-10-19 19:13:227378 scoped_refptr<LayerWithForcedDrawsContent> root =
7379 make_scoped_refptr(new LayerWithForcedDrawsContent);
[email protected]995708c52013-10-17 20:52:597380
7381 scoped_refptr<Layer> scroll_parent_border = Layer::Create();
7382 scoped_refptr<Layer> scroll_parent_clip = Layer::Create();
7383 scoped_refptr<LayerWithForcedDrawsContent> scroll_parent =
7384 make_scoped_refptr(new LayerWithForcedDrawsContent);
7385 scoped_refptr<LayerWithForcedDrawsContent> render_surface1 =
7386 make_scoped_refptr(new LayerWithForcedDrawsContent);
7387
7388 scoped_refptr<Layer> scroll_grandparent_border = Layer::Create();
7389 scoped_refptr<Layer> scroll_grandparent_clip = Layer::Create();
7390 scoped_refptr<LayerWithForcedDrawsContent> scroll_grandparent =
7391 make_scoped_refptr(new LayerWithForcedDrawsContent);
7392 scoped_refptr<LayerWithForcedDrawsContent> render_surface2 =
7393 make_scoped_refptr(new LayerWithForcedDrawsContent);
7394
7395 scoped_refptr<LayerWithForcedDrawsContent> scroll_child =
7396 make_scoped_refptr(new LayerWithForcedDrawsContent);
7397
7398 root->AddChild(scroll_child);
7399
7400 root->AddChild(scroll_parent_border);
7401 scroll_parent_border->AddChild(scroll_parent_clip);
7402 scroll_parent_clip->AddChild(scroll_parent);
7403 scroll_parent->AddChild(render_surface2);
7404
7405 root->AddChild(scroll_grandparent_border);
7406 scroll_grandparent_border->AddChild(scroll_grandparent_clip);
7407 scroll_grandparent_clip->AddChild(scroll_grandparent);
7408 scroll_grandparent->AddChild(render_surface1);
7409
7410 scroll_parent_clip->SetMasksToBounds(true);
7411 scroll_grandparent_clip->SetMasksToBounds(true);
7412
7413 scroll_child->SetScrollParent(scroll_parent.get());
7414 scroll_parent_border->SetScrollParent(scroll_grandparent.get());
7415
7416 render_surface1->SetForceRenderSurface(true);
7417 render_surface2->SetForceRenderSurface(true);
7418
7419 gfx::Transform identity_transform;
7420 SetLayerPropertiesForTesting(root.get(),
7421 identity_transform,
[email protected]a2566412014-06-05 03:14:207422 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597423 gfx::PointF(),
7424 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577425 true,
[email protected]995708c52013-10-17 20:52:597426 false);
7427 SetLayerPropertiesForTesting(scroll_grandparent_border.get(),
7428 identity_transform,
[email protected]a2566412014-06-05 03:14:207429 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597430 gfx::PointF(),
7431 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577432 true,
[email protected]995708c52013-10-17 20:52:597433 false);
7434 SetLayerPropertiesForTesting(scroll_grandparent_clip.get(),
7435 identity_transform,
[email protected]a2566412014-06-05 03:14:207436 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597437 gfx::PointF(),
7438 gfx::Size(20, 20),
[email protected]56fffdd2014-02-11 19:50:577439 true,
[email protected]995708c52013-10-17 20:52:597440 false);
7441 SetLayerPropertiesForTesting(scroll_grandparent.get(),
7442 identity_transform,
[email protected]a2566412014-06-05 03:14:207443 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597444 gfx::PointF(),
7445 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577446 true,
[email protected]995708c52013-10-17 20:52:597447 false);
7448 SetLayerPropertiesForTesting(render_surface1.get(),
7449 identity_transform,
[email protected]a2566412014-06-05 03:14:207450 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597451 gfx::PointF(),
7452 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577453 true,
[email protected]995708c52013-10-17 20:52:597454 false);
7455 SetLayerPropertiesForTesting(scroll_parent_border.get(),
7456 identity_transform,
[email protected]a2566412014-06-05 03:14:207457 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597458 gfx::PointF(),
7459 gfx::Size(40, 40),
[email protected]56fffdd2014-02-11 19:50:577460 true,
[email protected]995708c52013-10-17 20:52:597461 false);
7462 SetLayerPropertiesForTesting(scroll_parent_clip.get(),
7463 identity_transform,
[email protected]a2566412014-06-05 03:14:207464 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597465 gfx::PointF(),
7466 gfx::Size(30, 30),
[email protected]56fffdd2014-02-11 19:50:577467 true,
[email protected]995708c52013-10-17 20:52:597468 false);
7469 SetLayerPropertiesForTesting(scroll_parent.get(),
7470 identity_transform,
[email protected]a2566412014-06-05 03:14:207471 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597472 gfx::PointF(),
7473 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577474 true,
[email protected]995708c52013-10-17 20:52:597475 false);
7476 SetLayerPropertiesForTesting(render_surface2.get(),
7477 identity_transform,
[email protected]a2566412014-06-05 03:14:207478 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597479 gfx::PointF(),
7480 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577481 true,
[email protected]995708c52013-10-17 20:52:597482 false);
7483 SetLayerPropertiesForTesting(scroll_child.get(),
7484 identity_transform,
[email protected]a2566412014-06-05 03:14:207485 gfx::Point3F(),
[email protected]995708c52013-10-17 20:52:597486 gfx::PointF(),
7487 gfx::Size(50, 50),
[email protected]56fffdd2014-02-11 19:50:577488 true,
[email protected]995708c52013-10-17 20:52:597489 false);
7490
enne2097cab2014-09-25 20:16:317491 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost());
[email protected]995708c52013-10-17 20:52:597492 host->SetRootLayer(root);
7493
7494 RenderSurfaceLayerList render_surface_layer_list;
7495 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
7496 root.get(),
bokancccfde72014-10-08 15:15:227497 root->bounds(),
[email protected]995708c52013-10-17 20:52:597498 identity_transform,
7499 &render_surface_layer_list);
7500
7501 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7502
7503 EXPECT_TRUE(root->render_surface());
7504
7505 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7506 scroll_child->clip_rect().ToString());
7507 EXPECT_TRUE(scroll_child->is_clipped());
7508
7509 // Despite the fact that we had to process the layers out of order to get the
7510 // right clip, our render_surface_layer_list's order should be unaffected.
7511 EXPECT_EQ(3u, render_surface_layer_list.size());
7512 EXPECT_EQ(root.get(), render_surface_layer_list.at(0));
7513 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1));
7514 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2));
[email protected]44d8e84c2013-10-19 19:13:227515 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface());
7516 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface());
7517 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface());
[email protected]995708c52013-10-17 20:52:597518}
7519
7520TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) {
7521 // We rearrange layer list contributions if we have to visit children out of
7522 // order, but it should be a 'stable' rearrangement. That is, the layer list
7523 // additions for a single layer should not be reordered, though their position
7524 // wrt to the contributions due to a sibling may vary.
7525 //
7526 // + root
7527 // + scroll_child
7528 // + top_content
7529 // + bottom_content
7530 // + scroll_parent_border
7531 // + scroll_parent_clip
7532 // + scroll_parent
7533 //
7534 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457535 TestSharedBitmapManager shared_bitmap_manager;
7536 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]995708c52013-10-17 20:52:597537 host_impl.CreatePendingTree();
7538 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7539 scoped_ptr<LayerImpl> scroll_parent_border =
7540 LayerImpl::Create(host_impl.active_tree(), 2);
7541 scoped_ptr<LayerImpl> scroll_parent_clip =
7542 LayerImpl::Create(host_impl.active_tree(), 3);
7543 scoped_ptr<LayerImpl> scroll_parent =
7544 LayerImpl::Create(host_impl.active_tree(), 4);
7545 scoped_ptr<LayerImpl> scroll_child =
7546 LayerImpl::Create(host_impl.active_tree(), 5);
7547 scoped_ptr<LayerImpl> bottom_content =
7548 LayerImpl::Create(host_impl.active_tree(), 6);
7549 scoped_ptr<LayerImpl> top_content =
7550 LayerImpl::Create(host_impl.active_tree(), 7);
7551
7552 scroll_parent_clip->SetMasksToBounds(true);
7553
7554 scroll_child->SetScrollParent(scroll_parent.get());
danakj6496cba2014-10-16 01:31:087555 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>);
[email protected]995708c52013-10-17 20:52:597556 scroll_children->insert(scroll_child.get());
7557 scroll_parent->SetScrollChildren(scroll_children.release());
7558
7559 scroll_child->SetDrawsContent(true);
7560 scroll_parent->SetDrawsContent(true);
7561 top_content->SetDrawsContent(true);
7562 bottom_content->SetDrawsContent(true);
7563
7564 gfx::Transform identity_transform;
7565 gfx::Transform top_transform;
7566 top_transform.Translate3d(0.0, 0.0, 5.0);
7567 gfx::Transform bottom_transform;
7568 bottom_transform.Translate3d(0.0, 0.0, 3.0);
7569
awoloszyne83f28c2014-12-22 15:40:007570 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7571 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]56fffdd2014-02-11 19:50:577572 true);
awoloszyne83f28c2014-12-22 15:40:007573 SetLayerPropertiesForTesting(scroll_parent_border.get(), identity_transform,
7574 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7575 true, false, false);
7576 SetLayerPropertiesForTesting(scroll_parent_clip.get(), identity_transform,
7577 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7578 true, false, false);
7579 SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform,
7580 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7581 true, false, false);
7582 SetLayerPropertiesForTesting(scroll_child.get(), identity_transform,
7583 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7584 true, false, false);
7585 SetLayerPropertiesForTesting(top_content.get(), top_transform, gfx::Point3F(),
7586 gfx::PointF(), gfx::Size(50, 50), false, true,
[email protected]56fffdd2014-02-11 19:50:577587 true);
awoloszyne83f28c2014-12-22 15:40:007588 SetLayerPropertiesForTesting(bottom_content.get(), bottom_transform,
7589 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7590 false, true, true);
[email protected]995708c52013-10-17 20:52:597591
[email protected]56fffdd2014-02-11 19:50:577592 scroll_child->SetShouldFlattenTransform(false);
[email protected]a9d4d4f2014-06-19 06:49:287593 scroll_child->Set3dSortingContextId(1);
[email protected]995708c52013-10-17 20:52:597594
7595 scroll_child->AddChild(top_content.Pass());
7596 scroll_child->AddChild(bottom_content.Pass());
7597 root->AddChild(scroll_child.Pass());
7598
7599 scroll_parent_clip->AddChild(scroll_parent.Pass());
7600 scroll_parent_border->AddChild(scroll_parent_clip.Pass());
7601 root->AddChild(scroll_parent_border.Pass());
7602
7603 LayerImplList render_surface_layer_list;
7604 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227605 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]995708c52013-10-17 20:52:597606
7607 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7608
7609 EXPECT_TRUE(root->render_surface());
7610
7611 // If we don't sort by depth and let the layers get added in the order they
7612 // would normally be visited in, then layers 6 and 7 will be out of order. In
7613 // other words, although we've had to shift 5, 6, and 7 to appear before 4
7614 // in the list (because of the scroll parent relationship), this should not
7615 // have an effect on the the order of 5, 6, and 7 (which had been reordered
7616 // due to layer sorting).
7617 EXPECT_EQ(4u, root->render_surface()->layer_list().size());
7618 EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id());
7619 EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id());
7620 EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id());
7621 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id());
7622}
7623
[email protected]d81752b2013-10-25 08:32:237624TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
7625 // This test verifies that a scrolling layer that gets snapped to
7626 // integer coordinates doesn't move a fixed position child.
7627 //
7628 // + root
7629 // + container
7630 // + scroller
7631 // + fixed
7632 //
7633 FakeImplProxy proxy;
[email protected]4e2eb352014-03-20 17:25:457634 TestSharedBitmapManager shared_bitmap_manager;
7635 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
[email protected]d81752b2013-10-25 08:32:237636 host_impl.CreatePendingTree();
7637 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7638 scoped_ptr<LayerImpl> container =
7639 LayerImpl::Create(host_impl.active_tree(), 2);
7640 LayerImpl* container_layer = container.get();
7641 scoped_ptr<LayerImpl> scroller =
7642 LayerImpl::Create(host_impl.active_tree(), 3);
7643 LayerImpl* scroll_layer = scroller.get();
7644 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7645 LayerImpl* fixed_layer = fixed.get();
7646
7647 container->SetIsContainerForFixedPositionLayers(true);
7648
7649 LayerPositionConstraint constraint;
7650 constraint.set_is_fixed_position(true);
7651 fixed->SetPositionConstraint(constraint);
7652
[email protected]adeda572014-01-31 00:49:477653 scroller->SetScrollClipLayer(container->id());
[email protected]d81752b2013-10-25 08:32:237654
7655 gfx::Transform identity_transform;
7656 gfx::Transform container_transform;
7657 container_transform.Translate3d(10.0, 20.0, 0.0);
7658 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7659
awoloszyne83f28c2014-12-22 15:40:007660 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7661 gfx::PointF(), gfx::Size(50, 50), true, false,
7662 true);
7663 SetLayerPropertiesForTesting(container.get(), container_transform,
7664 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7665 true, false, false);
7666 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7667 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7668 true, false, false);
7669 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7670 gfx::PointF(), gfx::Size(50, 50), true, false,
[email protected]d81752b2013-10-25 08:32:237671 false);
7672
7673 scroller->AddChild(fixed.Pass());
7674 container->AddChild(scroller.Pass());
7675 root->AddChild(container.Pass());
7676
7677 // Rounded to integers already.
7678 {
7679 gfx::Vector2dF scroll_delta(3.0, 5.0);
7680 scroll_layer->SetScrollDelta(scroll_delta);
7681
7682 LayerImplList render_surface_layer_list;
7683 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227684 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]d81752b2013-10-25 08:32:237685 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7686
7687 EXPECT_TRANSFORMATION_MATRIX_EQ(
7688 container_layer->draw_properties().screen_space_transform,
7689 fixed_layer->draw_properties().screen_space_transform);
7690 EXPECT_VECTOR_EQ(
7691 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7692 container_offset);
7693 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7694 .screen_space_transform.To2dTranslation(),
7695 container_offset - scroll_delta);
7696 }
7697
7698 // Scroll delta requiring rounding.
7699 {
7700 gfx::Vector2dF scroll_delta(4.1f, 8.1f);
7701 scroll_layer->SetScrollDelta(scroll_delta);
7702
7703 gfx::Vector2dF rounded_scroll_delta(4.f, 8.f);
7704
7705 LayerImplList render_surface_layer_list;
7706 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227707 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]d81752b2013-10-25 08:32:237708 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7709
7710 EXPECT_TRANSFORMATION_MATRIX_EQ(
7711 container_layer->draw_properties().screen_space_transform,
7712 fixed_layer->draw_properties().screen_space_transform);
7713 EXPECT_VECTOR_EQ(
7714 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7715 container_offset);
7716 EXPECT_VECTOR_EQ(scroll_layer->draw_properties()
7717 .screen_space_transform.To2dTranslation(),
7718 container_offset - rounded_scroll_delta);
7719 }
[email protected]cf15ad7b2014-04-02 03:59:267720
7721 // Scale is applied earlier in the tree.
7722 {
7723 gfx::Transform scaled_container_transform = container_transform;
7724 scaled_container_transform.Scale3d(3.0, 3.0, 1.0);
7725 container_layer->SetTransform(scaled_container_transform);
7726
7727 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7728 scroll_layer->SetScrollDelta(scroll_delta);
7729
7730 LayerImplList render_surface_layer_list;
7731 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227732 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]cf15ad7b2014-04-02 03:59:267733 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7734
7735 EXPECT_TRANSFORMATION_MATRIX_EQ(
7736 container_layer->draw_properties().screen_space_transform,
7737 fixed_layer->draw_properties().screen_space_transform);
7738 EXPECT_VECTOR_EQ(
7739 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7740 container_offset);
7741
7742 container_layer->SetTransform(container_transform);
7743 }
7744
7745 // Scale is applied on the scroll layer itself.
7746 {
7747 gfx::Transform scale_transform;
7748 scale_transform.Scale3d(3.0, 3.0, 1.0);
7749 scroll_layer->SetTransform(scale_transform);
7750
7751 gfx::Vector2dF scroll_delta(4.5f, 8.5f);
7752 scroll_layer->SetScrollDelta(scroll_delta);
7753
7754 LayerImplList render_surface_layer_list;
7755 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
bokancccfde72014-10-08 15:15:227756 root.get(), root->bounds(), &render_surface_layer_list);
[email protected]cf15ad7b2014-04-02 03:59:267757 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7758
7759 EXPECT_VECTOR_EQ(
7760 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7761 container_offset);
7762
7763 scroll_layer->SetTransform(identity_transform);
7764 }
[email protected]d81752b2013-10-25 08:32:237765}
7766
miletus2c78036b2015-01-29 20:52:377767TEST_F(LayerTreeHostCommonTest,
7768 ScrollCompensationMainScrollOffsetFractionalPart) {
7769 // This test verifies that a scrolling layer that has fractional scroll offset
7770 // from main doesn't move a fixed position child.
7771 //
7772 // + root
7773 // + container
7774 // + scroller
7775 // + fixed
7776 //
7777 FakeImplProxy proxy;
7778 TestSharedBitmapManager shared_bitmap_manager;
7779 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7780 host_impl.CreatePendingTree();
7781 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
7782 scoped_ptr<LayerImpl> container =
7783 LayerImpl::Create(host_impl.active_tree(), 2);
7784 LayerImpl* container_layer = container.get();
7785 scoped_ptr<LayerImpl> scroller =
7786 LayerImpl::Create(host_impl.active_tree(), 3);
7787 LayerImpl* scroll_layer = scroller.get();
7788 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4);
7789 LayerImpl* fixed_layer = fixed.get();
7790
7791 container->SetIsContainerForFixedPositionLayers(true);
7792
7793 LayerPositionConstraint constraint;
7794 constraint.set_is_fixed_position(true);
7795 fixed->SetPositionConstraint(constraint);
7796
7797 scroller->SetScrollClipLayer(container->id());
7798
7799 gfx::Transform identity_transform;
7800 gfx::Transform container_transform;
7801 container_transform.Translate3d(10.0, 20.0, 0.0);
7802 gfx::Vector2dF container_offset = container_transform.To2dTranslation();
7803
7804 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(),
7805 gfx::PointF(), gfx::Size(50, 50), true, false,
7806 true);
7807 SetLayerPropertiesForTesting(container.get(), container_transform,
7808 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7809 true, false, false);
7810 SetLayerPropertiesForTesting(scroller.get(), identity_transform,
7811 gfx::Point3F(), gfx::PointF(0.0, 0.0),
7812 gfx::Size(30, 30), true, false, false);
7813
7814 gfx::ScrollOffset scroll_offset(3.3, 4.2);
7815 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f);
7816 gfx::Vector2dF scroll_delta(0.1f, 0.4f);
7817 // Blink only uses the integer part of the scroll_offset for fixed
7818 // position layer.
7819 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(),
7820 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true,
7821 false, false);
7822 scroll_layer->SetScrollOffsetAndDelta(scroll_offset, scroll_delta);
miletusff93ab72015-01-30 04:30:447823 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part);
miletus2c78036b2015-01-29 20:52:377824
7825 scroller->AddChild(fixed.Pass());
7826 container->AddChild(scroller.Pass());
7827 root->AddChild(container.Pass());
7828
7829 LayerImplList render_surface_layer_list;
7830 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
7831 root.get(), root->bounds(), &render_surface_layer_list);
7832 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
7833
7834 EXPECT_TRANSFORMATION_MATRIX_EQ(
7835 container_layer->draw_properties().screen_space_transform,
7836 fixed_layer->draw_properties().screen_space_transform);
7837 EXPECT_VECTOR_EQ(
7838 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(),
7839 container_offset);
7840
7841 gfx::ScrollOffset effective_scroll_offset =
7842 ScrollOffsetWithDelta(scroll_offset, scroll_delta);
7843 gfx::Vector2d rounded_effective_scroll_offset =
7844 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset));
7845 EXPECT_VECTOR_EQ(
7846 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(),
7847 container_offset - rounded_effective_scroll_offset);
7848}
7849
[email protected]1c3626e2014-04-09 17:49:227850class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
7851 public:
7852 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
7853 LayerTreeImpl* tree_impl,
7854 int id) {
7855 return make_scoped_ptr(
7856 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
7857 }
7858
dcheng716bedf2014-10-21 09:51:087859 ~AnimationScaleFactorTrackingLayerImpl() override {}
[email protected]1c3626e2014-04-09 17:49:227860
[email protected]1c3626e2014-04-09 17:49:227861 private:
7862 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7863 int id)
[email protected]a57cb8b12014-06-13 18:15:377864 : LayerImpl(tree_impl, id) {
[email protected]1c3626e2014-04-09 17:49:227865 SetDrawsContent(true);
7866 }
[email protected]1c3626e2014-04-09 17:49:227867};
7868
7869TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
7870 FakeImplProxy proxy;
7871 TestSharedBitmapManager shared_bitmap_manager;
7872 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7873 gfx::Transform identity_matrix;
7874 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
7875 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
7876 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
7877 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
7878 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
7879 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
7880 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
7881 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
7882
7883 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
7884 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
7885 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
7886
danakjf446a072014-09-27 21:55:487887 child->AddChild(grand_child.Pass());
7888 parent->AddChild(child.Pass());
7889 grand_parent->AddChild(parent.Pass());
[email protected]1c3626e2014-04-09 17:49:227890
awoloszyne83f28c2014-12-22 15:40:007891 SetLayerPropertiesForTesting(grand_parent.get(), identity_matrix,
7892 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7893 true, false, true);
7894 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
7895 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227896 false);
awoloszyne83f28c2014-12-22 15:40:007897 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
7898 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227899 false);
awoloszyne83f28c2014-12-22 15:40:007900
7901 SetLayerPropertiesForTesting(grand_child_raw, identity_matrix, gfx::Point3F(),
7902 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]1c3626e2014-04-09 17:49:227903 false);
7904
7905 ExecuteCalculateDrawProperties(grand_parent.get());
7906
7907 // No layers have animations.
[email protected]a57cb8b12014-06-13 18:15:377908 EXPECT_EQ(0.f,
7909 grand_parent->draw_properties().maximum_animation_contents_scale);
7910 EXPECT_EQ(0.f,
7911 parent_raw->draw_properties().maximum_animation_contents_scale);
7912 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7913 EXPECT_EQ(
7914 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227915
7916 TransformOperations translation;
7917 translation.AppendTranslate(1.f, 2.f, 3.f);
7918
7919 AddAnimatedTransformToLayer(
7920 parent_raw, 1.0, TransformOperations(), translation);
7921
7922 // No layers have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377923 EXPECT_EQ(0.f,
7924 grand_parent->draw_properties().maximum_animation_contents_scale);
7925 EXPECT_EQ(0.f,
7926 parent_raw->draw_properties().maximum_animation_contents_scale);
7927 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7928 EXPECT_EQ(
7929 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227930
7931 TransformOperations scale;
7932 scale.AppendScale(5.f, 4.f, 3.f);
7933
7934 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
7935 ExecuteCalculateDrawProperties(grand_parent.get());
7936
7937 // Only |child| has a scale-affecting animation.
[email protected]a57cb8b12014-06-13 18:15:377938 EXPECT_EQ(0.f,
7939 grand_parent->draw_properties().maximum_animation_contents_scale);
7940 EXPECT_EQ(0.f,
7941 parent_raw->draw_properties().maximum_animation_contents_scale);
7942 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
7943 EXPECT_EQ(
7944 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227945
7946 AddAnimatedTransformToLayer(
7947 grand_parent.get(), 1.0, TransformOperations(), scale);
7948 ExecuteCalculateDrawProperties(grand_parent.get());
7949
7950 // |grand_parent| and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377951 EXPECT_EQ(5.f,
7952 grand_parent->draw_properties().maximum_animation_contents_scale);
7953 EXPECT_EQ(5.f,
7954 parent_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227955 // We don't support combining animated scales from two nodes; 0.f means
7956 // that the maximum scale could not be computed.
[email protected]a57cb8b12014-06-13 18:15:377957 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7958 EXPECT_EQ(
7959 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227960
7961 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
7962 ExecuteCalculateDrawProperties(grand_parent.get());
7963
7964 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
[email protected]a57cb8b12014-06-13 18:15:377965 EXPECT_EQ(5.f,
7966 grand_parent->draw_properties().maximum_animation_contents_scale);
7967 EXPECT_EQ(0.f,
7968 parent_raw->draw_properties().maximum_animation_contents_scale);
7969 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7970 EXPECT_EQ(
7971 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227972
7973 grand_parent->layer_animation_controller()->AbortAnimations(
7974 Animation::Transform);
7975 parent_raw->layer_animation_controller()->AbortAnimations(
7976 Animation::Transform);
7977 child_raw->layer_animation_controller()->AbortAnimations(
7978 Animation::Transform);
7979
7980 TransformOperations perspective;
7981 perspective.AppendPerspective(10.f);
7982
7983 AddAnimatedTransformToLayer(
7984 child_raw, 1.0, TransformOperations(), perspective);
7985 ExecuteCalculateDrawProperties(grand_parent.get());
7986
7987 // |child| has a scale-affecting animation but computing the maximum of this
7988 // animation is not supported.
[email protected]a57cb8b12014-06-13 18:15:377989 EXPECT_EQ(0.f,
7990 grand_parent->draw_properties().maximum_animation_contents_scale);
7991 EXPECT_EQ(0.f,
7992 parent_raw->draw_properties().maximum_animation_contents_scale);
7993 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7994 EXPECT_EQ(
7995 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:227996
7997 child_raw->layer_animation_controller()->AbortAnimations(
7998 Animation::Transform);
7999
8000 gfx::Transform scale_matrix;
8001 scale_matrix.Scale(1.f, 2.f);
8002 grand_parent->SetTransform(scale_matrix);
8003 parent_raw->SetTransform(scale_matrix);
8004 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
8005 ExecuteCalculateDrawProperties(grand_parent.get());
8006
8007 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
8008 // animation with maximum scale 5.f.
[email protected]a57cb8b12014-06-13 18:15:378009 EXPECT_EQ(0.f,
8010 grand_parent->draw_properties().maximum_animation_contents_scale);
8011 EXPECT_EQ(10.f,
8012 parent_raw->draw_properties().maximum_animation_contents_scale);
8013 EXPECT_EQ(10.f,
8014 child_raw->draw_properties().maximum_animation_contents_scale);
8015 EXPECT_EQ(
8016 10.f,
8017 grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228018
8019 gfx::Transform perspective_matrix;
8020 perspective_matrix.ApplyPerspectiveDepth(2.f);
8021 child_raw->SetTransform(perspective_matrix);
8022 ExecuteCalculateDrawProperties(grand_parent.get());
8023
8024 // |child| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:378025 EXPECT_EQ(0.f,
8026 grand_parent->draw_properties().maximum_animation_contents_scale);
8027 EXPECT_EQ(10.f,
8028 parent_raw->draw_properties().maximum_animation_contents_scale);
8029 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8030 EXPECT_EQ(
8031 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228032
8033 parent_raw->SetTransform(perspective_matrix);
8034 ExecuteCalculateDrawProperties(grand_parent.get());
8035
8036 // |parent| and |child| have transforms that are neither translations nor
8037 // scales.
[email protected]a57cb8b12014-06-13 18:15:378038 EXPECT_EQ(0.f,
8039 grand_parent->draw_properties().maximum_animation_contents_scale);
8040 EXPECT_EQ(0.f,
8041 parent_raw->draw_properties().maximum_animation_contents_scale);
8042 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8043 EXPECT_EQ(
8044 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228045
8046 parent_raw->SetTransform(identity_matrix);
8047 child_raw->SetTransform(identity_matrix);
8048 grand_parent->SetTransform(perspective_matrix);
8049
8050 ExecuteCalculateDrawProperties(grand_parent.get());
8051
8052 // |grand_parent| has a transform that's neither a translation nor a scale.
[email protected]a57cb8b12014-06-13 18:15:378053 EXPECT_EQ(0.f,
8054 grand_parent->draw_properties().maximum_animation_contents_scale);
8055 EXPECT_EQ(0.f,
8056 parent_raw->draw_properties().maximum_animation_contents_scale);
8057 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8058 EXPECT_EQ(
8059 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
[email protected]1c3626e2014-04-09 17:49:228060}
8061
[email protected]390bb1ff2014-05-09 17:14:408062static int membership_id(LayerImpl* layer) {
8063 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
8064}
8065
8066static void GatherDrawnLayers(LayerImplList* rsll,
8067 std::set<LayerImpl*>* drawn_layers) {
8068 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll),
8069 end = LayerIterator<LayerImpl>::End(rsll);
8070 it != end;
8071 ++it) {
8072 LayerImpl* layer = *it;
8073 if (it.represents_itself())
8074 drawn_layers->insert(layer);
8075
8076 if (!it.represents_contributing_render_surface())
8077 continue;
8078
8079 if (layer->mask_layer())
8080 drawn_layers->insert(layer->mask_layer());
8081 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
8082 drawn_layers->insert(layer->replica_layer()->mask_layer());
8083 }
8084}
8085
8086TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) {
8087 FakeImplProxy proxy;
8088 TestSharedBitmapManager shared_bitmap_manager;
8089 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
8090 gfx::Transform identity_matrix;
8091
8092 scoped_ptr<LayerImpl> grand_parent =
8093 LayerImpl::Create(host_impl.active_tree(), 1);
8094 scoped_ptr<LayerImpl> parent = LayerImpl::Create(host_impl.active_tree(), 3);
8095 scoped_ptr<LayerImpl> child = LayerImpl::Create(host_impl.active_tree(), 5);
8096 scoped_ptr<LayerImpl> grand_child1 =
8097 LayerImpl::Create(host_impl.active_tree(), 7);
8098 scoped_ptr<LayerImpl> grand_child2 =
8099 LayerImpl::Create(host_impl.active_tree(), 9);
8100
8101 LayerImpl* grand_parent_raw = grand_parent.get();
8102 LayerImpl* parent_raw = parent.get();
8103 LayerImpl* child_raw = child.get();
8104 LayerImpl* grand_child1_raw = grand_child1.get();
8105 LayerImpl* grand_child2_raw = grand_child2.get();
8106
8107 child->AddChild(grand_child1.Pass());
8108 child->AddChild(grand_child2.Pass());
8109 parent->AddChild(child.Pass());
8110 grand_parent->AddChild(parent.Pass());
8111
awoloszyne83f28c2014-12-22 15:40:008112 SetLayerPropertiesForTesting(grand_parent_raw, identity_matrix,
8113 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8114 true, false, true);
8115 SetLayerPropertiesForTesting(parent_raw, identity_matrix, gfx::Point3F(),
8116 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:408117 false);
awoloszyne83f28c2014-12-22 15:40:008118
8119 SetLayerPropertiesForTesting(child_raw, identity_matrix, gfx::Point3F(),
8120 gfx::PointF(), gfx::Size(1, 2), true, false,
[email protected]390bb1ff2014-05-09 17:14:408121 false);
awoloszyne83f28c2014-12-22 15:40:008122
8123 SetLayerPropertiesForTesting(grand_child1_raw, identity_matrix,
8124 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8125 true, false, false);
8126
8127 SetLayerPropertiesForTesting(grand_child2_raw, identity_matrix,
8128 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8129 true, false, false);
[email protected]390bb1ff2014-05-09 17:14:408130
8131 // Start with nothing being drawn.
8132 ExecuteCalculateDrawProperties(grand_parent_raw);
8133 int member_id = render_surface_layer_list_count();
8134
8135 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8136 EXPECT_NE(member_id, membership_id(parent_raw));
8137 EXPECT_NE(member_id, membership_id(child_raw));
8138 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8139 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8140
8141 std::set<LayerImpl*> expected;
8142 std::set<LayerImpl*> actual;
8143 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8144 EXPECT_EQ(expected, actual);
8145
8146 // If we force render surface, but none of the layers are in the layer list,
8147 // then this layer should not appear in RSLL.
awoloszyne83f28c2014-12-22 15:40:008148 grand_child1_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:408149
8150 ExecuteCalculateDrawProperties(grand_parent_raw);
8151 member_id = render_surface_layer_list_count();
8152
8153 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8154 EXPECT_NE(member_id, membership_id(parent_raw));
8155 EXPECT_NE(member_id, membership_id(child_raw));
8156 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8157 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8158
8159 expected.clear();
8160 actual.clear();
8161 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8162 EXPECT_EQ(expected, actual);
8163
8164 // However, if we say that this layer also draws content, it will appear in
8165 // RSLL.
8166 grand_child1_raw->SetDrawsContent(true);
8167
8168 ExecuteCalculateDrawProperties(grand_parent_raw);
8169 member_id = render_surface_layer_list_count();
8170
8171 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8172 EXPECT_NE(member_id, membership_id(parent_raw));
8173 EXPECT_NE(member_id, membership_id(child_raw));
8174 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
8175 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8176
8177 expected.clear();
8178 expected.insert(grand_child1_raw);
8179
8180 actual.clear();
8181 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8182 EXPECT_EQ(expected, actual);
8183
8184 // Now child is forced to have a render surface, and one if its children draws
8185 // content.
8186 grand_child1_raw->SetDrawsContent(false);
awoloszyne83f28c2014-12-22 15:40:008187 grand_child1_raw->SetHasRenderSurface(false);
8188 child_raw->SetHasRenderSurface(true);
[email protected]390bb1ff2014-05-09 17:14:408189 grand_child2_raw->SetDrawsContent(true);
8190
8191 ExecuteCalculateDrawProperties(grand_parent_raw);
8192 member_id = render_surface_layer_list_count();
8193
8194 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8195 EXPECT_NE(member_id, membership_id(parent_raw));
8196 EXPECT_NE(member_id, membership_id(child_raw));
8197 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8198 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8199
8200 expected.clear();
8201 expected.insert(grand_child2_raw);
8202
8203 actual.clear();
8204 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8205 EXPECT_EQ(expected, actual);
8206
8207 // Add a mask layer to child.
8208 child_raw->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6).Pass());
8209
8210 ExecuteCalculateDrawProperties(grand_parent_raw);
8211 member_id = render_surface_layer_list_count();
8212
8213 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8214 EXPECT_NE(member_id, membership_id(parent_raw));
8215 EXPECT_NE(member_id, membership_id(child_raw));
8216 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8217 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8218 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8219
8220 expected.clear();
8221 expected.insert(grand_child2_raw);
8222 expected.insert(child_raw->mask_layer());
8223
8224 expected.clear();
8225 expected.insert(grand_child2_raw);
8226 expected.insert(child_raw->mask_layer());
8227
8228 actual.clear();
8229 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8230 EXPECT_EQ(expected, actual);
8231
8232 // Add replica mask layer.
8233 scoped_ptr<LayerImpl> replica_layer =
8234 LayerImpl::Create(host_impl.active_tree(), 20);
8235 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 21));
8236 child_raw->SetReplicaLayer(replica_layer.Pass());
8237
8238 ExecuteCalculateDrawProperties(grand_parent_raw);
8239 member_id = render_surface_layer_list_count();
8240
8241 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8242 EXPECT_NE(member_id, membership_id(parent_raw));
8243 EXPECT_NE(member_id, membership_id(child_raw));
8244 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8245 EXPECT_EQ(member_id, membership_id(child_raw->replica_layer()->mask_layer()));
8246 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8247 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8248
8249 expected.clear();
8250 expected.insert(grand_child2_raw);
8251 expected.insert(child_raw->mask_layer());
8252 expected.insert(child_raw->replica_layer()->mask_layer());
8253
8254 actual.clear();
8255 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8256 EXPECT_EQ(expected, actual);
8257
8258 child_raw->TakeReplicaLayer();
8259
8260 // With nothing drawing, we should have no layers.
8261 grand_child2_raw->SetDrawsContent(false);
8262
8263 ExecuteCalculateDrawProperties(grand_parent_raw);
8264 member_id = render_surface_layer_list_count();
8265
8266 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8267 EXPECT_NE(member_id, membership_id(parent_raw));
8268 EXPECT_NE(member_id, membership_id(child_raw));
8269 EXPECT_NE(member_id, membership_id(child_raw->mask_layer()));
8270 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8271 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8272
8273 expected.clear();
8274 actual.clear();
8275 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8276 EXPECT_EQ(expected, actual);
8277
8278 // Child itself draws means that we should have the child and the mask in the
8279 // list.
8280 child_raw->SetDrawsContent(true);
8281
8282 ExecuteCalculateDrawProperties(grand_parent_raw);
8283 member_id = render_surface_layer_list_count();
8284
8285 EXPECT_NE(member_id, membership_id(grand_parent_raw));
8286 EXPECT_NE(member_id, membership_id(parent_raw));
8287 EXPECT_EQ(member_id, membership_id(child_raw));
8288 EXPECT_EQ(member_id, membership_id(child_raw->mask_layer()));
8289 EXPECT_NE(member_id, membership_id(grand_child1_raw));
8290 EXPECT_NE(member_id, membership_id(grand_child2_raw));
8291
8292 expected.clear();
8293 expected.insert(child_raw);
8294 expected.insert(child_raw->mask_layer());
8295 actual.clear();
8296 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8297 EXPECT_EQ(expected, actual);
8298
8299 child_raw->TakeMaskLayer();
8300
8301 // Now everyone's a member!
8302 grand_parent_raw->SetDrawsContent(true);
8303 parent_raw->SetDrawsContent(true);
8304 child_raw->SetDrawsContent(true);
8305 grand_child1_raw->SetDrawsContent(true);
8306 grand_child2_raw->SetDrawsContent(true);
8307
8308 ExecuteCalculateDrawProperties(grand_parent_raw);
8309 member_id = render_surface_layer_list_count();
8310
8311 EXPECT_EQ(member_id, membership_id(grand_parent_raw));
8312 EXPECT_EQ(member_id, membership_id(parent_raw));
8313 EXPECT_EQ(member_id, membership_id(child_raw));
8314 EXPECT_EQ(member_id, membership_id(grand_child1_raw));
8315 EXPECT_EQ(member_id, membership_id(grand_child2_raw));
8316
8317 expected.clear();
8318 expected.insert(grand_parent_raw);
8319 expected.insert(parent_raw);
8320 expected.insert(child_raw);
8321 expected.insert(grand_child1_raw);
8322 expected.insert(grand_child2_raw);
8323
8324 actual.clear();
8325 GatherDrawnLayers(render_surface_layer_list_impl(), &actual);
8326 EXPECT_EQ(expected, actual);
8327}
[email protected]18e69652014-06-13 12:50:588328
8329TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) {
8330 FakeImplProxy proxy;
8331 TestSharedBitmapManager shared_bitmap_manager;
8332 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
8333
8334 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1);
8335 LayerImpl* root_layer = root.get();
8336 scoped_ptr<LayerImpl> child1 = LayerImpl::Create(host_impl.active_tree(), 2);
8337 LayerImpl* child1_layer = child1.get();
8338 scoped_ptr<LayerImpl> child2 = LayerImpl::Create(host_impl.active_tree(), 3);
8339 LayerImpl* child2_layer = child2.get();
8340
8341 root->AddChild(child1.Pass());
8342 root->AddChild(child2.Pass());
awoloszyne83f28c2014-12-22 15:40:008343 root->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588344
8345 gfx::Transform identity_matrix, scale_transform_child1,
8346 scale_transform_child2;
8347 scale_transform_child1.Scale(2, 3);
8348 scale_transform_child2.Scale(4, 5);
8349
awoloszyne83f28c2014-12-22 15:40:008350 SetLayerPropertiesForTesting(root_layer, identity_matrix, gfx::Point3F(),
8351 gfx::PointF(), gfx::Size(1, 1), true, false,
8352 true);
8353 SetLayerPropertiesForTesting(child1_layer, scale_transform_child1,
8354 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8355 false, false);
[email protected]18e69652014-06-13 12:50:588356
8357 child1_layer->SetMaskLayer(
8358 LayerImpl::Create(host_impl.active_tree(), 4).Pass());
8359
8360 scoped_ptr<LayerImpl> replica_layer =
8361 LayerImpl::Create(host_impl.active_tree(), 5);
awoloszyne83f28c2014-12-22 15:40:008362 replica_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588363 replica_layer->SetMaskLayer(LayerImpl::Create(host_impl.active_tree(), 6));
8364 child1_layer->SetReplicaLayer(replica_layer.Pass());
awoloszyne83f28c2014-12-22 15:40:008365 child1_layer->SetHasRenderSurface(true);
[email protected]18e69652014-06-13 12:50:588366
8367 ExecuteCalculateDrawProperties(root_layer);
8368
8369 TransformOperations scale;
8370 scale.AppendScale(5.f, 8.f, 3.f);
8371
8372 AddAnimatedTransformToLayer(child2_layer, 1.0, TransformOperations(), scale);
awoloszyne83f28c2014-12-22 15:40:008373 SetLayerPropertiesForTesting(child2_layer, scale_transform_child2,
8374 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8375 false, false);
[email protected]18e69652014-06-13 12:50:588376
8377 ExecuteCalculateDrawProperties(root_layer);
8378
8379 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale);
8380 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().ideal_contents_scale);
8381 EXPECT_FLOAT_EQ(
8382 3.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8383 EXPECT_FLOAT_EQ(3.f,
8384 child1_layer->replica_layer()
8385 ->mask_layer()
8386 ->draw_properties()
8387 .ideal_contents_scale);
8388 EXPECT_FLOAT_EQ(5.f, child2_layer->draw_properties().ideal_contents_scale);
8389
8390 EXPECT_FLOAT_EQ(
8391 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8392 EXPECT_FLOAT_EQ(
8393 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8394 EXPECT_FLOAT_EQ(0.f,
8395 child1_layer->mask_layer()
8396 ->draw_properties()
8397 .maximum_animation_contents_scale);
8398 EXPECT_FLOAT_EQ(0.f,
8399 child1_layer->replica_layer()
8400 ->mask_layer()
8401 ->draw_properties()
8402 .maximum_animation_contents_scale);
8403 EXPECT_FLOAT_EQ(
8404 8.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8405
8406 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8407 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().page_scale_factor);
8408 EXPECT_FLOAT_EQ(
8409 1.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8410 EXPECT_FLOAT_EQ(1.f,
8411 child1_layer->replica_layer()
8412 ->mask_layer()
8413 ->draw_properties()
8414 .page_scale_factor);
8415 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().page_scale_factor);
8416
8417 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor);
8418 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor);
8419 EXPECT_FLOAT_EQ(
8420 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8421 EXPECT_FLOAT_EQ(1.f,
8422 child1_layer->replica_layer()
8423 ->mask_layer()
8424 ->draw_properties()
8425 .device_scale_factor);
8426 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor);
8427
8428 // Changing page-scale would affect ideal_contents_scale and
8429 // maximum_animation_contents_scale.
8430
8431 float page_scale_factor = 3.f;
8432 float device_scale_factor = 1.0f;
8433 std::vector<LayerImpl*> render_surface_layer_list;
8434 gfx::Size device_viewport_size =
8435 gfx::Size(root_layer->bounds().width() * device_scale_factor,
8436 root_layer->bounds().height() * device_scale_factor);
8437 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8438 root_layer, device_viewport_size, &render_surface_layer_list);
8439
8440 inputs.page_scale_factor = page_scale_factor;
8441 inputs.can_adjust_raster_scales = true;
8442 inputs.page_scale_application_layer = root_layer;
8443 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8444
8445 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().ideal_contents_scale);
8446 EXPECT_FLOAT_EQ(9.f, child1_layer->draw_properties().ideal_contents_scale);
8447 EXPECT_FLOAT_EQ(
8448 9.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8449 EXPECT_FLOAT_EQ(9.f,
8450 child1_layer->replica_layer()
8451 ->mask_layer()
8452 ->draw_properties()
8453 .ideal_contents_scale);
8454 EXPECT_FLOAT_EQ(15.f, child2_layer->draw_properties().ideal_contents_scale);
8455
8456 EXPECT_FLOAT_EQ(
8457 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8458 EXPECT_FLOAT_EQ(
8459 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8460 EXPECT_FLOAT_EQ(0.f,
8461 child1_layer->mask_layer()
8462 ->draw_properties()
8463 .maximum_animation_contents_scale);
8464 EXPECT_FLOAT_EQ(0.f,
8465 child1_layer->replica_layer()
8466 ->mask_layer()
8467 ->draw_properties()
8468 .maximum_animation_contents_scale);
8469 EXPECT_FLOAT_EQ(
8470 24.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8471
8472 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8473 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor);
8474 EXPECT_FLOAT_EQ(
8475 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8476 EXPECT_FLOAT_EQ(3.f,
8477 child1_layer->replica_layer()
8478 ->mask_layer()
8479 ->draw_properties()
8480 .page_scale_factor);
8481 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor);
8482
8483 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().device_scale_factor);
8484 EXPECT_FLOAT_EQ(1.f, child1_layer->draw_properties().device_scale_factor);
8485 EXPECT_FLOAT_EQ(
8486 1.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8487 EXPECT_FLOAT_EQ(1.f,
8488 child1_layer->replica_layer()
8489 ->mask_layer()
8490 ->draw_properties()
8491 .device_scale_factor);
8492 EXPECT_FLOAT_EQ(1.f, child2_layer->draw_properties().device_scale_factor);
8493
8494 // Changing device-scale would affect ideal_contents_scale and
8495 // maximum_animation_contents_scale.
8496
8497 device_scale_factor = 4.0f;
8498 inputs.device_scale_factor = device_scale_factor;
8499 inputs.can_adjust_raster_scales = true;
8500 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8501
8502 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().ideal_contents_scale);
8503 EXPECT_FLOAT_EQ(36.f, child1_layer->draw_properties().ideal_contents_scale);
8504 EXPECT_FLOAT_EQ(
8505 36.f, child1_layer->mask_layer()->draw_properties().ideal_contents_scale);
8506 EXPECT_FLOAT_EQ(36.f,
8507 child1_layer->replica_layer()
8508 ->mask_layer()
8509 ->draw_properties()
8510 .ideal_contents_scale);
8511 EXPECT_FLOAT_EQ(60.f, child2_layer->draw_properties().ideal_contents_scale);
8512
8513 EXPECT_FLOAT_EQ(
8514 0.f, root_layer->draw_properties().maximum_animation_contents_scale);
8515 EXPECT_FLOAT_EQ(
8516 0.f, child1_layer->draw_properties().maximum_animation_contents_scale);
8517 EXPECT_FLOAT_EQ(0.f,
8518 child1_layer->mask_layer()
8519 ->draw_properties()
8520 .maximum_animation_contents_scale);
8521 EXPECT_FLOAT_EQ(0.f,
8522 child1_layer->replica_layer()
8523 ->mask_layer()
8524 ->draw_properties()
8525 .maximum_animation_contents_scale);
8526 EXPECT_FLOAT_EQ(
8527 96.f, child2_layer->draw_properties().maximum_animation_contents_scale);
8528
8529 EXPECT_FLOAT_EQ(1.f, root_layer->draw_properties().page_scale_factor);
8530 EXPECT_FLOAT_EQ(3.f, child1_layer->draw_properties().page_scale_factor);
8531 EXPECT_FLOAT_EQ(
8532 3.f, child1_layer->mask_layer()->draw_properties().page_scale_factor);
8533 EXPECT_FLOAT_EQ(3.f,
8534 child1_layer->replica_layer()
8535 ->mask_layer()
8536 ->draw_properties()
8537 .page_scale_factor);
8538 EXPECT_FLOAT_EQ(3.f, child2_layer->draw_properties().page_scale_factor);
8539
8540 EXPECT_FLOAT_EQ(4.f, root_layer->draw_properties().device_scale_factor);
8541 EXPECT_FLOAT_EQ(4.f, child1_layer->draw_properties().device_scale_factor);
8542 EXPECT_FLOAT_EQ(
8543 4.f, child1_layer->mask_layer()->draw_properties().device_scale_factor);
8544 EXPECT_FLOAT_EQ(4.f,
8545 child1_layer->replica_layer()
8546 ->mask_layer()
8547 ->draw_properties()
8548 .device_scale_factor);
8549 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor);
8550}
8551
danakjf6069db2014-09-13 00:46:478552TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) {
8553 scoped_refptr<Layer> root = Layer::Create();
8554 SetLayerPropertiesForTesting(root.get(),
8555 gfx::Transform(),
8556 gfx::Point3F(),
8557 gfx::PointF(),
8558 gfx::Size(768 / 2, 3000),
8559 true,
8560 false);
8561 root->SetIsDrawable(true);
8562
8563 scoped_refptr<Layer> clip = Layer::Create();
8564 SetLayerPropertiesForTesting(clip.get(),
8565 gfx::Transform(),
8566 gfx::Point3F(),
8567 gfx::PointF(),
8568 gfx::Size(768 / 2, 10000),
8569 true,
8570 false);
8571 clip->SetMasksToBounds(true);
8572
8573 scoped_refptr<Layer> content = Layer::Create();
8574 SetLayerPropertiesForTesting(content.get(),
8575 gfx::Transform(),
8576 gfx::Point3F(),
8577 gfx::PointF(),
8578 gfx::Size(768 / 2, 10000),
8579 true,
8580 false);
8581 content->SetIsDrawable(true);
8582 content->SetForceRenderSurface(true);
8583
8584 root->AddChild(clip);
8585 clip->AddChild(content);
8586
enne2097cab2014-09-25 20:16:318587 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
8588 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
danakjf6069db2014-09-13 00:46:478589 host->SetRootLayer(root);
8590
8591 gfx::Size device_viewport_size(768, 582);
8592 RenderSurfaceLayerList render_surface_layer_list;
8593 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
8594 host->root_layer(), device_viewport_size, &render_surface_layer_list);
8595 inputs.device_scale_factor = 2.f;
8596 inputs.page_scale_factor = 1.f;
8597 inputs.page_scale_application_layer = NULL;
8598 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8599
8600 // Layers in the root render surface have their visible content rect clipped
8601 // by the viewport.
8602 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect());
8603
8604 // Layers drawing to a child render surface should still have their visible
8605 // content rect clipped by the viewport.
8606 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect());
8607}
8608
timav599f4359d2014-12-05 00:12:228609TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) {
8610 FakeImplProxy proxy;
8611 TestSharedBitmapManager shared_bitmap_manager;
8612 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
8613
8614 // Set two layers: the root layer clips it's child,
8615 // the child draws its content.
8616
8617 gfx::Size root_size = gfx::Size(300, 500);
8618
8619 // Sublayer should be bigger than the root enlarged by bounds_delta.
8620 gfx::Size sublayer_size = gfx::Size(300, 1000);
8621
8622 // Device viewport accomidated the root and the top controls.
8623 gfx::Size device_viewport_size = gfx::Size(300, 600);
8624 gfx::Transform identity_matrix;
8625
8626 host_impl.active_tree()->SetRootLayer(
8627 LayerImpl::Create(host_impl.active_tree(), 1));
8628
8629 LayerImpl* root = host_impl.active_tree()->root_layer();
8630 SetLayerPropertiesForTesting(root,
8631 identity_matrix,
8632 gfx::Point3F(),
8633 gfx::PointF(),
8634 root_size,
8635 false,
awoloszyne83f28c2014-12-22 15:40:008636 false,
8637 true);
timav599f4359d2014-12-05 00:12:228638
8639 root->SetContentBounds(root_size);
8640 root->SetMasksToBounds(true);
8641
8642 root->AddChild(LayerImpl::Create(host_impl.active_tree(), 2));
8643
8644 LayerImpl* sublayer = root->child_at(0);
8645 SetLayerPropertiesForTesting(sublayer,
8646 identity_matrix,
8647 gfx::Point3F(),
8648 gfx::PointF(),
8649 sublayer_size,
8650 false,
awoloszyne83f28c2014-12-22 15:40:008651 false,
timav599f4359d2014-12-05 00:12:228652 false);
8653
8654 sublayer->SetContentBounds(sublayer_size);
8655 sublayer->SetDrawsContent(true);
8656
8657 LayerImplList layer_impl_list;
8658 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
8659 root, device_viewport_size, &layer_impl_list);
8660
8661 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8662
8663 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_content_rect());
8664
8665 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
8666
8667 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8668
8669 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8670 root_size.height() + 50);
8671 EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect());
8672}
8673
[email protected]ba565742012-11-10 09:29:488674} // namespace
8675} // namespace cc