1 //// 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.
5 #include "cc/trees/layer_tree_host_common.h"
10 #include "cc/animation/keyframed_animation_curve.h"
11 #include "cc/animation/layer_animation_controller.h"
12 #include "cc/animation/transform_operations.h"
13 #include "cc/base/math_util.h"
14 #include "cc/layers/content_layer_client.h"
15 #include "cc/layers/layer.h"
16 #include "cc/layers/layer_client.h"
17 #include "cc/layers/layer_impl.h"
18 #include "cc/layers/layer_iterator.h"
19 #include "cc/layers/render_surface_impl.h"
20 #include "cc/output/copy_output_request.h"
21 #include "cc/output/copy_output_result.h"
22 #include "cc/test/animation_test_common.h"
23 #include "cc/test/fake_content_layer_client.h"
24 #include "cc/test/fake_impl_proxy.h"
25 #include "cc/test/fake_layer_tree_host.h"
26 #include "cc/test/fake_layer_tree_host_impl.h"
27 #include "cc/test/fake_output_surface.h"
28 #include "cc/test/fake_picture_layer.h"
29 #include "cc/test/fake_picture_layer_impl.h"
30 #include "cc/test/geometry_test_utils.h"
31 #include "cc/test/layer_tree_host_common_test.h"
32 #include "cc/test/test_task_graph_runner.h"
33 #include "cc/trees/draw_property_utils.h"
34 #include "cc/trees/layer_tree_impl.h"
35 #include "cc/trees/proxy.h"
36 #include "cc/trees/single_thread_proxy.h"
37 #include "testing/gmock/include/gmock/gmock.h"
38 #include "testing/gtest/include/gtest/gtest.h"
39 #include "ui/gfx/geometry/quad_f.h"
40 #include "ui/gfx/geometry/vector2d_conversions.h"
41 #include "ui/gfx/transform.h"
46 class LayerWithForcedDrawsContent
: public Layer
{
48 explicit LayerWithForcedDrawsContent(const LayerSettings
& settings
)
51 bool DrawsContent() const override
;
54 ~LayerWithForcedDrawsContent() override
{}
57 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
59 class MockContentLayerClient
: public ContentLayerClient
{
61 MockContentLayerClient() {}
62 ~MockContentLayerClient() override
{}
63 void PaintContents(SkCanvas
* canvas
,
64 const gfx::Rect
& clip
,
65 PaintingControlSetting picture_control
) override
{}
66 scoped_refptr
<DisplayItemList
> PaintContentsToDisplayList(
67 const gfx::Rect
& clip
,
68 PaintingControlSetting picture_control
) override
{
72 bool FillsBoundsCompletely() const override
{ return false; }
73 size_t GetApproximateUnsharedMemoryUsage() const override
{ return 0; }
76 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
78 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
79 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
82 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
84 EXPECT_FLOAT_EQ(expected, layer->GetIdealContentsScale()); \
87 class LayerTreeSettingsScaleContent
: public LayerTreeSettings
{
89 LayerTreeSettingsScaleContent() {
90 layer_transforms_should_scale_layer_contents
= true;
94 class LayerTreeHostCommonScalingTest
: public LayerTreeHostCommonTest
{
96 LayerTreeHostCommonScalingTest()
97 : LayerTreeHostCommonTest(LayerTreeSettingsScaleContent()) {}
100 TEST_F(LayerTreeHostCommonTest
, TransformsForNoOpLayer
) {
101 // Sanity check: For layers positioned at zero, with zero size,
102 // and with identity transforms, then the draw transform,
103 // screen space transform, and the hierarchy passed on to children
104 // layers should also be identity transforms.
106 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
107 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
108 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
109 parent
->AddChild(child
);
110 child
->AddChild(grand_child
);
112 host()->SetRootLayer(parent
);
114 gfx::Transform identity_matrix
;
115 SetLayerPropertiesForTesting(parent
.get(),
122 SetLayerPropertiesForTesting(child
.get(),
129 SetLayerPropertiesForTesting(grand_child
.get(),
137 ExecuteCalculateDrawProperties(parent
.get());
139 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
140 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
141 child
->screen_space_transform());
142 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
143 grand_child
->draw_transform());
144 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
145 grand_child
->screen_space_transform());
148 TEST_F(LayerTreeHostCommonTest
, DoNotSkipLayersWithHandlers
) {
149 LayerImpl
* parent
= root_layer();
150 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
151 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
153 gfx::Transform identity_matrix
;
154 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
155 gfx::PointF(), gfx::Size(100, 100), true, false,
157 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
158 gfx::PointF(10, 10), gfx::Size(100, 100), true,
160 // This would have previously caused us to skip our subtree, but this would be
161 // wrong; we need up-to-date draw properties to do hit testing on the layers
163 child
->SetOpacity(0.f
);
164 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
165 gfx::PointF(10, 10), gfx::Size(100, 100), true,
167 grand_child
->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
169 ExecuteCalculateDrawProperties(parent
);
171 // Check that we've computed draw properties for the subtree rooted at
173 EXPECT_FALSE(child
->draw_transform().IsIdentity());
174 EXPECT_FALSE(grand_child
->draw_transform().IsIdentity());
177 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleLayer
) {
178 gfx::Transform identity_matrix
;
179 scoped_refptr
<Layer
> layer
= Layer::Create(layer_settings());
181 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
182 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
183 gfx::PointF(), gfx::Size(1, 2), true, false);
184 root
->AddChild(layer
);
186 host()->SetRootLayer(root
);
188 TransformTree
& tree
= host()->property_trees()->transform_tree
;
190 // Case 2: Setting the bounds of the layer should not affect either the draw
191 // transform or the screenspace transform.
192 gfx::Transform translation_to_center
;
193 translation_to_center
.Translate(5.0, 6.0);
194 SetLayerPropertiesForTesting(layer
.get(), identity_matrix
, gfx::Point3F(),
195 gfx::PointF(), gfx::Size(10, 12), true, false);
196 ExecuteCalculateDrawProperties(root
.get());
197 EXPECT_TRANSFORMATION_MATRIX_EQ(
198 identity_matrix
, DrawTransformFromPropertyTrees(layer
.get(), tree
));
199 EXPECT_TRANSFORMATION_MATRIX_EQ(
201 ScreenSpaceTransformFromPropertyTrees(layer
.get(), tree
));
203 // Case 3: The anchor point by itself (without a layer transform) should have
204 // no effect on the transforms.
205 SetLayerPropertiesForTesting(layer
.get(), identity_matrix
,
206 gfx::Point3F(2.5f
, 3.0f
, 0.f
), gfx::PointF(),
207 gfx::Size(10, 12), true, false);
208 ExecuteCalculateDrawProperties(root
.get());
209 EXPECT_TRANSFORMATION_MATRIX_EQ(
210 identity_matrix
, DrawTransformFromPropertyTrees(layer
.get(), tree
));
211 EXPECT_TRANSFORMATION_MATRIX_EQ(
213 ScreenSpaceTransformFromPropertyTrees(layer
.get(), tree
));
215 // Case 4: A change in actual position affects both the draw transform and
216 // screen space transform.
217 gfx::Transform position_transform
;
218 position_transform
.Translate(0.f
, 1.2f
);
219 SetLayerPropertiesForTesting(
220 layer
.get(), identity_matrix
, gfx::Point3F(2.5f
, 3.0f
, 0.f
),
221 gfx::PointF(0.f
, 1.2f
), gfx::Size(10, 12), true, false);
222 ExecuteCalculateDrawProperties(root
.get());
223 EXPECT_TRANSFORMATION_MATRIX_EQ(
224 position_transform
, DrawTransformFromPropertyTrees(layer
.get(), tree
));
225 EXPECT_TRANSFORMATION_MATRIX_EQ(
227 ScreenSpaceTransformFromPropertyTrees(layer
.get(), tree
));
229 // Case 5: In the correct sequence of transforms, the layer transform should
230 // pre-multiply the translation_to_center. This is easily tested by using a
231 // scale transform, because scale and translation are not commutative.
232 gfx::Transform layer_transform
;
233 layer_transform
.Scale3d(2.0, 2.0, 1.0);
234 SetLayerPropertiesForTesting(layer
.get(), layer_transform
, gfx::Point3F(),
235 gfx::PointF(), gfx::Size(10, 12), true, false);
236 ExecuteCalculateDrawProperties(root
.get());
237 EXPECT_TRANSFORMATION_MATRIX_EQ(
238 layer_transform
, DrawTransformFromPropertyTrees(layer
.get(), tree
));
239 EXPECT_TRANSFORMATION_MATRIX_EQ(
241 ScreenSpaceTransformFromPropertyTrees(layer
.get(), tree
));
243 // Case 6: The layer transform should occur with respect to the anchor point.
244 gfx::Transform translation_to_anchor
;
245 translation_to_anchor
.Translate(5.0, 0.0);
246 gfx::Transform expected_result
=
247 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
248 SetLayerPropertiesForTesting(layer
.get(), layer_transform
,
249 gfx::Point3F(5.0f
, 0.f
, 0.f
), gfx::PointF(),
250 gfx::Size(10, 12), true, false);
251 ExecuteCalculateDrawProperties(root
.get());
252 EXPECT_TRANSFORMATION_MATRIX_EQ(
253 expected_result
, DrawTransformFromPropertyTrees(layer
.get(), tree
));
254 EXPECT_TRANSFORMATION_MATRIX_EQ(
256 ScreenSpaceTransformFromPropertyTrees(layer
.get(), tree
));
258 // Case 7: Verify that position pre-multiplies the layer transform. The
259 // current implementation of CalculateDrawProperties does this implicitly, but
260 // it is still worth testing to detect accidental regressions.
261 expected_result
= position_transform
* translation_to_anchor
*
262 layer_transform
* Inverse(translation_to_anchor
);
263 SetLayerPropertiesForTesting(
264 layer
.get(), layer_transform
, gfx::Point3F(5.0f
, 0.f
, 0.f
),
265 gfx::PointF(0.f
, 1.2f
), gfx::Size(10, 12), true, false);
266 ExecuteCalculateDrawProperties(root
.get());
267 EXPECT_TRANSFORMATION_MATRIX_EQ(
268 expected_result
, DrawTransformFromPropertyTrees(layer
.get(), tree
));
269 EXPECT_TRANSFORMATION_MATRIX_EQ(
271 ScreenSpaceTransformFromPropertyTrees(layer
.get(), tree
));
274 TEST_F(LayerTreeHostCommonTest
, TransformsAboutScrollOffset
) {
275 const gfx::ScrollOffset
kScrollOffset(50, 100);
276 const gfx::Vector2dF
kScrollDelta(2.34f
, 5.67f
);
277 const gfx::Vector2d
kMaxScrollOffset(200, 200);
278 const gfx::PointF
kScrollLayerPosition(-kScrollOffset
.x(),
280 const float kPageScale
= 0.888f
;
281 const float kDeviceScale
= 1.666f
;
284 TestSharedBitmapManager shared_bitmap_manager
;
285 TestTaskGraphRunner task_graph_runner
;
286 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
289 gfx::Transform identity_matrix
;
290 scoped_ptr
<LayerImpl
> sublayer_scoped_ptr(
291 LayerImpl::Create(host_impl
.active_tree(), 1));
292 LayerImpl
* sublayer
= sublayer_scoped_ptr
.get();
293 SetLayerPropertiesForTesting(sublayer
, identity_matrix
, gfx::Point3F(),
294 gfx::PointF(), gfx::Size(500, 500), true, false,
297 scoped_ptr
<LayerImpl
> scroll_layer_scoped_ptr(
298 LayerImpl::Create(host_impl
.active_tree(), 2));
299 LayerImpl
* scroll_layer
= scroll_layer_scoped_ptr
.get();
300 SetLayerPropertiesForTesting(scroll_layer
, identity_matrix
, gfx::Point3F(),
301 gfx::PointF(), gfx::Size(10, 20), true, false,
303 scoped_ptr
<LayerImpl
> clip_layer_scoped_ptr(
304 LayerImpl::Create(host_impl
.active_tree(), 4));
305 LayerImpl
* clip_layer
= clip_layer_scoped_ptr
.get();
307 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
308 clip_layer
->SetBounds(
309 gfx::Size(scroll_layer
->bounds().width() + kMaxScrollOffset
.x(),
310 scroll_layer
->bounds().height() + kMaxScrollOffset
.y()));
311 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
312 scroll_layer
->SetScrollDelta(kScrollDelta
);
313 gfx::Transform impl_transform
;
314 scroll_layer
->AddChild(sublayer_scoped_ptr
.Pass());
315 LayerImpl
* scroll_layer_raw_ptr
= scroll_layer_scoped_ptr
.get();
316 clip_layer
->AddChild(scroll_layer_scoped_ptr
.Pass());
317 scroll_layer_raw_ptr
->PushScrollOffsetFromMainThread(kScrollOffset
);
319 scoped_ptr
<LayerImpl
> root(LayerImpl::Create(host_impl
.active_tree(), 3));
320 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
321 gfx::PointF(), gfx::Size(3, 4), true, false,
323 root
->AddChild(clip_layer_scoped_ptr
.Pass());
324 root
->SetHasRenderSurface(true);
326 ExecuteCalculateDrawProperties(
327 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
328 gfx::Transform expected_transform
= identity_matrix
;
329 gfx::PointF sub_layer_screen_position
= kScrollLayerPosition
- kScrollDelta
;
330 expected_transform
.Translate(MathUtil::Round(sub_layer_screen_position
.x() *
331 kPageScale
* kDeviceScale
),
332 MathUtil::Round(sub_layer_screen_position
.y() *
333 kPageScale
* kDeviceScale
));
334 expected_transform
.Scale(kPageScale
* kDeviceScale
,
335 kPageScale
* kDeviceScale
);
336 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
337 sublayer
->draw_transform());
338 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
339 sublayer
->screen_space_transform());
341 gfx::Transform arbitrary_translate
;
342 const float kTranslateX
= 10.6f
;
343 const float kTranslateY
= 20.6f
;
344 arbitrary_translate
.Translate(kTranslateX
, kTranslateY
);
345 SetLayerPropertiesForTesting(scroll_layer
, arbitrary_translate
,
346 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
348 ExecuteCalculateDrawProperties(
349 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
350 expected_transform
.MakeIdentity();
351 expected_transform
.Translate(
352 MathUtil::Round(kTranslateX
* kPageScale
* kDeviceScale
+
353 sub_layer_screen_position
.x() * kPageScale
*
355 MathUtil::Round(kTranslateY
* kPageScale
* kDeviceScale
+
356 sub_layer_screen_position
.y() * kPageScale
*
358 expected_transform
.Scale(kPageScale
* kDeviceScale
,
359 kPageScale
* kDeviceScale
);
360 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
361 sublayer
->draw_transform());
364 TEST_F(LayerTreeHostCommonTest
, TransformsForSimpleHierarchy
) {
365 gfx::Transform identity_matrix
;
366 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
367 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
368 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
369 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
370 root
->AddChild(parent
);
371 parent
->AddChild(child
);
372 child
->AddChild(grand_child
);
374 host()->SetRootLayer(root
);
376 // One-time setup of root layer
377 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
378 gfx::PointF(), gfx::Size(1, 2), true, false);
380 TransformTree
& tree
= host()->property_trees()->transform_tree
;
382 // Case 1: parent's anchor point should not affect child or grand_child.
383 SetLayerPropertiesForTesting(parent
.get(), identity_matrix
,
384 gfx::Point3F(2.5f
, 3.0f
, 0.f
), gfx::PointF(),
385 gfx::Size(10, 12), true, false);
386 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
387 gfx::PointF(), gfx::Size(16, 18), true, false);
388 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
389 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
391 ExecuteCalculateDrawProperties(root
.get());
393 EXPECT_TRANSFORMATION_MATRIX_EQ(
394 identity_matrix
, DrawTransformFromPropertyTrees(child
.get(), tree
));
395 EXPECT_TRANSFORMATION_MATRIX_EQ(
397 ScreenSpaceTransformFromPropertyTrees(child
.get(), tree
));
398 EXPECT_TRANSFORMATION_MATRIX_EQ(
399 identity_matrix
, DrawTransformFromPropertyTrees(grand_child
.get(), tree
));
400 EXPECT_TRANSFORMATION_MATRIX_EQ(
402 ScreenSpaceTransformFromPropertyTrees(grand_child
.get(), tree
));
404 // Case 2: parent's position affects child and grand_child.
405 gfx::Transform parent_position_transform
;
406 parent_position_transform
.Translate(0.f
, 1.2f
);
407 SetLayerPropertiesForTesting(
408 parent
.get(), identity_matrix
, gfx::Point3F(2.5f
, 3.0f
, 0.f
),
409 gfx::PointF(0.f
, 1.2f
), gfx::Size(10, 12), true, false);
410 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
411 gfx::PointF(), gfx::Size(16, 18), true, false);
412 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
413 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
415 ExecuteCalculateDrawProperties(root
.get());
416 EXPECT_TRANSFORMATION_MATRIX_EQ(
417 parent_position_transform
,
418 DrawTransformFromPropertyTrees(child
.get(), tree
));
419 EXPECT_TRANSFORMATION_MATRIX_EQ(
420 parent_position_transform
,
421 ScreenSpaceTransformFromPropertyTrees(child
.get(), tree
));
422 EXPECT_TRANSFORMATION_MATRIX_EQ(
423 parent_position_transform
,
424 DrawTransformFromPropertyTrees(grand_child
.get(), tree
));
425 EXPECT_TRANSFORMATION_MATRIX_EQ(
426 parent_position_transform
,
427 ScreenSpaceTransformFromPropertyTrees(grand_child
.get(), tree
));
429 // Case 3: parent's local transform affects child and grandchild
430 gfx::Transform parent_layer_transform
;
431 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
432 gfx::Transform parent_translation_to_anchor
;
433 parent_translation_to_anchor
.Translate(2.5, 3.0);
434 gfx::Transform parent_composite_transform
=
435 parent_translation_to_anchor
* parent_layer_transform
*
436 Inverse(parent_translation_to_anchor
);
437 SetLayerPropertiesForTesting(parent
.get(), parent_layer_transform
,
438 gfx::Point3F(2.5f
, 3.0f
, 0.f
), gfx::PointF(),
439 gfx::Size(10, 12), true, false);
440 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
441 gfx::PointF(), gfx::Size(16, 18), true, false);
442 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
443 gfx::Point3F(), gfx::PointF(), gfx::Size(76, 78),
445 ExecuteCalculateDrawProperties(root
.get());
446 EXPECT_TRANSFORMATION_MATRIX_EQ(
447 parent_composite_transform
,
448 DrawTransformFromPropertyTrees(child
.get(), tree
));
449 EXPECT_TRANSFORMATION_MATRIX_EQ(
450 parent_composite_transform
,
451 ScreenSpaceTransformFromPropertyTrees(child
.get(), tree
));
452 EXPECT_TRANSFORMATION_MATRIX_EQ(
453 parent_composite_transform
,
454 DrawTransformFromPropertyTrees(grand_child
.get(), tree
));
455 EXPECT_TRANSFORMATION_MATRIX_EQ(
456 parent_composite_transform
,
457 ScreenSpaceTransformFromPropertyTrees(grand_child
.get(), tree
));
460 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleRenderSurface
) {
461 LayerImpl
* root
= root_layer();
462 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
463 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
464 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
465 grand_child
->SetDrawsContent(true);
467 gfx::Transform identity_matrix
;
468 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
469 gfx::PointF(), gfx::Size(1, 2), true, false,
472 // Child is set up so that a new render surface should be created.
473 child
->SetOpacity(0.5f
);
475 gfx::Transform parent_layer_transform
;
476 parent_layer_transform
.Scale3d(1.f
, 0.9f
, 1.f
);
477 gfx::Transform parent_translation_to_anchor
;
478 parent_translation_to_anchor
.Translate(25.0, 30.0);
480 gfx::Transform parent_composite_transform
=
481 parent_translation_to_anchor
* parent_layer_transform
*
482 Inverse(parent_translation_to_anchor
);
483 gfx::Vector2dF parent_composite_scale
=
484 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
486 gfx::Transform surface_sublayer_transform
;
487 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
488 parent_composite_scale
.y());
489 gfx::Transform surface_sublayer_composite_transform
=
490 parent_composite_transform
* Inverse(surface_sublayer_transform
);
492 SetLayerPropertiesForTesting(parent
, parent_layer_transform
,
493 gfx::Point3F(25.0f
, 30.0f
, 0.f
), gfx::PointF(),
494 gfx::Size(100, 120), true, false, false);
495 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
496 gfx::PointF(), gfx::Size(16, 18), true, false,
498 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
499 gfx::PointF(), gfx::Size(8, 10), true, false,
501 ExecuteCalculateDrawProperties(root
);
503 // Render surface should have been created now.
504 ASSERT_TRUE(child
->render_surface());
505 ASSERT_EQ(child
, child
->render_target());
507 // The child layer's draw transform should refer to its new render surface.
508 // The screen-space transform, however, should still refer to the root.
509 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform
,
510 child
->draw_transform());
511 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
512 child
->screen_space_transform());
514 // Because the grand_child is the only drawable content, the child's render
515 // surface will tighten its bounds to the grand_child. The scale at which the
516 // surface's subtree is drawn must be removed from the composite transform.
517 EXPECT_TRANSFORMATION_MATRIX_EQ(
518 surface_sublayer_composite_transform
,
519 child
->render_target()->render_surface()->draw_transform());
521 // The screen space is the same as the target since the child surface draws
523 EXPECT_TRANSFORMATION_MATRIX_EQ(
524 surface_sublayer_composite_transform
,
525 child
->render_target()->render_surface()->screen_space_transform());
528 TEST_F(LayerTreeHostCommonTest
, TransformsForReplica
) {
529 LayerImpl
* root
= root_layer();
530 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
531 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
532 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
533 grand_child
->SetDrawsContent(true);
534 scoped_ptr
<LayerImpl
> child_replica
=
535 LayerImpl::Create(host_impl()->active_tree(), 100);
537 // One-time setup of root layer
538 gfx::Transform identity_matrix
;
539 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
540 gfx::PointF(), gfx::Size(1, 2), true, false,
543 // Child is set up so that a new render surface should be created.
544 child
->SetOpacity(0.5f
);
546 gfx::Transform parent_layer_transform
;
547 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
548 gfx::Transform parent_translation_to_anchor
;
549 parent_translation_to_anchor
.Translate(2.5, 3.0);
550 gfx::Transform parent_composite_transform
=
551 parent_translation_to_anchor
* parent_layer_transform
*
552 Inverse(parent_translation_to_anchor
);
553 gfx::Transform replica_layer_transform
;
554 replica_layer_transform
.Scale3d(3.0, 3.0, 1.0);
555 gfx::Vector2dF parent_composite_scale
=
556 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
558 gfx::Transform surface_sublayer_transform
;
559 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
560 parent_composite_scale
.y());
561 gfx::Transform replica_composite_transform
=
562 parent_composite_transform
* replica_layer_transform
*
563 Inverse(surface_sublayer_transform
);
564 child_replica
->SetDrawsContent(true);
565 // Child's render surface should not exist yet.
566 ASSERT_FALSE(child
->render_surface());
568 SetLayerPropertiesForTesting(parent
, parent_layer_transform
,
569 gfx::Point3F(2.5f
, 3.0f
, 0.f
), gfx::PointF(),
570 gfx::Size(10, 12), true, false, false);
571 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
572 gfx::PointF(), gfx::Size(16, 18), true, false,
574 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
575 gfx::PointF(-0.5f
, -0.5f
), gfx::Size(1, 1), true,
577 SetLayerPropertiesForTesting(child_replica
.get(), replica_layer_transform
,
578 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
580 child
->SetReplicaLayer(child_replica
.Pass());
582 ExecuteCalculateDrawProperties(root
);
584 // Render surface should have been created now.
585 ASSERT_TRUE(child
->render_surface());
586 ASSERT_EQ(child
, child
->render_target());
588 EXPECT_TRANSFORMATION_MATRIX_EQ(
589 replica_composite_transform
,
590 child
->render_target()->render_surface()->replica_draw_transform());
591 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform
,
592 child
->render_target()
594 ->replica_screen_space_transform());
597 TEST_F(LayerTreeHostCommonTest
, TransformsForRenderSurfaceHierarchy
) {
598 // This test creates a more complex tree and verifies it all at once. This
599 // covers the following cases:
600 // - layers that are described w.r.t. a render surface: should have draw
601 // transforms described w.r.t. that surface
602 // - A render surface described w.r.t. an ancestor render surface: should
603 // have a draw transform described w.r.t. that ancestor surface
604 // - Replicas of a render surface are described w.r.t. the replica's
605 // transform around its anchor, along with the surface itself.
606 // - Sanity check on recursion: verify transforms of layers described w.r.t.
607 // a render surface that is described w.r.t. an ancestor render surface.
608 // - verifying that each layer has a reference to the correct render surface
609 // and render target values.
611 LayerImpl
* root
= root_layer();
612 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
613 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(parent
);
614 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
615 LayerImpl
* child_of_root
= AddChild
<LayerImpl
>(parent
);
616 LayerImpl
* child_of_rs1
= AddChild
<LayerImpl
>(render_surface1
);
617 LayerImpl
* child_of_rs2
= AddChild
<LayerImpl
>(render_surface2
);
618 LayerImpl
* grand_child_of_root
= AddChild
<LayerImpl
>(child_of_root
);
619 LayerImpl
* grand_child_of_rs1
= AddChild
<LayerImpl
>(child_of_rs1
);
620 grand_child_of_rs1
->SetDrawsContent(true);
621 LayerImpl
* grand_child_of_rs2
= AddChild
<LayerImpl
>(child_of_rs2
);
622 grand_child_of_rs2
->SetDrawsContent(true);
624 scoped_ptr
<LayerImpl
> replica_of_rs1
=
625 LayerImpl::Create(host_impl()->active_tree(), 101);
626 scoped_ptr
<LayerImpl
> replica_of_rs2
=
627 LayerImpl::Create(host_impl()->active_tree(), 102);
629 // In combination with descendant draws content, opacity != 1 forces the layer
630 // to have a new render surface.
631 render_surface1
->SetOpacity(0.5f
);
632 render_surface2
->SetOpacity(0.33f
);
634 // One-time setup of root layer
635 gfx::Transform identity_matrix
;
636 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
637 gfx::PointF(), gfx::Size(1, 2), true, false,
640 // All layers in the tree are initialized with an anchor at .25 and a size of
641 // (10,10). matrix "A" is the composite layer transform used in all layers,
642 // Matrix "R" is the composite replica transform used in all replica layers.
643 gfx::Transform translation_to_anchor
;
644 translation_to_anchor
.Translate(2.5, 0.0);
645 gfx::Transform layer_transform
;
646 layer_transform
.Translate(1.0, 1.0);
647 gfx::Transform replica_layer_transform
;
648 replica_layer_transform
.Scale3d(-2.0, 5.0, 1.0);
651 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
652 gfx::Transform R
= A
* translation_to_anchor
* replica_layer_transform
*
653 Inverse(translation_to_anchor
);
655 gfx::Vector2dF surface1_parent_transform_scale
=
656 MathUtil::ComputeTransform2dScaleComponents(A
, 1.f
);
657 gfx::Transform surface1_sublayer_transform
;
658 surface1_sublayer_transform
.Scale(surface1_parent_transform_scale
.x(),
659 surface1_parent_transform_scale
.y());
661 // SS1 = transform given to the subtree of render_surface1
662 gfx::Transform SS1
= surface1_sublayer_transform
;
663 // S1 = transform to move from render_surface1 pixels to the layer space of
665 gfx::Transform S1
= Inverse(surface1_sublayer_transform
);
667 gfx::Vector2dF surface2_parent_transform_scale
=
668 MathUtil::ComputeTransform2dScaleComponents(SS1
* A
, 1.f
);
669 gfx::Transform surface2_sublayer_transform
;
670 surface2_sublayer_transform
.Scale(surface2_parent_transform_scale
.x(),
671 surface2_parent_transform_scale
.y());
673 // SS2 = transform given to the subtree of render_surface2
674 gfx::Transform SS2
= surface2_sublayer_transform
;
675 // S2 = transform to move from render_surface2 pixels to the layer space of
677 gfx::Transform S2
= Inverse(surface2_sublayer_transform
);
679 SetLayerPropertiesForTesting(parent
, layer_transform
,
680 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
681 gfx::Size(10, 10), true, false, false);
682 SetLayerPropertiesForTesting(render_surface1
, layer_transform
,
683 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
684 gfx::Size(10, 10), true, false, true);
685 SetLayerPropertiesForTesting(render_surface2
, layer_transform
,
686 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
687 gfx::Size(10, 10), true, false, true);
688 SetLayerPropertiesForTesting(child_of_root
, layer_transform
,
689 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
690 gfx::Size(10, 10), true, false, false);
691 SetLayerPropertiesForTesting(child_of_rs1
, layer_transform
,
692 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
693 gfx::Size(10, 10), true, false, false);
694 SetLayerPropertiesForTesting(child_of_rs2
, layer_transform
,
695 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
696 gfx::Size(10, 10), true, false, false);
697 SetLayerPropertiesForTesting(grand_child_of_root
, layer_transform
,
698 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
699 gfx::Size(10, 10), true, false, false);
700 SetLayerPropertiesForTesting(grand_child_of_rs1
, layer_transform
,
701 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
702 gfx::Size(10, 10), true, false, false);
703 SetLayerPropertiesForTesting(grand_child_of_rs2
, layer_transform
,
704 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
705 gfx::Size(10, 10), true, false, false);
706 SetLayerPropertiesForTesting(replica_of_rs1
.get(), replica_layer_transform
,
707 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
708 gfx::Size(), true, false, false);
709 SetLayerPropertiesForTesting(replica_of_rs2
.get(), replica_layer_transform
,
710 gfx::Point3F(2.5f
, 0.f
, 0.f
), gfx::PointF(),
711 gfx::Size(), true, false, false);
713 render_surface1
->SetReplicaLayer(replica_of_rs1
.Pass());
714 render_surface2
->SetReplicaLayer(replica_of_rs2
.Pass());
715 ExecuteCalculateDrawProperties(root
);
717 // Only layers that are associated with render surfaces should have an actual
718 // RenderSurface() value.
719 ASSERT_TRUE(root
->render_surface());
720 ASSERT_FALSE(child_of_root
->render_surface());
721 ASSERT_FALSE(grand_child_of_root
->render_surface());
723 ASSERT_TRUE(render_surface1
->render_surface());
724 ASSERT_FALSE(child_of_rs1
->render_surface());
725 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
727 ASSERT_TRUE(render_surface2
->render_surface());
728 ASSERT_FALSE(child_of_rs2
->render_surface());
729 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
731 // Verify all render target accessors
732 EXPECT_EQ(root
, parent
->render_target());
733 EXPECT_EQ(root
, child_of_root
->render_target());
734 EXPECT_EQ(root
, grand_child_of_root
->render_target());
736 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
737 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
738 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
740 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
741 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
742 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
744 // Verify layer draw transforms note that draw transforms are described with
745 // respect to the nearest ancestor render surface but screen space transforms
746 // are described with respect to the root.
747 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->draw_transform());
748 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
, child_of_root
->draw_transform());
749 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
750 grand_child_of_root
->draw_transform());
752 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
, render_surface1
->draw_transform());
753 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
, child_of_rs1
->draw_transform());
754 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
* A
,
755 grand_child_of_rs1
->draw_transform());
757 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
, render_surface2
->draw_transform());
758 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
, child_of_rs2
->draw_transform());
759 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
* A
,
760 grand_child_of_rs2
->draw_transform());
762 // Verify layer screen-space transforms
764 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->screen_space_transform());
765 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
766 child_of_root
->screen_space_transform());
767 EXPECT_TRANSFORMATION_MATRIX_EQ(
768 A
* A
* A
, grand_child_of_root
->screen_space_transform());
770 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
771 render_surface1
->screen_space_transform());
772 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
773 child_of_rs1
->screen_space_transform());
774 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
775 grand_child_of_rs1
->screen_space_transform());
777 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
778 render_surface2
->screen_space_transform());
779 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
780 child_of_rs2
->screen_space_transform());
781 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
* A
,
782 grand_child_of_rs2
->screen_space_transform());
784 // Verify render surface transforms.
786 // Draw transform of render surface 1 is described with respect to root.
787 EXPECT_TRANSFORMATION_MATRIX_EQ(
788 A
* A
* S1
, render_surface1
->render_surface()->draw_transform());
789 EXPECT_TRANSFORMATION_MATRIX_EQ(
790 A
* R
* S1
, render_surface1
->render_surface()->replica_draw_transform());
791 EXPECT_TRANSFORMATION_MATRIX_EQ(
792 A
* A
* S1
, render_surface1
->render_surface()->screen_space_transform());
793 EXPECT_TRANSFORMATION_MATRIX_EQ(
795 render_surface1
->render_surface()->replica_screen_space_transform());
796 // Draw transform of render surface 2 is described with respect to render
798 EXPECT_TRANSFORMATION_MATRIX_EQ(
799 SS1
* A
* S2
, render_surface2
->render_surface()->draw_transform());
800 EXPECT_TRANSFORMATION_MATRIX_EQ(
802 render_surface2
->render_surface()->replica_draw_transform());
803 EXPECT_TRANSFORMATION_MATRIX_EQ(
805 render_surface2
->render_surface()->screen_space_transform());
806 EXPECT_TRANSFORMATION_MATRIX_EQ(
808 render_surface2
->render_surface()->replica_screen_space_transform());
810 // Sanity check. If these fail there is probably a bug in the test itself. It
811 // is expected that we correctly set up transforms so that the y-component of
812 // the screen-space transform encodes the "depth" of the layer in the tree.
813 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
815 child_of_root
->screen_space_transform().matrix().get(1, 3));
817 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
820 render_surface1
->screen_space_transform().matrix().get(1, 3));
822 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
824 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
827 render_surface2
->screen_space_transform().matrix().get(1, 3));
829 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
831 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
834 TEST_F(LayerTreeHostCommonTest
, TransformsForFlatteningLayer
) {
835 // For layers that flatten their subtree, there should be an orthographic
836 // projection (for x and y values) in the middle of the transform sequence.
837 // Note that the way the code is currently implemented, it is not expected to
838 // use a canonical orthographic projection.
840 LayerImpl
* root
= root_layer();
841 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
842 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
843 grand_child
->SetDrawsContent(true);
844 LayerImpl
* great_grand_child
= AddChild
<LayerImpl
>(grand_child
);
845 great_grand_child
->SetDrawsContent(true);
847 gfx::Transform rotation_about_y_axis
;
848 rotation_about_y_axis
.RotateAboutYAxis(30.0);
850 const gfx::Transform identity_matrix
;
851 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
852 gfx::PointF(), gfx::Size(100, 100), true, false,
854 SetLayerPropertiesForTesting(child
, rotation_about_y_axis
, gfx::Point3F(),
855 gfx::PointF(), gfx::Size(10, 10), true, false,
857 SetLayerPropertiesForTesting(grand_child
, rotation_about_y_axis
,
858 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
860 SetLayerPropertiesForTesting(great_grand_child
, identity_matrix
,
861 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
864 // No layers in this test should preserve 3d.
865 ASSERT_TRUE(root
->should_flatten_transform());
866 ASSERT_TRUE(child
->should_flatten_transform());
867 ASSERT_TRUE(grand_child
->should_flatten_transform());
868 ASSERT_TRUE(great_grand_child
->should_flatten_transform());
870 gfx::Transform expected_child_draw_transform
= rotation_about_y_axis
;
871 gfx::Transform expected_child_screen_space_transform
= rotation_about_y_axis
;
872 gfx::Transform expected_grand_child_draw_transform
=
873 rotation_about_y_axis
; // draws onto child's render surface
874 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
875 flattened_rotation_about_y
.FlattenTo2d();
876 gfx::Transform expected_grand_child_screen_space_transform
=
877 flattened_rotation_about_y
* rotation_about_y_axis
;
878 gfx::Transform expected_great_grand_child_draw_transform
=
879 flattened_rotation_about_y
;
880 gfx::Transform expected_great_grand_child_screen_space_transform
=
881 flattened_rotation_about_y
* flattened_rotation_about_y
;
883 ExecuteCalculateDrawProperties(root
);
885 // The child's draw transform should have been taken by its surface.
886 ASSERT_TRUE(child
->render_surface());
887 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform
,
888 child
->render_surface()->draw_transform());
889 EXPECT_TRANSFORMATION_MATRIX_EQ(
890 expected_child_screen_space_transform
,
891 child
->render_surface()->screen_space_transform());
892 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
893 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform
,
894 child
->screen_space_transform());
895 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform
,
896 grand_child
->draw_transform());
897 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform
,
898 grand_child
->screen_space_transform());
899 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform
,
900 great_grand_child
->draw_transform());
901 EXPECT_TRANSFORMATION_MATRIX_EQ(
902 expected_great_grand_child_screen_space_transform
,
903 great_grand_child
->screen_space_transform());
906 TEST_F(LayerTreeHostCommonTest
, LayerFullyContainedWithinClipInTargetSpace
) {
907 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
908 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
909 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
910 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
912 gfx::Transform child_transform
;
913 child_transform
.Translate(50.0, 50.0);
914 child_transform
.RotateAboutZAxis(30.0);
916 gfx::Transform grand_child_transform
;
917 grand_child_transform
.RotateAboutYAxis(90.0);
919 const gfx::Transform identity_matrix
;
920 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
921 gfx::PointF(), gfx::Size(200, 200), true, false);
922 SetLayerPropertiesForTesting(child
.get(), child_transform
, gfx::Point3F(),
923 gfx::PointF(), gfx::Size(10, 10), true, false);
924 SetLayerPropertiesForTesting(grand_child
.get(), grand_child_transform
,
925 gfx::Point3F(), gfx::PointF(),
926 gfx::Size(100, 100), true, false);
928 root
->AddChild(child
);
929 child
->AddChild(grand_child
);
930 grand_child
->SetShouldFlattenTransform(false);
932 host()->SetRootLayer(root
);
934 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
936 // Mapping grand_child's bounds to target space produces a non-empty rect
937 // that is fully contained within the target's bounds, so grand_child should
938 // be considered fully visible.
939 EXPECT_EQ(gfx::Rect(grand_child
->bounds()),
940 grand_child
->visible_rect_from_property_trees());
943 TEST_F(LayerTreeHostCommonTest
, TransformsForDegenerateIntermediateLayer
) {
944 // A layer that is empty in one axis, but not the other, was accidentally
945 // skipping a necessary translation. Without that translation, the coordinate
946 // space of the layer's draw transform is incorrect.
948 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
949 // but if that layer becomes a render surface, then its draw transform is
950 // implicitly inherited by the rest of the subtree, which then is positioned
951 // incorrectly as a result.
953 LayerImpl
* root
= root_layer();
954 LayerImpl
* child
= AddChild
<LayerImpl
>(root
);
955 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
956 grand_child
->SetDrawsContent(true);
958 // The child height is zero, but has non-zero width that should be accounted
959 // for while computing draw transforms.
960 const gfx::Transform identity_matrix
;
961 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
962 gfx::PointF(), gfx::Size(100, 100), true, false,
964 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
965 gfx::PointF(), gfx::Size(10, 0), true, false,
967 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
968 gfx::PointF(), gfx::Size(10, 10), true, false,
971 ExecuteCalculateDrawProperties(root
);
973 ASSERT_TRUE(child
->has_render_surface());
974 // This is the real test, the rest are sanity checks.
975 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
976 child
->render_surface()->draw_transform());
977 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
978 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
979 grand_child
->draw_transform());
982 TEST_F(LayerTreeHostCommonTest
, TransformAboveRootLayer
) {
983 // Transformations applied at the root of the tree should be forwarded
984 // to child layers instead of applied to the root RenderSurface.
985 const gfx::Transform identity_matrix
;
986 LayerImpl
* root
= root_layer();
987 root
->SetDrawsContent(true);
988 LayerImpl
* child
= AddChild
<LayerImpl
>(root
);
989 child
->SetDrawsContent(true);
991 child
->SetScrollClipLayer(root
->id());
993 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
994 gfx::PointF(), gfx::Size(20, 20), true, false,
996 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
997 gfx::PointF(), gfx::Size(20, 20), true, false,
1000 gfx::Transform translate
;
1001 translate
.Translate(50, 50);
1003 LayerImplList render_surface_layer_list_impl
;
1004 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1005 root
, root
->bounds(), translate
, &render_surface_layer_list_impl
);
1006 inputs
.property_trees
->needs_rebuild
= true;
1007 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1008 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1009 EXPECT_EQ(translate
, child
->draw_properties().target_space_transform
);
1010 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1013 gfx::Transform scale
;
1016 LayerImplList render_surface_layer_list_impl
;
1017 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1018 root
, root
->bounds(), scale
, &render_surface_layer_list_impl
);
1019 inputs
.property_trees
->needs_rebuild
= true;
1020 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1021 EXPECT_EQ(scale
, root
->draw_properties().target_space_transform
);
1022 EXPECT_EQ(scale
, child
->draw_properties().target_space_transform
);
1023 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1026 gfx::Transform rotate
;
1029 LayerImplList render_surface_layer_list_impl
;
1030 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1031 root
, root
->bounds(), rotate
, &render_surface_layer_list_impl
);
1032 inputs
.property_trees
->needs_rebuild
= true;
1033 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1034 EXPECT_EQ(rotate
, root
->draw_properties().target_space_transform
);
1035 EXPECT_EQ(rotate
, child
->draw_properties().target_space_transform
);
1036 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1039 gfx::Transform composite
;
1040 composite
.ConcatTransform(translate
);
1041 composite
.ConcatTransform(scale
);
1042 composite
.ConcatTransform(rotate
);
1044 LayerImplList render_surface_layer_list_impl
;
1045 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1046 root
, root
->bounds(), composite
, &render_surface_layer_list_impl
);
1047 inputs
.property_trees
->needs_rebuild
= true;
1048 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1049 EXPECT_EQ(composite
, root
->draw_properties().target_space_transform
);
1050 EXPECT_EQ(composite
, child
->draw_properties().target_space_transform
);
1051 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1054 // Verify it composes correctly with device scale.
1055 float device_scale_factor
= 1.5f
;
1058 LayerImplList render_surface_layer_list_impl
;
1059 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1060 root
, root
->bounds(), translate
, &render_surface_layer_list_impl
);
1061 inputs
.device_scale_factor
= device_scale_factor
;
1062 inputs
.property_trees
->needs_rebuild
= true;
1063 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1064 gfx::Transform device_scaled_translate
= translate
;
1065 device_scaled_translate
.Scale(device_scale_factor
, device_scale_factor
);
1066 EXPECT_EQ(device_scaled_translate
,
1067 root
->draw_properties().target_space_transform
);
1068 EXPECT_EQ(device_scaled_translate
,
1069 child
->draw_properties().target_space_transform
);
1070 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1073 // Verify it composes correctly with page scale.
1074 float page_scale_factor
= 2.f
;
1077 LayerImplList render_surface_layer_list_impl
;
1078 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1079 root
, root
->bounds(), translate
, &render_surface_layer_list_impl
);
1080 inputs
.page_scale_factor
= page_scale_factor
;
1081 inputs
.page_scale_layer
= root
;
1082 inputs
.property_trees
->needs_rebuild
= true;
1083 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1084 gfx::Transform page_scaled_translate
= translate
;
1085 page_scaled_translate
.Scale(page_scale_factor
, page_scale_factor
);
1086 EXPECT_EQ(page_scaled_translate
,
1087 root
->draw_properties().target_space_transform
);
1088 EXPECT_EQ(page_scaled_translate
,
1089 child
->draw_properties().target_space_transform
);
1090 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1093 // Verify that it composes correctly with transforms directly on root layer.
1094 root
->SetTransform(composite
);
1097 LayerImplList render_surface_layer_list_impl
;
1098 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1099 root
, root
->bounds(), composite
, &render_surface_layer_list_impl
);
1100 inputs
.property_trees
->needs_rebuild
= true;
1101 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1102 gfx::Transform compositeSquared
= composite
;
1103 compositeSquared
.ConcatTransform(composite
);
1104 EXPECT_TRANSFORMATION_MATRIX_EQ(
1105 compositeSquared
, root
->draw_properties().target_space_transform
);
1106 EXPECT_TRANSFORMATION_MATRIX_EQ(
1107 compositeSquared
, child
->draw_properties().target_space_transform
);
1108 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1112 TEST_F(LayerTreeHostCommonTest
,
1113 RenderSurfaceListForRenderSurfaceWithClippedLayer
) {
1114 LayerImpl
* parent
= root_layer();
1115 parent
->SetMasksToBounds(true);
1116 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
1117 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface1
);
1118 child
->SetDrawsContent(true);
1120 const gfx::Transform identity_matrix
;
1121 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1122 gfx::PointF(), gfx::Size(10, 10), true, false,
1124 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
1125 gfx::PointF(), gfx::Size(10, 10), true, false,
1127 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1128 gfx::PointF(30.f
, 30.f
), gfx::Size(10, 10), true,
1131 ExecuteCalculateDrawProperties(parent
);
1133 // The child layer's content is entirely outside the parent's clip rect, so
1134 // the intermediate render surface should not be listed here, even if it was
1135 // forced to be created. Render surfaces without children or visible content
1136 // are unexpected at draw time (e.g. we might try to create a content texture
1138 ASSERT_TRUE(parent
->render_surface());
1139 EXPECT_EQ(1U, render_surface_layer_list_impl()->size());
1142 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceListForTransparentChild
) {
1143 LayerImpl
* parent
= root_layer();
1144 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(parent
);
1145 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface1
);
1146 child
->SetDrawsContent(true);
1148 const gfx::Transform identity_matrix
;
1149 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
1150 gfx::PointF(), gfx::Size(10, 10), true, false,
1152 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1153 gfx::PointF(), gfx::Size(10, 10), true, false,
1155 render_surface1
->SetOpacity(0.f
);
1157 LayerImplList render_surface_layer_list
;
1158 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1159 parent
, parent
->bounds(), &render_surface_layer_list
);
1160 inputs
.can_adjust_raster_scales
= true;
1161 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1163 // Since the layer is transparent, render_surface1->render_surface() should
1164 // not have gotten added anywhere. Also, the drawable content rect should not
1165 // have been extended by the children.
1166 ASSERT_TRUE(parent
->render_surface());
1167 EXPECT_EQ(0U, parent
->render_surface()->layer_list().size());
1168 EXPECT_EQ(1U, render_surface_layer_list
.size());
1169 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1170 EXPECT_EQ(gfx::Rect(), parent
->drawable_content_rect());
1173 TEST_F(LayerTreeHostCommonTest
,
1174 RenderSurfaceListForTransparentChildWithBackgroundFilter
) {
1175 LayerImpl
* parent
= root_layer();
1176 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(parent
);
1177 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface1
);
1178 child
->SetDrawsContent(true);
1180 const gfx::Transform identity_matrix
;
1181 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1182 gfx::PointF(), gfx::Size(10, 10), true, false,
1184 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
1185 gfx::PointF(), gfx::Size(10, 10), true, false,
1187 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1188 gfx::PointF(), gfx::Size(10, 10), true, false,
1190 render_surface1
->SetOpacity(0.f
);
1191 FilterOperations filters
;
1192 filters
.Append(FilterOperation::CreateBlurFilter(1.5f
));
1193 render_surface1
->SetBackgroundFilters(filters
);
1195 LayerImplList render_surface_layer_list
;
1196 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
1197 parent
, parent
->bounds(), &render_surface_layer_list
);
1198 inputs
.can_adjust_raster_scales
= true;
1199 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1201 // The layer is fully transparent, but has a background filter, so it
1202 // shouldn't be skipped.
1203 ASSERT_TRUE(parent
->render_surface());
1204 EXPECT_EQ(1U, parent
->render_surface()->layer_list().size());
1205 EXPECT_EQ(2U, render_surface_layer_list
.size());
1206 EXPECT_EQ(gfx::Rect(0, 0, 10, 10), parent
->drawable_content_rect());
1209 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceForBlendMode
) {
1210 LayerImpl
* parent
= root_layer();
1211 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
1212 child
->SetDrawsContent(true);
1214 const gfx::Transform identity_matrix
;
1215 const SkXfermode::Mode blend_mode
= SkXfermode::kMultiply_Mode
;
1216 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1217 gfx::PointF(), gfx::Size(10, 10), true, false,
1219 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1220 gfx::PointF(), gfx::Size(10, 10), true, false,
1223 child
->SetBlendMode(blend_mode
);
1224 child
->SetOpacity(0.5f
);
1226 ExecuteCalculateDrawProperties(parent
);
1228 // Since the child layer has a blend mode other than normal, it should get
1229 // its own render surface. Also, layer's draw_properties should contain the
1230 // default blend mode, since the render surface becomes responsible for
1231 // applying the blend mode.
1232 ASSERT_TRUE(child
->render_surface());
1233 EXPECT_EQ(1.0f
, child
->draw_opacity());
1234 EXPECT_EQ(0.5f
, child
->render_surface()->draw_opacity());
1235 EXPECT_EQ(SkXfermode::kSrcOver_Mode
, child
->draw_blend_mode());
1238 TEST_F(LayerTreeHostCommonTest
, ForceRenderSurface
) {
1239 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1240 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
1241 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1242 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1243 render_surface1
->SetForceRenderSurface(true);
1245 host()->SetRootLayer(parent
);
1247 const gfx::Transform identity_matrix
;
1248 SetLayerPropertiesForTesting(parent
.get(),
1255 SetLayerPropertiesForTesting(render_surface1
.get(),
1262 SetLayerPropertiesForTesting(child
.get(),
1270 parent
->AddChild(render_surface1
);
1271 render_surface1
->AddChild(child
);
1273 // Sanity check before the actual test
1274 EXPECT_FALSE(parent
->has_render_surface());
1275 EXPECT_FALSE(render_surface1
->has_render_surface());
1278 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(parent
.get(),
1280 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1282 // The root layer always creates a render surface
1283 EXPECT_TRUE(parent
->has_render_surface());
1284 EXPECT_TRUE(render_surface1
->has_render_surface());
1288 render_surface1
->SetForceRenderSurface(false);
1289 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(parent
.get(),
1291 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1292 EXPECT_TRUE(parent
->has_render_surface());
1293 EXPECT_FALSE(render_surface1
->has_render_surface());
1297 TEST_F(LayerTreeHostCommonTest
, RenderSurfacesFlattenScreenSpaceTransform
) {
1298 // Render surfaces act as a flattening point for their subtree, so should
1299 // always flatten the target-to-screen space transform seen by descendants.
1301 LayerImpl
* root
= root_layer();
1302 LayerImpl
* parent
= AddChild
<LayerImpl
>(root
);
1303 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
1304 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
1306 child
->SetDrawsContent(true);
1307 grand_child
->SetDrawsContent(true);
1309 gfx::Transform rotation_about_y_axis
;
1310 rotation_about_y_axis
.RotateAboutYAxis(30.0);
1311 // Make |parent| have a render surface.
1312 parent
->SetOpacity(0.9f
);
1314 const gfx::Transform identity_matrix
;
1315 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
1316 gfx::PointF(), gfx::Size(100, 100), true, false,
1318 SetLayerPropertiesForTesting(parent
, rotation_about_y_axis
, gfx::Point3F(),
1319 gfx::PointF(), gfx::Size(10, 10), true, false,
1321 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1322 gfx::PointF(), gfx::Size(10, 10), true, false,
1324 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1325 gfx::PointF(), gfx::Size(10, 10), true, false,
1328 grand_child
->SetShouldFlattenTransform(false);
1330 // Only grand_child should preserve 3d.
1331 EXPECT_TRUE(root
->should_flatten_transform());
1332 EXPECT_TRUE(parent
->should_flatten_transform());
1333 EXPECT_TRUE(child
->should_flatten_transform());
1334 EXPECT_FALSE(grand_child
->should_flatten_transform());
1336 gfx::Transform expected_child_draw_transform
= identity_matrix
;
1337 gfx::Transform expected_grand_child_draw_transform
= identity_matrix
;
1339 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
1340 flattened_rotation_about_y
.FlattenTo2d();
1342 ExecuteCalculateDrawProperties(root
);
1344 EXPECT_TRUE(parent
->render_surface());
1345 EXPECT_FALSE(child
->render_surface());
1346 EXPECT_FALSE(grand_child
->render_surface());
1348 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1349 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1350 grand_child
->draw_transform());
1352 // The screen-space transform inherited by |child| and |grand_child| should
1353 // have been flattened at their render target. In particular, the fact that
1354 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1355 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y
,
1356 child
->screen_space_transform());
1357 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y
,
1358 grand_child
->screen_space_transform());
1361 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsRenderSurfaces
) {
1362 // The entire subtree of layers that are outside the clip rect should be
1363 // culled away, and should not affect the render_surface_layer_list.
1365 // The test tree is set up as follows:
1366 // - all layers except the leaf_nodes are forced to be a new render surface
1367 // that have something to draw.
1368 // - parent is a large container layer.
1369 // - child has masksToBounds=true to cause clipping.
1370 // - grand_child is positioned outside of the child's bounds
1371 // - great_grand_child is also kept outside child's bounds.
1373 // In this configuration, grand_child and great_grand_child are completely
1374 // outside the clip rect, and they should never get scheduled on the list of
1377 LayerImpl
* parent
= root_layer();
1378 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1379 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
1380 LayerImpl
* great_grand_child
= AddChild
<LayerImpl
>(grand_child
);
1382 // leaf_node1 ensures that parent and child are kept on the
1383 // render_surface_layer_list, even though grand_child and great_grand_child
1384 // should be clipped.
1385 LayerImpl
* leaf_node1
= AddChild
<LayerImpl
>(child
);
1386 leaf_node1
->SetDrawsContent(true);
1387 LayerImpl
* leaf_node2
= AddChild
<LayerImpl
>(great_grand_child
);
1388 leaf_node2
->SetDrawsContent(true);
1390 const gfx::Transform identity_matrix
;
1392 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1393 gfx::PointF(), gfx::Size(500, 500), true, false,
1395 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1396 gfx::PointF(), gfx::Size(20, 20), true, false,
1398 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1399 gfx::PointF(45.f
, 45.f
), gfx::Size(10, 10), true,
1401 SetLayerPropertiesForTesting(great_grand_child
, identity_matrix
,
1402 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1403 true, false, false);
1404 SetLayerPropertiesForTesting(leaf_node1
, identity_matrix
, gfx::Point3F(),
1405 gfx::PointF(), gfx::Size(500, 500), true, false,
1407 SetLayerPropertiesForTesting(leaf_node2
, identity_matrix
, gfx::Point3F(),
1408 gfx::PointF(), gfx::Size(20, 20), true, false,
1411 child
->SetMasksToBounds(true);
1412 child
->SetOpacity(0.4f
);
1413 grand_child
->SetOpacity(0.5f
);
1414 great_grand_child
->SetOpacity(0.4f
);
1416 ExecuteCalculateDrawProperties(parent
);
1418 ASSERT_EQ(2U, render_surface_layer_list_impl()->size());
1419 EXPECT_EQ(parent
->id(), render_surface_layer_list_impl()->at(0)->id());
1420 EXPECT_EQ(child
->id(), render_surface_layer_list_impl()->at(1)->id());
1423 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsSurfaceWithoutVisibleContent
) {
1424 // When a render surface has a clip rect, it is used to clip the content rect
1427 // The test tree is set up as follows:
1428 // - parent is a container layer that masksToBounds=true to cause clipping.
1429 // - child is a render surface, which has a clip rect set to the bounds of
1431 // - grand_child is a render surface, and the only visible content in child.
1432 // It is positioned outside of the clip rect from parent.
1434 // In this configuration, grand_child should be outside the clipped
1435 // content rect of the child, making grand_child not appear in the
1436 // render_surface_layer_list.
1438 LayerImpl
* parent
= root_layer();
1439 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1440 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
1441 LayerImpl
* leaf_node
= AddChild
<LayerImpl
>(grand_child
);
1442 leaf_node
->SetDrawsContent(true);
1444 const gfx::Transform identity_matrix
;
1446 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1447 gfx::PointF(), gfx::Size(100, 100), true, false,
1449 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1450 gfx::PointF(), gfx::Size(20, 20), true, false,
1452 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1453 gfx::PointF(200.f
, 200.f
), gfx::Size(10, 10),
1455 SetLayerPropertiesForTesting(leaf_node
, identity_matrix
, gfx::Point3F(),
1456 gfx::PointF(), gfx::Size(10, 10), true, false,
1459 parent
->SetMasksToBounds(true);
1460 child
->SetOpacity(0.4f
);
1461 grand_child
->SetOpacity(0.4f
);
1463 ExecuteCalculateDrawProperties(parent
);
1465 // We should cull child and grand_child from the
1466 // render_surface_layer_list.
1467 ASSERT_EQ(1U, render_surface_layer_list_impl()->size());
1468 EXPECT_EQ(parent
->id(), render_surface_layer_list_impl()->at(0)->id());
1471 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectly
) {
1472 // Layer's IsClipped() property is set to true when:
1473 // - the layer clips its subtree, e.g. masks to bounds,
1474 // - the layer is clipped by an ancestor that contributes to the same
1476 // - a surface is clipped by an ancestor that contributes to the same
1479 // In particular, for a layer that owns a render surface:
1480 // - the render surface inherits any clip from ancestors, and does NOT
1481 // pass that clipped status to the layer itself.
1482 // - but if the layer itself masks to bounds, it is considered clipped
1483 // and propagates the clip to the subtree.
1485 const gfx::Transform identity_matrix
;
1486 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1487 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1488 scoped_refptr
<Layer
> child1
= Layer::Create(layer_settings());
1489 scoped_refptr
<Layer
> child2
= Layer::Create(layer_settings());
1490 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
1491 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1492 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1493 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1494 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1495 root
->AddChild(parent
);
1496 parent
->AddChild(child1
);
1497 parent
->AddChild(child2
);
1498 child1
->AddChild(grand_child
);
1499 child2
->AddChild(leaf_node2
);
1500 grand_child
->AddChild(leaf_node1
);
1502 host()->SetRootLayer(root
);
1504 child2
->SetForceRenderSurface(true);
1506 SetLayerPropertiesForTesting(root
.get(),
1510 gfx::Size(100, 100),
1513 SetLayerPropertiesForTesting(parent
.get(),
1517 gfx::Size(100, 100),
1520 SetLayerPropertiesForTesting(child1
.get(),
1524 gfx::Size(100, 100),
1527 SetLayerPropertiesForTesting(child2
.get(),
1531 gfx::Size(100, 100),
1534 SetLayerPropertiesForTesting(grand_child
.get(),
1538 gfx::Size(100, 100),
1541 SetLayerPropertiesForTesting(leaf_node1
.get(),
1545 gfx::Size(100, 100),
1548 SetLayerPropertiesForTesting(leaf_node2
.get(),
1552 gfx::Size(100, 100),
1556 // Case 1: nothing is clipped except the root render surface.
1558 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(root
.get(),
1560 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1562 ASSERT_TRUE(root
->has_render_surface());
1563 ASSERT_TRUE(child2
->has_render_surface());
1565 EXPECT_FALSE(root
->is_clipped());
1566 EXPECT_FALSE(parent
->is_clipped());
1567 EXPECT_FALSE(child1
->is_clipped());
1568 EXPECT_FALSE(child2
->is_clipped());
1569 EXPECT_FALSE(grand_child
->is_clipped());
1570 EXPECT_FALSE(leaf_node1
->is_clipped());
1571 EXPECT_FALSE(leaf_node2
->is_clipped());
1574 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1575 // surface are clipped. But layers that contribute to child2's surface are
1576 // not clipped explicitly because child2's surface already accounts for
1579 parent
->SetMasksToBounds(true);
1580 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(root
.get(),
1582 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1584 ASSERT_TRUE(root
->has_render_surface());
1585 ASSERT_TRUE(child2
->has_render_surface());
1587 EXPECT_FALSE(root
->is_clipped());
1588 EXPECT_TRUE(parent
->is_clipped());
1589 EXPECT_TRUE(child1
->is_clipped());
1590 EXPECT_FALSE(child2
->is_clipped());
1591 EXPECT_TRUE(grand_child
->is_clipped());
1592 EXPECT_TRUE(leaf_node1
->is_clipped());
1593 EXPECT_FALSE(leaf_node2
->is_clipped());
1596 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1597 // child2's render surface is not clipped.
1599 parent
->SetMasksToBounds(false);
1600 child2
->SetMasksToBounds(true);
1601 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(root
.get(),
1603 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1605 ASSERT_TRUE(root
->has_render_surface());
1606 ASSERT_TRUE(child2
->has_render_surface());
1608 EXPECT_FALSE(root
->is_clipped());
1609 EXPECT_FALSE(parent
->is_clipped());
1610 EXPECT_FALSE(child1
->is_clipped());
1611 EXPECT_TRUE(child2
->is_clipped());
1612 EXPECT_FALSE(grand_child
->is_clipped());
1613 EXPECT_FALSE(leaf_node1
->is_clipped());
1614 EXPECT_TRUE(leaf_node2
->is_clipped());
1618 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectlyLayerImpl
) {
1619 // This is identical to the IsClippedIsSetCorrectly test,
1620 // but tests render surfaces instead of the layers.
1622 const gfx::Transform identity_matrix
;
1623 LayerImpl
* root
= root_layer();
1624 LayerImpl
* parent
= AddChild
<LayerImpl
>(root
);
1625 LayerImpl
* child1
= AddChild
<LayerImpl
>(parent
);
1626 LayerImpl
* child2
= AddChild
<LayerImpl
>(parent
);
1627 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child1
);
1628 LayerImpl
* leaf_node1
= AddChild
<LayerImpl
>(grand_child
);
1629 leaf_node1
->SetDrawsContent(true);
1630 LayerImpl
* leaf_node2
= AddChild
<LayerImpl
>(child2
);
1631 leaf_node2
->SetDrawsContent(true);
1633 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
1634 gfx::PointF(), gfx::Size(100, 100), true, false,
1636 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1637 gfx::PointF(), gfx::Size(100, 100), true, false,
1639 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
1640 gfx::PointF(), gfx::Size(100, 100), true, false,
1642 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
1643 gfx::PointF(), gfx::Size(100, 100), true, false,
1645 SetLayerPropertiesForTesting(grand_child
, identity_matrix
, gfx::Point3F(),
1646 gfx::PointF(), gfx::Size(100, 100), true, false,
1648 SetLayerPropertiesForTesting(leaf_node1
, identity_matrix
, gfx::Point3F(),
1649 gfx::PointF(), gfx::Size(100, 100), true, false,
1651 SetLayerPropertiesForTesting(leaf_node2
, identity_matrix
, gfx::Point3F(),
1652 gfx::PointF(), gfx::Size(100, 100), true, false,
1655 // Case 1: nothing is clipped except the root render surface.
1657 ExecuteCalculateDrawProperties(root
);
1659 ASSERT_TRUE(root
->render_surface());
1660 ASSERT_TRUE(child2
->render_surface());
1662 EXPECT_FALSE(root
->is_clipped());
1663 EXPECT_TRUE(root
->render_surface()->is_clipped());
1664 EXPECT_FALSE(parent
->is_clipped());
1665 EXPECT_FALSE(child1
->is_clipped());
1666 EXPECT_FALSE(child2
->is_clipped());
1667 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1668 EXPECT_FALSE(grand_child
->is_clipped());
1669 EXPECT_FALSE(leaf_node1
->is_clipped());
1670 EXPECT_FALSE(leaf_node2
->is_clipped());
1673 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1674 // surface are clipped. But layers that contribute to child2's surface are
1675 // not clipped explicitly because child2's surface already accounts for
1678 parent
->SetMasksToBounds(true);
1680 parent
->set_is_clipped(true);
1681 child1
->set_is_clipped(true);
1682 grand_child
->set_is_clipped(true);
1683 leaf_node1
->set_is_clipped(true);
1684 host_impl()->active_tree()->property_trees()->needs_rebuild
= true;
1686 ExecuteCalculateDrawProperties(root
);
1688 ASSERT_TRUE(root
->render_surface());
1689 ASSERT_TRUE(child2
->render_surface());
1691 EXPECT_TRUE(root
->render_surface()->is_clipped());
1692 EXPECT_TRUE(child2
->render_surface()->is_clipped());
1694 parent
->SetMasksToBounds(false);
1695 parent
->set_is_clipped(false);
1696 child1
->set_is_clipped(false);
1697 grand_child
->set_is_clipped(false);
1698 leaf_node1
->set_is_clipped(false);
1701 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1702 // child2's render surface is not clipped.
1704 child2
->SetMasksToBounds(true);
1705 child2
->set_is_clipped(true);
1706 leaf_node2
->set_is_clipped(true);
1707 host_impl()->active_tree()->property_trees()->needs_rebuild
= true;
1709 ExecuteCalculateDrawProperties(root
);
1711 ASSERT_TRUE(root
->render_surface());
1712 ASSERT_TRUE(child2
->render_surface());
1714 EXPECT_FALSE(root
->is_clipped());
1715 EXPECT_TRUE(root
->render_surface()->is_clipped());
1716 EXPECT_FALSE(parent
->is_clipped());
1717 EXPECT_FALSE(child1
->is_clipped());
1718 EXPECT_TRUE(child2
->is_clipped());
1719 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1720 EXPECT_FALSE(grand_child
->is_clipped());
1721 EXPECT_FALSE(leaf_node1
->is_clipped());
1722 EXPECT_TRUE(leaf_node2
->is_clipped());
1726 TEST_F(LayerTreeHostCommonTest
, DrawableContentRectForLayers
) {
1727 // Verify that layers get the appropriate DrawableContentRect when their
1728 // parent masksToBounds is true.
1730 // grand_child1 - completely inside the region; DrawableContentRect should
1731 // be the layer rect expressed in target space.
1732 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1733 // will be the intersection of layer bounds and the mask region.
1734 // grand_child3 - partially clipped and masksToBounds; the
1735 // DrawableContentRect will still be the intersection of layer bounds and
1737 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1740 const gfx::Transform identity_matrix
;
1741 LayerImpl
* parent
= root_layer();
1742 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
1743 LayerImpl
* grand_child1
= AddChild
<LayerImpl
>(child
);
1744 LayerImpl
* grand_child2
= AddChild
<LayerImpl
>(child
);
1745 LayerImpl
* grand_child3
= AddChild
<LayerImpl
>(child
);
1746 LayerImpl
* grand_child4
= AddChild
<LayerImpl
>(child
);
1748 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1749 gfx::PointF(), gfx::Size(500, 500), true, false,
1751 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1752 gfx::PointF(), gfx::Size(20, 20), true, false,
1754 SetLayerPropertiesForTesting(grand_child1
, identity_matrix
, gfx::Point3F(),
1755 gfx::PointF(5.f
, 5.f
), gfx::Size(10, 10), true,
1757 SetLayerPropertiesForTesting(grand_child2
, identity_matrix
, gfx::Point3F(),
1758 gfx::PointF(15.f
, 15.f
), gfx::Size(10, 10), true,
1760 SetLayerPropertiesForTesting(grand_child3
, identity_matrix
, gfx::Point3F(),
1761 gfx::PointF(15.f
, 15.f
), gfx::Size(10, 10), true,
1763 SetLayerPropertiesForTesting(grand_child4
, identity_matrix
, gfx::Point3F(),
1764 gfx::PointF(45.f
, 45.f
), gfx::Size(10, 10), true,
1767 child
->SetMasksToBounds(true);
1768 grand_child3
->SetMasksToBounds(true);
1770 // Force child to be a render surface.
1771 child
->SetOpacity(0.4f
);
1773 ExecuteCalculateDrawProperties(parent
);
1775 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1
->drawable_content_rect());
1776 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
1777 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
1778 EXPECT_TRUE(grand_child4
->drawable_content_rect().IsEmpty());
1781 TEST_F(LayerTreeHostCommonTest
, ClipRectIsPropagatedCorrectlyToSurfaces
) {
1782 // Verify that render surfaces (and their layers) get the appropriate
1783 // clip rects when their parent masksToBounds is true.
1785 // Layers that own render surfaces (at least for now) do not inherit any
1786 // clipping; instead the surface will enforce the clip for the entire subtree.
1787 // They may still have a clip rect of their own layer bounds, however, if
1788 // masksToBounds was true.
1789 LayerImpl
* parent
= root_layer();
1790 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1791 LayerImpl
* grand_child1
= AddChild
<LayerImpl
>(child
);
1792 LayerImpl
* grand_child2
= AddChild
<LayerImpl
>(child
);
1793 LayerImpl
* grand_child3
= AddChild
<LayerImpl
>(child
);
1794 LayerImpl
* grand_child4
= AddChild
<LayerImpl
>(child
);
1795 // the leaf nodes ensure that these grand_children become render surfaces for
1797 LayerImpl
* leaf_node1
= AddChild
<LayerImpl
>(grand_child1
);
1798 leaf_node1
->SetDrawsContent(true);
1799 LayerImpl
* leaf_node2
= AddChild
<LayerImpl
>(grand_child2
);
1800 leaf_node2
->SetDrawsContent(true);
1801 LayerImpl
* leaf_node3
= AddChild
<LayerImpl
>(grand_child3
);
1802 leaf_node3
->SetDrawsContent(true);
1803 LayerImpl
* leaf_node4
= AddChild
<LayerImpl
>(grand_child4
);
1804 leaf_node4
->SetDrawsContent(true);
1806 const gfx::Transform identity_matrix
;
1808 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
1809 gfx::PointF(), gfx::Size(500, 500), true, false,
1811 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
1812 gfx::PointF(), gfx::Size(20, 20), true, false,
1814 SetLayerPropertiesForTesting(grand_child1
, identity_matrix
, gfx::Point3F(),
1815 gfx::PointF(5.f
, 5.f
), gfx::Size(10, 10), true,
1817 SetLayerPropertiesForTesting(grand_child2
, identity_matrix
, gfx::Point3F(),
1818 gfx::PointF(15.f
, 15.f
), gfx::Size(10, 10), true,
1820 SetLayerPropertiesForTesting(grand_child3
, identity_matrix
, gfx::Point3F(),
1821 gfx::PointF(15.f
, 15.f
), gfx::Size(10, 10), true,
1823 SetLayerPropertiesForTesting(grand_child4
, identity_matrix
, gfx::Point3F(),
1824 gfx::PointF(45.f
, 45.f
), gfx::Size(10, 10), true,
1826 SetLayerPropertiesForTesting(leaf_node1
, identity_matrix
, gfx::Point3F(),
1827 gfx::PointF(), gfx::Size(10, 10), true, false,
1829 SetLayerPropertiesForTesting(leaf_node2
, identity_matrix
, gfx::Point3F(),
1830 gfx::PointF(), gfx::Size(10, 10), true, false,
1832 SetLayerPropertiesForTesting(leaf_node3
, identity_matrix
, gfx::Point3F(),
1833 gfx::PointF(), gfx::Size(10, 10), true, false,
1835 SetLayerPropertiesForTesting(leaf_node4
, identity_matrix
, gfx::Point3F(),
1836 gfx::PointF(), gfx::Size(10, 10), true, false,
1839 child
->SetMasksToBounds(true);
1840 grand_child3
->SetMasksToBounds(true);
1841 grand_child4
->SetMasksToBounds(true);
1843 // Force everyone to be a render surface.
1844 child
->SetOpacity(0.4f
);
1845 grand_child1
->SetOpacity(0.5f
);
1846 grand_child2
->SetOpacity(0.5f
);
1847 grand_child3
->SetOpacity(0.5f
);
1848 grand_child4
->SetOpacity(0.5f
);
1850 ExecuteCalculateDrawProperties(parent
);
1852 ASSERT_TRUE(grand_child1
->render_surface());
1853 ASSERT_TRUE(grand_child2
->render_surface());
1854 ASSERT_TRUE(grand_child3
->render_surface());
1856 // Surfaces are clipped by their parent, but un-affected by the owning layer's
1858 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1859 grand_child1
->render_surface()->clip_rect());
1860 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1861 grand_child2
->render_surface()->clip_rect());
1862 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
1863 grand_child3
->render_surface()->clip_rect());
1866 TEST_F(LayerTreeHostCommonTest
, AnimationsForRenderSurfaceHierarchy
) {
1867 LayerImpl
* parent
= root_layer();
1868 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
1869 LayerImpl
* child_of_rs1
= AddChild
<LayerImpl
>(render_surface1
);
1870 LayerImpl
* grand_child_of_rs1
= AddChild
<LayerImpl
>(child_of_rs1
);
1871 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
1872 LayerImpl
* child_of_rs2
= AddChild
<LayerImpl
>(render_surface2
);
1873 LayerImpl
* grand_child_of_rs2
= AddChild
<LayerImpl
>(child_of_rs2
);
1874 LayerImpl
* child_of_root
= AddChildToRoot
<LayerImpl
>();
1875 LayerImpl
* grand_child_of_root
= AddChild
<LayerImpl
>(child_of_root
);
1877 grand_child_of_rs1
->SetDrawsContent(true);
1878 grand_child_of_rs2
->SetDrawsContent(true);
1880 gfx::Transform layer_transform
;
1881 layer_transform
.Translate(1.0, 1.0);
1883 SetLayerPropertiesForTesting(
1884 parent
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1885 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
1886 SetLayerPropertiesForTesting(
1887 render_surface1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1888 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
1889 SetLayerPropertiesForTesting(
1890 render_surface2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1891 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, true);
1892 SetLayerPropertiesForTesting(
1893 child_of_root
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1894 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1895 SetLayerPropertiesForTesting(
1896 child_of_rs1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1897 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1898 SetLayerPropertiesForTesting(
1899 child_of_rs2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1900 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1901 SetLayerPropertiesForTesting(
1902 grand_child_of_root
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1903 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1904 SetLayerPropertiesForTesting(
1905 grand_child_of_rs1
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1906 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1907 SetLayerPropertiesForTesting(
1908 grand_child_of_rs2
, layer_transform
, gfx::Point3F(0.25f
, 0.f
, 0.f
),
1909 gfx::PointF(2.5f
, 0.f
), gfx::Size(10, 10), true, false, false);
1911 // Put an animated opacity on the render surface.
1912 AddOpacityTransitionToController(
1913 render_surface1
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
1915 // Also put an animated opacity on a layer without descendants.
1916 AddOpacityTransitionToController(
1917 grand_child_of_root
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
1919 // Put a transform animation on the render surface.
1920 AddAnimatedTransformToController(
1921 render_surface2
->layer_animation_controller(), 10.0, 30, 0);
1923 // Also put transform animations on grand_child_of_root, and
1924 // grand_child_of_rs2
1925 AddAnimatedTransformToController(
1926 grand_child_of_root
->layer_animation_controller(), 10.0, 30, 0);
1927 AddAnimatedTransformToController(
1928 grand_child_of_rs2
->layer_animation_controller(), 10.0, 30, 0);
1930 ExecuteCalculateDrawProperties(parent
);
1932 // Only layers that are associated with render surfaces should have an actual
1933 // RenderSurface() value.
1934 ASSERT_TRUE(parent
->render_surface());
1935 ASSERT_FALSE(child_of_root
->render_surface());
1936 ASSERT_FALSE(grand_child_of_root
->render_surface());
1938 ASSERT_TRUE(render_surface1
->render_surface());
1939 ASSERT_FALSE(child_of_rs1
->render_surface());
1940 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
1942 ASSERT_TRUE(render_surface2
->render_surface());
1943 ASSERT_FALSE(child_of_rs2
->render_surface());
1944 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
1946 // Verify all render target accessors
1947 EXPECT_EQ(parent
, parent
->render_target());
1948 EXPECT_EQ(parent
, child_of_root
->render_target());
1949 EXPECT_EQ(parent
, grand_child_of_root
->render_target());
1951 EXPECT_EQ(render_surface1
, render_surface1
->render_target());
1952 EXPECT_EQ(render_surface1
, child_of_rs1
->render_target());
1953 EXPECT_EQ(render_surface1
, grand_child_of_rs1
->render_target());
1955 EXPECT_EQ(render_surface2
, render_surface2
->render_target());
1956 EXPECT_EQ(render_surface2
, child_of_rs2
->render_target());
1957 EXPECT_EQ(render_surface2
, grand_child_of_rs2
->render_target());
1959 // Verify screen_space_transform_is_animating values
1960 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
1961 EXPECT_FALSE(child_of_root
->screen_space_transform_is_animating());
1962 EXPECT_TRUE(grand_child_of_root
->screen_space_transform_is_animating());
1963 EXPECT_FALSE(render_surface1
->screen_space_transform_is_animating());
1964 EXPECT_FALSE(child_of_rs1
->screen_space_transform_is_animating());
1965 EXPECT_FALSE(grand_child_of_rs1
->screen_space_transform_is_animating());
1966 EXPECT_TRUE(render_surface2
->screen_space_transform_is_animating());
1967 EXPECT_TRUE(child_of_rs2
->screen_space_transform_is_animating());
1968 EXPECT_TRUE(grand_child_of_rs2
->screen_space_transform_is_animating());
1970 // Sanity check. If these fail there is probably a bug in the test itself.
1971 // It is expected that we correctly set up transforms so that the y-component
1972 // of the screen-space transform encodes the "depth" of the layer in the tree.
1973 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
1974 EXPECT_FLOAT_EQ(2.0,
1975 child_of_root
->screen_space_transform().matrix().get(1, 3));
1977 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
1979 EXPECT_FLOAT_EQ(2.0,
1980 render_surface1
->screen_space_transform().matrix().get(1, 3));
1981 EXPECT_FLOAT_EQ(3.0,
1982 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
1984 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
1986 EXPECT_FLOAT_EQ(3.0,
1987 render_surface2
->screen_space_transform().matrix().get(1, 3));
1988 EXPECT_FLOAT_EQ(4.0,
1989 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1991 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1994 TEST_F(LayerTreeHostCommonTest
, LargeTransforms
) {
1995 LayerImpl
* parent
= root_layer();
1996 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
1997 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
1999 grand_child
->SetDrawsContent(true);
2001 gfx::Transform large_transform
;
2002 large_transform
.Scale(SkDoubleToMScalar(1e37
), SkDoubleToMScalar(1e37
));
2004 gfx::Transform identity
;
2006 SetLayerPropertiesForTesting(parent
, identity
, gfx::Point3F(), gfx::PointF(),
2007 gfx::Size(10, 10), true, false, true);
2008 SetLayerPropertiesForTesting(child
, large_transform
, gfx::Point3F(),
2009 gfx::PointF(), gfx::Size(10, 10), true, false,
2011 SetLayerPropertiesForTesting(grand_child
, large_transform
, gfx::Point3F(),
2012 gfx::PointF(), gfx::Size(10, 10), true, false,
2014 ExecuteCalculateDrawProperties(parent
);
2016 EXPECT_EQ(gfx::Rect(), grand_child
->visible_layer_rect());
2019 TEST_F(LayerTreeHostCommonTest
,
2020 ScreenSpaceTransformIsAnimatingWithDelayedAnimation
) {
2021 LayerImpl
* parent
= root_layer();
2022 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
2023 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
2024 LayerImpl
* great_grand_child
= AddChild
<LayerImpl
>(grand_child
);
2026 parent
->SetDrawsContent(true);
2027 child
->SetDrawsContent(true);
2028 grand_child
->SetDrawsContent(true);
2029 great_grand_child
->SetDrawsContent(true);
2031 gfx::Transform identity
;
2033 SetLayerPropertiesForTesting(parent
, identity
, gfx::Point3F(), gfx::PointF(),
2034 gfx::Size(10, 10), true, false, true);
2035 SetLayerPropertiesForTesting(child
, identity
, gfx::Point3F(), gfx::PointF(),
2036 gfx::Size(10, 10), true, false, false);
2037 SetLayerPropertiesForTesting(grand_child
, identity
, gfx::Point3F(),
2038 gfx::PointF(), gfx::Size(10, 10), true, false,
2040 SetLayerPropertiesForTesting(great_grand_child
, identity
, gfx::Point3F(),
2041 gfx::PointF(), gfx::Size(10, 10), true, false,
2044 // Add a transform animation with a start delay to |grand_child|.
2045 scoped_ptr
<Animation
> animation
= Animation::Create(
2046 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(), 0, 1,
2047 Animation::TRANSFORM
);
2048 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
2049 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
2050 grand_child
->layer_animation_controller()->AddAnimation(animation
.Pass());
2052 ExecuteCalculateDrawProperties(parent
);
2054 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
2055 EXPECT_FALSE(child
->screen_space_transform_is_animating());
2057 EXPECT_FALSE(grand_child
->TransformIsAnimating());
2058 EXPECT_TRUE(grand_child
->HasPotentiallyRunningTransformAnimation());
2059 EXPECT_TRUE(grand_child
->screen_space_transform_is_animating());
2060 EXPECT_TRUE(great_grand_child
->screen_space_transform_is_animating());
2063 TEST_F(LayerTreeHostCommonTest
, VisibleRectForIdentityTransform
) {
2064 // Test the calculateVisibleRect() function works correctly for identity
2067 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2068 gfx::Transform layer_to_surface_transform
;
2070 // Case 1: Layer is contained within the surface.
2071 gfx::Rect layer_content_rect
= gfx::Rect(10, 10, 30, 30);
2072 gfx::Rect expected
= gfx::Rect(10, 10, 30, 30);
2073 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2074 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2075 EXPECT_EQ(expected
, actual
);
2077 // Case 2: Layer is outside the surface rect.
2078 layer_content_rect
= gfx::Rect(120, 120, 30, 30);
2079 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2080 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2081 EXPECT_TRUE(actual
.IsEmpty());
2083 // Case 3: Layer is partially overlapping the surface rect.
2084 layer_content_rect
= gfx::Rect(80, 80, 30, 30);
2085 expected
= gfx::Rect(80, 80, 20, 20);
2086 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2087 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2088 EXPECT_EQ(expected
, actual
);
2091 TEST_F(LayerTreeHostCommonTest
, VisibleRectForTranslations
) {
2092 // Test the calculateVisibleRect() function works correctly for scaling
2095 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2096 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2097 gfx::Transform layer_to_surface_transform
;
2099 // Case 1: Layer is contained within the surface.
2100 layer_to_surface_transform
.MakeIdentity();
2101 layer_to_surface_transform
.Translate(10.0, 10.0);
2102 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2103 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2104 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2105 EXPECT_EQ(expected
, actual
);
2107 // Case 2: Layer is outside the surface rect.
2108 layer_to_surface_transform
.MakeIdentity();
2109 layer_to_surface_transform
.Translate(120.0, 120.0);
2110 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2111 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2112 EXPECT_TRUE(actual
.IsEmpty());
2114 // Case 3: Layer is partially overlapping the surface rect.
2115 layer_to_surface_transform
.MakeIdentity();
2116 layer_to_surface_transform
.Translate(80.0, 80.0);
2117 expected
= gfx::Rect(0, 0, 20, 20);
2118 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2119 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2120 EXPECT_EQ(expected
, actual
);
2123 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor2DRotations
) {
2124 // Test the calculateVisibleRect() function works correctly for rotations
2125 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2126 // should return the g in the layer's space.
2128 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2129 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2130 gfx::Transform layer_to_surface_transform
;
2132 // Case 1: Layer is contained within the surface.
2133 layer_to_surface_transform
.MakeIdentity();
2134 layer_to_surface_transform
.Translate(50.0, 50.0);
2135 layer_to_surface_transform
.Rotate(45.0);
2136 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2137 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2138 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2139 EXPECT_EQ(expected
, actual
);
2141 // Case 2: Layer is outside the surface rect.
2142 layer_to_surface_transform
.MakeIdentity();
2143 layer_to_surface_transform
.Translate(-50.0, 0.0);
2144 layer_to_surface_transform
.Rotate(45.0);
2145 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2146 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2147 EXPECT_TRUE(actual
.IsEmpty());
2149 // Case 3: The layer is rotated about its top-left corner. In surface space,
2150 // the layer is oriented diagonally, with the left half outside of the render
2151 // surface. In this case, the g should still be the entire layer
2152 // (remember the g is computed in layer space); both the top-left
2153 // and bottom-right corners of the layer are still visible.
2154 layer_to_surface_transform
.MakeIdentity();
2155 layer_to_surface_transform
.Rotate(45.0);
2156 expected
= gfx::Rect(0, 0, 30, 30);
2157 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2158 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2159 EXPECT_EQ(expected
, actual
);
2161 // Case 4: The layer is rotated about its top-left corner, and translated
2162 // upwards. In surface space, the layer is oriented diagonally, with only the
2163 // top corner of the surface overlapping the layer. In layer space, the render
2164 // surface overlaps the right side of the layer. The g should be
2165 // the layer's right half.
2166 layer_to_surface_transform
.MakeIdentity();
2167 layer_to_surface_transform
.Translate(0.0, -sqrt(2.0) * 15.0);
2168 layer_to_surface_transform
.Rotate(45.0);
2169 expected
= gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2170 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2171 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2172 EXPECT_EQ(expected
, actual
);
2175 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dOrthographicTransform
) {
2176 // Test that the calculateVisibleRect() function works correctly for 3d
2179 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2180 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2181 gfx::Transform layer_to_surface_transform
;
2183 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2184 // degrees, should be fully contained in the render surface.
2185 layer_to_surface_transform
.MakeIdentity();
2186 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2187 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2188 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2189 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2190 EXPECT_EQ(expected
, actual
);
2192 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2193 // degrees, but shifted to the side so only the right-half the layer would be
2194 // visible on the surface.
2195 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2196 SkMScalar half_width_of_rotated_layer
=
2197 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2198 layer_to_surface_transform
.MakeIdentity();
2199 layer_to_surface_transform
.Translate(-half_width_of_rotated_layer
, 0.0);
2200 layer_to_surface_transform
.RotateAboutYAxis(45.0); // Rotates about the left
2201 // edge of the layer.
2202 expected
= gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2203 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2204 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2205 EXPECT_EQ(expected
, actual
);
2208 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveTransform
) {
2209 // Test the calculateVisibleRect() function works correctly when the layer has
2210 // a perspective projection onto the target surface.
2212 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2213 gfx::Rect layer_content_rect
= gfx::Rect(-50, -50, 200, 200);
2214 gfx::Transform layer_to_surface_transform
;
2216 // Case 1: Even though the layer is twice as large as the surface, due to
2217 // perspective foreshortening, the layer will fit fully in the surface when
2218 // its translated more than the perspective amount.
2219 layer_to_surface_transform
.MakeIdentity();
2221 // The following sequence of transforms applies the perspective about the
2222 // center of the surface.
2223 layer_to_surface_transform
.Translate(50.0, 50.0);
2224 layer_to_surface_transform
.ApplyPerspectiveDepth(9.0);
2225 layer_to_surface_transform
.Translate(-50.0, -50.0);
2227 // This translate places the layer in front of the surface's projection plane.
2228 layer_to_surface_transform
.Translate3d(0.0, 0.0, -27.0);
2230 gfx::Rect expected
= gfx::Rect(-50, -50, 200, 200);
2231 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2232 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2233 EXPECT_EQ(expected
, actual
);
2235 // Case 2: same projection as before, except that the layer is also translated
2236 // to the side, so that only the right half of the layer should be visible.
2238 // Explanation of expected result: The perspective ratio is (z distance
2239 // between layer and camera origin) / (z distance between projection plane and
2240 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2241 // move a layer by translating -50 units in projected surface units (so that
2242 // only half of it is visible), then we would need to translate by (-36 / 9) *
2243 // -50 == -200 in the layer's units.
2244 layer_to_surface_transform
.Translate3d(-200.0, 0.0, 0.0);
2245 expected
= gfx::Rect(gfx::Point(50, -50),
2246 gfx::Size(100, 200)); // The right half of the layer's
2248 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2249 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2250 EXPECT_EQ(expected
, actual
);
2253 TEST_F(LayerTreeHostCommonTest
,
2254 VisibleRectFor3dOrthographicIsNotClippedBehindSurface
) {
2255 // There is currently no explicit concept of an orthographic projection plane
2256 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2257 // are technically behind the surface in an orthographic world should not be
2258 // clipped when they are flattened to the surface.
2260 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2261 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2262 gfx::Transform layer_to_surface_transform
;
2264 // This sequence of transforms effectively rotates the layer about the y-axis
2265 // at the center of the layer.
2266 layer_to_surface_transform
.MakeIdentity();
2267 layer_to_surface_transform
.Translate(50.0, 0.0);
2268 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2269 layer_to_surface_transform
.Translate(-50.0, 0.0);
2271 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2272 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2273 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2274 EXPECT_EQ(expected
, actual
);
2277 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveWhenClippedByW
) {
2278 // Test the calculateVisibleRect() function works correctly when projecting a
2279 // surface onto a layer, but the layer is partially behind the camera (not
2280 // just behind the projection plane). In this case, the cartesian coordinates
2281 // may seem to be valid, but actually they are not. The visible rect needs to
2282 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2283 // converting to cartesian coordinates.
2285 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2286 gfx::Rect layer_content_rect
= gfx::Rect(-10, -1, 20, 2);
2287 gfx::Transform layer_to_surface_transform
;
2289 // The layer is positioned so that the right half of the layer should be in
2290 // front of the camera, while the other half is behind the surface's
2291 // projection plane. The following sequence of transforms applies the
2292 // perspective and rotation about the center of the layer.
2293 layer_to_surface_transform
.MakeIdentity();
2294 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2295 layer_to_surface_transform
.Translate3d(-2.0, 0.0, 1.0);
2296 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2298 // Sanity check that this transform does indeed cause w < 0 when applying the
2299 // transform, otherwise this code is not testing the intended scenario.
2301 MathUtil::MapQuad(layer_to_surface_transform
,
2302 gfx::QuadF(gfx::RectF(layer_content_rect
)),
2304 ASSERT_TRUE(clipped
);
2306 int expected_x_position
= 0;
2307 int expected_width
= 10;
2308 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2309 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2310 EXPECT_EQ(expected_x_position
, actual
.x());
2311 EXPECT_EQ(expected_width
, actual
.width());
2314 TEST_F(LayerTreeHostCommonTest
, VisibleRectForPerspectiveUnprojection
) {
2315 // To determine visible rect in layer space, there needs to be an
2316 // un-projection from surface space to layer space. When the original
2317 // transform was a perspective projection that was clipped, it returns a rect
2318 // that encloses the clipped bounds. Un-projecting this new rect may require
2321 // This sequence of transforms causes one corner of the layer to protrude
2322 // across the w = 0 plane, and should be clipped.
2323 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2324 gfx::Rect layer_content_rect
= gfx::Rect(-10, -10, 20, 20);
2325 gfx::Transform layer_to_surface_transform
;
2326 layer_to_surface_transform
.MakeIdentity();
2327 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2328 layer_to_surface_transform
.Translate3d(0.0, 0.0, -5.0);
2329 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2330 layer_to_surface_transform
.RotateAboutXAxis(80.0);
2332 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2333 // code is not testing the intended scenario.
2335 gfx::RectF clipped_rect
= MathUtil::MapClippedRect(
2336 layer_to_surface_transform
, gfx::RectF(layer_content_rect
));
2337 MathUtil::ProjectQuad(
2338 Inverse(layer_to_surface_transform
), gfx::QuadF(clipped_rect
), &clipped
);
2339 ASSERT_TRUE(clipped
);
2341 // Only the corner of the layer is not visible on the surface because of being
2342 // clipped. But, the net result of rounding visible region to an axis-aligned
2343 // rect is that the entire layer should still be considered visible.
2344 gfx::Rect expected
= gfx::Rect(-10, -10, 20, 20);
2345 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2346 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2347 EXPECT_EQ(expected
, actual
);
2350 TEST_F(LayerTreeHostCommonTest
,
2351 VisibleRectsForPositionedRootLayerClippedByViewport
) {
2352 LayerImpl
* root
= root_layer();
2353 root
->SetDrawsContent(true);
2355 gfx::Transform identity_matrix
;
2356 // Root layer is positioned at (60, 70). The default device viewport size
2357 // is (0, 0, 100x100) in target space. So the root layer's visible rect
2358 // will be clipped by the viewport to be (0, 0, 40x30) in layer's space.
2359 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2360 gfx::PointF(60, 70), gfx::Size(100, 100), true,
2362 ExecuteCalculateDrawProperties(root
);
2364 EXPECT_EQ(gfx::RectF(100.f
, 100.f
),
2365 root
->render_surface()->DrawableContentRect());
2366 // In target space, not clipped.
2367 EXPECT_EQ(gfx::Rect(60, 70, 100, 100), root
->drawable_content_rect());
2368 // In layer space, clipped.
2369 EXPECT_EQ(gfx::Rect(40, 30), root
->visible_layer_rect());
2372 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsForSimpleLayers
) {
2373 LayerImpl
* root
= root_layer();
2374 LayerImpl
* child1_layer
= AddChildToRoot
<LayerImpl
>();
2375 child1_layer
->SetDrawsContent(true);
2376 LayerImpl
* child2_layer
= AddChildToRoot
<LayerImpl
>();
2377 child2_layer
->SetDrawsContent(true);
2378 LayerImpl
* child3_layer
= AddChildToRoot
<LayerImpl
>();
2379 child3_layer
->SetDrawsContent(true);
2381 gfx::Transform identity_matrix
;
2382 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2383 gfx::PointF(), gfx::Size(100, 100), true, false,
2385 SetLayerPropertiesForTesting(child1_layer
, identity_matrix
, gfx::Point3F(),
2386 gfx::PointF(), gfx::Size(50, 50), true, false,
2388 SetLayerPropertiesForTesting(child2_layer
, identity_matrix
, gfx::Point3F(),
2389 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2391 SetLayerPropertiesForTesting(child3_layer
, identity_matrix
, gfx::Point3F(),
2392 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2393 true, false, false);
2395 ExecuteCalculateDrawProperties(root
);
2397 EXPECT_EQ(gfx::RectF(100.f
, 100.f
),
2398 root
->render_surface()->DrawableContentRect());
2399 EXPECT_EQ(gfx::Rect(100, 100), root
->drawable_content_rect());
2401 // Layers that do not draw content should have empty visible_layer_rects.
2402 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2404 // layer visible_layer_rects are clipped by their target surface.
2405 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer
->visible_layer_rect());
2406 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2_layer
->visible_layer_rect());
2407 EXPECT_TRUE(child3_layer
->visible_layer_rect().IsEmpty());
2409 // layer drawable_content_rects are not clipped.
2410 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1_layer
->drawable_content_rect());
2411 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2_layer
->drawable_content_rect());
2412 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3_layer
->drawable_content_rect());
2415 TEST_F(LayerTreeHostCommonTest
,
2416 DrawableAndVisibleContentRectsForLayersClippedByLayer
) {
2417 LayerImpl
* root
= root_layer();
2418 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
2419 LayerImpl
* grand_child1
= AddChild
<LayerImpl
>(child
);
2420 grand_child1
->SetDrawsContent(true);
2421 LayerImpl
* grand_child2
= AddChild
<LayerImpl
>(child
);
2422 grand_child2
->SetDrawsContent(true);
2423 LayerImpl
* grand_child3
= AddChild
<LayerImpl
>(child
);
2424 grand_child3
->SetDrawsContent(true);
2426 gfx::Transform identity_matrix
;
2427 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2428 gfx::PointF(), gfx::Size(100, 100), true, false,
2430 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
2431 gfx::PointF(), gfx::Size(100, 100), true, false,
2433 SetLayerPropertiesForTesting(grand_child1
, identity_matrix
, gfx::Point3F(),
2434 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2436 SetLayerPropertiesForTesting(grand_child2
, identity_matrix
, gfx::Point3F(),
2437 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2439 SetLayerPropertiesForTesting(grand_child3
, identity_matrix
, gfx::Point3F(),
2440 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2441 true, false, false);
2443 child
->SetMasksToBounds(true);
2444 ExecuteCalculateDrawProperties(root
);
2446 EXPECT_EQ(gfx::RectF(100.f
, 100.f
),
2447 root
->render_surface()->DrawableContentRect());
2448 EXPECT_EQ(gfx::Rect(100, 100), root
->drawable_content_rect());
2450 // Layers that do not draw content should have empty visible content rects.
2451 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2452 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child
->visible_layer_rect());
2454 // All grandchild visible content rects should be clipped by child.
2455 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1
->visible_layer_rect());
2456 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2
->visible_layer_rect());
2457 EXPECT_TRUE(grand_child3
->visible_layer_rect().IsEmpty());
2459 // All grandchild DrawableContentRects should also be clipped by child.
2460 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1
->drawable_content_rect());
2461 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2
->drawable_content_rect());
2462 EXPECT_TRUE(grand_child3
->drawable_content_rect().IsEmpty());
2465 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectWithClippingAndScaling
) {
2466 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2467 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
2468 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
2469 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2470 root
->AddChild(child
);
2471 child
->AddChild(grand_child
);
2473 host()->SetRootLayer(root
);
2475 gfx::Transform identity_matrix
;
2476 gfx::Transform child_scale_matrix
;
2477 child_scale_matrix
.Scale(0.25f
, 0.25f
);
2478 gfx::Transform grand_child_scale_matrix
;
2479 grand_child_scale_matrix
.Scale(0.246f
, 0.246f
);
2480 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2481 gfx::PointF(), gfx::Size(100, 100), true, false);
2482 SetLayerPropertiesForTesting(child
.get(), child_scale_matrix
, gfx::Point3F(),
2483 gfx::PointF(), gfx::Size(10, 10), true, false);
2484 SetLayerPropertiesForTesting(grand_child
.get(), grand_child_scale_matrix
,
2485 gfx::Point3F(), gfx::PointF(),
2486 gfx::Size(100, 100), true, false);
2488 child
->SetMasksToBounds(true);
2489 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
2491 // The visible rect is expanded to integer coordinates in target space before
2492 // being projected back to layer space, where it is once again expanded to
2493 // integer coordinates.
2494 EXPECT_EQ(gfx::Rect(49, 49), grand_child
->visible_rect_from_property_trees());
2497 TEST_F(LayerTreeHostCommonTest
,
2498 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface
) {
2499 LayerImpl
* root
= root_layer();
2500 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
2501 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
2502 child1
->SetDrawsContent(true);
2503 LayerImpl
* child2
= AddChild
<LayerImpl
>(render_surface
);
2504 child2
->SetDrawsContent(true);
2505 LayerImpl
* child3
= AddChild
<LayerImpl
>(render_surface
);
2506 child3
->SetDrawsContent(true);
2508 gfx::Transform identity_matrix
;
2509 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2510 gfx::PointF(), gfx::Size(100, 100), true, false,
2512 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
2513 gfx::PointF(), gfx::Size(3, 4), true, false,
2515 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2516 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2518 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2519 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2521 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2522 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2523 true, false, false);
2525 ExecuteCalculateDrawProperties(root
);
2527 ASSERT_TRUE(render_surface
->render_surface());
2529 EXPECT_EQ(gfx::RectF(100.f
, 100.f
),
2530 root
->render_surface()->DrawableContentRect());
2531 EXPECT_EQ(gfx::Rect(100, 100), root
->drawable_content_rect());
2533 // Layers that do not draw content should have empty visible content rects.
2534 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2535 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface
->visible_layer_rect());
2537 // An unclipped surface grows its DrawableContentRect to include all drawable
2538 // regions of the subtree.
2539 EXPECT_EQ(gfx::RectF(5.f
, 5.f
, 170.f
, 170.f
),
2540 render_surface
->render_surface()->DrawableContentRect());
2542 // All layers that draw content into the unclipped surface are also unclipped.
2543 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2544 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
2545 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
2547 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2548 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2549 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2552 TEST_F(LayerTreeHostCommonTest
,
2553 VisibleContentRectsForClippedSurfaceWithEmptyClip
) {
2554 LayerImpl
* root
= root_layer();
2555 LayerImpl
* child1
= AddChild
<LayerImpl
>(root
);
2556 LayerImpl
* child2
= AddChild
<LayerImpl
>(root
);
2557 LayerImpl
* child3
= AddChild
<LayerImpl
>(root
);
2558 child1
->SetDrawsContent(true);
2559 child2
->SetDrawsContent(true);
2560 child3
->SetDrawsContent(true);
2562 gfx::Transform identity_matrix
;
2563 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2564 gfx::PointF(), gfx::Size(100, 100), true, false,
2566 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2567 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2569 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2570 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2572 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2573 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2574 true, false, false);
2576 LayerImplList render_surface_layer_list_impl
;
2577 // Now set the root render surface an empty clip.
2578 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
2579 root
, gfx::Size(), &render_surface_layer_list_impl
);
2581 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2582 ASSERT_TRUE(root
->render_surface());
2583 EXPECT_FALSE(root
->is_clipped());
2586 EXPECT_EQ(empty
, root
->render_surface()->clip_rect());
2587 EXPECT_TRUE(root
->render_surface()->is_clipped());
2589 // Visible content rect calculation will check if the target surface is
2590 // clipped or not. An empty clip rect does not indicate the render surface
2592 EXPECT_EQ(empty
, child1
->visible_layer_rect());
2593 EXPECT_EQ(empty
, child2
->visible_layer_rect());
2594 EXPECT_EQ(empty
, child3
->visible_layer_rect());
2597 TEST_F(LayerTreeHostCommonTest
,
2598 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform
) {
2599 LayerImpl
* root
= root_layer();
2600 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
2601 child
->SetDrawsContent(true);
2603 // Case 1: a truly degenerate matrix
2604 gfx::Transform identity_matrix
;
2605 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2606 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2608 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2609 gfx::PointF(), gfx::Size(100, 100), true, false,
2611 SetLayerPropertiesForTesting(child
, uninvertible_matrix
, gfx::Point3F(),
2612 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2615 ExecuteCalculateDrawProperties(root
);
2617 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2618 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2620 // Case 2: a matrix with flattened z, uninvertible and not visible according
2622 uninvertible_matrix
.MakeIdentity();
2623 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2624 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2626 SetLayerPropertiesForTesting(child
, uninvertible_matrix
, gfx::Point3F(),
2627 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2630 ExecuteCalculateDrawProperties(root
);
2632 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2633 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2635 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2636 uninvertible_matrix
.MakeIdentity();
2637 uninvertible_matrix
.Translate(500.0, 0.0);
2638 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2639 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2641 SetLayerPropertiesForTesting(child
, uninvertible_matrix
, gfx::Point3F(),
2642 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2645 ExecuteCalculateDrawProperties(root
);
2647 EXPECT_TRUE(child
->visible_layer_rect().IsEmpty());
2648 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2651 TEST_F(LayerTreeHostCommonTest
,
2652 VisibleContentRectForLayerWithUninvertibleDrawTransform
) {
2653 LayerImpl
* root
= root_layer();
2654 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
2655 LayerImpl
* grand_child
= AddChild
<LayerImpl
>(child
);
2656 child
->SetDrawsContent(true);
2657 grand_child
->SetDrawsContent(true);
2659 gfx::Transform identity_matrix
;
2661 gfx::Transform perspective
;
2662 perspective
.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2664 gfx::Transform rotation
;
2665 rotation
.RotateAboutYAxis(45.0);
2667 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2668 gfx::PointF(), gfx::Size(100, 100), true, false,
2670 SetLayerPropertiesForTesting(child
, perspective
, gfx::Point3F(),
2671 gfx::PointF(10.f
, 10.f
), gfx::Size(100, 100),
2672 false, true, false);
2673 SetLayerPropertiesForTesting(grand_child
, rotation
, gfx::Point3F(),
2674 gfx::PointF(), gfx::Size(100, 100), false, true,
2677 ExecuteCalculateDrawProperties(root
);
2679 // Though all layers have invertible transforms, matrix multiplication using
2680 // floating-point math makes the draw transform uninvertible.
2681 EXPECT_FALSE(grand_child
->draw_transform().IsInvertible());
2683 // CalcDrawProps only skips a subtree when a layer's own transform is
2684 // uninvertible, not when its draw transform is invertible, since CDP makes
2685 // skipping decisions before computing a layer's draw transform. Property
2686 // trees make skipping decisions after computing draw transforms, so could be
2687 // made to skip layers with an uninvertible draw transform (once CDP is
2689 EXPECT_EQ(gfx::Rect(grand_child
->bounds()),
2690 grand_child
->visible_layer_rect());
2693 TEST_F(LayerTreeHostCommonTest
,
2694 OcclusionForLayerWithUninvertibleDrawTransform
) {
2695 FakeImplProxy proxy
;
2696 TestSharedBitmapManager shared_bitmap_manager
;
2697 TestTaskGraphRunner task_graph_runner
;
2698 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
2699 &task_graph_runner
);
2700 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
2701 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 2);
2702 scoped_ptr
<LayerImpl
> grand_child
=
2703 LayerImpl::Create(host_impl
.active_tree(), 3);
2704 scoped_ptr
<LayerImpl
> occluding_child
=
2705 LayerImpl::Create(host_impl
.active_tree(), 4);
2706 child
->SetDrawsContent(true);
2707 grand_child
->SetDrawsContent(true);
2708 occluding_child
->SetDrawsContent(true);
2709 occluding_child
->SetContentsOpaque(true);
2711 gfx::Transform identity_matrix
;
2712 gfx::Transform perspective
;
2713 perspective
.ApplyPerspectiveDepth(SkDoubleToMScalar(1e-12));
2715 gfx::Transform rotation
;
2716 rotation
.RotateAboutYAxis(45.0);
2718 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2719 gfx::PointF(), gfx::Size(1000, 1000), true,
2721 SetLayerPropertiesForTesting(child
.get(), perspective
, gfx::Point3F(),
2722 gfx::PointF(10.f
, 10.f
), gfx::Size(300, 300),
2723 false, true, false);
2724 SetLayerPropertiesForTesting(grand_child
.get(), rotation
, gfx::Point3F(),
2725 gfx::PointF(), gfx::Size(200, 200), false, true,
2727 SetLayerPropertiesForTesting(occluding_child
.get(), identity_matrix
,
2728 gfx::Point3F(), gfx::PointF(),
2729 gfx::Size(200, 200), false, false, false);
2731 host_impl
.SetViewportSize(root
->bounds());
2733 child
->AddChild(grand_child
.Pass());
2734 root
->AddChild(child
.Pass());
2735 root
->AddChild(occluding_child
.Pass());
2736 host_impl
.active_tree()->SetRootLayer(root
.Pass());
2737 host_impl
.InitializeRenderer(FakeOutputSurface::Create3d());
2738 bool update_lcd_text
= false;
2739 host_impl
.active_tree()->UpdateDrawProperties(update_lcd_text
);
2741 LayerImpl
* grand_child_ptr
=
2742 host_impl
.active_tree()->root_layer()->children()[0]->children()[0];
2744 // Though all layers have invertible transforms, matrix multiplication using
2745 // floating-point math makes the draw transform uninvertible.
2746 EXPECT_FALSE(grand_child_ptr
->draw_transform().IsInvertible());
2748 // Since |grand_child| has an uninvertible draw transform, it is treated as
2749 // unoccluded (even though |occluding_child| comes later in draw order, and
2750 // hence potentially occludes it).
2751 gfx::Rect layer_bounds
= gfx::Rect(grand_child_ptr
->bounds());
2754 grand_child_ptr
->draw_properties()
2755 .occlusion_in_content_space
.GetUnoccludedContentRect(layer_bounds
));
2758 TEST_F(LayerTreeHostCommonTest
,
2759 SingularTransformDoesNotPreventClearingDrawProperties
) {
2760 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2761 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2762 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2763 root
->AddChild(child
);
2765 host()->SetRootLayer(root
);
2767 gfx::Transform identity_matrix
;
2768 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2769 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2771 SetLayerPropertiesForTesting(root
.get(),
2772 uninvertible_matrix
,
2775 gfx::Size(100, 100),
2778 SetLayerPropertiesForTesting(child
.get(),
2781 gfx::PointF(5.f
, 5.f
),
2786 child
->set_sorted_for_recursion(true);
2788 TransformOperations start_transform_operations
;
2789 start_transform_operations
.AppendScale(1.f
, 0.f
, 0.f
);
2791 TransformOperations end_transform_operations
;
2792 end_transform_operations
.AppendScale(1.f
, 1.f
, 0.f
);
2794 AddAnimatedTransformToLayer(
2795 root
.get(), 10.0, start_transform_operations
, end_transform_operations
);
2797 EXPECT_TRUE(root
->TransformIsAnimating());
2799 ExecuteCalculateDrawProperties(root
.get());
2801 EXPECT_FALSE(child
->sorted_for_recursion());
2804 TEST_F(LayerTreeHostCommonTest
,
2805 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties
) {
2806 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2808 host()->SetRootLayer(root
);
2810 gfx::Transform identity_matrix
;
2811 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2812 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2814 SetLayerPropertiesForTesting(root
.get(),
2815 uninvertible_matrix
,
2818 gfx::Size(100, 100),
2822 root
->set_sorted_for_recursion(true);
2824 EXPECT_FALSE(root
->TransformIsAnimating());
2826 ExecuteCalculateDrawProperties(root
.get());
2828 EXPECT_FALSE(root
->sorted_for_recursion());
2831 TEST_F(LayerTreeHostCommonTest
,
2832 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface
) {
2833 LayerImpl
* root
= root_layer();
2834 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
2835 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
2836 child1
->SetDrawsContent(true);
2837 LayerImpl
* child2
= AddChild
<LayerImpl
>(render_surface
);
2838 child2
->SetDrawsContent(true);
2839 LayerImpl
* child3
= AddChild
<LayerImpl
>(render_surface
);
2840 child3
->SetDrawsContent(true);
2842 gfx::Transform identity_matrix
;
2843 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2844 gfx::PointF(), gfx::Size(100, 100), true, false,
2846 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
2847 gfx::PointF(), gfx::Size(3, 4), true, false,
2849 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2850 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2852 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2853 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2855 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2856 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2857 true, false, false);
2859 root
->SetMasksToBounds(true);
2861 ExecuteCalculateDrawProperties(root
);
2863 ASSERT_TRUE(render_surface
->render_surface());
2865 EXPECT_EQ(gfx::RectF(100.f
, 100.f
),
2866 root
->render_surface()->DrawableContentRect());
2867 EXPECT_EQ(gfx::Rect(100, 100), root
->drawable_content_rect());
2869 // Layers that do not draw content should have empty visible content rects.
2870 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2871 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface
->visible_layer_rect());
2873 // A clipped surface grows its DrawableContentRect to include all drawable
2874 // regions of the subtree, but also gets clamped by the ancestor's clip.
2875 EXPECT_EQ(gfx::RectF(5.f
, 5.f
, 95.f
, 95.f
),
2876 render_surface
->render_surface()->DrawableContentRect());
2878 // All layers that draw content into the surface have their visible content
2879 // rect clipped by the surface clip rect.
2880 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2881 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_layer_rect());
2882 EXPECT_TRUE(child3
->visible_layer_rect().IsEmpty());
2884 // But the DrawableContentRects are unclipped.
2885 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2886 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2887 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2890 TEST_F(LayerTreeHostCommonTest
,
2891 DrawableAndVisibleContentRectsForSurfaceHierarchy
) {
2892 // Check that clipping does not propagate down surfaces.
2893 LayerImpl
* root
= root_layer();
2894 LayerImpl
* render_surface1
= AddChildToRoot
<LayerImpl
>();
2895 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(render_surface1
);
2896 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface2
);
2897 child1
->SetDrawsContent(true);
2898 LayerImpl
* child2
= AddChild
<LayerImpl
>(render_surface2
);
2899 child2
->SetDrawsContent(true);
2900 LayerImpl
* child3
= AddChild
<LayerImpl
>(render_surface2
);
2901 child3
->SetDrawsContent(true);
2903 gfx::Transform identity_matrix
;
2904 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2905 gfx::PointF(), gfx::Size(100, 100), true, false,
2907 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
2908 gfx::PointF(), gfx::Size(3, 4), true, false,
2910 SetLayerPropertiesForTesting(render_surface2
, identity_matrix
, gfx::Point3F(),
2911 gfx::PointF(), gfx::Size(7, 13), true, false,
2913 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
2914 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2916 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
2917 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2919 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
2920 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2921 true, false, false);
2923 root
->SetMasksToBounds(true);
2925 ExecuteCalculateDrawProperties(root
);
2927 ASSERT_TRUE(render_surface1
->render_surface());
2928 ASSERT_TRUE(render_surface2
->render_surface());
2930 EXPECT_EQ(gfx::RectF(100.f
, 100.f
),
2931 root
->render_surface()->DrawableContentRect());
2932 EXPECT_EQ(gfx::Rect(100, 100), root
->drawable_content_rect());
2934 // Layers that do not draw content should have empty visible content rects.
2935 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2936 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_layer_rect());
2937 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2
->visible_layer_rect());
2939 // A clipped surface grows its DrawableContentRect to include all drawable
2940 // regions of the subtree, but also gets clamped by the ancestor's clip.
2941 EXPECT_EQ(gfx::RectF(5.f
, 5.f
, 95.f
, 95.f
),
2942 render_surface1
->render_surface()->DrawableContentRect());
2944 // render_surface1 lives in the "unclipped universe" of render_surface1, and
2945 // is only implicitly clipped by render_surface1's content rect. So,
2946 // render_surface2 grows to enclose all drawable content of its subtree.
2947 EXPECT_EQ(gfx::RectF(5.f
, 5.f
, 170.f
, 170.f
),
2948 render_surface2
->render_surface()->DrawableContentRect());
2950 // All layers that draw content into render_surface2 think they are unclipped.
2951 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
2952 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
2953 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
2955 // DrawableContentRects are also unclipped.
2956 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2957 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2958 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2961 TEST_F(LayerTreeHostCommonTest
,
2962 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface
) {
2963 // Layers that have non-axis aligned bounds (due to transforms) have an
2964 // expanded, axis-aligned DrawableContentRect and visible content rect.
2965 LayerImpl
* root
= root_layer();
2966 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
2967 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
2968 child1
->SetDrawsContent(true);
2970 gfx::Transform identity_matrix
;
2971 gfx::Transform child_rotation
;
2972 child_rotation
.Rotate(45.0);
2973 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
2974 gfx::PointF(), gfx::Size(100, 100), true, false,
2976 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
2977 gfx::PointF(), gfx::Size(3, 4), true, false,
2979 SetLayerPropertiesForTesting(
2980 child1
, child_rotation
, gfx::Point3F(25, 25, 0.f
),
2981 gfx::PointF(25.f
, 25.f
), gfx::Size(50, 50), true, false, false);
2983 ExecuteCalculateDrawProperties(root
);
2985 ASSERT_TRUE(render_surface
->render_surface());
2987 EXPECT_EQ(gfx::RectF(100.f
, 100.f
),
2988 root
->render_surface()->DrawableContentRect());
2989 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2991 // Layers that do not draw content should have empty visible content rects.
2992 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
2993 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface
->visible_layer_rect());
2995 // The unclipped surface grows its DrawableContentRect to include all drawable
2996 // regions of the subtree.
2997 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
2998 gfx::Rect expected_surface_drawable_content
=
2999 gfx::Rect(50 - diagonal_radius
,
3000 50 - diagonal_radius
,
3001 diagonal_radius
* 2,
3002 diagonal_radius
* 2);
3003 EXPECT_EQ(gfx::RectF(expected_surface_drawable_content
),
3004 render_surface
->render_surface()->DrawableContentRect());
3006 // All layers that draw content into the unclipped surface are also unclipped.
3007 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
3008 EXPECT_EQ(expected_surface_drawable_content
, child1
->drawable_content_rect());
3011 TEST_F(LayerTreeHostCommonTest
,
3012 DrawableAndVisibleContentRectsWithTransformOnClippedSurface
) {
3013 // Layers that have non-axis aligned bounds (due to transforms) have an
3014 // expanded, axis-aligned DrawableContentRect and visible content rect.
3015 LayerImpl
* root
= root_layer();
3016 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
3017 LayerImpl
* child1
= AddChild
<LayerImpl
>(render_surface
);
3018 child1
->SetDrawsContent(true);
3020 gfx::Transform identity_matrix
;
3021 gfx::Transform child_rotation
;
3022 child_rotation
.Rotate(45.0);
3023 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3024 gfx::PointF(), gfx::Size(50, 50), true, false,
3026 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
3027 gfx::PointF(), gfx::Size(3, 4), true, false,
3030 SetLayerPropertiesForTesting(
3031 child1
, child_rotation
, gfx::Point3F(25, 25, 0.f
),
3032 gfx::PointF(25.f
, 25.f
), gfx::Size(50, 50), true, false, false);
3034 root
->SetMasksToBounds(true);
3036 ExecuteCalculateDrawProperties(root
);
3038 ASSERT_TRUE(render_surface
->render_surface());
3040 // The clipped surface clamps the DrawableContentRect that encloses the
3042 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3043 gfx::Rect unclipped_surface_content
= gfx::Rect(50 - diagonal_radius
,
3044 50 - diagonal_radius
,
3045 diagonal_radius
* 2,
3046 diagonal_radius
* 2);
3047 gfx::RectF
expected_surface_drawable_content(
3048 gfx::IntersectRects(unclipped_surface_content
, gfx::Rect(50, 50)));
3049 EXPECT_EQ(expected_surface_drawable_content
,
3050 render_surface
->render_surface()->DrawableContentRect());
3052 // On the clipped surface, only a quarter of the child1 is visible, but when
3053 // rotating it back to child1's content space, the actual enclosing rect ends
3054 // up covering the full left half of child1.
3056 // Given the floating point math, this number is a little bit fuzzy.
3057 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1
->visible_layer_rect());
3059 // The child's DrawableContentRect is unclipped.
3060 EXPECT_EQ(unclipped_surface_content
, child1
->drawable_content_rect());
3063 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsInHighDPI
) {
3064 LayerImpl
* root
= root_layer();
3065 FakePictureLayerImpl
* render_surface1
=
3066 AddChildToRoot
<FakePictureLayerImpl
>();
3067 render_surface1
->SetDrawsContent(true);
3068 FakePictureLayerImpl
* render_surface2
=
3069 AddChild
<FakePictureLayerImpl
>(render_surface1
);
3070 render_surface2
->SetDrawsContent(true);
3071 FakePictureLayerImpl
* child1
=
3072 AddChild
<FakePictureLayerImpl
>(render_surface2
);
3073 child1
->SetDrawsContent(true);
3074 FakePictureLayerImpl
* child2
=
3075 AddChild
<FakePictureLayerImpl
>(render_surface2
);
3076 child2
->SetDrawsContent(true);
3077 FakePictureLayerImpl
* child3
=
3078 AddChild
<FakePictureLayerImpl
>(render_surface2
);
3079 child3
->SetDrawsContent(true);
3081 gfx::Transform identity_matrix
;
3082 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3083 gfx::PointF(), gfx::Size(100, 100), true, false,
3085 SetLayerPropertiesForTesting(render_surface1
, identity_matrix
, gfx::Point3F(),
3086 gfx::PointF(5.f
, 5.f
), gfx::Size(3, 4), true,
3088 SetLayerPropertiesForTesting(render_surface2
, identity_matrix
, gfx::Point3F(),
3089 gfx::PointF(5.f
, 5.f
), gfx::Size(7, 13), true,
3091 SetLayerPropertiesForTesting(child1
, identity_matrix
, gfx::Point3F(),
3092 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
3094 SetLayerPropertiesForTesting(child2
, identity_matrix
, gfx::Point3F(),
3095 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
3097 SetLayerPropertiesForTesting(child3
, identity_matrix
, gfx::Point3F(),
3098 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
3099 true, false, false);
3101 float device_scale_factor
= 2.f
;
3103 root
->SetMasksToBounds(true);
3105 ExecuteCalculateDrawProperties(root
, device_scale_factor
);
3107 ASSERT_TRUE(render_surface1
->render_surface());
3108 ASSERT_TRUE(render_surface2
->render_surface());
3110 // drawable_content_rects for all layers and surfaces are scaled by
3111 // device_scale_factor.
3112 EXPECT_EQ(gfx::RectF(200.f
, 200.f
),
3113 root
->render_surface()->DrawableContentRect());
3114 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root
->drawable_content_rect());
3115 EXPECT_EQ(gfx::RectF(10.f
, 10.f
, 190.f
, 190.f
),
3116 render_surface1
->render_surface()->DrawableContentRect());
3118 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3119 // is only implicitly clipped by render_surface1.
3120 EXPECT_EQ(gfx::RectF(10.f
, 10.f
, 350.f
, 350.f
),
3121 render_surface2
->render_surface()->DrawableContentRect());
3123 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1
->drawable_content_rect());
3124 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2
->drawable_content_rect());
3125 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3
->drawable_content_rect());
3127 // The root layer does not actually draw content of its own.
3128 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_layer_rect());
3130 // All layer visible content rects are not expressed in content space of each
3131 // layer, so they are not scaled by the device_scale_factor.
3132 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1
->visible_layer_rect());
3133 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2
->visible_layer_rect());
3134 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_layer_rect());
3135 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_layer_rect());
3136 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_layer_rect());
3139 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithoutPreserves3d
) {
3140 // Verify the behavior of back-face culling when there are no preserve-3d
3141 // layers. Note that 3d transforms still apply in this case, but they are
3142 // "flattened" to each parent layer according to current W3C spec.
3144 const gfx::Transform identity_matrix
;
3145 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3146 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3147 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3148 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3149 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3150 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3151 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3152 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3153 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3154 scoped_refptr
<LayerWithForcedDrawsContent
>
3155 front_facing_child_of_front_facing_surface
=
3156 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3157 scoped_refptr
<LayerWithForcedDrawsContent
>
3158 back_facing_child_of_front_facing_surface
=
3159 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3160 scoped_refptr
<LayerWithForcedDrawsContent
>
3161 front_facing_child_of_back_facing_surface
=
3162 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3163 scoped_refptr
<LayerWithForcedDrawsContent
>
3164 back_facing_child_of_back_facing_surface
=
3165 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3167 parent
->AddChild(front_facing_child
);
3168 parent
->AddChild(back_facing_child
);
3169 parent
->AddChild(front_facing_surface
);
3170 parent
->AddChild(back_facing_surface
);
3171 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3172 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3173 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3174 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3176 host()->SetRootLayer(parent
);
3178 // Nothing is double-sided
3179 front_facing_child
->SetDoubleSided(false);
3180 back_facing_child
->SetDoubleSided(false);
3181 front_facing_surface
->SetDoubleSided(false);
3182 back_facing_surface
->SetDoubleSided(false);
3183 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3184 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3185 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3186 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3188 gfx::Transform backface_matrix
;
3189 backface_matrix
.Translate(50.0, 50.0);
3190 backface_matrix
.RotateAboutYAxis(180.0);
3191 backface_matrix
.Translate(-50.0, -50.0);
3193 // Having a descendant and opacity will force these to have render surfaces.
3194 front_facing_surface
->SetOpacity(0.5f
);
3195 back_facing_surface
->SetOpacity(0.5f
);
3197 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3198 // these layers should blindly use their own local transforms to determine
3199 // back-face culling.
3200 SetLayerPropertiesForTesting(parent
.get(),
3204 gfx::Size(100, 100),
3207 SetLayerPropertiesForTesting(front_facing_child
.get(),
3211 gfx::Size(100, 100),
3214 SetLayerPropertiesForTesting(back_facing_child
.get(),
3218 gfx::Size(100, 100),
3221 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3225 gfx::Size(100, 100),
3228 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3232 gfx::Size(100, 100),
3235 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3239 gfx::Size(100, 100),
3242 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3246 gfx::Size(100, 100),
3249 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3253 gfx::Size(100, 100),
3256 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3260 gfx::Size(100, 100),
3264 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3266 // Verify which render surfaces were created.
3267 EXPECT_FALSE(front_facing_child
->has_render_surface());
3268 EXPECT_FALSE(back_facing_child
->has_render_surface());
3269 EXPECT_TRUE(front_facing_surface
->has_render_surface());
3270 EXPECT_TRUE(back_facing_surface
->has_render_surface());
3272 front_facing_child_of_front_facing_surface
->has_render_surface());
3273 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->has_render_surface());
3274 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->has_render_surface());
3275 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->has_render_surface());
3277 EXPECT_EQ(4u, update_layer_list().size());
3278 EXPECT_TRUE(UpdateLayerListContains(front_facing_child
->id()));
3279 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface
->id()));
3280 EXPECT_TRUE(UpdateLayerListContains(
3281 front_facing_child_of_front_facing_surface
->id()));
3283 UpdateLayerListContains(front_facing_child_of_back_facing_surface
->id()));
3286 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithPreserves3d
) {
3287 // Verify the behavior of back-face culling when preserves-3d transform style
3290 const gfx::Transform identity_matrix
;
3291 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3292 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3293 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3294 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3295 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3296 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3297 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3298 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3299 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3300 scoped_refptr
<LayerWithForcedDrawsContent
>
3301 front_facing_child_of_front_facing_surface
=
3302 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3303 scoped_refptr
<LayerWithForcedDrawsContent
>
3304 back_facing_child_of_front_facing_surface
=
3305 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3306 scoped_refptr
<LayerWithForcedDrawsContent
>
3307 front_facing_child_of_back_facing_surface
=
3308 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3309 scoped_refptr
<LayerWithForcedDrawsContent
>
3310 back_facing_child_of_back_facing_surface
=
3311 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3312 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer1
=
3313 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3314 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer2
=
3315 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3317 parent
->AddChild(front_facing_child
);
3318 parent
->AddChild(back_facing_child
);
3319 parent
->AddChild(front_facing_surface
);
3320 parent
->AddChild(back_facing_surface
);
3321 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3322 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3323 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3324 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3326 host()->SetRootLayer(parent
);
3328 // Nothing is double-sided
3329 front_facing_child
->SetDoubleSided(false);
3330 back_facing_child
->SetDoubleSided(false);
3331 front_facing_surface
->SetDoubleSided(false);
3332 back_facing_surface
->SetDoubleSided(false);
3333 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3334 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3335 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3336 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3338 gfx::Transform backface_matrix
;
3339 backface_matrix
.Translate(50.0, 50.0);
3340 backface_matrix
.RotateAboutYAxis(180.0);
3341 backface_matrix
.Translate(-50.0, -50.0);
3343 // Opacity will not force creation of render surfaces in this case because of
3344 // the preserve-3d transform style. Instead, an example of when a surface
3345 // would be created with preserve-3d is when there is a replica layer.
3346 front_facing_surface
->SetReplicaLayer(dummy_replica_layer1
.get());
3347 back_facing_surface
->SetReplicaLayer(dummy_replica_layer2
.get());
3349 // Each surface creates its own new 3d rendering context (as defined by W3C
3350 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3351 // rendering context should use the transform with respect to that context.
3352 // This 3d rendering context occurs when (a) parent's transform style is flat
3353 // and (b) the layer's transform style is preserve-3d.
3354 SetLayerPropertiesForTesting(parent
.get(),
3358 gfx::Size(100, 100),
3360 false); // parent transform style is flat.
3361 SetLayerPropertiesForTesting(front_facing_child
.get(),
3365 gfx::Size(100, 100),
3368 SetLayerPropertiesForTesting(back_facing_child
.get(),
3372 gfx::Size(100, 100),
3375 // surface transform style is preserve-3d.
3376 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3380 gfx::Size(100, 100),
3383 // surface transform style is preserve-3d.
3384 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3388 gfx::Size(100, 100),
3391 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3395 gfx::Size(100, 100),
3398 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3402 gfx::Size(100, 100),
3405 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3409 gfx::Size(100, 100),
3412 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3416 gfx::Size(100, 100),
3420 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3422 // Verify which render surfaces were created and used.
3423 EXPECT_FALSE(front_facing_child
->has_render_surface());
3424 EXPECT_FALSE(back_facing_child
->has_render_surface());
3425 EXPECT_TRUE(front_facing_surface
->has_render_surface());
3426 // We expect that a has_render_surface was created but not used.
3427 EXPECT_TRUE(back_facing_surface
->has_render_surface());
3429 front_facing_child_of_front_facing_surface
->has_render_surface());
3430 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->has_render_surface());
3431 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->has_render_surface());
3432 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->has_render_surface());
3434 EXPECT_EQ(3u, update_layer_list().size());
3436 EXPECT_TRUE(UpdateLayerListContains(front_facing_child
->id()));
3437 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface
->id()));
3438 EXPECT_TRUE(UpdateLayerListContains(
3439 front_facing_child_of_front_facing_surface
->id()));
3442 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithAnimatingTransforms
) {
3443 // Verify that layers are appropriately culled when their back face is showing
3444 // and they are not double sided, while animations are going on.
3446 // Layers that are animating do not get culled on the main thread, as their
3447 // transforms should be treated as "unknown" so we can not be sure that their
3448 // back face is really showing.
3449 const gfx::Transform identity_matrix
;
3450 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3451 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
3452 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3453 scoped_refptr
<LayerWithForcedDrawsContent
> animating_surface
=
3454 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3455 scoped_refptr
<LayerWithForcedDrawsContent
> child_of_animating_surface
=
3456 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3457 scoped_refptr
<LayerWithForcedDrawsContent
> animating_child
=
3458 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3459 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3460 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3462 parent
->AddChild(child
);
3463 parent
->AddChild(animating_surface
);
3464 animating_surface
->AddChild(child_of_animating_surface
);
3465 parent
->AddChild(animating_child
);
3466 parent
->AddChild(child2
);
3468 host()->SetRootLayer(parent
);
3470 // Nothing is double-sided
3471 child
->SetDoubleSided(false);
3472 child2
->SetDoubleSided(false);
3473 animating_surface
->SetDoubleSided(false);
3474 child_of_animating_surface
->SetDoubleSided(false);
3475 animating_child
->SetDoubleSided(false);
3477 gfx::Transform backface_matrix
;
3478 backface_matrix
.Translate(50.0, 50.0);
3479 backface_matrix
.RotateAboutYAxis(180.0);
3480 backface_matrix
.Translate(-50.0, -50.0);
3482 // Make our render surface.
3483 animating_surface
->SetForceRenderSurface(true);
3485 // Animate the transform on the render surface.
3486 AddAnimatedTransformToController(
3487 animating_surface
->layer_animation_controller(), 10.0, 30, 0);
3488 // This is just an animating layer, not a surface.
3489 AddAnimatedTransformToController(
3490 animating_child
->layer_animation_controller(), 10.0, 30, 0);
3492 SetLayerPropertiesForTesting(parent
.get(),
3496 gfx::Size(100, 100),
3499 SetLayerPropertiesForTesting(child
.get(),
3503 gfx::Size(100, 100),
3506 SetLayerPropertiesForTesting(animating_surface
.get(),
3510 gfx::Size(100, 100),
3513 SetLayerPropertiesForTesting(child_of_animating_surface
.get(),
3517 gfx::Size(100, 100),
3520 SetLayerPropertiesForTesting(animating_child
.get(),
3524 gfx::Size(100, 100),
3527 SetLayerPropertiesForTesting(child2
.get(),
3531 gfx::Size(100, 100),
3535 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(parent
.get(),
3537 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3539 EXPECT_FALSE(child
->has_render_surface());
3540 EXPECT_TRUE(animating_surface
->has_render_surface());
3541 EXPECT_FALSE(child_of_animating_surface
->has_render_surface());
3542 EXPECT_FALSE(animating_child
->has_render_surface());
3543 EXPECT_FALSE(child2
->has_render_surface());
3545 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3547 EXPECT_EQ(4u, update_layer_list().size());
3549 // The non-animating child be culled from the layer list for the parent render
3551 EXPECT_TRUE(UpdateLayerListContains(animating_surface
->id()));
3552 EXPECT_TRUE(UpdateLayerListContains(animating_child
->id()));
3553 EXPECT_TRUE(UpdateLayerListContains(child2
->id()));
3554 EXPECT_TRUE(UpdateLayerListContains(child_of_animating_surface
->id()));
3556 EXPECT_FALSE(child2
->visible_rect_from_property_trees().IsEmpty());
3558 // The animating layers should have a visible content rect that represents the
3559 // area of the front face that is within the viewport.
3560 EXPECT_EQ(animating_child
->visible_rect_from_property_trees(),
3561 gfx::Rect(animating_child
->bounds()));
3562 EXPECT_EQ(animating_surface
->visible_rect_from_property_trees(),
3563 gfx::Rect(animating_surface
->bounds()));
3564 // And layers in the subtree of the animating layer should have valid visible
3565 // content rects also.
3566 EXPECT_EQ(child_of_animating_surface
->visible_rect_from_property_trees(),
3567 gfx::Rect(child_of_animating_surface
->bounds()));
3570 TEST_F(LayerTreeHostCommonTest
,
3571 BackFaceCullingWithPreserves3dForFlatteningSurface
) {
3572 // Verify the behavior of back-face culling for a render surface that is
3573 // created when it flattens its subtree, and its parent has preserves-3d.
3575 const gfx::Transform identity_matrix
;
3576 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3577 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3578 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3579 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3580 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3581 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3582 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3583 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3584 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3586 parent
->AddChild(front_facing_surface
);
3587 parent
->AddChild(back_facing_surface
);
3588 front_facing_surface
->AddChild(child1
);
3589 back_facing_surface
->AddChild(child2
);
3591 host()->SetRootLayer(parent
);
3593 // RenderSurfaces are not double-sided
3594 front_facing_surface
->SetDoubleSided(false);
3595 back_facing_surface
->SetDoubleSided(false);
3597 gfx::Transform backface_matrix
;
3598 backface_matrix
.Translate(50.0, 50.0);
3599 backface_matrix
.RotateAboutYAxis(180.0);
3600 backface_matrix
.Translate(-50.0, -50.0);
3602 SetLayerPropertiesForTesting(parent
.get(),
3606 gfx::Size(100, 100),
3608 true); // parent transform style is preserve3d.
3609 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3613 gfx::Size(100, 100),
3615 true); // surface transform style is flat.
3616 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3620 gfx::Size(100, 100),
3622 true); // surface transform style is flat.
3623 SetLayerPropertiesForTesting(child1
.get(),
3627 gfx::Size(100, 100),
3630 SetLayerPropertiesForTesting(child2
.get(),
3634 gfx::Size(100, 100),
3638 front_facing_surface
->Set3dSortingContextId(1);
3639 back_facing_surface
->Set3dSortingContextId(1);
3641 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent
.get());
3643 // Verify which render surfaces were created and used.
3644 EXPECT_TRUE(front_facing_surface
->has_render_surface());
3646 // We expect the render surface to have been created, but remain unused.
3647 EXPECT_TRUE(back_facing_surface
->has_render_surface());
3648 EXPECT_FALSE(child1
->has_render_surface());
3649 EXPECT_FALSE(child2
->has_render_surface());
3651 EXPECT_EQ(2u, update_layer_list().size());
3652 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface
->id()));
3653 EXPECT_TRUE(UpdateLayerListContains(child1
->id()));
3656 TEST_F(LayerTreeHostCommonScalingTest
, LayerTransformsInHighDPI
) {
3657 // Verify draw and screen space transforms of layers not in a surface.
3658 gfx::Transform identity_matrix
;
3660 LayerImpl
* parent
= root_layer();
3661 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
3662 gfx::PointF(), gfx::Size(100, 100), false, true,
3665 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
3666 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
3667 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3670 LayerImpl
* child_empty
= AddChildToRoot
<LayerImpl
>();
3671 SetLayerPropertiesForTesting(child_empty
, identity_matrix
, gfx::Point3F(),
3672 gfx::PointF(2.f
, 2.f
), gfx::Size(), false, true,
3675 float device_scale_factor
= 2.5f
;
3676 gfx::Size
viewport_size(100, 100);
3677 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
3679 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, parent
);
3680 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, child
);
3681 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
, child_empty
);
3683 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
3685 // Verify parent transforms
3686 gfx::Transform expected_parent_transform
;
3687 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
3688 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3689 parent
->screen_space_transform());
3690 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3691 parent
->draw_transform());
3693 // Verify results of transformed parent rects
3694 gfx::RectF
parent_bounds(parent
->bounds());
3696 gfx::RectF parent_draw_rect
=
3697 MathUtil::MapClippedRect(parent
->draw_transform(), parent_bounds
);
3698 gfx::RectF parent_screen_space_rect
=
3699 MathUtil::MapClippedRect(parent
->screen_space_transform(), parent_bounds
);
3701 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
3702 expected_parent_draw_rect
.Scale(device_scale_factor
);
3703 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
3704 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
3706 // Verify child and child_empty transforms. They should match.
3707 gfx::Transform expected_child_transform
;
3708 expected_child_transform
.Scale(device_scale_factor
, device_scale_factor
);
3709 expected_child_transform
.Translate(child
->position().x(),
3710 child
->position().y());
3711 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3712 child
->draw_transform());
3713 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3714 child
->screen_space_transform());
3715 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3716 child_empty
->draw_transform());
3717 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
3718 child_empty
->screen_space_transform());
3720 // Verify results of transformed child and child_empty rects. They should
3722 gfx::RectF
child_bounds(child
->bounds());
3724 gfx::RectF child_draw_rect
=
3725 MathUtil::MapClippedRect(child
->draw_transform(), child_bounds
);
3726 gfx::RectF child_screen_space_rect
=
3727 MathUtil::MapClippedRect(child
->screen_space_transform(), child_bounds
);
3729 gfx::RectF child_empty_draw_rect
=
3730 MathUtil::MapClippedRect(child_empty
->draw_transform(), child_bounds
);
3731 gfx::RectF child_empty_screen_space_rect
= MathUtil::MapClippedRect(
3732 child_empty
->screen_space_transform(), child_bounds
);
3734 gfx::RectF
expected_child_draw_rect(child
->position(), child
->bounds());
3735 expected_child_draw_rect
.Scale(device_scale_factor
);
3736 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
3737 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
3738 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_draw_rect
);
3739 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_screen_space_rect
);
3742 TEST_F(LayerTreeHostCommonScalingTest
, SurfaceLayerTransformsInHighDPI
) {
3743 // Verify draw and screen space transforms of layers in a surface.
3744 gfx::Transform identity_matrix
;
3745 gfx::Transform perspective_matrix
;
3746 perspective_matrix
.ApplyPerspectiveDepth(2.0);
3748 gfx::Transform scale_small_matrix
;
3749 scale_small_matrix
.Scale(SK_MScalar1
/ 10.f
, SK_MScalar1
/ 12.f
);
3751 LayerImpl
* root
= root_layer();
3752 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
3753 gfx::PointF(), gfx::Size(100, 100), false, true,
3755 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
3756 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
3757 gfx::PointF(), gfx::Size(100, 100), false, true,
3760 LayerImpl
* perspective_surface
= AddChild
<LayerImpl
>(parent
);
3761 SetLayerPropertiesForTesting(perspective_surface
,
3762 perspective_matrix
* scale_small_matrix
,
3763 gfx::Point3F(), gfx::PointF(2.f
, 2.f
),
3764 gfx::Size(10, 10), false, true, true);
3765 perspective_surface
->SetDrawsContent(true);
3767 LayerImpl
* scale_surface
= AddChild
<LayerImpl
>(parent
);
3768 SetLayerPropertiesForTesting(scale_surface
, scale_small_matrix
,
3769 gfx::Point3F(), gfx::PointF(2.f
, 2.f
),
3770 gfx::Size(10, 10), false, true, true);
3771 scale_surface
->SetDrawsContent(true);
3773 float device_scale_factor
= 2.5f
;
3774 float page_scale_factor
= 3.f
;
3775 ExecuteCalculateDrawProperties(root
, device_scale_factor
, page_scale_factor
,
3778 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
3779 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
,
3780 perspective_surface
);
3781 // Ideal scale is the max 2d scale component of the combined transform up to
3782 // the nearest render target. Here this includes the layer transform as well
3783 // as the device and page scale factors.
3784 gfx::Transform transform
= scale_small_matrix
;
3785 transform
.Scale(device_scale_factor
* page_scale_factor
,
3786 device_scale_factor
* page_scale_factor
);
3787 gfx::Vector2dF scales
=
3788 MathUtil::ComputeTransform2dScaleComponents(transform
, 0.f
);
3789 float max_2d_scale
= std::max(scales
.x(), scales
.y());
3790 EXPECT_IDEAL_SCALE_EQ(max_2d_scale
, scale_surface
);
3792 // The ideal scale will draw 1:1 with its render target space along
3793 // the larger-scale axis.
3794 gfx::Vector2dF target_space_transform_scales
=
3795 MathUtil::ComputeTransform2dScaleComponents(
3796 scale_surface
->draw_properties().target_space_transform
, 0.f
);
3797 EXPECT_FLOAT_EQ(max_2d_scale
,
3798 std::max(target_space_transform_scales
.x(),
3799 target_space_transform_scales
.y()));
3801 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
3803 gfx::Transform expected_parent_draw_transform
;
3804 expected_parent_draw_transform
.Scale(device_scale_factor
* page_scale_factor
,
3805 device_scale_factor
* page_scale_factor
);
3806 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform
,
3807 parent
->draw_transform());
3809 // The scale for the perspective surface is not known, so it is rendered 1:1
3810 // with the screen, and then scaled during drawing.
3811 gfx::Transform expected_perspective_surface_draw_transform
;
3812 expected_perspective_surface_draw_transform
.Translate(
3813 device_scale_factor
* page_scale_factor
*
3814 perspective_surface
->position().x(),
3815 device_scale_factor
* page_scale_factor
*
3816 perspective_surface
->position().y());
3817 expected_perspective_surface_draw_transform
.PreconcatTransform(
3818 perspective_matrix
);
3819 expected_perspective_surface_draw_transform
.PreconcatTransform(
3820 scale_small_matrix
);
3821 gfx::Transform expected_perspective_surface_layer_draw_transform
;
3822 expected_perspective_surface_layer_draw_transform
.Scale(
3823 device_scale_factor
* page_scale_factor
,
3824 device_scale_factor
* page_scale_factor
);
3825 EXPECT_TRANSFORMATION_MATRIX_EQ(
3826 expected_perspective_surface_draw_transform
,
3827 perspective_surface
->render_surface()->draw_transform());
3828 EXPECT_TRANSFORMATION_MATRIX_EQ(
3829 expected_perspective_surface_layer_draw_transform
,
3830 perspective_surface
->draw_transform());
3833 TEST_F(LayerTreeHostCommonScalingTest
, SmallIdealScale
) {
3834 gfx::Transform parent_scale_matrix
;
3835 SkMScalar initial_parent_scale
= 1.75;
3836 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
3838 gfx::Transform child_scale_matrix
;
3839 SkMScalar initial_child_scale
= 0.25;
3840 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
3842 LayerImpl
* root
= root_layer();
3843 root
->SetBounds(gfx::Size(100, 100));
3845 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
3846 SetLayerPropertiesForTesting(parent
, parent_scale_matrix
, gfx::Point3F(),
3847 gfx::PointF(), gfx::Size(100, 100), false, true,
3850 LayerImpl
* child_scale
= AddChild
<LayerImpl
>(parent
);
3851 SetLayerPropertiesForTesting(child_scale
, child_scale_matrix
, gfx::Point3F(),
3852 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3855 float device_scale_factor
= 2.5f
;
3856 float page_scale_factor
= 0.01f
;
3859 ExecuteCalculateDrawProperties(root
, device_scale_factor
, page_scale_factor
,
3862 // The ideal scale is able to go below 1.
3863 float expected_ideal_scale
=
3864 device_scale_factor
* page_scale_factor
* initial_parent_scale
;
3865 EXPECT_LT(expected_ideal_scale
, 1.f
);
3866 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, parent
);
3868 expected_ideal_scale
= device_scale_factor
* page_scale_factor
*
3869 initial_parent_scale
* initial_child_scale
;
3870 EXPECT_LT(expected_ideal_scale
, 1.f
);
3871 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, child_scale
);
3875 TEST_F(LayerTreeHostCommonScalingTest
, IdealScaleForAnimatingLayer
) {
3876 gfx::Transform parent_scale_matrix
;
3877 SkMScalar initial_parent_scale
= 1.75;
3878 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
3880 gfx::Transform child_scale_matrix
;
3881 SkMScalar initial_child_scale
= 1.25;
3882 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
3884 LayerImpl
* root
= root_layer();
3885 root
->SetBounds(gfx::Size(100, 100));
3887 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
3888 SetLayerPropertiesForTesting(parent
, parent_scale_matrix
, gfx::Point3F(),
3889 gfx::PointF(), gfx::Size(100, 100), false, true,
3892 LayerImpl
* child_scale
= AddChild
<LayerImpl
>(parent
);
3893 SetLayerPropertiesForTesting(child_scale
, child_scale_matrix
, gfx::Point3F(),
3894 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3898 ExecuteCalculateDrawProperties(root
);
3900 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale
, parent
);
3901 // Animating layers compute ideal scale in the same way as when
3903 EXPECT_IDEAL_SCALE_EQ(initial_child_scale
* initial_parent_scale
,
3908 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceTransformsInHighDPI
) {
3909 gfx::Transform identity_matrix
;
3911 LayerImpl
* parent
= root_layer();
3912 parent
->SetDrawsContent(true);
3913 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
3914 gfx::PointF(), gfx::Size(30, 30), false, true,
3917 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
3918 child
->SetDrawsContent(true);
3919 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
3920 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3923 gfx::Transform replica_transform
;
3924 replica_transform
.Scale(1.0, -1.0);
3926 scoped_ptr
<LayerImpl
> replica
=
3927 LayerImpl::Create(host_impl()->active_tree(), 7);
3928 SetLayerPropertiesForTesting(replica
.get(), replica_transform
, gfx::Point3F(),
3929 gfx::PointF(2.f
, 2.f
), gfx::Size(10, 10), false,
3931 child
->SetReplicaLayer(replica
.Pass());
3933 // This layer should end up in the same surface as child, with the same draw
3934 // and screen space transforms.
3935 LayerImpl
* duplicate_child_non_owner
= AddChild
<LayerImpl
>(child
);
3936 duplicate_child_non_owner
->SetDrawsContent(true);
3937 SetLayerPropertiesForTesting(duplicate_child_non_owner
, identity_matrix
,
3938 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
3939 false, true, false);
3941 float device_scale_factor
= 1.5f
;
3942 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
3944 // We should have two render surfaces. The root's render surface and child's
3945 // render surface (it needs one because it has a replica layer).
3946 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
3948 gfx::Transform expected_parent_transform
;
3949 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
3950 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3951 parent
->screen_space_transform());
3952 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
3953 parent
->draw_transform());
3955 gfx::Transform expected_draw_transform
;
3956 expected_draw_transform
.Scale(device_scale_factor
, device_scale_factor
);
3957 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform
,
3958 child
->draw_transform());
3960 gfx::Transform expected_screen_space_transform
;
3961 expected_screen_space_transform
.Scale(device_scale_factor
,
3962 device_scale_factor
);
3963 expected_screen_space_transform
.Translate(child
->position().x(),
3964 child
->position().y());
3965 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform
,
3966 child
->screen_space_transform());
3968 gfx::Transform expected_duplicate_child_draw_transform
=
3969 child
->draw_transform();
3970 EXPECT_TRANSFORMATION_MATRIX_EQ(child
->draw_transform(),
3971 duplicate_child_non_owner
->draw_transform());
3972 EXPECT_TRANSFORMATION_MATRIX_EQ(
3973 child
->screen_space_transform(),
3974 duplicate_child_non_owner
->screen_space_transform());
3975 EXPECT_EQ(child
->drawable_content_rect(),
3976 duplicate_child_non_owner
->drawable_content_rect());
3977 EXPECT_EQ(child
->bounds(), duplicate_child_non_owner
->bounds());
3979 gfx::Transform expected_render_surface_draw_transform
;
3980 expected_render_surface_draw_transform
.Translate(
3981 device_scale_factor
* child
->position().x(),
3982 device_scale_factor
* child
->position().y());
3983 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform
,
3984 child
->render_surface()->draw_transform());
3986 gfx::Transform expected_surface_draw_transform
;
3987 expected_surface_draw_transform
.Translate(device_scale_factor
* 2.f
,
3988 device_scale_factor
* 2.f
);
3989 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform
,
3990 child
->render_surface()->draw_transform());
3992 gfx::Transform expected_surface_screen_space_transform
;
3993 expected_surface_screen_space_transform
.Translate(device_scale_factor
* 2.f
,
3994 device_scale_factor
* 2.f
);
3995 EXPECT_TRANSFORMATION_MATRIX_EQ(
3996 expected_surface_screen_space_transform
,
3997 child
->render_surface()->screen_space_transform());
3999 gfx::Transform expected_replica_draw_transform
;
4000 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
4001 expected_replica_draw_transform
.matrix().set(0, 3, 6.0);
4002 expected_replica_draw_transform
.matrix().set(1, 3, 6.0);
4003 EXPECT_TRANSFORMATION_MATRIX_EQ(
4004 expected_replica_draw_transform
,
4005 child
->render_surface()->replica_draw_transform());
4007 gfx::Transform expected_replica_screen_space_transform
;
4008 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
4009 expected_replica_screen_space_transform
.matrix().set(0, 3, 6.0);
4010 expected_replica_screen_space_transform
.matrix().set(1, 3, 6.0);
4011 EXPECT_TRANSFORMATION_MATRIX_EQ(
4012 expected_replica_screen_space_transform
,
4013 child
->render_surface()->replica_screen_space_transform());
4014 EXPECT_TRANSFORMATION_MATRIX_EQ(
4015 expected_replica_screen_space_transform
,
4016 child
->render_surface()->replica_screen_space_transform());
4019 TEST_F(LayerTreeHostCommonTest
,
4020 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition
) {
4021 gfx::Transform identity_matrix
;
4023 LayerImpl
* parent
= root_layer();
4024 parent
->SetDrawsContent(true);
4025 SetLayerPropertiesForTesting(parent
, identity_matrix
, gfx::Point3F(),
4026 gfx::PointF(), gfx::Size(33, 31), false, true,
4029 LayerImpl
* child
= AddChildToRoot
<LayerImpl
>();
4030 child
->SetDrawsContent(true);
4031 SetLayerPropertiesForTesting(child
, identity_matrix
, gfx::Point3F(),
4032 gfx::PointF(), gfx::Size(13, 11), false, true,
4035 gfx::Transform replica_transform
;
4036 replica_transform
.Scale(1.0, -1.0);
4037 scoped_ptr
<LayerImpl
> replica
=
4038 LayerImpl::Create(host_impl()->active_tree(), 7);
4039 SetLayerPropertiesForTesting(replica
.get(), replica_transform
, gfx::Point3F(),
4040 gfx::PointF(), gfx::Size(13, 11), false, true,
4042 child
->SetReplicaLayer(replica
.Pass());
4044 float device_scale_factor
= 1.7f
;
4045 ExecuteCalculateDrawProperties(parent
, device_scale_factor
);
4047 // We should have two render surfaces. The root's render surface and child's
4048 // render surface (it needs one because it has a replica layer).
4049 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
4051 gfx::Transform identity_transform
;
4052 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
4053 child
->render_surface()->draw_transform());
4054 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
4055 child
->render_surface()->draw_transform());
4056 EXPECT_TRANSFORMATION_MATRIX_EQ(
4057 identity_transform
, child
->render_surface()->screen_space_transform());
4059 gfx::Transform expected_replica_draw_transform
;
4060 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
4061 EXPECT_TRANSFORMATION_MATRIX_EQ(
4062 expected_replica_draw_transform
,
4063 child
->render_surface()->replica_draw_transform());
4065 gfx::Transform expected_replica_screen_space_transform
;
4066 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
4067 EXPECT_TRANSFORMATION_MATRIX_EQ(
4068 expected_replica_screen_space_transform
,
4069 child
->render_surface()->replica_screen_space_transform());
4072 TEST_F(LayerTreeHostCommonTest
, SubtreeSearch
) {
4073 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4074 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
4075 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
4076 scoped_refptr
<Layer
> mask_layer
= Layer::Create(layer_settings());
4077 scoped_refptr
<Layer
> replica_layer
= Layer::Create(layer_settings());
4079 grand_child
->SetReplicaLayer(replica_layer
.get());
4080 child
->AddChild(grand_child
.get());
4081 child
->SetMaskLayer(mask_layer
.get());
4082 root
->AddChild(child
.get());
4084 host()->SetRootLayer(root
);
4086 int nonexistent_id
= -1;
4087 EXPECT_EQ(root
.get(),
4088 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), root
->id()));
4089 EXPECT_EQ(child
.get(),
4090 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), child
->id()));
4093 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), grand_child
->id()));
4096 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), mask_layer
->id()));
4098 replica_layer
.get(),
4099 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), replica_layer
->id()));
4101 0, LayerTreeHostCommon::FindLayerInSubtree(root
.get(), nonexistent_id
));
4104 TEST_F(LayerTreeHostCommonTest
, TransparentChildRenderSurfaceCreation
) {
4105 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4106 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
4107 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
4108 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4110 const gfx::Transform identity_matrix
;
4111 SetLayerPropertiesForTesting(root
.get(),
4115 gfx::Size(100, 100),
4118 SetLayerPropertiesForTesting(child
.get(),
4125 SetLayerPropertiesForTesting(grand_child
.get(),
4133 root
->AddChild(child
);
4134 child
->AddChild(grand_child
);
4135 child
->SetOpacity(0.5f
);
4137 host()->SetRootLayer(root
);
4139 ExecuteCalculateDrawProperties(root
.get());
4141 EXPECT_FALSE(child
->has_render_surface());
4144 TEST_F(LayerTreeHostCommonTest
, OpacityAnimatingOnPendingTree
) {
4145 FakeImplProxy proxy
;
4146 TestSharedBitmapManager shared_bitmap_manager
;
4147 TestTaskGraphRunner task_graph_runner
;
4148 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4149 &task_graph_runner
);
4150 host_impl
.CreatePendingTree();
4151 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4153 const gfx::Transform identity_matrix
;
4154 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4155 gfx::PointF(), gfx::Size(100, 100), true, false,
4157 root
->SetDrawsContent(true);
4159 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4160 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4161 gfx::PointF(), gfx::Size(50, 50), true, false,
4163 child
->SetDrawsContent(true);
4164 child
->SetOpacity(0.0f
);
4166 // Add opacity animation.
4167 AddOpacityTransitionToController(
4168 child
->layer_animation_controller(), 10.0, 0.0f
, 1.0f
, false);
4170 root
->AddChild(child
.Pass());
4171 root
->SetHasRenderSurface(true);
4173 LayerImplList render_surface_layer_list
;
4174 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4175 root
.get(), root
->bounds(), &render_surface_layer_list
);
4176 inputs
.can_adjust_raster_scales
= true;
4177 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4179 // We should have one render surface and two layers. The child
4180 // layer should be included even though it is transparent.
4181 ASSERT_EQ(1u, render_surface_layer_list
.size());
4182 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4185 using LCDTextTestParam
= std::tr1::tuple
<bool, bool, bool>;
4186 class LCDTextTest
: public LayerTreeHostCommonTestBase
,
4187 public testing::TestWithParam
<LCDTextTestParam
> {
4190 : LayerTreeHostCommonTestBase(LayerTreeSettings()),
4191 host_impl_(&proxy_
, &shared_bitmap_manager_
, &task_graph_runner_
),
4194 grand_child_(nullptr) {}
4197 void SetUp() override
{
4198 can_use_lcd_text_
= std::tr1::get
<0>(GetParam());
4199 layers_always_allowed_lcd_text_
= std::tr1::get
<1>(GetParam());
4201 scoped_ptr
<LayerImpl
> root_ptr
=
4202 LayerImpl::Create(host_impl_
.active_tree(), 1);
4203 scoped_ptr
<LayerImpl
> child_ptr
=
4204 LayerImpl::Create(host_impl_
.active_tree(), 2);
4205 scoped_ptr
<LayerImpl
> grand_child_ptr
=
4206 LayerImpl::Create(host_impl_
.active_tree(), 3);
4208 // Stash raw pointers to look at later.
4209 root_
= root_ptr
.get();
4210 child_
= child_ptr
.get();
4211 grand_child_
= grand_child_ptr
.get();
4213 child_
->AddChild(grand_child_ptr
.Pass());
4214 root_
->AddChild(child_ptr
.Pass());
4215 host_impl_
.active_tree()->SetRootLayer(root_ptr
.Pass());
4217 root_
->SetContentsOpaque(true);
4218 child_
->SetContentsOpaque(true);
4219 grand_child_
->SetContentsOpaque(true);
4221 root_
->SetDrawsContent(true);
4222 child_
->SetDrawsContent(true);
4223 grand_child_
->SetDrawsContent(true);
4225 gfx::Transform identity_matrix
;
4226 SetLayerPropertiesForTesting(root_
, identity_matrix
, gfx::Point3F(),
4227 gfx::PointF(), gfx::Size(1, 1), true, false,
4229 SetLayerPropertiesForTesting(child_
, identity_matrix
, gfx::Point3F(),
4230 gfx::PointF(), gfx::Size(1, 1), true, false,
4231 std::tr1::get
<2>(GetParam()));
4232 SetLayerPropertiesForTesting(grand_child_
, identity_matrix
, gfx::Point3F(),
4233 gfx::PointF(), gfx::Size(1, 1), true, false,
4237 bool can_use_lcd_text_
;
4238 bool layers_always_allowed_lcd_text_
;
4240 FakeImplProxy proxy_
;
4241 TestSharedBitmapManager shared_bitmap_manager_
;
4242 TestTaskGraphRunner task_graph_runner_
;
4243 FakeLayerTreeHostImpl host_impl_
;
4247 LayerImpl
* grand_child_
;
4250 TEST_P(LCDTextTest
, CanUseLCDText
) {
4251 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4252 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4254 // Case 1: Identity transform.
4255 gfx::Transform identity_matrix
;
4256 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4257 layers_always_allowed_lcd_text_
);
4258 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4259 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4260 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4262 // Case 2: Integral translation.
4263 gfx::Transform integral_translation
;
4264 integral_translation
.Translate(1.0, 2.0);
4265 child_
->SetTransform(integral_translation
);
4266 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4267 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4268 layers_always_allowed_lcd_text_
);
4269 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4270 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4271 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4273 // Case 3: Non-integral translation.
4274 gfx::Transform non_integral_translation
;
4275 non_integral_translation
.Translate(1.5, 2.5);
4276 child_
->SetTransform(non_integral_translation
);
4277 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4278 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4279 layers_always_allowed_lcd_text_
);
4280 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4281 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4282 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4284 // Case 4: Rotation.
4285 gfx::Transform rotation
;
4286 rotation
.Rotate(10.0);
4287 child_
->SetTransform(rotation
);
4288 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4289 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4290 layers_always_allowed_lcd_text_
);
4291 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4292 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4293 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4296 gfx::Transform scale
;
4297 scale
.Scale(2.0, 2.0);
4298 child_
->SetTransform(scale
);
4299 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4300 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4301 layers_always_allowed_lcd_text_
);
4302 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4303 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4304 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4307 gfx::Transform skew
;
4308 skew
.Skew(10.0, 0.0);
4309 child_
->SetTransform(skew
);
4310 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4311 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4312 layers_always_allowed_lcd_text_
);
4313 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4314 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4315 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4317 // Case 7: Translucent.
4318 child_
->SetTransform(identity_matrix
);
4319 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4320 child_
->SetOpacity(0.5f
);
4321 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4322 layers_always_allowed_lcd_text_
);
4323 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4324 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4325 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4327 // Case 8: Sanity check: restore transform and opacity.
4328 child_
->SetTransform(identity_matrix
);
4329 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4330 child_
->SetOpacity(1.f
);
4331 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4332 layers_always_allowed_lcd_text_
);
4333 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4334 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4335 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4337 // Case 9: Non-opaque content.
4338 child_
->SetContentsOpaque(false);
4339 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4340 layers_always_allowed_lcd_text_
);
4341 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4342 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4343 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4345 // Case 10: Sanity check: restore content opaqueness.
4346 child_
->SetContentsOpaque(true);
4347 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4348 layers_always_allowed_lcd_text_
);
4349 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4350 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4351 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4354 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimation
) {
4355 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4356 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4358 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4359 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4360 layers_always_allowed_lcd_text_
);
4361 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4362 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4363 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4365 // Add opacity animation.
4366 child_
->SetOpacity(0.9f
);
4367 child_
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
4368 AddOpacityTransitionToController(
4369 child_
->layer_animation_controller(), 10.0, 0.9f
, 0.1f
, false);
4371 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4372 layers_always_allowed_lcd_text_
);
4373 // Text LCD should be adjusted while animation is active.
4374 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4375 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4376 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
4379 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimationContentsOpaque
) {
4380 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
4381 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
4383 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
4384 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4385 layers_always_allowed_lcd_text_
);
4386 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4387 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
4388 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4390 // Mark contents non-opaque within the first animation frame.
4391 child_
->SetContentsOpaque(false);
4392 AddOpacityTransitionToController(child_
->layer_animation_controller(), 10.0,
4395 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
4396 layers_always_allowed_lcd_text_
);
4397 // LCD text should be disabled for non-opaque layers even during animations.
4398 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
4399 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
4400 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
4403 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest
,
4405 testing::Combine(testing::Bool(),
4409 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayerImpl
) {
4410 FakeImplProxy proxy
;
4411 TestSharedBitmapManager shared_bitmap_manager
;
4412 TestTaskGraphRunner task_graph_runner
;
4413 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4414 &task_graph_runner
);
4415 host_impl
.CreatePendingTree();
4416 const gfx::Transform identity_matrix
;
4418 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4419 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4420 gfx::PointF(), gfx::Size(50, 50), true, false,
4422 root
->SetDrawsContent(true);
4424 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4425 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4426 gfx::PointF(), gfx::Size(40, 40), true, false,
4428 child
->SetDrawsContent(true);
4430 scoped_ptr
<LayerImpl
> grand_child
=
4431 LayerImpl::Create(host_impl
.pending_tree(), 3);
4432 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
4433 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4434 true, false, false);
4435 grand_child
->SetDrawsContent(true);
4436 grand_child
->SetHideLayerAndSubtree(true);
4438 child
->AddChild(grand_child
.Pass());
4439 root
->AddChild(child
.Pass());
4440 root
->SetHasRenderSurface(true);
4442 LayerImplList render_surface_layer_list
;
4443 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4444 root
.get(), root
->bounds(), &render_surface_layer_list
);
4445 inputs
.can_adjust_raster_scales
= true;
4446 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4448 // We should have one render surface and two layers. The grand child has
4450 ASSERT_EQ(1u, render_surface_layer_list
.size());
4451 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4452 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
4453 EXPECT_EQ(2, root
->render_surface()->layer_list().at(1)->id());
4456 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayersImpl
) {
4457 FakeImplProxy proxy
;
4458 TestSharedBitmapManager shared_bitmap_manager
;
4459 TestTaskGraphRunner task_graph_runner
;
4460 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4461 &task_graph_runner
);
4462 host_impl
.CreatePendingTree();
4463 const gfx::Transform identity_matrix
;
4465 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4466 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4467 gfx::PointF(), gfx::Size(50, 50), true, false,
4469 root
->SetDrawsContent(true);
4471 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
4472 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
4473 gfx::PointF(), gfx::Size(40, 40), true, false,
4475 child
->SetDrawsContent(true);
4476 child
->SetHideLayerAndSubtree(true);
4478 scoped_ptr
<LayerImpl
> grand_child
=
4479 LayerImpl::Create(host_impl
.pending_tree(), 3);
4480 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
4481 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4482 true, false, false);
4483 grand_child
->SetDrawsContent(true);
4485 child
->AddChild(grand_child
.Pass());
4486 root
->AddChild(child
.Pass());
4488 LayerImplList render_surface_layer_list
;
4489 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4490 root
.get(), root
->bounds(), &render_surface_layer_list
);
4491 inputs
.can_adjust_raster_scales
= true;
4492 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4494 // We should have one render surface and one layers. The child has
4495 // hidden itself and the grand child.
4496 ASSERT_EQ(1u, render_surface_layer_list
.size());
4497 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
4498 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
4501 void EmptyCopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
4503 TEST_F(LayerTreeHostCommonTest
, SubtreeHiddenWithCopyRequest
) {
4504 FakeImplProxy proxy
;
4505 TestSharedBitmapManager shared_bitmap_manager
;
4506 TestTaskGraphRunner task_graph_runner
;
4507 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4508 &task_graph_runner
);
4509 host_impl
.CreatePendingTree();
4510 const gfx::Transform identity_matrix
;
4512 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4513 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4514 gfx::PointF(), gfx::Size(50, 50), true, false,
4516 root
->SetDrawsContent(true);
4518 scoped_ptr
<LayerImpl
> copy_grand_parent
=
4519 LayerImpl::Create(host_impl
.pending_tree(), 2);
4520 SetLayerPropertiesForTesting(copy_grand_parent
.get(), identity_matrix
,
4521 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
4522 true, false, false);
4523 copy_grand_parent
->SetDrawsContent(true);
4524 LayerImpl
* copy_grand_parent_layer
= copy_grand_parent
.get();
4526 scoped_ptr
<LayerImpl
> copy_parent
=
4527 LayerImpl::Create(host_impl
.pending_tree(), 3);
4528 SetLayerPropertiesForTesting(copy_parent
.get(), identity_matrix
,
4529 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4531 copy_parent
->SetDrawsContent(true);
4532 LayerImpl
* copy_parent_layer
= copy_parent
.get();
4534 scoped_ptr
<LayerImpl
> copy_request
=
4535 LayerImpl::Create(host_impl
.pending_tree(), 4);
4536 SetLayerPropertiesForTesting(copy_request
.get(), identity_matrix
,
4537 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4539 copy_request
->SetDrawsContent(true);
4540 LayerImpl
* copy_layer
= copy_request
.get();
4542 scoped_ptr
<LayerImpl
> copy_child
=
4543 LayerImpl::Create(host_impl
.pending_tree(), 5);
4544 SetLayerPropertiesForTesting(copy_child
.get(), identity_matrix
,
4545 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4546 true, false, false);
4547 copy_child
->SetDrawsContent(true);
4548 LayerImpl
* copy_child_layer
= copy_child
.get();
4550 scoped_ptr
<LayerImpl
> copy_grand_parent_sibling_before
=
4551 LayerImpl::Create(host_impl
.pending_tree(), 6);
4552 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before
.get(),
4553 identity_matrix
, gfx::Point3F(), gfx::PointF(),
4554 gfx::Size(40, 40), true, false, false);
4555 copy_grand_parent_sibling_before
->SetDrawsContent(true);
4556 LayerImpl
* copy_grand_parent_sibling_before_layer
=
4557 copy_grand_parent_sibling_before
.get();
4559 scoped_ptr
<LayerImpl
> copy_grand_parent_sibling_after
=
4560 LayerImpl::Create(host_impl
.pending_tree(), 7);
4561 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after
.get(),
4562 identity_matrix
, gfx::Point3F(), gfx::PointF(),
4563 gfx::Size(40, 40), true, false, false);
4564 copy_grand_parent_sibling_after
->SetDrawsContent(true);
4565 LayerImpl
* copy_grand_parent_sibling_after_layer
=
4566 copy_grand_parent_sibling_after
.get();
4568 copy_request
->AddChild(copy_child
.Pass());
4569 copy_parent
->AddChild(copy_request
.Pass());
4570 copy_grand_parent
->AddChild(copy_parent
.Pass());
4571 root
->AddChild(copy_grand_parent_sibling_before
.Pass());
4572 root
->AddChild(copy_grand_parent
.Pass());
4573 root
->AddChild(copy_grand_parent_sibling_after
.Pass());
4575 // Hide the copy_grand_parent and its subtree. But make a copy request in that
4576 // hidden subtree on copy_layer.
4577 copy_grand_parent_layer
->SetHideLayerAndSubtree(true);
4578 copy_grand_parent_sibling_before_layer
->SetHideLayerAndSubtree(true);
4579 copy_grand_parent_sibling_after_layer
->SetHideLayerAndSubtree(true);
4581 ScopedPtrVector
<CopyOutputRequest
> copy_requests
;
4582 copy_requests
.push_back(
4583 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
4584 copy_layer
->PassCopyRequests(©_requests
);
4585 EXPECT_TRUE(copy_layer
->HasCopyRequest());
4587 LayerImplList render_surface_layer_list
;
4588 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4589 root
.get(), root
->bounds(), &render_surface_layer_list
);
4590 inputs
.can_adjust_raster_scales
= true;
4591 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4593 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
4594 EXPECT_TRUE(copy_grand_parent_layer
->draw_properties()
4595 .layer_or_descendant_has_copy_request
);
4596 EXPECT_TRUE(copy_parent_layer
->draw_properties()
4597 .layer_or_descendant_has_copy_request
);
4599 copy_layer
->draw_properties().layer_or_descendant_has_copy_request
);
4601 copy_child_layer
->draw_properties().layer_or_descendant_has_copy_request
);
4602 EXPECT_FALSE(copy_grand_parent_sibling_before_layer
->draw_properties()
4603 .layer_or_descendant_has_copy_request
);
4604 EXPECT_FALSE(copy_grand_parent_sibling_after_layer
->draw_properties()
4605 .layer_or_descendant_has_copy_request
);
4607 // We should have three render surfaces, one for the root, one for the parent
4608 // since it owns a surface, and one for the copy_layer.
4609 ASSERT_EQ(3u, render_surface_layer_list
.size());
4610 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
4611 EXPECT_EQ(copy_parent_layer
->id(), render_surface_layer_list
.at(1)->id());
4612 EXPECT_EQ(copy_layer
->id(), render_surface_layer_list
.at(2)->id());
4614 // The root render surface should have 2 contributing layers. The
4615 // copy_grand_parent is hidden along with its siblings, but the copy_parent
4616 // will appear since something in its subtree needs to be drawn for a copy
4618 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
4619 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
4620 EXPECT_EQ(copy_parent_layer
->id(),
4621 root
->render_surface()->layer_list().at(1)->id());
4623 // Nothing actually draws into the copy parent, so only the copy_layer will
4624 // appear in its list, since it needs to be drawn for the copy request.
4625 ASSERT_EQ(1u, copy_parent_layer
->render_surface()->layer_list().size());
4626 EXPECT_EQ(copy_layer
->id(),
4627 copy_parent_layer
->render_surface()->layer_list().at(0)->id());
4629 // The copy_layer's render surface should have two contributing layers.
4630 ASSERT_EQ(2u, copy_layer
->render_surface()->layer_list().size());
4631 EXPECT_EQ(copy_layer
->id(),
4632 copy_layer
->render_surface()->layer_list().at(0)->id());
4633 EXPECT_EQ(copy_child_layer
->id(),
4634 copy_layer
->render_surface()->layer_list().at(1)->id());
4637 TEST_F(LayerTreeHostCommonTest
, ClippedOutCopyRequest
) {
4638 FakeImplProxy proxy
;
4639 TestSharedBitmapManager shared_bitmap_manager
;
4640 TestTaskGraphRunner task_graph_runner
;
4641 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4642 &task_graph_runner
);
4643 host_impl
.CreatePendingTree();
4644 const gfx::Transform identity_matrix
;
4646 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
4647 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
4648 gfx::PointF(), gfx::Size(50, 50), true, false,
4650 root
->SetDrawsContent(true);
4652 scoped_ptr
<LayerImpl
> copy_parent
=
4653 LayerImpl::Create(host_impl
.pending_tree(), 2);
4654 SetLayerPropertiesForTesting(copy_parent
.get(), identity_matrix
,
4655 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
4657 copy_parent
->SetDrawsContent(true);
4658 copy_parent
->SetMasksToBounds(true);
4660 scoped_ptr
<LayerImpl
> copy_layer
=
4661 LayerImpl::Create(host_impl
.pending_tree(), 3);
4662 SetLayerPropertiesForTesting(copy_layer
.get(), identity_matrix
,
4663 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
4665 copy_layer
->SetDrawsContent(true);
4667 scoped_ptr
<LayerImpl
> copy_child
=
4668 LayerImpl::Create(host_impl
.pending_tree(), 4);
4669 SetLayerPropertiesForTesting(copy_child
.get(), identity_matrix
,
4670 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
4671 true, false, false);
4672 copy_child
->SetDrawsContent(true);
4674 ScopedPtrVector
<CopyOutputRequest
> copy_requests
;
4675 copy_requests
.push_back(
4676 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
4677 copy_layer
->PassCopyRequests(©_requests
);
4678 EXPECT_TRUE(copy_layer
->HasCopyRequest());
4680 copy_layer
->AddChild(copy_child
.Pass());
4681 copy_parent
->AddChild(copy_layer
.Pass());
4682 root
->AddChild(copy_parent
.Pass());
4684 LayerImplList render_surface_layer_list
;
4685 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
4686 root
.get(), root
->bounds(), &render_surface_layer_list
);
4687 inputs
.can_adjust_raster_scales
= true;
4688 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4690 // We should have one render surface, as the others are clipped out.
4691 ASSERT_EQ(1u, render_surface_layer_list
.size());
4692 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
4694 // The root render surface should only have 1 contributing layer, since the
4695 // other layers are empty/clipped away.
4696 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
4697 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
4700 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInsideSurface
) {
4701 FakeImplProxy proxy
;
4702 TestSharedBitmapManager shared_bitmap_manager
;
4703 TestTaskGraphRunner task_graph_runner
;
4704 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
4705 &task_graph_runner
);
4706 host_impl
.CreatePendingTree();
4707 const gfx::Transform identity_matrix
;
4709 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4710 SetLayerPropertiesForTesting(root
.get(),
4717 root
->SetIsDrawable(true);
4719 // The surface is moved slightly outside of the viewport.
4720 scoped_refptr
<Layer
> surface
= Layer::Create(layer_settings());
4721 SetLayerPropertiesForTesting(surface
.get(),
4724 gfx::PointF(-10, -20),
4728 surface
->SetForceRenderSurface(true);
4730 scoped_refptr
<Layer
> surface_child
= Layer::Create(layer_settings());
4731 SetLayerPropertiesForTesting(surface_child
.get(),
4738 surface_child
->SetIsDrawable(true);
4740 surface
->AddChild(surface_child
);
4741 root
->AddChild(surface
);
4743 host()->SetRootLayer(root
);
4745 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(root
.get(),
4747 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4749 // The visible_layer_rect for the |surface_child| should not be clipped by
4751 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
4752 surface_child
->visible_rect_from_property_trees().ToString());
4755 TEST_F(LayerTreeHostCommonTest
, TransformedClipParent
) {
4756 // Ensure that a transform between the layer and its render surface is not a
4757 // problem. Constructs the following layer tree.
4759 // root (a render surface)
4761 // + clip_parent (scaled)
4762 // + intervening_clipping_layer
4765 // The render surface should be resized correctly and the clip child should
4766 // inherit the right clip rect.
4767 LayerImpl
* root
= root_layer();
4768 LayerImpl
* render_surface
= AddChildToRoot
<LayerImpl
>();
4769 LayerImpl
* clip_parent
= AddChild
<LayerImpl
>(render_surface
);
4770 LayerImpl
* intervening
= AddChild
<LayerImpl
>(clip_parent
);
4771 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(intervening
);
4772 clip_child
->SetDrawsContent(true);
4773 clip_child
->SetClipParent(clip_parent
);
4774 scoped_ptr
<std::set
<LayerImpl
*>> clip_children(new std::set
<LayerImpl
*>);
4775 clip_children
->insert(clip_child
);
4776 clip_parent
->SetClipChildren(clip_children
.release());
4778 intervening
->SetMasksToBounds(true);
4779 clip_parent
->SetMasksToBounds(true);
4781 gfx::Transform scale_transform
;
4782 scale_transform
.Scale(2, 2);
4784 gfx::Transform identity_transform
;
4786 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
4787 gfx::PointF(), gfx::Size(50, 50), true, false,
4789 SetLayerPropertiesForTesting(render_surface
, identity_transform
,
4790 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4792 SetLayerPropertiesForTesting(clip_parent
, scale_transform
, gfx::Point3F(),
4793 gfx::PointF(1.f
, 1.f
), gfx::Size(10, 10), true,
4795 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
4796 gfx::PointF(1.f
, 1.f
), gfx::Size(5, 5), true,
4798 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
4799 gfx::PointF(1.f
, 1.f
), gfx::Size(10, 10), true,
4802 ExecuteCalculateDrawProperties(root
);
4804 ASSERT_TRUE(root
->render_surface());
4805 ASSERT_TRUE(render_surface
->render_surface());
4807 // Ensure that we've inherited our clip parent's clip and weren't affected
4808 // by the intervening clip layer.
4809 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
4810 clip_parent
->clip_rect().ToString());
4811 ASSERT_EQ(clip_parent
->clip_rect().ToString(),
4812 clip_child
->clip_rect().ToString());
4813 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
4814 intervening
->clip_rect().ToString());
4816 // Ensure that the render surface reports a content rect that has been grown
4817 // to accomodate for the clip child.
4818 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
4819 render_surface
->render_surface()->content_rect().ToString());
4821 // The above check implies the two below, but they nicely demonstrate that
4822 // we've grown, despite the intervening layer's clip.
4823 ASSERT_TRUE(clip_parent
->clip_rect().Contains(
4824 render_surface
->render_surface()->content_rect()));
4825 ASSERT_FALSE(intervening
->clip_rect().Contains(
4826 render_surface
->render_surface()->content_rect()));
4829 TEST_F(LayerTreeHostCommonTest
, ClipParentWithInterveningRenderSurface
) {
4830 // Ensure that intervening render surfaces are not a problem in the basic
4831 // case. In the following tree, both render surfaces should be resized to
4832 // accomodate for the clip child, despite an intervening clip.
4834 // root (a render surface)
4835 // + clip_parent (masks to bounds)
4836 // + render_surface1 (sets opacity)
4837 // + intervening (masks to bounds)
4838 // + render_surface2 (also sets opacity)
4841 LayerImpl
* root
= root_layer();
4842 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
4843 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(clip_parent
);
4844 LayerImpl
* intervening
= AddChild
<LayerImpl
>(render_surface1
);
4845 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(intervening
);
4846 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(render_surface2
);
4847 clip_child
->SetDrawsContent(true);
4849 clip_child
->SetClipParent(clip_parent
);
4851 intervening
->SetMasksToBounds(true);
4852 clip_parent
->SetMasksToBounds(true);
4854 gfx::Transform translation_transform
;
4855 translation_transform
.Translate(2, 2);
4857 gfx::Transform identity_transform
;
4858 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
4859 gfx::PointF(), gfx::Size(50, 50), true, false,
4861 SetLayerPropertiesForTesting(clip_parent
, translation_transform
,
4862 gfx::Point3F(), gfx::PointF(1.f
, 1.f
),
4863 gfx::Size(40, 40), true, false, false);
4864 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
4865 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4867 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
4868 gfx::PointF(1.f
, 1.f
), gfx::Size(5, 5), true,
4870 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
4871 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4873 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
4874 gfx::PointF(-10.f
, -10.f
), gfx::Size(60, 60),
4875 true, false, false);
4877 ExecuteCalculateDrawProperties(root
);
4879 EXPECT_TRUE(root
->render_surface());
4880 EXPECT_TRUE(render_surface1
->render_surface());
4881 EXPECT_TRUE(render_surface2
->render_surface());
4883 // Since the render surfaces could have expanded, they should not clip (their
4884 // bounds would no longer be reliable). We should resort to layer clipping
4886 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4887 render_surface1
->render_surface()->clip_rect().ToString());
4888 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
4889 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4890 render_surface2
->render_surface()->clip_rect().ToString());
4891 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
4893 // NB: clip rects are in target space.
4894 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4895 render_surface1
->clip_rect().ToString());
4896 EXPECT_TRUE(render_surface1
->is_clipped());
4898 // This value is inherited from the clipping ancestor layer, 'intervening'.
4899 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
4900 render_surface2
->clip_rect().ToString());
4901 EXPECT_TRUE(render_surface2
->is_clipped());
4903 // The content rects of both render surfaces should both have expanded to
4904 // contain the clip child.
4905 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4906 render_surface1
->render_surface()->content_rect().ToString());
4907 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
4908 render_surface2
->render_surface()->content_rect().ToString());
4910 // The clip child should have inherited the clip parent's clip (projected to
4911 // the right space, of course), and should have the correctly sized visible
4913 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
4914 clip_child
->clip_rect().ToString());
4915 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
4916 clip_child
->visible_layer_rect().ToString());
4917 EXPECT_TRUE(clip_child
->is_clipped());
4920 TEST_F(LayerTreeHostCommonTest
, ClipParentScrolledInterveningLayer
) {
4921 // Ensure that intervening render surfaces are not a problem, even if there
4922 // is a scroll involved. Note, we do _not_ have to consider any other sort
4925 // root (a render surface)
4926 // + clip_parent (masks to bounds)
4927 // + render_surface1 (sets opacity)
4928 // + intervening (masks to bounds AND scrolls)
4929 // + render_surface2 (also sets opacity)
4932 LayerImpl
* root
= root_layer();
4933 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
4934 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(clip_parent
);
4935 LayerImpl
* intervening
= AddChild
<LayerImpl
>(render_surface1
);
4936 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(intervening
);
4937 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(render_surface2
);
4938 clip_child
->SetDrawsContent(true);
4940 clip_child
->SetClipParent(clip_parent
);
4942 intervening
->SetMasksToBounds(true);
4943 clip_parent
->SetMasksToBounds(true);
4944 intervening
->SetScrollClipLayer(clip_parent
->id());
4945 intervening
->SetCurrentScrollOffset(gfx::ScrollOffset(3, 3));
4947 gfx::Transform translation_transform
;
4948 translation_transform
.Translate(2, 2);
4950 gfx::Transform identity_transform
;
4951 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
4952 gfx::PointF(), gfx::Size(50, 50), true, false,
4954 SetLayerPropertiesForTesting(clip_parent
, translation_transform
,
4955 gfx::Point3F(), gfx::PointF(1.f
, 1.f
),
4956 gfx::Size(40, 40), true, false, false);
4957 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
4958 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4960 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
4961 gfx::PointF(1.f
, 1.f
), gfx::Size(5, 5), true,
4963 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
4964 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
4966 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
4967 gfx::PointF(-10.f
, -10.f
), gfx::Size(60, 60),
4968 true, false, false);
4970 ExecuteCalculateDrawProperties(root
);
4972 EXPECT_TRUE(root
->render_surface());
4973 EXPECT_TRUE(render_surface1
->render_surface());
4974 EXPECT_TRUE(render_surface2
->render_surface());
4976 // Since the render surfaces could have expanded, they should not clip (their
4977 // bounds would no longer be reliable). We should resort to layer clipping
4979 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4980 render_surface1
->render_surface()->clip_rect().ToString());
4981 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
4982 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
4983 render_surface2
->render_surface()->clip_rect().ToString());
4984 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
4986 // NB: clip rects are in target space.
4987 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4988 render_surface1
->clip_rect().ToString());
4989 EXPECT_TRUE(render_surface1
->is_clipped());
4991 // This value is inherited from the clipping ancestor layer, 'intervening'.
4992 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
4993 render_surface2
->clip_rect().ToString());
4994 EXPECT_TRUE(render_surface2
->is_clipped());
4996 // The content rects of both render surfaces should both have expanded to
4997 // contain the clip child.
4998 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
4999 render_surface1
->render_surface()->content_rect().ToString());
5000 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
5001 render_surface2
->render_surface()->content_rect().ToString());
5003 // The clip child should have inherited the clip parent's clip (projected to
5004 // the right space, of course), and should have the correctly sized visible
5006 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
5007 clip_child
->clip_rect().ToString());
5008 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
5009 clip_child
->visible_layer_rect().ToString());
5010 EXPECT_TRUE(clip_child
->is_clipped());
5013 TEST_F(LayerTreeHostCommonTest
, DescendantsOfClipChildren
) {
5014 // Ensures that descendants of the clip child inherit the correct clip.
5016 // root (a render surface)
5017 // + clip_parent (masks to bounds)
5018 // + intervening (masks to bounds)
5022 LayerImpl
* root
= root_layer();
5023 LayerImpl
* clip_parent
= AddChild
<LayerImpl
>(root
);
5024 LayerImpl
* intervening
= AddChild
<LayerImpl
>(clip_parent
);
5025 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(intervening
);
5026 LayerImpl
* child
= AddChild
<LayerImpl
>(clip_child
);
5027 child
->SetDrawsContent(true);
5029 clip_child
->SetClipParent(clip_parent
);
5030 scoped_ptr
<std::set
<LayerImpl
*>> clip_children(new std::set
<LayerImpl
*>);
5031 clip_children
->insert(clip_child
);
5032 clip_parent
->SetClipChildren(clip_children
.release());
5034 intervening
->SetMasksToBounds(true);
5035 clip_parent
->SetMasksToBounds(true);
5037 gfx::Transform identity_transform
;
5038 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5039 gfx::PointF(), gfx::Size(50, 50), true, false,
5041 SetLayerPropertiesForTesting(clip_parent
, identity_transform
, gfx::Point3F(),
5042 gfx::PointF(), gfx::Size(40, 40), true, false,
5044 SetLayerPropertiesForTesting(intervening
, identity_transform
, gfx::Point3F(),
5045 gfx::PointF(), gfx::Size(5, 5), true, false,
5047 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
5048 gfx::PointF(), gfx::Size(60, 60), true, false,
5050 SetLayerPropertiesForTesting(child
, identity_transform
, gfx::Point3F(),
5051 gfx::PointF(), gfx::Size(60, 60), true, false,
5054 ExecuteCalculateDrawProperties(root
);
5056 EXPECT_TRUE(root
->render_surface());
5058 // Neither the clip child nor its descendant should have inherited the clip
5059 // from |intervening|.
5060 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5061 clip_child
->clip_rect().ToString());
5062 EXPECT_TRUE(clip_child
->is_clipped());
5063 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
5064 child
->visible_layer_rect().ToString());
5065 EXPECT_TRUE(child
->is_clipped());
5068 TEST_F(LayerTreeHostCommonTest
,
5069 SurfacesShouldBeUnaffectedByNonDescendantClipChildren
) {
5070 // Ensures that non-descendant clip children in the tree do not affect
5073 // root (a render surface)
5074 // + clip_parent (masks to bounds)
5075 // + render_surface1
5077 // + render_surface2
5080 // In this example render_surface2 should be unaffected by clip_child.
5081 LayerImpl
* root
= root_layer();
5082 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
5083 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(clip_parent
);
5084 LayerImpl
* clip_child
= AddChild
<LayerImpl
>(render_surface1
);
5085 clip_child
->SetDrawsContent(true);
5086 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(clip_parent
);
5087 LayerImpl
* non_clip_child
= AddChild
<LayerImpl
>(render_surface2
);
5088 non_clip_child
->SetDrawsContent(true);
5090 clip_child
->SetClipParent(clip_parent
);
5091 scoped_ptr
<std::set
<LayerImpl
*>> clip_children(new std::set
<LayerImpl
*>);
5092 clip_children
->insert(clip_child
);
5093 clip_parent
->SetClipChildren(clip_children
.release());
5095 clip_parent
->SetMasksToBounds(true);
5096 render_surface1
->SetMasksToBounds(true);
5098 gfx::Transform identity_transform
;
5099 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5100 gfx::PointF(), gfx::Size(15, 15), true, false,
5102 SetLayerPropertiesForTesting(clip_parent
, identity_transform
, gfx::Point3F(),
5103 gfx::PointF(), gfx::Size(10, 10), true, false,
5105 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
5106 gfx::Point3F(), gfx::PointF(5, 5),
5107 gfx::Size(5, 5), true, false, true);
5108 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
5109 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5111 SetLayerPropertiesForTesting(clip_child
, identity_transform
, gfx::Point3F(),
5112 gfx::PointF(-1, 1), gfx::Size(10, 10), true,
5114 SetLayerPropertiesForTesting(non_clip_child
, identity_transform
,
5115 gfx::Point3F(), gfx::PointF(), gfx::Size(5, 5),
5116 true, false, false);
5118 ExecuteCalculateDrawProperties(root
);
5120 EXPECT_TRUE(root
->render_surface());
5121 EXPECT_TRUE(render_surface1
->render_surface());
5122 EXPECT_TRUE(render_surface2
->render_surface());
5124 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5125 render_surface1
->clip_rect().ToString());
5126 EXPECT_TRUE(render_surface1
->is_clipped());
5128 // The render surface should not clip (it has unclipped descendants), instead
5129 // it should rely on layer clipping.
5130 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
5131 render_surface1
->render_surface()->clip_rect().ToString());
5132 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
5134 // That said, it should have grown to accomodate the unclipped descendant.
5135 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
5136 render_surface1
->render_surface()->content_rect().ToString());
5138 // This render surface should clip. It has no unclipped descendants.
5139 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5140 render_surface2
->clip_rect().ToString());
5141 EXPECT_TRUE(render_surface2
->render_surface()->is_clipped());
5143 // It also shouldn't have grown to accomodate the clip child.
5144 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
5145 render_surface2
->render_surface()->content_rect().ToString());
5147 // Sanity check our num_unclipped_descendants values.
5148 EXPECT_EQ(1u, render_surface1
->num_unclipped_descendants());
5149 EXPECT_EQ(0u, render_surface2
->num_unclipped_descendants());
5152 TEST_F(LayerTreeHostCommonTest
, CanRenderToSeparateSurface
) {
5153 FakeImplProxy proxy
;
5154 TestSharedBitmapManager shared_bitmap_manager
;
5155 TestTaskGraphRunner task_graph_runner
;
5156 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5157 &task_graph_runner
);
5158 scoped_ptr
<LayerImpl
> root
=
5159 LayerImpl::Create(host_impl
.active_tree(), 12345);
5160 scoped_ptr
<LayerImpl
> child1
=
5161 LayerImpl::Create(host_impl
.active_tree(), 123456);
5162 scoped_ptr
<LayerImpl
> child2
=
5163 LayerImpl::Create(host_impl
.active_tree(), 1234567);
5164 scoped_ptr
<LayerImpl
> child3
=
5165 LayerImpl::Create(host_impl
.active_tree(), 12345678);
5167 gfx::Transform identity_matrix
;
5168 gfx::Point3F transform_origin
;
5169 gfx::PointF position
;
5170 gfx::Size
bounds(100, 100);
5171 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
5172 position
, bounds
, true, false, true);
5173 root
->SetDrawsContent(true);
5175 // This layer structure normally forces render surface due to preserves3d
5177 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
, transform_origin
,
5178 position
, bounds
, false, true, true);
5179 child1
->SetDrawsContent(true);
5180 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
, transform_origin
,
5181 position
, bounds
, true, false, false);
5182 child2
->SetDrawsContent(true);
5183 SetLayerPropertiesForTesting(child3
.get(), identity_matrix
, transform_origin
,
5184 position
, bounds
, true, false, false);
5185 child3
->SetDrawsContent(true);
5187 child2
->Set3dSortingContextId(1);
5188 child3
->Set3dSortingContextId(1);
5190 child2
->AddChild(child3
.Pass());
5191 child1
->AddChild(child2
.Pass());
5192 root
->AddChild(child1
.Pass());
5195 LayerImplList render_surface_layer_list
;
5196 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root
.get());
5197 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5198 root
.get(), root
->bounds(), &render_surface_layer_list
);
5199 inputs
.can_render_to_separate_surface
= true;
5200 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5202 EXPECT_EQ(2u, render_surface_layer_list
.size());
5204 int count_represents_target_render_surface
= 0;
5205 int count_represents_contributing_render_surface
= 0;
5206 int count_represents_itself
= 0;
5207 LayerIterator end
= LayerIterator::End(&render_surface_layer_list
);
5208 for (LayerIterator it
= LayerIterator::Begin(&render_surface_layer_list
);
5210 if (it
.represents_target_render_surface())
5211 count_represents_target_render_surface
++;
5212 if (it
.represents_contributing_render_surface())
5213 count_represents_contributing_render_surface
++;
5214 if (it
.represents_itself())
5215 count_represents_itself
++;
5218 // Two render surfaces.
5219 EXPECT_EQ(2, count_represents_target_render_surface
);
5220 // Second render surface contributes to root render surface.
5221 EXPECT_EQ(1, count_represents_contributing_render_surface
);
5222 // All 4 layers represent itself.
5223 EXPECT_EQ(4, count_represents_itself
);
5227 LayerImplList render_surface_layer_list
;
5228 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5229 root
.get(), root
->bounds(), &render_surface_layer_list
);
5230 inputs
.can_render_to_separate_surface
= false;
5231 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5233 EXPECT_EQ(1u, render_surface_layer_list
.size());
5235 int count_represents_target_render_surface
= 0;
5236 int count_represents_contributing_render_surface
= 0;
5237 int count_represents_itself
= 0;
5238 LayerIterator end
= LayerIterator::End(&render_surface_layer_list
);
5239 for (LayerIterator it
= LayerIterator::Begin(&render_surface_layer_list
);
5241 if (it
.represents_target_render_surface())
5242 count_represents_target_render_surface
++;
5243 if (it
.represents_contributing_render_surface())
5244 count_represents_contributing_render_surface
++;
5245 if (it
.represents_itself())
5246 count_represents_itself
++;
5249 // Only root layer has a render surface.
5250 EXPECT_EQ(1, count_represents_target_render_surface
);
5251 // No layer contributes a render surface to root render surface.
5252 EXPECT_EQ(0, count_represents_contributing_render_surface
);
5253 // All 4 layers represent itself.
5254 EXPECT_EQ(4, count_represents_itself
);
5258 TEST_F(LayerTreeHostCommonTest
, DoNotIncludeBackfaceInvisibleSurfaces
) {
5259 LayerImpl
* root
= root_layer();
5260 LayerImpl
* render_surface
= AddChild
<LayerImpl
>(root
);
5261 LayerImpl
* child
= AddChild
<LayerImpl
>(render_surface
);
5262 child
->SetDrawsContent(true);
5264 gfx::Transform identity_transform
;
5265 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5266 gfx::PointF(), gfx::Size(50, 50), true, false,
5268 SetLayerPropertiesForTesting(render_surface
, identity_transform
,
5269 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5271 SetLayerPropertiesForTesting(child
, identity_transform
, gfx::Point3F(),
5272 gfx::PointF(), gfx::Size(20, 20), true, false,
5275 root
->SetShouldFlattenTransform(false);
5276 root
->Set3dSortingContextId(1);
5277 render_surface
->SetDoubleSided(false);
5279 ExecuteCalculateDrawProperties(root
);
5281 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5282 EXPECT_EQ(1u, render_surface_layer_list_impl()
5287 EXPECT_EQ(1u, render_surface_layer_list_impl()
5293 gfx::Transform rotation_transform
= identity_transform
;
5294 rotation_transform
.RotateAboutXAxis(180.0);
5296 render_surface
->SetTransform(rotation_transform
);
5298 ExecuteCalculateDrawProperties(root
);
5300 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
5301 EXPECT_EQ(0u, render_surface_layer_list_impl()
5308 TEST_F(LayerTreeHostCommonTest
, ClippedByScrollParent
) {
5309 // Checks that the simple case (being clipped by a scroll parent that would
5310 // have been processed before you anyhow) results in the right clips.
5313 // + scroll_parent_border
5314 // | + scroll_parent_clip
5315 // | + scroll_parent
5318 LayerImpl
* root
= root_layer();
5319 LayerImpl
* scroll_parent_border
= AddChildToRoot
<LayerImpl
>();
5320 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5321 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5322 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5324 scroll_parent
->SetDrawsContent(true);
5325 scroll_child
->SetDrawsContent(true);
5326 scroll_parent_clip
->SetMasksToBounds(true);
5328 scroll_child
->SetScrollParent(scroll_parent
);
5329 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5330 scroll_children
->insert(scroll_child
);
5331 scroll_parent
->SetScrollChildren(scroll_children
.release());
5333 gfx::Transform identity_transform
;
5334 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5335 gfx::PointF(), gfx::Size(50, 50), true, false,
5337 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5338 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5339 true, false, false);
5340 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5341 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5342 true, false, false);
5343 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5344 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5345 true, false, false);
5346 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5347 gfx::PointF(), gfx::Size(50, 50), true, false,
5350 ExecuteCalculateDrawProperties(root
);
5352 EXPECT_TRUE(root
->render_surface());
5354 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
5355 scroll_child
->clip_rect().ToString());
5356 EXPECT_TRUE(scroll_child
->is_clipped());
5359 TEST_F(LayerTreeHostCommonTest
, SingularTransformSubtreesDoNotDraw
) {
5360 LayerImpl
* root
= root_layer();
5361 root
->SetDrawsContent(true);
5362 LayerImpl
* parent
= AddChildToRoot
<LayerImpl
>();
5363 parent
->SetDrawsContent(true);
5364 LayerImpl
* child
= AddChild
<LayerImpl
>(parent
);
5365 child
->SetDrawsContent(true);
5367 gfx::Transform identity_transform
;
5368 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5369 gfx::PointF(), gfx::Size(50, 50), true, true,
5371 SetLayerPropertiesForTesting(parent
, identity_transform
, gfx::Point3F(),
5372 gfx::PointF(), gfx::Size(30, 30), true, true,
5374 SetLayerPropertiesForTesting(child
, identity_transform
, gfx::Point3F(),
5375 gfx::PointF(), gfx::Size(20, 20), true, true,
5378 ExecuteCalculateDrawProperties(root
);
5380 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5382 gfx::Transform singular_transform
;
5383 singular_transform
.Scale3d(
5384 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
5386 child
->SetTransform(singular_transform
);
5388 ExecuteCalculateDrawProperties(root
);
5390 EXPECT_EQ(2u, render_surface_layer_list_impl()->size());
5392 // Ensure that the entire subtree under a layer with singular transform does
5393 // not get rendered.
5394 parent
->SetTransform(singular_transform
);
5395 child
->SetTransform(identity_transform
);
5397 ExecuteCalculateDrawProperties(root
);
5399 EXPECT_EQ(1u, render_surface_layer_list_impl()->size());
5402 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollParent
) {
5403 // Checks that clipping by a scroll parent that follows you in paint order
5404 // still results in correct clipping.
5407 // + scroll_parent_border
5408 // + scroll_parent_clip
5412 LayerImpl
* root
= root_layer();
5413 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
5414 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5415 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5416 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5418 scroll_parent
->SetDrawsContent(true);
5419 scroll_child
->SetDrawsContent(true);
5421 scroll_parent_clip
->SetMasksToBounds(true);
5423 scroll_child
->SetScrollParent(scroll_parent
);
5424 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5425 scroll_children
->insert(scroll_child
);
5426 scroll_parent
->SetScrollChildren(scroll_children
.release());
5428 gfx::Transform identity_transform
;
5429 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5430 gfx::PointF(), gfx::Size(50, 50), true, false,
5432 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5433 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5434 true, false, false);
5435 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5436 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5437 true, false, false);
5438 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5439 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5440 true, false, false);
5441 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5442 gfx::PointF(), gfx::Size(50, 50), true, false,
5445 ExecuteCalculateDrawProperties(root
);
5447 EXPECT_TRUE(root
->render_surface());
5449 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
5450 scroll_child
->clip_rect().ToString());
5451 EXPECT_TRUE(scroll_child
->is_clipped());
5454 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollGrandparent
) {
5455 // Checks that clipping by a scroll parent and scroll grandparent that follow
5456 // you in paint order still results in correct clipping.
5460 // + scroll_parent_border
5461 // | + scroll_parent_clip
5462 // | + scroll_parent
5463 // + scroll_grandparent_border
5464 // + scroll_grandparent_clip
5465 // + scroll_grandparent
5467 LayerImpl
* root
= root_layer();
5468 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5469 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
5470 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5471 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5472 LayerImpl
* scroll_grandparent_border
= AddChild
<LayerImpl
>(root
);
5473 LayerImpl
* scroll_grandparent_clip
=
5474 AddChild
<LayerImpl
>(scroll_grandparent_border
);
5475 LayerImpl
* scroll_grandparent
= AddChild
<LayerImpl
>(scroll_grandparent_clip
);
5477 scroll_parent
->SetDrawsContent(true);
5478 scroll_grandparent
->SetDrawsContent(true);
5479 scroll_child
->SetDrawsContent(true);
5481 scroll_parent_clip
->SetMasksToBounds(true);
5482 scroll_grandparent_clip
->SetMasksToBounds(true);
5484 scroll_child
->SetScrollParent(scroll_parent
);
5485 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5486 scroll_children
->insert(scroll_child
);
5487 scroll_parent
->SetScrollChildren(scroll_children
.release());
5489 scroll_parent_border
->SetScrollParent(scroll_grandparent
);
5490 scroll_children
.reset(new std::set
<LayerImpl
*>);
5491 scroll_children
->insert(scroll_parent_border
);
5492 scroll_grandparent
->SetScrollChildren(scroll_children
.release());
5494 gfx::Transform identity_transform
;
5495 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5496 gfx::PointF(), gfx::Size(50, 50), true, false,
5498 SetLayerPropertiesForTesting(scroll_grandparent_border
, identity_transform
,
5499 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5500 true, false, false);
5501 SetLayerPropertiesForTesting(scroll_grandparent_clip
, identity_transform
,
5502 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5503 true, false, false);
5504 SetLayerPropertiesForTesting(scroll_grandparent
, identity_transform
,
5505 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5506 true, false, false);
5507 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5508 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5509 true, false, false);
5510 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5511 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5512 true, false, false);
5513 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5514 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5515 true, false, false);
5516 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5517 gfx::PointF(), gfx::Size(50, 50), true, false,
5520 ExecuteCalculateDrawProperties(root
);
5522 EXPECT_TRUE(root
->render_surface());
5524 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
5525 scroll_child
->clip_rect().ToString());
5526 EXPECT_TRUE(scroll_child
->is_clipped());
5528 // Despite the fact that we visited the above layers out of order to get the
5529 // correct clip, the layer lists should be unaffected.
5530 EXPECT_EQ(3u, root
->render_surface()->layer_list().size());
5531 EXPECT_EQ(scroll_child
, root
->render_surface()->layer_list().at(0));
5532 EXPECT_EQ(scroll_parent
, root
->render_surface()->layer_list().at(1));
5533 EXPECT_EQ(scroll_grandparent
, root
->render_surface()->layer_list().at(2));
5536 TEST_F(LayerTreeHostCommonTest
, OutOfOrderClippingRequiresRSLLSorting
) {
5537 // Ensures that even if we visit layers out of order, we still produce a
5538 // correctly ordered render surface layer list.
5541 // + scroll_parent_border
5542 // + scroll_parent_clip
5544 // + render_surface2
5545 // + scroll_grandparent_border
5546 // + scroll_grandparent_clip
5547 // + scroll_grandparent
5548 // + render_surface1
5550 LayerImpl
* root
= root_layer();
5551 root
->SetDrawsContent(true);
5553 LayerImpl
* scroll_child
= AddChild
<LayerImpl
>(root
);
5554 scroll_child
->SetDrawsContent(true);
5556 LayerImpl
* scroll_parent_border
= AddChild
<LayerImpl
>(root
);
5557 LayerImpl
* scroll_parent_clip
= AddChild
<LayerImpl
>(scroll_parent_border
);
5558 LayerImpl
* scroll_parent
= AddChild
<LayerImpl
>(scroll_parent_clip
);
5559 LayerImpl
* render_surface2
= AddChild
<LayerImpl
>(scroll_parent
);
5560 LayerImpl
* scroll_grandparent_border
= AddChild
<LayerImpl
>(root
);
5561 LayerImpl
* scroll_grandparent_clip
=
5562 AddChild
<LayerImpl
>(scroll_grandparent_border
);
5563 LayerImpl
* scroll_grandparent
= AddChild
<LayerImpl
>(scroll_grandparent_clip
);
5564 LayerImpl
* render_surface1
= AddChild
<LayerImpl
>(scroll_grandparent
);
5566 scroll_parent
->SetDrawsContent(true);
5567 render_surface1
->SetDrawsContent(true);
5568 scroll_grandparent
->SetDrawsContent(true);
5569 render_surface2
->SetDrawsContent(true);
5571 scroll_parent_clip
->SetMasksToBounds(true);
5572 scroll_grandparent_clip
->SetMasksToBounds(true);
5574 scroll_child
->SetScrollParent(scroll_parent
);
5575 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
5576 scroll_children
->insert(scroll_child
);
5577 scroll_parent
->SetScrollChildren(scroll_children
.release());
5579 scroll_parent_border
->SetScrollParent(scroll_grandparent
);
5580 scroll_children
.reset(new std::set
<LayerImpl
*>);
5581 scroll_children
->insert(scroll_parent_border
);
5582 scroll_grandparent
->SetScrollChildren(scroll_children
.release());
5584 gfx::Transform identity_transform
;
5585 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5586 gfx::PointF(), gfx::Size(50, 50), true, false,
5588 SetLayerPropertiesForTesting(scroll_grandparent_border
, identity_transform
,
5589 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5590 true, false, false);
5591 SetLayerPropertiesForTesting(scroll_grandparent_clip
, identity_transform
,
5592 gfx::Point3F(), gfx::PointF(), gfx::Size(20, 20),
5593 true, false, false);
5594 SetLayerPropertiesForTesting(scroll_grandparent
, identity_transform
,
5595 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5596 true, false, false);
5597 SetLayerPropertiesForTesting(render_surface1
, identity_transform
,
5598 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5600 SetLayerPropertiesForTesting(scroll_parent_border
, identity_transform
,
5601 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5602 true, false, false);
5603 SetLayerPropertiesForTesting(scroll_parent_clip
, identity_transform
,
5604 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5605 true, false, false);
5606 SetLayerPropertiesForTesting(scroll_parent
, identity_transform
,
5607 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5608 true, false, false);
5609 SetLayerPropertiesForTesting(render_surface2
, identity_transform
,
5610 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
5612 SetLayerPropertiesForTesting(scroll_child
, identity_transform
, gfx::Point3F(),
5613 gfx::PointF(), gfx::Size(50, 50), true, false,
5616 ExecuteCalculateDrawProperties(root
);
5618 EXPECT_TRUE(root
->render_surface());
5620 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
5621 scroll_child
->clip_rect().ToString());
5622 EXPECT_TRUE(scroll_child
->is_clipped());
5624 // Despite the fact that we had to process the layers out of order to get the
5625 // right clip, our render_surface_layer_list's order should be unaffected.
5626 EXPECT_EQ(3u, render_surface_layer_list_impl()->size());
5627 EXPECT_EQ(root
, render_surface_layer_list_impl()->at(0));
5628 EXPECT_EQ(render_surface2
, render_surface_layer_list_impl()->at(1));
5629 EXPECT_EQ(render_surface1
, render_surface_layer_list_impl()->at(2));
5630 EXPECT_TRUE(render_surface_layer_list_impl()->at(0)->render_surface());
5631 EXPECT_TRUE(render_surface_layer_list_impl()->at(1)->render_surface());
5632 EXPECT_TRUE(render_surface_layer_list_impl()->at(2)->render_surface());
5635 TEST_F(LayerTreeHostCommonTest
, FixedPositionWithInterveningRenderSurface
) {
5636 // Ensures that when we have a render surface between a fixed position layer
5637 // and its container, we compute the fixed position layer's draw transform
5638 // with respect to that intervening render surface, not with respect to its
5639 // container's render target.
5646 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5647 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface
=
5648 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5649 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
5650 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5651 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
5652 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5654 root
->AddChild(render_surface
);
5655 render_surface
->AddChild(fixed
);
5656 fixed
->AddChild(child
);
5658 root
->SetIsContainerForFixedPositionLayers(true);
5659 render_surface
->SetForceRenderSurface(true);
5661 LayerPositionConstraint constraint
;
5662 constraint
.set_is_fixed_position(true);
5663 fixed
->SetPositionConstraint(constraint
);
5665 SetLayerPropertiesForTesting(root
.get(), gfx::Transform(), gfx::Point3F(),
5666 gfx::PointF(), gfx::Size(50, 50), true, false);
5667 SetLayerPropertiesForTesting(render_surface
.get(), gfx::Transform(),
5668 gfx::Point3F(), gfx::PointF(7.f
, 9.f
),
5669 gfx::Size(50, 50), true, false);
5670 SetLayerPropertiesForTesting(fixed
.get(), gfx::Transform(), gfx::Point3F(),
5671 gfx::PointF(10.f
, 15.f
), gfx::Size(50, 50), true,
5673 SetLayerPropertiesForTesting(child
.get(), gfx::Transform(), gfx::Point3F(),
5674 gfx::PointF(1.f
, 2.f
), gfx::Size(50, 50), true,
5677 host()->SetRootLayer(root
);
5679 ExecuteCalculateDrawProperties(root
.get());
5681 TransformTree
& tree
= host()->property_trees()->transform_tree
;
5683 gfx::Transform expected_fixed_draw_transform
;
5684 expected_fixed_draw_transform
.Translate(10.f
, 15.f
);
5685 EXPECT_EQ(expected_fixed_draw_transform
,
5686 DrawTransformFromPropertyTrees(fixed
.get(), tree
));
5688 gfx::Transform expected_fixed_screen_space_transform
;
5689 expected_fixed_screen_space_transform
.Translate(17.f
, 24.f
);
5690 EXPECT_EQ(expected_fixed_screen_space_transform
,
5691 ScreenSpaceTransformFromPropertyTrees(fixed
.get(), tree
));
5693 gfx::Transform expected_child_draw_transform
;
5694 expected_child_draw_transform
.Translate(11.f
, 17.f
);
5695 EXPECT_EQ(expected_child_draw_transform
,
5696 DrawTransformFromPropertyTrees(child
.get(), tree
));
5698 gfx::Transform expected_child_screen_space_transform
;
5699 expected_child_screen_space_transform
.Translate(18.f
, 26.f
);
5700 EXPECT_EQ(expected_child_screen_space_transform
,
5701 ScreenSpaceTransformFromPropertyTrees(child
.get(), tree
));
5704 TEST_F(LayerTreeHostCommonTest
, ScrollCompensationWithRounding
) {
5705 // This test verifies that a scrolling layer that gets snapped to
5706 // integer coordinates doesn't move a fixed position child.
5713 FakeImplProxy proxy
;
5714 TestSharedBitmapManager shared_bitmap_manager
;
5715 TestTaskGraphRunner task_graph_runner
;
5716 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5717 &task_graph_runner
);
5718 host_impl
.CreatePendingTree();
5719 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
5720 scoped_ptr
<LayerImpl
> container
=
5721 LayerImpl::Create(host_impl
.active_tree(), 2);
5722 LayerImpl
* container_layer
= container
.get();
5723 scoped_ptr
<LayerImpl
> scroller
=
5724 LayerImpl::Create(host_impl
.active_tree(), 3);
5725 LayerImpl
* scroll_layer
= scroller
.get();
5726 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
5727 LayerImpl
* fixed_layer
= fixed
.get();
5729 container
->SetIsContainerForFixedPositionLayers(true);
5731 LayerPositionConstraint constraint
;
5732 constraint
.set_is_fixed_position(true);
5733 fixed
->SetPositionConstraint(constraint
);
5735 scroller
->SetScrollClipLayer(container
->id());
5737 gfx::Transform identity_transform
;
5738 gfx::Transform container_transform
;
5739 container_transform
.Translate3d(10.0, 20.0, 0.0);
5740 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
5742 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
5743 gfx::PointF(), gfx::Size(50, 50), true, false,
5745 SetLayerPropertiesForTesting(container
.get(), container_transform
,
5746 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5747 true, false, false);
5748 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
5749 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5750 true, false, false);
5751 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
5752 gfx::PointF(), gfx::Size(50, 50), true, false,
5755 scroller
->AddChild(fixed
.Pass());
5756 container
->AddChild(scroller
.Pass());
5757 root
->AddChild(container
.Pass());
5759 // Rounded to integers already.
5761 gfx::Vector2dF
scroll_delta(3.0, 5.0);
5762 scroll_layer
->SetScrollDelta(scroll_delta
);
5764 LayerImplList render_surface_layer_list
;
5765 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5766 root
.get(), root
->bounds(), &render_surface_layer_list
);
5767 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5769 EXPECT_TRANSFORMATION_MATRIX_EQ(
5770 container_layer
->draw_properties().screen_space_transform
,
5771 fixed_layer
->draw_properties().screen_space_transform
);
5773 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5775 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
5776 .screen_space_transform
.To2dTranslation(),
5777 container_offset
- scroll_delta
);
5780 // Scroll delta requiring rounding.
5782 gfx::Vector2dF
scroll_delta(4.1f
, 8.1f
);
5783 scroll_layer
->SetScrollDelta(scroll_delta
);
5785 gfx::Vector2dF
rounded_scroll_delta(4.f
, 8.f
);
5787 LayerImplList render_surface_layer_list
;
5788 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5789 root
.get(), root
->bounds(), &render_surface_layer_list
);
5790 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5792 EXPECT_TRANSFORMATION_MATRIX_EQ(
5793 container_layer
->draw_properties().screen_space_transform
,
5794 fixed_layer
->draw_properties().screen_space_transform
);
5796 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5798 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
5799 .screen_space_transform
.To2dTranslation(),
5800 container_offset
- rounded_scroll_delta
);
5803 // Scale is applied earlier in the tree.
5805 gfx::Transform scaled_container_transform
= container_transform
;
5806 scaled_container_transform
.Scale3d(3.0, 3.0, 1.0);
5807 container_layer
->SetTransform(scaled_container_transform
);
5809 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
5810 scroll_layer
->SetScrollDelta(scroll_delta
);
5812 LayerImplList render_surface_layer_list
;
5813 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5814 root
.get(), root
->bounds(), &render_surface_layer_list
);
5815 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5817 EXPECT_TRANSFORMATION_MATRIX_EQ(
5818 container_layer
->draw_properties().screen_space_transform
,
5819 fixed_layer
->draw_properties().screen_space_transform
);
5821 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5824 container_layer
->SetTransform(container_transform
);
5827 // Scale is applied on the scroll layer itself.
5829 gfx::Transform scale_transform
;
5830 scale_transform
.Scale3d(3.0, 3.0, 1.0);
5831 scroll_layer
->SetTransform(scale_transform
);
5833 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
5834 scroll_layer
->SetScrollDelta(scroll_delta
);
5836 LayerImplList render_surface_layer_list
;
5837 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5838 root
.get(), root
->bounds(), &render_surface_layer_list
);
5839 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5842 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5845 scroll_layer
->SetTransform(identity_transform
);
5849 TEST_F(LayerTreeHostCommonTest
,
5850 ScrollCompensationMainScrollOffsetFractionalPart
) {
5851 // This test verifies that a scrolling layer that has fractional scroll offset
5852 // from main doesn't move a fixed position child.
5859 FakeImplProxy proxy
;
5860 TestSharedBitmapManager shared_bitmap_manager
;
5861 TestTaskGraphRunner task_graph_runner
;
5862 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
5863 &task_graph_runner
);
5864 host_impl
.CreatePendingTree();
5865 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
5866 scoped_ptr
<LayerImpl
> container
=
5867 LayerImpl::Create(host_impl
.active_tree(), 2);
5868 LayerImpl
* container_layer
= container
.get();
5869 scoped_ptr
<LayerImpl
> scroller
=
5870 LayerImpl::Create(host_impl
.active_tree(), 3);
5871 LayerImpl
* scroll_layer
= scroller
.get();
5872 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
5873 LayerImpl
* fixed_layer
= fixed
.get();
5875 container
->SetIsContainerForFixedPositionLayers(true);
5877 LayerPositionConstraint constraint
;
5878 constraint
.set_is_fixed_position(true);
5879 fixed
->SetPositionConstraint(constraint
);
5881 scroller
->SetScrollClipLayer(container
->id());
5883 gfx::Transform identity_transform
;
5884 gfx::Transform container_transform
;
5885 container_transform
.Translate3d(10.0, 20.0, 0.0);
5886 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
5888 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
5889 gfx::PointF(), gfx::Size(50, 50), true, false,
5891 SetLayerPropertiesForTesting(container
.get(), container_transform
,
5892 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
5893 true, false, false);
5894 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
5895 gfx::Point3F(), gfx::PointF(0.0, 0.0),
5896 gfx::Size(30, 30), true, false, false);
5898 gfx::ScrollOffset
scroll_offset(3.3, 4.2);
5899 gfx::Vector2dF
main_scroll_fractional_part(0.3f
, 0.2f
);
5900 gfx::Vector2dF
scroll_delta(0.1f
, 0.4f
);
5901 // Blink only uses the integer part of the scroll_offset for fixed
5903 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
5904 gfx::PointF(3.0f
, 4.0f
), gfx::Size(50, 50), true,
5906 scroll_layer
->PushScrollOffsetFromMainThread(scroll_offset
);
5907 scroll_layer
->SetScrollDelta(scroll_delta
);
5908 scroll_layer
->SetScrollCompensationAdjustment(main_scroll_fractional_part
);
5910 scroller
->AddChild(fixed
.Pass());
5911 container
->AddChild(scroller
.Pass());
5912 root
->AddChild(container
.Pass());
5914 LayerImplList render_surface_layer_list
;
5915 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5916 root
.get(), root
->bounds(), &render_surface_layer_list
);
5917 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5919 EXPECT_TRANSFORMATION_MATRIX_EQ(
5920 container_layer
->draw_properties().screen_space_transform
,
5921 fixed_layer
->draw_properties().screen_space_transform
);
5923 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5926 gfx::ScrollOffset effective_scroll_offset
=
5927 ScrollOffsetWithDelta(scroll_offset
, scroll_delta
);
5928 gfx::Vector2d rounded_effective_scroll_offset
=
5929 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset
));
5931 scroll_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
5932 container_offset
- rounded_effective_scroll_offset
);
5935 TEST_F(LayerTreeHostCommonTest
,
5936 ScrollSnappingWithAnimatedScreenSpaceTransform
) {
5937 // This test verifies that a scrolling layer whose screen space transform is
5938 // animating doesn't get snapped to integer coordinates.
5946 LayerImpl
* root
= root_layer();
5947 LayerImpl
* animated_layer
= AddChildToRoot
<FakePictureLayerImpl
>();
5948 LayerImpl
* surface
= AddChild
<LayerImpl
>(animated_layer
);
5949 LayerImpl
* container
= AddChild
<LayerImpl
>(surface
);
5950 LayerImpl
* scroller
= AddChild
<LayerImpl
>(container
);
5951 scroller
->SetScrollClipLayer(container
->id());
5952 scroller
->SetDrawsContent(true);
5954 gfx::Transform identity_transform
;
5955 gfx::Transform start_scale
;
5956 start_scale
.Scale(1.5f
, 1.5f
);
5957 SetLayerPropertiesForTesting(root
, identity_transform
, gfx::Point3F(),
5958 gfx::PointF(), gfx::Size(50, 50), true, false,
5960 SetLayerPropertiesForTesting(animated_layer
, start_scale
, gfx::Point3F(),
5961 gfx::PointF(), gfx::Size(50, 50), true, false,
5963 SetLayerPropertiesForTesting(surface
, identity_transform
, gfx::Point3F(),
5964 gfx::PointF(), gfx::Size(50, 50), true, false,
5966 SetLayerPropertiesForTesting(container
, identity_transform
, gfx::Point3F(),
5967 gfx::PointF(), gfx::Size(50, 50), true, false,
5969 SetLayerPropertiesForTesting(scroller
, identity_transform
, gfx::Point3F(),
5970 gfx::PointF(), gfx::Size(100, 100), true, false,
5973 gfx::Transform end_scale
;
5974 end_scale
.Scale(2.f
, 2.f
);
5975 TransformOperations start_operations
;
5976 start_operations
.AppendMatrix(start_scale
);
5977 TransformOperations end_operations
;
5978 end_operations
.AppendMatrix(end_scale
);
5979 AddAnimatedTransformToLayer(animated_layer
, 1.0, start_operations
,
5982 gfx::Vector2dF
scroll_delta(5.f
, 9.f
);
5983 scroller
->SetScrollDelta(scroll_delta
);
5985 ExecuteCalculateDrawProperties(root
);
5987 gfx::Vector2dF
expected_draw_transform_translation(-7.5f
, -13.5f
);
5988 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation
,
5989 scroller
->draw_transform().To2dTranslation());
5992 class AnimationScaleFactorTrackingLayerImpl
: public LayerImpl
{
5994 static scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> Create(
5995 LayerTreeImpl
* tree_impl
,
5997 return make_scoped_ptr(
5998 new AnimationScaleFactorTrackingLayerImpl(tree_impl
, id
));
6001 ~AnimationScaleFactorTrackingLayerImpl() override
{}
6004 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl
* tree_impl
,
6006 : LayerImpl(tree_impl
, id
) {
6007 SetDrawsContent(true);
6011 TEST_F(LayerTreeHostCommonTest
, MaximumAnimationScaleFactor
) {
6012 FakeImplProxy proxy
;
6013 TestSharedBitmapManager shared_bitmap_manager
;
6014 TestTaskGraphRunner task_graph_runner
;
6015 LayerTreeSettings settings
;
6016 settings
.layer_transforms_should_scale_layer_contents
= true;
6017 FakeLayerTreeHostImpl
host_impl(settings
, &proxy
, &shared_bitmap_manager
,
6018 &task_graph_runner
);
6019 gfx::Transform identity_matrix
;
6020 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_parent
=
6021 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 1);
6022 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> parent
=
6023 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 2);
6024 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> child
=
6025 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 3);
6026 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_child
=
6027 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 4);
6029 AnimationScaleFactorTrackingLayerImpl
* parent_raw
= parent
.get();
6030 AnimationScaleFactorTrackingLayerImpl
* child_raw
= child
.get();
6031 AnimationScaleFactorTrackingLayerImpl
* grand_child_raw
= grand_child
.get();
6033 child
->AddChild(grand_child
.Pass());
6034 parent
->AddChild(child
.Pass());
6035 grand_parent
->AddChild(parent
.Pass());
6037 SetLayerPropertiesForTesting(grand_parent
.get(), identity_matrix
,
6038 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6040 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
6041 gfx::PointF(), gfx::Size(1, 2), true, false,
6043 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
6044 gfx::PointF(), gfx::Size(1, 2), true, false,
6047 SetLayerPropertiesForTesting(grand_child_raw
, identity_matrix
, gfx::Point3F(),
6048 gfx::PointF(), gfx::Size(1, 2), true, false,
6051 ExecuteCalculateDrawProperties(grand_parent
.get());
6053 // No layers have animations.
6055 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6057 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6058 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6060 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6063 grand_parent
->draw_properties().starting_animation_contents_scale
);
6065 parent_raw
->draw_properties().starting_animation_contents_scale
);
6067 child_raw
->draw_properties().starting_animation_contents_scale
);
6070 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6072 TransformOperations translation
;
6073 translation
.AppendTranslate(1.f
, 2.f
, 3.f
);
6075 AddAnimatedTransformToLayer(
6076 parent_raw
, 1.0, TransformOperations(), translation
);
6078 // No layers have scale-affecting animations.
6080 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6082 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6083 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6085 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6088 grand_parent
->draw_properties().starting_animation_contents_scale
);
6090 parent_raw
->draw_properties().starting_animation_contents_scale
);
6092 child_raw
->draw_properties().starting_animation_contents_scale
);
6095 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6097 TransformOperations scale
;
6098 scale
.AppendScale(5.f
, 4.f
, 3.f
);
6100 AddAnimatedTransformToLayer(child_raw
, 1.0, TransformOperations(), scale
);
6101 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6102 ExecuteCalculateDrawProperties(grand_parent
.get());
6104 // Only |child| has a scale-affecting animation.
6106 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6108 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6109 EXPECT_EQ(5.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6111 5.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6114 grand_parent
->draw_properties().starting_animation_contents_scale
);
6116 parent_raw
->draw_properties().starting_animation_contents_scale
);
6118 child_raw
->draw_properties().starting_animation_contents_scale
);
6121 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6123 AddAnimatedTransformToLayer(
6124 grand_parent
.get(), 1.0, TransformOperations(), scale
);
6125 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6126 ExecuteCalculateDrawProperties(grand_parent
.get());
6128 // |grand_parent| and |child| have scale-affecting animations.
6130 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6132 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6133 // We don't support combining animated scales from two nodes; 0.f means
6134 // that the maximum scale could not be computed.
6135 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6137 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6140 grand_parent
->draw_properties().starting_animation_contents_scale
);
6142 parent_raw
->draw_properties().starting_animation_contents_scale
);
6144 child_raw
->draw_properties().starting_animation_contents_scale
);
6147 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6149 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
6150 parent_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6151 ExecuteCalculateDrawProperties(grand_parent
.get());
6153 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
6155 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6157 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6158 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6160 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6163 grand_parent
->draw_properties().starting_animation_contents_scale
);
6165 parent_raw
->draw_properties().starting_animation_contents_scale
);
6167 child_raw
->draw_properties().starting_animation_contents_scale
);
6170 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6172 grand_parent
->layer_animation_controller()->AbortAnimations(
6173 Animation::TRANSFORM
);
6174 parent_raw
->layer_animation_controller()->AbortAnimations(
6175 Animation::TRANSFORM
);
6176 child_raw
->layer_animation_controller()->AbortAnimations(
6177 Animation::TRANSFORM
);
6179 TransformOperations perspective
;
6180 perspective
.AppendPerspective(10.f
);
6182 AddAnimatedTransformToLayer(
6183 child_raw
, 1.0, TransformOperations(), perspective
);
6184 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6185 ExecuteCalculateDrawProperties(grand_parent
.get());
6187 // |child| has a scale-affecting animation but computing the maximum of this
6188 // animation is not supported.
6190 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6192 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6193 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6195 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6198 grand_parent
->draw_properties().starting_animation_contents_scale
);
6200 parent_raw
->draw_properties().starting_animation_contents_scale
);
6202 child_raw
->draw_properties().starting_animation_contents_scale
);
6205 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6207 child_raw
->layer_animation_controller()->AbortAnimations(
6208 Animation::TRANSFORM
);
6210 gfx::Transform scale_matrix
;
6211 scale_matrix
.Scale(1.f
, 2.f
);
6212 grand_parent
->SetTransform(scale_matrix
);
6213 parent_raw
->SetTransform(scale_matrix
);
6214 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6215 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
6216 ExecuteCalculateDrawProperties(grand_parent
.get());
6218 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
6219 // animation with maximum scale 5.f.
6221 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6223 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6225 child_raw
->draw_properties().maximum_animation_contents_scale
);
6228 grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6231 grand_parent
->draw_properties().starting_animation_contents_scale
);
6233 parent_raw
->draw_properties().starting_animation_contents_scale
);
6235 child_raw
->draw_properties().starting_animation_contents_scale
);
6238 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6240 gfx::Transform perspective_matrix
;
6241 perspective_matrix
.ApplyPerspectiveDepth(2.f
);
6242 child_raw
->SetTransform(perspective_matrix
);
6243 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6244 ExecuteCalculateDrawProperties(grand_parent
.get());
6246 // |child| has a transform that's neither a translation nor a scale.
6248 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6250 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6251 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6253 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6256 grand_parent
->draw_properties().starting_animation_contents_scale
);
6258 parent_raw
->draw_properties().starting_animation_contents_scale
);
6260 child_raw
->draw_properties().starting_animation_contents_scale
);
6263 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6265 parent_raw
->SetTransform(perspective_matrix
);
6266 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6267 ExecuteCalculateDrawProperties(grand_parent
.get());
6269 // |parent| and |child| have transforms that are neither translations nor
6272 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6274 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6275 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6277 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6280 grand_parent
->draw_properties().starting_animation_contents_scale
);
6282 parent_raw
->draw_properties().starting_animation_contents_scale
);
6284 child_raw
->draw_properties().starting_animation_contents_scale
);
6287 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6289 parent_raw
->SetTransform(identity_matrix
);
6290 child_raw
->SetTransform(identity_matrix
);
6291 grand_parent
->SetTransform(perspective_matrix
);
6292 grand_parent
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6294 ExecuteCalculateDrawProperties(grand_parent
.get());
6296 // |grand_parent| has a transform that's neither a translation nor a scale.
6298 grand_parent
->draw_properties().maximum_animation_contents_scale
);
6300 parent_raw
->draw_properties().maximum_animation_contents_scale
);
6301 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
6303 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
6306 grand_parent
->draw_properties().starting_animation_contents_scale
);
6308 parent_raw
->draw_properties().starting_animation_contents_scale
);
6310 child_raw
->draw_properties().starting_animation_contents_scale
);
6313 grand_child_raw
->draw_properties().starting_animation_contents_scale
);
6316 static int membership_id(LayerImpl
* layer
) {
6317 return layer
->draw_properties().last_drawn_render_surface_layer_list_id
;
6320 static void GatherDrawnLayers(LayerImplList
* rsll
,
6321 std::set
<LayerImpl
*>* drawn_layers
) {
6322 for (LayerIterator it
= LayerIterator::Begin(rsll
),
6323 end
= LayerIterator::End(rsll
);
6325 LayerImpl
* layer
= *it
;
6326 if (it
.represents_itself())
6327 drawn_layers
->insert(layer
);
6329 if (!it
.represents_contributing_render_surface())
6332 if (layer
->mask_layer())
6333 drawn_layers
->insert(layer
->mask_layer());
6334 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer())
6335 drawn_layers
->insert(layer
->replica_layer()->mask_layer());
6339 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceLayerListMembership
) {
6340 FakeImplProxy proxy
;
6341 TestSharedBitmapManager shared_bitmap_manager
;
6342 TestTaskGraphRunner task_graph_runner
;
6343 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6344 &task_graph_runner
);
6345 gfx::Transform identity_matrix
;
6347 scoped_ptr
<LayerImpl
> grand_parent
=
6348 LayerImpl::Create(host_impl
.active_tree(), 1);
6349 scoped_ptr
<LayerImpl
> parent
= LayerImpl::Create(host_impl
.active_tree(), 3);
6350 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 5);
6351 scoped_ptr
<LayerImpl
> grand_child1
=
6352 LayerImpl::Create(host_impl
.active_tree(), 7);
6353 scoped_ptr
<LayerImpl
> grand_child2
=
6354 LayerImpl::Create(host_impl
.active_tree(), 9);
6356 LayerImpl
* grand_parent_raw
= grand_parent
.get();
6357 LayerImpl
* parent_raw
= parent
.get();
6358 LayerImpl
* child_raw
= child
.get();
6359 LayerImpl
* grand_child1_raw
= grand_child1
.get();
6360 LayerImpl
* grand_child2_raw
= grand_child2
.get();
6362 child
->AddChild(grand_child1
.Pass());
6363 child
->AddChild(grand_child2
.Pass());
6364 parent
->AddChild(child
.Pass());
6365 grand_parent
->AddChild(parent
.Pass());
6367 SetLayerPropertiesForTesting(grand_parent_raw
, identity_matrix
,
6368 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6370 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
6371 gfx::PointF(), gfx::Size(1, 2), true, false,
6374 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
6375 gfx::PointF(), gfx::Size(1, 2), true, false,
6378 SetLayerPropertiesForTesting(grand_child1_raw
, identity_matrix
,
6379 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6380 true, false, false);
6382 SetLayerPropertiesForTesting(grand_child2_raw
, identity_matrix
,
6383 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
6384 true, false, false);
6386 // Start with nothing being drawn.
6387 ExecuteCalculateDrawProperties(grand_parent_raw
);
6388 int member_id
= render_surface_layer_list_count();
6390 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6391 EXPECT_NE(member_id
, membership_id(parent_raw
));
6392 EXPECT_NE(member_id
, membership_id(child_raw
));
6393 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6394 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6396 std::set
<LayerImpl
*> expected
;
6397 std::set
<LayerImpl
*> actual
;
6398 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6399 EXPECT_EQ(expected
, actual
);
6401 // If we force render surface, but none of the layers are in the layer list,
6402 // then this layer should not appear in RSLL.
6403 grand_child1_raw
->SetHasRenderSurface(true);
6404 grand_child1_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6406 ExecuteCalculateDrawProperties(grand_parent_raw
);
6407 member_id
= render_surface_layer_list_count();
6409 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6410 EXPECT_NE(member_id
, membership_id(parent_raw
));
6411 EXPECT_NE(member_id
, membership_id(child_raw
));
6412 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6413 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6417 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6418 EXPECT_EQ(expected
, actual
);
6420 // However, if we say that this layer also draws content, it will appear in
6422 grand_child1_raw
->SetDrawsContent(true);
6424 ExecuteCalculateDrawProperties(grand_parent_raw
);
6425 member_id
= render_surface_layer_list_count();
6427 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6428 EXPECT_NE(member_id
, membership_id(parent_raw
));
6429 EXPECT_NE(member_id
, membership_id(child_raw
));
6430 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
6431 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6434 expected
.insert(grand_child1_raw
);
6437 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6438 EXPECT_EQ(expected
, actual
);
6440 // Now child is forced to have a render surface, and one if its children draws
6442 grand_child1_raw
->SetDrawsContent(false);
6443 grand_child1_raw
->SetHasRenderSurface(false);
6444 grand_child1_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6445 child_raw
->SetHasRenderSurface(true);
6446 grand_child2_raw
->SetDrawsContent(true);
6448 ExecuteCalculateDrawProperties(grand_parent_raw
);
6449 member_id
= render_surface_layer_list_count();
6451 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6452 EXPECT_NE(member_id
, membership_id(parent_raw
));
6453 EXPECT_NE(member_id
, membership_id(child_raw
));
6454 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6455 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6458 expected
.insert(grand_child2_raw
);
6461 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6462 EXPECT_EQ(expected
, actual
);
6464 // Add a mask layer to child.
6465 child_raw
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6).Pass());
6466 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6468 ExecuteCalculateDrawProperties(grand_parent_raw
);
6469 member_id
= render_surface_layer_list_count();
6471 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6472 EXPECT_NE(member_id
, membership_id(parent_raw
));
6473 EXPECT_NE(member_id
, membership_id(child_raw
));
6474 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
6475 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6476 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6479 expected
.insert(grand_child2_raw
);
6480 expected
.insert(child_raw
->mask_layer());
6483 expected
.insert(grand_child2_raw
);
6484 expected
.insert(child_raw
->mask_layer());
6487 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6488 EXPECT_EQ(expected
, actual
);
6490 // Add replica mask layer.
6491 scoped_ptr
<LayerImpl
> replica_layer
=
6492 LayerImpl::Create(host_impl
.active_tree(), 20);
6493 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 21));
6494 child_raw
->SetReplicaLayer(replica_layer
.Pass());
6495 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6497 ExecuteCalculateDrawProperties(grand_parent_raw
);
6498 member_id
= render_surface_layer_list_count();
6500 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6501 EXPECT_NE(member_id
, membership_id(parent_raw
));
6502 EXPECT_NE(member_id
, membership_id(child_raw
));
6503 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
6504 EXPECT_EQ(member_id
, membership_id(child_raw
->replica_layer()->mask_layer()));
6505 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6506 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6509 expected
.insert(grand_child2_raw
);
6510 expected
.insert(child_raw
->mask_layer());
6511 expected
.insert(child_raw
->replica_layer()->mask_layer());
6514 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6515 EXPECT_EQ(expected
, actual
);
6517 child_raw
->TakeReplicaLayer();
6519 // With nothing drawing, we should have no layers.
6520 grand_child2_raw
->SetDrawsContent(false);
6522 ExecuteCalculateDrawProperties(grand_parent_raw
);
6523 member_id
= render_surface_layer_list_count();
6525 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6526 EXPECT_NE(member_id
, membership_id(parent_raw
));
6527 EXPECT_NE(member_id
, membership_id(child_raw
));
6528 EXPECT_NE(member_id
, membership_id(child_raw
->mask_layer()));
6529 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6530 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6534 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6535 EXPECT_EQ(expected
, actual
);
6537 // Child itself draws means that we should have the child and the mask in the
6539 child_raw
->SetDrawsContent(true);
6541 ExecuteCalculateDrawProperties(grand_parent_raw
);
6542 member_id
= render_surface_layer_list_count();
6544 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
6545 EXPECT_NE(member_id
, membership_id(parent_raw
));
6546 EXPECT_EQ(member_id
, membership_id(child_raw
));
6547 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
6548 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
6549 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
6552 expected
.insert(child_raw
);
6553 expected
.insert(child_raw
->mask_layer());
6555 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6556 EXPECT_EQ(expected
, actual
);
6558 child_raw
->TakeMaskLayer();
6559 child_raw
->layer_tree_impl()->property_trees()->needs_rebuild
= true;
6561 // Now everyone's a member!
6562 grand_parent_raw
->SetDrawsContent(true);
6563 parent_raw
->SetDrawsContent(true);
6564 child_raw
->SetDrawsContent(true);
6565 grand_child1_raw
->SetDrawsContent(true);
6566 grand_child2_raw
->SetDrawsContent(true);
6568 ExecuteCalculateDrawProperties(grand_parent_raw
);
6569 member_id
= render_surface_layer_list_count();
6571 EXPECT_EQ(member_id
, membership_id(grand_parent_raw
));
6572 EXPECT_EQ(member_id
, membership_id(parent_raw
));
6573 EXPECT_EQ(member_id
, membership_id(child_raw
));
6574 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
6575 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
6578 expected
.insert(grand_parent_raw
);
6579 expected
.insert(parent_raw
);
6580 expected
.insert(child_raw
);
6581 expected
.insert(grand_child1_raw
);
6582 expected
.insert(grand_child2_raw
);
6585 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
6586 EXPECT_EQ(expected
, actual
);
6589 TEST_F(LayerTreeHostCommonTest
, DrawPropertyScales
) {
6590 FakeImplProxy proxy
;
6591 TestSharedBitmapManager shared_bitmap_manager
;
6592 TestTaskGraphRunner task_graph_runner
;
6593 LayerTreeSettings settings
;
6594 settings
.layer_transforms_should_scale_layer_contents
= true;
6595 FakeLayerTreeHostImpl
host_impl(settings
, &proxy
, &shared_bitmap_manager
,
6596 &task_graph_runner
);
6598 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
6599 LayerImpl
* root_layer
= root
.get();
6600 scoped_ptr
<LayerImpl
> child1
= LayerImpl::Create(host_impl
.active_tree(), 2);
6601 LayerImpl
* child1_layer
= child1
.get();
6602 scoped_ptr
<LayerImpl
> child2
= LayerImpl::Create(host_impl
.active_tree(), 3);
6603 LayerImpl
* child2_layer
= child2
.get();
6605 root
->AddChild(child1
.Pass());
6606 root
->AddChild(child2
.Pass());
6607 root
->SetHasRenderSurface(true);
6609 gfx::Transform identity_matrix
, scale_transform_child1
,
6610 scale_transform_child2
;
6611 scale_transform_child1
.Scale(2, 3);
6612 scale_transform_child2
.Scale(4, 5);
6614 SetLayerPropertiesForTesting(root_layer
, identity_matrix
, gfx::Point3F(),
6615 gfx::PointF(), gfx::Size(1, 1), true, false,
6617 SetLayerPropertiesForTesting(child1_layer
, scale_transform_child1
,
6618 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
6621 child1_layer
->SetMaskLayer(
6622 LayerImpl::Create(host_impl
.active_tree(), 4).Pass());
6624 scoped_ptr
<LayerImpl
> replica_layer
=
6625 LayerImpl::Create(host_impl
.active_tree(), 5);
6626 replica_layer
->SetHasRenderSurface(true);
6627 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6));
6628 child1_layer
->SetReplicaLayer(replica_layer
.Pass());
6629 child1_layer
->SetHasRenderSurface(true);
6631 ExecuteCalculateDrawProperties(root_layer
);
6633 TransformOperations scale
;
6634 scale
.AppendScale(5.f
, 8.f
, 3.f
);
6636 AddAnimatedTransformToLayer(child2_layer
, 1.0, TransformOperations(), scale
);
6637 SetLayerPropertiesForTesting(child2_layer
, scale_transform_child2
,
6638 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
6641 ExecuteCalculateDrawProperties(root_layer
);
6643 EXPECT_FLOAT_EQ(1.f
, root_layer
->GetIdealContentsScale());
6644 EXPECT_FLOAT_EQ(3.f
, child1_layer
->GetIdealContentsScale());
6645 EXPECT_FLOAT_EQ(3.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
6646 EXPECT_FLOAT_EQ(5.f
, child2_layer
->GetIdealContentsScale());
6649 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
6651 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
6652 EXPECT_FLOAT_EQ(0.f
,
6653 child1_layer
->mask_layer()
6655 .maximum_animation_contents_scale
);
6656 EXPECT_FLOAT_EQ(0.f
,
6657 child1_layer
->replica_layer()
6660 .maximum_animation_contents_scale
);
6662 8.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
6664 // Changing page-scale would affect ideal_contents_scale and
6665 // maximum_animation_contents_scale.
6667 float page_scale_factor
= 3.f
;
6668 float device_scale_factor
= 1.0f
;
6669 std::vector
<LayerImpl
*> render_surface_layer_list
;
6670 gfx::Size device_viewport_size
=
6671 gfx::Size(root_layer
->bounds().width() * device_scale_factor
,
6672 root_layer
->bounds().height() * device_scale_factor
);
6673 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6674 root_layer
, device_viewport_size
, &render_surface_layer_list
);
6676 inputs
.page_scale_factor
= page_scale_factor
;
6677 inputs
.can_adjust_raster_scales
= true;
6678 inputs
.page_scale_layer
= root_layer
;
6679 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6681 EXPECT_FLOAT_EQ(3.f
, root_layer
->GetIdealContentsScale());
6682 EXPECT_FLOAT_EQ(9.f
, child1_layer
->GetIdealContentsScale());
6683 EXPECT_FLOAT_EQ(9.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
6686 child1_layer
->replica_layer()->mask_layer()->GetIdealContentsScale());
6687 EXPECT_FLOAT_EQ(15.f
, child2_layer
->GetIdealContentsScale());
6690 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
6692 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
6693 EXPECT_FLOAT_EQ(0.f
,
6694 child1_layer
->mask_layer()
6696 .maximum_animation_contents_scale
);
6697 EXPECT_FLOAT_EQ(0.f
,
6698 child1_layer
->replica_layer()
6701 .maximum_animation_contents_scale
);
6703 24.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
6705 // Changing device-scale would affect ideal_contents_scale and
6706 // maximum_animation_contents_scale.
6708 device_scale_factor
= 4.0f
;
6709 inputs
.device_scale_factor
= device_scale_factor
;
6710 inputs
.can_adjust_raster_scales
= true;
6711 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6713 EXPECT_FLOAT_EQ(12.f
, root_layer
->GetIdealContentsScale());
6714 EXPECT_FLOAT_EQ(36.f
, child1_layer
->GetIdealContentsScale());
6715 EXPECT_FLOAT_EQ(36.f
, child1_layer
->mask_layer()->GetIdealContentsScale());
6718 child1_layer
->replica_layer()->mask_layer()->GetIdealContentsScale());
6719 EXPECT_FLOAT_EQ(60.f
, child2_layer
->GetIdealContentsScale());
6722 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
6724 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
6725 EXPECT_FLOAT_EQ(0.f
,
6726 child1_layer
->mask_layer()
6728 .maximum_animation_contents_scale
);
6729 EXPECT_FLOAT_EQ(0.f
,
6730 child1_layer
->replica_layer()
6733 .maximum_animation_contents_scale
);
6735 96.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
6738 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInChildRenderSurface
) {
6739 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6740 SetLayerPropertiesForTesting(root
.get(),
6744 gfx::Size(768 / 2, 3000),
6747 root
->SetIsDrawable(true);
6749 scoped_refptr
<Layer
> clip
= Layer::Create(layer_settings());
6750 SetLayerPropertiesForTesting(clip
.get(),
6754 gfx::Size(768 / 2, 10000),
6757 clip
->SetMasksToBounds(true);
6759 scoped_refptr
<Layer
> content
= Layer::Create(layer_settings());
6760 SetLayerPropertiesForTesting(content
.get(),
6764 gfx::Size(768 / 2, 10000),
6767 content
->SetIsDrawable(true);
6768 content
->SetForceRenderSurface(true);
6770 root
->AddChild(clip
);
6771 clip
->AddChild(content
);
6773 host()->SetRootLayer(root
);
6775 gfx::Size
device_viewport_size(768, 582);
6776 LayerTreeHostCommon::CalcDrawPropsMainInputs
inputs(host()->root_layer(),
6777 device_viewport_size
);
6778 inputs
.device_scale_factor
= 2.f
;
6779 inputs
.page_scale_factor
= 1.f
;
6780 inputs
.page_scale_layer
= NULL
;
6781 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6783 // Layers in the root render surface have their visible content rect clipped
6785 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
6786 root
->visible_rect_from_property_trees());
6788 // Layers drawing to a child render surface should still have their visible
6789 // content rect clipped by the viewport.
6790 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2),
6791 content
->visible_rect_from_property_trees());
6794 TEST_F(LayerTreeHostCommonTest
, BoundsDeltaAffectVisibleContentRect
) {
6795 FakeImplProxy proxy
;
6796 TestSharedBitmapManager shared_bitmap_manager
;
6797 TestTaskGraphRunner task_graph_runner
;
6798 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
6799 &task_graph_runner
);
6801 // Set two layers: the root layer clips it's child,
6802 // the child draws its content.
6804 gfx::Size root_size
= gfx::Size(300, 500);
6806 // Sublayer should be bigger than the root enlarged by bounds_delta.
6807 gfx::Size sublayer_size
= gfx::Size(300, 1000);
6809 // Device viewport accomidated the root and the top controls.
6810 gfx::Size device_viewport_size
= gfx::Size(300, 600);
6811 gfx::Transform identity_matrix
;
6813 host_impl
.SetViewportSize(device_viewport_size
);
6814 host_impl
.active_tree()->SetRootLayer(
6815 LayerImpl::Create(host_impl
.active_tree(), 1));
6817 LayerImpl
* root
= host_impl
.active_tree()->root_layer();
6818 SetLayerPropertiesForTesting(root
,
6826 root
->SetMasksToBounds(true);
6828 root
->AddChild(LayerImpl::Create(host_impl
.active_tree(), 2));
6830 LayerImpl
* sublayer
= root
->child_at(0);
6831 SetLayerPropertiesForTesting(sublayer
,
6839 sublayer
->SetDrawsContent(true);
6841 LayerImplList layer_impl_list
;
6842 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6843 root
, device_viewport_size
, &layer_impl_list
);
6845 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6846 EXPECT_EQ(gfx::Rect(root_size
), sublayer
->visible_layer_rect());
6848 root
->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
6849 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6851 gfx::Rect
affected_by_delta(0, 0, root_size
.width(),
6852 root_size
.height() + 50);
6853 EXPECT_EQ(affected_by_delta
, sublayer
->visible_layer_rect());
6856 TEST_F(LayerTreeHostCommonTest
, NodesAffectedByBoundsDeltaGetUpdated
) {
6857 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6858 scoped_refptr
<Layer
> inner_viewport_container_layer
=
6859 Layer::Create(layer_settings());
6860 scoped_refptr
<Layer
> inner_viewport_scroll_layer
=
6861 Layer::Create(layer_settings());
6862 scoped_refptr
<Layer
> outer_viewport_container_layer
=
6863 Layer::Create(layer_settings());
6864 scoped_refptr
<Layer
> outer_viewport_scroll_layer
=
6865 Layer::Create(layer_settings());
6867 root
->AddChild(inner_viewport_container_layer
);
6868 inner_viewport_container_layer
->AddChild(inner_viewport_scroll_layer
);
6869 inner_viewport_scroll_layer
->AddChild(outer_viewport_container_layer
);
6870 outer_viewport_container_layer
->AddChild(outer_viewport_scroll_layer
);
6872 inner_viewport_scroll_layer
->SetScrollClipLayerId(
6873 inner_viewport_container_layer
->id());
6874 outer_viewport_scroll_layer
->SetScrollClipLayerId(
6875 outer_viewport_container_layer
->id());
6877 inner_viewport_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
6878 outer_viewport_scroll_layer
->SetIsContainerForFixedPositionLayers(true);
6880 host()->SetRootLayer(root
);
6881 host()->RegisterViewportLayers(nullptr, root
, inner_viewport_scroll_layer
,
6882 outer_viewport_scroll_layer
);
6884 scoped_refptr
<Layer
> fixed_to_inner
= Layer::Create(layer_settings());
6885 scoped_refptr
<Layer
> fixed_to_outer
= Layer::Create(layer_settings());
6887 inner_viewport_scroll_layer
->AddChild(fixed_to_inner
);
6888 outer_viewport_scroll_layer
->AddChild(fixed_to_outer
);
6890 LayerPositionConstraint fixed_to_right
;
6891 fixed_to_right
.set_is_fixed_position(true);
6892 fixed_to_right
.set_is_fixed_to_right_edge(true);
6894 fixed_to_inner
->SetPositionConstraint(fixed_to_right
);
6895 fixed_to_outer
->SetPositionConstraint(fixed_to_right
);
6897 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6899 TransformTree
& transform_tree
= host()->property_trees()->transform_tree
;
6900 EXPECT_TRUE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
6901 EXPECT_TRUE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
6903 LayerPositionConstraint fixed_to_left
;
6904 fixed_to_left
.set_is_fixed_position(true);
6905 fixed_to_inner
->SetPositionConstraint(fixed_to_left
);
6907 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6908 EXPECT_FALSE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
6909 EXPECT_TRUE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
6911 fixed_to_outer
->SetPositionConstraint(fixed_to_left
);
6913 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6914 EXPECT_FALSE(transform_tree
.HasNodesAffectedByInnerViewportBoundsDelta());
6915 EXPECT_FALSE(transform_tree
.HasNodesAffectedByOuterViewportBoundsDelta());
6918 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectForAnimatedLayer
) {
6919 const gfx::Transform identity_matrix
;
6920 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6921 scoped_refptr
<LayerWithForcedDrawsContent
> animated
=
6922 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6924 root
->AddChild(animated
);
6926 host()->SetRootLayer(root
);
6928 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
6929 gfx::PointF(), gfx::Size(100, 100), true, false);
6930 SetLayerPropertiesForTesting(animated
.get(), identity_matrix
, gfx::Point3F(),
6931 gfx::PointF(), gfx::Size(20, 20), true, false);
6933 root
->SetMasksToBounds(true);
6934 root
->SetForceRenderSurface(true);
6935 animated
->SetOpacity(0.f
);
6937 AddOpacityTransitionToController(animated
->layer_animation_controller(), 10.0,
6940 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6942 EXPECT_FALSE(animated
->visible_rect_from_property_trees().IsEmpty());
6945 TEST_F(LayerTreeHostCommonTest
,
6946 VisibleContentRectForAnimatedLayerWithSingularTransform
) {
6947 const gfx::Transform identity_matrix
;
6948 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6949 scoped_refptr
<Layer
> clip
= Layer::Create(layer_settings());
6950 scoped_refptr
<LayerWithForcedDrawsContent
> animated
=
6951 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6952 scoped_refptr
<LayerWithForcedDrawsContent
> surface
=
6953 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6954 scoped_refptr
<LayerWithForcedDrawsContent
> descendant_of_animation
=
6955 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6957 root
->AddChild(clip
);
6958 clip
->AddChild(animated
);
6959 animated
->AddChild(surface
);
6960 surface
->AddChild(descendant_of_animation
);
6962 clip
->SetMasksToBounds(true);
6963 surface
->SetForceRenderSurface(true);
6965 host()->SetRootLayer(root
);
6967 gfx::Transform uninvertible_matrix
;
6968 uninvertible_matrix
.Scale3d(6.f
, 6.f
, 0.f
);
6970 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
6971 gfx::PointF(), gfx::Size(100, 100), true, false);
6972 SetLayerPropertiesForTesting(clip
.get(), identity_matrix
, gfx::Point3F(),
6973 gfx::PointF(), gfx::Size(10, 10), true, false);
6974 SetLayerPropertiesForTesting(animated
.get(), uninvertible_matrix
,
6975 gfx::Point3F(), gfx::PointF(),
6976 gfx::Size(120, 120), true, false);
6977 SetLayerPropertiesForTesting(surface
.get(), identity_matrix
, gfx::Point3F(),
6978 gfx::PointF(), gfx::Size(100, 100), true, false);
6979 SetLayerPropertiesForTesting(descendant_of_animation
.get(), identity_matrix
,
6980 gfx::Point3F(), gfx::PointF(),
6981 gfx::Size(200, 200), true, false);
6983 TransformOperations start_transform_operations
;
6984 start_transform_operations
.AppendMatrix(uninvertible_matrix
);
6985 TransformOperations end_transform_operations
;
6987 AddAnimatedTransformToLayer(animated
.get(), 10.0, start_transform_operations
,
6988 end_transform_operations
);
6990 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
6992 // The animated layer has a singular transform and maps to a non-empty rect in
6993 // clipped target space, so is treated as fully visible.
6994 EXPECT_EQ(gfx::Rect(120, 120), animated
->visible_rect_from_property_trees());
6996 // The singular transform on |animated| is flattened when inherited by
6997 // |surface|, and this happens to make it invertible.
6998 EXPECT_EQ(gfx::Rect(2, 2), surface
->visible_rect_from_property_trees());
6999 EXPECT_EQ(gfx::Rect(2, 2),
7000 descendant_of_animation
->visible_rect_from_property_trees());
7002 gfx::Transform zero_matrix
;
7003 zero_matrix
.Scale3d(0.f
, 0.f
, 0.f
);
7004 SetLayerPropertiesForTesting(animated
.get(), zero_matrix
, gfx::Point3F(),
7005 gfx::PointF(), gfx::Size(120, 120), true, false);
7007 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7009 // The animated layer maps to the empty rect in clipped target space, so is
7010 // treated as having an empty visible rect.
7011 EXPECT_EQ(gfx::Rect(), animated
->visible_rect_from_property_trees());
7013 // This time, flattening does not make |animated|'s transform invertible. This
7014 // means the clip cannot be projected into |surface|'s space, so we treat
7015 // |surface| and layers that draw into it as having empty visible rect.
7016 EXPECT_EQ(gfx::Rect(), surface
->visible_rect_from_property_trees());
7017 EXPECT_EQ(gfx::Rect(),
7018 descendant_of_animation
->visible_rect_from_property_trees());
7021 // Verify that having an animated filter (but no current filter, as these
7022 // are mutually exclusive) correctly creates a render surface.
7023 TEST_F(LayerTreeHostCommonTest
, AnimatedFilterCreatesRenderSurface
) {
7024 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7025 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7026 scoped_refptr
<Layer
> grandchild
= Layer::Create(layer_settings());
7027 root
->AddChild(child
);
7028 child
->AddChild(grandchild
);
7030 gfx::Transform identity_transform
;
7031 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7032 gfx::PointF(), gfx::Size(50, 50), true, false);
7033 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7034 gfx::PointF(), gfx::Size(50, 50), true, false);
7035 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7036 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7038 host()->SetRootLayer(root
);
7040 AddAnimatedFilterToLayer(child
.get(), 10.0, 0.1f
, 0.2f
);
7042 ExecuteCalculateDrawProperties(root
.get());
7044 EXPECT_TRUE(root
->has_render_surface());
7045 EXPECT_TRUE(child
->has_render_surface());
7046 EXPECT_FALSE(grandchild
->has_render_surface());
7048 EXPECT_TRUE(root
->filters().IsEmpty());
7049 EXPECT_TRUE(child
->filters().IsEmpty());
7050 EXPECT_TRUE(grandchild
->filters().IsEmpty());
7052 EXPECT_FALSE(root
->FilterIsAnimating());
7053 EXPECT_TRUE(child
->FilterIsAnimating());
7054 EXPECT_FALSE(grandchild
->FilterIsAnimating());
7057 // Verify that having a filter animation with a delayed start time creates a
7059 TEST_F(LayerTreeHostCommonTest
, DelayedFilterAnimationCreatesRenderSurface
) {
7060 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7061 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7062 scoped_refptr
<Layer
> grandchild
= Layer::Create(layer_settings());
7063 root
->AddChild(child
);
7064 child
->AddChild(grandchild
);
7066 gfx::Transform identity_transform
;
7067 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7068 gfx::PointF(), gfx::Size(50, 50), true, false);
7069 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7070 gfx::PointF(), gfx::Size(50, 50), true, false);
7071 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7072 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7074 host()->SetRootLayer(root
);
7076 scoped_ptr
<KeyframedFilterAnimationCurve
> curve(
7077 KeyframedFilterAnimationCurve::Create());
7078 FilterOperations start_filters
;
7079 start_filters
.Append(FilterOperation::CreateBrightnessFilter(0.1f
));
7080 FilterOperations end_filters
;
7081 end_filters
.Append(FilterOperation::CreateBrightnessFilter(0.3f
));
7083 FilterKeyframe::Create(base::TimeDelta(), start_filters
, nullptr));
7084 curve
->AddKeyframe(FilterKeyframe::Create(
7085 base::TimeDelta::FromMilliseconds(100), end_filters
, nullptr));
7086 scoped_ptr
<Animation
> animation
=
7087 Animation::Create(curve
.Pass(), 0, 1, Animation::FILTER
);
7088 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
7089 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7090 child
->layer_animation_controller()->AddAnimation(animation
.Pass());
7092 ExecuteCalculateDrawProperties(root
.get());
7094 EXPECT_TRUE(root
->has_render_surface());
7095 EXPECT_TRUE(child
->has_render_surface());
7096 EXPECT_FALSE(grandchild
->has_render_surface());
7098 EXPECT_TRUE(root
->filters().IsEmpty());
7099 EXPECT_TRUE(child
->filters().IsEmpty());
7100 EXPECT_TRUE(grandchild
->filters().IsEmpty());
7102 EXPECT_FALSE(root
->FilterIsAnimating());
7103 EXPECT_FALSE(root
->HasPotentiallyRunningFilterAnimation());
7104 EXPECT_FALSE(child
->FilterIsAnimating());
7105 EXPECT_TRUE(child
->HasPotentiallyRunningFilterAnimation());
7106 EXPECT_FALSE(grandchild
->FilterIsAnimating());
7107 EXPECT_FALSE(grandchild
->HasPotentiallyRunningFilterAnimation());
7110 // Ensures that the property tree code accounts for offsets between fixed
7111 // position layers and their respective containers.
7112 TEST_F(LayerTreeHostCommonTest
, PropertyTreesAccountForFixedParentOffset
) {
7113 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7114 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7115 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7116 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7118 root
->AddChild(child
);
7119 child
->AddChild(grandchild
);
7121 gfx::Transform identity_transform
;
7122 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7123 gfx::PointF(), gfx::Size(50, 50), true, false);
7124 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7125 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7127 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7128 gfx::Point3F(), gfx::PointF(-1000, -1000),
7129 gfx::Size(50, 50), true, false);
7131 root
->SetMasksToBounds(true);
7132 root
->SetIsContainerForFixedPositionLayers(true);
7133 LayerPositionConstraint constraint
;
7134 constraint
.set_is_fixed_position(true);
7135 grandchild
->SetPositionConstraint(constraint
);
7137 root
->SetIsContainerForFixedPositionLayers(true);
7139 host()->SetRootLayer(root
);
7141 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7143 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7144 grandchild
->visible_rect_from_property_trees());
7147 // Ensures that the property tree code accounts for offsets between fixed
7148 // position containers and their transform tree parents, when a fixed position
7149 // layer's container is its layer tree parent, but this parent doesn't have its
7150 // own transform tree node.
7151 TEST_F(LayerTreeHostCommonTest
,
7152 PropertyTreesAccountForFixedParentOffsetWhenContainerIsParent
) {
7153 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7154 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7155 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7156 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7158 root
->AddChild(child
);
7159 child
->AddChild(grandchild
);
7161 gfx::Transform identity_transform
;
7162 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7163 gfx::PointF(), gfx::Size(50, 50), true, false);
7164 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
7165 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
7167 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
7168 gfx::Point3F(), gfx::PointF(-1000, -1000),
7169 gfx::Size(50, 50), true, false);
7171 root
->SetMasksToBounds(true);
7172 child
->SetIsContainerForFixedPositionLayers(true);
7173 LayerPositionConstraint constraint
;
7174 constraint
.set_is_fixed_position(true);
7175 grandchild
->SetPositionConstraint(constraint
);
7177 root
->SetIsContainerForFixedPositionLayers(true);
7179 host()->SetRootLayer(root
);
7181 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7183 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
7184 grandchild
->visible_rect_from_property_trees());
7187 TEST_F(LayerTreeHostCommonTest
, CombineClipsUsingContentTarget
) {
7188 // In the following layer tree, the layer |box|'s render target is |surface|.
7189 // |surface| also creates a transform node. We want to combine clips for |box|
7190 // in the space of its target (i.e., |surface|), not its target's target. This
7191 // test ensures that happens.
7193 gfx::Transform rotate
;
7195 gfx::Transform identity
;
7197 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7198 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7199 gfx::PointF(), gfx::Size(2500, 1500), true,
7202 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7203 SetLayerPropertiesForTesting(frame_clip
.get(), identity
, gfx::Point3F(),
7204 gfx::PointF(), gfx::Size(2500, 1500), true,
7206 frame_clip
->SetMasksToBounds(true);
7208 scoped_refptr
<Layer
> rotated
= Layer::Create(layer_settings());
7209 SetLayerPropertiesForTesting(rotated
.get(), rotate
,
7210 gfx::Point3F(1250, 250, 0), gfx::PointF(),
7211 gfx::Size(2500, 500), true, false);
7213 scoped_refptr
<Layer
> surface
= Layer::Create(layer_settings());
7214 SetLayerPropertiesForTesting(surface
.get(), rotate
, gfx::Point3F(),
7215 gfx::PointF(), gfx::Size(2500, 500), true,
7217 surface
->SetOpacity(0.5);
7219 scoped_refptr
<LayerWithForcedDrawsContent
> container
=
7220 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7221 SetLayerPropertiesForTesting(container
.get(), identity
, gfx::Point3F(),
7222 gfx::PointF(), gfx::Size(300, 300), true, false);
7224 scoped_refptr
<LayerWithForcedDrawsContent
> box
=
7225 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7226 SetLayerPropertiesForTesting(box
.get(), identity
, gfx::Point3F(),
7227 gfx::PointF(), gfx::Size(100, 100), true, false);
7229 root
->AddChild(frame_clip
);
7230 frame_clip
->AddChild(rotated
);
7231 rotated
->AddChild(surface
);
7232 surface
->AddChild(container
);
7233 surface
->AddChild(box
);
7235 host()->SetRootLayer(root
);
7237 ExecuteCalculateDrawProperties(root
.get());
7240 TEST_F(LayerTreeHostCommonTest
, OnlyApplyFixedPositioningOnce
) {
7241 gfx::Transform identity
;
7242 gfx::Transform translate_z
;
7243 translate_z
.Translate3d(0, 0, 10);
7245 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7246 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7247 gfx::PointF(), gfx::Size(800, 800), true, false);
7248 root
->SetIsContainerForFixedPositionLayers(true);
7250 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7251 SetLayerPropertiesForTesting(frame_clip
.get(), translate_z
, gfx::Point3F(),
7252 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7254 frame_clip
->SetMasksToBounds(true);
7256 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7257 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7258 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7259 gfx::PointF(), gfx::Size(1000, 1000), true,
7262 LayerPositionConstraint constraint
;
7263 constraint
.set_is_fixed_position(true);
7264 fixed
->SetPositionConstraint(constraint
);
7266 root
->AddChild(frame_clip
);
7267 frame_clip
->AddChild(fixed
);
7269 host()->SetRootLayer(root
);
7271 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7273 gfx::Rect
expected(0, 0, 100, 100);
7274 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7277 TEST_F(LayerTreeHostCommonTest
,
7278 PropertyTreesAccountForScrollCompensationAdjustment
) {
7279 gfx::Transform identity
;
7280 gfx::Transform translate_z
;
7281 translate_z
.Translate3d(0, 0, 10);
7283 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7284 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7285 gfx::PointF(), gfx::Size(800, 800), true, false);
7286 root
->SetIsContainerForFixedPositionLayers(true);
7288 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7289 SetLayerPropertiesForTesting(frame_clip
.get(), translate_z
, gfx::Point3F(),
7290 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7292 frame_clip
->SetMasksToBounds(true);
7294 scoped_refptr
<LayerWithForcedDrawsContent
> scroller
=
7295 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7296 SetLayerPropertiesForTesting(scroller
.get(), identity
, gfx::Point3F(),
7297 gfx::PointF(), gfx::Size(1000, 1000), true,
7300 scroller
->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f
, 0.7f
));
7301 scroller
->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
7302 scroller
->SetScrollClipLayerId(frame_clip
->id());
7304 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7305 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7306 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7307 gfx::PointF(), gfx::Size(50, 50), true, false);
7309 LayerPositionConstraint constraint
;
7310 constraint
.set_is_fixed_position(true);
7311 fixed
->SetPositionConstraint(constraint
);
7313 scoped_refptr
<LayerWithForcedDrawsContent
> fixed_child
=
7314 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7315 SetLayerPropertiesForTesting(fixed_child
.get(), identity
, gfx::Point3F(),
7316 gfx::PointF(), gfx::Size(10, 10), true, false);
7318 fixed_child
->SetPositionConstraint(constraint
);
7320 root
->AddChild(frame_clip
);
7321 frame_clip
->AddChild(scroller
);
7322 scroller
->AddChild(fixed
);
7323 fixed
->AddChild(fixed_child
);
7325 host()->SetRootLayer(root
);
7327 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7329 gfx::Rect
expected(0, 0, 50, 50);
7330 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7332 expected
= gfx::Rect(0, 0, 10, 10);
7333 EXPECT_EQ(expected
, fixed_child
->visible_rect_from_property_trees());
7336 TEST_F(LayerTreeHostCommonTest
, FixedClipsShouldBeAssociatedWithTheRightNode
) {
7337 gfx::Transform identity
;
7339 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7340 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7341 gfx::PointF(), gfx::Size(800, 800), true, false);
7342 root
->SetIsContainerForFixedPositionLayers(true);
7344 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
7345 SetLayerPropertiesForTesting(frame_clip
.get(), identity
, gfx::Point3F(),
7346 gfx::PointF(500, 100), gfx::Size(100, 100), true,
7348 frame_clip
->SetMasksToBounds(true);
7350 scoped_refptr
<LayerWithForcedDrawsContent
> scroller
=
7351 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7352 SetLayerPropertiesForTesting(scroller
.get(), identity
, gfx::Point3F(),
7353 gfx::PointF(), gfx::Size(1000, 1000), true,
7356 scroller
->SetScrollOffset(gfx::ScrollOffset(100, 100));
7357 scroller
->SetScrollClipLayerId(frame_clip
->id());
7359 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7360 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7361 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
7362 gfx::PointF(100, 100), gfx::Size(50, 50), true,
7365 LayerPositionConstraint constraint
;
7366 constraint
.set_is_fixed_position(true);
7367 fixed
->SetPositionConstraint(constraint
);
7368 fixed
->SetForceRenderSurface(true);
7369 fixed
->SetMasksToBounds(true);
7371 root
->AddChild(frame_clip
);
7372 frame_clip
->AddChild(scroller
);
7373 scroller
->AddChild(fixed
);
7375 host()->SetRootLayer(root
);
7377 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7379 gfx::Rect
expected(0, 0, 50, 50);
7380 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
7383 TEST_F(LayerTreeHostCommonTest
, ChangingAxisAlignmentTriggersRebuild
) {
7384 gfx::Transform identity
;
7385 gfx::Transform translate
;
7386 gfx::Transform rotate
;
7388 translate
.Translate(10, 10);
7391 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7392 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7393 gfx::PointF(), gfx::Size(800, 800), true, false);
7394 root
->SetIsContainerForFixedPositionLayers(true);
7396 host()->SetRootLayer(root
);
7398 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7399 EXPECT_FALSE(host()->property_trees()->needs_rebuild
);
7401 root
->SetTransform(translate
);
7402 EXPECT_FALSE(host()->property_trees()->needs_rebuild
);
7404 root
->SetTransform(rotate
);
7405 EXPECT_TRUE(host()->property_trees()->needs_rebuild
);
7408 TEST_F(LayerTreeHostCommonTest
, ChangeTransformOrigin
) {
7409 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7410 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7411 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7412 root
->AddChild(child
);
7414 host()->SetRootLayer(root
);
7416 gfx::Transform identity_matrix
;
7417 gfx::Transform scale_matrix
;
7418 scale_matrix
.Scale(2.f
, 2.f
);
7419 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
7420 gfx::PointF(), gfx::Size(100, 100), true, false);
7421 SetLayerPropertiesForTesting(child
.get(), scale_matrix
, gfx::Point3F(),
7422 gfx::PointF(), gfx::Size(10, 10), true, false);
7424 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7425 EXPECT_EQ(gfx::Rect(10, 10), child
->visible_rect_from_property_trees());
7427 child
->SetTransformOrigin(gfx::Point3F(10.f
, 10.f
, 10.f
));
7429 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7430 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child
->visible_rect_from_property_trees());
7433 TEST_F(LayerTreeHostCommonTest
, UpdateScrollChildPosition
) {
7434 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7435 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7436 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7437 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7438 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7440 root
->AddChild(scroll_child
);
7441 root
->AddChild(scroll_parent
);
7442 scroll_child
->SetScrollParent(scroll_parent
.get());
7443 scroll_parent
->SetScrollClipLayerId(root
->id());
7445 host()->SetRootLayer(root
);
7447 gfx::Transform identity_transform
;
7448 gfx::Transform scale
;
7449 scale
.Scale(2.f
, 2.f
);
7450 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7451 gfx::PointF(), gfx::Size(50, 50), true, false);
7452 SetLayerPropertiesForTesting(scroll_child
.get(), scale
, gfx::Point3F(),
7453 gfx::PointF(), gfx::Size(40, 40), true, false);
7454 SetLayerPropertiesForTesting(scroll_parent
.get(), identity_transform
,
7455 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7458 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7459 EXPECT_EQ(gfx::Rect(25, 25),
7460 scroll_child
->visible_rect_from_property_trees());
7462 scroll_child
->SetPosition(gfx::PointF(0, -10.f
));
7463 scroll_parent
->SetScrollOffset(gfx::ScrollOffset(0.f
, 10.f
));
7464 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7465 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
7466 scroll_child
->visible_rect_from_property_trees());
7469 static void CopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {
7472 TEST_F(LayerTreeHostCommonTest
, SkippingSubtreeMain
) {
7473 gfx::Transform identity
;
7474 FakeContentLayerClient client
;
7475 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7476 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7477 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7478 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
7479 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7480 scoped_refptr
<FakePictureLayer
> greatgrandchild(
7481 FakePictureLayer::Create(layer_settings(), &client
));
7482 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7483 gfx::PointF(), gfx::Size(100, 100), true, false);
7484 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7485 gfx::PointF(), gfx::Size(10, 10), true, false);
7486 SetLayerPropertiesForTesting(grandchild
.get(), identity
, gfx::Point3F(),
7487 gfx::PointF(), gfx::Size(10, 10), true, false);
7488 SetLayerPropertiesForTesting(greatgrandchild
.get(), identity
, gfx::Point3F(),
7489 gfx::PointF(), gfx::Size(10, 10), true, false);
7491 root
->AddChild(child
);
7492 child
->AddChild(grandchild
);
7493 grandchild
->AddChild(greatgrandchild
);
7495 host()->SetRootLayer(root
);
7497 // Check the non-skipped case.
7498 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7499 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7501 // Now we will reset the visible rect from property trees for the grandchild,
7502 // and we will configure |child| in several ways that should force the subtree
7503 // to be skipped. The visible content rect for |grandchild| should, therefore,
7505 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7506 gfx::Transform singular
;
7507 singular
.matrix().set(0, 0, 0);
7509 child
->SetTransform(singular
);
7510 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7511 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7512 child
->SetTransform(identity
);
7514 child
->SetHideLayerAndSubtree(true);
7515 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7516 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7517 child
->SetHideLayerAndSubtree(false);
7519 gfx::Transform zero_z_scale
;
7520 zero_z_scale
.Scale3d(1, 1, 0);
7521 child
->SetTransform(zero_z_scale
);
7523 // Add a transform animation with a start delay. Now, even though |child| has
7524 // a singular transform, the subtree should still get processed.
7525 int animation_id
= 0;
7526 scoped_ptr
<Animation
> animation
= Animation::Create(
7527 scoped_ptr
<AnimationCurve
>(new FakeTransformTransition(1.0)).Pass(),
7528 animation_id
, 1, Animation::TRANSFORM
);
7529 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
7530 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7531 child
->AddAnimation(animation
.Pass());
7532 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7533 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7534 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7536 child
->RemoveAnimation(animation_id
);
7537 child
->SetTransform(identity
);
7538 child
->SetOpacity(0.f
);
7539 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7540 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
7542 // Now, even though child has zero opacity, we will configure |grandchild| and
7543 // |greatgrandchild| in several ways that should force the subtree to be
7544 // processed anyhow.
7545 greatgrandchild
->RequestCopyOfOutput(
7546 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback
)));
7547 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7548 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7549 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
7551 // Add an opacity animation with a start delay.
7553 animation
= Animation::Create(
7554 scoped_ptr
<AnimationCurve
>(new FakeFloatTransition(1.0, 0.f
, 1.f
)).Pass(),
7555 animation_id
, 1, Animation::OPACITY
);
7556 animation
->set_fill_mode(Animation::FILL_MODE_NONE
);
7557 animation
->set_time_offset(base::TimeDelta::FromMilliseconds(-1000));
7558 child
->AddAnimation(animation
.Pass());
7559 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7560 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
7563 TEST_F(LayerTreeHostCommonTest
, SkippingSubtreeImpl
) {
7564 FakeImplProxy proxy
;
7565 TestSharedBitmapManager shared_bitmap_manager
;
7566 TestTaskGraphRunner task_graph_runner
;
7567 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
,
7568 &task_graph_runner
);
7570 gfx::Transform identity
;
7571 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7572 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 2);
7573 scoped_ptr
<LayerImpl
> grandchild
=
7574 LayerImpl::Create(host_impl
.active_tree(), 3);
7576 scoped_ptr
<FakePictureLayerImpl
> greatgrandchild(
7577 FakePictureLayerImpl::Create(host_impl
.active_tree(), 4));
7579 child
->SetDrawsContent(true);
7580 grandchild
->SetDrawsContent(true);
7581 greatgrandchild
->SetDrawsContent(true);
7583 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7584 gfx::PointF(), gfx::Size(100, 100), true, false,
7586 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7587 gfx::PointF(), gfx::Size(10, 10), true, false,
7589 SetLayerPropertiesForTesting(grandchild
.get(), identity
, gfx::Point3F(),
7590 gfx::PointF(), gfx::Size(10, 10), true, false,
7592 SetLayerPropertiesForTesting(greatgrandchild
.get(), identity
, gfx::Point3F(),
7593 gfx::PointF(), gfx::Size(10, 10), true, false,
7596 LayerImpl
* child_ptr
= child
.get();
7597 LayerImpl
* grandchild_ptr
= grandchild
.get();
7598 LayerImpl
* greatgrandchild_ptr
= greatgrandchild
.get();
7600 grandchild
->AddChild(greatgrandchild
.Pass());
7601 child
->AddChild(grandchild
.Pass());
7602 root
->AddChild(child
.Pass());
7604 // Check the non-skipped case.
7605 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7606 EXPECT_EQ(gfx::Rect(10, 10),
7607 grandchild_ptr
->visible_rect_from_property_trees());
7609 // Now we will reset the visible rect from property trees for the grandchild,
7610 // and we will configure |child| in several ways that should force the subtree
7611 // to be skipped. The visible content rect for |grandchild| should, therefore,
7613 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
7614 gfx::Transform singular
;
7615 singular
.matrix().set(0, 0, 0);
7617 child_ptr
->SetTransform(singular
);
7618 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7619 EXPECT_EQ(gfx::Rect(0, 0),
7620 grandchild_ptr
->visible_rect_from_property_trees());
7621 child_ptr
->SetTransform(identity
);
7623 child_ptr
->SetHideLayerAndSubtree(true);
7624 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7625 EXPECT_EQ(gfx::Rect(0, 0),
7626 grandchild_ptr
->visible_rect_from_property_trees());
7627 child_ptr
->SetHideLayerAndSubtree(false);
7629 child_ptr
->SetOpacity(0.f
);
7630 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7631 EXPECT_EQ(gfx::Rect(0, 0),
7632 grandchild_ptr
->visible_rect_from_property_trees());
7634 // Now, even though child has zero opacity, we will configure |grandchild| and
7635 // |greatgrandchild| in several ways that should force the subtree to be
7636 // processed anyhow.
7637 ScopedPtrVector
<CopyOutputRequest
> requests
;
7638 requests
.push_back(CopyOutputRequest::CreateEmptyRequest());
7640 greatgrandchild_ptr
->PassCopyRequests(&requests
);
7641 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7642 EXPECT_EQ(gfx::Rect(10, 10),
7643 grandchild_ptr
->visible_rect_from_property_trees());
7646 TEST_F(LayerTreeHostCommonTest
, SkippingLayer
) {
7647 gfx::Transform identity
;
7648 FakeContentLayerClient client
;
7649 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7650 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7651 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7652 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7653 gfx::PointF(), gfx::Size(100, 100), true, false);
7654 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7655 gfx::PointF(), gfx::Size(10, 10), true, false);
7656 root
->AddChild(child
);
7658 host()->SetRootLayer(root
);
7660 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7661 EXPECT_EQ(gfx::Rect(10, 10), child
->visible_rect_from_property_trees());
7662 child
->set_visible_rect_from_property_trees(gfx::Rect());
7664 child
->SetHideLayerAndSubtree(true);
7665 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7666 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7667 child
->SetHideLayerAndSubtree(false);
7669 child
->SetBounds(gfx::Size());
7670 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7671 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7672 child
->SetBounds(gfx::Size(10, 10));
7674 gfx::Transform rotate
;
7675 child
->SetDoubleSided(false);
7676 rotate
.RotateAboutXAxis(180.f
);
7677 child
->SetTransform(rotate
);
7678 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7679 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7680 child
->SetDoubleSided(true);
7681 child
->SetTransform(identity
);
7683 child
->SetOpacity(0.f
);
7684 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7685 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
7688 TEST_F(LayerTreeHostCommonTest
, LayerTreeRebuildTest
) {
7689 // Ensure that the treewalk in LayerTreeHostCommom::
7690 // PreCalculateMetaInformation happens when its required.
7691 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7692 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
7693 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7695 root
->AddChild(parent
);
7696 parent
->AddChild(child
);
7698 child
->SetClipParent(root
.get());
7700 gfx::Transform identity
;
7702 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7703 gfx::PointF(), gfx::Size(100, 100), true, false);
7704 SetLayerPropertiesForTesting(parent
.get(), identity
, gfx::Point3F(),
7705 gfx::PointF(), gfx::Size(100, 100), true, false);
7706 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7707 gfx::PointF(), gfx::Size(100, 100), true, false);
7709 host()->SetRootLayer(root
);
7711 ExecuteCalculateDrawProperties(root
.get());
7712 EXPECT_EQ(parent
->num_unclipped_descendants(), 1u);
7714 child
->RequestCopyOfOutput(
7715 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
7716 EXPECT_GT(root
->num_layer_or_descendants_with_copy_request(), 0);
7717 ExecuteCalculateDrawProperties(root
.get());
7718 EXPECT_GT(root
->num_layer_or_descendants_with_copy_request(), 0);
7721 TEST_F(LayerTreeHostCommonTest
, InputHandlersRecursiveUpdateTest
) {
7722 // Ensure that the treewalk in LayertreeHostCommon::
7723 // PreCalculateMetaInformation updates input handlers correctly.
7724 LayerImpl
* root
= root_layer();
7725 LayerImpl
* child
= AddChild
<LayerImpl
>(root
);
7727 gfx::Transform identity
;
7729 SetLayerPropertiesForTesting(root
, identity
, gfx::Point3F(), gfx::PointF(),
7730 gfx::Size(100, 100), true, false, true);
7731 SetLayerPropertiesForTesting(child
, identity
, gfx::Point3F(), gfx::PointF(),
7732 gfx::Size(100, 100), true, false, false);
7734 EXPECT_EQ(root
->draw_properties().layer_or_descendant_has_input_handler
,
7737 child
->SetHaveWheelEventHandlers(true);
7738 ExecuteCalculateDrawProperties(root
);
7739 EXPECT_EQ(root
->draw_properties().layer_or_descendant_has_input_handler
,
7742 child
->SetHaveWheelEventHandlers(false);
7743 ExecuteCalculateDrawProperties(root
);
7744 EXPECT_EQ(root
->draw_properties().layer_or_descendant_has_input_handler
,
7748 TEST_F(LayerTreeHostCommonTest
, ResetPropertyTreeIndices
) {
7749 gfx::Transform identity
;
7750 gfx::Transform translate_z
;
7751 translate_z
.Translate3d(0, 0, 10);
7753 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7754 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7755 gfx::PointF(), gfx::Size(800, 800), true, false);
7757 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7758 SetLayerPropertiesForTesting(child
.get(), translate_z
, gfx::Point3F(),
7759 gfx::PointF(), gfx::Size(100, 100), true, false);
7761 root
->AddChild(child
);
7763 host()->SetRootLayer(root
);
7765 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7766 EXPECT_NE(-1, child
->transform_tree_index());
7768 child
->RemoveFromParent();
7770 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
7771 EXPECT_EQ(-1, child
->transform_tree_index());
7774 TEST_F(LayerTreeHostCommonTest
, ResetLayerDrawPropertiestest
) {
7775 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7776 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
7778 root
->AddChild(child
);
7779 gfx::Transform identity
;
7781 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
7782 gfx::PointF(), gfx::Size(100, 100), true, false);
7783 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
7784 gfx::PointF(), gfx::Size(100, 100), true, false);
7786 host()->SetRootLayer(root
);
7788 EXPECT_FALSE(root
->layer_or_descendant_is_drawn());
7789 EXPECT_FALSE(root
->visited());
7790 EXPECT_FALSE(root
->sorted_for_recursion());
7791 EXPECT_FALSE(child
->layer_or_descendant_is_drawn());
7792 EXPECT_FALSE(child
->visited());
7793 EXPECT_FALSE(child
->sorted_for_recursion());
7795 root
->set_layer_or_descendant_is_drawn(true);
7796 root
->set_visited(true);
7797 root
->set_sorted_for_recursion(true);
7798 child
->set_layer_or_descendant_is_drawn(true);
7799 child
->set_visited(true);
7800 child
->set_sorted_for_recursion(true);
7802 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root
.get());
7804 EXPECT_FALSE(root
->layer_or_descendant_is_drawn());
7805 EXPECT_FALSE(root
->visited());
7806 EXPECT_FALSE(root
->sorted_for_recursion());
7807 EXPECT_FALSE(child
->layer_or_descendant_is_drawn());
7808 EXPECT_FALSE(child
->visited());
7809 EXPECT_FALSE(child
->sorted_for_recursion());
7812 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceClipsSubtree
) {
7813 // Ensure that a Clip Node is added when a render surface applies clip.
7814 LayerImpl
* root
= root_layer();
7815 LayerImpl
* significant_transform
= AddChildToRoot
<LayerImpl
>();
7816 LayerImpl
* layer_clips_subtree
= AddChild
<LayerImpl
>(significant_transform
);
7817 LayerImpl
* render_surface
= AddChild
<LayerImpl
>(layer_clips_subtree
);
7818 LayerImpl
* test_layer
= AddChild
<LayerImpl
>(render_surface
);
7820 const gfx::Transform identity_matrix
;
7821 // This transform should be a significant one so that a transform node is
7823 gfx::Transform transform1
;
7824 transform1
.RotateAboutYAxis(45);
7825 transform1
.RotateAboutXAxis(30);
7826 // This transform should be a 3d transform as we want the render surface
7827 // to flatten the transform
7828 gfx::Transform transform2
;
7829 transform2
.Translate3d(10, 10, 10);
7831 layer_clips_subtree
->SetMasksToBounds(true);
7832 test_layer
->SetDrawsContent(true);
7834 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
7835 gfx::PointF(), gfx::Size(30, 30), true, false,
7837 SetLayerPropertiesForTesting(significant_transform
, transform1
,
7838 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7839 true, false, false);
7840 SetLayerPropertiesForTesting(layer_clips_subtree
, identity_matrix
,
7841 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7842 true, false, false);
7843 SetLayerPropertiesForTesting(render_surface
, transform2
, gfx::Point3F(),
7844 gfx::PointF(), gfx::Size(30, 30), true, false,
7846 SetLayerPropertiesForTesting(test_layer
, identity_matrix
, gfx::Point3F(),
7847 gfx::PointF(), gfx::Size(30, 30), true, false,
7850 ExecuteCalculateDrawProperties(root
);
7852 TransformTree transform_tree
=
7853 root
->layer_tree_impl()->property_trees()->transform_tree
;
7854 TransformNode
* transform_node
=
7855 transform_tree
.Node(significant_transform
->transform_tree_index());
7856 EXPECT_EQ(transform_node
->owner_id
, significant_transform
->id());
7858 ClipTree clip_tree
= root
->layer_tree_impl()->property_trees()->clip_tree
;
7859 ClipNode
* clip_node
= clip_tree
.Node(render_surface
->clip_tree_index());
7860 EXPECT_TRUE(clip_node
->data
.inherit_parent_target_space_clip
);
7861 EXPECT_EQ(gfx::Rect(30, 21), test_layer
->visible_rect_from_property_trees());
7864 TEST_F(LayerTreeHostCommonTest
, TransformOfParentClipNodeAncestorOfTarget
) {
7865 // Ensure that when parent clip node's transform is an ancestor of current
7866 // clip node's target, clip is 'projected' from parent space to current
7867 // target space and visible rects are calculated correctly.
7868 LayerImpl
* root
= root_layer();
7869 LayerImpl
* clip_layer
= AddChild
<LayerImpl
>(root
);
7870 LayerImpl
* target_layer
= AddChild
<LayerImpl
>(clip_layer
);
7871 LayerImpl
* test_layer
= AddChild
<LayerImpl
>(target_layer
);
7873 const gfx::Transform identity_matrix
;
7874 gfx::Transform transform
;
7875 transform
.RotateAboutYAxis(45);
7876 clip_layer
->SetMasksToBounds(true);
7877 target_layer
->SetMasksToBounds(true);
7878 test_layer
->SetDrawsContent(true);
7880 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
7881 gfx::PointF(), gfx::Size(30, 30), true, false,
7883 SetLayerPropertiesForTesting(clip_layer
, transform
, gfx::Point3F(),
7884 gfx::PointF(), gfx::Size(30, 30), true, false,
7886 SetLayerPropertiesForTesting(target_layer
, transform
, gfx::Point3F(),
7887 gfx::PointF(), gfx::Size(30, 30), true, false,
7889 SetLayerPropertiesForTesting(test_layer
, identity_matrix
, gfx::Point3F(),
7890 gfx::PointF(), gfx::Size(30, 30), true, false,
7892 ExecuteCalculateDrawProperties(root
);
7894 ClipTree clip_tree
= root
->layer_tree_impl()->property_trees()->clip_tree
;
7895 ClipNode
* clip_node
= clip_tree
.Node(target_layer
->clip_tree_index());
7896 EXPECT_EQ(gfx::RectF(30, 30), clip_node
->data
.combined_clip
);
7897 EXPECT_EQ(gfx::Rect(30, 30), test_layer
->visible_rect_from_property_trees());
7900 TEST_F(LayerTreeHostCommonTest
,
7901 RenderSurfaceWithUnclippedDescendantsClipsSubtree
) {
7902 // Ensure clip rect is calculated correctly when render surface has unclipped
7904 LayerImpl
* root
= root_layer();
7905 LayerImpl
* clip_parent
= AddChildToRoot
<LayerImpl
>();
7906 LayerImpl
* between_clip_parent_and_child
= AddChild
<LayerImpl
>(clip_parent
);
7907 LayerImpl
* render_surface
=
7908 AddChild
<LayerImpl
>(between_clip_parent_and_child
);
7909 LayerImpl
* test_layer
= AddChild
<LayerImpl
>(render_surface
);
7911 const gfx::Transform identity_matrix
;
7912 gfx::Transform transform
;
7913 transform
.Translate(2.0, 2.0);
7915 test_layer
->SetDrawsContent(true);
7916 render_surface
->SetClipParent(clip_parent
);
7917 scoped_ptr
<std::set
<LayerImpl
*>> clip_children(new std::set
<LayerImpl
*>);
7918 clip_children
->insert(render_surface
);
7919 clip_parent
->SetClipChildren(clip_children
.release());
7920 SetLayerPropertiesForTesting(root
, identity_matrix
, gfx::Point3F(),
7921 gfx::PointF(), gfx::Size(30, 30), true, false,
7923 SetLayerPropertiesForTesting(clip_parent
, transform
, gfx::Point3F(),
7924 gfx::PointF(), gfx::Size(30, 30), true, false,
7926 SetLayerPropertiesForTesting(between_clip_parent_and_child
, transform
,
7927 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7928 true, false, false);
7929 SetLayerPropertiesForTesting(render_surface
, identity_matrix
, gfx::Point3F(),
7930 gfx::PointF(), gfx::Size(30, 30), true, false,
7932 SetLayerPropertiesForTesting(test_layer
, identity_matrix
, gfx::Point3F(),
7933 gfx::PointF(), gfx::Size(30, 30), true, false,
7936 ExecuteCalculateDrawProperties(root
);
7938 EXPECT_EQ(gfx::Rect(30, 30), test_layer
->clip_rect());