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/layer_animation_controller.h"
11 #include "cc/animation/transform_operations.h"
12 #include "cc/base/math_util.h"
13 #include "cc/layers/content_layer.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.h"
20 #include "cc/layers/render_surface_impl.h"
21 #include "cc/output/copy_output_request.h"
22 #include "cc/output/copy_output_result.h"
23 #include "cc/test/animation_test_common.h"
24 #include "cc/test/fake_content_layer.h"
25 #include "cc/test/fake_content_layer_client.h"
26 #include "cc/test/fake_content_layer_impl.h"
27 #include "cc/test/fake_impl_proxy.h"
28 #include "cc/test/fake_layer_tree_host.h"
29 #include "cc/test/fake_layer_tree_host_impl.h"
30 #include "cc/test/fake_picture_layer.h"
31 #include "cc/test/fake_picture_layer_impl.h"
32 #include "cc/test/geometry_test_utils.h"
33 #include "cc/test/layer_tree_host_common_test.h"
34 #include "cc/test/test_task_graph_runner.h"
35 #include "cc/trees/layer_tree_impl.h"
36 #include "cc/trees/proxy.h"
37 #include "cc/trees/single_thread_proxy.h"
38 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h"
40 #include "ui/gfx/geometry/quad_f.h"
41 #include "ui/gfx/geometry/vector2d_conversions.h"
42 #include "ui/gfx/transform.h"
47 class LayerWithForcedDrawsContent
: public Layer
{
49 explicit LayerWithForcedDrawsContent(const LayerSettings
& settings
)
52 bool DrawsContent() const override
;
55 ~LayerWithForcedDrawsContent() override
{}
58 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
60 class MockContentLayerClient
: public ContentLayerClient
{
62 MockContentLayerClient() {}
63 ~MockContentLayerClient() override
{}
64 void PaintContents(SkCanvas
* canvas
,
65 const gfx::Rect
& clip
,
66 PaintingControlSetting picture_control
) override
{}
67 void PaintContentsToDisplayList(
68 DisplayItemList
* display_list
,
69 const gfx::Rect
& clip
,
70 PaintingControlSetting picture_control
) override
{
73 bool FillsBoundsCompletely() const override
{ return false; }
76 scoped_refptr
<FakePictureLayer
> CreateDrawablePictureLayer(
77 const LayerSettings
& settings
,
78 ContentLayerClient
* delegate
) {
79 scoped_refptr
<FakePictureLayer
> to_return
=
80 FakePictureLayer::Create(settings
, delegate
);
81 to_return
->SetIsDrawable(true);
85 scoped_refptr
<ContentLayer
> CreateDrawableContentLayer(
86 const LayerSettings
& settings
,
87 ContentLayerClient
* delegate
) {
88 scoped_refptr
<ContentLayer
> to_return
=
89 ContentLayer::Create(settings
, delegate
);
90 to_return
->SetIsDrawable(true);
94 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
96 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
97 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
100 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
102 EXPECT_FLOAT_EQ(expected, layer->draw_properties().ideal_contents_scale); \
105 TEST_F(LayerTreeHostCommonTest
, TransformsForNoOpLayer
) {
106 // Sanity check: For layers positioned at zero, with zero size,
107 // and with identity transforms, then the draw transform,
108 // screen space transform, and the hierarchy passed on to children
109 // layers should also be identity transforms.
111 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
112 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
113 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
114 parent
->AddChild(child
);
115 child
->AddChild(grand_child
);
117 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
118 host
->SetRootLayer(parent
);
120 gfx::Transform identity_matrix
;
121 SetLayerPropertiesForTesting(parent
.get(),
128 SetLayerPropertiesForTesting(child
.get(),
135 SetLayerPropertiesForTesting(grand_child
.get(),
143 ExecuteCalculateDrawProperties(parent
.get());
145 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
146 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
147 child
->screen_space_transform());
148 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
149 grand_child
->draw_transform());
150 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
151 grand_child
->screen_space_transform());
154 TEST_F(LayerTreeHostCommonTest
, DoNotSkipLayersWithHandlers
) {
155 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
156 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
157 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
158 parent
->AddChild(child
);
159 child
->AddChild(grand_child
);
161 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
162 host
->SetRootLayer(parent
);
164 gfx::Transform identity_matrix
;
165 SetLayerPropertiesForTesting(parent
.get(),
172 SetLayerPropertiesForTesting(child
.get(),
179 // This would have previously caused us to skip our subtree, but this would be
180 // wrong; we need up-to-date draw properties to do hit testing on the layers
182 child
->SetOpacity(0.f
);
183 SetLayerPropertiesForTesting(grand_child
.get(),
190 grand_child
->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
192 ExecuteCalculateDrawProperties(parent
.get());
194 // Check that we've computed draw properties for the subtree rooted at
196 EXPECT_FALSE(child
->draw_transform().IsIdentity());
197 EXPECT_FALSE(grand_child
->draw_transform().IsIdentity());
200 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleLayer
) {
201 gfx::Transform identity_matrix
;
202 scoped_refptr
<Layer
> layer
= Layer::Create(layer_settings());
204 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
205 SetLayerPropertiesForTesting(root
.get(),
212 root
->AddChild(layer
);
214 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
215 host
->SetRootLayer(root
);
217 // Case 2: Setting the bounds of the layer should not affect either the draw
218 // transform or the screenspace transform.
219 gfx::Transform translation_to_center
;
220 translation_to_center
.Translate(5.0, 6.0);
221 SetLayerPropertiesForTesting(layer
.get(),
228 ExecuteCalculateDrawProperties(root
.get());
229 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
230 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
231 layer
->screen_space_transform());
233 // Case 3: The anchor point by itself (without a layer transform) should have
234 // no effect on the transforms.
235 SetLayerPropertiesForTesting(layer
.get(),
237 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
242 ExecuteCalculateDrawProperties(root
.get());
243 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
244 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
245 layer
->screen_space_transform());
247 // Case 4: A change in actual position affects both the draw transform and
248 // screen space transform.
249 gfx::Transform position_transform
;
250 position_transform
.Translate(0.f
, 1.2f
);
251 SetLayerPropertiesForTesting(layer
.get(),
253 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
254 gfx::PointF(0.f
, 1.2f
),
258 ExecuteCalculateDrawProperties(root
.get());
259 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
, layer
->draw_transform());
260 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
,
261 layer
->screen_space_transform());
263 // Case 5: In the correct sequence of transforms, the layer transform should
264 // pre-multiply the translation_to_center. This is easily tested by using a
265 // scale transform, because scale and translation are not commutative.
266 gfx::Transform layer_transform
;
267 layer_transform
.Scale3d(2.0, 2.0, 1.0);
268 SetLayerPropertiesForTesting(layer
.get(),
275 ExecuteCalculateDrawProperties(root
.get());
276 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
, layer
->draw_transform());
277 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
,
278 layer
->screen_space_transform());
280 // Case 6: The layer transform should occur with respect to the anchor point.
281 gfx::Transform translation_to_anchor
;
282 translation_to_anchor
.Translate(5.0, 0.0);
283 gfx::Transform expected_result
=
284 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
285 SetLayerPropertiesForTesting(layer
.get(),
287 gfx::Point3F(5.0f
, 0.f
, 0.f
),
292 ExecuteCalculateDrawProperties(root
.get());
293 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
294 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
295 layer
->screen_space_transform());
297 // Case 7: Verify that position pre-multiplies the layer transform. The
298 // current implementation of CalculateDrawProperties does this implicitly, but
299 // it is still worth testing to detect accidental regressions.
300 expected_result
= position_transform
* translation_to_anchor
*
301 layer_transform
* Inverse(translation_to_anchor
);
302 SetLayerPropertiesForTesting(layer
.get(),
304 gfx::Point3F(5.0f
, 0.f
, 0.f
),
305 gfx::PointF(0.f
, 1.2f
),
309 ExecuteCalculateDrawProperties(root
.get());
310 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
311 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
312 layer
->screen_space_transform());
315 TEST_F(LayerTreeHostCommonTest
, TransformsAboutScrollOffset
) {
316 const gfx::ScrollOffset
kScrollOffset(50, 100);
317 const gfx::Vector2dF
kScrollDelta(2.34f
, 5.67f
);
318 const gfx::Vector2d
kMaxScrollOffset(200, 200);
319 const gfx::PointF
kScrollLayerPosition(-kScrollOffset
.x(),
321 const float kPageScale
= 0.888f
;
322 const float kDeviceScale
= 1.666f
;
325 TestSharedBitmapManager shared_bitmap_manager
;
326 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
328 gfx::Transform identity_matrix
;
329 scoped_ptr
<LayerImpl
> sublayer_scoped_ptr(
330 LayerImpl::Create(host_impl
.active_tree(), 1));
331 LayerImpl
* sublayer
= sublayer_scoped_ptr
.get();
332 sublayer
->SetContentsScale(kPageScale
* kDeviceScale
,
333 kPageScale
* kDeviceScale
);
334 SetLayerPropertiesForTesting(sublayer
, identity_matrix
, gfx::Point3F(),
335 gfx::PointF(), gfx::Size(500, 500), true, false,
338 scoped_ptr
<LayerImpl
> scroll_layer_scoped_ptr(
339 LayerImpl::Create(host_impl
.active_tree(), 2));
340 LayerImpl
* scroll_layer
= scroll_layer_scoped_ptr
.get();
341 SetLayerPropertiesForTesting(scroll_layer
, identity_matrix
, gfx::Point3F(),
342 gfx::PointF(), gfx::Size(10, 20), true, false,
344 scoped_ptr
<LayerImpl
> clip_layer_scoped_ptr(
345 LayerImpl::Create(host_impl
.active_tree(), 4));
346 LayerImpl
* clip_layer
= clip_layer_scoped_ptr
.get();
348 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
349 clip_layer
->SetBounds(
350 gfx::Size(scroll_layer
->bounds().width() + kMaxScrollOffset
.x(),
351 scroll_layer
->bounds().height() + kMaxScrollOffset
.y()));
352 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
353 scroll_layer
->SetScrollDelta(kScrollDelta
);
354 gfx::Transform impl_transform
;
355 scroll_layer
->AddChild(sublayer_scoped_ptr
.Pass());
356 LayerImpl
* scroll_layer_raw_ptr
= scroll_layer_scoped_ptr
.get();
357 clip_layer
->AddChild(scroll_layer_scoped_ptr
.Pass());
358 scroll_layer_raw_ptr
->PushScrollOffsetFromMainThread(kScrollOffset
);
360 scoped_ptr
<LayerImpl
> root(LayerImpl::Create(host_impl
.active_tree(), 3));
361 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
362 gfx::PointF(), gfx::Size(3, 4), true, false,
364 root
->AddChild(clip_layer_scoped_ptr
.Pass());
365 root
->SetHasRenderSurface(true);
367 ExecuteCalculateDrawProperties(
368 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
369 gfx::Transform expected_transform
= identity_matrix
;
370 gfx::PointF sub_layer_screen_position
= kScrollLayerPosition
- kScrollDelta
;
371 sub_layer_screen_position
.Scale(kPageScale
* kDeviceScale
);
372 expected_transform
.Translate(MathUtil::Round(sub_layer_screen_position
.x()),
373 MathUtil::Round(sub_layer_screen_position
.y()));
374 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
375 sublayer
->draw_transform());
376 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
377 sublayer
->screen_space_transform());
379 gfx::Transform arbitrary_translate
;
380 const float kTranslateX
= 10.6f
;
381 const float kTranslateY
= 20.6f
;
382 arbitrary_translate
.Translate(kTranslateX
, kTranslateY
);
383 SetLayerPropertiesForTesting(scroll_layer
, arbitrary_translate
,
384 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
386 ExecuteCalculateDrawProperties(
387 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
388 expected_transform
.MakeIdentity();
389 expected_transform
.Translate(
390 MathUtil::Round(kTranslateX
* kPageScale
* kDeviceScale
+
391 sub_layer_screen_position
.x()),
392 MathUtil::Round(kTranslateY
* kPageScale
* kDeviceScale
+
393 sub_layer_screen_position
.y()));
394 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
395 sublayer
->draw_transform());
398 TEST_F(LayerTreeHostCommonTest
, TransformsForSimpleHierarchy
) {
399 gfx::Transform identity_matrix
;
400 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
401 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
402 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
403 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
404 root
->AddChild(parent
);
405 parent
->AddChild(child
);
406 child
->AddChild(grand_child
);
408 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
409 host
->SetRootLayer(root
);
411 // One-time setup of root layer
412 SetLayerPropertiesForTesting(root
.get(),
420 // Case 1: parent's anchor point should not affect child or grand_child.
421 SetLayerPropertiesForTesting(parent
.get(),
423 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
428 SetLayerPropertiesForTesting(child
.get(),
435 SetLayerPropertiesForTesting(grand_child
.get(),
442 ExecuteCalculateDrawProperties(root
.get());
443 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
444 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
445 child
->screen_space_transform());
446 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
447 grand_child
->draw_transform());
448 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
449 grand_child
->screen_space_transform());
451 // Case 2: parent's position affects child and grand_child.
452 gfx::Transform parent_position_transform
;
453 parent_position_transform
.Translate(0.f
, 1.2f
);
454 SetLayerPropertiesForTesting(parent
.get(),
456 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
457 gfx::PointF(0.f
, 1.2f
),
461 SetLayerPropertiesForTesting(child
.get(),
468 SetLayerPropertiesForTesting(grand_child
.get(),
475 ExecuteCalculateDrawProperties(root
.get());
476 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
477 child
->draw_transform());
478 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
479 child
->screen_space_transform());
480 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
481 grand_child
->draw_transform());
482 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
483 grand_child
->screen_space_transform());
485 // Case 3: parent's local transform affects child and grandchild
486 gfx::Transform parent_layer_transform
;
487 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
488 gfx::Transform parent_translation_to_anchor
;
489 parent_translation_to_anchor
.Translate(2.5, 3.0);
490 gfx::Transform parent_composite_transform
=
491 parent_translation_to_anchor
* parent_layer_transform
*
492 Inverse(parent_translation_to_anchor
);
493 SetLayerPropertiesForTesting(parent
.get(),
494 parent_layer_transform
,
495 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
500 SetLayerPropertiesForTesting(child
.get(),
507 SetLayerPropertiesForTesting(grand_child
.get(),
514 ExecuteCalculateDrawProperties(root
.get());
515 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
516 child
->draw_transform());
517 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
518 child
->screen_space_transform());
519 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
520 grand_child
->draw_transform());
521 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
522 grand_child
->screen_space_transform());
525 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleRenderSurface
) {
526 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
527 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
528 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
529 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
530 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
531 root
->AddChild(parent
);
532 parent
->AddChild(child
);
533 child
->AddChild(grand_child
);
535 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
536 host
->SetRootLayer(root
);
538 // One-time setup of root layer
539 gfx::Transform identity_matrix
;
540 SetLayerPropertiesForTesting(root
.get(),
548 // Child is set up so that a new render surface should be created.
549 child
->SetOpacity(0.5f
);
550 child
->SetForceRenderSurface(true);
552 gfx::Transform parent_layer_transform
;
553 parent_layer_transform
.Scale3d(1.f
, 0.9f
, 1.f
);
554 gfx::Transform parent_translation_to_anchor
;
555 parent_translation_to_anchor
.Translate(25.0, 30.0);
557 gfx::Transform parent_composite_transform
=
558 parent_translation_to_anchor
* parent_layer_transform
*
559 Inverse(parent_translation_to_anchor
);
560 gfx::Vector2dF parent_composite_scale
=
561 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
563 gfx::Transform surface_sublayer_transform
;
564 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
565 parent_composite_scale
.y());
566 gfx::Transform surface_sublayer_composite_transform
=
567 parent_composite_transform
* Inverse(surface_sublayer_transform
);
569 // Child's render surface should not exist yet.
570 ASSERT_FALSE(child
->render_surface());
572 SetLayerPropertiesForTesting(parent
.get(),
573 parent_layer_transform
,
574 gfx::Point3F(25.0f
, 30.0f
, 0.f
),
579 SetLayerPropertiesForTesting(child
.get(),
586 SetLayerPropertiesForTesting(grand_child
.get(),
593 ExecuteCalculateDrawProperties(root
.get());
595 // Render surface should have been created now.
596 ASSERT_TRUE(child
->render_surface());
597 ASSERT_EQ(child
.get(), child
->render_target());
599 // The child layer's draw transform should refer to its new render surface.
600 // The screen-space transform, however, should still refer to the root.
601 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform
,
602 child
->draw_transform());
603 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
604 child
->screen_space_transform());
606 // Because the grand_child is the only drawable content, the child's render
607 // surface will tighten its bounds to the grand_child. The scale at which the
608 // surface's subtree is drawn must be removed from the composite transform.
609 EXPECT_TRANSFORMATION_MATRIX_EQ(
610 surface_sublayer_composite_transform
,
611 child
->render_target()->render_surface()->draw_transform());
613 // The screen space is the same as the target since the child surface draws
615 EXPECT_TRANSFORMATION_MATRIX_EQ(
616 surface_sublayer_composite_transform
,
617 child
->render_target()->render_surface()->screen_space_transform());
620 TEST_F(LayerTreeHostCommonTest
, TransformsForReplica
) {
621 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
622 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
623 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
624 scoped_refptr
<Layer
> child_replica
= Layer::Create(layer_settings());
625 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
626 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
627 root
->AddChild(parent
);
628 parent
->AddChild(child
);
629 child
->AddChild(grand_child
);
630 child
->SetReplicaLayer(child_replica
.get());
632 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
633 host
->SetRootLayer(root
);
635 // One-time setup of root layer
636 gfx::Transform identity_matrix
;
637 SetLayerPropertiesForTesting(root
.get(),
645 // Child is set up so that a new render surface should be created.
646 child
->SetOpacity(0.5f
);
648 gfx::Transform parent_layer_transform
;
649 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
650 gfx::Transform parent_translation_to_anchor
;
651 parent_translation_to_anchor
.Translate(2.5, 3.0);
652 gfx::Transform parent_composite_transform
=
653 parent_translation_to_anchor
* parent_layer_transform
*
654 Inverse(parent_translation_to_anchor
);
655 gfx::Transform replica_layer_transform
;
656 replica_layer_transform
.Scale3d(3.0, 3.0, 1.0);
657 gfx::Vector2dF parent_composite_scale
=
658 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
660 gfx::Transform surface_sublayer_transform
;
661 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
662 parent_composite_scale
.y());
663 gfx::Transform replica_composite_transform
=
664 parent_composite_transform
* replica_layer_transform
*
665 Inverse(surface_sublayer_transform
);
666 child_replica
->SetIsDrawable(true);
667 // Child's render surface should not exist yet.
668 ASSERT_FALSE(child
->render_surface());
670 SetLayerPropertiesForTesting(parent
.get(),
671 parent_layer_transform
,
672 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
677 SetLayerPropertiesForTesting(child
.get(),
684 SetLayerPropertiesForTesting(grand_child
.get(),
687 gfx::PointF(-0.5f
, -0.5f
),
691 SetLayerPropertiesForTesting(child_replica
.get(),
692 replica_layer_transform
,
698 ExecuteCalculateDrawProperties(root
.get());
700 // Render surface should have been created now.
701 ASSERT_TRUE(child
->render_surface());
702 ASSERT_EQ(child
.get(), child
->render_target());
704 EXPECT_TRANSFORMATION_MATRIX_EQ(
705 replica_composite_transform
,
706 child
->render_target()->render_surface()->replica_draw_transform());
707 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform
,
708 child
->render_target()
710 ->replica_screen_space_transform());
713 TEST_F(LayerTreeHostCommonTest
, TransformsForRenderSurfaceHierarchy
) {
714 // This test creates a more complex tree and verifies it all at once. This
715 // covers the following cases:
716 // - layers that are described w.r.t. a render surface: should have draw
717 // transforms described w.r.t. that surface
718 // - A render surface described w.r.t. an ancestor render surface: should
719 // have a draw transform described w.r.t. that ancestor surface
720 // - Replicas of a render surface are described w.r.t. the replica's
721 // transform around its anchor, along with the surface itself.
722 // - Sanity check on recursion: verify transforms of layers described w.r.t.
723 // a render surface that is described w.r.t. an ancestor render surface.
724 // - verifying that each layer has a reference to the correct render surface
725 // and render target values.
727 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
728 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
729 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
730 scoped_refptr
<Layer
> render_surface2
= Layer::Create(layer_settings());
731 scoped_refptr
<Layer
> child_of_root
= Layer::Create(layer_settings());
732 scoped_refptr
<Layer
> child_of_rs1
= Layer::Create(layer_settings());
733 scoped_refptr
<Layer
> child_of_rs2
= Layer::Create(layer_settings());
734 scoped_refptr
<Layer
> replica_of_rs1
= Layer::Create(layer_settings());
735 scoped_refptr
<Layer
> replica_of_rs2
= Layer::Create(layer_settings());
736 scoped_refptr
<Layer
> grand_child_of_root
= Layer::Create(layer_settings());
737 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs1
=
738 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
739 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs2
=
740 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
741 root
->AddChild(parent
);
742 parent
->AddChild(render_surface1
);
743 parent
->AddChild(child_of_root
);
744 render_surface1
->AddChild(child_of_rs1
);
745 render_surface1
->AddChild(render_surface2
);
746 render_surface2
->AddChild(child_of_rs2
);
747 child_of_root
->AddChild(grand_child_of_root
);
748 child_of_rs1
->AddChild(grand_child_of_rs1
);
749 child_of_rs2
->AddChild(grand_child_of_rs2
);
750 render_surface1
->SetReplicaLayer(replica_of_rs1
.get());
751 render_surface2
->SetReplicaLayer(replica_of_rs2
.get());
753 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
754 host
->SetRootLayer(root
);
756 // In combination with descendant draws content, opacity != 1 forces the layer
757 // to have a new render surface.
758 render_surface1
->SetOpacity(0.5f
);
759 render_surface2
->SetOpacity(0.33f
);
761 // One-time setup of root layer
762 gfx::Transform identity_matrix
;
763 SetLayerPropertiesForTesting(root
.get(),
771 // All layers in the tree are initialized with an anchor at .25 and a size of
772 // (10,10). matrix "A" is the composite layer transform used in all layers,
773 // Matrix "R" is the composite replica transform used in all replica layers.
774 gfx::Transform translation_to_anchor
;
775 translation_to_anchor
.Translate(2.5, 0.0);
776 gfx::Transform layer_transform
;
777 layer_transform
.Translate(1.0, 1.0);
778 gfx::Transform replica_layer_transform
;
779 replica_layer_transform
.Scale3d(-2.0, 5.0, 1.0);
782 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
783 gfx::Transform R
= A
* translation_to_anchor
* replica_layer_transform
*
784 Inverse(translation_to_anchor
);
786 gfx::Vector2dF surface1_parent_transform_scale
=
787 MathUtil::ComputeTransform2dScaleComponents(A
, 1.f
);
788 gfx::Transform surface1_sublayer_transform
;
789 surface1_sublayer_transform
.Scale(surface1_parent_transform_scale
.x(),
790 surface1_parent_transform_scale
.y());
792 // SS1 = transform given to the subtree of render_surface1
793 gfx::Transform SS1
= surface1_sublayer_transform
;
794 // S1 = transform to move from render_surface1 pixels to the layer space of
796 gfx::Transform S1
= Inverse(surface1_sublayer_transform
);
798 gfx::Vector2dF surface2_parent_transform_scale
=
799 MathUtil::ComputeTransform2dScaleComponents(SS1
* A
, 1.f
);
800 gfx::Transform surface2_sublayer_transform
;
801 surface2_sublayer_transform
.Scale(surface2_parent_transform_scale
.x(),
802 surface2_parent_transform_scale
.y());
804 // SS2 = transform given to the subtree of render_surface2
805 gfx::Transform SS2
= surface2_sublayer_transform
;
806 // S2 = transform to move from render_surface2 pixels to the layer space of
808 gfx::Transform S2
= Inverse(surface2_sublayer_transform
);
810 SetLayerPropertiesForTesting(parent
.get(),
812 gfx::Point3F(2.5f
, 0.f
, 0.f
),
817 SetLayerPropertiesForTesting(render_surface1
.get(),
819 gfx::Point3F(2.5f
, 0.f
, 0.f
),
824 SetLayerPropertiesForTesting(render_surface2
.get(),
826 gfx::Point3F(2.5f
, 0.f
, 0.f
),
831 SetLayerPropertiesForTesting(child_of_root
.get(),
833 gfx::Point3F(2.5f
, 0.f
, 0.f
),
838 SetLayerPropertiesForTesting(child_of_rs1
.get(),
840 gfx::Point3F(2.5f
, 0.f
, 0.f
),
845 SetLayerPropertiesForTesting(child_of_rs2
.get(),
847 gfx::Point3F(2.5f
, 0.f
, 0.f
),
852 SetLayerPropertiesForTesting(grand_child_of_root
.get(),
854 gfx::Point3F(2.5f
, 0.f
, 0.f
),
859 SetLayerPropertiesForTesting(grand_child_of_rs1
.get(),
861 gfx::Point3F(2.5f
, 0.f
, 0.f
),
866 SetLayerPropertiesForTesting(grand_child_of_rs2
.get(),
868 gfx::Point3F(2.5f
, 0.f
, 0.f
),
873 SetLayerPropertiesForTesting(replica_of_rs1
.get(),
874 replica_layer_transform
,
875 gfx::Point3F(2.5f
, 0.f
, 0.f
),
880 SetLayerPropertiesForTesting(replica_of_rs2
.get(),
881 replica_layer_transform
,
882 gfx::Point3F(2.5f
, 0.f
, 0.f
),
888 ExecuteCalculateDrawProperties(root
.get());
890 // Only layers that are associated with render surfaces should have an actual
891 // RenderSurface() value.
892 ASSERT_TRUE(root
->render_surface());
893 ASSERT_FALSE(child_of_root
->render_surface());
894 ASSERT_FALSE(grand_child_of_root
->render_surface());
896 ASSERT_TRUE(render_surface1
->render_surface());
897 ASSERT_FALSE(child_of_rs1
->render_surface());
898 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
900 ASSERT_TRUE(render_surface2
->render_surface());
901 ASSERT_FALSE(child_of_rs2
->render_surface());
902 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
904 // Verify all render target accessors
905 EXPECT_EQ(root
.get(), parent
->render_target());
906 EXPECT_EQ(root
.get(), child_of_root
->render_target());
907 EXPECT_EQ(root
.get(), grand_child_of_root
->render_target());
909 EXPECT_EQ(render_surface1
.get(), render_surface1
->render_target());
910 EXPECT_EQ(render_surface1
.get(), child_of_rs1
->render_target());
911 EXPECT_EQ(render_surface1
.get(), grand_child_of_rs1
->render_target());
913 EXPECT_EQ(render_surface2
.get(), render_surface2
->render_target());
914 EXPECT_EQ(render_surface2
.get(), child_of_rs2
->render_target());
915 EXPECT_EQ(render_surface2
.get(), grand_child_of_rs2
->render_target());
917 // Verify layer draw transforms note that draw transforms are described with
918 // respect to the nearest ancestor render surface but screen space transforms
919 // are described with respect to the root.
920 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->draw_transform());
921 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
, child_of_root
->draw_transform());
922 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
923 grand_child_of_root
->draw_transform());
925 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
, render_surface1
->draw_transform());
926 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
, child_of_rs1
->draw_transform());
927 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
* A
,
928 grand_child_of_rs1
->draw_transform());
930 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
, render_surface2
->draw_transform());
931 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
, child_of_rs2
->draw_transform());
932 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
* A
,
933 grand_child_of_rs2
->draw_transform());
935 // Verify layer screen-space transforms
937 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->screen_space_transform());
938 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
939 child_of_root
->screen_space_transform());
940 EXPECT_TRANSFORMATION_MATRIX_EQ(
941 A
* A
* A
, grand_child_of_root
->screen_space_transform());
943 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
944 render_surface1
->screen_space_transform());
945 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
946 child_of_rs1
->screen_space_transform());
947 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
948 grand_child_of_rs1
->screen_space_transform());
950 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
951 render_surface2
->screen_space_transform());
952 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
953 child_of_rs2
->screen_space_transform());
954 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
* A
,
955 grand_child_of_rs2
->screen_space_transform());
957 // Verify render surface transforms.
959 // Draw transform of render surface 1 is described with respect to root.
960 EXPECT_TRANSFORMATION_MATRIX_EQ(
961 A
* A
* S1
, render_surface1
->render_surface()->draw_transform());
962 EXPECT_TRANSFORMATION_MATRIX_EQ(
963 A
* R
* S1
, render_surface1
->render_surface()->replica_draw_transform());
964 EXPECT_TRANSFORMATION_MATRIX_EQ(
965 A
* A
* S1
, render_surface1
->render_surface()->screen_space_transform());
966 EXPECT_TRANSFORMATION_MATRIX_EQ(
968 render_surface1
->render_surface()->replica_screen_space_transform());
969 // Draw transform of render surface 2 is described with respect to render
971 EXPECT_TRANSFORMATION_MATRIX_EQ(
972 SS1
* A
* S2
, render_surface2
->render_surface()->draw_transform());
973 EXPECT_TRANSFORMATION_MATRIX_EQ(
975 render_surface2
->render_surface()->replica_draw_transform());
976 EXPECT_TRANSFORMATION_MATRIX_EQ(
978 render_surface2
->render_surface()->screen_space_transform());
979 EXPECT_TRANSFORMATION_MATRIX_EQ(
981 render_surface2
->render_surface()->replica_screen_space_transform());
983 // Sanity check. If these fail there is probably a bug in the test itself. It
984 // is expected that we correctly set up transforms so that the y-component of
985 // the screen-space transform encodes the "depth" of the layer in the tree.
986 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
988 child_of_root
->screen_space_transform().matrix().get(1, 3));
990 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
993 render_surface1
->screen_space_transform().matrix().get(1, 3));
995 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
997 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
1000 render_surface2
->screen_space_transform().matrix().get(1, 3));
1001 EXPECT_FLOAT_EQ(4.0,
1002 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1004 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1007 TEST_F(LayerTreeHostCommonTest
, TransformsForFlatteningLayer
) {
1008 // For layers that flatten their subtree, there should be an orthographic
1009 // projection (for x and y values) in the middle of the transform sequence.
1010 // Note that the way the code is currently implemented, it is not expected to
1011 // use a canonical orthographic projection.
1013 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1014 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1015 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1016 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1017 scoped_refptr
<LayerWithForcedDrawsContent
> great_grand_child
=
1018 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1020 gfx::Transform rotation_about_y_axis
;
1021 rotation_about_y_axis
.RotateAboutYAxis(30.0);
1023 const gfx::Transform identity_matrix
;
1024 SetLayerPropertiesForTesting(root
.get(),
1028 gfx::Size(100, 100),
1031 SetLayerPropertiesForTesting(child
.get(),
1032 rotation_about_y_axis
,
1038 SetLayerPropertiesForTesting(grand_child
.get(),
1039 rotation_about_y_axis
,
1045 SetLayerPropertiesForTesting(great_grand_child
.get(), identity_matrix
,
1046 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1049 root
->AddChild(child
);
1050 child
->AddChild(grand_child
);
1051 grand_child
->AddChild(great_grand_child
);
1052 child
->SetForceRenderSurface(true);
1054 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1055 host
->SetRootLayer(root
);
1057 // No layers in this test should preserve 3d.
1058 ASSERT_TRUE(root
->should_flatten_transform());
1059 ASSERT_TRUE(child
->should_flatten_transform());
1060 ASSERT_TRUE(grand_child
->should_flatten_transform());
1061 ASSERT_TRUE(great_grand_child
->should_flatten_transform());
1063 gfx::Transform expected_child_draw_transform
= rotation_about_y_axis
;
1064 gfx::Transform expected_child_screen_space_transform
= rotation_about_y_axis
;
1065 gfx::Transform expected_grand_child_draw_transform
=
1066 rotation_about_y_axis
; // draws onto child's render surface
1067 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
1068 flattened_rotation_about_y
.FlattenTo2d();
1069 gfx::Transform expected_grand_child_screen_space_transform
=
1070 flattened_rotation_about_y
* rotation_about_y_axis
;
1071 gfx::Transform expected_great_grand_child_draw_transform
=
1072 flattened_rotation_about_y
;
1073 gfx::Transform expected_great_grand_child_screen_space_transform
=
1074 flattened_rotation_about_y
* flattened_rotation_about_y
;
1076 ExecuteCalculateDrawProperties(root
.get());
1078 // The child's draw transform should have been taken by its surface.
1079 ASSERT_TRUE(child
->render_surface());
1080 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform
,
1081 child
->render_surface()->draw_transform());
1082 EXPECT_TRANSFORMATION_MATRIX_EQ(
1083 expected_child_screen_space_transform
,
1084 child
->render_surface()->screen_space_transform());
1085 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1086 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform
,
1087 child
->screen_space_transform());
1088 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform
,
1089 grand_child
->draw_transform());
1090 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform
,
1091 grand_child
->screen_space_transform());
1092 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_draw_transform
,
1093 great_grand_child
->draw_transform());
1094 EXPECT_TRANSFORMATION_MATRIX_EQ(
1095 expected_great_grand_child_screen_space_transform
,
1096 great_grand_child
->screen_space_transform());
1099 TEST_F(LayerTreeHostCommonTest
, TransformsForDegenerateIntermediateLayer
) {
1100 // A layer that is empty in one axis, but not the other, was accidentally
1101 // skipping a necessary translation. Without that translation, the coordinate
1102 // space of the layer's draw transform is incorrect.
1104 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1105 // but if that layer becomes a render surface, then its draw transform is
1106 // implicitly inherited by the rest of the subtree, which then is positioned
1107 // incorrectly as a result.
1109 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1110 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1111 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1112 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1114 // The child height is zero, but has non-zero width that should be accounted
1115 // for while computing draw transforms.
1116 const gfx::Transform identity_matrix
;
1117 SetLayerPropertiesForTesting(root
.get(),
1121 gfx::Size(100, 100),
1124 SetLayerPropertiesForTesting(child
.get(),
1131 SetLayerPropertiesForTesting(grand_child
.get(),
1139 root
->AddChild(child
);
1140 child
->AddChild(grand_child
);
1141 child
->SetForceRenderSurface(true);
1143 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1144 host
->SetRootLayer(root
);
1146 ExecuteCalculateDrawProperties(root
.get());
1148 ASSERT_TRUE(child
->render_surface());
1149 // This is the real test, the rest are sanity checks.
1150 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1151 child
->render_surface()->draw_transform());
1152 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1153 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1154 grand_child
->draw_transform());
1157 TEST_F(LayerTreeHostCommonTest
, TransformAboveRootLayer
) {
1158 // Transformations applied at the root of the tree should be forwarded
1159 // to child layers instead of applied to the root RenderSurface.
1160 const gfx::Transform identity_matrix
;
1161 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
1162 new LayerWithForcedDrawsContent(layer_settings());
1163 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1164 new LayerWithForcedDrawsContent(layer_settings());
1165 child
->SetScrollClipLayerId(root
->id());
1166 root
->AddChild(child
);
1168 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1169 host
->SetRootLayer(root
);
1171 SetLayerPropertiesForTesting(root
.get(),
1178 SetLayerPropertiesForTesting(child
.get(),
1186 gfx::Transform translate
;
1187 translate
.Translate(50, 50);
1189 RenderSurfaceLayerList render_surface_layer_list
;
1190 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1191 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1192 inputs
.can_adjust_raster_scales
= true;
1193 inputs
.property_trees
->needs_rebuild
= true;
1194 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1195 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1196 EXPECT_EQ(translate
, child
->draw_properties().target_space_transform
);
1197 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1198 EXPECT_EQ(1.f
, root
->draw_properties().device_scale_factor
);
1199 EXPECT_EQ(1.f
, child
->draw_properties().device_scale_factor
);
1202 gfx::Transform scale
;
1205 RenderSurfaceLayerList render_surface_layer_list
;
1206 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1207 root
.get(), root
->bounds(), scale
, &render_surface_layer_list
);
1208 inputs
.can_adjust_raster_scales
= true;
1209 inputs
.property_trees
->needs_rebuild
= true;
1210 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1211 EXPECT_EQ(scale
, root
->draw_properties().target_space_transform
);
1212 EXPECT_EQ(scale
, child
->draw_properties().target_space_transform
);
1213 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1214 EXPECT_EQ(2.f
, root
->draw_properties().device_scale_factor
);
1215 EXPECT_EQ(2.f
, child
->draw_properties().device_scale_factor
);
1218 gfx::Transform rotate
;
1221 RenderSurfaceLayerList render_surface_layer_list
;
1222 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1223 root
.get(), root
->bounds(), rotate
, &render_surface_layer_list
);
1224 inputs
.can_adjust_raster_scales
= true;
1225 inputs
.property_trees
->needs_rebuild
= true;
1226 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1227 EXPECT_EQ(rotate
, root
->draw_properties().target_space_transform
);
1228 EXPECT_EQ(rotate
, child
->draw_properties().target_space_transform
);
1229 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1230 EXPECT_EQ(1.f
, root
->draw_properties().device_scale_factor
);
1231 EXPECT_EQ(1.f
, child
->draw_properties().device_scale_factor
);
1234 gfx::Transform composite
;
1235 composite
.ConcatTransform(translate
);
1236 composite
.ConcatTransform(scale
);
1237 composite
.ConcatTransform(rotate
);
1239 RenderSurfaceLayerList render_surface_layer_list
;
1240 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1241 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1242 inputs
.can_adjust_raster_scales
= true;
1243 inputs
.property_trees
->needs_rebuild
= true;
1244 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1245 EXPECT_EQ(composite
, root
->draw_properties().target_space_transform
);
1246 EXPECT_EQ(composite
, child
->draw_properties().target_space_transform
);
1247 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1250 // Verify it composes correctly with device scale.
1251 float device_scale_factor
= 1.5f
;
1254 RenderSurfaceLayerList render_surface_layer_list
;
1255 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1256 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1257 inputs
.device_scale_factor
= device_scale_factor
;
1258 inputs
.can_adjust_raster_scales
= true;
1259 inputs
.property_trees
->needs_rebuild
= true;
1260 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1261 gfx::Transform device_scaled_translate
= translate
;
1262 device_scaled_translate
.Scale(device_scale_factor
, device_scale_factor
);
1263 EXPECT_EQ(device_scaled_translate
,
1264 root
->draw_properties().target_space_transform
);
1265 EXPECT_EQ(device_scaled_translate
,
1266 child
->draw_properties().target_space_transform
);
1267 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1268 EXPECT_EQ(device_scale_factor
, root
->draw_properties().device_scale_factor
);
1269 EXPECT_EQ(device_scale_factor
,
1270 child
->draw_properties().device_scale_factor
);
1273 // Verify it composes correctly with page scale.
1274 float page_scale_factor
= 2.f
;
1277 RenderSurfaceLayerList render_surface_layer_list
;
1278 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1279 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1280 inputs
.page_scale_factor
= page_scale_factor
;
1281 inputs
.page_scale_application_layer
= root
.get();
1282 inputs
.can_adjust_raster_scales
= true;
1283 inputs
.property_trees
->needs_rebuild
= true;
1284 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1285 gfx::Transform page_scaled_translate
= translate
;
1286 page_scaled_translate
.Scale(page_scale_factor
, page_scale_factor
);
1287 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1288 EXPECT_EQ(page_scaled_translate
,
1289 child
->draw_properties().target_space_transform
);
1290 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1291 EXPECT_EQ(1.f
, root
->draw_properties().device_scale_factor
);
1292 EXPECT_EQ(1.f
, child
->draw_properties().device_scale_factor
);
1295 // Verify that it composes correctly with transforms directly on root layer.
1296 root
->SetTransform(composite
);
1299 RenderSurfaceLayerList render_surface_layer_list
;
1300 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1301 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1302 inputs
.can_adjust_raster_scales
= true;
1303 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1304 gfx::Transform compositeSquared
= composite
;
1305 compositeSquared
.ConcatTransform(composite
);
1306 EXPECT_TRANSFORMATION_MATRIX_EQ(
1307 compositeSquared
, root
->draw_properties().target_space_transform
);
1308 EXPECT_TRANSFORMATION_MATRIX_EQ(
1309 compositeSquared
, child
->draw_properties().target_space_transform
);
1310 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1314 TEST_F(LayerTreeHostCommonTest
,
1315 RenderSurfaceListForRenderSurfaceWithClippedLayer
) {
1316 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1317 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
1318 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1319 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1321 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1322 host
->SetRootLayer(parent
);
1324 const gfx::Transform identity_matrix
;
1325 SetLayerPropertiesForTesting(parent
.get(),
1332 SetLayerPropertiesForTesting(render_surface1
.get(),
1339 SetLayerPropertiesForTesting(child
.get(),
1342 gfx::PointF(30.f
, 30.f
),
1347 parent
->AddChild(render_surface1
);
1348 parent
->SetMasksToBounds(true);
1349 render_surface1
->AddChild(child
);
1350 render_surface1
->SetForceRenderSurface(true);
1352 RenderSurfaceLayerList render_surface_layer_list
;
1353 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1357 &render_surface_layer_list
);
1358 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1360 // The child layer's content is entirely outside the parent's clip rect, so
1361 // the intermediate render surface should not be listed here, even if it was
1362 // forced to be created. Render surfaces without children or visible content
1363 // are unexpected at draw time (e.g. we might try to create a content texture
1365 ASSERT_TRUE(parent
->render_surface());
1366 EXPECT_EQ(1U, render_surface_layer_list
.size());
1369 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceListForTransparentChild
) {
1370 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1371 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
1372 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1373 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1375 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1376 host
->SetRootLayer(parent
);
1378 const gfx::Transform identity_matrix
;
1379 SetLayerPropertiesForTesting(render_surface1
.get(),
1386 SetLayerPropertiesForTesting(child
.get(),
1394 parent
->AddChild(render_surface1
);
1395 render_surface1
->AddChild(child
);
1396 render_surface1
->SetForceRenderSurface(true);
1397 render_surface1
->SetOpacity(0.f
);
1399 RenderSurfaceLayerList render_surface_layer_list
;
1400 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1401 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1402 inputs
.can_adjust_raster_scales
= true;
1403 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1405 // Since the layer is transparent, render_surface1->render_surface() should
1406 // not have gotten added anywhere. Also, the drawable content rect should not
1407 // have been extended by the children.
1408 ASSERT_TRUE(parent
->render_surface());
1409 EXPECT_EQ(0U, parent
->render_surface()->layer_list().size());
1410 EXPECT_EQ(1U, render_surface_layer_list
.size());
1411 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1412 EXPECT_EQ(gfx::Rect(), parent
->drawable_content_rect());
1415 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceForBlendMode
) {
1416 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1417 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1418 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1420 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1421 host
->SetRootLayer(parent
);
1423 const gfx::Transform identity_matrix
;
1424 const SkXfermode::Mode blend_mode
= SkXfermode::kMultiply_Mode
;
1425 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
1426 gfx::PointF(), gfx::Size(10, 10), true, false);
1428 parent
->AddChild(child
);
1429 child
->SetBlendMode(blend_mode
);
1431 RenderSurfaceLayerList render_surface_layer_list
;
1432 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1433 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1434 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1436 // Since the child layer has a blend mode other than normal, it should get
1437 // its own render surface. Also, layer's draw_properties should contain the
1438 // default blend mode, since the render surface becomes responsible for
1439 // applying the blend mode.
1440 ASSERT_TRUE(child
->render_surface());
1441 EXPECT_EQ(1U, child
->render_surface()->layer_list().size());
1442 EXPECT_EQ(SkXfermode::kSrcOver_Mode
, child
->draw_properties().blend_mode
);
1445 TEST_F(LayerTreeHostCommonTest
, ForceRenderSurface
) {
1446 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1447 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
1448 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1449 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1450 render_surface1
->SetForceRenderSurface(true);
1452 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1453 host
->SetRootLayer(parent
);
1455 const gfx::Transform identity_matrix
;
1456 SetLayerPropertiesForTesting(parent
.get(),
1463 SetLayerPropertiesForTesting(render_surface1
.get(),
1470 SetLayerPropertiesForTesting(child
.get(),
1478 parent
->AddChild(render_surface1
);
1479 render_surface1
->AddChild(child
);
1481 // Sanity check before the actual test
1482 EXPECT_FALSE(parent
->render_surface());
1483 EXPECT_FALSE(render_surface1
->render_surface());
1486 RenderSurfaceLayerList render_surface_layer_list
;
1487 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1488 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1489 inputs
.can_adjust_raster_scales
= true;
1490 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1492 // The root layer always creates a render surface
1493 EXPECT_TRUE(parent
->render_surface());
1494 EXPECT_TRUE(render_surface1
->render_surface());
1495 EXPECT_EQ(2U, render_surface_layer_list
.size());
1499 RenderSurfaceLayerList render_surface_layer_list
;
1500 render_surface1
->SetForceRenderSurface(false);
1501 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1502 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1503 inputs
.can_adjust_raster_scales
= true;
1504 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1505 EXPECT_TRUE(parent
->render_surface());
1506 EXPECT_FALSE(render_surface1
->render_surface());
1507 EXPECT_EQ(1U, render_surface_layer_list
.size());
1511 TEST_F(LayerTreeHostCommonTest
, RenderSurfacesFlattenScreenSpaceTransform
) {
1512 // Render surfaces act as a flattening point for their subtree, so should
1513 // always flatten the target-to-screen space transform seen by descendants.
1515 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1516 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1517 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1518 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1519 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1520 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1522 gfx::Transform rotation_about_y_axis
;
1523 rotation_about_y_axis
.RotateAboutYAxis(30.0);
1524 // Make |parent| have a render surface.
1525 parent
->SetOpacity(0.9f
);
1527 const gfx::Transform identity_matrix
;
1528 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
1529 gfx::PointF(), gfx::Size(100, 100), true, false);
1530 SetLayerPropertiesForTesting(parent
.get(), rotation_about_y_axis
,
1531 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1533 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
1534 gfx::PointF(), gfx::Size(10, 10), true, false);
1535 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
1536 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 10),
1539 root
->AddChild(parent
);
1540 parent
->AddChild(child
);
1541 child
->AddChild(grand_child
);
1543 grand_child
->SetShouldFlattenTransform(false);
1545 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1546 host
->SetRootLayer(root
);
1548 // Only grand_child should preserve 3d.
1549 EXPECT_TRUE(root
->should_flatten_transform());
1550 EXPECT_TRUE(parent
->should_flatten_transform());
1551 EXPECT_TRUE(child
->should_flatten_transform());
1552 EXPECT_FALSE(grand_child
->should_flatten_transform());
1554 gfx::Transform expected_child_draw_transform
= identity_matrix
;
1555 gfx::Transform expected_grand_child_draw_transform
= identity_matrix
;
1557 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
1558 flattened_rotation_about_y
.FlattenTo2d();
1560 ExecuteCalculateDrawProperties(root
.get());
1562 EXPECT_TRUE(parent
->render_surface());
1563 EXPECT_FALSE(child
->render_surface());
1564 EXPECT_FALSE(grand_child
->render_surface());
1566 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1567 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1568 grand_child
->draw_transform());
1570 // The screen-space transform inherited by |child| and |grand_child| should
1571 // have been flattened at their render target. In particular, the fact that
1572 // |grand_child| happens to preserve 3d shouldn't affect this flattening.
1573 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y
,
1574 child
->screen_space_transform());
1575 EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_y
,
1576 grand_child
->screen_space_transform());
1579 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsRenderSurfaces
) {
1580 // The entire subtree of layers that are outside the clip rect should be
1581 // culled away, and should not affect the render_surface_layer_list.
1583 // The test tree is set up as follows:
1584 // - all layers except the leaf_nodes are forced to be a new render surface
1585 // that have something to draw.
1586 // - parent is a large container layer.
1587 // - child has masksToBounds=true to cause clipping.
1588 // - grand_child is positioned outside of the child's bounds
1589 // - great_grand_child is also kept outside child's bounds.
1591 // In this configuration, grand_child and great_grand_child are completely
1592 // outside the clip rect, and they should never get scheduled on the list of
1596 const gfx::Transform identity_matrix
;
1597 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1598 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1599 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
1600 scoped_refptr
<Layer
> great_grand_child
= Layer::Create(layer_settings());
1601 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1602 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1603 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1604 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1605 parent
->AddChild(child
);
1606 child
->AddChild(grand_child
);
1607 grand_child
->AddChild(great_grand_child
);
1609 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1610 host
->SetRootLayer(parent
);
1612 // leaf_node1 ensures that parent and child are kept on the
1613 // render_surface_layer_list, even though grand_child and great_grand_child
1614 // should be clipped.
1615 child
->AddChild(leaf_node1
);
1616 great_grand_child
->AddChild(leaf_node2
);
1618 SetLayerPropertiesForTesting(parent
.get(),
1622 gfx::Size(500, 500),
1625 SetLayerPropertiesForTesting(child
.get(),
1632 SetLayerPropertiesForTesting(grand_child
.get(),
1635 gfx::PointF(45.f
, 45.f
),
1639 SetLayerPropertiesForTesting(great_grand_child
.get(),
1646 SetLayerPropertiesForTesting(leaf_node1
.get(),
1650 gfx::Size(500, 500),
1653 SetLayerPropertiesForTesting(leaf_node2
.get(),
1661 child
->SetMasksToBounds(true);
1662 child
->SetOpacity(0.4f
);
1663 child
->SetForceRenderSurface(true);
1664 grand_child
->SetOpacity(0.5f
);
1665 great_grand_child
->SetOpacity(0.4f
);
1667 RenderSurfaceLayerList render_surface_layer_list
;
1668 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1669 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1670 inputs
.can_adjust_raster_scales
= true;
1671 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1673 ASSERT_EQ(2U, render_surface_layer_list
.size());
1674 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1675 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1678 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsSurfaceWithoutVisibleContent
) {
1679 // When a render surface has a clip rect, it is used to clip the content rect
1680 // of the surface. When the render surface is animating its transforms, then
1681 // the content rect's position in the clip rect is not defined on the main
1682 // thread, and its content rect should not be clipped.
1684 // The test tree is set up as follows:
1685 // - parent is a container layer that masksToBounds=true to cause clipping.
1686 // - child is a render surface, which has a clip rect set to the bounds of
1688 // - grand_child is a render surface, and the only visible content in child.
1689 // It is positioned outside of the clip rect from parent.
1691 // In this configuration, grand_child should be outside the clipped
1692 // content rect of the child, making grand_child not appear in the
1693 // render_surface_layer_list. However, when we place an animation on the
1694 // child, this clipping should be avoided and we should keep the grand_child
1695 // in the render_surface_layer_list.
1697 const gfx::Transform identity_matrix
;
1698 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1699 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1700 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
1701 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node
=
1702 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1703 parent
->AddChild(child
);
1704 child
->AddChild(grand_child
);
1705 grand_child
->AddChild(leaf_node
);
1707 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1708 host
->SetRootLayer(parent
);
1710 SetLayerPropertiesForTesting(parent
.get(),
1714 gfx::Size(100, 100),
1717 SetLayerPropertiesForTesting(child
.get(),
1724 SetLayerPropertiesForTesting(grand_child
.get(),
1727 gfx::PointF(200.f
, 200.f
),
1731 SetLayerPropertiesForTesting(leaf_node
.get(),
1739 parent
->SetMasksToBounds(true);
1740 child
->SetOpacity(0.4f
);
1741 child
->SetForceRenderSurface(true);
1742 grand_child
->SetOpacity(0.4f
);
1743 grand_child
->SetForceRenderSurface(true);
1746 RenderSurfaceLayerList render_surface_layer_list
;
1747 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1748 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1749 inputs
.can_adjust_raster_scales
= true;
1750 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1752 // Without an animation, we should cull child and grand_child from the
1753 // render_surface_layer_list.
1754 ASSERT_EQ(1U, render_surface_layer_list
.size());
1755 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1758 // Now put an animating transform on child.
1759 AddAnimatedTransformToController(
1760 child
->layer_animation_controller(), 10.0, 30, 0);
1763 RenderSurfaceLayerList render_surface_layer_list
;
1764 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1765 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1766 inputs
.can_adjust_raster_scales
= true;
1767 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1769 // With an animating transform, we should keep child and grand_child in the
1770 // render_surface_layer_list.
1771 ASSERT_EQ(3U, render_surface_layer_list
.size());
1772 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1773 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1774 EXPECT_EQ(grand_child
->id(), render_surface_layer_list
.at(2)->id());
1778 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectly
) {
1779 // Layer's IsClipped() property is set to true when:
1780 // - the layer clips its subtree, e.g. masks to bounds,
1781 // - the layer is clipped by an ancestor that contributes to the same
1783 // - a surface is clipped by an ancestor that contributes to the same
1786 // In particular, for a layer that owns a render surface:
1787 // - the render surface inherits any clip from ancestors, and does NOT
1788 // pass that clipped status to the layer itself.
1789 // - but if the layer itself masks to bounds, it is considered clipped
1790 // and propagates the clip to the subtree.
1792 const gfx::Transform identity_matrix
;
1793 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
1794 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1795 scoped_refptr
<Layer
> child1
= Layer::Create(layer_settings());
1796 scoped_refptr
<Layer
> child2
= Layer::Create(layer_settings());
1797 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
1798 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1799 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1800 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1801 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
1802 root
->AddChild(parent
);
1803 parent
->AddChild(child1
);
1804 parent
->AddChild(child2
);
1805 child1
->AddChild(grand_child
);
1806 child2
->AddChild(leaf_node2
);
1807 grand_child
->AddChild(leaf_node1
);
1809 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1810 host
->SetRootLayer(root
);
1812 child2
->SetForceRenderSurface(true);
1814 SetLayerPropertiesForTesting(root
.get(),
1818 gfx::Size(100, 100),
1821 SetLayerPropertiesForTesting(parent
.get(),
1825 gfx::Size(100, 100),
1828 SetLayerPropertiesForTesting(child1
.get(),
1832 gfx::Size(100, 100),
1835 SetLayerPropertiesForTesting(child2
.get(),
1839 gfx::Size(100, 100),
1842 SetLayerPropertiesForTesting(grand_child
.get(),
1846 gfx::Size(100, 100),
1849 SetLayerPropertiesForTesting(leaf_node1
.get(),
1853 gfx::Size(100, 100),
1856 SetLayerPropertiesForTesting(leaf_node2
.get(),
1860 gfx::Size(100, 100),
1864 // Case 1: nothing is clipped except the root render surface.
1866 RenderSurfaceLayerList render_surface_layer_list
;
1867 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1868 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1869 inputs
.can_adjust_raster_scales
= true;
1870 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1872 ASSERT_TRUE(root
->render_surface());
1873 ASSERT_TRUE(child2
->render_surface());
1875 EXPECT_FALSE(root
->is_clipped());
1876 EXPECT_TRUE(root
->render_surface()->is_clipped());
1877 EXPECT_FALSE(parent
->is_clipped());
1878 EXPECT_FALSE(child1
->is_clipped());
1879 EXPECT_FALSE(child2
->is_clipped());
1880 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1881 EXPECT_FALSE(grand_child
->is_clipped());
1882 EXPECT_FALSE(leaf_node1
->is_clipped());
1883 EXPECT_FALSE(leaf_node2
->is_clipped());
1886 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1887 // surface are clipped. But layers that contribute to child2's surface are
1888 // not clipped explicitly because child2's surface already accounts for
1891 RenderSurfaceLayerList render_surface_layer_list
;
1892 parent
->SetMasksToBounds(true);
1893 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1894 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1895 inputs
.can_adjust_raster_scales
= true;
1896 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1898 ASSERT_TRUE(root
->render_surface());
1899 ASSERT_TRUE(child2
->render_surface());
1901 EXPECT_FALSE(root
->is_clipped());
1902 EXPECT_TRUE(root
->render_surface()->is_clipped());
1903 EXPECT_TRUE(parent
->is_clipped());
1904 EXPECT_TRUE(child1
->is_clipped());
1905 EXPECT_FALSE(child2
->is_clipped());
1906 EXPECT_TRUE(child2
->render_surface()->is_clipped());
1907 EXPECT_TRUE(grand_child
->is_clipped());
1908 EXPECT_TRUE(leaf_node1
->is_clipped());
1909 EXPECT_FALSE(leaf_node2
->is_clipped());
1912 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1913 // child2's render surface is not clipped.
1915 RenderSurfaceLayerList render_surface_layer_list
;
1916 parent
->SetMasksToBounds(false);
1917 child2
->SetMasksToBounds(true);
1918 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1919 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1920 inputs
.can_adjust_raster_scales
= true;
1921 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1923 ASSERT_TRUE(root
->render_surface());
1924 ASSERT_TRUE(child2
->render_surface());
1926 EXPECT_FALSE(root
->is_clipped());
1927 EXPECT_TRUE(root
->render_surface()->is_clipped());
1928 EXPECT_FALSE(parent
->is_clipped());
1929 EXPECT_FALSE(child1
->is_clipped());
1930 EXPECT_TRUE(child2
->is_clipped());
1931 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1932 EXPECT_FALSE(grand_child
->is_clipped());
1933 EXPECT_FALSE(leaf_node1
->is_clipped());
1934 EXPECT_TRUE(leaf_node2
->is_clipped());
1938 TEST_F(LayerTreeHostCommonTest
, DrawableContentRectForLayers
) {
1939 // Verify that layers get the appropriate DrawableContentRect when their
1940 // parent masksToBounds is true.
1942 // grand_child1 - completely inside the region; DrawableContentRect should
1943 // be the layer rect expressed in target space.
1944 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1945 // will be the intersection of layer bounds and the mask region.
1946 // grand_child3 - partially clipped and masksToBounds; the
1947 // DrawableContentRect will still be the intersection of layer bounds and
1949 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1953 const gfx::Transform identity_matrix
;
1954 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
1955 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
1956 scoped_refptr
<Layer
> grand_child1
= Layer::Create(layer_settings());
1957 scoped_refptr
<Layer
> grand_child2
= Layer::Create(layer_settings());
1958 scoped_refptr
<Layer
> grand_child3
= Layer::Create(layer_settings());
1959 scoped_refptr
<Layer
> grand_child4
= Layer::Create(layer_settings());
1961 parent
->AddChild(child
);
1962 child
->AddChild(grand_child1
);
1963 child
->AddChild(grand_child2
);
1964 child
->AddChild(grand_child3
);
1965 child
->AddChild(grand_child4
);
1967 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1968 host
->SetRootLayer(parent
);
1970 SetLayerPropertiesForTesting(parent
.get(),
1974 gfx::Size(500, 500),
1977 SetLayerPropertiesForTesting(child
.get(),
1984 SetLayerPropertiesForTesting(grand_child1
.get(),
1987 gfx::PointF(5.f
, 5.f
),
1991 SetLayerPropertiesForTesting(grand_child2
.get(),
1994 gfx::PointF(15.f
, 15.f
),
1998 SetLayerPropertiesForTesting(grand_child3
.get(),
2001 gfx::PointF(15.f
, 15.f
),
2005 SetLayerPropertiesForTesting(grand_child4
.get(),
2008 gfx::PointF(45.f
, 45.f
),
2013 child
->SetMasksToBounds(true);
2014 grand_child3
->SetMasksToBounds(true);
2016 // Force everyone to be a render surface.
2017 child
->SetOpacity(0.4f
);
2018 grand_child1
->SetOpacity(0.5f
);
2019 grand_child2
->SetOpacity(0.5f
);
2020 grand_child3
->SetOpacity(0.5f
);
2021 grand_child4
->SetOpacity(0.5f
);
2023 RenderSurfaceLayerList render_surface_layer_list
;
2024 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2025 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
2026 inputs
.can_adjust_raster_scales
= true;
2027 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2029 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1
->drawable_content_rect());
2030 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
2031 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
2032 EXPECT_TRUE(grand_child4
->drawable_content_rect().IsEmpty());
2035 TEST_F(LayerTreeHostCommonTest
, ClipRectIsPropagatedCorrectlyToSurfaces
) {
2036 // Verify that render surfaces (and their layers) get the appropriate
2037 // clip rects when their parent masksToBounds is true.
2039 // Layers that own render surfaces (at least for now) do not inherit any
2040 // clipping; instead the surface will enforce the clip for the entire subtree.
2041 // They may still have a clip rect of their own layer bounds, however, if
2042 // masksToBounds was true.
2043 const gfx::Transform identity_matrix
;
2044 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
2045 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
2046 scoped_refptr
<Layer
> grand_child1
= Layer::Create(layer_settings());
2047 scoped_refptr
<Layer
> grand_child2
= Layer::Create(layer_settings());
2048 scoped_refptr
<Layer
> grand_child3
= Layer::Create(layer_settings());
2049 scoped_refptr
<Layer
> grand_child4
= Layer::Create(layer_settings());
2050 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
2051 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2052 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
2053 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2054 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node3
=
2055 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2056 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node4
=
2057 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2059 parent
->AddChild(child
);
2060 child
->AddChild(grand_child1
);
2061 child
->AddChild(grand_child2
);
2062 child
->AddChild(grand_child3
);
2063 child
->AddChild(grand_child4
);
2065 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2066 host
->SetRootLayer(parent
);
2068 // the leaf nodes ensure that these grand_children become render surfaces for
2070 grand_child1
->AddChild(leaf_node1
);
2071 grand_child2
->AddChild(leaf_node2
);
2072 grand_child3
->AddChild(leaf_node3
);
2073 grand_child4
->AddChild(leaf_node4
);
2075 SetLayerPropertiesForTesting(parent
.get(),
2079 gfx::Size(500, 500),
2082 SetLayerPropertiesForTesting(child
.get(),
2089 SetLayerPropertiesForTesting(grand_child1
.get(),
2092 gfx::PointF(5.f
, 5.f
),
2096 SetLayerPropertiesForTesting(grand_child2
.get(),
2099 gfx::PointF(15.f
, 15.f
),
2103 SetLayerPropertiesForTesting(grand_child3
.get(),
2106 gfx::PointF(15.f
, 15.f
),
2110 SetLayerPropertiesForTesting(grand_child4
.get(),
2113 gfx::PointF(45.f
, 45.f
),
2117 SetLayerPropertiesForTesting(leaf_node1
.get(),
2124 SetLayerPropertiesForTesting(leaf_node2
.get(),
2131 SetLayerPropertiesForTesting(leaf_node3
.get(),
2138 SetLayerPropertiesForTesting(leaf_node4
.get(),
2146 child
->SetMasksToBounds(true);
2147 grand_child3
->SetMasksToBounds(true);
2148 grand_child4
->SetMasksToBounds(true);
2150 // Force everyone to be a render surface.
2151 child
->SetOpacity(0.4f
);
2152 child
->SetForceRenderSurface(true);
2153 grand_child1
->SetOpacity(0.5f
);
2154 grand_child1
->SetForceRenderSurface(true);
2155 grand_child2
->SetOpacity(0.5f
);
2156 grand_child2
->SetForceRenderSurface(true);
2157 grand_child3
->SetOpacity(0.5f
);
2158 grand_child3
->SetForceRenderSurface(true);
2159 grand_child4
->SetOpacity(0.5f
);
2160 grand_child4
->SetForceRenderSurface(true);
2162 RenderSurfaceLayerList render_surface_layer_list
;
2163 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2164 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
2165 inputs
.can_adjust_raster_scales
= true;
2166 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2167 ASSERT_TRUE(grand_child1
->render_surface());
2168 ASSERT_TRUE(grand_child2
->render_surface());
2169 ASSERT_TRUE(grand_child3
->render_surface());
2171 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2173 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2174 grand_child1
->render_surface()->clip_rect());
2175 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2176 grand_child2
->render_surface()->clip_rect());
2177 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2178 grand_child3
->render_surface()->clip_rect());
2181 TEST_F(LayerTreeHostCommonTest
, AnimationsForRenderSurfaceHierarchy
) {
2182 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
2183 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
2184 scoped_refptr
<Layer
> render_surface2
= Layer::Create(layer_settings());
2185 scoped_refptr
<Layer
> child_of_root
= Layer::Create(layer_settings());
2186 scoped_refptr
<Layer
> child_of_rs1
= Layer::Create(layer_settings());
2187 scoped_refptr
<Layer
> child_of_rs2
= Layer::Create(layer_settings());
2188 scoped_refptr
<Layer
> grand_child_of_root
= Layer::Create(layer_settings());
2189 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs1
=
2190 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2191 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs2
=
2192 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2193 parent
->AddChild(render_surface1
);
2194 parent
->AddChild(child_of_root
);
2195 render_surface1
->AddChild(child_of_rs1
);
2196 render_surface1
->AddChild(render_surface2
);
2197 render_surface2
->AddChild(child_of_rs2
);
2198 child_of_root
->AddChild(grand_child_of_root
);
2199 child_of_rs1
->AddChild(grand_child_of_rs1
);
2200 child_of_rs2
->AddChild(grand_child_of_rs2
);
2202 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2203 host
->SetRootLayer(parent
);
2205 // Make our render surfaces.
2206 render_surface1
->SetForceRenderSurface(true);
2207 render_surface2
->SetForceRenderSurface(true);
2209 gfx::Transform layer_transform
;
2210 layer_transform
.Translate(1.0, 1.0);
2212 SetLayerPropertiesForTesting(parent
.get(),
2214 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2215 gfx::PointF(2.5f
, 0.f
),
2219 SetLayerPropertiesForTesting(render_surface1
.get(),
2221 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2222 gfx::PointF(2.5f
, 0.f
),
2226 SetLayerPropertiesForTesting(render_surface2
.get(),
2228 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2229 gfx::PointF(2.5f
, 0.f
),
2233 SetLayerPropertiesForTesting(child_of_root
.get(),
2235 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2236 gfx::PointF(2.5f
, 0.f
),
2240 SetLayerPropertiesForTesting(child_of_rs1
.get(),
2242 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2243 gfx::PointF(2.5f
, 0.f
),
2247 SetLayerPropertiesForTesting(child_of_rs2
.get(),
2249 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2250 gfx::PointF(2.5f
, 0.f
),
2254 SetLayerPropertiesForTesting(grand_child_of_root
.get(),
2256 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2257 gfx::PointF(2.5f
, 0.f
),
2261 SetLayerPropertiesForTesting(grand_child_of_rs1
.get(),
2263 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2264 gfx::PointF(2.5f
, 0.f
),
2268 SetLayerPropertiesForTesting(grand_child_of_rs2
.get(),
2270 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2271 gfx::PointF(2.5f
, 0.f
),
2276 // Put an animated opacity on the render surface.
2277 AddOpacityTransitionToController(
2278 render_surface1
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2280 // Also put an animated opacity on a layer without descendants.
2281 AddOpacityTransitionToController(
2282 grand_child_of_root
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2284 // Put a transform animation on the render surface.
2285 AddAnimatedTransformToController(
2286 render_surface2
->layer_animation_controller(), 10.0, 30, 0);
2288 // Also put transform animations on grand_child_of_root, and
2289 // grand_child_of_rs2
2290 AddAnimatedTransformToController(
2291 grand_child_of_root
->layer_animation_controller(), 10.0, 30, 0);
2292 AddAnimatedTransformToController(
2293 grand_child_of_rs2
->layer_animation_controller(), 10.0, 30, 0);
2295 ExecuteCalculateDrawProperties(parent
.get());
2297 // Only layers that are associated with render surfaces should have an actual
2298 // RenderSurface() value.
2299 ASSERT_TRUE(parent
->render_surface());
2300 ASSERT_FALSE(child_of_root
->render_surface());
2301 ASSERT_FALSE(grand_child_of_root
->render_surface());
2303 ASSERT_TRUE(render_surface1
->render_surface());
2304 ASSERT_FALSE(child_of_rs1
->render_surface());
2305 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
2307 ASSERT_TRUE(render_surface2
->render_surface());
2308 ASSERT_FALSE(child_of_rs2
->render_surface());
2309 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
2311 // Verify all render target accessors
2312 EXPECT_EQ(parent
.get(), parent
->render_target());
2313 EXPECT_EQ(parent
.get(), child_of_root
->render_target());
2314 EXPECT_EQ(parent
.get(), grand_child_of_root
->render_target());
2316 EXPECT_EQ(render_surface1
.get(), render_surface1
->render_target());
2317 EXPECT_EQ(render_surface1
.get(), child_of_rs1
->render_target());
2318 EXPECT_EQ(render_surface1
.get(), grand_child_of_rs1
->render_target());
2320 EXPECT_EQ(render_surface2
.get(), render_surface2
->render_target());
2321 EXPECT_EQ(render_surface2
.get(), child_of_rs2
->render_target());
2322 EXPECT_EQ(render_surface2
.get(), grand_child_of_rs2
->render_target());
2324 // Verify draw_opacity_is_animating values
2325 EXPECT_FALSE(parent
->draw_opacity_is_animating());
2326 EXPECT_FALSE(child_of_root
->draw_opacity_is_animating());
2327 EXPECT_TRUE(grand_child_of_root
->draw_opacity_is_animating());
2328 EXPECT_FALSE(render_surface1
->draw_opacity_is_animating());
2329 EXPECT_TRUE(render_surface1
->render_surface()->draw_opacity_is_animating());
2330 EXPECT_FALSE(child_of_rs1
->draw_opacity_is_animating());
2331 EXPECT_FALSE(grand_child_of_rs1
->draw_opacity_is_animating());
2332 EXPECT_FALSE(render_surface2
->draw_opacity_is_animating());
2333 EXPECT_FALSE(render_surface2
->render_surface()->draw_opacity_is_animating());
2334 EXPECT_FALSE(child_of_rs2
->draw_opacity_is_animating());
2335 EXPECT_FALSE(grand_child_of_rs2
->draw_opacity_is_animating());
2337 // Verify draw_transform_is_animating values
2338 EXPECT_FALSE(parent
->draw_transform_is_animating());
2339 EXPECT_FALSE(child_of_root
->draw_transform_is_animating());
2340 EXPECT_TRUE(grand_child_of_root
->draw_transform_is_animating());
2341 EXPECT_FALSE(render_surface1
->draw_transform_is_animating());
2342 EXPECT_FALSE(render_surface1
->render_surface()
2343 ->target_surface_transforms_are_animating());
2344 EXPECT_FALSE(child_of_rs1
->draw_transform_is_animating());
2345 EXPECT_FALSE(grand_child_of_rs1
->draw_transform_is_animating());
2346 EXPECT_FALSE(render_surface2
->draw_transform_is_animating());
2347 EXPECT_TRUE(render_surface2
->render_surface()
2348 ->target_surface_transforms_are_animating());
2349 EXPECT_FALSE(child_of_rs2
->draw_transform_is_animating());
2350 EXPECT_TRUE(grand_child_of_rs2
->draw_transform_is_animating());
2352 // Verify screen_space_transform_is_animating values
2353 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
2354 EXPECT_FALSE(child_of_root
->screen_space_transform_is_animating());
2355 EXPECT_TRUE(grand_child_of_root
->screen_space_transform_is_animating());
2356 EXPECT_FALSE(render_surface1
->screen_space_transform_is_animating());
2357 EXPECT_FALSE(render_surface1
->render_surface()
2358 ->screen_space_transforms_are_animating());
2359 EXPECT_FALSE(child_of_rs1
->screen_space_transform_is_animating());
2360 EXPECT_FALSE(grand_child_of_rs1
->screen_space_transform_is_animating());
2361 EXPECT_TRUE(render_surface2
->screen_space_transform_is_animating());
2362 EXPECT_TRUE(render_surface2
->render_surface()
2363 ->screen_space_transforms_are_animating());
2364 EXPECT_TRUE(child_of_rs2
->screen_space_transform_is_animating());
2365 EXPECT_TRUE(grand_child_of_rs2
->screen_space_transform_is_animating());
2367 // Sanity check. If these fail there is probably a bug in the test itself.
2368 // It is expected that we correctly set up transforms so that the y-component
2369 // of the screen-space transform encodes the "depth" of the layer in the tree.
2370 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
2371 EXPECT_FLOAT_EQ(2.0,
2372 child_of_root
->screen_space_transform().matrix().get(1, 3));
2374 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
2376 EXPECT_FLOAT_EQ(2.0,
2377 render_surface1
->screen_space_transform().matrix().get(1, 3));
2378 EXPECT_FLOAT_EQ(3.0,
2379 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2381 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2383 EXPECT_FLOAT_EQ(3.0,
2384 render_surface2
->screen_space_transform().matrix().get(1, 3));
2385 EXPECT_FLOAT_EQ(4.0,
2386 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2388 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2391 TEST_F(LayerTreeHostCommonTest
, VisibleRectForIdentityTransform
) {
2392 // Test the calculateVisibleRect() function works correctly for identity
2395 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2396 gfx::Transform layer_to_surface_transform
;
2398 // Case 1: Layer is contained within the surface.
2399 gfx::Rect layer_content_rect
= gfx::Rect(10, 10, 30, 30);
2400 gfx::Rect expected
= gfx::Rect(10, 10, 30, 30);
2401 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2402 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2403 EXPECT_EQ(expected
, actual
);
2405 // Case 2: Layer is outside the surface rect.
2406 layer_content_rect
= gfx::Rect(120, 120, 30, 30);
2407 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2408 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2409 EXPECT_TRUE(actual
.IsEmpty());
2411 // Case 3: Layer is partially overlapping the surface rect.
2412 layer_content_rect
= gfx::Rect(80, 80, 30, 30);
2413 expected
= gfx::Rect(80, 80, 20, 20);
2414 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2415 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2416 EXPECT_EQ(expected
, actual
);
2419 TEST_F(LayerTreeHostCommonTest
, VisibleRectForTranslations
) {
2420 // Test the calculateVisibleRect() function works correctly for scaling
2423 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2424 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2425 gfx::Transform layer_to_surface_transform
;
2427 // Case 1: Layer is contained within the surface.
2428 layer_to_surface_transform
.MakeIdentity();
2429 layer_to_surface_transform
.Translate(10.0, 10.0);
2430 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2431 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2432 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2433 EXPECT_EQ(expected
, actual
);
2435 // Case 2: Layer is outside the surface rect.
2436 layer_to_surface_transform
.MakeIdentity();
2437 layer_to_surface_transform
.Translate(120.0, 120.0);
2438 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2439 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2440 EXPECT_TRUE(actual
.IsEmpty());
2442 // Case 3: Layer is partially overlapping the surface rect.
2443 layer_to_surface_transform
.MakeIdentity();
2444 layer_to_surface_transform
.Translate(80.0, 80.0);
2445 expected
= gfx::Rect(0, 0, 20, 20);
2446 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2447 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2448 EXPECT_EQ(expected
, actual
);
2451 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor2DRotations
) {
2452 // Test the calculateVisibleRect() function works correctly for rotations
2453 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2454 // should return the g in the layer's space.
2456 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2457 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2458 gfx::Transform layer_to_surface_transform
;
2460 // Case 1: Layer is contained within the surface.
2461 layer_to_surface_transform
.MakeIdentity();
2462 layer_to_surface_transform
.Translate(50.0, 50.0);
2463 layer_to_surface_transform
.Rotate(45.0);
2464 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2465 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2466 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2467 EXPECT_EQ(expected
, actual
);
2469 // Case 2: Layer is outside the surface rect.
2470 layer_to_surface_transform
.MakeIdentity();
2471 layer_to_surface_transform
.Translate(-50.0, 0.0);
2472 layer_to_surface_transform
.Rotate(45.0);
2473 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2474 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2475 EXPECT_TRUE(actual
.IsEmpty());
2477 // Case 3: The layer is rotated about its top-left corner. In surface space,
2478 // the layer is oriented diagonally, with the left half outside of the render
2479 // surface. In this case, the g should still be the entire layer
2480 // (remember the g is computed in layer space); both the top-left
2481 // and bottom-right corners of the layer are still visible.
2482 layer_to_surface_transform
.MakeIdentity();
2483 layer_to_surface_transform
.Rotate(45.0);
2484 expected
= gfx::Rect(0, 0, 30, 30);
2485 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2486 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2487 EXPECT_EQ(expected
, actual
);
2489 // Case 4: The layer is rotated about its top-left corner, and translated
2490 // upwards. In surface space, the layer is oriented diagonally, with only the
2491 // top corner of the surface overlapping the layer. In layer space, the render
2492 // surface overlaps the right side of the layer. The g should be
2493 // the layer's right half.
2494 layer_to_surface_transform
.MakeIdentity();
2495 layer_to_surface_transform
.Translate(0.0, -sqrt(2.0) * 15.0);
2496 layer_to_surface_transform
.Rotate(45.0);
2497 expected
= gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2498 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2499 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2500 EXPECT_EQ(expected
, actual
);
2503 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dOrthographicTransform
) {
2504 // Test that the calculateVisibleRect() function works correctly for 3d
2507 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2508 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2509 gfx::Transform layer_to_surface_transform
;
2511 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2512 // degrees, should be fully contained in the render surface.
2513 layer_to_surface_transform
.MakeIdentity();
2514 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2515 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2516 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2517 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2518 EXPECT_EQ(expected
, actual
);
2520 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2521 // degrees, but shifted to the side so only the right-half the layer would be
2522 // visible on the surface.
2523 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2524 SkMScalar half_width_of_rotated_layer
=
2525 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2526 layer_to_surface_transform
.MakeIdentity();
2527 layer_to_surface_transform
.Translate(-half_width_of_rotated_layer
, 0.0);
2528 layer_to_surface_transform
.RotateAboutYAxis(45.0); // Rotates about the left
2529 // edge of the layer.
2530 expected
= gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2531 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2532 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2533 EXPECT_EQ(expected
, actual
);
2536 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveTransform
) {
2537 // Test the calculateVisibleRect() function works correctly when the layer has
2538 // a perspective projection onto the target surface.
2540 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2541 gfx::Rect layer_content_rect
= gfx::Rect(-50, -50, 200, 200);
2542 gfx::Transform layer_to_surface_transform
;
2544 // Case 1: Even though the layer is twice as large as the surface, due to
2545 // perspective foreshortening, the layer will fit fully in the surface when
2546 // its translated more than the perspective amount.
2547 layer_to_surface_transform
.MakeIdentity();
2549 // The following sequence of transforms applies the perspective about the
2550 // center of the surface.
2551 layer_to_surface_transform
.Translate(50.0, 50.0);
2552 layer_to_surface_transform
.ApplyPerspectiveDepth(9.0);
2553 layer_to_surface_transform
.Translate(-50.0, -50.0);
2555 // This translate places the layer in front of the surface's projection plane.
2556 layer_to_surface_transform
.Translate3d(0.0, 0.0, -27.0);
2558 gfx::Rect expected
= gfx::Rect(-50, -50, 200, 200);
2559 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2560 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2561 EXPECT_EQ(expected
, actual
);
2563 // Case 2: same projection as before, except that the layer is also translated
2564 // to the side, so that only the right half of the layer should be visible.
2566 // Explanation of expected result: The perspective ratio is (z distance
2567 // between layer and camera origin) / (z distance between projection plane and
2568 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2569 // move a layer by translating -50 units in projected surface units (so that
2570 // only half of it is visible), then we would need to translate by (-36 / 9) *
2571 // -50 == -200 in the layer's units.
2572 layer_to_surface_transform
.Translate3d(-200.0, 0.0, 0.0);
2573 expected
= gfx::Rect(gfx::Point(50, -50),
2574 gfx::Size(100, 200)); // The right half of the layer's
2576 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2577 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2578 EXPECT_EQ(expected
, actual
);
2581 TEST_F(LayerTreeHostCommonTest
,
2582 VisibleRectFor3dOrthographicIsNotClippedBehindSurface
) {
2583 // There is currently no explicit concept of an orthographic projection plane
2584 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2585 // are technically behind the surface in an orthographic world should not be
2586 // clipped when they are flattened to the surface.
2588 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2589 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2590 gfx::Transform layer_to_surface_transform
;
2592 // This sequence of transforms effectively rotates the layer about the y-axis
2593 // at the center of the layer.
2594 layer_to_surface_transform
.MakeIdentity();
2595 layer_to_surface_transform
.Translate(50.0, 0.0);
2596 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2597 layer_to_surface_transform
.Translate(-50.0, 0.0);
2599 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2600 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2601 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2602 EXPECT_EQ(expected
, actual
);
2605 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveWhenClippedByW
) {
2606 // Test the calculateVisibleRect() function works correctly when projecting a
2607 // surface onto a layer, but the layer is partially behind the camera (not
2608 // just behind the projection plane). In this case, the cartesian coordinates
2609 // may seem to be valid, but actually they are not. The visible rect needs to
2610 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2611 // converting to cartesian coordinates.
2613 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2614 gfx::Rect layer_content_rect
= gfx::Rect(-10, -1, 20, 2);
2615 gfx::Transform layer_to_surface_transform
;
2617 // The layer is positioned so that the right half of the layer should be in
2618 // front of the camera, while the other half is behind the surface's
2619 // projection plane. The following sequence of transforms applies the
2620 // perspective and rotation about the center of the layer.
2621 layer_to_surface_transform
.MakeIdentity();
2622 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2623 layer_to_surface_transform
.Translate3d(-2.0, 0.0, 1.0);
2624 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2626 // Sanity check that this transform does indeed cause w < 0 when applying the
2627 // transform, otherwise this code is not testing the intended scenario.
2629 MathUtil::MapQuad(layer_to_surface_transform
,
2630 gfx::QuadF(gfx::RectF(layer_content_rect
)),
2632 ASSERT_TRUE(clipped
);
2634 int expected_x_position
= 0;
2635 int expected_width
= 10;
2636 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2637 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2638 EXPECT_EQ(expected_x_position
, actual
.x());
2639 EXPECT_EQ(expected_width
, actual
.width());
2642 TEST_F(LayerTreeHostCommonTest
, VisibleRectForPerspectiveUnprojection
) {
2643 // To determine visible rect in layer space, there needs to be an
2644 // un-projection from surface space to layer space. When the original
2645 // transform was a perspective projection that was clipped, it returns a rect
2646 // that encloses the clipped bounds. Un-projecting this new rect may require
2649 // This sequence of transforms causes one corner of the layer to protrude
2650 // across the w = 0 plane, and should be clipped.
2651 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2652 gfx::Rect layer_content_rect
= gfx::Rect(-10, -10, 20, 20);
2653 gfx::Transform layer_to_surface_transform
;
2654 layer_to_surface_transform
.MakeIdentity();
2655 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2656 layer_to_surface_transform
.Translate3d(0.0, 0.0, -5.0);
2657 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2658 layer_to_surface_transform
.RotateAboutXAxis(80.0);
2660 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2661 // code is not testing the intended scenario.
2663 gfx::RectF clipped_rect
=
2664 MathUtil::MapClippedRect(layer_to_surface_transform
, layer_content_rect
);
2665 MathUtil::ProjectQuad(
2666 Inverse(layer_to_surface_transform
), gfx::QuadF(clipped_rect
), &clipped
);
2667 ASSERT_TRUE(clipped
);
2669 // Only the corner of the layer is not visible on the surface because of being
2670 // clipped. But, the net result of rounding visible region to an axis-aligned
2671 // rect is that the entire layer should still be considered visible.
2672 gfx::Rect expected
= gfx::Rect(-10, -10, 20, 20);
2673 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2674 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2675 EXPECT_EQ(expected
, actual
);
2678 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsForSimpleLayers
) {
2679 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2680 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2681 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2682 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2683 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2684 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2685 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2686 root
->AddChild(child1
);
2687 root
->AddChild(child2
);
2688 root
->AddChild(child3
);
2690 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2691 host
->SetRootLayer(root
);
2693 gfx::Transform identity_matrix
;
2694 SetLayerPropertiesForTesting(root
.get(),
2698 gfx::Size(100, 100),
2701 SetLayerPropertiesForTesting(child1
.get(),
2708 SetLayerPropertiesForTesting(child2
.get(),
2711 gfx::PointF(75.f
, 75.f
),
2715 SetLayerPropertiesForTesting(child3
.get(),
2718 gfx::PointF(125.f
, 125.f
),
2723 ExecuteCalculateDrawProperties(root
.get());
2725 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2726 root
->render_surface()->DrawableContentRect());
2727 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2729 // Layers that do not draw content should have empty visible_content_rects.
2730 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2732 // layer visible_content_rects are clipped by their target surface.
2733 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
2734 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_content_rect());
2735 EXPECT_TRUE(child3
->visible_content_rect().IsEmpty());
2737 // layer drawable_content_rects are not clipped.
2738 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->drawable_content_rect());
2739 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2740 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2743 TEST_F(LayerTreeHostCommonTest
,
2744 DrawableAndVisibleContentRectsForLayersClippedByLayer
) {
2745 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2746 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
2747 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child1
=
2748 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2749 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child2
=
2750 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2751 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child3
=
2752 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2753 root
->AddChild(child
);
2754 child
->AddChild(grand_child1
);
2755 child
->AddChild(grand_child2
);
2756 child
->AddChild(grand_child3
);
2758 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2759 host
->SetRootLayer(root
);
2761 gfx::Transform identity_matrix
;
2762 SetLayerPropertiesForTesting(root
.get(),
2766 gfx::Size(100, 100),
2769 SetLayerPropertiesForTesting(child
.get(),
2773 gfx::Size(100, 100),
2776 SetLayerPropertiesForTesting(grand_child1
.get(),
2779 gfx::PointF(5.f
, 5.f
),
2783 SetLayerPropertiesForTesting(grand_child2
.get(),
2786 gfx::PointF(75.f
, 75.f
),
2790 SetLayerPropertiesForTesting(grand_child3
.get(),
2793 gfx::PointF(125.f
, 125.f
),
2798 child
->SetMasksToBounds(true);
2799 ExecuteCalculateDrawProperties(root
.get());
2801 ASSERT_FALSE(child
->render_surface());
2803 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2804 root
->render_surface()->DrawableContentRect());
2805 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2807 // Layers that do not draw content should have empty visible content rects.
2808 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2809 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child
->visible_content_rect());
2811 // All grandchild visible content rects should be clipped by child.
2812 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1
->visible_content_rect());
2813 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2
->visible_content_rect());
2814 EXPECT_TRUE(grand_child3
->visible_content_rect().IsEmpty());
2816 // All grandchild DrawableContentRects should also be clipped by child.
2817 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1
->drawable_content_rect());
2818 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2
->drawable_content_rect());
2819 EXPECT_TRUE(grand_child3
->drawable_content_rect().IsEmpty());
2822 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectWithClippingAndScaling
) {
2823 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2824 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
2825 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
2826 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2827 root
->AddChild(child
);
2828 child
->AddChild(grand_child
);
2830 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2831 host
->SetRootLayer(root
);
2833 gfx::Transform identity_matrix
;
2834 gfx::Transform child_scale_matrix
;
2835 child_scale_matrix
.Scale(0.25f
, 0.25f
);
2836 gfx::Transform grand_child_scale_matrix
;
2837 grand_child_scale_matrix
.Scale(0.246f
, 0.246f
);
2838 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2839 gfx::PointF(), gfx::Size(100, 100), true, false);
2840 SetLayerPropertiesForTesting(child
.get(), child_scale_matrix
, gfx::Point3F(),
2841 gfx::PointF(), gfx::Size(10, 10), true, false);
2842 SetLayerPropertiesForTesting(grand_child
.get(), grand_child_scale_matrix
,
2843 gfx::Point3F(), gfx::PointF(),
2844 gfx::Size(100, 100), true, false);
2846 child
->SetMasksToBounds(true);
2847 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
2849 // The visible rect is expanded to integer coordinates in target space before
2850 // being projected back to layer space, where it is once again expanded to
2851 // integer coordinates.
2852 EXPECT_EQ(gfx::Rect(49, 49), grand_child
->visible_rect_from_property_trees());
2855 TEST_F(LayerTreeHostCommonTest
,
2856 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface
) {
2857 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2858 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
2859 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2860 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2861 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2862 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2863 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2864 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2865 root
->AddChild(render_surface1
);
2866 render_surface1
->AddChild(child1
);
2867 render_surface1
->AddChild(child2
);
2868 render_surface1
->AddChild(child3
);
2870 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2871 host
->SetRootLayer(root
);
2873 gfx::Transform identity_matrix
;
2874 SetLayerPropertiesForTesting(root
.get(),
2878 gfx::Size(100, 100),
2881 SetLayerPropertiesForTesting(render_surface1
.get(),
2888 SetLayerPropertiesForTesting(child1
.get(),
2891 gfx::PointF(5.f
, 5.f
),
2895 SetLayerPropertiesForTesting(child2
.get(),
2898 gfx::PointF(75.f
, 75.f
),
2902 SetLayerPropertiesForTesting(child3
.get(),
2905 gfx::PointF(125.f
, 125.f
),
2910 render_surface1
->SetForceRenderSurface(true);
2911 ExecuteCalculateDrawProperties(root
.get());
2913 ASSERT_TRUE(render_surface1
->render_surface());
2915 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2916 root
->render_surface()->DrawableContentRect());
2917 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2919 // Layers that do not draw content should have empty visible content rects.
2920 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2921 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_content_rect());
2923 // An unclipped surface grows its DrawableContentRect to include all drawable
2924 // regions of the subtree.
2925 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2926 render_surface1
->render_surface()->DrawableContentRect());
2928 // All layers that draw content into the unclipped surface are also unclipped.
2929 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
2930 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
2931 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
2933 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2934 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2935 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2938 TEST_F(LayerTreeHostCommonTest
,
2939 VisibleContentRectsForClippedSurfaceWithEmptyClip
) {
2940 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2941 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2942 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2943 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2944 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2945 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2946 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2947 root
->AddChild(child1
);
2948 root
->AddChild(child2
);
2949 root
->AddChild(child3
);
2951 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2952 host
->SetRootLayer(root
);
2954 gfx::Transform identity_matrix
;
2955 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2956 gfx::PointF(), gfx::Size(100, 100), true, false);
2957 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
, gfx::Point3F(),
2958 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2960 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
, gfx::Point3F(),
2961 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2963 SetLayerPropertiesForTesting(child3
.get(), identity_matrix
, gfx::Point3F(),
2964 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2967 RenderSurfaceLayerList render_surface_layer_list
;
2968 // Now set the root render surface an empty clip.
2969 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2970 root
.get(), gfx::Size(), &render_surface_layer_list
);
2972 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2973 ASSERT_TRUE(root
->render_surface());
2974 EXPECT_FALSE(root
->is_clipped());
2977 EXPECT_EQ(empty
, root
->render_surface()->clip_rect());
2978 EXPECT_TRUE(root
->render_surface()->is_clipped());
2980 // Visible content rect calculation will check if the target surface is
2981 // clipped or not. An empty clip rect does not indicate the render surface
2983 EXPECT_EQ(empty
, child1
->visible_content_rect());
2984 EXPECT_EQ(empty
, child2
->visible_content_rect());
2985 EXPECT_EQ(empty
, child3
->visible_content_rect());
2988 TEST_F(LayerTreeHostCommonTest
,
2989 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform
) {
2990 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
2991 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2992 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
2993 root
->AddChild(child
);
2995 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2996 host
->SetRootLayer(root
);
2998 // Case 1: a truly degenerate matrix
2999 gfx::Transform identity_matrix
;
3000 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3001 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
3003 SetLayerPropertiesForTesting(root
.get(),
3007 gfx::Size(100, 100),
3010 SetLayerPropertiesForTesting(child
.get(),
3011 uninvertible_matrix
,
3013 gfx::PointF(5.f
, 5.f
),
3018 ExecuteCalculateDrawProperties(root
.get());
3020 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
3021 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
3023 // Case 2: a matrix with flattened z, uninvertible and not visible according
3025 uninvertible_matrix
.MakeIdentity();
3026 uninvertible_matrix
.matrix().set(2, 2, 0.0);
3027 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
3029 SetLayerPropertiesForTesting(child
.get(),
3030 uninvertible_matrix
,
3032 gfx::PointF(5.f
, 5.f
),
3037 ExecuteCalculateDrawProperties(root
.get());
3039 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
3040 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
3042 // Case 3: a matrix with flattened z, also uninvertible and not visible.
3043 uninvertible_matrix
.MakeIdentity();
3044 uninvertible_matrix
.Translate(500.0, 0.0);
3045 uninvertible_matrix
.matrix().set(2, 2, 0.0);
3046 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
3048 SetLayerPropertiesForTesting(child
.get(),
3049 uninvertible_matrix
,
3051 gfx::PointF(5.f
, 5.f
),
3056 ExecuteCalculateDrawProperties(root
.get());
3058 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
3059 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
3062 TEST_F(LayerTreeHostCommonTest
,
3063 SingularTransformDoesNotPreventClearingDrawProperties
) {
3064 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3065 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
3066 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3067 root
->AddChild(child
);
3069 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3070 host
->SetRootLayer(root
);
3072 gfx::Transform identity_matrix
;
3073 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3074 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
3076 SetLayerPropertiesForTesting(root
.get(),
3077 uninvertible_matrix
,
3080 gfx::Size(100, 100),
3083 SetLayerPropertiesForTesting(child
.get(),
3086 gfx::PointF(5.f
, 5.f
),
3091 child
->set_sorted_for_recursion(true);
3093 TransformOperations start_transform_operations
;
3094 start_transform_operations
.AppendScale(1.f
, 0.f
, 0.f
);
3096 TransformOperations end_transform_operations
;
3097 end_transform_operations
.AppendScale(1.f
, 1.f
, 0.f
);
3099 AddAnimatedTransformToLayer(
3100 root
.get(), 10.0, start_transform_operations
, end_transform_operations
);
3102 EXPECT_TRUE(root
->TransformIsAnimating());
3104 ExecuteCalculateDrawProperties(root
.get());
3106 EXPECT_FALSE(child
->sorted_for_recursion());
3109 TEST_F(LayerTreeHostCommonTest
,
3110 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties
) {
3111 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3113 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3114 host
->SetRootLayer(root
);
3116 gfx::Transform identity_matrix
;
3117 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
3118 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
3120 SetLayerPropertiesForTesting(root
.get(),
3121 uninvertible_matrix
,
3124 gfx::Size(100, 100),
3128 root
->set_sorted_for_recursion(true);
3130 EXPECT_FALSE(root
->TransformIsAnimating());
3132 ExecuteCalculateDrawProperties(root
.get());
3134 EXPECT_FALSE(root
->sorted_for_recursion());
3137 TEST_F(LayerTreeHostCommonTest
,
3138 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface
) {
3139 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3140 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
3141 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3142 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3143 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3144 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3145 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
3146 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3147 root
->AddChild(render_surface1
);
3148 render_surface1
->AddChild(child1
);
3149 render_surface1
->AddChild(child2
);
3150 render_surface1
->AddChild(child3
);
3152 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3153 host
->SetRootLayer(root
);
3155 gfx::Transform identity_matrix
;
3156 SetLayerPropertiesForTesting(root
.get(),
3160 gfx::Size(100, 100),
3163 SetLayerPropertiesForTesting(render_surface1
.get(),
3170 SetLayerPropertiesForTesting(child1
.get(),
3173 gfx::PointF(5.f
, 5.f
),
3177 SetLayerPropertiesForTesting(child2
.get(),
3180 gfx::PointF(75.f
, 75.f
),
3184 SetLayerPropertiesForTesting(child3
.get(),
3187 gfx::PointF(125.f
, 125.f
),
3192 root
->SetMasksToBounds(true);
3193 render_surface1
->SetForceRenderSurface(true);
3194 ExecuteCalculateDrawProperties(root
.get());
3196 ASSERT_TRUE(render_surface1
->render_surface());
3198 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3199 root
->render_surface()->DrawableContentRect());
3200 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3202 // Layers that do not draw content should have empty visible content rects.
3203 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3204 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_content_rect());
3206 // A clipped surface grows its DrawableContentRect to include all drawable
3207 // regions of the subtree, but also gets clamped by the ancestor's clip.
3208 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3209 render_surface1
->render_surface()->DrawableContentRect());
3211 // All layers that draw content into the surface have their visible content
3212 // rect clipped by the surface clip rect.
3213 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3214 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_content_rect());
3215 EXPECT_TRUE(child3
->visible_content_rect().IsEmpty());
3217 // But the DrawableContentRects are unclipped.
3218 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3219 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3220 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3223 TEST_F(LayerTreeHostCommonTest
,
3224 DrawableAndVisibleContentRectsForSurfaceHierarchy
) {
3225 // Check that clipping does not propagate down surfaces.
3226 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3227 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
3228 scoped_refptr
<Layer
> render_surface2
= Layer::Create(layer_settings());
3229 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3230 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3231 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3232 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3233 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
3234 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3235 root
->AddChild(render_surface1
);
3236 render_surface1
->AddChild(render_surface2
);
3237 render_surface2
->AddChild(child1
);
3238 render_surface2
->AddChild(child2
);
3239 render_surface2
->AddChild(child3
);
3241 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3242 host
->SetRootLayer(root
);
3244 gfx::Transform identity_matrix
;
3245 SetLayerPropertiesForTesting(root
.get(),
3249 gfx::Size(100, 100),
3252 SetLayerPropertiesForTesting(render_surface1
.get(),
3259 SetLayerPropertiesForTesting(render_surface2
.get(),
3266 SetLayerPropertiesForTesting(child1
.get(),
3269 gfx::PointF(5.f
, 5.f
),
3273 SetLayerPropertiesForTesting(child2
.get(),
3276 gfx::PointF(75.f
, 75.f
),
3280 SetLayerPropertiesForTesting(child3
.get(),
3283 gfx::PointF(125.f
, 125.f
),
3288 root
->SetMasksToBounds(true);
3289 render_surface1
->SetForceRenderSurface(true);
3290 render_surface2
->SetForceRenderSurface(true);
3291 ExecuteCalculateDrawProperties(root
.get());
3293 ASSERT_TRUE(render_surface1
->render_surface());
3294 ASSERT_TRUE(render_surface2
->render_surface());
3296 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3297 root
->render_surface()->DrawableContentRect());
3298 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3300 // Layers that do not draw content should have empty visible content rects.
3301 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3302 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_content_rect());
3303 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2
->visible_content_rect());
3305 // A clipped surface grows its DrawableContentRect to include all drawable
3306 // regions of the subtree, but also gets clamped by the ancestor's clip.
3307 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3308 render_surface1
->render_surface()->DrawableContentRect());
3310 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3311 // is only implicitly clipped by render_surface1's content rect. So,
3312 // render_surface2 grows to enclose all drawable content of its subtree.
3313 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
3314 render_surface2
->render_surface()->DrawableContentRect());
3316 // All layers that draw content into render_surface2 think they are unclipped.
3317 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3318 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
3319 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
3321 // DrawableContentRects are also unclipped.
3322 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3323 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3324 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3327 TEST_F(LayerTreeHostCommonTest
,
3328 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface
) {
3329 // Layers that have non-axis aligned bounds (due to transforms) have an
3330 // expanded, axis-aligned DrawableContentRect and visible content rect.
3332 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3333 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
3334 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3335 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3336 root
->AddChild(render_surface1
);
3337 render_surface1
->AddChild(child1
);
3339 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3340 host
->SetRootLayer(root
);
3342 gfx::Transform identity_matrix
;
3343 gfx::Transform child_rotation
;
3344 child_rotation
.Rotate(45.0);
3345 SetLayerPropertiesForTesting(root
.get(),
3349 gfx::Size(100, 100),
3352 SetLayerPropertiesForTesting(render_surface1
.get(),
3359 SetLayerPropertiesForTesting(child1
.get(),
3361 gfx::Point3F(25, 25, 0.f
),
3362 gfx::PointF(25.f
, 25.f
),
3367 render_surface1
->SetForceRenderSurface(true);
3368 ExecuteCalculateDrawProperties(root
.get());
3370 ASSERT_TRUE(render_surface1
->render_surface());
3372 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3373 root
->render_surface()->DrawableContentRect());
3374 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3376 // Layers that do not draw content should have empty visible content rects.
3377 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3378 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_content_rect());
3380 // The unclipped surface grows its DrawableContentRect to include all drawable
3381 // regions of the subtree.
3382 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3383 gfx::Rect expected_surface_drawable_content
=
3384 gfx::Rect(50 - diagonal_radius
,
3385 50 - diagonal_radius
,
3386 diagonal_radius
* 2,
3387 diagonal_radius
* 2);
3388 EXPECT_EQ(expected_surface_drawable_content
,
3389 render_surface1
->render_surface()->DrawableContentRect());
3391 // All layers that draw content into the unclipped surface are also unclipped.
3392 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3393 EXPECT_EQ(expected_surface_drawable_content
, child1
->drawable_content_rect());
3396 TEST_F(LayerTreeHostCommonTest
,
3397 DrawableAndVisibleContentRectsWithTransformOnClippedSurface
) {
3398 // Layers that have non-axis aligned bounds (due to transforms) have an
3399 // expanded, axis-aligned DrawableContentRect and visible content rect.
3401 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3402 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
3403 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3404 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3405 root
->AddChild(render_surface1
);
3406 render_surface1
->AddChild(child1
);
3408 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3409 host
->SetRootLayer(root
);
3411 gfx::Transform identity_matrix
;
3412 gfx::Transform child_rotation
;
3413 child_rotation
.Rotate(45.0);
3414 SetLayerPropertiesForTesting(root
.get(),
3421 SetLayerPropertiesForTesting(render_surface1
.get(),
3429 SetLayerPropertiesForTesting(child1
.get(),
3431 gfx::Point3F(25, 25, 0.f
),
3432 gfx::PointF(25.f
, 25.f
),
3437 root
->SetMasksToBounds(true);
3438 render_surface1
->SetForceRenderSurface(true);
3439 ExecuteCalculateDrawProperties(root
.get());
3441 ASSERT_TRUE(render_surface1
->render_surface());
3443 // The clipped surface clamps the DrawableContentRect that encloses the
3445 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3446 gfx::Rect unclipped_surface_content
= gfx::Rect(50 - diagonal_radius
,
3447 50 - diagonal_radius
,
3448 diagonal_radius
* 2,
3449 diagonal_radius
* 2);
3450 gfx::Rect expected_surface_drawable_content
=
3451 gfx::IntersectRects(unclipped_surface_content
, gfx::Rect(0, 0, 50, 50));
3452 EXPECT_EQ(expected_surface_drawable_content
,
3453 render_surface1
->render_surface()->DrawableContentRect());
3455 // On the clipped surface, only a quarter of the child1 is visible, but when
3456 // rotating it back to child1's content space, the actual enclosing rect ends
3457 // up covering the full left half of child1.
3459 // Given the floating point math, this number is a little bit fuzzy.
3460 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1
->visible_content_rect());
3462 // The child's DrawableContentRect is unclipped.
3463 EXPECT_EQ(unclipped_surface_content
, child1
->drawable_content_rect());
3466 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsInHighDPI
) {
3467 MockContentLayerClient client
;
3469 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
3470 scoped_refptr
<FakePictureLayer
> render_surface1
=
3471 CreateDrawablePictureLayer(layer_settings(), &client
);
3472 scoped_refptr
<FakePictureLayer
> render_surface2
=
3473 CreateDrawablePictureLayer(layer_settings(), &client
);
3474 scoped_refptr
<FakePictureLayer
> child1
=
3475 CreateDrawablePictureLayer(layer_settings(), &client
);
3476 scoped_refptr
<FakePictureLayer
> child2
=
3477 CreateDrawablePictureLayer(layer_settings(), &client
);
3478 scoped_refptr
<FakePictureLayer
> child3
=
3479 CreateDrawablePictureLayer(layer_settings(), &client
);
3480 root
->AddChild(render_surface1
);
3481 render_surface1
->AddChild(render_surface2
);
3482 render_surface2
->AddChild(child1
);
3483 render_surface2
->AddChild(child2
);
3484 render_surface2
->AddChild(child3
);
3486 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3487 host
->SetRootLayer(root
);
3489 gfx::Transform identity_matrix
;
3490 SetLayerPropertiesForTesting(root
.get(),
3494 gfx::Size(100, 100),
3497 SetLayerPropertiesForTesting(render_surface1
.get(),
3500 gfx::PointF(5.f
, 5.f
),
3504 SetLayerPropertiesForTesting(render_surface2
.get(),
3507 gfx::PointF(5.f
, 5.f
),
3511 SetLayerPropertiesForTesting(child1
.get(),
3514 gfx::PointF(5.f
, 5.f
),
3518 SetLayerPropertiesForTesting(child2
.get(),
3521 gfx::PointF(75.f
, 75.f
),
3525 SetLayerPropertiesForTesting(child3
.get(),
3528 gfx::PointF(125.f
, 125.f
),
3533 float device_scale_factor
= 2.f
;
3535 root
->SetMasksToBounds(true);
3536 render_surface1
->SetForceRenderSurface(true);
3537 render_surface2
->SetForceRenderSurface(true);
3538 ExecuteCalculateDrawProperties(root
.get(), device_scale_factor
);
3540 ASSERT_TRUE(render_surface1
->render_surface());
3541 ASSERT_TRUE(render_surface2
->render_surface());
3543 // drawable_content_rects for all layers and surfaces are scaled by
3544 // device_scale_factor.
3545 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3546 root
->render_surface()->DrawableContentRect());
3547 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root
->drawable_content_rect());
3548 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3549 render_surface1
->render_surface()->DrawableContentRect());
3551 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3552 // is only implicitly clipped by render_surface1.
3553 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3554 render_surface2
->render_surface()->DrawableContentRect());
3556 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1
->drawable_content_rect());
3557 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2
->drawable_content_rect());
3558 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3
->drawable_content_rect());
3560 // The root layer does not actually draw content of its own.
3561 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3563 // All layer visible content rects are not expressed in content space of each
3564 // layer, so they are not scaled by the device_scale_factor.
3565 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1
->visible_content_rect());
3566 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2
->visible_content_rect());
3567 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3568 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
3569 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
3572 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithoutPreserves3d
) {
3573 // Verify the behavior of back-face culling when there are no preserve-3d
3574 // layers. Note that 3d transforms still apply in this case, but they are
3575 // "flattened" to each parent layer according to current W3C spec.
3577 const gfx::Transform identity_matrix
;
3578 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3579 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3580 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3581 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3582 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3583 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3584 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3585 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3586 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3587 scoped_refptr
<LayerWithForcedDrawsContent
>
3588 front_facing_child_of_front_facing_surface
=
3589 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3590 scoped_refptr
<LayerWithForcedDrawsContent
>
3591 back_facing_child_of_front_facing_surface
=
3592 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3593 scoped_refptr
<LayerWithForcedDrawsContent
>
3594 front_facing_child_of_back_facing_surface
=
3595 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3596 scoped_refptr
<LayerWithForcedDrawsContent
>
3597 back_facing_child_of_back_facing_surface
=
3598 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3600 parent
->AddChild(front_facing_child
);
3601 parent
->AddChild(back_facing_child
);
3602 parent
->AddChild(front_facing_surface
);
3603 parent
->AddChild(back_facing_surface
);
3604 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3605 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3606 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3607 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3609 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3610 host
->SetRootLayer(parent
);
3612 // Nothing is double-sided
3613 front_facing_child
->SetDoubleSided(false);
3614 back_facing_child
->SetDoubleSided(false);
3615 front_facing_surface
->SetDoubleSided(false);
3616 back_facing_surface
->SetDoubleSided(false);
3617 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3618 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3619 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3620 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3622 gfx::Transform backface_matrix
;
3623 backface_matrix
.Translate(50.0, 50.0);
3624 backface_matrix
.RotateAboutYAxis(180.0);
3625 backface_matrix
.Translate(-50.0, -50.0);
3627 // Having a descendant and opacity will force these to have render surfaces.
3628 front_facing_surface
->SetOpacity(0.5f
);
3629 back_facing_surface
->SetOpacity(0.5f
);
3631 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3632 // these layers should blindly use their own local transforms to determine
3633 // back-face culling.
3634 SetLayerPropertiesForTesting(parent
.get(),
3638 gfx::Size(100, 100),
3641 SetLayerPropertiesForTesting(front_facing_child
.get(),
3645 gfx::Size(100, 100),
3648 SetLayerPropertiesForTesting(back_facing_child
.get(),
3652 gfx::Size(100, 100),
3655 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3659 gfx::Size(100, 100),
3662 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3666 gfx::Size(100, 100),
3669 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3673 gfx::Size(100, 100),
3676 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3680 gfx::Size(100, 100),
3683 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3687 gfx::Size(100, 100),
3690 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3694 gfx::Size(100, 100),
3698 RenderSurfaceLayerList render_surface_layer_list
;
3699 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3700 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3701 inputs
.can_adjust_raster_scales
= true;
3702 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3704 // Verify which render surfaces were created.
3705 EXPECT_FALSE(front_facing_child
->render_surface());
3706 EXPECT_FALSE(back_facing_child
->render_surface());
3707 EXPECT_TRUE(front_facing_surface
->render_surface());
3708 EXPECT_TRUE(back_facing_surface
->render_surface());
3709 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3710 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3711 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3712 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3714 // Verify the render_surface_layer_list.
3715 ASSERT_EQ(3u, render_surface_layer_list
.size());
3716 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3717 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3718 // Even though the back facing surface LAYER gets culled, the other
3719 // descendants should still be added, so the SURFACE should not be culled.
3720 EXPECT_EQ(back_facing_surface
->id(), render_surface_layer_list
.at(2)->id());
3722 // Verify root surface's layer list.
3725 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3726 EXPECT_EQ(front_facing_child
->id(),
3727 render_surface_layer_list
.at(0)
3732 EXPECT_EQ(front_facing_surface
->id(),
3733 render_surface_layer_list
.at(0)
3738 EXPECT_EQ(back_facing_surface
->id(),
3739 render_surface_layer_list
.at(0)
3745 // Verify front_facing_surface's layer list.
3748 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3749 EXPECT_EQ(front_facing_surface
->id(),
3750 render_surface_layer_list
.at(1)
3755 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3756 render_surface_layer_list
.at(1)
3762 // Verify back_facing_surface's layer list; its own layer should be culled
3763 // from the surface list.
3766 render_surface_layer_list
.at(2)->render_surface()->layer_list().size());
3767 EXPECT_EQ(front_facing_child_of_back_facing_surface
->id(),
3768 render_surface_layer_list
.at(2)
3775 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithPreserves3d
) {
3776 // Verify the behavior of back-face culling when preserves-3d transform style
3779 const gfx::Transform identity_matrix
;
3780 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3781 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3782 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3783 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3784 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3785 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3786 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3787 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3788 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3789 scoped_refptr
<LayerWithForcedDrawsContent
>
3790 front_facing_child_of_front_facing_surface
=
3791 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3792 scoped_refptr
<LayerWithForcedDrawsContent
>
3793 back_facing_child_of_front_facing_surface
=
3794 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3795 scoped_refptr
<LayerWithForcedDrawsContent
>
3796 front_facing_child_of_back_facing_surface
=
3797 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3798 scoped_refptr
<LayerWithForcedDrawsContent
>
3799 back_facing_child_of_back_facing_surface
=
3800 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3801 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer1
=
3802 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3803 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer2
=
3804 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3806 parent
->AddChild(front_facing_child
);
3807 parent
->AddChild(back_facing_child
);
3808 parent
->AddChild(front_facing_surface
);
3809 parent
->AddChild(back_facing_surface
);
3810 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3811 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3812 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3813 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3815 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3816 host
->SetRootLayer(parent
);
3818 // Nothing is double-sided
3819 front_facing_child
->SetDoubleSided(false);
3820 back_facing_child
->SetDoubleSided(false);
3821 front_facing_surface
->SetDoubleSided(false);
3822 back_facing_surface
->SetDoubleSided(false);
3823 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3824 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3825 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3826 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3828 gfx::Transform backface_matrix
;
3829 backface_matrix
.Translate(50.0, 50.0);
3830 backface_matrix
.RotateAboutYAxis(180.0);
3831 backface_matrix
.Translate(-50.0, -50.0);
3833 // Opacity will not force creation of render surfaces in this case because of
3834 // the preserve-3d transform style. Instead, an example of when a surface
3835 // would be created with preserve-3d is when there is a replica layer.
3836 front_facing_surface
->SetReplicaLayer(dummy_replica_layer1
.get());
3837 back_facing_surface
->SetReplicaLayer(dummy_replica_layer2
.get());
3839 // Each surface creates its own new 3d rendering context (as defined by W3C
3840 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3841 // rendering context should use the transform with respect to that context.
3842 // This 3d rendering context occurs when (a) parent's transform style is flat
3843 // and (b) the layer's transform style is preserve-3d.
3844 SetLayerPropertiesForTesting(parent
.get(),
3848 gfx::Size(100, 100),
3850 false); // parent transform style is flat.
3851 SetLayerPropertiesForTesting(front_facing_child
.get(),
3855 gfx::Size(100, 100),
3858 SetLayerPropertiesForTesting(back_facing_child
.get(),
3862 gfx::Size(100, 100),
3865 // surface transform style is preserve-3d.
3866 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3870 gfx::Size(100, 100),
3873 // surface transform style is preserve-3d.
3874 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3878 gfx::Size(100, 100),
3881 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3885 gfx::Size(100, 100),
3888 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3892 gfx::Size(100, 100),
3895 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3899 gfx::Size(100, 100),
3902 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3906 gfx::Size(100, 100),
3910 RenderSurfaceLayerList render_surface_layer_list
;
3911 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3912 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3913 inputs
.can_adjust_raster_scales
= true;
3914 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3916 // Verify which render surfaces were created and used.
3917 EXPECT_FALSE(front_facing_child
->render_surface());
3918 EXPECT_FALSE(back_facing_child
->render_surface());
3919 EXPECT_TRUE(front_facing_surface
->render_surface());
3920 EXPECT_NE(back_facing_surface
->render_target(), back_facing_surface
);
3921 // We expect that a render_surface was created but not used.
3922 EXPECT_TRUE(back_facing_surface
->render_surface());
3923 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3924 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3925 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3926 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3928 // Verify the render_surface_layer_list. The back-facing surface should be
3930 ASSERT_EQ(2u, render_surface_layer_list
.size());
3931 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3932 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3934 // Verify root surface's layer list.
3937 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3938 EXPECT_EQ(front_facing_child
->id(),
3939 render_surface_layer_list
.at(0)
3940 ->render_surface()->layer_list().at(0)->id());
3941 EXPECT_EQ(front_facing_surface
->id(),
3942 render_surface_layer_list
.at(0)
3943 ->render_surface()->layer_list().at(1)->id());
3945 // Verify front_facing_surface's layer list.
3948 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3949 EXPECT_EQ(front_facing_surface
->id(),
3950 render_surface_layer_list
.at(1)
3951 ->render_surface()->layer_list().at(0)->id());
3952 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3953 render_surface_layer_list
.at(1)
3954 ->render_surface()->layer_list().at(1)->id());
3957 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithAnimatingTransforms
) {
3958 // Verify that layers are appropriately culled when their back face is showing
3959 // and they are not double sided, while animations are going on.
3961 // Layers that are animating do not get culled on the main thread, as their
3962 // transforms should be treated as "unknown" so we can not be sure that their
3963 // back face is really showing.
3964 const gfx::Transform identity_matrix
;
3965 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
3966 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
3967 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3968 scoped_refptr
<LayerWithForcedDrawsContent
> animating_surface
=
3969 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3970 scoped_refptr
<LayerWithForcedDrawsContent
> child_of_animating_surface
=
3971 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3972 scoped_refptr
<LayerWithForcedDrawsContent
> animating_child
=
3973 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3974 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3975 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
3977 parent
->AddChild(child
);
3978 parent
->AddChild(animating_surface
);
3979 animating_surface
->AddChild(child_of_animating_surface
);
3980 parent
->AddChild(animating_child
);
3981 parent
->AddChild(child2
);
3983 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3984 host
->SetRootLayer(parent
);
3986 // Nothing is double-sided
3987 child
->SetDoubleSided(false);
3988 child2
->SetDoubleSided(false);
3989 animating_surface
->SetDoubleSided(false);
3990 child_of_animating_surface
->SetDoubleSided(false);
3991 animating_child
->SetDoubleSided(false);
3993 gfx::Transform backface_matrix
;
3994 backface_matrix
.Translate(50.0, 50.0);
3995 backface_matrix
.RotateAboutYAxis(180.0);
3996 backface_matrix
.Translate(-50.0, -50.0);
3998 // Make our render surface.
3999 animating_surface
->SetForceRenderSurface(true);
4001 // Animate the transform on the render surface.
4002 AddAnimatedTransformToController(
4003 animating_surface
->layer_animation_controller(), 10.0, 30, 0);
4004 // This is just an animating layer, not a surface.
4005 AddAnimatedTransformToController(
4006 animating_child
->layer_animation_controller(), 10.0, 30, 0);
4008 SetLayerPropertiesForTesting(parent
.get(),
4012 gfx::Size(100, 100),
4015 SetLayerPropertiesForTesting(child
.get(),
4019 gfx::Size(100, 100),
4022 SetLayerPropertiesForTesting(animating_surface
.get(),
4026 gfx::Size(100, 100),
4029 SetLayerPropertiesForTesting(child_of_animating_surface
.get(),
4033 gfx::Size(100, 100),
4036 SetLayerPropertiesForTesting(animating_child
.get(),
4040 gfx::Size(100, 100),
4043 SetLayerPropertiesForTesting(child2
.get(),
4047 gfx::Size(100, 100),
4051 RenderSurfaceLayerList render_surface_layer_list
;
4052 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4053 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4054 inputs
.can_adjust_raster_scales
= true;
4055 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4057 EXPECT_FALSE(child
->render_surface());
4058 EXPECT_TRUE(animating_surface
->render_surface());
4059 EXPECT_FALSE(child_of_animating_surface
->render_surface());
4060 EXPECT_FALSE(animating_child
->render_surface());
4061 EXPECT_FALSE(child2
->render_surface());
4063 // Verify that the animating_child and child_of_animating_surface were not
4064 // culled, but that child was.
4065 ASSERT_EQ(2u, render_surface_layer_list
.size());
4066 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
4067 EXPECT_EQ(animating_surface
->id(), render_surface_layer_list
.at(1)->id());
4069 // The non-animating child be culled from the layer list for the parent render
4073 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
4074 EXPECT_EQ(animating_surface
->id(),
4075 render_surface_layer_list
.at(0)
4076 ->render_surface()->layer_list().at(0)->id());
4077 EXPECT_EQ(animating_child
->id(),
4078 render_surface_layer_list
.at(0)
4079 ->render_surface()->layer_list().at(1)->id());
4080 EXPECT_EQ(child2
->id(),
4081 render_surface_layer_list
.at(0)
4082 ->render_surface()->layer_list().at(2)->id());
4086 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
4087 EXPECT_EQ(animating_surface
->id(),
4088 render_surface_layer_list
.at(1)
4089 ->render_surface()->layer_list().at(0)->id());
4090 EXPECT_EQ(child_of_animating_surface
->id(),
4091 render_surface_layer_list
.at(1)
4092 ->render_surface()->layer_list().at(1)->id());
4094 EXPECT_FALSE(child2
->visible_content_rect().IsEmpty());
4096 // The animating layers should have a visible content rect that represents the
4097 // area of the front face that is within the viewport.
4098 EXPECT_EQ(animating_child
->visible_content_rect(),
4099 gfx::Rect(animating_child
->content_bounds()));
4100 EXPECT_EQ(animating_surface
->visible_content_rect(),
4101 gfx::Rect(animating_surface
->content_bounds()));
4102 // And layers in the subtree of the animating layer should have valid visible
4103 // content rects also.
4104 EXPECT_EQ(child_of_animating_surface
->visible_content_rect(),
4105 gfx::Rect(child_of_animating_surface
->content_bounds()));
4108 TEST_F(LayerTreeHostCommonTest
,
4109 BackFaceCullingWithPreserves3dForFlatteningSurface
) {
4110 // Verify the behavior of back-face culling for a render surface that is
4111 // created when it flattens its subtree, and its parent has preserves-3d.
4113 const gfx::Transform identity_matrix
;
4114 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
4115 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
4116 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4117 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
4118 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4119 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
4120 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4121 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
4122 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
4124 parent
->AddChild(front_facing_surface
);
4125 parent
->AddChild(back_facing_surface
);
4126 front_facing_surface
->AddChild(child1
);
4127 back_facing_surface
->AddChild(child2
);
4129 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4130 host
->SetRootLayer(parent
);
4132 // RenderSurfaces are not double-sided
4133 front_facing_surface
->SetDoubleSided(false);
4134 back_facing_surface
->SetDoubleSided(false);
4136 gfx::Transform backface_matrix
;
4137 backface_matrix
.Translate(50.0, 50.0);
4138 backface_matrix
.RotateAboutYAxis(180.0);
4139 backface_matrix
.Translate(-50.0, -50.0);
4141 SetLayerPropertiesForTesting(parent
.get(),
4145 gfx::Size(100, 100),
4147 true); // parent transform style is preserve3d.
4148 SetLayerPropertiesForTesting(front_facing_surface
.get(),
4152 gfx::Size(100, 100),
4154 true); // surface transform style is flat.
4155 SetLayerPropertiesForTesting(back_facing_surface
.get(),
4159 gfx::Size(100, 100),
4161 true); // surface transform style is flat.
4162 SetLayerPropertiesForTesting(child1
.get(),
4166 gfx::Size(100, 100),
4169 SetLayerPropertiesForTesting(child2
.get(),
4173 gfx::Size(100, 100),
4177 front_facing_surface
->Set3dSortingContextId(1);
4178 back_facing_surface
->Set3dSortingContextId(1);
4180 RenderSurfaceLayerList render_surface_layer_list
;
4181 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4182 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4183 inputs
.can_adjust_raster_scales
= true;
4184 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4186 // Verify which render surfaces were created and used.
4187 EXPECT_TRUE(front_facing_surface
->render_surface());
4189 // We expect the render surface to have been created, but remain unused.
4190 EXPECT_TRUE(back_facing_surface
->render_surface());
4191 EXPECT_NE(back_facing_surface
->render_target(),
4192 back_facing_surface
); // because it should be culled
4193 EXPECT_FALSE(child1
->render_surface());
4194 EXPECT_FALSE(child2
->render_surface());
4196 // Verify the render_surface_layer_list. The back-facing surface should be
4198 ASSERT_EQ(2u, render_surface_layer_list
.size());
4199 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
4200 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
4202 // Verify root surface's layer list.
4205 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
4206 EXPECT_EQ(front_facing_surface
->id(),
4207 render_surface_layer_list
.at(0)
4208 ->render_surface()->layer_list().at(0)->id());
4210 // Verify front_facing_surface's layer list.
4213 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
4214 EXPECT_EQ(front_facing_surface
->id(),
4215 render_surface_layer_list
.at(1)
4216 ->render_surface()->layer_list().at(0)->id());
4217 EXPECT_EQ(child1
->id(),
4218 render_surface_layer_list
.at(1)
4219 ->render_surface()->layer_list().at(1)->id());
4222 class NoScaleContentLayer
: public ContentLayer
{
4224 static scoped_refptr
<NoScaleContentLayer
> Create(
4225 const LayerSettings
& settings
,
4226 ContentLayerClient
* client
) {
4227 return make_scoped_refptr(new NoScaleContentLayer(settings
, client
));
4230 void CalculateContentsScale(float ideal_contents_scale
,
4231 float* contents_scale_x
,
4232 float* contents_scale_y
,
4233 gfx::Size
* content_bounds
) override
{
4234 // Skip over the ContentLayer to the base Layer class.
4235 Layer::CalculateContentsScale(ideal_contents_scale
,
4242 NoScaleContentLayer(const LayerSettings
& settings
, ContentLayerClient
* client
)
4243 : ContentLayer(settings
, client
) {}
4244 ~NoScaleContentLayer() override
{}
4247 scoped_refptr
<NoScaleContentLayer
> CreateNoScaleDrawableContentLayer(
4248 const LayerSettings
& settings
,
4249 ContentLayerClient
* delegate
) {
4250 scoped_refptr
<NoScaleContentLayer
> to_return
=
4251 NoScaleContentLayer::Create(settings
, delegate
);
4252 to_return
->SetIsDrawable(true);
4256 TEST_F(LayerTreeHostCommonTest
, LayerTransformsInHighDPI
) {
4257 // Verify draw and screen space transforms of layers not in a surface.
4258 MockContentLayerClient delegate
;
4259 gfx::Transform identity_matrix
;
4261 scoped_refptr
<FakePictureLayer
> parent
=
4262 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4263 SetLayerPropertiesForTesting(parent
.get(),
4267 gfx::Size(100, 100),
4271 scoped_refptr
<FakePictureLayer
> child
=
4272 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4273 SetLayerPropertiesForTesting(child
.get(),
4276 gfx::PointF(2.f
, 2.f
),
4281 scoped_refptr
<FakePictureLayer
> child_empty
=
4282 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4283 SetLayerPropertiesForTesting(child_empty
.get(),
4286 gfx::PointF(2.f
, 2.f
),
4291 parent
->AddChild(child
);
4292 parent
->AddChild(child_empty
);
4294 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4295 host
->SetRootLayer(parent
);
4297 float device_scale_factor
= 2.5f
;
4298 float page_scale_factor
= 1.f
;
4300 RenderSurfaceLayerList render_surface_layer_list
;
4301 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4302 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4303 inputs
.device_scale_factor
= device_scale_factor
;
4304 inputs
.page_scale_factor
= page_scale_factor
;
4305 inputs
.can_adjust_raster_scales
= true;
4306 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4308 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4309 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, child
);
4310 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, child_empty
);
4312 EXPECT_EQ(1u, render_surface_layer_list
.size());
4314 // Verify parent transforms
4315 gfx::Transform expected_parent_transform
;
4316 expected_parent_transform
.Scale(device_scale_factor
* page_scale_factor
,
4317 device_scale_factor
* page_scale_factor
);
4318 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4319 parent
->screen_space_transform());
4320 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4321 parent
->draw_transform());
4323 // Verify results of transformed parent rects
4324 gfx::RectF
parent_content_bounds(parent
->content_bounds());
4326 gfx::RectF parent_draw_rect
=
4327 MathUtil::MapClippedRect(parent
->draw_transform(), parent_content_bounds
);
4328 gfx::RectF parent_screen_space_rect
= MathUtil::MapClippedRect(
4329 parent
->screen_space_transform(), parent_content_bounds
);
4331 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4332 expected_parent_draw_rect
.Scale(device_scale_factor
);
4333 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4334 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4336 // Verify child and child_empty transforms. They should match.
4337 gfx::Transform expected_child_transform
;
4338 expected_child_transform
.Scale(device_scale_factor
, device_scale_factor
);
4339 expected_child_transform
.Translate(child
->position().x(),
4340 child
->position().y());
4341 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4342 child
->draw_transform());
4343 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4344 child
->screen_space_transform());
4345 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4346 child_empty
->draw_transform());
4347 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4348 child_empty
->screen_space_transform());
4350 // Verify results of transformed child and child_empty rects. They should
4352 gfx::RectF
child_content_bounds(child
->content_bounds());
4354 gfx::RectF child_draw_rect
=
4355 MathUtil::MapClippedRect(child
->draw_transform(), child_content_bounds
);
4356 gfx::RectF child_screen_space_rect
= MathUtil::MapClippedRect(
4357 child
->screen_space_transform(), child_content_bounds
);
4359 gfx::RectF child_empty_draw_rect
= MathUtil::MapClippedRect(
4360 child_empty
->draw_transform(), child_content_bounds
);
4361 gfx::RectF child_empty_screen_space_rect
= MathUtil::MapClippedRect(
4362 child_empty
->screen_space_transform(), child_content_bounds
);
4364 gfx::RectF
expected_child_draw_rect(child
->position(), child
->bounds());
4365 expected_child_draw_rect
.Scale(device_scale_factor
);
4366 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4367 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4368 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_draw_rect
);
4369 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_screen_space_rect
);
4372 TEST_F(LayerTreeHostCommonTest
, SurfaceLayerTransformsInHighDPI
) {
4373 // Verify draw and screen space transforms of layers in a surface.
4374 MockContentLayerClient delegate
;
4375 gfx::Transform identity_matrix
;
4377 gfx::Transform perspective_matrix
;
4378 perspective_matrix
.ApplyPerspectiveDepth(2.0);
4380 gfx::Transform scale_small_matrix
;
4381 scale_small_matrix
.Scale(SK_MScalar1
/ 10.f
, SK_MScalar1
/ 12.f
);
4383 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4385 scoped_refptr
<FakePictureLayer
> parent
=
4386 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4387 SetLayerPropertiesForTesting(parent
.get(),
4391 gfx::Size(100, 100),
4395 scoped_refptr
<FakePictureLayer
> perspective_surface
=
4396 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4397 SetLayerPropertiesForTesting(perspective_surface
.get(),
4398 perspective_matrix
* scale_small_matrix
,
4400 gfx::PointF(2.f
, 2.f
),
4405 scoped_refptr
<FakePictureLayer
> scale_surface
=
4406 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4407 SetLayerPropertiesForTesting(scale_surface
.get(),
4410 gfx::PointF(2.f
, 2.f
),
4415 perspective_surface
->SetForceRenderSurface(true);
4416 scale_surface
->SetForceRenderSurface(true);
4418 parent
->AddChild(perspective_surface
);
4419 parent
->AddChild(scale_surface
);
4420 root
->AddChild(parent
);
4422 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4423 host
->SetRootLayer(root
);
4425 float device_scale_factor
= 2.5f
;
4426 float page_scale_factor
= 3.f
;
4428 RenderSurfaceLayerList render_surface_layer_list
;
4429 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4430 root
.get(), parent
->bounds(), &render_surface_layer_list
);
4431 inputs
.device_scale_factor
= device_scale_factor
;
4432 inputs
.page_scale_factor
= page_scale_factor
;
4433 inputs
.page_scale_application_layer
= root
.get();
4434 inputs
.can_adjust_raster_scales
= true;
4435 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4437 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4438 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4439 perspective_surface
);
4440 // Ideal scale is the max 2d scale component of the combined transform up to
4441 // the nearest render target. Here this includes the layer transform as well
4442 // as the device and page scale factors.
4443 gfx::Transform transform
= scale_small_matrix
;
4444 transform
.Scale(device_scale_factor
* page_scale_factor
,
4445 device_scale_factor
* page_scale_factor
);
4446 gfx::Vector2dF scales
=
4447 MathUtil::ComputeTransform2dScaleComponents(transform
, 0.f
);
4448 float max_2d_scale
= std::max(scales
.x(), scales
.y());
4449 EXPECT_IDEAL_SCALE_EQ(max_2d_scale
, scale_surface
);
4451 // The ideal scale will draw 1:1 with its render target space along
4452 // the larger-scale axis.
4453 gfx::Vector2dF target_space_transform_scales
=
4454 MathUtil::ComputeTransform2dScaleComponents(
4455 scale_surface
->draw_properties().target_space_transform
, 0.f
);
4456 EXPECT_FLOAT_EQ(max_2d_scale
,
4457 std::max(target_space_transform_scales
.x(),
4458 target_space_transform_scales
.y()));
4460 EXPECT_EQ(3u, render_surface_layer_list
.size());
4462 gfx::Transform expected_parent_draw_transform
;
4463 expected_parent_draw_transform
.Scale(device_scale_factor
* page_scale_factor
,
4464 device_scale_factor
* page_scale_factor
);
4465 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform
,
4466 parent
->draw_transform());
4468 // The scale for the perspective surface is not known, so it is rendered 1:1
4469 // with the screen, and then scaled during drawing.
4470 gfx::Transform expected_perspective_surface_draw_transform
;
4471 expected_perspective_surface_draw_transform
.Translate(
4472 device_scale_factor
* page_scale_factor
*
4473 perspective_surface
->position().x(),
4474 device_scale_factor
* page_scale_factor
*
4475 perspective_surface
->position().y());
4476 expected_perspective_surface_draw_transform
.PreconcatTransform(
4477 perspective_matrix
);
4478 expected_perspective_surface_draw_transform
.PreconcatTransform(
4479 scale_small_matrix
);
4480 gfx::Transform expected_perspective_surface_layer_draw_transform
;
4481 expected_perspective_surface_layer_draw_transform
.Scale(
4482 device_scale_factor
* page_scale_factor
,
4483 device_scale_factor
* page_scale_factor
);
4484 EXPECT_TRANSFORMATION_MATRIX_EQ(
4485 expected_perspective_surface_draw_transform
,
4486 perspective_surface
->render_surface()->draw_transform());
4487 EXPECT_TRANSFORMATION_MATRIX_EQ(
4488 expected_perspective_surface_layer_draw_transform
,
4489 perspective_surface
->draw_transform());
4492 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4493 TEST_F(LayerTreeHostCommonTest
,
4494 LayerTransformsInHighDPIAccurateScaleZeroChildPosition
) {
4495 // Verify draw and screen space transforms of layers not in a surface.
4496 MockContentLayerClient delegate
;
4497 gfx::Transform identity_matrix
;
4499 scoped_refptr
<ContentLayer
> parent
=
4500 CreateDrawableContentLayer(layer_settings(), &delegate
);
4501 SetLayerPropertiesForTesting(parent
.get(),
4505 gfx::Size(133, 133),
4509 scoped_refptr
<ContentLayer
> child
=
4510 CreateDrawableContentLayer(layer_settings(), &delegate
);
4511 SetLayerPropertiesForTesting(child
.get(),
4519 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4520 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate
);
4521 SetLayerPropertiesForTesting(child_no_scale
.get(),
4529 parent
->AddChild(child
);
4530 parent
->AddChild(child_no_scale
);
4532 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4533 host
->SetRootLayer(parent
);
4535 float device_scale_factor
= 1.7f
;
4536 float page_scale_factor
= 1.f
;
4538 RenderSurfaceLayerList render_surface_layer_list
;
4539 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4540 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4541 inputs
.device_scale_factor
= device_scale_factor
;
4542 inputs
.page_scale_factor
= page_scale_factor
;
4543 inputs
.page_scale_application_layer
= parent
.get();
4544 inputs
.can_adjust_raster_scales
= true;
4545 inputs
.verify_property_trees
= false;
4546 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4548 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4549 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, child
);
4550 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4552 EXPECT_EQ(1u, render_surface_layer_list
.size());
4554 // Verify parent transforms
4555 gfx::Transform expected_parent_transform
;
4556 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4557 parent
->screen_space_transform());
4558 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4559 parent
->draw_transform());
4561 // Verify results of transformed parent rects
4562 gfx::RectF
parent_content_bounds(parent
->content_bounds());
4564 gfx::RectF parent_draw_rect
=
4565 MathUtil::MapClippedRect(parent
->draw_transform(), parent_content_bounds
);
4566 gfx::RectF parent_screen_space_rect
= MathUtil::MapClippedRect(
4567 parent
->screen_space_transform(), parent_content_bounds
);
4569 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4570 expected_parent_draw_rect
.Scale(device_scale_factor
);
4571 expected_parent_draw_rect
.set_width(ceil(expected_parent_draw_rect
.width()));
4572 expected_parent_draw_rect
.set_height(
4573 ceil(expected_parent_draw_rect
.height()));
4574 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4575 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4577 // Verify child transforms
4578 gfx::Transform expected_child_transform
;
4579 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4580 child
->draw_transform());
4581 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4582 child
->screen_space_transform());
4584 // Verify results of transformed child rects
4585 gfx::RectF
child_content_bounds(child
->content_bounds());
4587 gfx::RectF child_draw_rect
=
4588 MathUtil::MapClippedRect(child
->draw_transform(), child_content_bounds
);
4589 gfx::RectF child_screen_space_rect
= MathUtil::MapClippedRect(
4590 child
->screen_space_transform(), child_content_bounds
);
4592 gfx::RectF
expected_child_draw_rect(child
->bounds());
4593 expected_child_draw_rect
.Scale(device_scale_factor
);
4594 expected_child_draw_rect
.set_width(ceil(expected_child_draw_rect
.width()));
4595 expected_child_draw_rect
.set_height(ceil(expected_child_draw_rect
.height()));
4596 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4597 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4599 // Verify child_no_scale transforms
4600 gfx::Transform expected_child_no_scale_transform
= child
->draw_transform();
4601 // All transforms operate on content rects. The child's content rect
4602 // incorporates device scale, but the child_no_scale does not; add it here.
4603 expected_child_no_scale_transform
.Scale(device_scale_factor
,
4604 device_scale_factor
);
4605 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4606 child_no_scale
->draw_transform());
4607 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4608 child_no_scale
->screen_space_transform());
4611 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4612 TEST_F(LayerTreeHostCommonTest
, ContentsScale
) {
4613 MockContentLayerClient delegate
;
4614 gfx::Transform identity_matrix
;
4616 gfx::Transform parent_scale_matrix
;
4617 SkMScalar initial_parent_scale
= 1.75;
4618 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4620 gfx::Transform child_scale_matrix
;
4621 SkMScalar initial_child_scale
= 1.25;
4622 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4624 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4625 root
->SetBounds(gfx::Size(100, 100));
4627 scoped_refptr
<ContentLayer
> parent
=
4628 CreateDrawableContentLayer(layer_settings(), &delegate
);
4629 SetLayerPropertiesForTesting(parent
.get(),
4630 parent_scale_matrix
,
4633 gfx::Size(100, 100),
4637 scoped_refptr
<ContentLayer
> child_scale
=
4638 CreateDrawableContentLayer(layer_settings(), &delegate
);
4639 SetLayerPropertiesForTesting(child_scale
.get(),
4642 gfx::PointF(2.f
, 2.f
),
4647 scoped_refptr
<ContentLayer
> child_empty
=
4648 CreateDrawableContentLayer(layer_settings(), &delegate
);
4649 SetLayerPropertiesForTesting(child_empty
.get(),
4652 gfx::PointF(2.f
, 2.f
),
4657 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4658 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate
);
4659 SetLayerPropertiesForTesting(child_no_scale
.get(),
4662 gfx::PointF(12.f
, 12.f
),
4667 root
->AddChild(parent
);
4669 parent
->AddChild(child_scale
);
4670 parent
->AddChild(child_empty
);
4671 parent
->AddChild(child_no_scale
);
4673 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4674 host
->SetRootLayer(root
);
4676 float device_scale_factor
= 2.5f
;
4677 float page_scale_factor
= 1.f
;
4680 RenderSurfaceLayerList render_surface_layer_list
;
4681 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4682 root
.get(), root
->bounds(), &render_surface_layer_list
);
4683 inputs
.device_scale_factor
= device_scale_factor
;
4684 inputs
.page_scale_factor
= page_scale_factor
;
4685 inputs
.page_scale_application_layer
= root
.get();
4686 inputs
.can_adjust_raster_scales
= true;
4687 inputs
.verify_property_trees
= false;
4688 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4690 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4691 initial_parent_scale
, parent
);
4692 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4693 initial_parent_scale
* initial_child_scale
,
4695 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4696 initial_parent_scale
* initial_child_scale
,
4698 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4700 // The parent is scaled up and shouldn't need to scale during draw. The
4701 // child that can scale its contents should also not need to scale during
4702 // draw. This shouldn't change if the child has empty bounds. The other
4704 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(0, 0));
4705 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(1, 1));
4706 EXPECT_FLOAT_EQ(1.0, child_scale
->draw_transform().matrix().get(0, 0));
4707 EXPECT_FLOAT_EQ(1.0, child_scale
->draw_transform().matrix().get(1, 1));
4708 EXPECT_FLOAT_EQ(1.0, child_empty
->draw_transform().matrix().get(0, 0));
4709 EXPECT_FLOAT_EQ(1.0, child_empty
->draw_transform().matrix().get(1, 1));
4710 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4711 initial_parent_scale
* initial_child_scale
,
4712 child_no_scale
->draw_transform().matrix().get(0, 0));
4713 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4714 initial_parent_scale
* initial_child_scale
,
4715 child_no_scale
->draw_transform().matrix().get(1, 1));
4718 // If the device_scale_factor or page_scale_factor changes, then it should be
4719 // updated using the initial transform as the raster scale.
4720 device_scale_factor
= 2.25f
;
4721 page_scale_factor
= 1.25f
;
4724 RenderSurfaceLayerList render_surface_layer_list
;
4725 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4726 root
.get(), root
->bounds(), &render_surface_layer_list
);
4727 inputs
.device_scale_factor
= device_scale_factor
;
4728 inputs
.page_scale_factor
= page_scale_factor
;
4729 inputs
.page_scale_application_layer
= root
.get();
4730 inputs
.can_adjust_raster_scales
= true;
4731 inputs
.verify_property_trees
= false;
4732 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4734 EXPECT_CONTENTS_SCALE_EQ(
4735 device_scale_factor
* page_scale_factor
* initial_parent_scale
, parent
);
4736 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4737 initial_parent_scale
* initial_child_scale
,
4739 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4740 initial_parent_scale
* initial_child_scale
,
4742 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4745 // If the transform changes, we expect the raster scale to be reset to 1.0.
4746 SkMScalar second_child_scale
= 1.75;
4747 child_scale_matrix
.Scale(second_child_scale
/ initial_child_scale
,
4748 second_child_scale
/ initial_child_scale
);
4749 child_scale
->SetTransform(child_scale_matrix
);
4750 child_empty
->SetTransform(child_scale_matrix
);
4753 RenderSurfaceLayerList render_surface_layer_list
;
4754 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4755 root
.get(), root
->bounds(), &render_surface_layer_list
);
4756 inputs
.device_scale_factor
= device_scale_factor
;
4757 inputs
.page_scale_factor
= page_scale_factor
;
4758 inputs
.page_scale_application_layer
= root
.get();
4759 inputs
.can_adjust_raster_scales
= true;
4760 inputs
.verify_property_trees
= false;
4761 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4763 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4764 initial_parent_scale
,
4766 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4768 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4770 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4773 // If the device_scale_factor or page_scale_factor changes, then it should be
4774 // updated, but still using 1.0 as the raster scale.
4775 device_scale_factor
= 2.75f
;
4776 page_scale_factor
= 1.75f
;
4779 RenderSurfaceLayerList render_surface_layer_list
;
4780 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4781 root
.get(), root
->bounds(), &render_surface_layer_list
);
4782 inputs
.device_scale_factor
= device_scale_factor
;
4783 inputs
.page_scale_factor
= page_scale_factor
;
4784 inputs
.page_scale_application_layer
= root
.get();
4785 inputs
.can_adjust_raster_scales
= true;
4786 inputs
.verify_property_trees
= false;
4787 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4789 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4790 initial_parent_scale
,
4792 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4794 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4796 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4800 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4801 TEST_F(LayerTreeHostCommonTest
,
4802 ContentsScale_LayerTransformsDontAffectContentsScale
) {
4803 MockContentLayerClient delegate
;
4804 gfx::Transform identity_matrix
;
4806 gfx::Transform parent_scale_matrix
;
4807 SkMScalar initial_parent_scale
= 1.75;
4808 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4810 gfx::Transform child_scale_matrix
;
4811 SkMScalar initial_child_scale
= 1.25;
4812 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4814 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4815 root
->SetBounds(gfx::Size(100, 100));
4817 scoped_refptr
<ContentLayer
> parent
=
4818 CreateDrawableContentLayer(layer_settings(), &delegate
);
4819 SetLayerPropertiesForTesting(parent
.get(),
4820 parent_scale_matrix
,
4823 gfx::Size(100, 100),
4827 scoped_refptr
<ContentLayer
> child_scale
=
4828 CreateDrawableContentLayer(layer_settings(), &delegate
);
4829 SetLayerPropertiesForTesting(child_scale
.get(),
4832 gfx::PointF(2.f
, 2.f
),
4837 scoped_refptr
<ContentLayer
> child_empty
=
4838 CreateDrawableContentLayer(layer_settings(), &delegate
);
4839 SetLayerPropertiesForTesting(child_empty
.get(),
4842 gfx::PointF(2.f
, 2.f
),
4847 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4848 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate
);
4849 SetLayerPropertiesForTesting(child_no_scale
.get(),
4852 gfx::PointF(12.f
, 12.f
),
4857 root
->AddChild(parent
);
4859 parent
->AddChild(child_scale
);
4860 parent
->AddChild(child_empty
);
4861 parent
->AddChild(child_no_scale
);
4863 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4864 host
->SetRootLayer(root
);
4866 RenderSurfaceLayerList render_surface_layer_list
;
4868 float device_scale_factor
= 2.5f
;
4869 float page_scale_factor
= 1.f
;
4871 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4872 root
.get(), root
->bounds(), &render_surface_layer_list
);
4873 inputs
.device_scale_factor
= device_scale_factor
;
4874 inputs
.page_scale_factor
= page_scale_factor
;
4875 inputs
.page_scale_application_layer
= root
.get();
4876 inputs
.verify_property_trees
= false;
4877 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4879 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4880 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4882 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4884 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4886 // Since the transform scale does not affect contents scale, it should affect
4887 // the draw transform instead.
4888 EXPECT_FLOAT_EQ(initial_parent_scale
,
4889 parent
->draw_transform().matrix().get(0, 0));
4890 EXPECT_FLOAT_EQ(initial_parent_scale
,
4891 parent
->draw_transform().matrix().get(1, 1));
4892 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4893 child_scale
->draw_transform().matrix().get(0, 0));
4894 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4895 child_scale
->draw_transform().matrix().get(1, 1));
4896 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4897 child_empty
->draw_transform().matrix().get(0, 0));
4898 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4899 child_empty
->draw_transform().matrix().get(1, 1));
4900 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4901 initial_parent_scale
* initial_child_scale
,
4902 child_no_scale
->draw_transform().matrix().get(0, 0));
4903 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4904 initial_parent_scale
* initial_child_scale
,
4905 child_no_scale
->draw_transform().matrix().get(1, 1));
4908 TEST_F(LayerTreeHostCommonTest
, SmallIdealScale
) {
4909 MockContentLayerClient delegate
;
4910 gfx::Transform identity_matrix
;
4912 gfx::Transform parent_scale_matrix
;
4913 SkMScalar initial_parent_scale
= 1.75;
4914 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4916 gfx::Transform child_scale_matrix
;
4917 SkMScalar initial_child_scale
= 0.25;
4918 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4920 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4921 root
->SetBounds(gfx::Size(100, 100));
4923 scoped_refptr
<FakePictureLayer
> parent
=
4924 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4925 SetLayerPropertiesForTesting(parent
.get(),
4926 parent_scale_matrix
,
4929 gfx::Size(100, 100),
4933 scoped_refptr
<FakePictureLayer
> child_scale
=
4934 CreateDrawablePictureLayer(layer_settings(), &delegate
);
4935 SetLayerPropertiesForTesting(child_scale
.get(),
4938 gfx::PointF(2.f
, 2.f
),
4943 root
->AddChild(parent
);
4945 parent
->AddChild(child_scale
);
4947 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4948 host
->SetRootLayer(root
);
4950 float device_scale_factor
= 2.5f
;
4951 float page_scale_factor
= 0.01f
;
4954 RenderSurfaceLayerList render_surface_layer_list
;
4955 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4956 root
.get(), root
->bounds(), &render_surface_layer_list
);
4957 inputs
.device_scale_factor
= device_scale_factor
;
4958 inputs
.page_scale_factor
= page_scale_factor
;
4959 inputs
.page_scale_application_layer
= root
.get();
4960 inputs
.can_adjust_raster_scales
= true;
4961 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4963 // The ideal scale is able to go below 1.
4964 float expected_ideal_scale
=
4965 device_scale_factor
* page_scale_factor
* initial_parent_scale
;
4966 EXPECT_LT(expected_ideal_scale
, 1.f
);
4967 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, parent
);
4969 expected_ideal_scale
= device_scale_factor
* page_scale_factor
*
4970 initial_parent_scale
* initial_child_scale
;
4971 EXPECT_LT(expected_ideal_scale
, 1.f
);
4972 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, child_scale
);
4976 TEST_F(LayerTreeHostCommonTest
, ContentsScaleForSurfaces
) {
4977 MockContentLayerClient delegate
;
4978 gfx::Transform identity_matrix
;
4980 gfx::Transform parent_scale_matrix
;
4981 SkMScalar initial_parent_scale
= 2.0;
4982 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4984 gfx::Transform child_scale_matrix
;
4985 SkMScalar initial_child_scale
= 3.0;
4986 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4988 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
4989 root
->SetBounds(gfx::Size(100, 100));
4991 scoped_refptr
<ContentLayer
> parent
=
4992 CreateDrawableContentLayer(layer_settings(), &delegate
);
4993 SetLayerPropertiesForTesting(parent
.get(),
4994 parent_scale_matrix
,
4997 gfx::Size(100, 100),
5001 scoped_refptr
<ContentLayer
> surface_scale
=
5002 CreateDrawableContentLayer(layer_settings(), &delegate
);
5003 SetLayerPropertiesForTesting(surface_scale
.get(),
5006 gfx::PointF(2.f
, 2.f
),
5011 scoped_refptr
<ContentLayer
> surface_scale_child_scale
=
5012 CreateDrawableContentLayer(layer_settings(), &delegate
);
5013 SetLayerPropertiesForTesting(surface_scale_child_scale
.get(),
5021 scoped_refptr
<NoScaleContentLayer
> surface_scale_child_no_scale
=
5022 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate
);
5023 SetLayerPropertiesForTesting(surface_scale_child_no_scale
.get(),
5031 scoped_refptr
<NoScaleContentLayer
> surface_no_scale
=
5032 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate
);
5033 SetLayerPropertiesForTesting(surface_no_scale
.get(),
5036 gfx::PointF(12.f
, 12.f
),
5041 scoped_refptr
<ContentLayer
> surface_no_scale_child_scale
=
5042 CreateDrawableContentLayer(layer_settings(), &delegate
);
5043 SetLayerPropertiesForTesting(surface_no_scale_child_scale
.get(),
5051 scoped_refptr
<NoScaleContentLayer
> surface_no_scale_child_no_scale
=
5052 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate
);
5053 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale
.get(),
5061 root
->AddChild(parent
);
5063 parent
->AddChild(surface_scale
);
5064 parent
->AddChild(surface_no_scale
);
5066 surface_scale
->SetForceRenderSurface(true);
5067 surface_scale
->AddChild(surface_scale_child_scale
);
5068 surface_scale
->AddChild(surface_scale_child_no_scale
);
5070 surface_no_scale
->SetForceRenderSurface(true);
5071 surface_no_scale
->AddChild(surface_no_scale_child_scale
);
5072 surface_no_scale
->AddChild(surface_no_scale_child_no_scale
);
5074 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5075 host
->SetRootLayer(root
);
5077 SkMScalar device_scale_factor
= 5;
5078 SkMScalar page_scale_factor
= 7;
5080 RenderSurfaceLayerList render_surface_layer_list
;
5081 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5082 root
.get(), root
->bounds(), &render_surface_layer_list
);
5083 inputs
.device_scale_factor
= device_scale_factor
;
5084 inputs
.page_scale_factor
= page_scale_factor
;
5085 inputs
.page_scale_application_layer
= root
.get();
5086 inputs
.can_adjust_raster_scales
= true;
5087 inputs
.verify_property_trees
= false;
5088 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5090 EXPECT_CONTENTS_SCALE_EQ(
5091 device_scale_factor
* page_scale_factor
* initial_parent_scale
, parent
);
5092 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
5093 initial_parent_scale
* initial_child_scale
,
5095 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale
);
5096 EXPECT_CONTENTS_SCALE_EQ(
5097 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5098 initial_child_scale
* initial_child_scale
,
5099 surface_scale_child_scale
);
5100 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale
);
5101 EXPECT_CONTENTS_SCALE_EQ(
5102 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5103 initial_child_scale
* initial_child_scale
,
5104 surface_no_scale_child_scale
);
5105 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale
);
5107 // The parent is scaled up and shouldn't need to scale during draw.
5108 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(0, 0));
5109 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(1, 1));
5111 // RenderSurfaces should always be 1:1 with their target.
5114 surface_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5117 surface_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5119 // The surface_scale can apply contents scale so the layer shouldn't need to
5120 // scale during draw.
5121 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(0, 0));
5122 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(1, 1));
5124 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5125 // to scale during draw.
5127 1.0, surface_scale_child_scale
->draw_transform().matrix().get(0, 0));
5129 1.0, surface_scale_child_scale
->draw_transform().matrix().get(1, 1));
5131 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5132 // to be scaled during draw.
5134 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5135 initial_child_scale
* initial_child_scale
,
5136 surface_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5138 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5139 initial_child_scale
* initial_child_scale
,
5140 surface_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5142 // RenderSurfaces should always be 1:1 with their target.
5145 surface_no_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5148 surface_no_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5150 // The surface_no_scale layer can not apply contents scale, so it needs to be
5151 // scaled during draw.
5152 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
5153 initial_parent_scale
* initial_child_scale
,
5154 surface_no_scale
->draw_transform().matrix().get(0, 0));
5155 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
5156 initial_parent_scale
* initial_child_scale
,
5157 surface_no_scale
->draw_transform().matrix().get(1, 1));
5159 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5160 // to scale during draw.
5162 1.0, surface_no_scale_child_scale
->draw_transform().matrix().get(0, 0));
5164 1.0, surface_no_scale_child_scale
->draw_transform().matrix().get(1, 1));
5166 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5167 // to be scaled during draw.
5169 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5170 initial_child_scale
* initial_child_scale
,
5171 surface_no_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5173 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5174 initial_child_scale
* initial_child_scale
,
5175 surface_no_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5178 // TODO(sohanjg): Remove this test when ContentLayer is removed.
5179 TEST_F(LayerTreeHostCommonTest
,
5180 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale
) {
5181 MockContentLayerClient delegate
;
5182 gfx::Transform identity_matrix
;
5184 gfx::Transform parent_scale_matrix
;
5185 SkMScalar initial_parent_scale
= 2.0;
5186 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
5188 gfx::Transform child_scale_matrix
;
5189 SkMScalar initial_child_scale
= 3.0;
5190 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
5192 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5193 root
->SetBounds(gfx::Size(100, 100));
5195 scoped_refptr
<ContentLayer
> parent
=
5196 CreateDrawableContentLayer(layer_settings(), &delegate
);
5197 SetLayerPropertiesForTesting(parent
.get(),
5198 parent_scale_matrix
,
5201 gfx::Size(100, 100),
5205 scoped_refptr
<ContentLayer
> surface_scale
=
5206 CreateDrawableContentLayer(layer_settings(), &delegate
);
5207 SetLayerPropertiesForTesting(surface_scale
.get(),
5210 gfx::PointF(2.f
, 2.f
),
5215 scoped_refptr
<ContentLayer
> surface_scale_child_scale
=
5216 CreateDrawableContentLayer(layer_settings(), &delegate
);
5217 SetLayerPropertiesForTesting(surface_scale_child_scale
.get(),
5225 scoped_refptr
<NoScaleContentLayer
> surface_scale_child_no_scale
=
5226 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate
);
5227 SetLayerPropertiesForTesting(surface_scale_child_no_scale
.get(),
5235 scoped_refptr
<NoScaleContentLayer
> surface_no_scale
=
5236 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate
);
5237 SetLayerPropertiesForTesting(surface_no_scale
.get(),
5240 gfx::PointF(12.f
, 12.f
),
5245 scoped_refptr
<ContentLayer
> surface_no_scale_child_scale
=
5246 CreateDrawableContentLayer(layer_settings(), &delegate
);
5247 SetLayerPropertiesForTesting(surface_no_scale_child_scale
.get(),
5255 scoped_refptr
<NoScaleContentLayer
> surface_no_scale_child_no_scale
=
5256 CreateNoScaleDrawableContentLayer(layer_settings(), &delegate
);
5257 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale
.get(),
5265 root
->AddChild(parent
);
5267 parent
->AddChild(surface_scale
);
5268 parent
->AddChild(surface_no_scale
);
5270 surface_scale
->SetForceRenderSurface(true);
5271 surface_scale
->AddChild(surface_scale_child_scale
);
5272 surface_scale
->AddChild(surface_scale_child_no_scale
);
5274 surface_no_scale
->SetForceRenderSurface(true);
5275 surface_no_scale
->AddChild(surface_no_scale_child_scale
);
5276 surface_no_scale
->AddChild(surface_no_scale_child_no_scale
);
5278 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5279 host
->SetRootLayer(root
);
5281 RenderSurfaceLayerList render_surface_layer_list
;
5283 SkMScalar device_scale_factor
= 5.0;
5284 SkMScalar page_scale_factor
= 7.0;
5285 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5286 root
.get(), root
->bounds(), &render_surface_layer_list
);
5287 inputs
.device_scale_factor
= device_scale_factor
;
5288 inputs
.page_scale_factor
= page_scale_factor
;
5289 inputs
.page_scale_application_layer
= root
.get();
5290 inputs
.verify_property_trees
= false;
5291 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5293 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5295 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5297 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_no_scale
);
5298 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5299 surface_scale_child_scale
);
5300 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_scale_child_no_scale
);
5301 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5302 surface_no_scale_child_scale
);
5303 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_no_scale_child_no_scale
);
5305 // The parent is scaled up during draw, since its contents are not scaled by
5306 // the transform hierarchy.
5307 EXPECT_FLOAT_EQ(initial_parent_scale
,
5308 parent
->draw_transform().matrix().get(0, 0));
5309 EXPECT_FLOAT_EQ(initial_parent_scale
,
5310 parent
->draw_transform().matrix().get(1, 1));
5312 // The child surface is not scaled up during draw since its subtree is scaled
5313 // by the transform hierarchy.
5316 surface_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5319 surface_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5321 // The surface_scale's RenderSurface is not scaled during draw, so the layer
5322 // needs to be scaled when drawing into its surface.
5323 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
5324 surface_scale
->draw_transform().matrix().get(0, 0));
5325 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
5326 surface_scale
->draw_transform().matrix().get(1, 1));
5328 // The surface_scale_child_scale is not scaled when drawing into its surface,
5329 // since its content bounds are scaled by the transform hierarchy.
5331 initial_child_scale
* initial_child_scale
* initial_parent_scale
,
5332 surface_scale_child_scale
->draw_transform().matrix().get(0, 0));
5334 initial_child_scale
* initial_child_scale
* initial_parent_scale
,
5335 surface_scale_child_scale
->draw_transform().matrix().get(1, 1));
5337 // The surface_scale_child_no_scale is scaled by the device scale, page scale
5338 // and transform hierarchy.
5340 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5341 initial_child_scale
* initial_child_scale
,
5342 surface_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5344 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5345 initial_child_scale
* initial_child_scale
,
5346 surface_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5348 // The child surface is not scaled up during draw since its subtree is scaled
5349 // by the transform hierarchy.
5352 surface_no_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5355 surface_no_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5357 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
5358 // be scaled by the device and page scale factors. Its surface is already
5359 // scaled by the transform hierarchy so those don't need to scale the layer's
5361 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
*
5362 device_scale_factor
* page_scale_factor
,
5363 surface_no_scale
->draw_transform().matrix().get(0, 0));
5364 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
*
5365 device_scale_factor
* page_scale_factor
,
5366 surface_no_scale
->draw_transform().matrix().get(1, 1));
5368 // The surface_no_scale_child_scale has its contents scaled by the page and
5369 // device scale factors, but needs to be scaled by the transform hierarchy
5372 initial_parent_scale
* initial_child_scale
* initial_child_scale
,
5373 surface_no_scale_child_scale
->draw_transform().matrix().get(0, 0));
5375 initial_parent_scale
* initial_child_scale
* initial_child_scale
,
5376 surface_no_scale_child_scale
->draw_transform().matrix().get(1, 1));
5378 // The surface_no_scale_child_no_scale needs to be scaled by the device and
5379 // page scale factors and by any transform heirarchy below its target surface.
5381 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5382 initial_child_scale
* initial_child_scale
,
5383 surface_no_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5385 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5386 initial_child_scale
* initial_child_scale
,
5387 surface_no_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5390 TEST_F(LayerTreeHostCommonTest
, IdealScaleForAnimatingLayer
) {
5391 MockContentLayerClient delegate
;
5392 gfx::Transform identity_matrix
;
5394 gfx::Transform parent_scale_matrix
;
5395 SkMScalar initial_parent_scale
= 1.75;
5396 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
5398 gfx::Transform child_scale_matrix
;
5399 SkMScalar initial_child_scale
= 1.25;
5400 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
5402 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5403 root
->SetBounds(gfx::Size(100, 100));
5405 scoped_refptr
<FakePictureLayer
> parent
=
5406 CreateDrawablePictureLayer(layer_settings(), &delegate
);
5407 SetLayerPropertiesForTesting(parent
.get(),
5408 parent_scale_matrix
,
5411 gfx::Size(100, 100),
5415 scoped_refptr
<FakePictureLayer
> child_scale
=
5416 CreateDrawablePictureLayer(layer_settings(), &delegate
);
5417 SetLayerPropertiesForTesting(child_scale
.get(),
5420 gfx::PointF(2.f
, 2.f
),
5425 root
->AddChild(parent
);
5427 parent
->AddChild(child_scale
);
5429 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5430 host
->SetRootLayer(root
);
5433 RenderSurfaceLayerList render_surface_layer_list
;
5434 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5435 root
.get(), root
->bounds(), &render_surface_layer_list
);
5436 inputs
.can_adjust_raster_scales
= true;
5437 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5439 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale
, parent
);
5440 // Animating layers compute ideal scale in the same way as when
5442 EXPECT_IDEAL_SCALE_EQ(initial_child_scale
* initial_parent_scale
,
5447 // TODO(sohanjg): Remove this test when ContentLayer is removed.
5448 TEST_F(LayerTreeHostCommonTest
,
5449 ChangeInContentBoundsOrScaleTriggersPushProperties
) {
5450 MockContentLayerClient delegate
;
5451 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5452 scoped_refptr
<Layer
> child
=
5453 CreateDrawableContentLayer(layer_settings(), &delegate
);
5454 root
->AddChild(child
);
5456 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5457 host
->SetRootLayer(root
);
5459 gfx::Transform identity_matrix
;
5460 SetLayerPropertiesForTesting(root
.get(),
5464 gfx::Size(100, 100),
5467 SetLayerPropertiesForTesting(child
.get(),
5471 gfx::Size(100, 100),
5475 root
->reset_needs_push_properties_for_testing();
5476 child
->reset_needs_push_properties_for_testing();
5478 gfx::Size device_viewport_size
= gfx::Size(100, 100);
5479 RenderSurfaceLayerList render_surface_layer_list
;
5480 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5481 root
.get(), device_viewport_size
, &render_surface_layer_list
);
5482 inputs
.device_scale_factor
= 1.f
;
5483 inputs
.can_adjust_raster_scales
= true;
5484 inputs
.verify_property_trees
= false;
5486 // This will change both layers' content bounds.
5487 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5488 EXPECT_TRUE(root
->needs_push_properties());
5489 EXPECT_TRUE(child
->needs_push_properties());
5491 root
->reset_needs_push_properties_for_testing();
5492 child
->reset_needs_push_properties_for_testing();
5494 // This will change only the child layer's contents scale and content bounds,
5495 // since the root layer is not a ContentsScalingLayer.
5496 inputs
.device_scale_factor
= 2.f
;
5497 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5498 EXPECT_FALSE(root
->needs_push_properties());
5499 EXPECT_TRUE(child
->needs_push_properties());
5501 root
->reset_needs_push_properties_for_testing();
5502 child
->reset_needs_push_properties_for_testing();
5504 // This will not change either layer's contents scale or content bounds.
5505 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5506 EXPECT_FALSE(root
->needs_push_properties());
5507 EXPECT_FALSE(child
->needs_push_properties());
5510 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceTransformsInHighDPI
) {
5511 MockContentLayerClient delegate
;
5512 gfx::Transform identity_matrix
;
5514 scoped_refptr
<FakePictureLayer
> parent
=
5515 CreateDrawablePictureLayer(layer_settings(), &delegate
);
5516 SetLayerPropertiesForTesting(parent
.get(),
5524 scoped_refptr
<FakePictureLayer
> child
=
5525 CreateDrawablePictureLayer(layer_settings(), &delegate
);
5526 SetLayerPropertiesForTesting(child
.get(),
5529 gfx::PointF(2.f
, 2.f
),
5534 gfx::Transform replica_transform
;
5535 replica_transform
.Scale(1.0, -1.0);
5536 scoped_refptr
<FakePictureLayer
> replica
=
5537 CreateDrawablePictureLayer(layer_settings(), &delegate
);
5538 SetLayerPropertiesForTesting(replica
.get(),
5541 gfx::PointF(2.f
, 2.f
),
5546 // This layer should end up in the same surface as child, with the same draw
5547 // and screen space transforms.
5548 scoped_refptr
<FakePictureLayer
> duplicate_child_non_owner
=
5549 CreateDrawablePictureLayer(layer_settings(), &delegate
);
5550 SetLayerPropertiesForTesting(duplicate_child_non_owner
.get(),
5558 parent
->AddChild(child
);
5559 child
->AddChild(duplicate_child_non_owner
);
5560 child
->SetReplicaLayer(replica
.get());
5562 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5563 host
->SetRootLayer(parent
);
5565 RenderSurfaceLayerList render_surface_layer_list
;
5567 float device_scale_factor
= 1.5f
;
5568 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5569 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
5570 inputs
.device_scale_factor
= device_scale_factor
;
5571 inputs
.can_adjust_raster_scales
= true;
5572 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5574 // We should have two render surfaces. The root's render surface and child's
5575 // render surface (it needs one because it has a replica layer).
5576 EXPECT_EQ(2u, render_surface_layer_list
.size());
5578 gfx::Transform expected_parent_transform
;
5579 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
5580 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
5581 parent
->screen_space_transform());
5582 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
5583 parent
->draw_transform());
5585 gfx::Transform expected_draw_transform
;
5586 expected_draw_transform
.Scale(device_scale_factor
, device_scale_factor
);
5587 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform
,
5588 child
->draw_transform());
5590 gfx::Transform expected_screen_space_transform
;
5591 expected_screen_space_transform
.Scale(device_scale_factor
,
5592 device_scale_factor
);
5593 expected_screen_space_transform
.Translate(child
->position().x(),
5594 child
->position().y());
5595 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform
,
5596 child
->screen_space_transform());
5598 gfx::Transform expected_duplicate_child_draw_transform
=
5599 child
->draw_transform();
5600 EXPECT_TRANSFORMATION_MATRIX_EQ(child
->draw_transform(),
5601 duplicate_child_non_owner
->draw_transform());
5602 EXPECT_TRANSFORMATION_MATRIX_EQ(
5603 child
->screen_space_transform(),
5604 duplicate_child_non_owner
->screen_space_transform());
5605 EXPECT_EQ(child
->drawable_content_rect(),
5606 duplicate_child_non_owner
->drawable_content_rect());
5607 EXPECT_EQ(child
->content_bounds(),
5608 duplicate_child_non_owner
->content_bounds());
5610 gfx::Transform expected_render_surface_draw_transform
;
5611 expected_render_surface_draw_transform
.Translate(
5612 device_scale_factor
* child
->position().x(),
5613 device_scale_factor
* child
->position().y());
5614 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform
,
5615 child
->render_surface()->draw_transform());
5617 gfx::Transform expected_surface_draw_transform
;
5618 expected_surface_draw_transform
.Translate(device_scale_factor
* 2.f
,
5619 device_scale_factor
* 2.f
);
5620 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform
,
5621 child
->render_surface()->draw_transform());
5623 gfx::Transform expected_surface_screen_space_transform
;
5624 expected_surface_screen_space_transform
.Translate(device_scale_factor
* 2.f
,
5625 device_scale_factor
* 2.f
);
5626 EXPECT_TRANSFORMATION_MATRIX_EQ(
5627 expected_surface_screen_space_transform
,
5628 child
->render_surface()->screen_space_transform());
5630 gfx::Transform expected_replica_draw_transform
;
5631 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
5632 expected_replica_draw_transform
.matrix().set(0, 3, 6.0);
5633 expected_replica_draw_transform
.matrix().set(1, 3, 6.0);
5634 EXPECT_TRANSFORMATION_MATRIX_EQ(
5635 expected_replica_draw_transform
,
5636 child
->render_surface()->replica_draw_transform());
5638 gfx::Transform expected_replica_screen_space_transform
;
5639 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
5640 expected_replica_screen_space_transform
.matrix().set(0, 3, 6.0);
5641 expected_replica_screen_space_transform
.matrix().set(1, 3, 6.0);
5642 EXPECT_TRANSFORMATION_MATRIX_EQ(
5643 expected_replica_screen_space_transform
,
5644 child
->render_surface()->replica_screen_space_transform());
5645 EXPECT_TRANSFORMATION_MATRIX_EQ(
5646 expected_replica_screen_space_transform
,
5647 child
->render_surface()->replica_screen_space_transform());
5650 TEST_F(LayerTreeHostCommonTest
,
5651 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition
) {
5652 MockContentLayerClient delegate
;
5653 gfx::Transform identity_matrix
;
5655 scoped_refptr
<FakePictureLayer
> parent
=
5656 CreateDrawablePictureLayer(layer_settings(), &delegate
);
5657 SetLayerPropertiesForTesting(parent
.get(),
5665 scoped_refptr
<FakePictureLayer
> child
=
5666 CreateDrawablePictureLayer(layer_settings(), &delegate
);
5667 SetLayerPropertiesForTesting(child
.get(),
5675 gfx::Transform replica_transform
;
5676 replica_transform
.Scale(1.0, -1.0);
5677 scoped_refptr
<FakePictureLayer
> replica
=
5678 CreateDrawablePictureLayer(layer_settings(), &delegate
);
5679 SetLayerPropertiesForTesting(replica
.get(),
5687 parent
->AddChild(child
);
5688 child
->SetReplicaLayer(replica
.get());
5690 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5691 host
->SetRootLayer(parent
);
5693 float device_scale_factor
= 1.7f
;
5695 RenderSurfaceLayerList render_surface_layer_list
;
5696 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5697 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
5698 inputs
.device_scale_factor
= device_scale_factor
;
5699 inputs
.can_adjust_raster_scales
= true;
5700 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5702 // We should have two render surfaces. The root's render surface and child's
5703 // render surface (it needs one because it has a replica layer).
5704 EXPECT_EQ(2u, render_surface_layer_list
.size());
5706 gfx::Transform identity_transform
;
5707 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5708 child
->render_surface()->draw_transform());
5709 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5710 child
->render_surface()->draw_transform());
5711 EXPECT_TRANSFORMATION_MATRIX_EQ(
5712 identity_transform
, child
->render_surface()->screen_space_transform());
5714 gfx::Transform expected_replica_draw_transform
;
5715 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
5716 EXPECT_TRANSFORMATION_MATRIX_EQ(
5717 expected_replica_draw_transform
,
5718 child
->render_surface()->replica_draw_transform());
5720 gfx::Transform expected_replica_screen_space_transform
;
5721 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
5722 EXPECT_TRANSFORMATION_MATRIX_EQ(
5723 expected_replica_screen_space_transform
,
5724 child
->render_surface()->replica_screen_space_transform());
5727 TEST_F(LayerTreeHostCommonTest
, SubtreeSearch
) {
5728 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5729 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
5730 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
5731 scoped_refptr
<Layer
> mask_layer
= Layer::Create(layer_settings());
5732 scoped_refptr
<Layer
> replica_layer
= Layer::Create(layer_settings());
5734 grand_child
->SetReplicaLayer(replica_layer
.get());
5735 child
->AddChild(grand_child
.get());
5736 child
->SetMaskLayer(mask_layer
.get());
5737 root
->AddChild(child
.get());
5739 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5740 host
->SetRootLayer(root
);
5742 int nonexistent_id
= -1;
5743 EXPECT_EQ(root
.get(),
5744 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), root
->id()));
5745 EXPECT_EQ(child
.get(),
5746 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), child
->id()));
5749 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), grand_child
->id()));
5752 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), mask_layer
->id()));
5754 replica_layer
.get(),
5755 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), replica_layer
->id()));
5757 0, LayerTreeHostCommon::FindLayerInSubtree(root
.get(), nonexistent_id
));
5760 TEST_F(LayerTreeHostCommonTest
, TransparentChildRenderSurfaceCreation
) {
5761 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
5762 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
5763 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
5764 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
5766 const gfx::Transform identity_matrix
;
5767 SetLayerPropertiesForTesting(root
.get(),
5771 gfx::Size(100, 100),
5774 SetLayerPropertiesForTesting(child
.get(),
5781 SetLayerPropertiesForTesting(grand_child
.get(),
5789 root
->AddChild(child
);
5790 child
->AddChild(grand_child
);
5791 child
->SetOpacity(0.5f
);
5793 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5794 host
->SetRootLayer(root
);
5796 ExecuteCalculateDrawProperties(root
.get());
5798 EXPECT_FALSE(child
->render_surface());
5801 TEST_F(LayerTreeHostCommonTest
, OpacityAnimatingOnPendingTree
) {
5802 FakeImplProxy proxy
;
5803 TestSharedBitmapManager shared_bitmap_manager
;
5804 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
5805 host_impl
.CreatePendingTree();
5806 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5808 const gfx::Transform identity_matrix
;
5809 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
5810 gfx::PointF(), gfx::Size(100, 100), true, false,
5812 root
->SetDrawsContent(true);
5814 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5815 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
5816 gfx::PointF(), gfx::Size(50, 50), true, false,
5818 child
->SetDrawsContent(true);
5819 child
->SetOpacity(0.0f
);
5821 // Add opacity animation.
5822 AddOpacityTransitionToController(
5823 child
->layer_animation_controller(), 10.0, 0.0f
, 1.0f
, false);
5825 root
->AddChild(child
.Pass());
5826 root
->SetHasRenderSurface(true);
5828 LayerImplList render_surface_layer_list
;
5829 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5830 root
.get(), root
->bounds(), &render_surface_layer_list
);
5831 inputs
.can_adjust_raster_scales
= true;
5832 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5834 // We should have one render surface and two layers. The child
5835 // layer should be included even though it is transparent.
5836 ASSERT_EQ(1u, render_surface_layer_list
.size());
5837 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5840 using LCDTextTestParam
= std::tr1::tuple
<bool, bool, bool>;
5842 : public LayerTreeHostCommonTestBase
,
5843 public testing::TestWithParam
<LCDTextTestParam
> {
5846 : host_impl_(&proxy_
, &shared_bitmap_manager_
, &task_graph_runner_
),
5849 grand_child_(nullptr) {}
5852 void SetUp() override
{
5853 can_use_lcd_text_
= std::tr1::get
<0>(GetParam());
5854 layers_always_allowed_lcd_text_
= std::tr1::get
<1>(GetParam());
5856 scoped_ptr
<LayerImpl
> root_ptr
=
5857 LayerImpl::Create(host_impl_
.active_tree(), 1);
5858 scoped_ptr
<LayerImpl
> child_ptr
=
5859 LayerImpl::Create(host_impl_
.active_tree(), 2);
5860 scoped_ptr
<LayerImpl
> grand_child_ptr
=
5861 LayerImpl::Create(host_impl_
.active_tree(), 3);
5863 // Stash raw pointers to look at later.
5864 root_
= root_ptr
.get();
5865 child_
= child_ptr
.get();
5866 grand_child_
= grand_child_ptr
.get();
5868 child_
->AddChild(grand_child_ptr
.Pass());
5869 root_
->AddChild(child_ptr
.Pass());
5870 host_impl_
.active_tree()->SetRootLayer(root_ptr
.Pass());
5872 root_
->SetContentsOpaque(true);
5873 child_
->SetContentsOpaque(true);
5874 grand_child_
->SetContentsOpaque(true);
5876 gfx::Transform identity_matrix
;
5877 SetLayerPropertiesForTesting(root_
, identity_matrix
, gfx::Point3F(),
5878 gfx::PointF(), gfx::Size(1, 1), true, false,
5880 SetLayerPropertiesForTesting(child_
, identity_matrix
, gfx::Point3F(),
5881 gfx::PointF(), gfx::Size(1, 1), true, false,
5882 std::tr1::get
<2>(GetParam()));
5883 SetLayerPropertiesForTesting(grand_child_
, identity_matrix
, gfx::Point3F(),
5884 gfx::PointF(), gfx::Size(1, 1), true, false,
5888 bool can_use_lcd_text_
;
5889 bool layers_always_allowed_lcd_text_
;
5891 FakeImplProxy proxy_
;
5892 TestSharedBitmapManager shared_bitmap_manager_
;
5893 TestTaskGraphRunner task_graph_runner_
;
5894 FakeLayerTreeHostImpl host_impl_
;
5898 LayerImpl
* grand_child_
;
5901 TEST_P(LCDTextTest
, CanUseLCDText
) {
5902 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
5903 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
5905 // Case 1: Identity transform.
5906 gfx::Transform identity_matrix
;
5907 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5908 layers_always_allowed_lcd_text_
);
5909 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5910 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
5911 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
5913 // Case 2: Integral translation.
5914 gfx::Transform integral_translation
;
5915 integral_translation
.Translate(1.0, 2.0);
5916 child_
->SetTransform(integral_translation
);
5917 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5918 layers_always_allowed_lcd_text_
);
5919 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5920 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
5921 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
5923 // Case 3: Non-integral translation.
5924 gfx::Transform non_integral_translation
;
5925 non_integral_translation
.Translate(1.5, 2.5);
5926 child_
->SetTransform(non_integral_translation
);
5927 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5928 layers_always_allowed_lcd_text_
);
5929 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5930 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
5931 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
5933 // Case 4: Rotation.
5934 gfx::Transform rotation
;
5935 rotation
.Rotate(10.0);
5936 child_
->SetTransform(rotation
);
5937 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5938 layers_always_allowed_lcd_text_
);
5939 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5940 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
5941 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
5944 gfx::Transform scale
;
5945 scale
.Scale(2.0, 2.0);
5946 child_
->SetTransform(scale
);
5947 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5948 layers_always_allowed_lcd_text_
);
5949 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5950 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
5951 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
5954 gfx::Transform skew
;
5956 child_
->SetTransform(skew
);
5957 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5958 layers_always_allowed_lcd_text_
);
5959 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5960 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
5961 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
5963 // Case 7: Translucent.
5964 child_
->SetTransform(identity_matrix
);
5965 child_
->SetOpacity(0.5f
);
5966 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5967 layers_always_allowed_lcd_text_
);
5968 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5969 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
5970 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
5972 // Case 8: Sanity check: restore transform and opacity.
5973 child_
->SetTransform(identity_matrix
);
5974 child_
->SetOpacity(1.f
);
5975 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5976 layers_always_allowed_lcd_text_
);
5977 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5978 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
5979 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
5981 // Case 9: Non-opaque content.
5982 child_
->SetContentsOpaque(false);
5983 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5984 layers_always_allowed_lcd_text_
);
5985 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5986 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
5987 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
5989 // Case 10: Sanity check: restore content opaqueness.
5990 child_
->SetContentsOpaque(true);
5991 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5992 layers_always_allowed_lcd_text_
);
5993 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5994 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
5995 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
5998 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimation
) {
5999 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
6000 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
6002 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
6003 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
6004 layers_always_allowed_lcd_text_
);
6005 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
6006 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
6007 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
6009 // Add opacity animation.
6010 child_
->SetOpacity(0.9f
);
6011 AddOpacityTransitionToController(
6012 child_
->layer_animation_controller(), 10.0, 0.9f
, 0.1f
, false);
6014 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
6015 layers_always_allowed_lcd_text_
);
6016 // Text LCD should be adjusted while animation is active.
6017 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
6018 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
6019 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
6022 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimationContentsOpaque
) {
6023 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
6024 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
6026 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
6027 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
6028 layers_always_allowed_lcd_text_
);
6029 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
6030 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
6031 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
6033 // Mark contents non-opaque within the first animation frame.
6034 child_
->SetContentsOpaque(false);
6035 AddOpacityTransitionToController(child_
->layer_animation_controller(), 10.0,
6038 ExecuteCalculateDrawProperties(root_
, 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
6039 layers_always_allowed_lcd_text_
);
6040 // LCD text should be disabled for non-opaque layers even during animations.
6041 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
6042 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
6043 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
6046 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest
,
6048 testing::Combine(testing::Bool(),
6052 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayer
) {
6053 FakeImplProxy proxy
;
6054 TestSharedBitmapManager shared_bitmap_manager
;
6055 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
6056 host_impl
.CreatePendingTree();
6057 const gfx::Transform identity_matrix
;
6059 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6060 SetLayerPropertiesForTesting(root
.get(),
6067 root
->SetIsDrawable(true);
6069 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
6070 SetLayerPropertiesForTesting(child
.get(),
6077 child
->SetIsDrawable(true);
6079 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
6080 SetLayerPropertiesForTesting(grand_child
.get(),
6087 grand_child
->SetIsDrawable(true);
6088 grand_child
->SetHideLayerAndSubtree(true);
6090 child
->AddChild(grand_child
);
6091 root
->AddChild(child
);
6093 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6094 host
->SetRootLayer(root
);
6096 RenderSurfaceLayerList render_surface_layer_list
;
6097 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6098 root
.get(), root
->bounds(), &render_surface_layer_list
);
6099 inputs
.can_adjust_raster_scales
= true;
6100 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6102 // We should have one render surface and two layers. The grand child has
6104 ASSERT_EQ(1u, render_surface_layer_list
.size());
6105 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
6106 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6107 EXPECT_EQ(child
->id(), root
->render_surface()->layer_list().at(1)->id());
6110 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayerImpl
) {
6111 FakeImplProxy proxy
;
6112 TestSharedBitmapManager shared_bitmap_manager
;
6113 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
6114 host_impl
.CreatePendingTree();
6115 const gfx::Transform identity_matrix
;
6117 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
6118 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
6119 gfx::PointF(), gfx::Size(50, 50), true, false,
6121 root
->SetDrawsContent(true);
6123 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
6124 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
6125 gfx::PointF(), gfx::Size(40, 40), true, false,
6127 child
->SetDrawsContent(true);
6129 scoped_ptr
<LayerImpl
> grand_child
=
6130 LayerImpl::Create(host_impl
.pending_tree(), 3);
6131 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
6132 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6133 true, false, false);
6134 grand_child
->SetDrawsContent(true);
6135 grand_child
->SetHideLayerAndSubtree(true);
6137 child
->AddChild(grand_child
.Pass());
6138 root
->AddChild(child
.Pass());
6139 root
->SetHasRenderSurface(true);
6141 LayerImplList render_surface_layer_list
;
6142 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6143 root
.get(), root
->bounds(), &render_surface_layer_list
);
6144 inputs
.can_adjust_raster_scales
= true;
6145 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6147 // We should have one render surface and two layers. The grand child has
6149 ASSERT_EQ(1u, render_surface_layer_list
.size());
6150 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
6151 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
6152 EXPECT_EQ(2, root
->render_surface()->layer_list().at(1)->id());
6155 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayers
) {
6156 FakeImplProxy proxy
;
6157 TestSharedBitmapManager shared_bitmap_manager
;
6158 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
6159 host_impl
.CreatePendingTree();
6160 const gfx::Transform identity_matrix
;
6162 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6163 SetLayerPropertiesForTesting(root
.get(),
6170 root
->SetIsDrawable(true);
6172 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
6173 SetLayerPropertiesForTesting(child
.get(),
6180 child
->SetIsDrawable(true);
6181 child
->SetHideLayerAndSubtree(true);
6183 scoped_refptr
<Layer
> grand_child
= Layer::Create(layer_settings());
6184 SetLayerPropertiesForTesting(grand_child
.get(),
6191 grand_child
->SetIsDrawable(true);
6193 child
->AddChild(grand_child
);
6194 root
->AddChild(child
);
6196 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6197 host
->SetRootLayer(root
);
6199 RenderSurfaceLayerList render_surface_layer_list
;
6200 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6201 root
.get(), root
->bounds(), &render_surface_layer_list
);
6202 inputs
.can_adjust_raster_scales
= true;
6203 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6205 // We should have one render surface and one layers. The child has
6206 // hidden itself and the grand child.
6207 ASSERT_EQ(1u, render_surface_layer_list
.size());
6208 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6209 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6212 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayersImpl
) {
6213 FakeImplProxy proxy
;
6214 TestSharedBitmapManager shared_bitmap_manager
;
6215 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
6216 host_impl
.CreatePendingTree();
6217 const gfx::Transform identity_matrix
;
6219 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
6220 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
6221 gfx::PointF(), gfx::Size(50, 50), true, false,
6223 root
->SetDrawsContent(true);
6225 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
6226 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
6227 gfx::PointF(), gfx::Size(40, 40), true, false,
6229 child
->SetDrawsContent(true);
6230 child
->SetHideLayerAndSubtree(true);
6232 scoped_ptr
<LayerImpl
> grand_child
=
6233 LayerImpl::Create(host_impl
.pending_tree(), 3);
6234 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
6235 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6236 true, false, false);
6237 grand_child
->SetDrawsContent(true);
6239 child
->AddChild(grand_child
.Pass());
6240 root
->AddChild(child
.Pass());
6242 LayerImplList render_surface_layer_list
;
6243 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6244 root
.get(), root
->bounds(), &render_surface_layer_list
);
6245 inputs
.can_adjust_raster_scales
= true;
6246 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6248 // We should have one render surface and one layers. The child has
6249 // hidden itself and the grand child.
6250 ASSERT_EQ(1u, render_surface_layer_list
.size());
6251 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6252 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
6255 void EmptyCopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
6257 TEST_F(LayerTreeHostCommonTest
, SubtreeHiddenWithCopyRequest
) {
6258 FakeImplProxy proxy
;
6259 TestSharedBitmapManager shared_bitmap_manager
;
6260 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
6261 host_impl
.CreatePendingTree();
6262 const gfx::Transform identity_matrix
;
6264 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6265 SetLayerPropertiesForTesting(root
.get(),
6272 root
->SetIsDrawable(true);
6274 scoped_refptr
<Layer
> copy_grand_parent
= Layer::Create(layer_settings());
6275 SetLayerPropertiesForTesting(copy_grand_parent
.get(),
6282 copy_grand_parent
->SetIsDrawable(true);
6284 scoped_refptr
<Layer
> copy_parent
= Layer::Create(layer_settings());
6285 SetLayerPropertiesForTesting(copy_parent
.get(),
6292 copy_parent
->SetIsDrawable(true);
6293 copy_parent
->SetForceRenderSurface(true);
6295 scoped_refptr
<Layer
> copy_layer
= Layer::Create(layer_settings());
6296 SetLayerPropertiesForTesting(copy_layer
.get(),
6303 copy_layer
->SetIsDrawable(true);
6305 scoped_refptr
<Layer
> copy_child
= Layer::Create(layer_settings());
6306 SetLayerPropertiesForTesting(copy_child
.get(),
6313 copy_child
->SetIsDrawable(true);
6315 scoped_refptr
<Layer
> copy_grand_parent_sibling_before
=
6316 Layer::Create(layer_settings());
6317 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before
.get(),
6324 copy_grand_parent_sibling_before
->SetIsDrawable(true);
6326 scoped_refptr
<Layer
> copy_grand_parent_sibling_after
=
6327 Layer::Create(layer_settings());
6328 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after
.get(),
6335 copy_grand_parent_sibling_after
->SetIsDrawable(true);
6337 copy_layer
->AddChild(copy_child
);
6338 copy_parent
->AddChild(copy_layer
);
6339 copy_grand_parent
->AddChild(copy_parent
);
6340 root
->AddChild(copy_grand_parent_sibling_before
);
6341 root
->AddChild(copy_grand_parent
);
6342 root
->AddChild(copy_grand_parent_sibling_after
);
6344 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6345 host
->SetRootLayer(root
);
6347 // Hide the copy_grand_parent and its subtree. But make a copy request in that
6348 // hidden subtree on copy_layer.
6349 copy_grand_parent
->SetHideLayerAndSubtree(true);
6350 copy_grand_parent_sibling_before
->SetHideLayerAndSubtree(true);
6351 copy_grand_parent_sibling_after
->SetHideLayerAndSubtree(true);
6352 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6353 base::Bind(&EmptyCopyOutputCallback
)));
6354 EXPECT_TRUE(copy_layer
->HasCopyRequest());
6356 RenderSurfaceLayerList render_surface_layer_list
;
6357 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6358 root
.get(), root
->bounds(), &render_surface_layer_list
);
6359 inputs
.can_adjust_raster_scales
= true;
6360 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6362 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
6363 EXPECT_TRUE(copy_grand_parent
->draw_properties().
6364 layer_or_descendant_has_copy_request
);
6365 EXPECT_TRUE(copy_parent
->draw_properties().
6366 layer_or_descendant_has_copy_request
);
6367 EXPECT_TRUE(copy_layer
->draw_properties().
6368 layer_or_descendant_has_copy_request
);
6369 EXPECT_FALSE(copy_child
->draw_properties().
6370 layer_or_descendant_has_copy_request
);
6371 EXPECT_FALSE(copy_grand_parent_sibling_before
->draw_properties().
6372 layer_or_descendant_has_copy_request
);
6373 EXPECT_FALSE(copy_grand_parent_sibling_after
->draw_properties().
6374 layer_or_descendant_has_copy_request
);
6376 // We should have three render surfaces, one for the root, one for the parent
6377 // since it owns a surface, and one for the copy_layer.
6378 ASSERT_EQ(3u, render_surface_layer_list
.size());
6379 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
6380 EXPECT_EQ(copy_parent
->id(), render_surface_layer_list
.at(1)->id());
6381 EXPECT_EQ(copy_layer
->id(), render_surface_layer_list
.at(2)->id());
6383 // The root render surface should have 2 contributing layers. The
6384 // copy_grand_parent is hidden along with its siblings, but the copy_parent
6385 // will appear since something in its subtree needs to be drawn for a copy
6387 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
6388 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6389 EXPECT_EQ(copy_parent
->id(),
6390 root
->render_surface()->layer_list().at(1)->id());
6392 // Nothing actually draws into the copy parent, so only the copy_layer will
6393 // appear in its list, since it needs to be drawn for the copy request.
6394 ASSERT_EQ(1u, copy_parent
->render_surface()->layer_list().size());
6395 EXPECT_EQ(copy_layer
->id(),
6396 copy_parent
->render_surface()->layer_list().at(0)->id());
6398 // The copy_layer's render surface should have two contributing layers.
6399 ASSERT_EQ(2u, copy_layer
->render_surface()->layer_list().size());
6400 EXPECT_EQ(copy_layer
->id(),
6401 copy_layer
->render_surface()->layer_list().at(0)->id());
6402 EXPECT_EQ(copy_child
->id(),
6403 copy_layer
->render_surface()->layer_list().at(1)->id());
6406 TEST_F(LayerTreeHostCommonTest
, ClippedOutCopyRequest
) {
6407 FakeImplProxy proxy
;
6408 TestSharedBitmapManager shared_bitmap_manager
;
6409 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
6410 host_impl
.CreatePendingTree();
6411 const gfx::Transform identity_matrix
;
6413 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6414 SetLayerPropertiesForTesting(root
.get(),
6421 root
->SetIsDrawable(true);
6423 scoped_refptr
<Layer
> copy_parent
= Layer::Create(layer_settings());
6424 SetLayerPropertiesForTesting(copy_parent
.get(),
6431 copy_parent
->SetIsDrawable(true);
6432 copy_parent
->SetMasksToBounds(true);
6434 scoped_refptr
<Layer
> copy_layer
= Layer::Create(layer_settings());
6435 SetLayerPropertiesForTesting(copy_layer
.get(),
6442 copy_layer
->SetIsDrawable(true);
6444 scoped_refptr
<Layer
> copy_child
= Layer::Create(layer_settings());
6445 SetLayerPropertiesForTesting(copy_child
.get(),
6452 copy_child
->SetIsDrawable(true);
6454 copy_layer
->AddChild(copy_child
);
6455 copy_parent
->AddChild(copy_layer
);
6456 root
->AddChild(copy_parent
);
6458 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6459 host
->SetRootLayer(root
);
6461 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6462 base::Bind(&EmptyCopyOutputCallback
)));
6463 EXPECT_TRUE(copy_layer
->HasCopyRequest());
6465 RenderSurfaceLayerList render_surface_layer_list
;
6466 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6467 root
.get(), root
->bounds(), &render_surface_layer_list
);
6468 inputs
.can_adjust_raster_scales
= true;
6469 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6471 // We should have one render surface, as the others are clipped out.
6472 ASSERT_EQ(1u, render_surface_layer_list
.size());
6473 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
6475 // The root render surface should only have 1 contributing layer, since the
6476 // other layers are empty/clipped away.
6477 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6478 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6481 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInsideSurface
) {
6482 FakeImplProxy proxy
;
6483 TestSharedBitmapManager shared_bitmap_manager
;
6484 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
6485 host_impl
.CreatePendingTree();
6486 const gfx::Transform identity_matrix
;
6488 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6489 SetLayerPropertiesForTesting(root
.get(),
6496 root
->SetIsDrawable(true);
6498 // The surface is moved slightly outside of the viewport.
6499 scoped_refptr
<Layer
> surface
= Layer::Create(layer_settings());
6500 SetLayerPropertiesForTesting(surface
.get(),
6503 gfx::PointF(-10, -20),
6507 surface
->SetForceRenderSurface(true);
6509 scoped_refptr
<Layer
> surface_child
= Layer::Create(layer_settings());
6510 SetLayerPropertiesForTesting(surface_child
.get(),
6517 surface_child
->SetIsDrawable(true);
6519 surface
->AddChild(surface_child
);
6520 root
->AddChild(surface
);
6522 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6523 host
->SetRootLayer(root
);
6525 RenderSurfaceLayerList render_surface_layer_list
;
6526 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6527 root
.get(), root
->bounds(), &render_surface_layer_list
);
6528 inputs
.can_adjust_raster_scales
= true;
6529 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6531 // The visible_content_rect for the |surface_child| should not be clipped by
6533 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
6534 surface_child
->visible_content_rect().ToString());
6537 TEST_F(LayerTreeHostCommonTest
, TransformedClipParent
) {
6538 // Ensure that a transform between the layer and its render surface is not a
6539 // problem. Constructs the following layer tree.
6541 // root (a render surface)
6543 // + clip_parent (scaled)
6544 // + intervening_clipping_layer
6547 // The render surface should be resized correctly and the clip child should
6548 // inherit the right clip rect.
6549 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6550 scoped_refptr
<Layer
> render_surface
= Layer::Create(layer_settings());
6551 scoped_refptr
<Layer
> clip_parent
= Layer::Create(layer_settings());
6552 scoped_refptr
<Layer
> intervening
= Layer::Create(layer_settings());
6553 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6554 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6556 root
->AddChild(render_surface
);
6557 render_surface
->AddChild(clip_parent
);
6558 clip_parent
->AddChild(intervening
);
6559 intervening
->AddChild(clip_child
);
6561 clip_child
->SetClipParent(clip_parent
.get());
6563 intervening
->SetMasksToBounds(true);
6564 clip_parent
->SetMasksToBounds(true);
6566 render_surface
->SetForceRenderSurface(true);
6568 gfx::Transform scale_transform
;
6569 scale_transform
.Scale(2, 2);
6571 gfx::Transform identity_transform
;
6573 SetLayerPropertiesForTesting(root
.get(),
6580 SetLayerPropertiesForTesting(render_surface
.get(),
6587 SetLayerPropertiesForTesting(clip_parent
.get(),
6590 gfx::PointF(1.f
, 1.f
),
6594 SetLayerPropertiesForTesting(intervening
.get(),
6597 gfx::PointF(1.f
, 1.f
),
6601 SetLayerPropertiesForTesting(clip_child
.get(),
6604 gfx::PointF(1.f
, 1.f
),
6609 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6610 host
->SetRootLayer(root
);
6612 ExecuteCalculateDrawProperties(root
.get());
6614 ASSERT_TRUE(root
->render_surface());
6615 ASSERT_TRUE(render_surface
->render_surface());
6617 // Ensure that we've inherited our clip parent's clip and weren't affected
6618 // by the intervening clip layer.
6619 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
6620 clip_parent
->clip_rect().ToString());
6621 ASSERT_EQ(clip_parent
->clip_rect().ToString(),
6622 clip_child
->clip_rect().ToString());
6623 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
6624 intervening
->clip_rect().ToString());
6626 // Ensure that the render surface reports a content rect that has been grown
6627 // to accomodate for the clip child.
6628 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
6629 render_surface
->render_surface()->content_rect().ToString());
6631 // The above check implies the two below, but they nicely demonstrate that
6632 // we've grown, despite the intervening layer's clip.
6633 ASSERT_TRUE(clip_parent
->clip_rect().Contains(
6634 render_surface
->render_surface()->content_rect()));
6635 ASSERT_FALSE(intervening
->clip_rect().Contains(
6636 render_surface
->render_surface()->content_rect()));
6639 TEST_F(LayerTreeHostCommonTest
, ClipParentWithInterveningRenderSurface
) {
6640 // Ensure that intervening render surfaces are not a problem in the basic
6641 // case. In the following tree, both render surfaces should be resized to
6642 // accomodate for the clip child, despite an intervening clip.
6644 // root (a render surface)
6645 // + clip_parent (masks to bounds)
6646 // + render_surface1 (sets opacity)
6647 // + intervening (masks to bounds)
6648 // + render_surface2 (also sets opacity)
6651 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6652 scoped_refptr
<Layer
> clip_parent
= Layer::Create(layer_settings());
6653 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
6654 scoped_refptr
<Layer
> intervening
= Layer::Create(layer_settings());
6655 scoped_refptr
<Layer
> render_surface2
= Layer::Create(layer_settings());
6656 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6657 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6659 root
->AddChild(clip_parent
);
6660 clip_parent
->AddChild(render_surface1
);
6661 render_surface1
->AddChild(intervening
);
6662 intervening
->AddChild(render_surface2
);
6663 render_surface2
->AddChild(clip_child
);
6665 clip_child
->SetClipParent(clip_parent
.get());
6667 intervening
->SetMasksToBounds(true);
6668 clip_parent
->SetMasksToBounds(true);
6670 render_surface1
->SetForceRenderSurface(true);
6671 render_surface2
->SetForceRenderSurface(true);
6673 gfx::Transform translation_transform
;
6674 translation_transform
.Translate(2, 2);
6676 gfx::Transform identity_transform
;
6677 SetLayerPropertiesForTesting(root
.get(),
6684 SetLayerPropertiesForTesting(clip_parent
.get(),
6685 translation_transform
,
6687 gfx::PointF(1.f
, 1.f
),
6691 SetLayerPropertiesForTesting(render_surface1
.get(),
6698 SetLayerPropertiesForTesting(intervening
.get(),
6701 gfx::PointF(1.f
, 1.f
),
6705 SetLayerPropertiesForTesting(render_surface2
.get(),
6712 SetLayerPropertiesForTesting(clip_child
.get(),
6715 gfx::PointF(-10.f
, -10.f
),
6720 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6721 host
->SetRootLayer(root
);
6723 ExecuteCalculateDrawProperties(root
.get());
6725 EXPECT_TRUE(root
->render_surface());
6726 EXPECT_TRUE(render_surface1
->render_surface());
6727 EXPECT_TRUE(render_surface2
->render_surface());
6729 // Since the render surfaces could have expanded, they should not clip (their
6730 // bounds would no longer be reliable). We should resort to layer clipping
6732 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6733 render_surface1
->render_surface()->clip_rect().ToString());
6734 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6735 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6736 render_surface2
->render_surface()->clip_rect().ToString());
6737 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
6739 // NB: clip rects are in target space.
6740 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6741 render_surface1
->clip_rect().ToString());
6742 EXPECT_TRUE(render_surface1
->is_clipped());
6744 // This value is inherited from the clipping ancestor layer, 'intervening'.
6745 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6746 render_surface2
->clip_rect().ToString());
6747 EXPECT_TRUE(render_surface2
->is_clipped());
6749 // The content rects of both render surfaces should both have expanded to
6750 // contain the clip child.
6751 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6752 render_surface1
->render_surface()->content_rect().ToString());
6753 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6754 render_surface2
->render_surface()->content_rect().ToString());
6756 // The clip child should have inherited the clip parent's clip (projected to
6757 // the right space, of course), and should have the correctly sized visible
6759 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6760 clip_child
->clip_rect().ToString());
6761 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
6762 clip_child
->visible_content_rect().ToString());
6763 EXPECT_TRUE(clip_child
->is_clipped());
6766 TEST_F(LayerTreeHostCommonTest
, ClipParentScrolledInterveningLayer
) {
6767 // Ensure that intervening render surfaces are not a problem, even if there
6768 // is a scroll involved. Note, we do _not_ have to consider any other sort
6771 // root (a render surface)
6772 // + clip_parent (masks to bounds)
6773 // + render_surface1 (sets opacity)
6774 // + intervening (masks to bounds AND scrolls)
6775 // + render_surface2 (also sets opacity)
6778 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6779 scoped_refptr
<Layer
> clip_parent
= Layer::Create(layer_settings());
6780 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
6781 scoped_refptr
<Layer
> intervening
= Layer::Create(layer_settings());
6782 scoped_refptr
<Layer
> render_surface2
= Layer::Create(layer_settings());
6783 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6784 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6786 root
->AddChild(clip_parent
);
6787 clip_parent
->AddChild(render_surface1
);
6788 render_surface1
->AddChild(intervening
);
6789 intervening
->AddChild(render_surface2
);
6790 render_surface2
->AddChild(clip_child
);
6792 clip_child
->SetClipParent(clip_parent
.get());
6794 intervening
->SetMasksToBounds(true);
6795 clip_parent
->SetMasksToBounds(true);
6796 intervening
->SetScrollClipLayerId(clip_parent
->id());
6797 intervening
->SetScrollOffset(gfx::ScrollOffset(3, 3));
6799 render_surface1
->SetForceRenderSurface(true);
6800 render_surface2
->SetForceRenderSurface(true);
6802 gfx::Transform translation_transform
;
6803 translation_transform
.Translate(2, 2);
6805 gfx::Transform identity_transform
;
6806 SetLayerPropertiesForTesting(root
.get(),
6813 SetLayerPropertiesForTesting(clip_parent
.get(),
6814 translation_transform
,
6816 gfx::PointF(1.f
, 1.f
),
6820 SetLayerPropertiesForTesting(render_surface1
.get(),
6827 SetLayerPropertiesForTesting(intervening
.get(),
6830 gfx::PointF(1.f
, 1.f
),
6834 SetLayerPropertiesForTesting(render_surface2
.get(),
6841 SetLayerPropertiesForTesting(clip_child
.get(),
6844 gfx::PointF(-10.f
, -10.f
),
6849 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6850 host
->SetRootLayer(root
);
6852 ExecuteCalculateDrawProperties(root
.get());
6854 EXPECT_TRUE(root
->render_surface());
6855 EXPECT_TRUE(render_surface1
->render_surface());
6856 EXPECT_TRUE(render_surface2
->render_surface());
6858 // Since the render surfaces could have expanded, they should not clip (their
6859 // bounds would no longer be reliable). We should resort to layer clipping
6861 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6862 render_surface1
->render_surface()->clip_rect().ToString());
6863 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6864 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6865 render_surface2
->render_surface()->clip_rect().ToString());
6866 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
6868 // NB: clip rects are in target space.
6869 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6870 render_surface1
->clip_rect().ToString());
6871 EXPECT_TRUE(render_surface1
->is_clipped());
6873 // This value is inherited from the clipping ancestor layer, 'intervening'.
6874 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6875 render_surface2
->clip_rect().ToString());
6876 EXPECT_TRUE(render_surface2
->is_clipped());
6878 // The content rects of both render surfaces should both have expanded to
6879 // contain the clip child.
6880 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6881 render_surface1
->render_surface()->content_rect().ToString());
6882 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6883 render_surface2
->render_surface()->content_rect().ToString());
6885 // The clip child should have inherited the clip parent's clip (projected to
6886 // the right space, of course), and should have the correctly sized visible
6888 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6889 clip_child
->clip_rect().ToString());
6890 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6891 clip_child
->visible_content_rect().ToString());
6892 EXPECT_TRUE(clip_child
->is_clipped());
6895 TEST_F(LayerTreeHostCommonTest
, DescendantsOfClipChildren
) {
6896 // Ensures that descendants of the clip child inherit the correct clip.
6898 // root (a render surface)
6899 // + clip_parent (masks to bounds)
6900 // + intervening (masks to bounds)
6904 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6905 scoped_refptr
<Layer
> clip_parent
= Layer::Create(layer_settings());
6906 scoped_refptr
<Layer
> intervening
= Layer::Create(layer_settings());
6907 scoped_refptr
<Layer
> clip_child
= Layer::Create(layer_settings());
6908 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
6909 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6911 root
->AddChild(clip_parent
);
6912 clip_parent
->AddChild(intervening
);
6913 intervening
->AddChild(clip_child
);
6914 clip_child
->AddChild(child
);
6916 clip_child
->SetClipParent(clip_parent
.get());
6918 intervening
->SetMasksToBounds(true);
6919 clip_parent
->SetMasksToBounds(true);
6921 gfx::Transform identity_transform
;
6922 SetLayerPropertiesForTesting(root
.get(),
6929 SetLayerPropertiesForTesting(clip_parent
.get(),
6936 SetLayerPropertiesForTesting(intervening
.get(),
6943 SetLayerPropertiesForTesting(clip_child
.get(),
6950 SetLayerPropertiesForTesting(child
.get(),
6958 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6959 host
->SetRootLayer(root
);
6961 ExecuteCalculateDrawProperties(root
.get());
6963 EXPECT_TRUE(root
->render_surface());
6965 // Neither the clip child nor its descendant should have inherited the clip
6966 // from |intervening|.
6967 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6968 clip_child
->clip_rect().ToString());
6969 EXPECT_TRUE(clip_child
->is_clipped());
6970 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6971 child
->visible_content_rect().ToString());
6972 EXPECT_TRUE(child
->is_clipped());
6975 TEST_F(LayerTreeHostCommonTest
,
6976 SurfacesShouldBeUnaffectedByNonDescendantClipChildren
) {
6977 // Ensures that non-descendant clip children in the tree do not affect
6980 // root (a render surface)
6981 // + clip_parent (masks to bounds)
6982 // + render_surface1
6984 // + render_surface2
6987 // In this example render_surface2 should be unaffected by clip_child.
6988 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
6989 scoped_refptr
<Layer
> clip_parent
= Layer::Create(layer_settings());
6990 scoped_refptr
<Layer
> render_surface1
= Layer::Create(layer_settings());
6991 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6992 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6993 scoped_refptr
<Layer
> render_surface2
= Layer::Create(layer_settings());
6994 scoped_refptr
<LayerWithForcedDrawsContent
> non_clip_child
=
6995 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
6997 root
->AddChild(clip_parent
);
6998 clip_parent
->AddChild(render_surface1
);
6999 render_surface1
->AddChild(clip_child
);
7000 clip_parent
->AddChild(render_surface2
);
7001 render_surface2
->AddChild(non_clip_child
);
7003 clip_child
->SetClipParent(clip_parent
.get());
7005 clip_parent
->SetMasksToBounds(true);
7006 render_surface1
->SetMasksToBounds(true);
7008 gfx::Transform identity_transform
;
7009 SetLayerPropertiesForTesting(root
.get(),
7016 SetLayerPropertiesForTesting(clip_parent
.get(),
7023 SetLayerPropertiesForTesting(render_surface1
.get(),
7030 SetLayerPropertiesForTesting(render_surface2
.get(),
7037 SetLayerPropertiesForTesting(clip_child
.get(),
7044 SetLayerPropertiesForTesting(non_clip_child
.get(),
7052 render_surface1
->SetForceRenderSurface(true);
7053 render_surface2
->SetForceRenderSurface(true);
7055 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7056 host
->SetRootLayer(root
);
7058 ExecuteCalculateDrawProperties(root
.get());
7060 EXPECT_TRUE(root
->render_surface());
7061 EXPECT_TRUE(render_surface1
->render_surface());
7062 EXPECT_TRUE(render_surface2
->render_surface());
7064 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
7065 render_surface1
->clip_rect().ToString());
7066 EXPECT_TRUE(render_surface1
->is_clipped());
7068 // The render surface should not clip (it has unclipped descendants), instead
7069 // it should rely on layer clipping.
7070 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
7071 render_surface1
->render_surface()->clip_rect().ToString());
7072 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
7074 // That said, it should have grown to accomodate the unclipped descendant.
7075 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
7076 render_surface1
->render_surface()->content_rect().ToString());
7078 // This render surface should clip. It has no unclipped descendants.
7079 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
7080 render_surface2
->clip_rect().ToString());
7081 EXPECT_TRUE(render_surface2
->render_surface()->is_clipped());
7083 // It also shouldn't have grown to accomodate the clip child.
7084 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
7085 render_surface2
->render_surface()->content_rect().ToString());
7087 // Sanity check our num_unclipped_descendants values.
7088 EXPECT_EQ(1, render_surface1
->num_unclipped_descendants());
7089 EXPECT_EQ(0, render_surface2
->num_unclipped_descendants());
7092 TEST_F(LayerTreeHostCommonTest
, CanRenderToSeparateSurface
) {
7093 FakeImplProxy proxy
;
7094 TestSharedBitmapManager shared_bitmap_manager
;
7095 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
7096 scoped_ptr
<LayerImpl
> root
=
7097 LayerImpl::Create(host_impl
.active_tree(), 12345);
7098 scoped_ptr
<LayerImpl
> child1
=
7099 LayerImpl::Create(host_impl
.active_tree(), 123456);
7100 scoped_ptr
<LayerImpl
> child2
=
7101 LayerImpl::Create(host_impl
.active_tree(), 1234567);
7102 scoped_ptr
<LayerImpl
> child3
=
7103 LayerImpl::Create(host_impl
.active_tree(), 12345678);
7105 gfx::Transform identity_matrix
;
7106 gfx::Point3F transform_origin
;
7107 gfx::PointF position
;
7108 gfx::Size
bounds(100, 100);
7109 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
7110 position
, bounds
, true, false, true);
7111 root
->SetDrawsContent(true);
7113 // This layer structure normally forces render surface due to preserves3d
7115 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
, transform_origin
,
7116 position
, bounds
, false, true, true);
7117 child1
->SetDrawsContent(true);
7118 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
, transform_origin
,
7119 position
, bounds
, true, false, false);
7120 child2
->SetDrawsContent(true);
7121 SetLayerPropertiesForTesting(child3
.get(), identity_matrix
, transform_origin
,
7122 position
, bounds
, true, false, false);
7123 child3
->SetDrawsContent(true);
7125 child2
->Set3dSortingContextId(1);
7126 child3
->Set3dSortingContextId(1);
7128 child2
->AddChild(child3
.Pass());
7129 child1
->AddChild(child2
.Pass());
7130 root
->AddChild(child1
.Pass());
7133 LayerImplList render_surface_layer_list
;
7134 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root
.get());
7135 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7136 root
.get(), root
->bounds(), &render_surface_layer_list
);
7137 inputs
.can_render_to_separate_surface
= true;
7138 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7140 EXPECT_EQ(2u, render_surface_layer_list
.size());
7142 int count_represents_target_render_surface
= 0;
7143 int count_represents_contributing_render_surface
= 0;
7144 int count_represents_itself
= 0;
7145 auto end
= LayerIterator
<LayerImpl
>::End(&render_surface_layer_list
);
7146 for (auto it
= LayerIterator
<LayerImpl
>::Begin(&render_surface_layer_list
);
7148 if (it
.represents_target_render_surface())
7149 count_represents_target_render_surface
++;
7150 if (it
.represents_contributing_render_surface())
7151 count_represents_contributing_render_surface
++;
7152 if (it
.represents_itself())
7153 count_represents_itself
++;
7156 // Two render surfaces.
7157 EXPECT_EQ(2, count_represents_target_render_surface
);
7158 // Second render surface contributes to root render surface.
7159 EXPECT_EQ(1, count_represents_contributing_render_surface
);
7160 // All 4 layers represent itself.
7161 EXPECT_EQ(4, count_represents_itself
);
7165 LayerImplList render_surface_layer_list
;
7166 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7167 root
.get(), root
->bounds(), &render_surface_layer_list
);
7168 inputs
.can_render_to_separate_surface
= false;
7169 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7171 EXPECT_EQ(1u, render_surface_layer_list
.size());
7173 int count_represents_target_render_surface
= 0;
7174 int count_represents_contributing_render_surface
= 0;
7175 int count_represents_itself
= 0;
7176 auto end
= LayerIterator
<LayerImpl
>::End(&render_surface_layer_list
);
7177 for (auto it
= LayerIterator
<LayerImpl
>::Begin(&render_surface_layer_list
);
7179 if (it
.represents_target_render_surface())
7180 count_represents_target_render_surface
++;
7181 if (it
.represents_contributing_render_surface())
7182 count_represents_contributing_render_surface
++;
7183 if (it
.represents_itself())
7184 count_represents_itself
++;
7187 // Only root layer has a render surface.
7188 EXPECT_EQ(1, count_represents_target_render_surface
);
7189 // No layer contributes a render surface to root render surface.
7190 EXPECT_EQ(0, count_represents_contributing_render_surface
);
7191 // All 4 layers represent itself.
7192 EXPECT_EQ(4, count_represents_itself
);
7196 TEST_F(LayerTreeHostCommonTest
, DoNotIncludeBackfaceInvisibleSurfaces
) {
7197 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7198 scoped_refptr
<Layer
> render_surface
= Layer::Create(layer_settings());
7199 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7200 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7202 root
->AddChild(render_surface
);
7203 render_surface
->AddChild(child
);
7205 gfx::Transform identity_transform
;
7206 SetLayerPropertiesForTesting(root
.get(),
7213 SetLayerPropertiesForTesting(render_surface
.get(),
7220 SetLayerPropertiesForTesting(child
.get(),
7228 root
->SetShouldFlattenTransform(false);
7229 root
->Set3dSortingContextId(1);
7230 render_surface
->SetDoubleSided(false);
7231 render_surface
->SetForceRenderSurface(true);
7233 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7234 host
->SetRootLayer(root
);
7236 ExecuteCalculateDrawProperties(root
.get());
7238 EXPECT_EQ(2u, render_surface_layer_list()->size());
7240 render_surface_layer_list()->at(0)
7241 ->render_surface()->layer_list().size());
7243 render_surface_layer_list()->at(1)
7244 ->render_surface()->layer_list().size());
7246 gfx::Transform rotation_transform
= identity_transform
;
7247 rotation_transform
.RotateAboutXAxis(180.0);
7249 render_surface
->SetTransform(rotation_transform
);
7251 ExecuteCalculateDrawProperties(root
.get());
7253 EXPECT_EQ(1u, render_surface_layer_list()->size());
7255 render_surface_layer_list()->at(0)
7256 ->render_surface()->layer_list().size());
7259 TEST_F(LayerTreeHostCommonTest
, ClippedByScrollParent
) {
7260 // Checks that the simple case (being clipped by a scroll parent that would
7261 // have been processed before you anyhow) results in the right clips.
7264 // + scroll_parent_border
7265 // | + scroll_parent_clip
7266 // | + scroll_parent
7269 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7270 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create(layer_settings());
7271 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create(layer_settings());
7272 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7273 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7274 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7275 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7277 root
->AddChild(scroll_child
);
7279 root
->AddChild(scroll_parent_border
);
7280 scroll_parent_border
->AddChild(scroll_parent_clip
);
7281 scroll_parent_clip
->AddChild(scroll_parent
);
7283 scroll_parent_clip
->SetMasksToBounds(true);
7285 scroll_child
->SetScrollParent(scroll_parent
.get());
7287 gfx::Transform identity_transform
;
7288 SetLayerPropertiesForTesting(root
.get(),
7295 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7302 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7309 SetLayerPropertiesForTesting(scroll_parent
.get(),
7316 SetLayerPropertiesForTesting(scroll_child
.get(),
7324 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7325 host
->SetRootLayer(root
);
7327 ExecuteCalculateDrawProperties(root
.get());
7329 EXPECT_TRUE(root
->render_surface());
7331 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7332 scroll_child
->clip_rect().ToString());
7333 EXPECT_TRUE(scroll_child
->is_clipped());
7336 TEST_F(LayerTreeHostCommonTest
, SingularTransformSubtreesDoNotDraw
) {
7337 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
7338 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7339 scoped_refptr
<LayerWithForcedDrawsContent
> parent
=
7340 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7341 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7342 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7344 root
->AddChild(parent
);
7345 parent
->AddChild(child
);
7347 gfx::Transform identity_transform
;
7348 SetLayerPropertiesForTesting(root
.get(),
7355 root
->SetForceRenderSurface(true);
7356 SetLayerPropertiesForTesting(parent
.get(),
7363 parent
->SetForceRenderSurface(true);
7364 SetLayerPropertiesForTesting(child
.get(),
7371 child
->SetForceRenderSurface(true);
7373 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7374 host
->SetRootLayer(root
);
7376 ExecuteCalculateDrawProperties(root
.get());
7378 EXPECT_EQ(3u, render_surface_layer_list()->size());
7380 gfx::Transform singular_transform
;
7381 singular_transform
.Scale3d(
7382 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
7384 child
->SetTransform(singular_transform
);
7386 ExecuteCalculateDrawProperties(root
.get());
7388 EXPECT_EQ(2u, render_surface_layer_list()->size());
7390 // Ensure that the entire subtree under a layer with singular transform does
7391 // not get rendered.
7392 parent
->SetTransform(singular_transform
);
7393 child
->SetTransform(identity_transform
);
7395 ExecuteCalculateDrawProperties(root
.get());
7397 EXPECT_EQ(1u, render_surface_layer_list()->size());
7400 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollParent
) {
7401 // Checks that clipping by a scroll parent that follows you in paint order
7402 // still results in correct clipping.
7406 // + scroll_parent_border
7407 // + scroll_parent_clip
7410 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7411 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create(layer_settings());
7412 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create(layer_settings());
7413 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7414 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7415 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7416 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7418 root
->AddChild(scroll_parent_border
);
7419 scroll_parent_border
->AddChild(scroll_parent_clip
);
7420 scroll_parent_clip
->AddChild(scroll_parent
);
7422 root
->AddChild(scroll_child
);
7424 scroll_parent_clip
->SetMasksToBounds(true);
7426 scroll_child
->SetScrollParent(scroll_parent
.get());
7428 gfx::Transform identity_transform
;
7429 SetLayerPropertiesForTesting(root
.get(),
7436 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7443 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7450 SetLayerPropertiesForTesting(scroll_parent
.get(),
7457 SetLayerPropertiesForTesting(scroll_child
.get(),
7465 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7466 host
->SetRootLayer(root
);
7468 ExecuteCalculateDrawProperties(root
.get());
7470 EXPECT_TRUE(root
->render_surface());
7472 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7473 scroll_child
->clip_rect().ToString());
7474 EXPECT_TRUE(scroll_child
->is_clipped());
7477 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollGrandparent
) {
7478 // Checks that clipping by a scroll parent and scroll grandparent that follow
7479 // you in paint order still results in correct clipping.
7483 // + scroll_parent_border
7484 // | + scroll_parent_clip
7485 // | + scroll_parent
7486 // + scroll_grandparent_border
7487 // + scroll_grandparent_clip
7488 // + scroll_grandparent
7490 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7491 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create(layer_settings());
7492 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create(layer_settings());
7493 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7494 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7496 scoped_refptr
<Layer
> scroll_grandparent_border
=
7497 Layer::Create(layer_settings());
7498 scoped_refptr
<Layer
> scroll_grandparent_clip
=
7499 Layer::Create(layer_settings());
7500 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_grandparent
=
7501 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7503 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7504 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7506 root
->AddChild(scroll_child
);
7508 root
->AddChild(scroll_parent_border
);
7509 scroll_parent_border
->AddChild(scroll_parent_clip
);
7510 scroll_parent_clip
->AddChild(scroll_parent
);
7512 root
->AddChild(scroll_grandparent_border
);
7513 scroll_grandparent_border
->AddChild(scroll_grandparent_clip
);
7514 scroll_grandparent_clip
->AddChild(scroll_grandparent
);
7516 scroll_parent_clip
->SetMasksToBounds(true);
7517 scroll_grandparent_clip
->SetMasksToBounds(true);
7519 scroll_child
->SetScrollParent(scroll_parent
.get());
7520 scroll_parent_border
->SetScrollParent(scroll_grandparent
.get());
7522 gfx::Transform identity_transform
;
7523 SetLayerPropertiesForTesting(root
.get(),
7530 SetLayerPropertiesForTesting(scroll_grandparent_border
.get(),
7537 SetLayerPropertiesForTesting(scroll_grandparent_clip
.get(),
7544 SetLayerPropertiesForTesting(scroll_grandparent
.get(),
7551 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7558 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7565 SetLayerPropertiesForTesting(scroll_parent
.get(),
7572 SetLayerPropertiesForTesting(scroll_child
.get(),
7580 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7581 host
->SetRootLayer(root
);
7583 ExecuteCalculateDrawProperties(root
.get());
7585 EXPECT_TRUE(root
->render_surface());
7587 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7588 scroll_child
->clip_rect().ToString());
7589 EXPECT_TRUE(scroll_child
->is_clipped());
7591 // Despite the fact that we visited the above layers out of order to get the
7592 // correct clip, the layer lists should be unaffected.
7593 EXPECT_EQ(3u, root
->render_surface()->layer_list().size());
7594 EXPECT_EQ(scroll_child
.get(),
7595 root
->render_surface()->layer_list().at(0).get());
7596 EXPECT_EQ(scroll_parent
.get(),
7597 root
->render_surface()->layer_list().at(1).get());
7598 EXPECT_EQ(scroll_grandparent
.get(),
7599 root
->render_surface()->layer_list().at(2).get());
7602 TEST_F(LayerTreeHostCommonTest
, OutOfOrderClippingRequiresRSLLSorting
) {
7603 // Ensures that even if we visit layers out of order, we still produce a
7604 // correctly ordered render surface layer list.
7607 // + scroll_parent_border
7608 // + scroll_parent_clip
7610 // + render_surface1
7611 // + scroll_grandparent_border
7612 // + scroll_grandparent_clip
7613 // + scroll_grandparent
7614 // + render_surface2
7616 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
7617 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7619 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create(layer_settings());
7620 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create(layer_settings());
7621 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7622 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7623 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface1
=
7624 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7626 scoped_refptr
<Layer
> scroll_grandparent_border
=
7627 Layer::Create(layer_settings());
7628 scoped_refptr
<Layer
> scroll_grandparent_clip
=
7629 Layer::Create(layer_settings());
7630 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_grandparent
=
7631 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7632 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface2
=
7633 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7635 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7636 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7638 root
->AddChild(scroll_child
);
7640 root
->AddChild(scroll_parent_border
);
7641 scroll_parent_border
->AddChild(scroll_parent_clip
);
7642 scroll_parent_clip
->AddChild(scroll_parent
);
7643 scroll_parent
->AddChild(render_surface2
);
7645 root
->AddChild(scroll_grandparent_border
);
7646 scroll_grandparent_border
->AddChild(scroll_grandparent_clip
);
7647 scroll_grandparent_clip
->AddChild(scroll_grandparent
);
7648 scroll_grandparent
->AddChild(render_surface1
);
7650 scroll_parent_clip
->SetMasksToBounds(true);
7651 scroll_grandparent_clip
->SetMasksToBounds(true);
7653 scroll_child
->SetScrollParent(scroll_parent
.get());
7654 scroll_parent_border
->SetScrollParent(scroll_grandparent
.get());
7656 render_surface1
->SetForceRenderSurface(true);
7657 render_surface2
->SetForceRenderSurface(true);
7659 gfx::Transform identity_transform
;
7660 SetLayerPropertiesForTesting(root
.get(),
7667 SetLayerPropertiesForTesting(scroll_grandparent_border
.get(),
7674 SetLayerPropertiesForTesting(scroll_grandparent_clip
.get(),
7681 SetLayerPropertiesForTesting(scroll_grandparent
.get(),
7688 SetLayerPropertiesForTesting(render_surface1
.get(),
7695 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7702 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7709 SetLayerPropertiesForTesting(scroll_parent
.get(),
7716 SetLayerPropertiesForTesting(render_surface2
.get(),
7723 SetLayerPropertiesForTesting(scroll_child
.get(),
7731 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7732 host
->SetRootLayer(root
);
7734 RenderSurfaceLayerList render_surface_layer_list
;
7735 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
7739 &render_surface_layer_list
);
7741 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7743 EXPECT_TRUE(root
->render_surface());
7745 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7746 scroll_child
->clip_rect().ToString());
7747 EXPECT_TRUE(scroll_child
->is_clipped());
7749 // Despite the fact that we had to process the layers out of order to get the
7750 // right clip, our render_surface_layer_list's order should be unaffected.
7751 EXPECT_EQ(3u, render_surface_layer_list
.size());
7752 EXPECT_EQ(root
.get(), render_surface_layer_list
.at(0));
7753 EXPECT_EQ(render_surface2
.get(), render_surface_layer_list
.at(1));
7754 EXPECT_EQ(render_surface1
.get(), render_surface_layer_list
.at(2));
7755 EXPECT_TRUE(render_surface_layer_list
.at(0)->render_surface());
7756 EXPECT_TRUE(render_surface_layer_list
.at(1)->render_surface());
7757 EXPECT_TRUE(render_surface_layer_list
.at(2)->render_surface());
7760 TEST_F(LayerTreeHostCommonTest
, FixedPositionWithInterveningRenderSurface
) {
7761 // Ensures that when we have a render surface between a fixed position layer
7762 // and its container, we compute the fixed position layer's draw transform
7763 // with respect to that intervening render surface, not with respect to its
7764 // container's render target.
7771 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
7772 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface
=
7773 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7774 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
7775 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7776 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7777 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
7779 root
->AddChild(render_surface
);
7780 render_surface
->AddChild(fixed
);
7781 fixed
->AddChild(child
);
7783 root
->SetIsContainerForFixedPositionLayers(true);
7784 render_surface
->SetForceRenderSurface(true);
7786 LayerPositionConstraint constraint
;
7787 constraint
.set_is_fixed_position(true);
7788 fixed
->SetPositionConstraint(constraint
);
7790 SetLayerPropertiesForTesting(root
.get(), gfx::Transform(), gfx::Point3F(),
7791 gfx::PointF(), gfx::Size(50, 50), true, false);
7792 SetLayerPropertiesForTesting(render_surface
.get(), gfx::Transform(),
7793 gfx::Point3F(), gfx::PointF(7.f
, 9.f
),
7794 gfx::Size(50, 50), true, false);
7795 SetLayerPropertiesForTesting(fixed
.get(), gfx::Transform(), gfx::Point3F(),
7796 gfx::PointF(10.f
, 15.f
), gfx::Size(50, 50), true,
7798 SetLayerPropertiesForTesting(child
.get(), gfx::Transform(), gfx::Point3F(),
7799 gfx::PointF(1.f
, 2.f
), gfx::Size(50, 50), true,
7802 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7803 host
->SetRootLayer(root
);
7805 ExecuteCalculateDrawProperties(root
.get());
7807 gfx::Transform expected_fixed_draw_transform
;
7808 expected_fixed_draw_transform
.Translate(10.f
, 15.f
);
7809 EXPECT_EQ(expected_fixed_draw_transform
, fixed
->draw_transform());
7811 gfx::Transform expected_fixed_screen_space_transform
;
7812 expected_fixed_screen_space_transform
.Translate(17.f
, 24.f
);
7813 EXPECT_EQ(expected_fixed_screen_space_transform
,
7814 fixed
->screen_space_transform());
7816 gfx::Transform expected_child_draw_transform
;
7817 expected_child_draw_transform
.Translate(11.f
, 17.f
);
7818 EXPECT_EQ(expected_child_draw_transform
, child
->draw_transform());
7820 gfx::Transform expected_child_screen_space_transform
;
7821 expected_child_screen_space_transform
.Translate(18.f
, 26.f
);
7822 EXPECT_EQ(expected_child_screen_space_transform
,
7823 child
->screen_space_transform());
7826 TEST_F(LayerTreeHostCommonTest
, ScrollCompensationWithRounding
) {
7827 // This test verifies that a scrolling layer that gets snapped to
7828 // integer coordinates doesn't move a fixed position child.
7835 FakeImplProxy proxy
;
7836 TestSharedBitmapManager shared_bitmap_manager
;
7837 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
7838 host_impl
.CreatePendingTree();
7839 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7840 scoped_ptr
<LayerImpl
> container
=
7841 LayerImpl::Create(host_impl
.active_tree(), 2);
7842 LayerImpl
* container_layer
= container
.get();
7843 scoped_ptr
<LayerImpl
> scroller
=
7844 LayerImpl::Create(host_impl
.active_tree(), 3);
7845 LayerImpl
* scroll_layer
= scroller
.get();
7846 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
7847 LayerImpl
* fixed_layer
= fixed
.get();
7849 container
->SetIsContainerForFixedPositionLayers(true);
7851 LayerPositionConstraint constraint
;
7852 constraint
.set_is_fixed_position(true);
7853 fixed
->SetPositionConstraint(constraint
);
7855 scroller
->SetScrollClipLayer(container
->id());
7857 gfx::Transform identity_transform
;
7858 gfx::Transform container_transform
;
7859 container_transform
.Translate3d(10.0, 20.0, 0.0);
7860 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
7862 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7863 gfx::PointF(), gfx::Size(50, 50), true, false,
7865 SetLayerPropertiesForTesting(container
.get(), container_transform
,
7866 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7867 true, false, false);
7868 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
7869 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7870 true, false, false);
7871 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
7872 gfx::PointF(), gfx::Size(50, 50), true, false,
7875 scroller
->AddChild(fixed
.Pass());
7876 container
->AddChild(scroller
.Pass());
7877 root
->AddChild(container
.Pass());
7879 // Rounded to integers already.
7881 gfx::Vector2dF
scroll_delta(3.0, 5.0);
7882 scroll_layer
->SetScrollDelta(scroll_delta
);
7884 LayerImplList render_surface_layer_list
;
7885 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7886 root
.get(), root
->bounds(), &render_surface_layer_list
);
7887 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7889 EXPECT_TRANSFORMATION_MATRIX_EQ(
7890 container_layer
->draw_properties().screen_space_transform
,
7891 fixed_layer
->draw_properties().screen_space_transform
);
7893 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7895 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
7896 .screen_space_transform
.To2dTranslation(),
7897 container_offset
- scroll_delta
);
7900 // Scroll delta requiring rounding.
7902 gfx::Vector2dF
scroll_delta(4.1f
, 8.1f
);
7903 scroll_layer
->SetScrollDelta(scroll_delta
);
7905 gfx::Vector2dF
rounded_scroll_delta(4.f
, 8.f
);
7907 LayerImplList render_surface_layer_list
;
7908 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7909 root
.get(), root
->bounds(), &render_surface_layer_list
);
7910 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7912 EXPECT_TRANSFORMATION_MATRIX_EQ(
7913 container_layer
->draw_properties().screen_space_transform
,
7914 fixed_layer
->draw_properties().screen_space_transform
);
7916 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7918 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
7919 .screen_space_transform
.To2dTranslation(),
7920 container_offset
- rounded_scroll_delta
);
7923 // Scale is applied earlier in the tree.
7925 gfx::Transform scaled_container_transform
= container_transform
;
7926 scaled_container_transform
.Scale3d(3.0, 3.0, 1.0);
7927 container_layer
->SetTransform(scaled_container_transform
);
7929 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
7930 scroll_layer
->SetScrollDelta(scroll_delta
);
7932 LayerImplList render_surface_layer_list
;
7933 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7934 root
.get(), root
->bounds(), &render_surface_layer_list
);
7935 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7937 EXPECT_TRANSFORMATION_MATRIX_EQ(
7938 container_layer
->draw_properties().screen_space_transform
,
7939 fixed_layer
->draw_properties().screen_space_transform
);
7941 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7944 container_layer
->SetTransform(container_transform
);
7947 // Scale is applied on the scroll layer itself.
7949 gfx::Transform scale_transform
;
7950 scale_transform
.Scale3d(3.0, 3.0, 1.0);
7951 scroll_layer
->SetTransform(scale_transform
);
7953 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
7954 scroll_layer
->SetScrollDelta(scroll_delta
);
7956 LayerImplList render_surface_layer_list
;
7957 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7958 root
.get(), root
->bounds(), &render_surface_layer_list
);
7959 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7962 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7965 scroll_layer
->SetTransform(identity_transform
);
7969 TEST_F(LayerTreeHostCommonTest
,
7970 ScrollCompensationMainScrollOffsetFractionalPart
) {
7971 // This test verifies that a scrolling layer that has fractional scroll offset
7972 // from main doesn't move a fixed position child.
7979 FakeImplProxy proxy
;
7980 TestSharedBitmapManager shared_bitmap_manager
;
7981 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
7982 host_impl
.CreatePendingTree();
7983 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7984 scoped_ptr
<LayerImpl
> container
=
7985 LayerImpl::Create(host_impl
.active_tree(), 2);
7986 LayerImpl
* container_layer
= container
.get();
7987 scoped_ptr
<LayerImpl
> scroller
=
7988 LayerImpl::Create(host_impl
.active_tree(), 3);
7989 LayerImpl
* scroll_layer
= scroller
.get();
7990 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
7991 LayerImpl
* fixed_layer
= fixed
.get();
7993 container
->SetIsContainerForFixedPositionLayers(true);
7995 LayerPositionConstraint constraint
;
7996 constraint
.set_is_fixed_position(true);
7997 fixed
->SetPositionConstraint(constraint
);
7999 scroller
->SetScrollClipLayer(container
->id());
8001 gfx::Transform identity_transform
;
8002 gfx::Transform container_transform
;
8003 container_transform
.Translate3d(10.0, 20.0, 0.0);
8004 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
8006 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
8007 gfx::PointF(), gfx::Size(50, 50), true, false,
8009 SetLayerPropertiesForTesting(container
.get(), container_transform
,
8010 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
8011 true, false, false);
8012 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
8013 gfx::Point3F(), gfx::PointF(0.0, 0.0),
8014 gfx::Size(30, 30), true, false, false);
8016 gfx::ScrollOffset
scroll_offset(3.3, 4.2);
8017 gfx::Vector2dF
main_scroll_fractional_part(0.3f
, 0.2f
);
8018 gfx::Vector2dF
scroll_delta(0.1f
, 0.4f
);
8019 // Blink only uses the integer part of the scroll_offset for fixed
8021 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
8022 gfx::PointF(3.0f
, 4.0f
), gfx::Size(50, 50), true,
8024 scroll_layer
->PushScrollOffsetFromMainThread(scroll_offset
);
8025 scroll_layer
->SetScrollDelta(scroll_delta
);
8026 scroll_layer
->SetScrollCompensationAdjustment(main_scroll_fractional_part
);
8028 scroller
->AddChild(fixed
.Pass());
8029 container
->AddChild(scroller
.Pass());
8030 root
->AddChild(container
.Pass());
8032 LayerImplList render_surface_layer_list
;
8033 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
8034 root
.get(), root
->bounds(), &render_surface_layer_list
);
8035 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8037 EXPECT_TRANSFORMATION_MATRIX_EQ(
8038 container_layer
->draw_properties().screen_space_transform
,
8039 fixed_layer
->draw_properties().screen_space_transform
);
8041 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
8044 gfx::ScrollOffset effective_scroll_offset
=
8045 ScrollOffsetWithDelta(scroll_offset
, scroll_delta
);
8046 gfx::Vector2d rounded_effective_scroll_offset
=
8047 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset
));
8049 scroll_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
8050 container_offset
- rounded_effective_scroll_offset
);
8053 class AnimationScaleFactorTrackingLayerImpl
: public LayerImpl
{
8055 static scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> Create(
8056 LayerTreeImpl
* tree_impl
,
8058 return make_scoped_ptr(
8059 new AnimationScaleFactorTrackingLayerImpl(tree_impl
, id
));
8062 ~AnimationScaleFactorTrackingLayerImpl() override
{}
8065 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl
* tree_impl
,
8067 : LayerImpl(tree_impl
, id
) {
8068 SetDrawsContent(true);
8072 TEST_F(LayerTreeHostCommonTest
, MaximumAnimationScaleFactor
) {
8073 FakeImplProxy proxy
;
8074 TestSharedBitmapManager shared_bitmap_manager
;
8075 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
8076 gfx::Transform identity_matrix
;
8077 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_parent
=
8078 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 1);
8079 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> parent
=
8080 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 2);
8081 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> child
=
8082 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 3);
8083 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_child
=
8084 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 4);
8086 AnimationScaleFactorTrackingLayerImpl
* parent_raw
= parent
.get();
8087 AnimationScaleFactorTrackingLayerImpl
* child_raw
= child
.get();
8088 AnimationScaleFactorTrackingLayerImpl
* grand_child_raw
= grand_child
.get();
8090 child
->AddChild(grand_child
.Pass());
8091 parent
->AddChild(child
.Pass());
8092 grand_parent
->AddChild(parent
.Pass());
8094 SetLayerPropertiesForTesting(grand_parent
.get(), identity_matrix
,
8095 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8097 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
8098 gfx::PointF(), gfx::Size(1, 2), true, false,
8100 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
8101 gfx::PointF(), gfx::Size(1, 2), true, false,
8104 SetLayerPropertiesForTesting(grand_child_raw
, identity_matrix
, gfx::Point3F(),
8105 gfx::PointF(), gfx::Size(1, 2), true, false,
8108 ExecuteCalculateDrawProperties(grand_parent
.get());
8110 // No layers have animations.
8112 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8114 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8115 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8117 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8119 TransformOperations translation
;
8120 translation
.AppendTranslate(1.f
, 2.f
, 3.f
);
8122 AddAnimatedTransformToLayer(
8123 parent_raw
, 1.0, TransformOperations(), translation
);
8125 // No layers have scale-affecting animations.
8127 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8129 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8130 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8132 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8134 TransformOperations scale
;
8135 scale
.AppendScale(5.f
, 4.f
, 3.f
);
8137 AddAnimatedTransformToLayer(child_raw
, 1.0, TransformOperations(), scale
);
8138 ExecuteCalculateDrawProperties(grand_parent
.get());
8140 // Only |child| has a scale-affecting animation.
8142 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8144 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8145 EXPECT_EQ(5.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8147 5.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8149 AddAnimatedTransformToLayer(
8150 grand_parent
.get(), 1.0, TransformOperations(), scale
);
8151 ExecuteCalculateDrawProperties(grand_parent
.get());
8153 // |grand_parent| and |child| have scale-affecting animations.
8155 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8157 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8158 // We don't support combining animated scales from two nodes; 0.f means
8159 // that the maximum scale could not be computed.
8160 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8162 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8164 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
8165 ExecuteCalculateDrawProperties(grand_parent
.get());
8167 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
8169 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8171 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8172 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8174 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8176 grand_parent
->layer_animation_controller()->AbortAnimations(
8177 Animation::TRANSFORM
);
8178 parent_raw
->layer_animation_controller()->AbortAnimations(
8179 Animation::TRANSFORM
);
8180 child_raw
->layer_animation_controller()->AbortAnimations(
8181 Animation::TRANSFORM
);
8183 TransformOperations perspective
;
8184 perspective
.AppendPerspective(10.f
);
8186 AddAnimatedTransformToLayer(
8187 child_raw
, 1.0, TransformOperations(), perspective
);
8188 ExecuteCalculateDrawProperties(grand_parent
.get());
8190 // |child| has a scale-affecting animation but computing the maximum of this
8191 // animation is not supported.
8193 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8195 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8196 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8198 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8200 child_raw
->layer_animation_controller()->AbortAnimations(
8201 Animation::TRANSFORM
);
8203 gfx::Transform scale_matrix
;
8204 scale_matrix
.Scale(1.f
, 2.f
);
8205 grand_parent
->SetTransform(scale_matrix
);
8206 parent_raw
->SetTransform(scale_matrix
);
8207 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
8208 ExecuteCalculateDrawProperties(grand_parent
.get());
8210 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
8211 // animation with maximum scale 5.f.
8213 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8215 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8217 child_raw
->draw_properties().maximum_animation_contents_scale
);
8220 grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8222 gfx::Transform perspective_matrix
;
8223 perspective_matrix
.ApplyPerspectiveDepth(2.f
);
8224 child_raw
->SetTransform(perspective_matrix
);
8225 ExecuteCalculateDrawProperties(grand_parent
.get());
8227 // |child| has a transform that's neither a translation nor a scale.
8229 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8231 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8232 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8234 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8236 parent_raw
->SetTransform(perspective_matrix
);
8237 ExecuteCalculateDrawProperties(grand_parent
.get());
8239 // |parent| and |child| have transforms that are neither translations nor
8242 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8244 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8245 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8247 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8249 parent_raw
->SetTransform(identity_matrix
);
8250 child_raw
->SetTransform(identity_matrix
);
8251 grand_parent
->SetTransform(perspective_matrix
);
8253 ExecuteCalculateDrawProperties(grand_parent
.get());
8255 // |grand_parent| has a transform that's neither a translation nor a scale.
8257 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8259 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8260 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8262 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8265 static int membership_id(LayerImpl
* layer
) {
8266 return layer
->draw_properties().last_drawn_render_surface_layer_list_id
;
8269 static void GatherDrawnLayers(LayerImplList
* rsll
,
8270 std::set
<LayerImpl
*>* drawn_layers
) {
8271 for (LayerIterator
<LayerImpl
> it
= LayerIterator
<LayerImpl
>::Begin(rsll
),
8272 end
= LayerIterator
<LayerImpl
>::End(rsll
);
8275 LayerImpl
* layer
= *it
;
8276 if (it
.represents_itself())
8277 drawn_layers
->insert(layer
);
8279 if (!it
.represents_contributing_render_surface())
8282 if (layer
->mask_layer())
8283 drawn_layers
->insert(layer
->mask_layer());
8284 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer())
8285 drawn_layers
->insert(layer
->replica_layer()->mask_layer());
8289 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceLayerListMembership
) {
8290 FakeImplProxy proxy
;
8291 TestSharedBitmapManager shared_bitmap_manager
;
8292 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
8293 gfx::Transform identity_matrix
;
8295 scoped_ptr
<LayerImpl
> grand_parent
=
8296 LayerImpl::Create(host_impl
.active_tree(), 1);
8297 scoped_ptr
<LayerImpl
> parent
= LayerImpl::Create(host_impl
.active_tree(), 3);
8298 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 5);
8299 scoped_ptr
<LayerImpl
> grand_child1
=
8300 LayerImpl::Create(host_impl
.active_tree(), 7);
8301 scoped_ptr
<LayerImpl
> grand_child2
=
8302 LayerImpl::Create(host_impl
.active_tree(), 9);
8304 LayerImpl
* grand_parent_raw
= grand_parent
.get();
8305 LayerImpl
* parent_raw
= parent
.get();
8306 LayerImpl
* child_raw
= child
.get();
8307 LayerImpl
* grand_child1_raw
= grand_child1
.get();
8308 LayerImpl
* grand_child2_raw
= grand_child2
.get();
8310 child
->AddChild(grand_child1
.Pass());
8311 child
->AddChild(grand_child2
.Pass());
8312 parent
->AddChild(child
.Pass());
8313 grand_parent
->AddChild(parent
.Pass());
8315 SetLayerPropertiesForTesting(grand_parent_raw
, identity_matrix
,
8316 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8318 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
8319 gfx::PointF(), gfx::Size(1, 2), true, false,
8322 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
8323 gfx::PointF(), gfx::Size(1, 2), true, false,
8326 SetLayerPropertiesForTesting(grand_child1_raw
, identity_matrix
,
8327 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8328 true, false, false);
8330 SetLayerPropertiesForTesting(grand_child2_raw
, identity_matrix
,
8331 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8332 true, false, false);
8334 // Start with nothing being drawn.
8335 ExecuteCalculateDrawProperties(grand_parent_raw
);
8336 int member_id
= render_surface_layer_list_count();
8338 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8339 EXPECT_NE(member_id
, membership_id(parent_raw
));
8340 EXPECT_NE(member_id
, membership_id(child_raw
));
8341 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8342 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8344 std::set
<LayerImpl
*> expected
;
8345 std::set
<LayerImpl
*> actual
;
8346 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8347 EXPECT_EQ(expected
, actual
);
8349 // If we force render surface, but none of the layers are in the layer list,
8350 // then this layer should not appear in RSLL.
8351 grand_child1_raw
->SetHasRenderSurface(true);
8353 ExecuteCalculateDrawProperties(grand_parent_raw
);
8354 member_id
= render_surface_layer_list_count();
8356 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8357 EXPECT_NE(member_id
, membership_id(parent_raw
));
8358 EXPECT_NE(member_id
, membership_id(child_raw
));
8359 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8360 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8364 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8365 EXPECT_EQ(expected
, actual
);
8367 // However, if we say that this layer also draws content, it will appear in
8369 grand_child1_raw
->SetDrawsContent(true);
8371 ExecuteCalculateDrawProperties(grand_parent_raw
);
8372 member_id
= render_surface_layer_list_count();
8374 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8375 EXPECT_NE(member_id
, membership_id(parent_raw
));
8376 EXPECT_NE(member_id
, membership_id(child_raw
));
8377 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
8378 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8381 expected
.insert(grand_child1_raw
);
8384 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8385 EXPECT_EQ(expected
, actual
);
8387 // Now child is forced to have a render surface, and one if its children draws
8389 grand_child1_raw
->SetDrawsContent(false);
8390 grand_child1_raw
->SetHasRenderSurface(false);
8391 child_raw
->SetHasRenderSurface(true);
8392 grand_child2_raw
->SetDrawsContent(true);
8394 ExecuteCalculateDrawProperties(grand_parent_raw
);
8395 member_id
= render_surface_layer_list_count();
8397 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8398 EXPECT_NE(member_id
, membership_id(parent_raw
));
8399 EXPECT_NE(member_id
, membership_id(child_raw
));
8400 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8401 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8404 expected
.insert(grand_child2_raw
);
8407 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8408 EXPECT_EQ(expected
, actual
);
8410 // Add a mask layer to child.
8411 child_raw
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6).Pass());
8413 ExecuteCalculateDrawProperties(grand_parent_raw
);
8414 member_id
= render_surface_layer_list_count();
8416 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8417 EXPECT_NE(member_id
, membership_id(parent_raw
));
8418 EXPECT_NE(member_id
, membership_id(child_raw
));
8419 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8420 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8421 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8424 expected
.insert(grand_child2_raw
);
8425 expected
.insert(child_raw
->mask_layer());
8428 expected
.insert(grand_child2_raw
);
8429 expected
.insert(child_raw
->mask_layer());
8432 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8433 EXPECT_EQ(expected
, actual
);
8435 // Add replica mask layer.
8436 scoped_ptr
<LayerImpl
> replica_layer
=
8437 LayerImpl::Create(host_impl
.active_tree(), 20);
8438 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 21));
8439 child_raw
->SetReplicaLayer(replica_layer
.Pass());
8441 ExecuteCalculateDrawProperties(grand_parent_raw
);
8442 member_id
= render_surface_layer_list_count();
8444 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8445 EXPECT_NE(member_id
, membership_id(parent_raw
));
8446 EXPECT_NE(member_id
, membership_id(child_raw
));
8447 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8448 EXPECT_EQ(member_id
, membership_id(child_raw
->replica_layer()->mask_layer()));
8449 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8450 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8453 expected
.insert(grand_child2_raw
);
8454 expected
.insert(child_raw
->mask_layer());
8455 expected
.insert(child_raw
->replica_layer()->mask_layer());
8458 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8459 EXPECT_EQ(expected
, actual
);
8461 child_raw
->TakeReplicaLayer();
8463 // With nothing drawing, we should have no layers.
8464 grand_child2_raw
->SetDrawsContent(false);
8466 ExecuteCalculateDrawProperties(grand_parent_raw
);
8467 member_id
= render_surface_layer_list_count();
8469 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8470 EXPECT_NE(member_id
, membership_id(parent_raw
));
8471 EXPECT_NE(member_id
, membership_id(child_raw
));
8472 EXPECT_NE(member_id
, membership_id(child_raw
->mask_layer()));
8473 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8474 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8478 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8479 EXPECT_EQ(expected
, actual
);
8481 // Child itself draws means that we should have the child and the mask in the
8483 child_raw
->SetDrawsContent(true);
8485 ExecuteCalculateDrawProperties(grand_parent_raw
);
8486 member_id
= render_surface_layer_list_count();
8488 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8489 EXPECT_NE(member_id
, membership_id(parent_raw
));
8490 EXPECT_EQ(member_id
, membership_id(child_raw
));
8491 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8492 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8493 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8496 expected
.insert(child_raw
);
8497 expected
.insert(child_raw
->mask_layer());
8499 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8500 EXPECT_EQ(expected
, actual
);
8502 child_raw
->TakeMaskLayer();
8504 // Now everyone's a member!
8505 grand_parent_raw
->SetDrawsContent(true);
8506 parent_raw
->SetDrawsContent(true);
8507 child_raw
->SetDrawsContent(true);
8508 grand_child1_raw
->SetDrawsContent(true);
8509 grand_child2_raw
->SetDrawsContent(true);
8511 ExecuteCalculateDrawProperties(grand_parent_raw
);
8512 member_id
= render_surface_layer_list_count();
8514 EXPECT_EQ(member_id
, membership_id(grand_parent_raw
));
8515 EXPECT_EQ(member_id
, membership_id(parent_raw
));
8516 EXPECT_EQ(member_id
, membership_id(child_raw
));
8517 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
8518 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8521 expected
.insert(grand_parent_raw
);
8522 expected
.insert(parent_raw
);
8523 expected
.insert(child_raw
);
8524 expected
.insert(grand_child1_raw
);
8525 expected
.insert(grand_child2_raw
);
8528 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8529 EXPECT_EQ(expected
, actual
);
8532 TEST_F(LayerTreeHostCommonTest
, DrawPropertyScales
) {
8533 FakeImplProxy proxy
;
8534 TestSharedBitmapManager shared_bitmap_manager
;
8535 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
8537 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
8538 LayerImpl
* root_layer
= root
.get();
8539 scoped_ptr
<LayerImpl
> child1
= LayerImpl::Create(host_impl
.active_tree(), 2);
8540 LayerImpl
* child1_layer
= child1
.get();
8541 scoped_ptr
<LayerImpl
> child2
= LayerImpl::Create(host_impl
.active_tree(), 3);
8542 LayerImpl
* child2_layer
= child2
.get();
8544 root
->AddChild(child1
.Pass());
8545 root
->AddChild(child2
.Pass());
8546 root
->SetHasRenderSurface(true);
8548 gfx::Transform identity_matrix
, scale_transform_child1
,
8549 scale_transform_child2
;
8550 scale_transform_child1
.Scale(2, 3);
8551 scale_transform_child2
.Scale(4, 5);
8553 SetLayerPropertiesForTesting(root_layer
, identity_matrix
, gfx::Point3F(),
8554 gfx::PointF(), gfx::Size(1, 1), true, false,
8556 SetLayerPropertiesForTesting(child1_layer
, scale_transform_child1
,
8557 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8560 child1_layer
->SetMaskLayer(
8561 LayerImpl::Create(host_impl
.active_tree(), 4).Pass());
8563 scoped_ptr
<LayerImpl
> replica_layer
=
8564 LayerImpl::Create(host_impl
.active_tree(), 5);
8565 replica_layer
->SetHasRenderSurface(true);
8566 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6));
8567 child1_layer
->SetReplicaLayer(replica_layer
.Pass());
8568 child1_layer
->SetHasRenderSurface(true);
8570 ExecuteCalculateDrawProperties(root_layer
);
8572 TransformOperations scale
;
8573 scale
.AppendScale(5.f
, 8.f
, 3.f
);
8575 AddAnimatedTransformToLayer(child2_layer
, 1.0, TransformOperations(), scale
);
8576 SetLayerPropertiesForTesting(child2_layer
, scale_transform_child2
,
8577 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8580 ExecuteCalculateDrawProperties(root_layer
);
8582 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().ideal_contents_scale
);
8583 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8585 3.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8586 EXPECT_FLOAT_EQ(3.f
,
8587 child1_layer
->replica_layer()
8590 .ideal_contents_scale
);
8591 EXPECT_FLOAT_EQ(5.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8594 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8596 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8597 EXPECT_FLOAT_EQ(0.f
,
8598 child1_layer
->mask_layer()
8600 .maximum_animation_contents_scale
);
8601 EXPECT_FLOAT_EQ(0.f
,
8602 child1_layer
->replica_layer()
8605 .maximum_animation_contents_scale
);
8607 8.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8609 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8610 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().page_scale_factor
);
8612 1.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8613 EXPECT_FLOAT_EQ(1.f
,
8614 child1_layer
->replica_layer()
8617 .page_scale_factor
);
8618 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().page_scale_factor
);
8620 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().device_scale_factor
);
8621 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().device_scale_factor
);
8623 1.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8624 EXPECT_FLOAT_EQ(1.f
,
8625 child1_layer
->replica_layer()
8628 .device_scale_factor
);
8629 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().device_scale_factor
);
8631 // Changing page-scale would affect ideal_contents_scale and
8632 // maximum_animation_contents_scale.
8634 float page_scale_factor
= 3.f
;
8635 float device_scale_factor
= 1.0f
;
8636 std::vector
<LayerImpl
*> render_surface_layer_list
;
8637 gfx::Size device_viewport_size
=
8638 gfx::Size(root_layer
->bounds().width() * device_scale_factor
,
8639 root_layer
->bounds().height() * device_scale_factor
);
8640 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
8641 root_layer
, device_viewport_size
, &render_surface_layer_list
);
8643 inputs
.page_scale_factor
= page_scale_factor
;
8644 inputs
.can_adjust_raster_scales
= true;
8645 inputs
.page_scale_application_layer
= root_layer
;
8646 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8648 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().ideal_contents_scale
);
8649 EXPECT_FLOAT_EQ(9.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8651 9.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8652 EXPECT_FLOAT_EQ(9.f
,
8653 child1_layer
->replica_layer()
8656 .ideal_contents_scale
);
8657 EXPECT_FLOAT_EQ(15.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8660 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8662 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8663 EXPECT_FLOAT_EQ(0.f
,
8664 child1_layer
->mask_layer()
8666 .maximum_animation_contents_scale
);
8667 EXPECT_FLOAT_EQ(0.f
,
8668 child1_layer
->replica_layer()
8671 .maximum_animation_contents_scale
);
8673 24.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8675 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8676 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().page_scale_factor
);
8678 3.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8679 EXPECT_FLOAT_EQ(3.f
,
8680 child1_layer
->replica_layer()
8683 .page_scale_factor
);
8684 EXPECT_FLOAT_EQ(3.f
, child2_layer
->draw_properties().page_scale_factor
);
8686 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().device_scale_factor
);
8687 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().device_scale_factor
);
8689 1.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8690 EXPECT_FLOAT_EQ(1.f
,
8691 child1_layer
->replica_layer()
8694 .device_scale_factor
);
8695 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().device_scale_factor
);
8697 // Changing device-scale would affect ideal_contents_scale and
8698 // maximum_animation_contents_scale.
8700 device_scale_factor
= 4.0f
;
8701 inputs
.device_scale_factor
= device_scale_factor
;
8702 inputs
.can_adjust_raster_scales
= true;
8703 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8705 EXPECT_FLOAT_EQ(4.f
, root_layer
->draw_properties().ideal_contents_scale
);
8706 EXPECT_FLOAT_EQ(36.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8708 36.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8709 EXPECT_FLOAT_EQ(36.f
,
8710 child1_layer
->replica_layer()
8713 .ideal_contents_scale
);
8714 EXPECT_FLOAT_EQ(60.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8717 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8719 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8720 EXPECT_FLOAT_EQ(0.f
,
8721 child1_layer
->mask_layer()
8723 .maximum_animation_contents_scale
);
8724 EXPECT_FLOAT_EQ(0.f
,
8725 child1_layer
->replica_layer()
8728 .maximum_animation_contents_scale
);
8730 96.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8732 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8733 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().page_scale_factor
);
8735 3.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8736 EXPECT_FLOAT_EQ(3.f
,
8737 child1_layer
->replica_layer()
8740 .page_scale_factor
);
8741 EXPECT_FLOAT_EQ(3.f
, child2_layer
->draw_properties().page_scale_factor
);
8743 EXPECT_FLOAT_EQ(4.f
, root_layer
->draw_properties().device_scale_factor
);
8744 EXPECT_FLOAT_EQ(4.f
, child1_layer
->draw_properties().device_scale_factor
);
8746 4.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8747 EXPECT_FLOAT_EQ(4.f
,
8748 child1_layer
->replica_layer()
8751 .device_scale_factor
);
8752 EXPECT_FLOAT_EQ(4.f
, child2_layer
->draw_properties().device_scale_factor
);
8755 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInChildRenderSurface
) {
8756 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8757 SetLayerPropertiesForTesting(root
.get(),
8761 gfx::Size(768 / 2, 3000),
8764 root
->SetIsDrawable(true);
8766 scoped_refptr
<Layer
> clip
= Layer::Create(layer_settings());
8767 SetLayerPropertiesForTesting(clip
.get(),
8771 gfx::Size(768 / 2, 10000),
8774 clip
->SetMasksToBounds(true);
8776 scoped_refptr
<Layer
> content
= Layer::Create(layer_settings());
8777 SetLayerPropertiesForTesting(content
.get(),
8781 gfx::Size(768 / 2, 10000),
8784 content
->SetIsDrawable(true);
8785 content
->SetForceRenderSurface(true);
8787 root
->AddChild(clip
);
8788 clip
->AddChild(content
);
8790 FakeLayerTreeHostClient
client(FakeLayerTreeHostClient::DIRECT_3D
);
8791 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&client
);
8792 host
->SetRootLayer(root
);
8794 gfx::Size
device_viewport_size(768, 582);
8795 RenderSurfaceLayerList render_surface_layer_list
;
8796 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
8797 host
->root_layer(), device_viewport_size
, &render_surface_layer_list
);
8798 inputs
.device_scale_factor
= 2.f
;
8799 inputs
.page_scale_factor
= 1.f
;
8800 inputs
.page_scale_application_layer
= NULL
;
8801 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8803 // Layers in the root render surface have their visible content rect clipped
8805 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root
->visible_content_rect());
8807 // Layers drawing to a child render surface should still have their visible
8808 // content rect clipped by the viewport.
8809 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content
->visible_content_rect());
8812 TEST_F(LayerTreeHostCommonTest
, BoundsDeltaAffectVisibleContentRect
) {
8813 FakeImplProxy proxy
;
8814 TestSharedBitmapManager shared_bitmap_manager
;
8815 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
8817 // Set two layers: the root layer clips it's child,
8818 // the child draws its content.
8820 gfx::Size root_size
= gfx::Size(300, 500);
8822 // Sublayer should be bigger than the root enlarged by bounds_delta.
8823 gfx::Size sublayer_size
= gfx::Size(300, 1000);
8825 // Device viewport accomidated the root and the top controls.
8826 gfx::Size device_viewport_size
= gfx::Size(300, 600);
8827 gfx::Transform identity_matrix
;
8829 host_impl
.active_tree()->SetRootLayer(
8830 LayerImpl::Create(host_impl
.active_tree(), 1));
8832 LayerImpl
* root
= host_impl
.active_tree()->root_layer();
8833 SetLayerPropertiesForTesting(root
,
8842 root
->SetContentBounds(root_size
);
8843 root
->SetMasksToBounds(true);
8845 root
->AddChild(LayerImpl::Create(host_impl
.active_tree(), 2));
8847 LayerImpl
* sublayer
= root
->child_at(0);
8848 SetLayerPropertiesForTesting(sublayer
,
8857 sublayer
->SetContentBounds(sublayer_size
);
8858 sublayer
->SetDrawsContent(true);
8860 LayerImplList layer_impl_list
;
8861 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
8862 root
, device_viewport_size
, &layer_impl_list
);
8864 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8866 EXPECT_EQ(gfx::Rect(root_size
), sublayer
->visible_content_rect());
8868 root
->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
8870 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8872 gfx::Rect
affected_by_delta(0, 0, root_size
.width(),
8873 root_size
.height() + 50);
8874 EXPECT_EQ(affected_by_delta
, sublayer
->visible_content_rect());
8877 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectForAnimatedLayer
) {
8878 const gfx::Transform identity_matrix
;
8879 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8880 scoped_refptr
<LayerWithForcedDrawsContent
> animated
=
8881 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8883 root
->AddChild(animated
);
8885 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
8886 host
->SetRootLayer(root
);
8888 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
8889 gfx::PointF(), gfx::Size(100, 100), true, false);
8890 SetLayerPropertiesForTesting(animated
.get(), identity_matrix
, gfx::Point3F(),
8891 gfx::PointF(), gfx::Size(20, 20), true, false);
8893 root
->SetMasksToBounds(true);
8894 root
->SetForceRenderSurface(true);
8895 animated
->SetOpacity(0.f
);
8897 AddOpacityTransitionToController(animated
->layer_animation_controller(), 10.0,
8900 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8902 EXPECT_FALSE(animated
->visible_rect_from_property_trees().IsEmpty());
8905 TEST_F(LayerTreeHostCommonTest
,
8906 VisibleContentRectForAnimatedLayerWithSingularTransform
) {
8907 const gfx::Transform identity_matrix
;
8908 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8909 scoped_refptr
<Layer
> clip
= Layer::Create(layer_settings());
8910 scoped_refptr
<LayerWithForcedDrawsContent
> animated
=
8911 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8912 scoped_refptr
<LayerWithForcedDrawsContent
> surface
=
8913 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8914 scoped_refptr
<LayerWithForcedDrawsContent
> descendant_of_animation
=
8915 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
8917 root
->AddChild(clip
);
8918 clip
->AddChild(animated
);
8919 animated
->AddChild(surface
);
8920 surface
->AddChild(descendant_of_animation
);
8922 clip
->SetMasksToBounds(true);
8923 surface
->SetForceRenderSurface(true);
8925 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
8926 host
->SetRootLayer(root
);
8928 gfx::Transform uninvertible_matrix
;
8929 uninvertible_matrix
.Scale3d(6.f
, 6.f
, 0.f
);
8931 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
8932 gfx::PointF(), gfx::Size(100, 100), true, false);
8933 SetLayerPropertiesForTesting(clip
.get(), identity_matrix
, gfx::Point3F(),
8934 gfx::PointF(), gfx::Size(10, 10), true, false);
8935 SetLayerPropertiesForTesting(animated
.get(), uninvertible_matrix
,
8936 gfx::Point3F(), gfx::PointF(),
8937 gfx::Size(120, 120), true, false);
8938 SetLayerPropertiesForTesting(surface
.get(), identity_matrix
, gfx::Point3F(),
8939 gfx::PointF(), gfx::Size(100, 100), true, false);
8940 SetLayerPropertiesForTesting(descendant_of_animation
.get(), identity_matrix
,
8941 gfx::Point3F(), gfx::PointF(),
8942 gfx::Size(200, 200), true, false);
8944 TransformOperations start_transform_operations
;
8945 start_transform_operations
.AppendMatrix(uninvertible_matrix
);
8946 TransformOperations end_transform_operations
;
8948 AddAnimatedTransformToLayer(animated
.get(), 10.0, start_transform_operations
,
8949 end_transform_operations
);
8951 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8953 // The animated layer has a singular transform and maps to a non-empty rect in
8954 // clipped target space, so is treated as fully visible.
8955 EXPECT_EQ(gfx::Rect(120, 120), animated
->visible_rect_from_property_trees());
8957 // The singular transform on |animated| is flattened when inherited by
8958 // |surface|, and this happens to make it invertible.
8959 EXPECT_EQ(gfx::Rect(2, 2), surface
->visible_rect_from_property_trees());
8960 EXPECT_EQ(gfx::Rect(2, 2),
8961 descendant_of_animation
->visible_rect_from_property_trees());
8963 gfx::Transform zero_matrix
;
8964 zero_matrix
.Scale3d(0.f
, 0.f
, 0.f
);
8965 SetLayerPropertiesForTesting(animated
.get(), zero_matrix
, gfx::Point3F(),
8966 gfx::PointF(), gfx::Size(120, 120), true, false);
8968 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
8970 // The animated layer maps to the empty rect in clipped target space, so is
8971 // treated as having an empty visible rect.
8972 EXPECT_EQ(gfx::Rect(), animated
->visible_rect_from_property_trees());
8974 // This time, flattening does not make |animated|'s transform invertible. This
8975 // means the clip cannot be projected into |surface|'s space, so we treat
8976 // |surface| and layers that draw into it as fully visible.
8977 EXPECT_EQ(gfx::Rect(100, 100), surface
->visible_rect_from_property_trees());
8978 EXPECT_EQ(gfx::Rect(200, 200),
8979 descendant_of_animation
->visible_rect_from_property_trees());
8982 // Verify that having an animated filter (but no current filter, as these
8983 // are mutually exclusive) correctly creates a render surface.
8984 TEST_F(LayerTreeHostCommonTest
, AnimatedFilterCreatesRenderSurface
) {
8985 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
8986 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
8987 scoped_refptr
<Layer
> grandchild
= Layer::Create(layer_settings());
8988 root
->AddChild(child
);
8989 child
->AddChild(grandchild
);
8991 gfx::Transform identity_transform
;
8992 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
8993 gfx::PointF(), gfx::Size(50, 50), true, false);
8994 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
8995 gfx::PointF(), gfx::Size(50, 50), true, false);
8996 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
8997 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
8999 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9000 host
->SetRootLayer(root
);
9002 AddAnimatedFilterToLayer(child
.get(), 10.0, 0.1f
, 0.2f
);
9004 ExecuteCalculateDrawProperties(root
.get());
9006 EXPECT_TRUE(root
->render_surface());
9007 EXPECT_TRUE(child
->render_surface());
9008 EXPECT_FALSE(grandchild
->render_surface());
9010 EXPECT_TRUE(root
->filters().IsEmpty());
9011 EXPECT_TRUE(child
->filters().IsEmpty());
9012 EXPECT_TRUE(grandchild
->filters().IsEmpty());
9014 EXPECT_FALSE(root
->FilterIsAnimating());
9015 EXPECT_TRUE(child
->FilterIsAnimating());
9016 EXPECT_FALSE(grandchild
->FilterIsAnimating());
9019 // Ensures that the property tree code accounts for offsets between fixed
9020 // position layers and their respective containers.
9021 TEST_F(LayerTreeHostCommonTest
, PropertyTreesAccountForFixedParentOffset
) {
9022 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9023 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
9024 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
9025 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9027 root
->AddChild(child
);
9028 child
->AddChild(grandchild
);
9030 gfx::Transform identity_transform
;
9031 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
9032 gfx::PointF(), gfx::Size(50, 50), true, false);
9033 SetLayerPropertiesForTesting(child
.get(), identity_transform
, gfx::Point3F(),
9034 gfx::PointF(1000, 1000), gfx::Size(50, 50), true,
9036 SetLayerPropertiesForTesting(grandchild
.get(), identity_transform
,
9037 gfx::Point3F(), gfx::PointF(-1000, -1000),
9038 gfx::Size(50, 50), true, false);
9040 root
->SetMasksToBounds(true);
9041 root
->SetIsContainerForFixedPositionLayers(true);
9042 LayerPositionConstraint constraint
;
9043 constraint
.set_is_fixed_position(true);
9044 grandchild
->SetPositionConstraint(constraint
);
9046 root
->SetIsContainerForFixedPositionLayers(true);
9048 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9049 host
->SetRootLayer(root
);
9051 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9053 EXPECT_EQ(gfx::Rect(0, 0, 50, 50),
9054 grandchild
->visible_rect_from_property_trees());
9057 TEST_F(LayerTreeHostCommonTest
, CombineClipsUsingContentTarget
) {
9058 // In the following layer tree, the layer |box|'s render target is |surface|.
9059 // |surface| also creates a transform node. We want to combine clips for |box|
9060 // in the space of its target (i.e., |surface|), not its target's target. This
9061 // test ensures that happens.
9063 gfx::Transform rotate
;
9065 gfx::Transform identity
;
9067 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9068 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
9069 gfx::PointF(), gfx::Size(2500, 1500), true,
9072 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
9073 SetLayerPropertiesForTesting(frame_clip
.get(), identity
, gfx::Point3F(),
9074 gfx::PointF(), gfx::Size(2500, 1500), true,
9076 frame_clip
->SetMasksToBounds(true);
9078 scoped_refptr
<Layer
> rotated
= Layer::Create(layer_settings());
9079 SetLayerPropertiesForTesting(rotated
.get(), rotate
,
9080 gfx::Point3F(1250, 250, 0), gfx::PointF(),
9081 gfx::Size(2500, 500), true, false);
9083 scoped_refptr
<Layer
> surface
= Layer::Create(layer_settings());
9084 SetLayerPropertiesForTesting(surface
.get(), rotate
, gfx::Point3F(),
9085 gfx::PointF(), gfx::Size(2500, 500), true,
9087 surface
->SetOpacity(0.5);
9089 scoped_refptr
<LayerWithForcedDrawsContent
> container
=
9090 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9091 SetLayerPropertiesForTesting(container
.get(), identity
, gfx::Point3F(),
9092 gfx::PointF(), gfx::Size(300, 300), true, false);
9094 scoped_refptr
<LayerWithForcedDrawsContent
> box
=
9095 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9096 SetLayerPropertiesForTesting(box
.get(), identity
, gfx::Point3F(),
9097 gfx::PointF(), gfx::Size(100, 100), true, false);
9099 root
->AddChild(frame_clip
);
9100 frame_clip
->AddChild(rotated
);
9101 rotated
->AddChild(surface
);
9102 surface
->AddChild(container
);
9103 surface
->AddChild(box
);
9105 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9106 host
->SetRootLayer(root
);
9108 ExecuteCalculateDrawProperties(root
.get());
9111 TEST_F(LayerTreeHostCommonTest
, OnlyApplyFixedPositioningOnce
) {
9112 gfx::Transform identity
;
9113 gfx::Transform translate_z
;
9114 translate_z
.Translate3d(0, 0, 10);
9116 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9117 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
9118 gfx::PointF(), gfx::Size(800, 800), true, false);
9119 root
->SetIsContainerForFixedPositionLayers(true);
9121 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
9122 SetLayerPropertiesForTesting(frame_clip
.get(), translate_z
, gfx::Point3F(),
9123 gfx::PointF(500, 100), gfx::Size(100, 100), true,
9125 frame_clip
->SetMasksToBounds(true);
9127 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
9128 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9129 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
9130 gfx::PointF(), gfx::Size(1000, 1000), true,
9133 LayerPositionConstraint constraint
;
9134 constraint
.set_is_fixed_position(true);
9135 fixed
->SetPositionConstraint(constraint
);
9137 root
->AddChild(frame_clip
);
9138 frame_clip
->AddChild(fixed
);
9140 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9141 host
->SetRootLayer(root
);
9143 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9145 gfx::Rect
expected(0, 0, 100, 100);
9146 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
9149 TEST_F(LayerTreeHostCommonTest
,
9150 PropertyTreesAccountForScrollCompensationAdjustment
) {
9151 gfx::Transform identity
;
9152 gfx::Transform translate_z
;
9153 translate_z
.Translate3d(0, 0, 10);
9155 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9156 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
9157 gfx::PointF(), gfx::Size(800, 800), true, false);
9158 root
->SetIsContainerForFixedPositionLayers(true);
9160 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
9161 SetLayerPropertiesForTesting(frame_clip
.get(), translate_z
, gfx::Point3F(),
9162 gfx::PointF(500, 100), gfx::Size(100, 100), true,
9164 frame_clip
->SetMasksToBounds(true);
9166 scoped_refptr
<LayerWithForcedDrawsContent
> scroller
=
9167 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9168 SetLayerPropertiesForTesting(scroller
.get(), identity
, gfx::Point3F(),
9169 gfx::PointF(), gfx::Size(1000, 1000), true,
9172 scroller
->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f
, 0.7f
));
9173 scroller
->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7));
9174 scroller
->SetScrollClipLayerId(frame_clip
->id());
9176 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
9177 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9178 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
9179 gfx::PointF(), gfx::Size(50, 50), true, false);
9181 LayerPositionConstraint constraint
;
9182 constraint
.set_is_fixed_position(true);
9183 fixed
->SetPositionConstraint(constraint
);
9185 scoped_refptr
<LayerWithForcedDrawsContent
> fixed_child
=
9186 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9187 SetLayerPropertiesForTesting(fixed_child
.get(), identity
, gfx::Point3F(),
9188 gfx::PointF(), gfx::Size(10, 10), true, false);
9190 fixed_child
->SetPositionConstraint(constraint
);
9192 root
->AddChild(frame_clip
);
9193 frame_clip
->AddChild(scroller
);
9194 scroller
->AddChild(fixed
);
9195 fixed
->AddChild(fixed_child
);
9197 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9198 host
->SetRootLayer(root
);
9200 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9202 gfx::Rect
expected(0, 0, 50, 50);
9203 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
9205 expected
= gfx::Rect(0, 0, 10, 10);
9206 EXPECT_EQ(expected
, fixed_child
->visible_rect_from_property_trees());
9209 TEST_F(LayerTreeHostCommonTest
, FixedClipsShouldBeAssociatedWithTheRightNode
) {
9210 gfx::Transform identity
;
9212 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9213 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
9214 gfx::PointF(), gfx::Size(800, 800), true, false);
9215 root
->SetIsContainerForFixedPositionLayers(true);
9217 scoped_refptr
<Layer
> frame_clip
= Layer::Create(layer_settings());
9218 SetLayerPropertiesForTesting(frame_clip
.get(), identity
, gfx::Point3F(),
9219 gfx::PointF(500, 100), gfx::Size(100, 100), true,
9221 frame_clip
->SetMasksToBounds(true);
9223 scoped_refptr
<LayerWithForcedDrawsContent
> scroller
=
9224 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9225 SetLayerPropertiesForTesting(scroller
.get(), identity
, gfx::Point3F(),
9226 gfx::PointF(), gfx::Size(1000, 1000), true,
9229 scroller
->SetScrollOffset(gfx::ScrollOffset(100, 100));
9230 scroller
->SetScrollClipLayerId(frame_clip
->id());
9232 scoped_refptr
<LayerWithForcedDrawsContent
> fixed
=
9233 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9234 SetLayerPropertiesForTesting(fixed
.get(), identity
, gfx::Point3F(),
9235 gfx::PointF(100, 100), gfx::Size(50, 50), true,
9238 LayerPositionConstraint constraint
;
9239 constraint
.set_is_fixed_position(true);
9240 fixed
->SetPositionConstraint(constraint
);
9241 fixed
->SetForceRenderSurface(true);
9242 fixed
->SetMasksToBounds(true);
9244 root
->AddChild(frame_clip
);
9245 frame_clip
->AddChild(scroller
);
9246 scroller
->AddChild(fixed
);
9248 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9249 host
->SetRootLayer(root
);
9251 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9253 gfx::Rect
expected(0, 0, 50, 50);
9254 EXPECT_EQ(expected
, fixed
->visible_rect_from_property_trees());
9257 TEST_F(LayerTreeHostCommonTest
, ChangingAxisAlignmentTriggersRebuild
) {
9258 gfx::Transform identity
;
9259 gfx::Transform translate
;
9260 gfx::Transform rotate
;
9262 translate
.Translate(10, 10);
9265 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9266 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
9267 gfx::PointF(), gfx::Size(800, 800), true, false);
9268 root
->SetIsContainerForFixedPositionLayers(true);
9270 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9271 host
->SetRootLayer(root
);
9273 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9274 EXPECT_FALSE(host
->property_trees()->needs_rebuild
);
9276 root
->SetTransform(translate
);
9277 EXPECT_FALSE(host
->property_trees()->needs_rebuild
);
9279 root
->SetTransform(rotate
);
9280 EXPECT_TRUE(host
->property_trees()->needs_rebuild
);
9283 TEST_F(LayerTreeHostCommonTest
, ChangeTransformOrigin
) {
9284 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9285 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
9286 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9287 root
->AddChild(child
);
9289 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9290 host
->SetRootLayer(root
);
9292 gfx::Transform identity_matrix
;
9293 gfx::Transform scale_matrix
;
9294 scale_matrix
.Scale(2.f
, 2.f
);
9295 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
9296 gfx::PointF(), gfx::Size(100, 100), true, false);
9297 SetLayerPropertiesForTesting(child
.get(), scale_matrix
, gfx::Point3F(),
9298 gfx::PointF(), gfx::Size(10, 10), true, false);
9300 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9301 EXPECT_EQ(gfx::Rect(10, 10), child
->visible_rect_from_property_trees());
9303 child
->SetTransformOrigin(gfx::Point3F(10.f
, 10.f
, 10.f
));
9305 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9306 EXPECT_EQ(gfx::Rect(5, 5, 5, 5), child
->visible_rect_from_property_trees());
9309 TEST_F(LayerTreeHostCommonTest
, UpdateScrollChildPosition
) {
9310 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9311 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
9312 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9313 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
9314 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9316 root
->AddChild(scroll_child
);
9317 root
->AddChild(scroll_parent
);
9318 scroll_child
->SetScrollParent(scroll_parent
.get());
9319 scroll_parent
->SetScrollClipLayerId(root
->id());
9321 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9322 host
->SetRootLayer(root
);
9324 gfx::Transform identity_transform
;
9325 gfx::Transform scale
;
9326 scale
.Scale(2.f
, 2.f
);
9327 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
9328 gfx::PointF(), gfx::Size(50, 50), true, false);
9329 SetLayerPropertiesForTesting(scroll_child
.get(), scale
, gfx::Point3F(),
9330 gfx::PointF(), gfx::Size(40, 40), true, false);
9331 SetLayerPropertiesForTesting(scroll_parent
.get(), identity_transform
,
9332 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
9335 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9336 EXPECT_EQ(gfx::Rect(25, 25),
9337 scroll_child
->visible_rect_from_property_trees());
9339 scroll_child
->SetPosition(gfx::PointF(0, -10.f
));
9340 scroll_parent
->SetScrollOffset(gfx::ScrollOffset(0.f
, 10.f
));
9341 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9342 EXPECT_EQ(gfx::Rect(0, 5, 25, 25),
9343 scroll_child
->visible_rect_from_property_trees());
9346 static void CopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {
9349 TEST_F(LayerTreeHostCommonTest
, SkippingSubtreeMain
) {
9350 gfx::Transform identity
;
9351 FakeContentLayerClient client
;
9352 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9353 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
9354 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9355 scoped_refptr
<LayerWithForcedDrawsContent
> grandchild
=
9356 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9357 scoped_refptr
<FakeContentLayer
> greatgrandchild(
9358 FakeContentLayer::Create(layer_settings(), &client
));
9359 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
9360 gfx::PointF(), gfx::Size(100, 100), true, false);
9361 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
9362 gfx::PointF(), gfx::Size(10, 10), true, false);
9363 SetLayerPropertiesForTesting(grandchild
.get(), identity
, gfx::Point3F(),
9364 gfx::PointF(), gfx::Size(10, 10), true, false);
9365 SetLayerPropertiesForTesting(greatgrandchild
.get(), identity
, gfx::Point3F(),
9366 gfx::PointF(), gfx::Size(10, 10), true, false);
9368 root
->AddChild(child
);
9369 child
->AddChild(grandchild
);
9370 grandchild
->AddChild(greatgrandchild
);
9372 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9373 host
->SetRootLayer(root
);
9375 // Check the non-skipped case.
9376 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9377 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
9379 // Now we will reset the visible rect from property trees for the grandchild,
9380 // and we will configure |child| in several ways that should force the subtree
9381 // to be skipped. The visible content rect for |grandchild| should, therefore,
9383 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
9384 gfx::Transform singular
;
9385 singular
.matrix().set(0, 0, 0);
9387 child
->SetTransform(singular
);
9388 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9389 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
9390 child
->SetTransform(identity
);
9392 child
->SetHideLayerAndSubtree(true);
9393 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9394 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
9395 child
->SetHideLayerAndSubtree(false);
9397 child
->SetOpacity(0.f
);
9398 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9399 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
9401 // Now, even though child has zero opacity, we will configure |grandchild| and
9402 // |greatgrandchild| in several ways that should force the subtree to be
9403 // processed anyhow.
9404 grandchild
->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
9405 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9406 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
9407 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
9408 grandchild
->SetTouchEventHandlerRegion(Region());
9409 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9410 EXPECT_EQ(gfx::Rect(0, 0), grandchild
->visible_rect_from_property_trees());
9411 grandchild
->set_visible_rect_from_property_trees(gfx::Rect());
9413 greatgrandchild
->RequestCopyOfOutput(
9414 CopyOutputRequest::CreateBitmapRequest(base::Bind(&CopyOutputCallback
)));
9415 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9416 EXPECT_EQ(gfx::Rect(10, 10), grandchild
->visible_rect_from_property_trees());
9419 TEST_F(LayerTreeHostCommonTest
, SkippingSubtreeImpl
) {
9420 FakeImplProxy proxy
;
9421 TestSharedBitmapManager shared_bitmap_manager
;
9422 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
, nullptr);
9424 gfx::Transform identity
;
9425 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
9426 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 2);
9427 scoped_ptr
<LayerImpl
> grandchild
=
9428 LayerImpl::Create(host_impl
.active_tree(), 3);
9430 scoped_ptr
<FakeContentLayerImpl
> greatgrandchild(
9431 FakeContentLayerImpl::Create(host_impl
.active_tree(), 4));
9433 child
->SetDrawsContent(true);
9434 grandchild
->SetDrawsContent(true);
9435 greatgrandchild
->SetDrawsContent(true);
9437 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
9438 gfx::PointF(), gfx::Size(100, 100), true, false,
9440 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
9441 gfx::PointF(), gfx::Size(10, 10), true, false,
9443 SetLayerPropertiesForTesting(grandchild
.get(), identity
, gfx::Point3F(),
9444 gfx::PointF(), gfx::Size(10, 10), true, false,
9446 SetLayerPropertiesForTesting(greatgrandchild
.get(), identity
, gfx::Point3F(),
9447 gfx::PointF(), gfx::Size(10, 10), true, false,
9450 LayerImpl
* child_ptr
= child
.get();
9451 LayerImpl
* grandchild_ptr
= grandchild
.get();
9452 LayerImpl
* greatgrandchild_ptr
= greatgrandchild
.get();
9454 grandchild
->AddChild(greatgrandchild
.Pass());
9455 child
->AddChild(grandchild
.Pass());
9456 root
->AddChild(child
.Pass());
9458 // Check the non-skipped case.
9459 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9460 EXPECT_EQ(gfx::Rect(10, 10),
9461 grandchild_ptr
->visible_rect_from_property_trees());
9463 // Now we will reset the visible rect from property trees for the grandchild,
9464 // and we will configure |child| in several ways that should force the subtree
9465 // to be skipped. The visible content rect for |grandchild| should, therefore,
9467 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
9468 gfx::Transform singular
;
9469 singular
.matrix().set(0, 0, 0);
9471 child_ptr
->SetTransform(singular
);
9472 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9473 EXPECT_EQ(gfx::Rect(0, 0),
9474 grandchild_ptr
->visible_rect_from_property_trees());
9475 child_ptr
->SetTransform(identity
);
9477 child_ptr
->SetHideLayerAndSubtree(true);
9478 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9479 EXPECT_EQ(gfx::Rect(0, 0),
9480 grandchild_ptr
->visible_rect_from_property_trees());
9481 child_ptr
->SetHideLayerAndSubtree(false);
9483 child_ptr
->SetOpacity(0.f
);
9484 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9485 EXPECT_EQ(gfx::Rect(0, 0),
9486 grandchild_ptr
->visible_rect_from_property_trees());
9488 // Now, even though child has zero opacity, we will configure |grandchild| and
9489 // |greatgrandchild| in several ways that should force the subtree to be
9490 // processed anyhow.
9491 grandchild_ptr
->SetTouchEventHandlerRegion(Region(gfx::Rect(0, 0, 10, 10)));
9492 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9493 EXPECT_EQ(gfx::Rect(10, 10),
9494 grandchild_ptr
->visible_rect_from_property_trees());
9495 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
9496 grandchild_ptr
->SetTouchEventHandlerRegion(Region());
9497 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9498 EXPECT_EQ(gfx::Rect(0, 0),
9499 grandchild_ptr
->visible_rect_from_property_trees());
9500 grandchild_ptr
->set_visible_rect_from_property_trees(gfx::Rect());
9502 ScopedPtrVector
<CopyOutputRequest
> requests
;
9503 requests
.push_back(CopyOutputRequest::CreateEmptyRequest());
9505 greatgrandchild_ptr
->PassCopyRequests(&requests
);
9506 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9507 EXPECT_EQ(gfx::Rect(10, 10),
9508 grandchild_ptr
->visible_rect_from_property_trees());
9511 TEST_F(LayerTreeHostCommonTest
, SkippingLayer
) {
9512 gfx::Transform identity
;
9513 FakeContentLayerClient client
;
9514 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9515 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
9516 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
9517 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
9518 gfx::PointF(), gfx::Size(100, 100), true, false);
9519 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
9520 gfx::PointF(), gfx::Size(10, 10), true, false);
9521 root
->AddChild(child
);
9523 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9524 host
->SetRootLayer(root
);
9526 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9527 EXPECT_EQ(gfx::Rect(10, 10), child
->visible_rect_from_property_trees());
9528 child
->set_visible_rect_from_property_trees(gfx::Rect());
9530 child
->SetHideLayerAndSubtree(true);
9531 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9532 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
9533 child
->SetHideLayerAndSubtree(false);
9535 child
->SetBounds(gfx::Size());
9536 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9537 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
9538 child
->SetBounds(gfx::Size(10, 10));
9540 gfx::Transform rotate
;
9541 child
->SetDoubleSided(false);
9542 rotate
.RotateAboutXAxis(180.f
);
9543 child
->SetTransform(rotate
);
9544 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9545 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
9546 child
->SetDoubleSided(true);
9547 child
->SetTransform(identity
);
9549 child
->SetOpacity(0.f
);
9550 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9551 EXPECT_EQ(gfx::Rect(0, 0), child
->visible_rect_from_property_trees());
9554 TEST_F(LayerTreeHostCommonTest
, LayerTreeRebuildTest
) {
9555 // Ensure that the treewalk in LayerTreeHostCommom::
9556 // PreCalculateMetaInformation happens when its required.
9557 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9558 scoped_refptr
<Layer
> parent
= Layer::Create(layer_settings());
9559 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
9561 root
->AddChild(parent
);
9562 parent
->AddChild(child
);
9564 child
->SetClipParent(root
.get());
9566 gfx::Transform identity
;
9568 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
9569 gfx::PointF(), gfx::Size(100, 100), true, false);
9570 SetLayerPropertiesForTesting(parent
.get(), identity
, gfx::Point3F(),
9571 gfx::PointF(), gfx::Size(100, 100), true, false);
9572 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
9573 gfx::PointF(), gfx::Size(100, 100), true, false);
9575 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9576 host
->SetRootLayer(root
);
9578 ExecuteCalculateDrawProperties(root
.get());
9579 EXPECT_EQ(parent
->draw_properties().num_unclipped_descendants
, 1);
9581 // Ensure the dynamic update to input handlers happens.
9582 child
->SetHaveWheelEventHandlers(true);
9583 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_input_handler
);
9584 ExecuteCalculateDrawProperties(root
.get());
9585 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_input_handler
);
9587 child
->SetHaveWheelEventHandlers(false);
9588 EXPECT_FALSE(root
->draw_properties().layer_or_descendant_has_input_handler
);
9589 ExecuteCalculateDrawProperties(root
.get());
9590 EXPECT_FALSE(root
->draw_properties().layer_or_descendant_has_input_handler
);
9592 child
->RequestCopyOfOutput(
9593 CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback
)));
9594 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
9595 ExecuteCalculateDrawProperties(root
.get());
9596 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
9599 TEST_F(LayerTreeHostCommonTest
, InputHandlersRecursiveUpdateTest
) {
9600 // Ensure that the treewalk in LayertreeHostCommon::
9601 // PreCalculateMetaInformation updates input handlers correctly.
9602 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9603 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
9605 root
->AddChild(child
);
9607 child
->SetHaveWheelEventHandlers(true);
9609 gfx::Transform identity
;
9611 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
9612 gfx::PointF(), gfx::Size(100, 100), true, false);
9613 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
9614 gfx::PointF(), gfx::Size(100, 100), true, false);
9616 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9617 host
->SetRootLayer(root
);
9619 EXPECT_EQ(root
->num_layer_or_descendants_with_input_handler(), 0);
9620 ExecuteCalculateDrawProperties(root
.get());
9621 EXPECT_EQ(root
->num_layer_or_descendants_with_input_handler(), 1);
9622 child
->SetHaveWheelEventHandlers(false);
9623 EXPECT_EQ(root
->num_layer_or_descendants_with_input_handler(), 0);
9626 TEST_F(LayerTreeHostCommonTest
, ResetPropertyTreeIndices
) {
9627 gfx::Transform identity
;
9628 gfx::Transform translate_z
;
9629 translate_z
.Translate3d(0, 0, 10);
9631 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9632 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
9633 gfx::PointF(), gfx::Size(800, 800), true, false);
9635 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
9636 SetLayerPropertiesForTesting(child
.get(), translate_z
, gfx::Point3F(),
9637 gfx::PointF(), gfx::Size(100, 100), true, false);
9639 root
->AddChild(child
);
9641 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9642 host
->SetRootLayer(root
);
9644 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9645 EXPECT_NE(-1, child
->transform_tree_index());
9647 child
->RemoveFromParent();
9649 ExecuteCalculateDrawPropertiesWithPropertyTrees(root
.get());
9650 EXPECT_EQ(-1, child
->transform_tree_index());
9653 TEST_F(LayerTreeHostCommonTest
, ResetLayerDrawPropertiestest
) {
9654 scoped_refptr
<Layer
> root
= Layer::Create(layer_settings());
9655 scoped_refptr
<Layer
> child
= Layer::Create(layer_settings());
9657 root
->AddChild(child
);
9658 gfx::Transform identity
;
9660 SetLayerPropertiesForTesting(root
.get(), identity
, gfx::Point3F(),
9661 gfx::PointF(), gfx::Size(100, 100), true, false);
9662 SetLayerPropertiesForTesting(child
.get(), identity
, gfx::Point3F(),
9663 gfx::PointF(), gfx::Size(100, 100), true, false);
9665 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
9666 host
->SetRootLayer(root
);
9668 EXPECT_FALSE(root
->layer_or_descendant_is_drawn());
9669 EXPECT_FALSE(root
->visited());
9670 EXPECT_FALSE(root
->sorted_for_recursion());
9671 EXPECT_FALSE(child
->layer_or_descendant_is_drawn());
9672 EXPECT_FALSE(child
->visited());
9673 EXPECT_FALSE(child
->sorted_for_recursion());
9675 root
->set_layer_or_descendant_is_drawn(true);
9676 root
->set_visited(true);
9677 root
->set_sorted_for_recursion(true);
9678 child
->set_layer_or_descendant_is_drawn(true);
9679 child
->set_visited(true);
9680 child
->set_sorted_for_recursion(true);
9682 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root
.get());
9684 EXPECT_FALSE(root
->layer_or_descendant_is_drawn());
9685 EXPECT_FALSE(root
->visited());
9686 EXPECT_FALSE(root
->sorted_for_recursion());
9687 EXPECT_FALSE(child
->layer_or_descendant_is_drawn());
9688 EXPECT_FALSE(child
->visited());
9689 EXPECT_FALSE(child
->sorted_for_recursion());