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_impl_proxy.h"
25 #include "cc/test/fake_layer_tree_host.h"
26 #include "cc/test/fake_layer_tree_host_impl.h"
27 #include "cc/test/fake_picture_layer.h"
28 #include "cc/test/fake_picture_layer_impl.h"
29 #include "cc/test/geometry_test_utils.h"
30 #include "cc/test/layer_tree_host_common_test.h"
31 #include "cc/trees/layer_tree_impl.h"
32 #include "cc/trees/proxy.h"
33 #include "cc/trees/single_thread_proxy.h"
34 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h"
36 #include "ui/gfx/geometry/quad_f.h"
37 #include "ui/gfx/geometry/vector2d_conversions.h"
38 #include "ui/gfx/transform.h"
43 class LayerWithForcedDrawsContent
: public Layer
{
45 LayerWithForcedDrawsContent() {}
47 bool DrawsContent() const override
;
50 ~LayerWithForcedDrawsContent() override
{}
53 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
55 class MockContentLayerClient
: public ContentLayerClient
{
57 MockContentLayerClient() {}
58 ~MockContentLayerClient() override
{}
61 const gfx::Rect
& clip
,
62 ContentLayerClient::GraphicsContextStatus gc_status
) override
{}
63 scoped_refptr
<DisplayItemList
> PaintContentsToDisplayList(
64 const gfx::Rect
& clip
,
65 GraphicsContextStatus gc_status
) override
{
67 return DisplayItemList::Create();
69 bool FillsBoundsCompletely() const override
{ return false; }
72 scoped_refptr
<FakePictureLayer
> CreateDrawablePictureLayer(
73 ContentLayerClient
* delegate
) {
74 scoped_refptr
<FakePictureLayer
> to_return
=
75 FakePictureLayer::Create(delegate
);
76 to_return
->SetIsDrawable(true);
80 scoped_refptr
<ContentLayer
> CreateDrawableContentLayer(
81 ContentLayerClient
* delegate
) {
82 scoped_refptr
<ContentLayer
> to_return
= ContentLayer::Create(delegate
);
83 to_return
->SetIsDrawable(true);
87 #define EXPECT_CONTENTS_SCALE_EQ(expected, layer) \
89 EXPECT_FLOAT_EQ(expected, layer->contents_scale_x()); \
90 EXPECT_FLOAT_EQ(expected, layer->contents_scale_y()); \
93 #define EXPECT_IDEAL_SCALE_EQ(expected, layer) \
95 EXPECT_FLOAT_EQ(expected, layer->draw_properties().ideal_contents_scale); \
98 TEST_F(LayerTreeHostCommonTest
, TransformsForNoOpLayer
) {
99 // Sanity check: For layers positioned at zero, with zero size,
100 // and with identity transforms, then the draw transform,
101 // screen space transform, and the hierarchy passed on to children
102 // layers should also be identity transforms.
104 scoped_refptr
<Layer
> parent
= Layer::Create();
105 scoped_refptr
<Layer
> child
= Layer::Create();
106 scoped_refptr
<Layer
> grand_child
= Layer::Create();
107 parent
->AddChild(child
);
108 child
->AddChild(grand_child
);
110 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
111 host
->SetRootLayer(parent
);
113 gfx::Transform identity_matrix
;
114 SetLayerPropertiesForTesting(parent
.get(),
121 SetLayerPropertiesForTesting(child
.get(),
128 SetLayerPropertiesForTesting(grand_child
.get(),
136 ExecuteCalculateDrawProperties(parent
.get());
138 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
139 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
140 child
->screen_space_transform());
141 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
142 grand_child
->draw_transform());
143 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
144 grand_child
->screen_space_transform());
147 TEST_F(LayerTreeHostCommonTest
, DoNotSkipLayersWithHandlers
) {
148 scoped_refptr
<Layer
> parent
= Layer::Create();
149 scoped_refptr
<Layer
> child
= Layer::Create();
150 scoped_refptr
<Layer
> grand_child
= Layer::Create();
151 parent
->AddChild(child
);
152 child
->AddChild(grand_child
);
154 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
155 host
->SetRootLayer(parent
);
157 gfx::Transform identity_matrix
;
158 SetLayerPropertiesForTesting(parent
.get(),
165 SetLayerPropertiesForTesting(child
.get(),
172 // This would have previously caused us to skip our subtree, but this would be
173 // wrong; we need up-to-date draw properties to do hit testing on the layers
175 child
->SetOpacity(0.f
);
176 SetLayerPropertiesForTesting(grand_child
.get(),
183 grand_child
->SetTouchEventHandlerRegion(gfx::Rect(0, 0, 100, 100));
185 ExecuteCalculateDrawProperties(parent
.get());
187 // Check that we've computed draw properties for the subtree rooted at
189 EXPECT_FALSE(child
->draw_transform().IsIdentity());
190 EXPECT_FALSE(grand_child
->draw_transform().IsIdentity());
193 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleLayer
) {
194 gfx::Transform identity_matrix
;
195 scoped_refptr
<Layer
> layer
= Layer::Create();
197 scoped_refptr
<Layer
> root
= Layer::Create();
198 SetLayerPropertiesForTesting(root
.get(),
205 root
->AddChild(layer
);
207 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
208 host
->SetRootLayer(root
);
210 // Case 2: Setting the bounds of the layer should not affect either the draw
211 // transform or the screenspace transform.
212 gfx::Transform translation_to_center
;
213 translation_to_center
.Translate(5.0, 6.0);
214 SetLayerPropertiesForTesting(layer
.get(),
221 ExecuteCalculateDrawProperties(root
.get());
222 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
223 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
224 layer
->screen_space_transform());
226 // Case 3: The anchor point by itself (without a layer transform) should have
227 // no effect on the transforms.
228 SetLayerPropertiesForTesting(layer
.get(),
230 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
235 ExecuteCalculateDrawProperties(root
.get());
236 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, layer
->draw_transform());
237 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
238 layer
->screen_space_transform());
240 // Case 4: A change in actual position affects both the draw transform and
241 // screen space transform.
242 gfx::Transform position_transform
;
243 position_transform
.Translate(0.f
, 1.2f
);
244 SetLayerPropertiesForTesting(layer
.get(),
246 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
247 gfx::PointF(0.f
, 1.2f
),
251 ExecuteCalculateDrawProperties(root
.get());
252 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
, layer
->draw_transform());
253 EXPECT_TRANSFORMATION_MATRIX_EQ(position_transform
,
254 layer
->screen_space_transform());
256 // Case 5: In the correct sequence of transforms, the layer transform should
257 // pre-multiply the translation_to_center. This is easily tested by using a
258 // scale transform, because scale and translation are not commutative.
259 gfx::Transform layer_transform
;
260 layer_transform
.Scale3d(2.0, 2.0, 1.0);
261 SetLayerPropertiesForTesting(layer
.get(),
268 ExecuteCalculateDrawProperties(root
.get());
269 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
, layer
->draw_transform());
270 EXPECT_TRANSFORMATION_MATRIX_EQ(layer_transform
,
271 layer
->screen_space_transform());
273 // Case 6: The layer transform should occur with respect to the anchor point.
274 gfx::Transform translation_to_anchor
;
275 translation_to_anchor
.Translate(5.0, 0.0);
276 gfx::Transform expected_result
=
277 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
278 SetLayerPropertiesForTesting(layer
.get(),
280 gfx::Point3F(5.0f
, 0.f
, 0.f
),
285 ExecuteCalculateDrawProperties(root
.get());
286 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
287 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
288 layer
->screen_space_transform());
290 // Case 7: Verify that position pre-multiplies the layer transform. The
291 // current implementation of CalculateDrawProperties does this implicitly, but
292 // it is still worth testing to detect accidental regressions.
293 expected_result
= position_transform
* translation_to_anchor
*
294 layer_transform
* Inverse(translation_to_anchor
);
295 SetLayerPropertiesForTesting(layer
.get(),
297 gfx::Point3F(5.0f
, 0.f
, 0.f
),
298 gfx::PointF(0.f
, 1.2f
),
302 ExecuteCalculateDrawProperties(root
.get());
303 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
, layer
->draw_transform());
304 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_result
,
305 layer
->screen_space_transform());
308 TEST_F(LayerTreeHostCommonTest
, TransformsAboutScrollOffset
) {
309 const gfx::ScrollOffset
kScrollOffset(50, 100);
310 const gfx::Vector2dF
kScrollDelta(2.34f
, 5.67f
);
311 const gfx::Vector2d
kMaxScrollOffset(200, 200);
312 const gfx::PointF
kScrollLayerPosition(-kScrollOffset
.x(),
314 const float kPageScale
= 0.888f
;
315 const float kDeviceScale
= 1.666f
;
318 TestSharedBitmapManager shared_bitmap_manager
;
319 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
321 gfx::Transform identity_matrix
;
322 scoped_ptr
<LayerImpl
> sublayer_scoped_ptr(
323 LayerImpl::Create(host_impl
.active_tree(), 1));
324 LayerImpl
* sublayer
= sublayer_scoped_ptr
.get();
325 sublayer
->SetContentsScale(kPageScale
* kDeviceScale
,
326 kPageScale
* kDeviceScale
);
327 SetLayerPropertiesForTesting(sublayer
, identity_matrix
, gfx::Point3F(),
328 gfx::PointF(), gfx::Size(500, 500), true, false,
331 scoped_ptr
<LayerImpl
> scroll_layer_scoped_ptr(
332 LayerImpl::Create(host_impl
.active_tree(), 2));
333 LayerImpl
* scroll_layer
= scroll_layer_scoped_ptr
.get();
334 SetLayerPropertiesForTesting(scroll_layer
, identity_matrix
, gfx::Point3F(),
335 gfx::PointF(), gfx::Size(10, 20), true, false,
337 scoped_ptr
<LayerImpl
> clip_layer_scoped_ptr(
338 LayerImpl::Create(host_impl
.active_tree(), 4));
339 LayerImpl
* clip_layer
= clip_layer_scoped_ptr
.get();
341 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
342 clip_layer
->SetBounds(
343 gfx::Size(scroll_layer
->bounds().width() + kMaxScrollOffset
.x(),
344 scroll_layer
->bounds().height() + kMaxScrollOffset
.y()));
345 scroll_layer
->SetScrollClipLayer(clip_layer
->id());
346 scroll_layer
->SetScrollDelta(kScrollDelta
);
347 gfx::Transform impl_transform
;
348 scroll_layer
->AddChild(sublayer_scoped_ptr
.Pass());
349 LayerImpl
* scroll_layer_raw_ptr
= scroll_layer_scoped_ptr
.get();
350 clip_layer
->AddChild(scroll_layer_scoped_ptr
.Pass());
351 scroll_layer_raw_ptr
->SetScrollOffset(kScrollOffset
);
353 scoped_ptr
<LayerImpl
> root(LayerImpl::Create(host_impl
.active_tree(), 3));
354 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
355 gfx::PointF(), gfx::Size(3, 4), true, false,
357 root
->AddChild(clip_layer_scoped_ptr
.Pass());
358 root
->SetHasRenderSurface(true);
360 ExecuteCalculateDrawProperties(
361 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
362 gfx::Transform expected_transform
= identity_matrix
;
363 gfx::PointF sub_layer_screen_position
= kScrollLayerPosition
- kScrollDelta
;
364 sub_layer_screen_position
.Scale(kPageScale
* kDeviceScale
);
365 expected_transform
.Translate(MathUtil::Round(sub_layer_screen_position
.x()),
366 MathUtil::Round(sub_layer_screen_position
.y()));
367 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
368 sublayer
->draw_transform());
369 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
370 sublayer
->screen_space_transform());
372 gfx::Transform arbitrary_translate
;
373 const float kTranslateX
= 10.6f
;
374 const float kTranslateY
= 20.6f
;
375 arbitrary_translate
.Translate(kTranslateX
, kTranslateY
);
376 SetLayerPropertiesForTesting(scroll_layer
, arbitrary_translate
,
377 gfx::Point3F(), gfx::PointF(), gfx::Size(10, 20),
379 ExecuteCalculateDrawProperties(
380 root
.get(), kDeviceScale
, kPageScale
, scroll_layer
->parent());
381 expected_transform
.MakeIdentity();
382 expected_transform
.Translate(
383 MathUtil::Round(kTranslateX
* kPageScale
* kDeviceScale
+
384 sub_layer_screen_position
.x()),
385 MathUtil::Round(kTranslateY
* kPageScale
* kDeviceScale
+
386 sub_layer_screen_position
.y()));
387 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform
,
388 sublayer
->draw_transform());
391 TEST_F(LayerTreeHostCommonTest
, TransformsForSimpleHierarchy
) {
392 gfx::Transform identity_matrix
;
393 scoped_refptr
<Layer
> root
= Layer::Create();
394 scoped_refptr
<Layer
> parent
= Layer::Create();
395 scoped_refptr
<Layer
> child
= Layer::Create();
396 scoped_refptr
<Layer
> grand_child
= Layer::Create();
397 root
->AddChild(parent
);
398 parent
->AddChild(child
);
399 child
->AddChild(grand_child
);
401 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
402 host
->SetRootLayer(root
);
404 // One-time setup of root layer
405 SetLayerPropertiesForTesting(root
.get(),
413 // Case 1: parent's anchor point should not affect child or grand_child.
414 SetLayerPropertiesForTesting(parent
.get(),
416 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
421 SetLayerPropertiesForTesting(child
.get(),
428 SetLayerPropertiesForTesting(grand_child
.get(),
435 ExecuteCalculateDrawProperties(root
.get());
436 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
437 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
438 child
->screen_space_transform());
439 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
440 grand_child
->draw_transform());
441 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
442 grand_child
->screen_space_transform());
444 // Case 2: parent's position affects child and grand_child.
445 gfx::Transform parent_position_transform
;
446 parent_position_transform
.Translate(0.f
, 1.2f
);
447 SetLayerPropertiesForTesting(parent
.get(),
449 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
450 gfx::PointF(0.f
, 1.2f
),
454 SetLayerPropertiesForTesting(child
.get(),
461 SetLayerPropertiesForTesting(grand_child
.get(),
468 ExecuteCalculateDrawProperties(root
.get());
469 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
470 child
->draw_transform());
471 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
472 child
->screen_space_transform());
473 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
474 grand_child
->draw_transform());
475 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_position_transform
,
476 grand_child
->screen_space_transform());
478 // Case 3: parent's local transform affects child and grandchild
479 gfx::Transform parent_layer_transform
;
480 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
481 gfx::Transform parent_translation_to_anchor
;
482 parent_translation_to_anchor
.Translate(2.5, 3.0);
483 gfx::Transform parent_composite_transform
=
484 parent_translation_to_anchor
* parent_layer_transform
*
485 Inverse(parent_translation_to_anchor
);
486 SetLayerPropertiesForTesting(parent
.get(),
487 parent_layer_transform
,
488 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
493 SetLayerPropertiesForTesting(child
.get(),
500 SetLayerPropertiesForTesting(grand_child
.get(),
507 ExecuteCalculateDrawProperties(root
.get());
508 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
509 child
->draw_transform());
510 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
511 child
->screen_space_transform());
512 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
513 grand_child
->draw_transform());
514 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
515 grand_child
->screen_space_transform());
518 TEST_F(LayerTreeHostCommonTest
, TransformsForSingleRenderSurface
) {
519 scoped_refptr
<Layer
> root
= Layer::Create();
520 scoped_refptr
<Layer
> parent
= Layer::Create();
521 scoped_refptr
<Layer
> child
= Layer::Create();
522 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
523 make_scoped_refptr(new LayerWithForcedDrawsContent());
524 root
->AddChild(parent
);
525 parent
->AddChild(child
);
526 child
->AddChild(grand_child
);
528 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
529 host
->SetRootLayer(root
);
531 // One-time setup of root layer
532 gfx::Transform identity_matrix
;
533 SetLayerPropertiesForTesting(root
.get(),
541 // Child is set up so that a new render surface should be created.
542 child
->SetOpacity(0.5f
);
543 child
->SetForceRenderSurface(true);
545 gfx::Transform parent_layer_transform
;
546 parent_layer_transform
.Scale3d(1.f
, 0.9f
, 1.f
);
547 gfx::Transform parent_translation_to_anchor
;
548 parent_translation_to_anchor
.Translate(25.0, 30.0);
550 gfx::Transform parent_composite_transform
=
551 parent_translation_to_anchor
* parent_layer_transform
*
552 Inverse(parent_translation_to_anchor
);
553 gfx::Vector2dF parent_composite_scale
=
554 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
556 gfx::Transform surface_sublayer_transform
;
557 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
558 parent_composite_scale
.y());
559 gfx::Transform surface_sublayer_composite_transform
=
560 parent_composite_transform
* Inverse(surface_sublayer_transform
);
562 // Child's render surface should not exist yet.
563 ASSERT_FALSE(child
->render_surface());
565 SetLayerPropertiesForTesting(parent
.get(),
566 parent_layer_transform
,
567 gfx::Point3F(25.0f
, 30.0f
, 0.f
),
572 SetLayerPropertiesForTesting(child
.get(),
579 SetLayerPropertiesForTesting(grand_child
.get(),
586 ExecuteCalculateDrawProperties(root
.get());
588 // Render surface should have been created now.
589 ASSERT_TRUE(child
->render_surface());
590 ASSERT_EQ(child
.get(), child
->render_target());
592 // The child layer's draw transform should refer to its new render surface.
593 // The screen-space transform, however, should still refer to the root.
594 EXPECT_TRANSFORMATION_MATRIX_EQ(surface_sublayer_transform
,
595 child
->draw_transform());
596 EXPECT_TRANSFORMATION_MATRIX_EQ(parent_composite_transform
,
597 child
->screen_space_transform());
599 // Because the grand_child is the only drawable content, the child's render
600 // surface will tighten its bounds to the grand_child. The scale at which the
601 // surface's subtree is drawn must be removed from the composite transform.
602 EXPECT_TRANSFORMATION_MATRIX_EQ(
603 surface_sublayer_composite_transform
,
604 child
->render_target()->render_surface()->draw_transform());
606 // The screen space is the same as the target since the child surface draws
608 EXPECT_TRANSFORMATION_MATRIX_EQ(
609 surface_sublayer_composite_transform
,
610 child
->render_target()->render_surface()->screen_space_transform());
613 TEST_F(LayerTreeHostCommonTest
, TransformsForReplica
) {
614 scoped_refptr
<Layer
> root
= Layer::Create();
615 scoped_refptr
<Layer
> parent
= Layer::Create();
616 scoped_refptr
<Layer
> child
= Layer::Create();
617 scoped_refptr
<Layer
> child_replica
= Layer::Create();
618 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
619 make_scoped_refptr(new LayerWithForcedDrawsContent());
620 root
->AddChild(parent
);
621 parent
->AddChild(child
);
622 child
->AddChild(grand_child
);
623 child
->SetReplicaLayer(child_replica
.get());
625 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
626 host
->SetRootLayer(root
);
628 // One-time setup of root layer
629 gfx::Transform identity_matrix
;
630 SetLayerPropertiesForTesting(root
.get(),
638 // Child is set up so that a new render surface should be created.
639 child
->SetOpacity(0.5f
);
641 gfx::Transform parent_layer_transform
;
642 parent_layer_transform
.Scale3d(2.0, 2.0, 1.0);
643 gfx::Transform parent_translation_to_anchor
;
644 parent_translation_to_anchor
.Translate(2.5, 3.0);
645 gfx::Transform parent_composite_transform
=
646 parent_translation_to_anchor
* parent_layer_transform
*
647 Inverse(parent_translation_to_anchor
);
648 gfx::Transform replica_layer_transform
;
649 replica_layer_transform
.Scale3d(3.0, 3.0, 1.0);
650 gfx::Vector2dF parent_composite_scale
=
651 MathUtil::ComputeTransform2dScaleComponents(parent_composite_transform
,
653 gfx::Transform surface_sublayer_transform
;
654 surface_sublayer_transform
.Scale(parent_composite_scale
.x(),
655 parent_composite_scale
.y());
656 gfx::Transform replica_composite_transform
=
657 parent_composite_transform
* replica_layer_transform
*
658 Inverse(surface_sublayer_transform
);
659 child_replica
->SetIsDrawable(true);
660 // Child's render surface should not exist yet.
661 ASSERT_FALSE(child
->render_surface());
663 SetLayerPropertiesForTesting(parent
.get(),
664 parent_layer_transform
,
665 gfx::Point3F(2.5f
, 3.0f
, 0.f
),
670 SetLayerPropertiesForTesting(child
.get(),
677 SetLayerPropertiesForTesting(grand_child
.get(),
680 gfx::PointF(-0.5f
, -0.5f
),
684 SetLayerPropertiesForTesting(child_replica
.get(),
685 replica_layer_transform
,
691 ExecuteCalculateDrawProperties(root
.get());
693 // Render surface should have been created now.
694 ASSERT_TRUE(child
->render_surface());
695 ASSERT_EQ(child
.get(), child
->render_target());
697 EXPECT_TRANSFORMATION_MATRIX_EQ(
698 replica_composite_transform
,
699 child
->render_target()->render_surface()->replica_draw_transform());
700 EXPECT_TRANSFORMATION_MATRIX_EQ(replica_composite_transform
,
701 child
->render_target()
703 ->replica_screen_space_transform());
706 TEST_F(LayerTreeHostCommonTest
, TransformsForRenderSurfaceHierarchy
) {
707 // This test creates a more complex tree and verifies it all at once. This
708 // covers the following cases:
709 // - layers that are described w.r.t. a render surface: should have draw
710 // transforms described w.r.t. that surface
711 // - A render surface described w.r.t. an ancestor render surface: should
712 // have a draw transform described w.r.t. that ancestor surface
713 // - Replicas of a render surface are described w.r.t. the replica's
714 // transform around its anchor, along with the surface itself.
715 // - Sanity check on recursion: verify transforms of layers described w.r.t.
716 // a render surface that is described w.r.t. an ancestor render surface.
717 // - verifying that each layer has a reference to the correct render surface
718 // and render target values.
720 scoped_refptr
<Layer
> root
= Layer::Create();
721 scoped_refptr
<Layer
> parent
= Layer::Create();
722 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
723 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
724 scoped_refptr
<Layer
> child_of_root
= Layer::Create();
725 scoped_refptr
<Layer
> child_of_rs1
= Layer::Create();
726 scoped_refptr
<Layer
> child_of_rs2
= Layer::Create();
727 scoped_refptr
<Layer
> replica_of_rs1
= Layer::Create();
728 scoped_refptr
<Layer
> replica_of_rs2
= Layer::Create();
729 scoped_refptr
<Layer
> grand_child_of_root
= Layer::Create();
730 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs1
=
731 make_scoped_refptr(new LayerWithForcedDrawsContent());
732 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs2
=
733 make_scoped_refptr(new LayerWithForcedDrawsContent());
734 root
->AddChild(parent
);
735 parent
->AddChild(render_surface1
);
736 parent
->AddChild(child_of_root
);
737 render_surface1
->AddChild(child_of_rs1
);
738 render_surface1
->AddChild(render_surface2
);
739 render_surface2
->AddChild(child_of_rs2
);
740 child_of_root
->AddChild(grand_child_of_root
);
741 child_of_rs1
->AddChild(grand_child_of_rs1
);
742 child_of_rs2
->AddChild(grand_child_of_rs2
);
743 render_surface1
->SetReplicaLayer(replica_of_rs1
.get());
744 render_surface2
->SetReplicaLayer(replica_of_rs2
.get());
746 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
747 host
->SetRootLayer(root
);
749 // In combination with descendant draws content, opacity != 1 forces the layer
750 // to have a new render surface.
751 render_surface1
->SetOpacity(0.5f
);
752 render_surface2
->SetOpacity(0.33f
);
754 // One-time setup of root layer
755 gfx::Transform identity_matrix
;
756 SetLayerPropertiesForTesting(root
.get(),
764 // All layers in the tree are initialized with an anchor at .25 and a size of
765 // (10,10). matrix "A" is the composite layer transform used in all layers,
766 // Matrix "R" is the composite replica transform used in all replica layers.
767 gfx::Transform translation_to_anchor
;
768 translation_to_anchor
.Translate(2.5, 0.0);
769 gfx::Transform layer_transform
;
770 layer_transform
.Translate(1.0, 1.0);
771 gfx::Transform replica_layer_transform
;
772 replica_layer_transform
.Scale3d(-2.0, 5.0, 1.0);
775 translation_to_anchor
* layer_transform
* Inverse(translation_to_anchor
);
776 gfx::Transform R
= A
* translation_to_anchor
* replica_layer_transform
*
777 Inverse(translation_to_anchor
);
779 gfx::Vector2dF surface1_parent_transform_scale
=
780 MathUtil::ComputeTransform2dScaleComponents(A
, 1.f
);
781 gfx::Transform surface1_sublayer_transform
;
782 surface1_sublayer_transform
.Scale(surface1_parent_transform_scale
.x(),
783 surface1_parent_transform_scale
.y());
785 // SS1 = transform given to the subtree of render_surface1
786 gfx::Transform SS1
= surface1_sublayer_transform
;
787 // S1 = transform to move from render_surface1 pixels to the layer space of
789 gfx::Transform S1
= Inverse(surface1_sublayer_transform
);
791 gfx::Vector2dF surface2_parent_transform_scale
=
792 MathUtil::ComputeTransform2dScaleComponents(SS1
* A
, 1.f
);
793 gfx::Transform surface2_sublayer_transform
;
794 surface2_sublayer_transform
.Scale(surface2_parent_transform_scale
.x(),
795 surface2_parent_transform_scale
.y());
797 // SS2 = transform given to the subtree of render_surface2
798 gfx::Transform SS2
= surface2_sublayer_transform
;
799 // S2 = transform to move from render_surface2 pixels to the layer space of
801 gfx::Transform S2
= Inverse(surface2_sublayer_transform
);
803 SetLayerPropertiesForTesting(parent
.get(),
805 gfx::Point3F(2.5f
, 0.f
, 0.f
),
810 SetLayerPropertiesForTesting(render_surface1
.get(),
812 gfx::Point3F(2.5f
, 0.f
, 0.f
),
817 SetLayerPropertiesForTesting(render_surface2
.get(),
819 gfx::Point3F(2.5f
, 0.f
, 0.f
),
824 SetLayerPropertiesForTesting(child_of_root
.get(),
826 gfx::Point3F(2.5f
, 0.f
, 0.f
),
831 SetLayerPropertiesForTesting(child_of_rs1
.get(),
833 gfx::Point3F(2.5f
, 0.f
, 0.f
),
838 SetLayerPropertiesForTesting(child_of_rs2
.get(),
840 gfx::Point3F(2.5f
, 0.f
, 0.f
),
845 SetLayerPropertiesForTesting(grand_child_of_root
.get(),
847 gfx::Point3F(2.5f
, 0.f
, 0.f
),
852 SetLayerPropertiesForTesting(grand_child_of_rs1
.get(),
854 gfx::Point3F(2.5f
, 0.f
, 0.f
),
859 SetLayerPropertiesForTesting(grand_child_of_rs2
.get(),
861 gfx::Point3F(2.5f
, 0.f
, 0.f
),
866 SetLayerPropertiesForTesting(replica_of_rs1
.get(),
867 replica_layer_transform
,
868 gfx::Point3F(2.5f
, 0.f
, 0.f
),
873 SetLayerPropertiesForTesting(replica_of_rs2
.get(),
874 replica_layer_transform
,
875 gfx::Point3F(2.5f
, 0.f
, 0.f
),
881 ExecuteCalculateDrawProperties(root
.get());
883 // Only layers that are associated with render surfaces should have an actual
884 // RenderSurface() value.
885 ASSERT_TRUE(root
->render_surface());
886 ASSERT_FALSE(child_of_root
->render_surface());
887 ASSERT_FALSE(grand_child_of_root
->render_surface());
889 ASSERT_TRUE(render_surface1
->render_surface());
890 ASSERT_FALSE(child_of_rs1
->render_surface());
891 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
893 ASSERT_TRUE(render_surface2
->render_surface());
894 ASSERT_FALSE(child_of_rs2
->render_surface());
895 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
897 // Verify all render target accessors
898 EXPECT_EQ(root
.get(), parent
->render_target());
899 EXPECT_EQ(root
.get(), child_of_root
->render_target());
900 EXPECT_EQ(root
.get(), grand_child_of_root
->render_target());
902 EXPECT_EQ(render_surface1
.get(), render_surface1
->render_target());
903 EXPECT_EQ(render_surface1
.get(), child_of_rs1
->render_target());
904 EXPECT_EQ(render_surface1
.get(), grand_child_of_rs1
->render_target());
906 EXPECT_EQ(render_surface2
.get(), render_surface2
->render_target());
907 EXPECT_EQ(render_surface2
.get(), child_of_rs2
->render_target());
908 EXPECT_EQ(render_surface2
.get(), grand_child_of_rs2
->render_target());
910 // Verify layer draw transforms note that draw transforms are described with
911 // respect to the nearest ancestor render surface but screen space transforms
912 // are described with respect to the root.
913 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->draw_transform());
914 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
, child_of_root
->draw_transform());
915 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
916 grand_child_of_root
->draw_transform());
918 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
, render_surface1
->draw_transform());
919 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
, child_of_rs1
->draw_transform());
920 EXPECT_TRANSFORMATION_MATRIX_EQ(SS1
* A
* A
,
921 grand_child_of_rs1
->draw_transform());
923 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
, render_surface2
->draw_transform());
924 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
, child_of_rs2
->draw_transform());
925 EXPECT_TRANSFORMATION_MATRIX_EQ(SS2
* A
* A
,
926 grand_child_of_rs2
->draw_transform());
928 // Verify layer screen-space transforms
930 EXPECT_TRANSFORMATION_MATRIX_EQ(A
, parent
->screen_space_transform());
931 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
932 child_of_root
->screen_space_transform());
933 EXPECT_TRANSFORMATION_MATRIX_EQ(
934 A
* A
* A
, grand_child_of_root
->screen_space_transform());
936 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
,
937 render_surface1
->screen_space_transform());
938 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
939 child_of_rs1
->screen_space_transform());
940 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
941 grand_child_of_rs1
->screen_space_transform());
943 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
,
944 render_surface2
->screen_space_transform());
945 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
,
946 child_of_rs2
->screen_space_transform());
947 EXPECT_TRANSFORMATION_MATRIX_EQ(A
* A
* A
* A
* A
,
948 grand_child_of_rs2
->screen_space_transform());
950 // Verify render surface transforms.
952 // Draw transform of render surface 1 is described with respect to root.
953 EXPECT_TRANSFORMATION_MATRIX_EQ(
954 A
* A
* S1
, render_surface1
->render_surface()->draw_transform());
955 EXPECT_TRANSFORMATION_MATRIX_EQ(
956 A
* R
* S1
, render_surface1
->render_surface()->replica_draw_transform());
957 EXPECT_TRANSFORMATION_MATRIX_EQ(
958 A
* A
* S1
, render_surface1
->render_surface()->screen_space_transform());
959 EXPECT_TRANSFORMATION_MATRIX_EQ(
961 render_surface1
->render_surface()->replica_screen_space_transform());
962 // Draw transform of render surface 2 is described with respect to render
964 EXPECT_TRANSFORMATION_MATRIX_EQ(
965 SS1
* A
* S2
, render_surface2
->render_surface()->draw_transform());
966 EXPECT_TRANSFORMATION_MATRIX_EQ(
968 render_surface2
->render_surface()->replica_draw_transform());
969 EXPECT_TRANSFORMATION_MATRIX_EQ(
971 render_surface2
->render_surface()->screen_space_transform());
972 EXPECT_TRANSFORMATION_MATRIX_EQ(
974 render_surface2
->render_surface()->replica_screen_space_transform());
976 // Sanity check. If these fail there is probably a bug in the test itself. It
977 // is expected that we correctly set up transforms so that the y-component of
978 // the screen-space transform encodes the "depth" of the layer in the tree.
979 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
981 child_of_root
->screen_space_transform().matrix().get(1, 3));
983 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
986 render_surface1
->screen_space_transform().matrix().get(1, 3));
988 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
990 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
993 render_surface2
->screen_space_transform().matrix().get(1, 3));
995 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
997 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
1000 TEST_F(LayerTreeHostCommonTest
, TransformsForFlatteningLayer
) {
1001 // For layers that flatten their subtree, there should be an orthographic
1002 // projection (for x and y values) in the middle of the transform sequence.
1003 // Note that the way the code is currently implemented, it is not expected to
1004 // use a canonical orthographic projection.
1006 scoped_refptr
<Layer
> root
= Layer::Create();
1007 scoped_refptr
<Layer
> child
= Layer::Create();
1008 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1009 make_scoped_refptr(new LayerWithForcedDrawsContent());
1011 gfx::Transform rotation_about_y_axis
;
1012 rotation_about_y_axis
.RotateAboutYAxis(30.0);
1014 const gfx::Transform identity_matrix
;
1015 SetLayerPropertiesForTesting(root
.get(),
1019 gfx::Size(100, 100),
1022 SetLayerPropertiesForTesting(child
.get(),
1023 rotation_about_y_axis
,
1029 SetLayerPropertiesForTesting(grand_child
.get(),
1030 rotation_about_y_axis
,
1037 root
->AddChild(child
);
1038 child
->AddChild(grand_child
);
1039 child
->SetForceRenderSurface(true);
1041 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1042 host
->SetRootLayer(root
);
1044 // No layers in this test should preserve 3d.
1045 ASSERT_TRUE(root
->should_flatten_transform());
1046 ASSERT_TRUE(child
->should_flatten_transform());
1047 ASSERT_TRUE(grand_child
->should_flatten_transform());
1049 gfx::Transform expected_child_draw_transform
= rotation_about_y_axis
;
1050 gfx::Transform expected_child_screen_space_transform
= rotation_about_y_axis
;
1051 gfx::Transform expected_grand_child_draw_transform
=
1052 rotation_about_y_axis
; // draws onto child's render surface
1053 gfx::Transform flattened_rotation_about_y
= rotation_about_y_axis
;
1054 flattened_rotation_about_y
.FlattenTo2d();
1055 gfx::Transform expected_grand_child_screen_space_transform
=
1056 flattened_rotation_about_y
* rotation_about_y_axis
;
1058 ExecuteCalculateDrawProperties(root
.get());
1060 // The child's draw transform should have been taken by its surface.
1061 ASSERT_TRUE(child
->render_surface());
1062 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_draw_transform
,
1063 child
->render_surface()->draw_transform());
1064 EXPECT_TRANSFORMATION_MATRIX_EQ(
1065 expected_child_screen_space_transform
,
1066 child
->render_surface()->screen_space_transform());
1067 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1068 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_screen_space_transform
,
1069 child
->screen_space_transform());
1070 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_draw_transform
,
1071 grand_child
->draw_transform());
1072 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_screen_space_transform
,
1073 grand_child
->screen_space_transform());
1076 TEST_F(LayerTreeHostCommonTest
, TransformsForDegenerateIntermediateLayer
) {
1077 // A layer that is empty in one axis, but not the other, was accidentally
1078 // skipping a necessary translation. Without that translation, the coordinate
1079 // space of the layer's draw transform is incorrect.
1081 // Normally this isn't a problem, because the layer wouldn't be drawn anyway,
1082 // but if that layer becomes a render surface, then its draw transform is
1083 // implicitly inherited by the rest of the subtree, which then is positioned
1084 // incorrectly as a result.
1086 scoped_refptr
<Layer
> root
= Layer::Create();
1087 scoped_refptr
<Layer
> child
= Layer::Create();
1088 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
1089 make_scoped_refptr(new LayerWithForcedDrawsContent());
1091 // The child height is zero, but has non-zero width that should be accounted
1092 // for while computing draw transforms.
1093 const gfx::Transform identity_matrix
;
1094 SetLayerPropertiesForTesting(root
.get(),
1098 gfx::Size(100, 100),
1101 SetLayerPropertiesForTesting(child
.get(),
1108 SetLayerPropertiesForTesting(grand_child
.get(),
1116 root
->AddChild(child
);
1117 child
->AddChild(grand_child
);
1118 child
->SetForceRenderSurface(true);
1120 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1121 host
->SetRootLayer(root
);
1123 ExecuteCalculateDrawProperties(root
.get());
1125 ASSERT_TRUE(child
->render_surface());
1126 // This is the real test, the rest are sanity checks.
1127 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1128 child
->render_surface()->draw_transform());
1129 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
, child
->draw_transform());
1130 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix
,
1131 grand_child
->draw_transform());
1134 TEST_F(LayerTreeHostCommonTest
, TransformAboveRootLayer
) {
1135 // Transformations applied at the root of the tree should be forwarded
1136 // to child layers instead of applied to the root RenderSurface.
1137 const gfx::Transform identity_matrix
;
1138 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
1139 new LayerWithForcedDrawsContent
;
1140 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1141 new LayerWithForcedDrawsContent
;
1142 child
->SetScrollClipLayerId(root
->id());
1143 root
->AddChild(child
);
1145 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1146 host
->SetRootLayer(root
);
1148 SetLayerPropertiesForTesting(root
.get(),
1155 SetLayerPropertiesForTesting(child
.get(),
1163 gfx::Transform translate
;
1164 translate
.Translate(50, 50);
1166 RenderSurfaceLayerList render_surface_layer_list
;
1167 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1168 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1169 inputs
.can_adjust_raster_scales
= true;
1170 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1171 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1172 EXPECT_EQ(translate
, child
->draw_properties().target_space_transform
);
1173 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1174 EXPECT_EQ(1.f
, root
->draw_properties().device_scale_factor
);
1175 EXPECT_EQ(1.f
, child
->draw_properties().device_scale_factor
);
1178 gfx::Transform scale
;
1181 RenderSurfaceLayerList render_surface_layer_list
;
1182 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1183 root
.get(), root
->bounds(), scale
, &render_surface_layer_list
);
1184 inputs
.can_adjust_raster_scales
= true;
1185 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1186 EXPECT_EQ(scale
, root
->draw_properties().target_space_transform
);
1187 EXPECT_EQ(scale
, child
->draw_properties().target_space_transform
);
1188 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1189 EXPECT_EQ(2.f
, root
->draw_properties().device_scale_factor
);
1190 EXPECT_EQ(2.f
, child
->draw_properties().device_scale_factor
);
1193 gfx::Transform rotate
;
1196 RenderSurfaceLayerList render_surface_layer_list
;
1197 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1198 root
.get(), root
->bounds(), rotate
, &render_surface_layer_list
);
1199 inputs
.can_adjust_raster_scales
= true;
1200 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1201 EXPECT_EQ(rotate
, root
->draw_properties().target_space_transform
);
1202 EXPECT_EQ(rotate
, child
->draw_properties().target_space_transform
);
1203 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1204 EXPECT_EQ(1.f
, root
->draw_properties().device_scale_factor
);
1205 EXPECT_EQ(1.f
, child
->draw_properties().device_scale_factor
);
1208 gfx::Transform composite
;
1209 composite
.ConcatTransform(translate
);
1210 composite
.ConcatTransform(scale
);
1211 composite
.ConcatTransform(rotate
);
1213 RenderSurfaceLayerList render_surface_layer_list
;
1214 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1215 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1216 inputs
.can_adjust_raster_scales
= true;
1217 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1218 EXPECT_EQ(composite
, root
->draw_properties().target_space_transform
);
1219 EXPECT_EQ(composite
, child
->draw_properties().target_space_transform
);
1220 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1223 // Verify it composes correctly with device scale.
1224 float device_scale_factor
= 1.5f
;
1227 RenderSurfaceLayerList render_surface_layer_list
;
1228 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1229 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1230 inputs
.device_scale_factor
= device_scale_factor
;
1231 inputs
.can_adjust_raster_scales
= true;
1232 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1233 gfx::Transform device_scaled_translate
= translate
;
1234 device_scaled_translate
.Scale(device_scale_factor
, device_scale_factor
);
1235 EXPECT_EQ(device_scaled_translate
,
1236 root
->draw_properties().target_space_transform
);
1237 EXPECT_EQ(device_scaled_translate
,
1238 child
->draw_properties().target_space_transform
);
1239 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1240 EXPECT_EQ(device_scale_factor
, root
->draw_properties().device_scale_factor
);
1241 EXPECT_EQ(device_scale_factor
,
1242 child
->draw_properties().device_scale_factor
);
1245 // Verify it composes correctly with page scale.
1246 float page_scale_factor
= 2.f
;
1249 RenderSurfaceLayerList render_surface_layer_list
;
1250 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1251 root
.get(), root
->bounds(), translate
, &render_surface_layer_list
);
1252 inputs
.page_scale_factor
= page_scale_factor
;
1253 inputs
.page_scale_application_layer
= root
.get();
1254 inputs
.can_adjust_raster_scales
= true;
1255 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1256 gfx::Transform page_scaled_translate
= translate
;
1257 page_scaled_translate
.Scale(page_scale_factor
, page_scale_factor
);
1258 EXPECT_EQ(translate
, root
->draw_properties().target_space_transform
);
1259 EXPECT_EQ(page_scaled_translate
,
1260 child
->draw_properties().target_space_transform
);
1261 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1262 EXPECT_EQ(1.f
, root
->draw_properties().device_scale_factor
);
1263 EXPECT_EQ(1.f
, child
->draw_properties().device_scale_factor
);
1266 // Verify that it composes correctly with transforms directly on root layer.
1267 root
->SetTransform(composite
);
1270 RenderSurfaceLayerList render_surface_layer_list
;
1271 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1272 root
.get(), root
->bounds(), composite
, &render_surface_layer_list
);
1273 inputs
.can_adjust_raster_scales
= true;
1274 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1275 gfx::Transform compositeSquared
= composite
;
1276 compositeSquared
.ConcatTransform(composite
);
1277 EXPECT_TRANSFORMATION_MATRIX_EQ(
1278 compositeSquared
, root
->draw_properties().target_space_transform
);
1279 EXPECT_TRANSFORMATION_MATRIX_EQ(
1280 compositeSquared
, child
->draw_properties().target_space_transform
);
1281 EXPECT_EQ(identity_matrix
, root
->render_surface()->draw_transform());
1285 TEST_F(LayerTreeHostCommonTest
,
1286 RenderSurfaceListForRenderSurfaceWithClippedLayer
) {
1287 scoped_refptr
<Layer
> parent
= Layer::Create();
1288 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1289 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1290 make_scoped_refptr(new LayerWithForcedDrawsContent());
1292 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1293 host
->SetRootLayer(parent
);
1295 const gfx::Transform identity_matrix
;
1296 SetLayerPropertiesForTesting(parent
.get(),
1303 SetLayerPropertiesForTesting(render_surface1
.get(),
1310 SetLayerPropertiesForTesting(child
.get(),
1313 gfx::PointF(30.f
, 30.f
),
1318 parent
->AddChild(render_surface1
);
1319 parent
->SetMasksToBounds(true);
1320 render_surface1
->AddChild(child
);
1321 render_surface1
->SetForceRenderSurface(true);
1323 RenderSurfaceLayerList render_surface_layer_list
;
1324 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1328 &render_surface_layer_list
);
1329 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1331 // The child layer's content is entirely outside the parent's clip rect, so
1332 // the intermediate render surface should not be listed here, even if it was
1333 // forced to be created. Render surfaces without children or visible content
1334 // are unexpected at draw time (e.g. we might try to create a content texture
1336 ASSERT_TRUE(parent
->render_surface());
1337 EXPECT_EQ(1U, render_surface_layer_list
.size());
1340 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceListForTransparentChild
) {
1341 scoped_refptr
<Layer
> parent
= Layer::Create();
1342 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1343 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1344 make_scoped_refptr(new LayerWithForcedDrawsContent());
1346 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1347 host
->SetRootLayer(parent
);
1349 const gfx::Transform identity_matrix
;
1350 SetLayerPropertiesForTesting(render_surface1
.get(),
1357 SetLayerPropertiesForTesting(child
.get(),
1365 parent
->AddChild(render_surface1
);
1366 render_surface1
->AddChild(child
);
1367 render_surface1
->SetForceRenderSurface(true);
1368 render_surface1
->SetOpacity(0.f
);
1370 RenderSurfaceLayerList render_surface_layer_list
;
1371 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1372 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1373 inputs
.can_adjust_raster_scales
= true;
1374 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1376 // Since the layer is transparent, render_surface1->render_surface() should
1377 // not have gotten added anywhere. Also, the drawable content rect should not
1378 // have been extended by the children.
1379 ASSERT_TRUE(parent
->render_surface());
1380 EXPECT_EQ(0U, parent
->render_surface()->layer_list().size());
1381 EXPECT_EQ(1U, render_surface_layer_list
.size());
1382 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1383 EXPECT_EQ(gfx::Rect(), parent
->drawable_content_rect());
1386 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceForBlendMode
) {
1387 scoped_refptr
<Layer
> parent
= Layer::Create();
1388 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1389 make_scoped_refptr(new LayerWithForcedDrawsContent());
1391 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1392 host
->SetRootLayer(parent
);
1394 const gfx::Transform identity_matrix
;
1395 const SkXfermode::Mode blend_mode
= SkXfermode::kMultiply_Mode
;
1396 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
1397 gfx::PointF(), gfx::Size(10, 10), true, false);
1399 parent
->AddChild(child
);
1400 child
->SetBlendMode(blend_mode
);
1402 RenderSurfaceLayerList render_surface_layer_list
;
1403 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1404 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1405 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1407 // Since the child layer has a blend mode other than normal, it should get
1408 // its own render surface. Also, layer's draw_properties should contain the
1409 // default blend mode, since the render surface becomes responsible for
1410 // applying the blend mode.
1411 ASSERT_TRUE(child
->render_surface());
1412 EXPECT_EQ(1U, child
->render_surface()->layer_list().size());
1413 EXPECT_EQ(SkXfermode::kSrcOver_Mode
, child
->draw_properties().blend_mode
);
1416 TEST_F(LayerTreeHostCommonTest
, ForceRenderSurface
) {
1417 scoped_refptr
<Layer
> parent
= Layer::Create();
1418 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
1419 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
1420 make_scoped_refptr(new LayerWithForcedDrawsContent());
1421 render_surface1
->SetForceRenderSurface(true);
1423 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1424 host
->SetRootLayer(parent
);
1426 const gfx::Transform identity_matrix
;
1427 SetLayerPropertiesForTesting(parent
.get(),
1434 SetLayerPropertiesForTesting(render_surface1
.get(),
1441 SetLayerPropertiesForTesting(child
.get(),
1449 parent
->AddChild(render_surface1
);
1450 render_surface1
->AddChild(child
);
1452 // Sanity check before the actual test
1453 EXPECT_FALSE(parent
->render_surface());
1454 EXPECT_FALSE(render_surface1
->render_surface());
1457 RenderSurfaceLayerList render_surface_layer_list
;
1458 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1459 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1460 inputs
.can_adjust_raster_scales
= true;
1461 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1463 // The root layer always creates a render surface
1464 EXPECT_TRUE(parent
->render_surface());
1465 EXPECT_TRUE(render_surface1
->render_surface());
1466 EXPECT_EQ(2U, render_surface_layer_list
.size());
1470 RenderSurfaceLayerList render_surface_layer_list
;
1471 render_surface1
->SetForceRenderSurface(false);
1472 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1473 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1474 inputs
.can_adjust_raster_scales
= true;
1475 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1476 EXPECT_TRUE(parent
->render_surface());
1477 EXPECT_FALSE(render_surface1
->render_surface());
1478 EXPECT_EQ(1U, render_surface_layer_list
.size());
1482 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsRenderSurfaces
) {
1483 // The entire subtree of layers that are outside the clip rect should be
1484 // culled away, and should not affect the render_surface_layer_list.
1486 // The test tree is set up as follows:
1487 // - all layers except the leaf_nodes are forced to be a new render surface
1488 // that have something to draw.
1489 // - parent is a large container layer.
1490 // - child has masksToBounds=true to cause clipping.
1491 // - grand_child is positioned outside of the child's bounds
1492 // - great_grand_child is also kept outside child's bounds.
1494 // In this configuration, grand_child and great_grand_child are completely
1495 // outside the clip rect, and they should never get scheduled on the list of
1499 const gfx::Transform identity_matrix
;
1500 scoped_refptr
<Layer
> parent
= Layer::Create();
1501 scoped_refptr
<Layer
> child
= Layer::Create();
1502 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1503 scoped_refptr
<Layer
> great_grand_child
= Layer::Create();
1504 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1505 make_scoped_refptr(new LayerWithForcedDrawsContent());
1506 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1507 make_scoped_refptr(new LayerWithForcedDrawsContent());
1508 parent
->AddChild(child
);
1509 child
->AddChild(grand_child
);
1510 grand_child
->AddChild(great_grand_child
);
1512 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1513 host
->SetRootLayer(parent
);
1515 // leaf_node1 ensures that parent and child are kept on the
1516 // render_surface_layer_list, even though grand_child and great_grand_child
1517 // should be clipped.
1518 child
->AddChild(leaf_node1
);
1519 great_grand_child
->AddChild(leaf_node2
);
1521 SetLayerPropertiesForTesting(parent
.get(),
1525 gfx::Size(500, 500),
1528 SetLayerPropertiesForTesting(child
.get(),
1535 SetLayerPropertiesForTesting(grand_child
.get(),
1538 gfx::PointF(45.f
, 45.f
),
1542 SetLayerPropertiesForTesting(great_grand_child
.get(),
1549 SetLayerPropertiesForTesting(leaf_node1
.get(),
1553 gfx::Size(500, 500),
1556 SetLayerPropertiesForTesting(leaf_node2
.get(),
1564 child
->SetMasksToBounds(true);
1565 child
->SetOpacity(0.4f
);
1566 child
->SetForceRenderSurface(true);
1567 grand_child
->SetOpacity(0.5f
);
1568 great_grand_child
->SetOpacity(0.4f
);
1570 RenderSurfaceLayerList render_surface_layer_list
;
1571 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1572 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1573 inputs
.can_adjust_raster_scales
= true;
1574 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1576 ASSERT_EQ(2U, render_surface_layer_list
.size());
1577 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1578 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1581 TEST_F(LayerTreeHostCommonTest
, ClipRectCullsSurfaceWithoutVisibleContent
) {
1582 // When a render surface has a clip rect, it is used to clip the content rect
1583 // of the surface. When the render surface is animating its transforms, then
1584 // the content rect's position in the clip rect is not defined on the main
1585 // thread, and its content rect should not be clipped.
1587 // The test tree is set up as follows:
1588 // - parent is a container layer that masksToBounds=true to cause clipping.
1589 // - child is a render surface, which has a clip rect set to the bounds of
1591 // - grand_child is a render surface, and the only visible content in child.
1592 // It is positioned outside of the clip rect from parent.
1594 // In this configuration, grand_child should be outside the clipped
1595 // content rect of the child, making grand_child not appear in the
1596 // render_surface_layer_list. However, when we place an animation on the
1597 // child, this clipping should be avoided and we should keep the grand_child
1598 // in the render_surface_layer_list.
1600 const gfx::Transform identity_matrix
;
1601 scoped_refptr
<Layer
> parent
= Layer::Create();
1602 scoped_refptr
<Layer
> child
= Layer::Create();
1603 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1604 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node
=
1605 make_scoped_refptr(new LayerWithForcedDrawsContent());
1606 parent
->AddChild(child
);
1607 child
->AddChild(grand_child
);
1608 grand_child
->AddChild(leaf_node
);
1610 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1611 host
->SetRootLayer(parent
);
1613 SetLayerPropertiesForTesting(parent
.get(),
1617 gfx::Size(100, 100),
1620 SetLayerPropertiesForTesting(child
.get(),
1627 SetLayerPropertiesForTesting(grand_child
.get(),
1630 gfx::PointF(200.f
, 200.f
),
1634 SetLayerPropertiesForTesting(leaf_node
.get(),
1642 parent
->SetMasksToBounds(true);
1643 child
->SetOpacity(0.4f
);
1644 child
->SetForceRenderSurface(true);
1645 grand_child
->SetOpacity(0.4f
);
1646 grand_child
->SetForceRenderSurface(true);
1649 RenderSurfaceLayerList render_surface_layer_list
;
1650 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1651 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1652 inputs
.can_adjust_raster_scales
= true;
1653 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1655 // Without an animation, we should cull child and grand_child from the
1656 // render_surface_layer_list.
1657 ASSERT_EQ(1U, render_surface_layer_list
.size());
1658 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1661 // Now put an animating transform on child.
1662 AddAnimatedTransformToController(
1663 child
->layer_animation_controller(), 10.0, 30, 0);
1666 RenderSurfaceLayerList render_surface_layer_list
;
1667 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1668 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1669 inputs
.can_adjust_raster_scales
= true;
1670 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1672 // With an animating transform, we should keep child and grand_child in the
1673 // render_surface_layer_list.
1674 ASSERT_EQ(3U, render_surface_layer_list
.size());
1675 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
1676 EXPECT_EQ(child
->id(), render_surface_layer_list
.at(1)->id());
1677 EXPECT_EQ(grand_child
->id(), render_surface_layer_list
.at(2)->id());
1681 TEST_F(LayerTreeHostCommonTest
, IsClippedIsSetCorrectly
) {
1682 // Layer's IsClipped() property is set to true when:
1683 // - the layer clips its subtree, e.g. masks to bounds,
1684 // - the layer is clipped by an ancestor that contributes to the same
1686 // - a surface is clipped by an ancestor that contributes to the same
1689 // In particular, for a layer that owns a render surface:
1690 // - the render surface inherits any clip from ancestors, and does NOT
1691 // pass that clipped status to the layer itself.
1692 // - but if the layer itself masks to bounds, it is considered clipped
1693 // and propagates the clip to the subtree.
1695 const gfx::Transform identity_matrix
;
1696 scoped_refptr
<Layer
> root
= Layer::Create();
1697 scoped_refptr
<Layer
> parent
= Layer::Create();
1698 scoped_refptr
<Layer
> child1
= Layer::Create();
1699 scoped_refptr
<Layer
> child2
= Layer::Create();
1700 scoped_refptr
<Layer
> grand_child
= Layer::Create();
1701 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1702 make_scoped_refptr(new LayerWithForcedDrawsContent());
1703 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1704 make_scoped_refptr(new LayerWithForcedDrawsContent());
1705 root
->AddChild(parent
);
1706 parent
->AddChild(child1
);
1707 parent
->AddChild(child2
);
1708 child1
->AddChild(grand_child
);
1709 child2
->AddChild(leaf_node2
);
1710 grand_child
->AddChild(leaf_node1
);
1712 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1713 host
->SetRootLayer(root
);
1715 child2
->SetForceRenderSurface(true);
1717 SetLayerPropertiesForTesting(root
.get(),
1721 gfx::Size(100, 100),
1724 SetLayerPropertiesForTesting(parent
.get(),
1728 gfx::Size(100, 100),
1731 SetLayerPropertiesForTesting(child1
.get(),
1735 gfx::Size(100, 100),
1738 SetLayerPropertiesForTesting(child2
.get(),
1742 gfx::Size(100, 100),
1745 SetLayerPropertiesForTesting(grand_child
.get(),
1749 gfx::Size(100, 100),
1752 SetLayerPropertiesForTesting(leaf_node1
.get(),
1756 gfx::Size(100, 100),
1759 SetLayerPropertiesForTesting(leaf_node2
.get(),
1763 gfx::Size(100, 100),
1767 // Case 1: nothing is clipped except the root render surface.
1769 RenderSurfaceLayerList render_surface_layer_list
;
1770 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1771 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1772 inputs
.can_adjust_raster_scales
= true;
1773 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1775 ASSERT_TRUE(root
->render_surface());
1776 ASSERT_TRUE(child2
->render_surface());
1778 EXPECT_FALSE(root
->is_clipped());
1779 EXPECT_TRUE(root
->render_surface()->is_clipped());
1780 EXPECT_FALSE(parent
->is_clipped());
1781 EXPECT_FALSE(child1
->is_clipped());
1782 EXPECT_FALSE(child2
->is_clipped());
1783 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1784 EXPECT_FALSE(grand_child
->is_clipped());
1785 EXPECT_FALSE(leaf_node1
->is_clipped());
1786 EXPECT_FALSE(leaf_node2
->is_clipped());
1789 // Case 2: parent masksToBounds, so the parent, child1, and child2's
1790 // surface are clipped. But layers that contribute to child2's surface are
1791 // not clipped explicitly because child2's surface already accounts for
1794 RenderSurfaceLayerList render_surface_layer_list
;
1795 parent
->SetMasksToBounds(true);
1796 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1797 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1798 inputs
.can_adjust_raster_scales
= true;
1799 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1801 ASSERT_TRUE(root
->render_surface());
1802 ASSERT_TRUE(child2
->render_surface());
1804 EXPECT_FALSE(root
->is_clipped());
1805 EXPECT_TRUE(root
->render_surface()->is_clipped());
1806 EXPECT_TRUE(parent
->is_clipped());
1807 EXPECT_TRUE(child1
->is_clipped());
1808 EXPECT_FALSE(child2
->is_clipped());
1809 EXPECT_TRUE(child2
->render_surface()->is_clipped());
1810 EXPECT_TRUE(grand_child
->is_clipped());
1811 EXPECT_TRUE(leaf_node1
->is_clipped());
1812 EXPECT_FALSE(leaf_node2
->is_clipped());
1815 // Case 3: child2 masksToBounds. The layer and subtree are clipped, and
1816 // child2's render surface is not clipped.
1818 RenderSurfaceLayerList render_surface_layer_list
;
1819 parent
->SetMasksToBounds(false);
1820 child2
->SetMasksToBounds(true);
1821 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1822 root
.get(), parent
->bounds(), &render_surface_layer_list
);
1823 inputs
.can_adjust_raster_scales
= true;
1824 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1826 ASSERT_TRUE(root
->render_surface());
1827 ASSERT_TRUE(child2
->render_surface());
1829 EXPECT_FALSE(root
->is_clipped());
1830 EXPECT_TRUE(root
->render_surface()->is_clipped());
1831 EXPECT_FALSE(parent
->is_clipped());
1832 EXPECT_FALSE(child1
->is_clipped());
1833 EXPECT_TRUE(child2
->is_clipped());
1834 EXPECT_FALSE(child2
->render_surface()->is_clipped());
1835 EXPECT_FALSE(grand_child
->is_clipped());
1836 EXPECT_FALSE(leaf_node1
->is_clipped());
1837 EXPECT_TRUE(leaf_node2
->is_clipped());
1841 TEST_F(LayerTreeHostCommonTest
, DrawableContentRectForLayers
) {
1842 // Verify that layers get the appropriate DrawableContentRect when their
1843 // parent masksToBounds is true.
1845 // grand_child1 - completely inside the region; DrawableContentRect should
1846 // be the layer rect expressed in target space.
1847 // grand_child2 - partially clipped but NOT masksToBounds; the clip rect
1848 // will be the intersection of layer bounds and the mask region.
1849 // grand_child3 - partially clipped and masksToBounds; the
1850 // DrawableContentRect will still be the intersection of layer bounds and
1852 // grand_child4 - outside parent's clip rect; the DrawableContentRect should
1856 const gfx::Transform identity_matrix
;
1857 scoped_refptr
<Layer
> parent
= Layer::Create();
1858 scoped_refptr
<Layer
> child
= Layer::Create();
1859 scoped_refptr
<Layer
> grand_child1
= Layer::Create();
1860 scoped_refptr
<Layer
> grand_child2
= Layer::Create();
1861 scoped_refptr
<Layer
> grand_child3
= Layer::Create();
1862 scoped_refptr
<Layer
> grand_child4
= Layer::Create();
1864 parent
->AddChild(child
);
1865 child
->AddChild(grand_child1
);
1866 child
->AddChild(grand_child2
);
1867 child
->AddChild(grand_child3
);
1868 child
->AddChild(grand_child4
);
1870 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1871 host
->SetRootLayer(parent
);
1873 SetLayerPropertiesForTesting(parent
.get(),
1877 gfx::Size(500, 500),
1880 SetLayerPropertiesForTesting(child
.get(),
1887 SetLayerPropertiesForTesting(grand_child1
.get(),
1890 gfx::PointF(5.f
, 5.f
),
1894 SetLayerPropertiesForTesting(grand_child2
.get(),
1897 gfx::PointF(15.f
, 15.f
),
1901 SetLayerPropertiesForTesting(grand_child3
.get(),
1904 gfx::PointF(15.f
, 15.f
),
1908 SetLayerPropertiesForTesting(grand_child4
.get(),
1911 gfx::PointF(45.f
, 45.f
),
1916 child
->SetMasksToBounds(true);
1917 grand_child3
->SetMasksToBounds(true);
1919 // Force everyone to be a render surface.
1920 child
->SetOpacity(0.4f
);
1921 grand_child1
->SetOpacity(0.5f
);
1922 grand_child2
->SetOpacity(0.5f
);
1923 grand_child3
->SetOpacity(0.5f
);
1924 grand_child4
->SetOpacity(0.5f
);
1926 RenderSurfaceLayerList render_surface_layer_list
;
1927 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
1928 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
1929 inputs
.can_adjust_raster_scales
= true;
1930 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
1932 EXPECT_EQ(gfx::Rect(5, 5, 10, 10), grand_child1
->drawable_content_rect());
1933 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
1934 EXPECT_EQ(gfx::Rect(15, 15, 5, 5), grand_child3
->drawable_content_rect());
1935 EXPECT_TRUE(grand_child4
->drawable_content_rect().IsEmpty());
1938 TEST_F(LayerTreeHostCommonTest
, ClipRectIsPropagatedCorrectlyToSurfaces
) {
1939 // Verify that render surfaces (and their layers) get the appropriate
1940 // clip rects when their parent masksToBounds is true.
1942 // Layers that own render surfaces (at least for now) do not inherit any
1943 // clipping; instead the surface will enforce the clip for the entire subtree.
1944 // They may still have a clip rect of their own layer bounds, however, if
1945 // masksToBounds was true.
1946 const gfx::Transform identity_matrix
;
1947 scoped_refptr
<Layer
> parent
= Layer::Create();
1948 scoped_refptr
<Layer
> child
= Layer::Create();
1949 scoped_refptr
<Layer
> grand_child1
= Layer::Create();
1950 scoped_refptr
<Layer
> grand_child2
= Layer::Create();
1951 scoped_refptr
<Layer
> grand_child3
= Layer::Create();
1952 scoped_refptr
<Layer
> grand_child4
= Layer::Create();
1953 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node1
=
1954 make_scoped_refptr(new LayerWithForcedDrawsContent());
1955 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node2
=
1956 make_scoped_refptr(new LayerWithForcedDrawsContent());
1957 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node3
=
1958 make_scoped_refptr(new LayerWithForcedDrawsContent());
1959 scoped_refptr
<LayerWithForcedDrawsContent
> leaf_node4
=
1960 make_scoped_refptr(new LayerWithForcedDrawsContent());
1962 parent
->AddChild(child
);
1963 child
->AddChild(grand_child1
);
1964 child
->AddChild(grand_child2
);
1965 child
->AddChild(grand_child3
);
1966 child
->AddChild(grand_child4
);
1968 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
1969 host
->SetRootLayer(parent
);
1971 // the leaf nodes ensure that these grand_children become render surfaces for
1973 grand_child1
->AddChild(leaf_node1
);
1974 grand_child2
->AddChild(leaf_node2
);
1975 grand_child3
->AddChild(leaf_node3
);
1976 grand_child4
->AddChild(leaf_node4
);
1978 SetLayerPropertiesForTesting(parent
.get(),
1982 gfx::Size(500, 500),
1985 SetLayerPropertiesForTesting(child
.get(),
1992 SetLayerPropertiesForTesting(grand_child1
.get(),
1995 gfx::PointF(5.f
, 5.f
),
1999 SetLayerPropertiesForTesting(grand_child2
.get(),
2002 gfx::PointF(15.f
, 15.f
),
2006 SetLayerPropertiesForTesting(grand_child3
.get(),
2009 gfx::PointF(15.f
, 15.f
),
2013 SetLayerPropertiesForTesting(grand_child4
.get(),
2016 gfx::PointF(45.f
, 45.f
),
2020 SetLayerPropertiesForTesting(leaf_node1
.get(),
2027 SetLayerPropertiesForTesting(leaf_node2
.get(),
2034 SetLayerPropertiesForTesting(leaf_node3
.get(),
2041 SetLayerPropertiesForTesting(leaf_node4
.get(),
2049 child
->SetMasksToBounds(true);
2050 grand_child3
->SetMasksToBounds(true);
2051 grand_child4
->SetMasksToBounds(true);
2053 // Force everyone to be a render surface.
2054 child
->SetOpacity(0.4f
);
2055 child
->SetForceRenderSurface(true);
2056 grand_child1
->SetOpacity(0.5f
);
2057 grand_child1
->SetForceRenderSurface(true);
2058 grand_child2
->SetOpacity(0.5f
);
2059 grand_child2
->SetForceRenderSurface(true);
2060 grand_child3
->SetOpacity(0.5f
);
2061 grand_child3
->SetForceRenderSurface(true);
2062 grand_child4
->SetOpacity(0.5f
);
2063 grand_child4
->SetForceRenderSurface(true);
2065 RenderSurfaceLayerList render_surface_layer_list
;
2066 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2067 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
2068 inputs
.can_adjust_raster_scales
= true;
2069 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2070 ASSERT_TRUE(grand_child1
->render_surface());
2071 ASSERT_TRUE(grand_child2
->render_surface());
2072 ASSERT_TRUE(grand_child3
->render_surface());
2074 // Surfaces are clipped by their parent, but un-affected by the owning layer's
2076 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2077 grand_child1
->render_surface()->clip_rect());
2078 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2079 grand_child2
->render_surface()->clip_rect());
2080 EXPECT_EQ(gfx::Rect(0, 0, 20, 20),
2081 grand_child3
->render_surface()->clip_rect());
2084 TEST_F(LayerTreeHostCommonTest
, AnimationsForRenderSurfaceHierarchy
) {
2085 scoped_refptr
<Layer
> parent
= Layer::Create();
2086 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2087 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
2088 scoped_refptr
<Layer
> child_of_root
= Layer::Create();
2089 scoped_refptr
<Layer
> child_of_rs1
= Layer::Create();
2090 scoped_refptr
<Layer
> child_of_rs2
= Layer::Create();
2091 scoped_refptr
<Layer
> grand_child_of_root
= Layer::Create();
2092 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs1
=
2093 make_scoped_refptr(new LayerWithForcedDrawsContent());
2094 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child_of_rs2
=
2095 make_scoped_refptr(new LayerWithForcedDrawsContent());
2096 parent
->AddChild(render_surface1
);
2097 parent
->AddChild(child_of_root
);
2098 render_surface1
->AddChild(child_of_rs1
);
2099 render_surface1
->AddChild(render_surface2
);
2100 render_surface2
->AddChild(child_of_rs2
);
2101 child_of_root
->AddChild(grand_child_of_root
);
2102 child_of_rs1
->AddChild(grand_child_of_rs1
);
2103 child_of_rs2
->AddChild(grand_child_of_rs2
);
2105 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2106 host
->SetRootLayer(parent
);
2108 // Make our render surfaces.
2109 render_surface1
->SetForceRenderSurface(true);
2110 render_surface2
->SetForceRenderSurface(true);
2112 gfx::Transform layer_transform
;
2113 layer_transform
.Translate(1.0, 1.0);
2115 SetLayerPropertiesForTesting(parent
.get(),
2117 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2118 gfx::PointF(2.5f
, 0.f
),
2122 SetLayerPropertiesForTesting(render_surface1
.get(),
2124 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2125 gfx::PointF(2.5f
, 0.f
),
2129 SetLayerPropertiesForTesting(render_surface2
.get(),
2131 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2132 gfx::PointF(2.5f
, 0.f
),
2136 SetLayerPropertiesForTesting(child_of_root
.get(),
2138 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2139 gfx::PointF(2.5f
, 0.f
),
2143 SetLayerPropertiesForTesting(child_of_rs1
.get(),
2145 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2146 gfx::PointF(2.5f
, 0.f
),
2150 SetLayerPropertiesForTesting(child_of_rs2
.get(),
2152 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2153 gfx::PointF(2.5f
, 0.f
),
2157 SetLayerPropertiesForTesting(grand_child_of_root
.get(),
2159 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2160 gfx::PointF(2.5f
, 0.f
),
2164 SetLayerPropertiesForTesting(grand_child_of_rs1
.get(),
2166 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2167 gfx::PointF(2.5f
, 0.f
),
2171 SetLayerPropertiesForTesting(grand_child_of_rs2
.get(),
2173 gfx::Point3F(0.25f
, 0.f
, 0.f
),
2174 gfx::PointF(2.5f
, 0.f
),
2179 // Put an animated opacity on the render surface.
2180 AddOpacityTransitionToController(
2181 render_surface1
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2183 // Also put an animated opacity on a layer without descendants.
2184 AddOpacityTransitionToController(
2185 grand_child_of_root
->layer_animation_controller(), 10.0, 1.f
, 0.f
, false);
2187 // Put a transform animation on the render surface.
2188 AddAnimatedTransformToController(
2189 render_surface2
->layer_animation_controller(), 10.0, 30, 0);
2191 // Also put transform animations on grand_child_of_root, and
2192 // grand_child_of_rs2
2193 AddAnimatedTransformToController(
2194 grand_child_of_root
->layer_animation_controller(), 10.0, 30, 0);
2195 AddAnimatedTransformToController(
2196 grand_child_of_rs2
->layer_animation_controller(), 10.0, 30, 0);
2198 ExecuteCalculateDrawProperties(parent
.get());
2200 // Only layers that are associated with render surfaces should have an actual
2201 // RenderSurface() value.
2202 ASSERT_TRUE(parent
->render_surface());
2203 ASSERT_FALSE(child_of_root
->render_surface());
2204 ASSERT_FALSE(grand_child_of_root
->render_surface());
2206 ASSERT_TRUE(render_surface1
->render_surface());
2207 ASSERT_FALSE(child_of_rs1
->render_surface());
2208 ASSERT_FALSE(grand_child_of_rs1
->render_surface());
2210 ASSERT_TRUE(render_surface2
->render_surface());
2211 ASSERT_FALSE(child_of_rs2
->render_surface());
2212 ASSERT_FALSE(grand_child_of_rs2
->render_surface());
2214 // Verify all render target accessors
2215 EXPECT_EQ(parent
.get(), parent
->render_target());
2216 EXPECT_EQ(parent
.get(), child_of_root
->render_target());
2217 EXPECT_EQ(parent
.get(), grand_child_of_root
->render_target());
2219 EXPECT_EQ(render_surface1
.get(), render_surface1
->render_target());
2220 EXPECT_EQ(render_surface1
.get(), child_of_rs1
->render_target());
2221 EXPECT_EQ(render_surface1
.get(), grand_child_of_rs1
->render_target());
2223 EXPECT_EQ(render_surface2
.get(), render_surface2
->render_target());
2224 EXPECT_EQ(render_surface2
.get(), child_of_rs2
->render_target());
2225 EXPECT_EQ(render_surface2
.get(), grand_child_of_rs2
->render_target());
2227 // Verify draw_opacity_is_animating values
2228 EXPECT_FALSE(parent
->draw_opacity_is_animating());
2229 EXPECT_FALSE(child_of_root
->draw_opacity_is_animating());
2230 EXPECT_TRUE(grand_child_of_root
->draw_opacity_is_animating());
2231 EXPECT_FALSE(render_surface1
->draw_opacity_is_animating());
2232 EXPECT_TRUE(render_surface1
->render_surface()->draw_opacity_is_animating());
2233 EXPECT_FALSE(child_of_rs1
->draw_opacity_is_animating());
2234 EXPECT_FALSE(grand_child_of_rs1
->draw_opacity_is_animating());
2235 EXPECT_FALSE(render_surface2
->draw_opacity_is_animating());
2236 EXPECT_FALSE(render_surface2
->render_surface()->draw_opacity_is_animating());
2237 EXPECT_FALSE(child_of_rs2
->draw_opacity_is_animating());
2238 EXPECT_FALSE(grand_child_of_rs2
->draw_opacity_is_animating());
2240 // Verify draw_transform_is_animating values
2241 EXPECT_FALSE(parent
->draw_transform_is_animating());
2242 EXPECT_FALSE(child_of_root
->draw_transform_is_animating());
2243 EXPECT_TRUE(grand_child_of_root
->draw_transform_is_animating());
2244 EXPECT_FALSE(render_surface1
->draw_transform_is_animating());
2245 EXPECT_FALSE(render_surface1
->render_surface()
2246 ->target_surface_transforms_are_animating());
2247 EXPECT_FALSE(child_of_rs1
->draw_transform_is_animating());
2248 EXPECT_FALSE(grand_child_of_rs1
->draw_transform_is_animating());
2249 EXPECT_FALSE(render_surface2
->draw_transform_is_animating());
2250 EXPECT_TRUE(render_surface2
->render_surface()
2251 ->target_surface_transforms_are_animating());
2252 EXPECT_FALSE(child_of_rs2
->draw_transform_is_animating());
2253 EXPECT_TRUE(grand_child_of_rs2
->draw_transform_is_animating());
2255 // Verify screen_space_transform_is_animating values
2256 EXPECT_FALSE(parent
->screen_space_transform_is_animating());
2257 EXPECT_FALSE(child_of_root
->screen_space_transform_is_animating());
2258 EXPECT_TRUE(grand_child_of_root
->screen_space_transform_is_animating());
2259 EXPECT_FALSE(render_surface1
->screen_space_transform_is_animating());
2260 EXPECT_FALSE(render_surface1
->render_surface()
2261 ->screen_space_transforms_are_animating());
2262 EXPECT_FALSE(child_of_rs1
->screen_space_transform_is_animating());
2263 EXPECT_FALSE(grand_child_of_rs1
->screen_space_transform_is_animating());
2264 EXPECT_TRUE(render_surface2
->screen_space_transform_is_animating());
2265 EXPECT_TRUE(render_surface2
->render_surface()
2266 ->screen_space_transforms_are_animating());
2267 EXPECT_TRUE(child_of_rs2
->screen_space_transform_is_animating());
2268 EXPECT_TRUE(grand_child_of_rs2
->screen_space_transform_is_animating());
2270 // Sanity check. If these fail there is probably a bug in the test itself.
2271 // It is expected that we correctly set up transforms so that the y-component
2272 // of the screen-space transform encodes the "depth" of the layer in the tree.
2273 EXPECT_FLOAT_EQ(1.0, parent
->screen_space_transform().matrix().get(1, 3));
2274 EXPECT_FLOAT_EQ(2.0,
2275 child_of_root
->screen_space_transform().matrix().get(1, 3));
2277 3.0, grand_child_of_root
->screen_space_transform().matrix().get(1, 3));
2279 EXPECT_FLOAT_EQ(2.0,
2280 render_surface1
->screen_space_transform().matrix().get(1, 3));
2281 EXPECT_FLOAT_EQ(3.0,
2282 child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2284 4.0, grand_child_of_rs1
->screen_space_transform().matrix().get(1, 3));
2286 EXPECT_FLOAT_EQ(3.0,
2287 render_surface2
->screen_space_transform().matrix().get(1, 3));
2288 EXPECT_FLOAT_EQ(4.0,
2289 child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2291 5.0, grand_child_of_rs2
->screen_space_transform().matrix().get(1, 3));
2294 TEST_F(LayerTreeHostCommonTest
, VisibleRectForIdentityTransform
) {
2295 // Test the calculateVisibleRect() function works correctly for identity
2298 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2299 gfx::Transform layer_to_surface_transform
;
2301 // Case 1: Layer is contained within the surface.
2302 gfx::Rect layer_content_rect
= gfx::Rect(10, 10, 30, 30);
2303 gfx::Rect expected
= gfx::Rect(10, 10, 30, 30);
2304 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2305 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2306 EXPECT_EQ(expected
, actual
);
2308 // Case 2: Layer is outside the surface rect.
2309 layer_content_rect
= gfx::Rect(120, 120, 30, 30);
2310 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2311 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2312 EXPECT_TRUE(actual
.IsEmpty());
2314 // Case 3: Layer is partially overlapping the surface rect.
2315 layer_content_rect
= gfx::Rect(80, 80, 30, 30);
2316 expected
= gfx::Rect(80, 80, 20, 20);
2317 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2318 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2319 EXPECT_EQ(expected
, actual
);
2322 TEST_F(LayerTreeHostCommonTest
, VisibleRectForTranslations
) {
2323 // Test the calculateVisibleRect() function works correctly for scaling
2326 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2327 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2328 gfx::Transform layer_to_surface_transform
;
2330 // Case 1: Layer is contained within the surface.
2331 layer_to_surface_transform
.MakeIdentity();
2332 layer_to_surface_transform
.Translate(10.0, 10.0);
2333 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2334 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2335 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2336 EXPECT_EQ(expected
, actual
);
2338 // Case 2: Layer is outside the surface rect.
2339 layer_to_surface_transform
.MakeIdentity();
2340 layer_to_surface_transform
.Translate(120.0, 120.0);
2341 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2342 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2343 EXPECT_TRUE(actual
.IsEmpty());
2345 // Case 3: Layer is partially overlapping the surface rect.
2346 layer_to_surface_transform
.MakeIdentity();
2347 layer_to_surface_transform
.Translate(80.0, 80.0);
2348 expected
= gfx::Rect(0, 0, 20, 20);
2349 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2350 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2351 EXPECT_EQ(expected
, actual
);
2354 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor2DRotations
) {
2355 // Test the calculateVisibleRect() function works correctly for rotations
2356 // about z-axis (i.e. 2D rotations). Remember that calculateVisibleRect()
2357 // should return the g in the layer's space.
2359 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2360 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 30, 30);
2361 gfx::Transform layer_to_surface_transform
;
2363 // Case 1: Layer is contained within the surface.
2364 layer_to_surface_transform
.MakeIdentity();
2365 layer_to_surface_transform
.Translate(50.0, 50.0);
2366 layer_to_surface_transform
.Rotate(45.0);
2367 gfx::Rect expected
= gfx::Rect(0, 0, 30, 30);
2368 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2369 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2370 EXPECT_EQ(expected
, actual
);
2372 // Case 2: Layer is outside the surface rect.
2373 layer_to_surface_transform
.MakeIdentity();
2374 layer_to_surface_transform
.Translate(-50.0, 0.0);
2375 layer_to_surface_transform
.Rotate(45.0);
2376 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2377 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2378 EXPECT_TRUE(actual
.IsEmpty());
2380 // Case 3: The layer is rotated about its top-left corner. In surface space,
2381 // the layer is oriented diagonally, with the left half outside of the render
2382 // surface. In this case, the g should still be the entire layer
2383 // (remember the g is computed in layer space); both the top-left
2384 // and bottom-right corners of the layer are still visible.
2385 layer_to_surface_transform
.MakeIdentity();
2386 layer_to_surface_transform
.Rotate(45.0);
2387 expected
= gfx::Rect(0, 0, 30, 30);
2388 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2389 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2390 EXPECT_EQ(expected
, actual
);
2392 // Case 4: The layer is rotated about its top-left corner, and translated
2393 // upwards. In surface space, the layer is oriented diagonally, with only the
2394 // top corner of the surface overlapping the layer. In layer space, the render
2395 // surface overlaps the right side of the layer. The g should be
2396 // the layer's right half.
2397 layer_to_surface_transform
.MakeIdentity();
2398 layer_to_surface_transform
.Translate(0.0, -sqrt(2.0) * 15.0);
2399 layer_to_surface_transform
.Rotate(45.0);
2400 expected
= gfx::Rect(15, 0, 15, 30); // Right half of layer bounds.
2401 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2402 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2403 EXPECT_EQ(expected
, actual
);
2406 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dOrthographicTransform
) {
2407 // Test that the calculateVisibleRect() function works correctly for 3d
2410 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2411 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2412 gfx::Transform layer_to_surface_transform
;
2414 // Case 1: Orthographic projection of a layer rotated about y-axis by 45
2415 // degrees, should be fully contained in the render surface.
2416 layer_to_surface_transform
.MakeIdentity();
2417 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2418 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2419 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2420 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2421 EXPECT_EQ(expected
, actual
);
2423 // Case 2: Orthographic projection of a layer rotated about y-axis by 45
2424 // degrees, but shifted to the side so only the right-half the layer would be
2425 // visible on the surface.
2426 // 100 is the un-rotated layer width; divided by sqrt(2) is the rotated width.
2427 SkMScalar half_width_of_rotated_layer
=
2428 SkDoubleToMScalar((100.0 / sqrt(2.0)) * 0.5);
2429 layer_to_surface_transform
.MakeIdentity();
2430 layer_to_surface_transform
.Translate(-half_width_of_rotated_layer
, 0.0);
2431 layer_to_surface_transform
.RotateAboutYAxis(45.0); // Rotates about the left
2432 // edge of the layer.
2433 expected
= gfx::Rect(50, 0, 50, 100); // Tight half of the layer.
2434 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2435 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2436 EXPECT_EQ(expected
, actual
);
2439 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveTransform
) {
2440 // Test the calculateVisibleRect() function works correctly when the layer has
2441 // a perspective projection onto the target surface.
2443 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2444 gfx::Rect layer_content_rect
= gfx::Rect(-50, -50, 200, 200);
2445 gfx::Transform layer_to_surface_transform
;
2447 // Case 1: Even though the layer is twice as large as the surface, due to
2448 // perspective foreshortening, the layer will fit fully in the surface when
2449 // its translated more than the perspective amount.
2450 layer_to_surface_transform
.MakeIdentity();
2452 // The following sequence of transforms applies the perspective about the
2453 // center of the surface.
2454 layer_to_surface_transform
.Translate(50.0, 50.0);
2455 layer_to_surface_transform
.ApplyPerspectiveDepth(9.0);
2456 layer_to_surface_transform
.Translate(-50.0, -50.0);
2458 // This translate places the layer in front of the surface's projection plane.
2459 layer_to_surface_transform
.Translate3d(0.0, 0.0, -27.0);
2461 gfx::Rect expected
= gfx::Rect(-50, -50, 200, 200);
2462 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2463 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2464 EXPECT_EQ(expected
, actual
);
2466 // Case 2: same projection as before, except that the layer is also translated
2467 // to the side, so that only the right half of the layer should be visible.
2469 // Explanation of expected result: The perspective ratio is (z distance
2470 // between layer and camera origin) / (z distance between projection plane and
2471 // camera origin) == ((-27 - 9) / 9) Then, by similar triangles, if we want to
2472 // move a layer by translating -50 units in projected surface units (so that
2473 // only half of it is visible), then we would need to translate by (-36 / 9) *
2474 // -50 == -200 in the layer's units.
2475 layer_to_surface_transform
.Translate3d(-200.0, 0.0, 0.0);
2476 expected
= gfx::Rect(gfx::Point(50, -50),
2477 gfx::Size(100, 200)); // The right half of the layer's
2479 actual
= LayerTreeHostCommon::CalculateVisibleRect(
2480 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2481 EXPECT_EQ(expected
, actual
);
2484 TEST_F(LayerTreeHostCommonTest
,
2485 VisibleRectFor3dOrthographicIsNotClippedBehindSurface
) {
2486 // There is currently no explicit concept of an orthographic projection plane
2487 // in our code (nor in the CSS spec to my knowledge). Therefore, layers that
2488 // are technically behind the surface in an orthographic world should not be
2489 // clipped when they are flattened to the surface.
2491 gfx::Rect target_surface_rect
= gfx::Rect(0, 0, 100, 100);
2492 gfx::Rect layer_content_rect
= gfx::Rect(0, 0, 100, 100);
2493 gfx::Transform layer_to_surface_transform
;
2495 // This sequence of transforms effectively rotates the layer about the y-axis
2496 // at the center of the layer.
2497 layer_to_surface_transform
.MakeIdentity();
2498 layer_to_surface_transform
.Translate(50.0, 0.0);
2499 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2500 layer_to_surface_transform
.Translate(-50.0, 0.0);
2502 gfx::Rect expected
= gfx::Rect(0, 0, 100, 100);
2503 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2504 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2505 EXPECT_EQ(expected
, actual
);
2508 TEST_F(LayerTreeHostCommonTest
, VisibleRectFor3dPerspectiveWhenClippedByW
) {
2509 // Test the calculateVisibleRect() function works correctly when projecting a
2510 // surface onto a layer, but the layer is partially behind the camera (not
2511 // just behind the projection plane). In this case, the cartesian coordinates
2512 // may seem to be valid, but actually they are not. The visible rect needs to
2513 // be properly clipped by the w = 0 plane in homogeneous coordinates before
2514 // converting to cartesian coordinates.
2516 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2517 gfx::Rect layer_content_rect
= gfx::Rect(-10, -1, 20, 2);
2518 gfx::Transform layer_to_surface_transform
;
2520 // The layer is positioned so that the right half of the layer should be in
2521 // front of the camera, while the other half is behind the surface's
2522 // projection plane. The following sequence of transforms applies the
2523 // perspective and rotation about the center of the layer.
2524 layer_to_surface_transform
.MakeIdentity();
2525 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2526 layer_to_surface_transform
.Translate3d(-2.0, 0.0, 1.0);
2527 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2529 // Sanity check that this transform does indeed cause w < 0 when applying the
2530 // transform, otherwise this code is not testing the intended scenario.
2532 MathUtil::MapQuad(layer_to_surface_transform
,
2533 gfx::QuadF(gfx::RectF(layer_content_rect
)),
2535 ASSERT_TRUE(clipped
);
2537 int expected_x_position
= 0;
2538 int expected_width
= 10;
2539 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2540 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2541 EXPECT_EQ(expected_x_position
, actual
.x());
2542 EXPECT_EQ(expected_width
, actual
.width());
2545 TEST_F(LayerTreeHostCommonTest
, VisibleRectForPerspectiveUnprojection
) {
2546 // To determine visible rect in layer space, there needs to be an
2547 // un-projection from surface space to layer space. When the original
2548 // transform was a perspective projection that was clipped, it returns a rect
2549 // that encloses the clipped bounds. Un-projecting this new rect may require
2552 // This sequence of transforms causes one corner of the layer to protrude
2553 // across the w = 0 plane, and should be clipped.
2554 gfx::Rect target_surface_rect
= gfx::Rect(-50, -50, 100, 100);
2555 gfx::Rect layer_content_rect
= gfx::Rect(-10, -10, 20, 20);
2556 gfx::Transform layer_to_surface_transform
;
2557 layer_to_surface_transform
.MakeIdentity();
2558 layer_to_surface_transform
.ApplyPerspectiveDepth(1.0);
2559 layer_to_surface_transform
.Translate3d(0.0, 0.0, -5.0);
2560 layer_to_surface_transform
.RotateAboutYAxis(45.0);
2561 layer_to_surface_transform
.RotateAboutXAxis(80.0);
2563 // Sanity check that un-projection does indeed cause w < 0, otherwise this
2564 // code is not testing the intended scenario.
2566 gfx::RectF clipped_rect
=
2567 MathUtil::MapClippedRect(layer_to_surface_transform
, layer_content_rect
);
2568 MathUtil::ProjectQuad(
2569 Inverse(layer_to_surface_transform
), gfx::QuadF(clipped_rect
), &clipped
);
2570 ASSERT_TRUE(clipped
);
2572 // Only the corner of the layer is not visible on the surface because of being
2573 // clipped. But, the net result of rounding visible region to an axis-aligned
2574 // rect is that the entire layer should still be considered visible.
2575 gfx::Rect expected
= gfx::Rect(-10, -10, 20, 20);
2576 gfx::Rect actual
= LayerTreeHostCommon::CalculateVisibleRect(
2577 target_surface_rect
, layer_content_rect
, layer_to_surface_transform
);
2578 EXPECT_EQ(expected
, actual
);
2581 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsForSimpleLayers
) {
2582 scoped_refptr
<Layer
> root
= Layer::Create();
2583 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2584 make_scoped_refptr(new LayerWithForcedDrawsContent());
2585 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2586 make_scoped_refptr(new LayerWithForcedDrawsContent());
2587 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2588 make_scoped_refptr(new LayerWithForcedDrawsContent());
2589 root
->AddChild(child1
);
2590 root
->AddChild(child2
);
2591 root
->AddChild(child3
);
2593 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2594 host
->SetRootLayer(root
);
2596 gfx::Transform identity_matrix
;
2597 SetLayerPropertiesForTesting(root
.get(),
2601 gfx::Size(100, 100),
2604 SetLayerPropertiesForTesting(child1
.get(),
2611 SetLayerPropertiesForTesting(child2
.get(),
2614 gfx::PointF(75.f
, 75.f
),
2618 SetLayerPropertiesForTesting(child3
.get(),
2621 gfx::PointF(125.f
, 125.f
),
2626 ExecuteCalculateDrawProperties(root
.get());
2628 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2629 root
->render_surface()->DrawableContentRect());
2630 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2632 // Layers that do not draw content should have empty visible_content_rects.
2633 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2635 // layer visible_content_rects are clipped by their target surface.
2636 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
2637 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_content_rect());
2638 EXPECT_TRUE(child3
->visible_content_rect().IsEmpty());
2640 // layer drawable_content_rects are not clipped.
2641 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->drawable_content_rect());
2642 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2643 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2646 TEST_F(LayerTreeHostCommonTest
,
2647 DrawableAndVisibleContentRectsForLayersClippedByLayer
) {
2648 scoped_refptr
<Layer
> root
= Layer::Create();
2649 scoped_refptr
<Layer
> child
= Layer::Create();
2650 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child1
=
2651 make_scoped_refptr(new LayerWithForcedDrawsContent());
2652 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child2
=
2653 make_scoped_refptr(new LayerWithForcedDrawsContent());
2654 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child3
=
2655 make_scoped_refptr(new LayerWithForcedDrawsContent());
2656 root
->AddChild(child
);
2657 child
->AddChild(grand_child1
);
2658 child
->AddChild(grand_child2
);
2659 child
->AddChild(grand_child3
);
2661 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2662 host
->SetRootLayer(root
);
2664 gfx::Transform identity_matrix
;
2665 SetLayerPropertiesForTesting(root
.get(),
2669 gfx::Size(100, 100),
2672 SetLayerPropertiesForTesting(child
.get(),
2676 gfx::Size(100, 100),
2679 SetLayerPropertiesForTesting(grand_child1
.get(),
2682 gfx::PointF(5.f
, 5.f
),
2686 SetLayerPropertiesForTesting(grand_child2
.get(),
2689 gfx::PointF(75.f
, 75.f
),
2693 SetLayerPropertiesForTesting(grand_child3
.get(),
2696 gfx::PointF(125.f
, 125.f
),
2701 child
->SetMasksToBounds(true);
2702 ExecuteCalculateDrawProperties(root
.get());
2704 ASSERT_FALSE(child
->render_surface());
2706 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2707 root
->render_surface()->DrawableContentRect());
2708 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2710 // Layers that do not draw content should have empty visible content rects.
2711 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2712 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), child
->visible_content_rect());
2714 // All grandchild visible content rects should be clipped by child.
2715 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), grand_child1
->visible_content_rect());
2716 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), grand_child2
->visible_content_rect());
2717 EXPECT_TRUE(grand_child3
->visible_content_rect().IsEmpty());
2719 // All grandchild DrawableContentRects should also be clipped by child.
2720 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), grand_child1
->drawable_content_rect());
2721 EXPECT_EQ(gfx::Rect(75, 75, 25, 25), grand_child2
->drawable_content_rect());
2722 EXPECT_TRUE(grand_child3
->drawable_content_rect().IsEmpty());
2725 TEST_F(LayerTreeHostCommonTest
,
2726 DrawableAndVisibleContentRectsForLayersInUnclippedRenderSurface
) {
2727 scoped_refptr
<Layer
> root
= Layer::Create();
2728 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
2729 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2730 make_scoped_refptr(new LayerWithForcedDrawsContent());
2731 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2732 make_scoped_refptr(new LayerWithForcedDrawsContent());
2733 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2734 make_scoped_refptr(new LayerWithForcedDrawsContent());
2735 root
->AddChild(render_surface1
);
2736 render_surface1
->AddChild(child1
);
2737 render_surface1
->AddChild(child2
);
2738 render_surface1
->AddChild(child3
);
2740 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2741 host
->SetRootLayer(root
);
2743 gfx::Transform identity_matrix
;
2744 SetLayerPropertiesForTesting(root
.get(),
2748 gfx::Size(100, 100),
2751 SetLayerPropertiesForTesting(render_surface1
.get(),
2758 SetLayerPropertiesForTesting(child1
.get(),
2761 gfx::PointF(5.f
, 5.f
),
2765 SetLayerPropertiesForTesting(child2
.get(),
2768 gfx::PointF(75.f
, 75.f
),
2772 SetLayerPropertiesForTesting(child3
.get(),
2775 gfx::PointF(125.f
, 125.f
),
2780 render_surface1
->SetForceRenderSurface(true);
2781 ExecuteCalculateDrawProperties(root
.get());
2783 ASSERT_TRUE(render_surface1
->render_surface());
2785 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
2786 root
->render_surface()->DrawableContentRect());
2787 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
2789 // Layers that do not draw content should have empty visible content rects.
2790 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
2791 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_content_rect());
2793 // An unclipped surface grows its DrawableContentRect to include all drawable
2794 // regions of the subtree.
2795 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
2796 render_surface1
->render_surface()->DrawableContentRect());
2798 // All layers that draw content into the unclipped surface are also unclipped.
2799 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
2800 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
2801 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
2803 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
2804 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
2805 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
2808 TEST_F(LayerTreeHostCommonTest
,
2809 VisibleContentRectsForClippedSurfaceWithEmptyClip
) {
2810 scoped_refptr
<Layer
> root
= Layer::Create();
2811 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
2812 make_scoped_refptr(new LayerWithForcedDrawsContent());
2813 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
2814 make_scoped_refptr(new LayerWithForcedDrawsContent());
2815 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
2816 make_scoped_refptr(new LayerWithForcedDrawsContent());
2817 root
->AddChild(child1
);
2818 root
->AddChild(child2
);
2819 root
->AddChild(child3
);
2821 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2822 host
->SetRootLayer(root
);
2824 gfx::Transform identity_matrix
;
2825 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
2826 gfx::PointF(), gfx::Size(100, 100), true, false);
2827 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
, gfx::Point3F(),
2828 gfx::PointF(5.f
, 5.f
), gfx::Size(50, 50), true,
2830 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
, gfx::Point3F(),
2831 gfx::PointF(75.f
, 75.f
), gfx::Size(50, 50), true,
2833 SetLayerPropertiesForTesting(child3
.get(), identity_matrix
, gfx::Point3F(),
2834 gfx::PointF(125.f
, 125.f
), gfx::Size(50, 50),
2837 RenderSurfaceLayerList render_surface_layer_list
;
2838 // Now set the root render surface an empty clip.
2839 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
2840 root
.get(), gfx::Size(), &render_surface_layer_list
);
2842 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
2843 ASSERT_TRUE(root
->render_surface());
2844 EXPECT_FALSE(root
->is_clipped());
2847 EXPECT_EQ(empty
, root
->render_surface()->clip_rect());
2848 EXPECT_TRUE(root
->render_surface()->is_clipped());
2850 // Visible content rect calculation will check if the target surface is
2851 // clipped or not. An empty clip rect does not indicate the render surface
2853 EXPECT_EQ(empty
, child1
->visible_content_rect());
2854 EXPECT_EQ(empty
, child2
->visible_content_rect());
2855 EXPECT_EQ(empty
, child3
->visible_content_rect());
2858 TEST_F(LayerTreeHostCommonTest
,
2859 DrawableAndVisibleContentRectsForLayersWithUninvertibleTransform
) {
2860 scoped_refptr
<Layer
> root
= Layer::Create();
2861 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2862 make_scoped_refptr(new LayerWithForcedDrawsContent());
2863 root
->AddChild(child
);
2865 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2866 host
->SetRootLayer(root
);
2868 // Case 1: a truly degenerate matrix
2869 gfx::Transform identity_matrix
;
2870 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2871 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2873 SetLayerPropertiesForTesting(root
.get(),
2877 gfx::Size(100, 100),
2880 SetLayerPropertiesForTesting(child
.get(),
2881 uninvertible_matrix
,
2883 gfx::PointF(5.f
, 5.f
),
2888 ExecuteCalculateDrawProperties(root
.get());
2890 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2891 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2893 // Case 2: a matrix with flattened z, uninvertible and not visible according
2895 uninvertible_matrix
.MakeIdentity();
2896 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2897 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2899 SetLayerPropertiesForTesting(child
.get(),
2900 uninvertible_matrix
,
2902 gfx::PointF(5.f
, 5.f
),
2907 ExecuteCalculateDrawProperties(root
.get());
2909 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2910 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2912 // Case 3: a matrix with flattened z, also uninvertible and not visible.
2913 uninvertible_matrix
.MakeIdentity();
2914 uninvertible_matrix
.Translate(500.0, 0.0);
2915 uninvertible_matrix
.matrix().set(2, 2, 0.0);
2916 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2918 SetLayerPropertiesForTesting(child
.get(),
2919 uninvertible_matrix
,
2921 gfx::PointF(5.f
, 5.f
),
2926 ExecuteCalculateDrawProperties(root
.get());
2928 EXPECT_TRUE(child
->visible_content_rect().IsEmpty());
2929 EXPECT_TRUE(child
->drawable_content_rect().IsEmpty());
2932 TEST_F(LayerTreeHostCommonTest
,
2933 SingularTransformDoesNotPreventClearingDrawProperties
) {
2934 scoped_refptr
<Layer
> root
= Layer::Create();
2935 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
2936 make_scoped_refptr(new LayerWithForcedDrawsContent());
2937 root
->AddChild(child
);
2939 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2940 host
->SetRootLayer(root
);
2942 gfx::Transform identity_matrix
;
2943 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2944 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2946 SetLayerPropertiesForTesting(root
.get(),
2947 uninvertible_matrix
,
2950 gfx::Size(100, 100),
2953 SetLayerPropertiesForTesting(child
.get(),
2956 gfx::PointF(5.f
, 5.f
),
2961 child
->draw_properties().sorted_for_recursion
= true;
2963 TransformOperations start_transform_operations
;
2964 start_transform_operations
.AppendScale(1.f
, 0.f
, 0.f
);
2966 TransformOperations end_transform_operations
;
2967 end_transform_operations
.AppendScale(1.f
, 1.f
, 0.f
);
2969 AddAnimatedTransformToLayer(
2970 root
.get(), 10.0, start_transform_operations
, end_transform_operations
);
2972 EXPECT_TRUE(root
->TransformIsAnimating());
2974 ExecuteCalculateDrawProperties(root
.get());
2976 EXPECT_FALSE(child
->draw_properties().sorted_for_recursion
);
2979 TEST_F(LayerTreeHostCommonTest
,
2980 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties
) {
2981 scoped_refptr
<Layer
> root
= Layer::Create();
2983 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
2984 host
->SetRootLayer(root
);
2986 gfx::Transform identity_matrix
;
2987 gfx::Transform
uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
2988 ASSERT_FALSE(uninvertible_matrix
.IsInvertible());
2990 SetLayerPropertiesForTesting(root
.get(),
2991 uninvertible_matrix
,
2994 gfx::Size(100, 100),
2998 root
->draw_properties().sorted_for_recursion
= true;
3000 EXPECT_FALSE(root
->TransformIsAnimating());
3002 ExecuteCalculateDrawProperties(root
.get());
3004 EXPECT_FALSE(root
->draw_properties().sorted_for_recursion
);
3007 TEST_F(LayerTreeHostCommonTest
,
3008 DrawableAndVisibleContentRectsForLayersInClippedRenderSurface
) {
3009 scoped_refptr
<Layer
> root
= Layer::Create();
3010 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3011 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3012 make_scoped_refptr(new LayerWithForcedDrawsContent());
3013 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3014 make_scoped_refptr(new LayerWithForcedDrawsContent());
3015 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
3016 make_scoped_refptr(new LayerWithForcedDrawsContent());
3017 root
->AddChild(render_surface1
);
3018 render_surface1
->AddChild(child1
);
3019 render_surface1
->AddChild(child2
);
3020 render_surface1
->AddChild(child3
);
3022 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3023 host
->SetRootLayer(root
);
3025 gfx::Transform identity_matrix
;
3026 SetLayerPropertiesForTesting(root
.get(),
3030 gfx::Size(100, 100),
3033 SetLayerPropertiesForTesting(render_surface1
.get(),
3040 SetLayerPropertiesForTesting(child1
.get(),
3043 gfx::PointF(5.f
, 5.f
),
3047 SetLayerPropertiesForTesting(child2
.get(),
3050 gfx::PointF(75.f
, 75.f
),
3054 SetLayerPropertiesForTesting(child3
.get(),
3057 gfx::PointF(125.f
, 125.f
),
3062 root
->SetMasksToBounds(true);
3063 render_surface1
->SetForceRenderSurface(true);
3064 ExecuteCalculateDrawProperties(root
.get());
3066 ASSERT_TRUE(render_surface1
->render_surface());
3068 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3069 root
->render_surface()->DrawableContentRect());
3070 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3072 // Layers that do not draw content should have empty visible content rects.
3073 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3074 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_content_rect());
3076 // A clipped surface grows its DrawableContentRect to include all drawable
3077 // regions of the subtree, but also gets clamped by the ancestor's clip.
3078 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3079 render_surface1
->render_surface()->DrawableContentRect());
3081 // All layers that draw content into the surface have their visible content
3082 // rect clipped by the surface clip rect.
3083 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3084 EXPECT_EQ(gfx::Rect(0, 0, 25, 25), child2
->visible_content_rect());
3085 EXPECT_TRUE(child3
->visible_content_rect().IsEmpty());
3087 // But the DrawableContentRects are unclipped.
3088 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3089 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3090 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3093 TEST_F(LayerTreeHostCommonTest
,
3094 DrawableAndVisibleContentRectsForSurfaceHierarchy
) {
3095 // Check that clipping does not propagate down surfaces.
3096 scoped_refptr
<Layer
> root
= Layer::Create();
3097 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3098 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
3099 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3100 make_scoped_refptr(new LayerWithForcedDrawsContent());
3101 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3102 make_scoped_refptr(new LayerWithForcedDrawsContent());
3103 scoped_refptr
<LayerWithForcedDrawsContent
> child3
=
3104 make_scoped_refptr(new LayerWithForcedDrawsContent());
3105 root
->AddChild(render_surface1
);
3106 render_surface1
->AddChild(render_surface2
);
3107 render_surface2
->AddChild(child1
);
3108 render_surface2
->AddChild(child2
);
3109 render_surface2
->AddChild(child3
);
3111 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3112 host
->SetRootLayer(root
);
3114 gfx::Transform identity_matrix
;
3115 SetLayerPropertiesForTesting(root
.get(),
3119 gfx::Size(100, 100),
3122 SetLayerPropertiesForTesting(render_surface1
.get(),
3129 SetLayerPropertiesForTesting(render_surface2
.get(),
3136 SetLayerPropertiesForTesting(child1
.get(),
3139 gfx::PointF(5.f
, 5.f
),
3143 SetLayerPropertiesForTesting(child2
.get(),
3146 gfx::PointF(75.f
, 75.f
),
3150 SetLayerPropertiesForTesting(child3
.get(),
3153 gfx::PointF(125.f
, 125.f
),
3158 root
->SetMasksToBounds(true);
3159 render_surface1
->SetForceRenderSurface(true);
3160 render_surface2
->SetForceRenderSurface(true);
3161 ExecuteCalculateDrawProperties(root
.get());
3163 ASSERT_TRUE(render_surface1
->render_surface());
3164 ASSERT_TRUE(render_surface2
->render_surface());
3166 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3167 root
->render_surface()->DrawableContentRect());
3168 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3170 // Layers that do not draw content should have empty visible content rects.
3171 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3172 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_content_rect());
3173 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface2
->visible_content_rect());
3175 // A clipped surface grows its DrawableContentRect to include all drawable
3176 // regions of the subtree, but also gets clamped by the ancestor's clip.
3177 EXPECT_EQ(gfx::Rect(5, 5, 95, 95),
3178 render_surface1
->render_surface()->DrawableContentRect());
3180 // render_surface1 lives in the "unclipped universe" of render_surface1, and
3181 // is only implicitly clipped by render_surface1's content rect. So,
3182 // render_surface2 grows to enclose all drawable content of its subtree.
3183 EXPECT_EQ(gfx::Rect(5, 5, 170, 170),
3184 render_surface2
->render_surface()->DrawableContentRect());
3186 // All layers that draw content into render_surface2 think they are unclipped.
3187 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3188 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
3189 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
3191 // DrawableContentRects are also unclipped.
3192 EXPECT_EQ(gfx::Rect(5, 5, 50, 50), child1
->drawable_content_rect());
3193 EXPECT_EQ(gfx::Rect(75, 75, 50, 50), child2
->drawable_content_rect());
3194 EXPECT_EQ(gfx::Rect(125, 125, 50, 50), child3
->drawable_content_rect());
3197 TEST_F(LayerTreeHostCommonTest
,
3198 DrawableAndVisibleContentRectsWithTransformOnUnclippedSurface
) {
3199 // Layers that have non-axis aligned bounds (due to transforms) have an
3200 // expanded, axis-aligned DrawableContentRect and visible content rect.
3202 scoped_refptr
<Layer
> root
= Layer::Create();
3203 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3204 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3205 make_scoped_refptr(new LayerWithForcedDrawsContent());
3206 root
->AddChild(render_surface1
);
3207 render_surface1
->AddChild(child1
);
3209 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3210 host
->SetRootLayer(root
);
3212 gfx::Transform identity_matrix
;
3213 gfx::Transform child_rotation
;
3214 child_rotation
.Rotate(45.0);
3215 SetLayerPropertiesForTesting(root
.get(),
3219 gfx::Size(100, 100),
3222 SetLayerPropertiesForTesting(render_surface1
.get(),
3229 SetLayerPropertiesForTesting(child1
.get(),
3231 gfx::Point3F(25, 25, 0.f
),
3232 gfx::PointF(25.f
, 25.f
),
3237 render_surface1
->SetForceRenderSurface(true);
3238 ExecuteCalculateDrawProperties(root
.get());
3240 ASSERT_TRUE(render_surface1
->render_surface());
3242 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
3243 root
->render_surface()->DrawableContentRect());
3244 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), root
->drawable_content_rect());
3246 // Layers that do not draw content should have empty visible content rects.
3247 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3248 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), render_surface1
->visible_content_rect());
3250 // The unclipped surface grows its DrawableContentRect to include all drawable
3251 // regions of the subtree.
3252 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3253 gfx::Rect expected_surface_drawable_content
=
3254 gfx::Rect(50 - diagonal_radius
,
3255 50 - diagonal_radius
,
3256 diagonal_radius
* 2,
3257 diagonal_radius
* 2);
3258 EXPECT_EQ(expected_surface_drawable_content
,
3259 render_surface1
->render_surface()->DrawableContentRect());
3261 // All layers that draw content into the unclipped surface are also unclipped.
3262 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3263 EXPECT_EQ(expected_surface_drawable_content
, child1
->drawable_content_rect());
3266 TEST_F(LayerTreeHostCommonTest
,
3267 DrawableAndVisibleContentRectsWithTransformOnClippedSurface
) {
3268 // Layers that have non-axis aligned bounds (due to transforms) have an
3269 // expanded, axis-aligned DrawableContentRect and visible content rect.
3271 scoped_refptr
<Layer
> root
= Layer::Create();
3272 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
3273 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3274 make_scoped_refptr(new LayerWithForcedDrawsContent());
3275 root
->AddChild(render_surface1
);
3276 render_surface1
->AddChild(child1
);
3278 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3279 host
->SetRootLayer(root
);
3281 gfx::Transform identity_matrix
;
3282 gfx::Transform child_rotation
;
3283 child_rotation
.Rotate(45.0);
3284 SetLayerPropertiesForTesting(root
.get(),
3291 SetLayerPropertiesForTesting(render_surface1
.get(),
3299 SetLayerPropertiesForTesting(child1
.get(),
3301 gfx::Point3F(25, 25, 0.f
),
3302 gfx::PointF(25.f
, 25.f
),
3307 root
->SetMasksToBounds(true);
3308 render_surface1
->SetForceRenderSurface(true);
3309 ExecuteCalculateDrawProperties(root
.get());
3311 ASSERT_TRUE(render_surface1
->render_surface());
3313 // The clipped surface clamps the DrawableContentRect that encloses the
3315 int diagonal_radius
= ceil(sqrt(2.0) * 25.0);
3316 gfx::Rect unclipped_surface_content
= gfx::Rect(50 - diagonal_radius
,
3317 50 - diagonal_radius
,
3318 diagonal_radius
* 2,
3319 diagonal_radius
* 2);
3320 gfx::Rect expected_surface_drawable_content
=
3321 gfx::IntersectRects(unclipped_surface_content
, gfx::Rect(0, 0, 50, 50));
3322 EXPECT_EQ(expected_surface_drawable_content
,
3323 render_surface1
->render_surface()->DrawableContentRect());
3325 // On the clipped surface, only a quarter of the child1 is visible, but when
3326 // rotating it back to child1's content space, the actual enclosing rect ends
3327 // up covering the full left half of child1.
3329 // Given the floating point math, this number is a little bit fuzzy.
3330 EXPECT_EQ(gfx::Rect(0, 0, 26, 50), child1
->visible_content_rect());
3332 // The child's DrawableContentRect is unclipped.
3333 EXPECT_EQ(unclipped_surface_content
, child1
->drawable_content_rect());
3336 TEST_F(LayerTreeHostCommonTest
, DrawableAndVisibleContentRectsInHighDPI
) {
3337 MockContentLayerClient client
;
3339 scoped_refptr
<Layer
> root
= Layer::Create();
3340 scoped_refptr
<FakePictureLayer
> render_surface1
=
3341 CreateDrawablePictureLayer(&client
);
3342 scoped_refptr
<FakePictureLayer
> render_surface2
=
3343 CreateDrawablePictureLayer(&client
);
3344 scoped_refptr
<FakePictureLayer
> child1
= CreateDrawablePictureLayer(&client
);
3345 scoped_refptr
<FakePictureLayer
> child2
= CreateDrawablePictureLayer(&client
);
3346 scoped_refptr
<FakePictureLayer
> child3
= CreateDrawablePictureLayer(&client
);
3347 root
->AddChild(render_surface1
);
3348 render_surface1
->AddChild(render_surface2
);
3349 render_surface2
->AddChild(child1
);
3350 render_surface2
->AddChild(child2
);
3351 render_surface2
->AddChild(child3
);
3353 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3354 host
->SetRootLayer(root
);
3356 gfx::Transform identity_matrix
;
3357 SetLayerPropertiesForTesting(root
.get(),
3361 gfx::Size(100, 100),
3364 SetLayerPropertiesForTesting(render_surface1
.get(),
3367 gfx::PointF(5.f
, 5.f
),
3371 SetLayerPropertiesForTesting(render_surface2
.get(),
3374 gfx::PointF(5.f
, 5.f
),
3378 SetLayerPropertiesForTesting(child1
.get(),
3381 gfx::PointF(5.f
, 5.f
),
3385 SetLayerPropertiesForTesting(child2
.get(),
3388 gfx::PointF(75.f
, 75.f
),
3392 SetLayerPropertiesForTesting(child3
.get(),
3395 gfx::PointF(125.f
, 125.f
),
3400 float device_scale_factor
= 2.f
;
3402 root
->SetMasksToBounds(true);
3403 render_surface1
->SetForceRenderSurface(true);
3404 render_surface2
->SetForceRenderSurface(true);
3405 ExecuteCalculateDrawProperties(root
.get(), device_scale_factor
);
3407 ASSERT_TRUE(render_surface1
->render_surface());
3408 ASSERT_TRUE(render_surface2
->render_surface());
3410 // drawable_content_rects for all layers and surfaces are scaled by
3411 // device_scale_factor.
3412 EXPECT_EQ(gfx::Rect(0, 0, 200, 200),
3413 root
->render_surface()->DrawableContentRect());
3414 EXPECT_EQ(gfx::Rect(0, 0, 200, 200), root
->drawable_content_rect());
3415 EXPECT_EQ(gfx::Rect(10, 10, 190, 190),
3416 render_surface1
->render_surface()->DrawableContentRect());
3418 // render_surface2 lives in the "unclipped universe" of render_surface1, and
3419 // is only implicitly clipped by render_surface1.
3420 EXPECT_EQ(gfx::Rect(10, 10, 350, 350),
3421 render_surface2
->render_surface()->DrawableContentRect());
3423 EXPECT_EQ(gfx::Rect(10, 10, 100, 100), child1
->drawable_content_rect());
3424 EXPECT_EQ(gfx::Rect(150, 150, 100, 100), child2
->drawable_content_rect());
3425 EXPECT_EQ(gfx::Rect(250, 250, 100, 100), child3
->drawable_content_rect());
3427 // The root layer does not actually draw content of its own.
3428 EXPECT_EQ(gfx::Rect(0, 0, 0, 0), root
->visible_content_rect());
3430 // All layer visible content rects are not expressed in content space of each
3431 // layer, so they are not scaled by the device_scale_factor.
3432 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), render_surface1
->visible_content_rect());
3433 EXPECT_EQ(gfx::Rect(0, 0, 7, 13), render_surface2
->visible_content_rect());
3434 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child1
->visible_content_rect());
3435 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child2
->visible_content_rect());
3436 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), child3
->visible_content_rect());
3439 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithoutPreserves3d
) {
3440 // Verify the behavior of back-face culling when there are no preserve-3d
3441 // layers. Note that 3d transforms still apply in this case, but they are
3442 // "flattened" to each parent layer according to current W3C spec.
3444 const gfx::Transform identity_matrix
;
3445 scoped_refptr
<Layer
> parent
= Layer::Create();
3446 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3447 make_scoped_refptr(new LayerWithForcedDrawsContent());
3448 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3449 make_scoped_refptr(new LayerWithForcedDrawsContent());
3450 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3451 make_scoped_refptr(new LayerWithForcedDrawsContent());
3452 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3453 make_scoped_refptr(new LayerWithForcedDrawsContent());
3454 scoped_refptr
<LayerWithForcedDrawsContent
>
3455 front_facing_child_of_front_facing_surface
=
3456 make_scoped_refptr(new LayerWithForcedDrawsContent());
3457 scoped_refptr
<LayerWithForcedDrawsContent
>
3458 back_facing_child_of_front_facing_surface
=
3459 make_scoped_refptr(new LayerWithForcedDrawsContent());
3460 scoped_refptr
<LayerWithForcedDrawsContent
>
3461 front_facing_child_of_back_facing_surface
=
3462 make_scoped_refptr(new LayerWithForcedDrawsContent());
3463 scoped_refptr
<LayerWithForcedDrawsContent
>
3464 back_facing_child_of_back_facing_surface
=
3465 make_scoped_refptr(new LayerWithForcedDrawsContent());
3467 parent
->AddChild(front_facing_child
);
3468 parent
->AddChild(back_facing_child
);
3469 parent
->AddChild(front_facing_surface
);
3470 parent
->AddChild(back_facing_surface
);
3471 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3472 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3473 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3474 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3476 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3477 host
->SetRootLayer(parent
);
3479 // Nothing is double-sided
3480 front_facing_child
->SetDoubleSided(false);
3481 back_facing_child
->SetDoubleSided(false);
3482 front_facing_surface
->SetDoubleSided(false);
3483 back_facing_surface
->SetDoubleSided(false);
3484 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3485 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3486 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3487 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3489 gfx::Transform backface_matrix
;
3490 backface_matrix
.Translate(50.0, 50.0);
3491 backface_matrix
.RotateAboutYAxis(180.0);
3492 backface_matrix
.Translate(-50.0, -50.0);
3494 // Having a descendant and opacity will force these to have render surfaces.
3495 front_facing_surface
->SetOpacity(0.5f
);
3496 back_facing_surface
->SetOpacity(0.5f
);
3498 // Nothing preserves 3d. According to current W3C CSS gfx::Transforms spec,
3499 // these layers should blindly use their own local transforms to determine
3500 // back-face culling.
3501 SetLayerPropertiesForTesting(parent
.get(),
3505 gfx::Size(100, 100),
3508 SetLayerPropertiesForTesting(front_facing_child
.get(),
3512 gfx::Size(100, 100),
3515 SetLayerPropertiesForTesting(back_facing_child
.get(),
3519 gfx::Size(100, 100),
3522 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3526 gfx::Size(100, 100),
3529 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3533 gfx::Size(100, 100),
3536 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3540 gfx::Size(100, 100),
3543 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3547 gfx::Size(100, 100),
3550 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3554 gfx::Size(100, 100),
3557 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3561 gfx::Size(100, 100),
3565 RenderSurfaceLayerList render_surface_layer_list
;
3566 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3567 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3568 inputs
.can_adjust_raster_scales
= true;
3569 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3571 // Verify which render surfaces were created.
3572 EXPECT_FALSE(front_facing_child
->render_surface());
3573 EXPECT_FALSE(back_facing_child
->render_surface());
3574 EXPECT_TRUE(front_facing_surface
->render_surface());
3575 EXPECT_TRUE(back_facing_surface
->render_surface());
3576 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3577 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3578 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3579 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3581 // Verify the render_surface_layer_list.
3582 ASSERT_EQ(3u, render_surface_layer_list
.size());
3583 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3584 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3585 // Even though the back facing surface LAYER gets culled, the other
3586 // descendants should still be added, so the SURFACE should not be culled.
3587 EXPECT_EQ(back_facing_surface
->id(), render_surface_layer_list
.at(2)->id());
3589 // Verify root surface's layer list.
3592 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3593 EXPECT_EQ(front_facing_child
->id(),
3594 render_surface_layer_list
.at(0)
3599 EXPECT_EQ(front_facing_surface
->id(),
3600 render_surface_layer_list
.at(0)
3605 EXPECT_EQ(back_facing_surface
->id(),
3606 render_surface_layer_list
.at(0)
3612 // Verify front_facing_surface's layer list.
3615 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3616 EXPECT_EQ(front_facing_surface
->id(),
3617 render_surface_layer_list
.at(1)
3622 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3623 render_surface_layer_list
.at(1)
3629 // Verify back_facing_surface's layer list; its own layer should be culled
3630 // from the surface list.
3633 render_surface_layer_list
.at(2)->render_surface()->layer_list().size());
3634 EXPECT_EQ(front_facing_child_of_back_facing_surface
->id(),
3635 render_surface_layer_list
.at(2)
3642 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithPreserves3d
) {
3643 // Verify the behavior of back-face culling when preserves-3d transform style
3646 const gfx::Transform identity_matrix
;
3647 scoped_refptr
<Layer
> parent
= Layer::Create();
3648 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_child
=
3649 make_scoped_refptr(new LayerWithForcedDrawsContent());
3650 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_child
=
3651 make_scoped_refptr(new LayerWithForcedDrawsContent());
3652 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3653 make_scoped_refptr(new LayerWithForcedDrawsContent());
3654 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3655 make_scoped_refptr(new LayerWithForcedDrawsContent());
3656 scoped_refptr
<LayerWithForcedDrawsContent
>
3657 front_facing_child_of_front_facing_surface
=
3658 make_scoped_refptr(new LayerWithForcedDrawsContent());
3659 scoped_refptr
<LayerWithForcedDrawsContent
>
3660 back_facing_child_of_front_facing_surface
=
3661 make_scoped_refptr(new LayerWithForcedDrawsContent());
3662 scoped_refptr
<LayerWithForcedDrawsContent
>
3663 front_facing_child_of_back_facing_surface
=
3664 make_scoped_refptr(new LayerWithForcedDrawsContent());
3665 scoped_refptr
<LayerWithForcedDrawsContent
>
3666 back_facing_child_of_back_facing_surface
=
3667 make_scoped_refptr(new LayerWithForcedDrawsContent());
3668 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer1
=
3669 make_scoped_refptr(new LayerWithForcedDrawsContent());
3670 scoped_refptr
<LayerWithForcedDrawsContent
> dummy_replica_layer2
=
3671 make_scoped_refptr(new LayerWithForcedDrawsContent());
3673 parent
->AddChild(front_facing_child
);
3674 parent
->AddChild(back_facing_child
);
3675 parent
->AddChild(front_facing_surface
);
3676 parent
->AddChild(back_facing_surface
);
3677 front_facing_surface
->AddChild(front_facing_child_of_front_facing_surface
);
3678 front_facing_surface
->AddChild(back_facing_child_of_front_facing_surface
);
3679 back_facing_surface
->AddChild(front_facing_child_of_back_facing_surface
);
3680 back_facing_surface
->AddChild(back_facing_child_of_back_facing_surface
);
3682 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3683 host
->SetRootLayer(parent
);
3685 // Nothing is double-sided
3686 front_facing_child
->SetDoubleSided(false);
3687 back_facing_child
->SetDoubleSided(false);
3688 front_facing_surface
->SetDoubleSided(false);
3689 back_facing_surface
->SetDoubleSided(false);
3690 front_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3691 back_facing_child_of_front_facing_surface
->SetDoubleSided(false);
3692 front_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3693 back_facing_child_of_back_facing_surface
->SetDoubleSided(false);
3695 gfx::Transform backface_matrix
;
3696 backface_matrix
.Translate(50.0, 50.0);
3697 backface_matrix
.RotateAboutYAxis(180.0);
3698 backface_matrix
.Translate(-50.0, -50.0);
3700 // Opacity will not force creation of render surfaces in this case because of
3701 // the preserve-3d transform style. Instead, an example of when a surface
3702 // would be created with preserve-3d is when there is a replica layer.
3703 front_facing_surface
->SetReplicaLayer(dummy_replica_layer1
.get());
3704 back_facing_surface
->SetReplicaLayer(dummy_replica_layer2
.get());
3706 // Each surface creates its own new 3d rendering context (as defined by W3C
3707 // spec). According to current W3C CSS gfx::Transforms spec, layers in a 3d
3708 // rendering context should use the transform with respect to that context.
3709 // This 3d rendering context occurs when (a) parent's transform style is flat
3710 // and (b) the layer's transform style is preserve-3d.
3711 SetLayerPropertiesForTesting(parent
.get(),
3715 gfx::Size(100, 100),
3717 false); // parent transform style is flat.
3718 SetLayerPropertiesForTesting(front_facing_child
.get(),
3722 gfx::Size(100, 100),
3725 SetLayerPropertiesForTesting(back_facing_child
.get(),
3729 gfx::Size(100, 100),
3732 // surface transform style is preserve-3d.
3733 SetLayerPropertiesForTesting(front_facing_surface
.get(),
3737 gfx::Size(100, 100),
3740 // surface transform style is preserve-3d.
3741 SetLayerPropertiesForTesting(back_facing_surface
.get(),
3745 gfx::Size(100, 100),
3748 SetLayerPropertiesForTesting(front_facing_child_of_front_facing_surface
.get(),
3752 gfx::Size(100, 100),
3755 SetLayerPropertiesForTesting(back_facing_child_of_front_facing_surface
.get(),
3759 gfx::Size(100, 100),
3762 SetLayerPropertiesForTesting(front_facing_child_of_back_facing_surface
.get(),
3766 gfx::Size(100, 100),
3769 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface
.get(),
3773 gfx::Size(100, 100),
3777 RenderSurfaceLayerList render_surface_layer_list
;
3778 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3779 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3780 inputs
.can_adjust_raster_scales
= true;
3781 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3783 // Verify which render surfaces were created and used.
3784 EXPECT_FALSE(front_facing_child
->render_surface());
3785 EXPECT_FALSE(back_facing_child
->render_surface());
3786 EXPECT_TRUE(front_facing_surface
->render_surface());
3787 EXPECT_NE(back_facing_surface
->render_target(), back_facing_surface
);
3788 // We expect that a render_surface was created but not used.
3789 EXPECT_TRUE(back_facing_surface
->render_surface());
3790 EXPECT_FALSE(front_facing_child_of_front_facing_surface
->render_surface());
3791 EXPECT_FALSE(back_facing_child_of_front_facing_surface
->render_surface());
3792 EXPECT_FALSE(front_facing_child_of_back_facing_surface
->render_surface());
3793 EXPECT_FALSE(back_facing_child_of_back_facing_surface
->render_surface());
3795 // Verify the render_surface_layer_list. The back-facing surface should be
3797 ASSERT_EQ(2u, render_surface_layer_list
.size());
3798 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3799 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
3801 // Verify root surface's layer list.
3804 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3805 EXPECT_EQ(front_facing_child
->id(),
3806 render_surface_layer_list
.at(0)
3807 ->render_surface()->layer_list().at(0)->id());
3808 EXPECT_EQ(front_facing_surface
->id(),
3809 render_surface_layer_list
.at(0)
3810 ->render_surface()->layer_list().at(1)->id());
3812 // Verify front_facing_surface's layer list.
3815 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3816 EXPECT_EQ(front_facing_surface
->id(),
3817 render_surface_layer_list
.at(1)
3818 ->render_surface()->layer_list().at(0)->id());
3819 EXPECT_EQ(front_facing_child_of_front_facing_surface
->id(),
3820 render_surface_layer_list
.at(1)
3821 ->render_surface()->layer_list().at(1)->id());
3824 TEST_F(LayerTreeHostCommonTest
, BackFaceCullingWithAnimatingTransforms
) {
3825 // Verify that layers are appropriately culled when their back face is showing
3826 // and they are not double sided, while animations are going on.
3828 // Layers that are animating do not get culled on the main thread, as their
3829 // transforms should be treated as "unknown" so we can not be sure that their
3830 // back face is really showing.
3831 const gfx::Transform identity_matrix
;
3832 scoped_refptr
<Layer
> parent
= Layer::Create();
3833 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
3834 make_scoped_refptr(new LayerWithForcedDrawsContent());
3835 scoped_refptr
<LayerWithForcedDrawsContent
> animating_surface
=
3836 make_scoped_refptr(new LayerWithForcedDrawsContent());
3837 scoped_refptr
<LayerWithForcedDrawsContent
> child_of_animating_surface
=
3838 make_scoped_refptr(new LayerWithForcedDrawsContent());
3839 scoped_refptr
<LayerWithForcedDrawsContent
> animating_child
=
3840 make_scoped_refptr(new LayerWithForcedDrawsContent());
3841 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3842 make_scoped_refptr(new LayerWithForcedDrawsContent());
3844 parent
->AddChild(child
);
3845 parent
->AddChild(animating_surface
);
3846 animating_surface
->AddChild(child_of_animating_surface
);
3847 parent
->AddChild(animating_child
);
3848 parent
->AddChild(child2
);
3850 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3851 host
->SetRootLayer(parent
);
3853 // Nothing is double-sided
3854 child
->SetDoubleSided(false);
3855 child2
->SetDoubleSided(false);
3856 animating_surface
->SetDoubleSided(false);
3857 child_of_animating_surface
->SetDoubleSided(false);
3858 animating_child
->SetDoubleSided(false);
3860 gfx::Transform backface_matrix
;
3861 backface_matrix
.Translate(50.0, 50.0);
3862 backface_matrix
.RotateAboutYAxis(180.0);
3863 backface_matrix
.Translate(-50.0, -50.0);
3865 // Make our render surface.
3866 animating_surface
->SetForceRenderSurface(true);
3868 // Animate the transform on the render surface.
3869 AddAnimatedTransformToController(
3870 animating_surface
->layer_animation_controller(), 10.0, 30, 0);
3871 // This is just an animating layer, not a surface.
3872 AddAnimatedTransformToController(
3873 animating_child
->layer_animation_controller(), 10.0, 30, 0);
3875 SetLayerPropertiesForTesting(parent
.get(),
3879 gfx::Size(100, 100),
3882 SetLayerPropertiesForTesting(child
.get(),
3886 gfx::Size(100, 100),
3889 SetLayerPropertiesForTesting(animating_surface
.get(),
3893 gfx::Size(100, 100),
3896 SetLayerPropertiesForTesting(child_of_animating_surface
.get(),
3900 gfx::Size(100, 100),
3903 SetLayerPropertiesForTesting(animating_child
.get(),
3907 gfx::Size(100, 100),
3910 SetLayerPropertiesForTesting(child2
.get(),
3914 gfx::Size(100, 100),
3918 RenderSurfaceLayerList render_surface_layer_list
;
3919 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
3920 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
3921 inputs
.can_adjust_raster_scales
= true;
3922 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
3924 EXPECT_FALSE(child
->render_surface());
3925 EXPECT_TRUE(animating_surface
->render_surface());
3926 EXPECT_FALSE(child_of_animating_surface
->render_surface());
3927 EXPECT_FALSE(animating_child
->render_surface());
3928 EXPECT_FALSE(child2
->render_surface());
3930 // Verify that the animating_child and child_of_animating_surface were not
3931 // culled, but that child was.
3932 ASSERT_EQ(2u, render_surface_layer_list
.size());
3933 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
3934 EXPECT_EQ(animating_surface
->id(), render_surface_layer_list
.at(1)->id());
3936 // The non-animating child be culled from the layer list for the parent render
3940 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
3941 EXPECT_EQ(animating_surface
->id(),
3942 render_surface_layer_list
.at(0)
3943 ->render_surface()->layer_list().at(0)->id());
3944 EXPECT_EQ(animating_child
->id(),
3945 render_surface_layer_list
.at(0)
3946 ->render_surface()->layer_list().at(1)->id());
3947 EXPECT_EQ(child2
->id(),
3948 render_surface_layer_list
.at(0)
3949 ->render_surface()->layer_list().at(2)->id());
3953 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
3954 EXPECT_EQ(animating_surface
->id(),
3955 render_surface_layer_list
.at(1)
3956 ->render_surface()->layer_list().at(0)->id());
3957 EXPECT_EQ(child_of_animating_surface
->id(),
3958 render_surface_layer_list
.at(1)
3959 ->render_surface()->layer_list().at(1)->id());
3961 EXPECT_FALSE(child2
->visible_content_rect().IsEmpty());
3963 // The animating layers should have a visible content rect that represents the
3964 // area of the front face that is within the viewport.
3965 EXPECT_EQ(animating_child
->visible_content_rect(),
3966 gfx::Rect(animating_child
->content_bounds()));
3967 EXPECT_EQ(animating_surface
->visible_content_rect(),
3968 gfx::Rect(animating_surface
->content_bounds()));
3969 // And layers in the subtree of the animating layer should have valid visible
3970 // content rects also.
3971 EXPECT_EQ(child_of_animating_surface
->visible_content_rect(),
3972 gfx::Rect(child_of_animating_surface
->content_bounds()));
3975 TEST_F(LayerTreeHostCommonTest
,
3976 BackFaceCullingWithPreserves3dForFlatteningSurface
) {
3977 // Verify the behavior of back-face culling for a render surface that is
3978 // created when it flattens its subtree, and its parent has preserves-3d.
3980 const gfx::Transform identity_matrix
;
3981 scoped_refptr
<Layer
> parent
= Layer::Create();
3982 scoped_refptr
<LayerWithForcedDrawsContent
> front_facing_surface
=
3983 make_scoped_refptr(new LayerWithForcedDrawsContent());
3984 scoped_refptr
<LayerWithForcedDrawsContent
> back_facing_surface
=
3985 make_scoped_refptr(new LayerWithForcedDrawsContent());
3986 scoped_refptr
<LayerWithForcedDrawsContent
> child1
=
3987 make_scoped_refptr(new LayerWithForcedDrawsContent());
3988 scoped_refptr
<LayerWithForcedDrawsContent
> child2
=
3989 make_scoped_refptr(new LayerWithForcedDrawsContent());
3991 parent
->AddChild(front_facing_surface
);
3992 parent
->AddChild(back_facing_surface
);
3993 front_facing_surface
->AddChild(child1
);
3994 back_facing_surface
->AddChild(child2
);
3996 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
3997 host
->SetRootLayer(parent
);
3999 // RenderSurfaces are not double-sided
4000 front_facing_surface
->SetDoubleSided(false);
4001 back_facing_surface
->SetDoubleSided(false);
4003 gfx::Transform backface_matrix
;
4004 backface_matrix
.Translate(50.0, 50.0);
4005 backface_matrix
.RotateAboutYAxis(180.0);
4006 backface_matrix
.Translate(-50.0, -50.0);
4008 SetLayerPropertiesForTesting(parent
.get(),
4012 gfx::Size(100, 100),
4014 true); // parent transform style is preserve3d.
4015 SetLayerPropertiesForTesting(front_facing_surface
.get(),
4019 gfx::Size(100, 100),
4021 true); // surface transform style is flat.
4022 SetLayerPropertiesForTesting(back_facing_surface
.get(),
4026 gfx::Size(100, 100),
4028 true); // surface transform style is flat.
4029 SetLayerPropertiesForTesting(child1
.get(),
4033 gfx::Size(100, 100),
4036 SetLayerPropertiesForTesting(child2
.get(),
4040 gfx::Size(100, 100),
4044 front_facing_surface
->Set3dSortingContextId(1);
4045 back_facing_surface
->Set3dSortingContextId(1);
4047 RenderSurfaceLayerList render_surface_layer_list
;
4048 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4049 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4050 inputs
.can_adjust_raster_scales
= true;
4051 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4053 // Verify which render surfaces were created and used.
4054 EXPECT_TRUE(front_facing_surface
->render_surface());
4056 // We expect the render surface to have been created, but remain unused.
4057 EXPECT_TRUE(back_facing_surface
->render_surface());
4058 EXPECT_NE(back_facing_surface
->render_target(),
4059 back_facing_surface
); // because it should be culled
4060 EXPECT_FALSE(child1
->render_surface());
4061 EXPECT_FALSE(child2
->render_surface());
4063 // Verify the render_surface_layer_list. The back-facing surface should be
4065 ASSERT_EQ(2u, render_surface_layer_list
.size());
4066 EXPECT_EQ(parent
->id(), render_surface_layer_list
.at(0)->id());
4067 EXPECT_EQ(front_facing_surface
->id(), render_surface_layer_list
.at(1)->id());
4069 // Verify root surface's layer list.
4072 render_surface_layer_list
.at(0)->render_surface()->layer_list().size());
4073 EXPECT_EQ(front_facing_surface
->id(),
4074 render_surface_layer_list
.at(0)
4075 ->render_surface()->layer_list().at(0)->id());
4077 // Verify front_facing_surface's layer list.
4080 render_surface_layer_list
.at(1)->render_surface()->layer_list().size());
4081 EXPECT_EQ(front_facing_surface
->id(),
4082 render_surface_layer_list
.at(1)
4083 ->render_surface()->layer_list().at(0)->id());
4084 EXPECT_EQ(child1
->id(),
4085 render_surface_layer_list
.at(1)
4086 ->render_surface()->layer_list().at(1)->id());
4089 class NoScaleContentLayer
: public ContentLayer
{
4091 static scoped_refptr
<NoScaleContentLayer
> Create(ContentLayerClient
* client
) {
4092 return make_scoped_refptr(new NoScaleContentLayer(client
));
4095 void CalculateContentsScale(float ideal_contents_scale
,
4096 float* contents_scale_x
,
4097 float* contents_scale_y
,
4098 gfx::Size
* content_bounds
) override
{
4099 // Skip over the ContentLayer to the base Layer class.
4100 Layer::CalculateContentsScale(ideal_contents_scale
,
4107 explicit NoScaleContentLayer(ContentLayerClient
* client
)
4108 : ContentLayer(client
) {}
4109 ~NoScaleContentLayer() override
{}
4112 scoped_refptr
<NoScaleContentLayer
> CreateNoScaleDrawableContentLayer(
4113 ContentLayerClient
* delegate
) {
4114 scoped_refptr
<NoScaleContentLayer
> to_return
=
4115 NoScaleContentLayer::Create(delegate
);
4116 to_return
->SetIsDrawable(true);
4120 TEST_F(LayerTreeHostCommonTest
, LayerTransformsInHighDPI
) {
4121 // Verify draw and screen space transforms of layers not in a surface.
4122 MockContentLayerClient delegate
;
4123 gfx::Transform identity_matrix
;
4125 scoped_refptr
<FakePictureLayer
> parent
=
4126 CreateDrawablePictureLayer(&delegate
);
4127 SetLayerPropertiesForTesting(parent
.get(),
4131 gfx::Size(100, 100),
4135 scoped_refptr
<FakePictureLayer
> child
= CreateDrawablePictureLayer(&delegate
);
4136 SetLayerPropertiesForTesting(child
.get(),
4139 gfx::PointF(2.f
, 2.f
),
4144 scoped_refptr
<FakePictureLayer
> child_empty
=
4145 CreateDrawablePictureLayer(&delegate
);
4146 SetLayerPropertiesForTesting(child_empty
.get(),
4149 gfx::PointF(2.f
, 2.f
),
4154 parent
->AddChild(child
);
4155 parent
->AddChild(child_empty
);
4157 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4158 host
->SetRootLayer(parent
);
4160 float device_scale_factor
= 2.5f
;
4161 float page_scale_factor
= 1.f
;
4163 RenderSurfaceLayerList render_surface_layer_list
;
4164 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4165 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4166 inputs
.device_scale_factor
= device_scale_factor
;
4167 inputs
.page_scale_factor
= page_scale_factor
;
4168 inputs
.can_adjust_raster_scales
= true;
4169 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4171 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4172 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, child
);
4173 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, child_empty
);
4175 EXPECT_EQ(1u, render_surface_layer_list
.size());
4177 // Verify parent transforms
4178 gfx::Transform expected_parent_transform
;
4179 expected_parent_transform
.Scale(device_scale_factor
* page_scale_factor
,
4180 device_scale_factor
* page_scale_factor
);
4181 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4182 parent
->screen_space_transform());
4183 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4184 parent
->draw_transform());
4186 // Verify results of transformed parent rects
4187 gfx::RectF
parent_content_bounds(parent
->content_bounds());
4189 gfx::RectF parent_draw_rect
=
4190 MathUtil::MapClippedRect(parent
->draw_transform(), parent_content_bounds
);
4191 gfx::RectF parent_screen_space_rect
= MathUtil::MapClippedRect(
4192 parent
->screen_space_transform(), parent_content_bounds
);
4194 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4195 expected_parent_draw_rect
.Scale(device_scale_factor
);
4196 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4197 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4199 // Verify child and child_empty transforms. They should match.
4200 gfx::Transform expected_child_transform
;
4201 expected_child_transform
.Scale(device_scale_factor
, device_scale_factor
);
4202 expected_child_transform
.Translate(child
->position().x(),
4203 child
->position().y());
4204 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4205 child
->draw_transform());
4206 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4207 child
->screen_space_transform());
4208 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4209 child_empty
->draw_transform());
4210 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4211 child_empty
->screen_space_transform());
4213 // Verify results of transformed child and child_empty rects. They should
4215 gfx::RectF
child_content_bounds(child
->content_bounds());
4217 gfx::RectF child_draw_rect
=
4218 MathUtil::MapClippedRect(child
->draw_transform(), child_content_bounds
);
4219 gfx::RectF child_screen_space_rect
= MathUtil::MapClippedRect(
4220 child
->screen_space_transform(), child_content_bounds
);
4222 gfx::RectF child_empty_draw_rect
= MathUtil::MapClippedRect(
4223 child_empty
->draw_transform(), child_content_bounds
);
4224 gfx::RectF child_empty_screen_space_rect
= MathUtil::MapClippedRect(
4225 child_empty
->screen_space_transform(), child_content_bounds
);
4227 gfx::RectF
expected_child_draw_rect(child
->position(), child
->bounds());
4228 expected_child_draw_rect
.Scale(device_scale_factor
);
4229 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4230 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4231 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_draw_rect
);
4232 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_empty_screen_space_rect
);
4235 TEST_F(LayerTreeHostCommonTest
, SurfaceLayerTransformsInHighDPI
) {
4236 // Verify draw and screen space transforms of layers in a surface.
4237 MockContentLayerClient delegate
;
4238 gfx::Transform identity_matrix
;
4240 gfx::Transform perspective_matrix
;
4241 perspective_matrix
.ApplyPerspectiveDepth(2.0);
4243 gfx::Transform scale_small_matrix
;
4244 scale_small_matrix
.Scale(SK_MScalar1
/ 10.f
, SK_MScalar1
/ 12.f
);
4246 scoped_refptr
<Layer
> root
= Layer::Create();
4248 scoped_refptr
<FakePictureLayer
> parent
=
4249 CreateDrawablePictureLayer(&delegate
);
4250 SetLayerPropertiesForTesting(parent
.get(),
4254 gfx::Size(100, 100),
4258 scoped_refptr
<FakePictureLayer
> perspective_surface
=
4259 CreateDrawablePictureLayer(&delegate
);
4260 SetLayerPropertiesForTesting(perspective_surface
.get(),
4261 perspective_matrix
* scale_small_matrix
,
4263 gfx::PointF(2.f
, 2.f
),
4268 scoped_refptr
<FakePictureLayer
> scale_surface
=
4269 CreateDrawablePictureLayer(&delegate
);
4270 SetLayerPropertiesForTesting(scale_surface
.get(),
4273 gfx::PointF(2.f
, 2.f
),
4278 perspective_surface
->SetForceRenderSurface(true);
4279 scale_surface
->SetForceRenderSurface(true);
4281 parent
->AddChild(perspective_surface
);
4282 parent
->AddChild(scale_surface
);
4283 root
->AddChild(parent
);
4285 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4286 host
->SetRootLayer(root
);
4288 float device_scale_factor
= 2.5f
;
4289 float page_scale_factor
= 3.f
;
4291 RenderSurfaceLayerList render_surface_layer_list
;
4292 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4293 root
.get(), parent
->bounds(), &render_surface_layer_list
);
4294 inputs
.device_scale_factor
= device_scale_factor
;
4295 inputs
.page_scale_factor
= page_scale_factor
;
4296 inputs
.page_scale_application_layer
= root
.get();
4297 inputs
.can_adjust_raster_scales
= true;
4298 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4300 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4301 EXPECT_IDEAL_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4302 perspective_surface
);
4303 // Ideal scale is the max 2d scale component of the combined transform up to
4304 // the nearest render target. Here this includes the layer transform as well
4305 // as the device and page scale factors.
4306 gfx::Transform transform
= scale_small_matrix
;
4307 transform
.Scale(device_scale_factor
* page_scale_factor
,
4308 device_scale_factor
* page_scale_factor
);
4309 gfx::Vector2dF scales
=
4310 MathUtil::ComputeTransform2dScaleComponents(transform
, 0.f
);
4311 float max_2d_scale
= std::max(scales
.x(), scales
.y());
4312 EXPECT_IDEAL_SCALE_EQ(max_2d_scale
, scale_surface
);
4314 // The ideal scale will draw 1:1 with its render target space along
4315 // the larger-scale axis.
4316 gfx::Vector2dF target_space_transform_scales
=
4317 MathUtil::ComputeTransform2dScaleComponents(
4318 scale_surface
->draw_properties().target_space_transform
, 0.f
);
4319 EXPECT_FLOAT_EQ(max_2d_scale
,
4320 std::max(target_space_transform_scales
.x(),
4321 target_space_transform_scales
.y()));
4323 EXPECT_EQ(3u, render_surface_layer_list
.size());
4325 gfx::Transform expected_parent_draw_transform
;
4326 expected_parent_draw_transform
.Scale(device_scale_factor
* page_scale_factor
,
4327 device_scale_factor
* page_scale_factor
);
4328 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_draw_transform
,
4329 parent
->draw_transform());
4331 // The scale for the perspective surface is not known, so it is rendered 1:1
4332 // with the screen, and then scaled during drawing.
4333 gfx::Transform expected_perspective_surface_draw_transform
;
4334 expected_perspective_surface_draw_transform
.Translate(
4335 device_scale_factor
* page_scale_factor
*
4336 perspective_surface
->position().x(),
4337 device_scale_factor
* page_scale_factor
*
4338 perspective_surface
->position().y());
4339 expected_perspective_surface_draw_transform
.PreconcatTransform(
4340 perspective_matrix
);
4341 expected_perspective_surface_draw_transform
.PreconcatTransform(
4342 scale_small_matrix
);
4343 gfx::Transform expected_perspective_surface_layer_draw_transform
;
4344 expected_perspective_surface_layer_draw_transform
.Scale(
4345 device_scale_factor
* page_scale_factor
,
4346 device_scale_factor
* page_scale_factor
);
4347 EXPECT_TRANSFORMATION_MATRIX_EQ(
4348 expected_perspective_surface_draw_transform
,
4349 perspective_surface
->render_surface()->draw_transform());
4350 EXPECT_TRANSFORMATION_MATRIX_EQ(
4351 expected_perspective_surface_layer_draw_transform
,
4352 perspective_surface
->draw_transform());
4355 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4356 TEST_F(LayerTreeHostCommonTest
,
4357 LayerTransformsInHighDPIAccurateScaleZeroChildPosition
) {
4358 // Verify draw and screen space transforms of layers not in a surface.
4359 MockContentLayerClient delegate
;
4360 gfx::Transform identity_matrix
;
4362 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4363 SetLayerPropertiesForTesting(parent
.get(),
4367 gfx::Size(133, 133),
4371 scoped_refptr
<ContentLayer
> child
= CreateDrawableContentLayer(&delegate
);
4372 SetLayerPropertiesForTesting(child
.get(),
4380 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4381 CreateNoScaleDrawableContentLayer(&delegate
);
4382 SetLayerPropertiesForTesting(child_no_scale
.get(),
4390 parent
->AddChild(child
);
4391 parent
->AddChild(child_no_scale
);
4393 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4394 host
->SetRootLayer(parent
);
4396 float device_scale_factor
= 1.7f
;
4397 float page_scale_factor
= 1.f
;
4399 RenderSurfaceLayerList render_surface_layer_list
;
4400 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4401 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
4402 inputs
.device_scale_factor
= device_scale_factor
;
4403 inputs
.page_scale_factor
= page_scale_factor
;
4404 inputs
.page_scale_application_layer
= parent
.get();
4405 inputs
.can_adjust_raster_scales
= true;
4406 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4408 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4409 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, child
);
4410 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4412 EXPECT_EQ(1u, render_surface_layer_list
.size());
4414 // Verify parent transforms
4415 gfx::Transform expected_parent_transform
;
4416 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4417 parent
->screen_space_transform());
4418 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
4419 parent
->draw_transform());
4421 // Verify results of transformed parent rects
4422 gfx::RectF
parent_content_bounds(parent
->content_bounds());
4424 gfx::RectF parent_draw_rect
=
4425 MathUtil::MapClippedRect(parent
->draw_transform(), parent_content_bounds
);
4426 gfx::RectF parent_screen_space_rect
= MathUtil::MapClippedRect(
4427 parent
->screen_space_transform(), parent_content_bounds
);
4429 gfx::RectF
expected_parent_draw_rect(parent
->bounds());
4430 expected_parent_draw_rect
.Scale(device_scale_factor
);
4431 expected_parent_draw_rect
.set_width(ceil(expected_parent_draw_rect
.width()));
4432 expected_parent_draw_rect
.set_height(
4433 ceil(expected_parent_draw_rect
.height()));
4434 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_draw_rect
);
4435 EXPECT_FLOAT_RECT_EQ(expected_parent_draw_rect
, parent_screen_space_rect
);
4437 // Verify child transforms
4438 gfx::Transform expected_child_transform
;
4439 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4440 child
->draw_transform());
4441 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform
,
4442 child
->screen_space_transform());
4444 // Verify results of transformed child rects
4445 gfx::RectF
child_content_bounds(child
->content_bounds());
4447 gfx::RectF child_draw_rect
=
4448 MathUtil::MapClippedRect(child
->draw_transform(), child_content_bounds
);
4449 gfx::RectF child_screen_space_rect
= MathUtil::MapClippedRect(
4450 child
->screen_space_transform(), child_content_bounds
);
4452 gfx::RectF
expected_child_draw_rect(child
->bounds());
4453 expected_child_draw_rect
.Scale(device_scale_factor
);
4454 expected_child_draw_rect
.set_width(ceil(expected_child_draw_rect
.width()));
4455 expected_child_draw_rect
.set_height(ceil(expected_child_draw_rect
.height()));
4456 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_draw_rect
);
4457 EXPECT_FLOAT_RECT_EQ(expected_child_draw_rect
, child_screen_space_rect
);
4459 // Verify child_no_scale transforms
4460 gfx::Transform expected_child_no_scale_transform
= child
->draw_transform();
4461 // All transforms operate on content rects. The child's content rect
4462 // incorporates device scale, but the child_no_scale does not; add it here.
4463 expected_child_no_scale_transform
.Scale(device_scale_factor
,
4464 device_scale_factor
);
4465 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4466 child_no_scale
->draw_transform());
4467 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_no_scale_transform
,
4468 child_no_scale
->screen_space_transform());
4471 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4472 TEST_F(LayerTreeHostCommonTest
, ContentsScale
) {
4473 MockContentLayerClient delegate
;
4474 gfx::Transform identity_matrix
;
4476 gfx::Transform parent_scale_matrix
;
4477 SkMScalar initial_parent_scale
= 1.75;
4478 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4480 gfx::Transform child_scale_matrix
;
4481 SkMScalar initial_child_scale
= 1.25;
4482 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4484 scoped_refptr
<Layer
> root
= Layer::Create();
4485 root
->SetBounds(gfx::Size(100, 100));
4487 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4488 SetLayerPropertiesForTesting(parent
.get(),
4489 parent_scale_matrix
,
4492 gfx::Size(100, 100),
4496 scoped_refptr
<ContentLayer
> child_scale
=
4497 CreateDrawableContentLayer(&delegate
);
4498 SetLayerPropertiesForTesting(child_scale
.get(),
4501 gfx::PointF(2.f
, 2.f
),
4506 scoped_refptr
<ContentLayer
> child_empty
=
4507 CreateDrawableContentLayer(&delegate
);
4508 SetLayerPropertiesForTesting(child_empty
.get(),
4511 gfx::PointF(2.f
, 2.f
),
4516 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4517 CreateNoScaleDrawableContentLayer(&delegate
);
4518 SetLayerPropertiesForTesting(child_no_scale
.get(),
4521 gfx::PointF(12.f
, 12.f
),
4526 root
->AddChild(parent
);
4528 parent
->AddChild(child_scale
);
4529 parent
->AddChild(child_empty
);
4530 parent
->AddChild(child_no_scale
);
4532 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4533 host
->SetRootLayer(root
);
4535 float device_scale_factor
= 2.5f
;
4536 float page_scale_factor
= 1.f
;
4539 RenderSurfaceLayerList render_surface_layer_list
;
4540 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4541 root
.get(), root
->bounds(), &render_surface_layer_list
);
4542 inputs
.device_scale_factor
= device_scale_factor
;
4543 inputs
.page_scale_factor
= page_scale_factor
;
4544 inputs
.page_scale_application_layer
= root
.get();
4545 inputs
.can_adjust_raster_scales
= true;
4546 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4548 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4549 initial_parent_scale
, parent
);
4550 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4551 initial_parent_scale
* initial_child_scale
,
4553 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4554 initial_parent_scale
* initial_child_scale
,
4556 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4558 // The parent is scaled up and shouldn't need to scale during draw. The
4559 // child that can scale its contents should also not need to scale during
4560 // draw. This shouldn't change if the child has empty bounds. The other
4562 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(0, 0));
4563 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(1, 1));
4564 EXPECT_FLOAT_EQ(1.0, child_scale
->draw_transform().matrix().get(0, 0));
4565 EXPECT_FLOAT_EQ(1.0, child_scale
->draw_transform().matrix().get(1, 1));
4566 EXPECT_FLOAT_EQ(1.0, child_empty
->draw_transform().matrix().get(0, 0));
4567 EXPECT_FLOAT_EQ(1.0, child_empty
->draw_transform().matrix().get(1, 1));
4568 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4569 initial_parent_scale
* initial_child_scale
,
4570 child_no_scale
->draw_transform().matrix().get(0, 0));
4571 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4572 initial_parent_scale
* initial_child_scale
,
4573 child_no_scale
->draw_transform().matrix().get(1, 1));
4576 // If the device_scale_factor or page_scale_factor changes, then it should be
4577 // updated using the initial transform as the raster scale.
4578 device_scale_factor
= 2.25f
;
4579 page_scale_factor
= 1.25f
;
4582 RenderSurfaceLayerList render_surface_layer_list
;
4583 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4584 root
.get(), root
->bounds(), &render_surface_layer_list
);
4585 inputs
.device_scale_factor
= device_scale_factor
;
4586 inputs
.page_scale_factor
= page_scale_factor
;
4587 inputs
.page_scale_application_layer
= root
.get();
4588 inputs
.can_adjust_raster_scales
= true;
4589 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4591 EXPECT_CONTENTS_SCALE_EQ(
4592 device_scale_factor
* page_scale_factor
* initial_parent_scale
, parent
);
4593 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4594 initial_parent_scale
* initial_child_scale
,
4596 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4597 initial_parent_scale
* initial_child_scale
,
4599 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4602 // If the transform changes, we expect the raster scale to be reset to 1.0.
4603 SkMScalar second_child_scale
= 1.75;
4604 child_scale_matrix
.Scale(second_child_scale
/ initial_child_scale
,
4605 second_child_scale
/ initial_child_scale
);
4606 child_scale
->SetTransform(child_scale_matrix
);
4607 child_empty
->SetTransform(child_scale_matrix
);
4610 RenderSurfaceLayerList render_surface_layer_list
;
4611 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4612 root
.get(), root
->bounds(), &render_surface_layer_list
);
4613 inputs
.device_scale_factor
= device_scale_factor
;
4614 inputs
.page_scale_factor
= page_scale_factor
;
4615 inputs
.page_scale_application_layer
= root
.get();
4616 inputs
.can_adjust_raster_scales
= true;
4617 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4619 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4620 initial_parent_scale
,
4622 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4624 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4626 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4629 // If the device_scale_factor or page_scale_factor changes, then it should be
4630 // updated, but still using 1.0 as the raster scale.
4631 device_scale_factor
= 2.75f
;
4632 page_scale_factor
= 1.75f
;
4635 RenderSurfaceLayerList render_surface_layer_list
;
4636 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4637 root
.get(), root
->bounds(), &render_surface_layer_list
);
4638 inputs
.device_scale_factor
= device_scale_factor
;
4639 inputs
.page_scale_factor
= page_scale_factor
;
4640 inputs
.page_scale_application_layer
= root
.get();
4641 inputs
.can_adjust_raster_scales
= true;
4642 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4644 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4645 initial_parent_scale
,
4647 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4649 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4651 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4655 // TODO(sohanjg): Remove this test when ContentLayer is removed.
4656 TEST_F(LayerTreeHostCommonTest
,
4657 ContentsScale_LayerTransformsDontAffectContentsScale
) {
4658 MockContentLayerClient delegate
;
4659 gfx::Transform identity_matrix
;
4661 gfx::Transform parent_scale_matrix
;
4662 SkMScalar initial_parent_scale
= 1.75;
4663 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4665 gfx::Transform child_scale_matrix
;
4666 SkMScalar initial_child_scale
= 1.25;
4667 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4669 scoped_refptr
<Layer
> root
= Layer::Create();
4670 root
->SetBounds(gfx::Size(100, 100));
4672 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4673 SetLayerPropertiesForTesting(parent
.get(),
4674 parent_scale_matrix
,
4677 gfx::Size(100, 100),
4681 scoped_refptr
<ContentLayer
> child_scale
=
4682 CreateDrawableContentLayer(&delegate
);
4683 SetLayerPropertiesForTesting(child_scale
.get(),
4686 gfx::PointF(2.f
, 2.f
),
4691 scoped_refptr
<ContentLayer
> child_empty
=
4692 CreateDrawableContentLayer(&delegate
);
4693 SetLayerPropertiesForTesting(child_empty
.get(),
4696 gfx::PointF(2.f
, 2.f
),
4701 scoped_refptr
<NoScaleContentLayer
> child_no_scale
=
4702 CreateNoScaleDrawableContentLayer(&delegate
);
4703 SetLayerPropertiesForTesting(child_no_scale
.get(),
4706 gfx::PointF(12.f
, 12.f
),
4711 root
->AddChild(parent
);
4713 parent
->AddChild(child_scale
);
4714 parent
->AddChild(child_empty
);
4715 parent
->AddChild(child_no_scale
);
4717 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4718 host
->SetRootLayer(root
);
4720 RenderSurfaceLayerList render_surface_layer_list
;
4722 float device_scale_factor
= 2.5f
;
4723 float page_scale_factor
= 1.f
;
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 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4732 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
, parent
);
4733 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4735 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
4737 EXPECT_CONTENTS_SCALE_EQ(1, child_no_scale
);
4739 // Since the transform scale does not affect contents scale, it should affect
4740 // the draw transform instead.
4741 EXPECT_FLOAT_EQ(initial_parent_scale
,
4742 parent
->draw_transform().matrix().get(0, 0));
4743 EXPECT_FLOAT_EQ(initial_parent_scale
,
4744 parent
->draw_transform().matrix().get(1, 1));
4745 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4746 child_scale
->draw_transform().matrix().get(0, 0));
4747 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4748 child_scale
->draw_transform().matrix().get(1, 1));
4749 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4750 child_empty
->draw_transform().matrix().get(0, 0));
4751 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
4752 child_empty
->draw_transform().matrix().get(1, 1));
4753 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4754 initial_parent_scale
* initial_child_scale
,
4755 child_no_scale
->draw_transform().matrix().get(0, 0));
4756 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
4757 initial_parent_scale
* initial_child_scale
,
4758 child_no_scale
->draw_transform().matrix().get(1, 1));
4761 TEST_F(LayerTreeHostCommonTest
, SmallIdealScale
) {
4762 MockContentLayerClient delegate
;
4763 gfx::Transform identity_matrix
;
4765 gfx::Transform parent_scale_matrix
;
4766 SkMScalar initial_parent_scale
= 1.75;
4767 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4769 gfx::Transform child_scale_matrix
;
4770 SkMScalar initial_child_scale
= 0.25;
4771 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4773 scoped_refptr
<Layer
> root
= Layer::Create();
4774 root
->SetBounds(gfx::Size(100, 100));
4776 scoped_refptr
<FakePictureLayer
> parent
=
4777 CreateDrawablePictureLayer(&delegate
);
4778 SetLayerPropertiesForTesting(parent
.get(),
4779 parent_scale_matrix
,
4782 gfx::Size(100, 100),
4786 scoped_refptr
<FakePictureLayer
> child_scale
=
4787 CreateDrawablePictureLayer(&delegate
);
4788 SetLayerPropertiesForTesting(child_scale
.get(),
4791 gfx::PointF(2.f
, 2.f
),
4796 root
->AddChild(parent
);
4798 parent
->AddChild(child_scale
);
4800 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4801 host
->SetRootLayer(root
);
4803 float device_scale_factor
= 2.5f
;
4804 float page_scale_factor
= 0.01f
;
4807 RenderSurfaceLayerList render_surface_layer_list
;
4808 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4809 root
.get(), root
->bounds(), &render_surface_layer_list
);
4810 inputs
.device_scale_factor
= device_scale_factor
;
4811 inputs
.page_scale_factor
= page_scale_factor
;
4812 inputs
.page_scale_application_layer
= root
.get();
4813 inputs
.can_adjust_raster_scales
= true;
4814 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4816 // The ideal scale is able to go below 1.
4817 float expected_ideal_scale
=
4818 device_scale_factor
* page_scale_factor
* initial_parent_scale
;
4819 EXPECT_LT(expected_ideal_scale
, 1.f
);
4820 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, parent
);
4822 expected_ideal_scale
= device_scale_factor
* page_scale_factor
*
4823 initial_parent_scale
* initial_child_scale
;
4824 EXPECT_LT(expected_ideal_scale
, 1.f
);
4825 EXPECT_IDEAL_SCALE_EQ(expected_ideal_scale
, child_scale
);
4829 TEST_F(LayerTreeHostCommonTest
, ContentsScaleForSurfaces
) {
4830 MockContentLayerClient delegate
;
4831 gfx::Transform identity_matrix
;
4833 gfx::Transform parent_scale_matrix
;
4834 SkMScalar initial_parent_scale
= 2.0;
4835 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
4837 gfx::Transform child_scale_matrix
;
4838 SkMScalar initial_child_scale
= 3.0;
4839 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
4841 scoped_refptr
<Layer
> root
= Layer::Create();
4842 root
->SetBounds(gfx::Size(100, 100));
4844 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
4845 SetLayerPropertiesForTesting(parent
.get(),
4846 parent_scale_matrix
,
4849 gfx::Size(100, 100),
4853 scoped_refptr
<ContentLayer
> surface_scale
=
4854 CreateDrawableContentLayer(&delegate
);
4855 SetLayerPropertiesForTesting(surface_scale
.get(),
4858 gfx::PointF(2.f
, 2.f
),
4863 scoped_refptr
<ContentLayer
> surface_scale_child_scale
=
4864 CreateDrawableContentLayer(&delegate
);
4865 SetLayerPropertiesForTesting(surface_scale_child_scale
.get(),
4873 scoped_refptr
<NoScaleContentLayer
> surface_scale_child_no_scale
=
4874 CreateNoScaleDrawableContentLayer(&delegate
);
4875 SetLayerPropertiesForTesting(surface_scale_child_no_scale
.get(),
4883 scoped_refptr
<NoScaleContentLayer
> surface_no_scale
=
4884 CreateNoScaleDrawableContentLayer(&delegate
);
4885 SetLayerPropertiesForTesting(surface_no_scale
.get(),
4888 gfx::PointF(12.f
, 12.f
),
4893 scoped_refptr
<ContentLayer
> surface_no_scale_child_scale
=
4894 CreateDrawableContentLayer(&delegate
);
4895 SetLayerPropertiesForTesting(surface_no_scale_child_scale
.get(),
4903 scoped_refptr
<NoScaleContentLayer
> surface_no_scale_child_no_scale
=
4904 CreateNoScaleDrawableContentLayer(&delegate
);
4905 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale
.get(),
4913 root
->AddChild(parent
);
4915 parent
->AddChild(surface_scale
);
4916 parent
->AddChild(surface_no_scale
);
4918 surface_scale
->SetForceRenderSurface(true);
4919 surface_scale
->AddChild(surface_scale_child_scale
);
4920 surface_scale
->AddChild(surface_scale_child_no_scale
);
4922 surface_no_scale
->SetForceRenderSurface(true);
4923 surface_no_scale
->AddChild(surface_no_scale_child_scale
);
4924 surface_no_scale
->AddChild(surface_no_scale_child_no_scale
);
4926 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
4927 host
->SetRootLayer(root
);
4929 SkMScalar device_scale_factor
= 5;
4930 SkMScalar page_scale_factor
= 7;
4932 RenderSurfaceLayerList render_surface_layer_list
;
4933 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
4934 root
.get(), root
->bounds(), &render_surface_layer_list
);
4935 inputs
.device_scale_factor
= device_scale_factor
;
4936 inputs
.page_scale_factor
= page_scale_factor
;
4937 inputs
.page_scale_application_layer
= root
.get();
4938 inputs
.can_adjust_raster_scales
= true;
4939 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
4941 EXPECT_CONTENTS_SCALE_EQ(
4942 device_scale_factor
* page_scale_factor
* initial_parent_scale
, parent
);
4943 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
*
4944 initial_parent_scale
* initial_child_scale
,
4946 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale
);
4947 EXPECT_CONTENTS_SCALE_EQ(
4948 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4949 initial_child_scale
* initial_child_scale
,
4950 surface_scale_child_scale
);
4951 EXPECT_CONTENTS_SCALE_EQ(1, surface_scale_child_no_scale
);
4952 EXPECT_CONTENTS_SCALE_EQ(
4953 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4954 initial_child_scale
* initial_child_scale
,
4955 surface_no_scale_child_scale
);
4956 EXPECT_CONTENTS_SCALE_EQ(1, surface_no_scale_child_no_scale
);
4958 // The parent is scaled up and shouldn't need to scale during draw.
4959 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(0, 0));
4960 EXPECT_FLOAT_EQ(1.0, parent
->draw_transform().matrix().get(1, 1));
4962 // RenderSurfaces should always be 1:1 with their target.
4965 surface_scale
->render_surface()->draw_transform().matrix().get(0, 0));
4968 surface_scale
->render_surface()->draw_transform().matrix().get(1, 1));
4970 // The surface_scale can apply contents scale so the layer shouldn't need to
4971 // scale during draw.
4972 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(0, 0));
4973 EXPECT_FLOAT_EQ(1.0, surface_scale
->draw_transform().matrix().get(1, 1));
4975 // The surface_scale_child_scale can apply contents scale so it shouldn't need
4976 // to scale during draw.
4978 1.0, surface_scale_child_scale
->draw_transform().matrix().get(0, 0));
4980 1.0, surface_scale_child_scale
->draw_transform().matrix().get(1, 1));
4982 // The surface_scale_child_no_scale can not apply contents scale, so it needs
4983 // to be scaled during draw.
4985 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4986 initial_child_scale
* initial_child_scale
,
4987 surface_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
4989 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
4990 initial_child_scale
* initial_child_scale
,
4991 surface_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
4993 // RenderSurfaces should always be 1:1 with their target.
4996 surface_no_scale
->render_surface()->draw_transform().matrix().get(0, 0));
4999 surface_no_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5001 // The surface_no_scale layer can not apply contents scale, so it needs to be
5002 // scaled during draw.
5003 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
5004 initial_parent_scale
* initial_child_scale
,
5005 surface_no_scale
->draw_transform().matrix().get(0, 0));
5006 EXPECT_FLOAT_EQ(device_scale_factor
* page_scale_factor
*
5007 initial_parent_scale
* initial_child_scale
,
5008 surface_no_scale
->draw_transform().matrix().get(1, 1));
5010 // The surface_scale_child_scale can apply contents scale so it shouldn't need
5011 // to scale during draw.
5013 1.0, surface_no_scale_child_scale
->draw_transform().matrix().get(0, 0));
5015 1.0, surface_no_scale_child_scale
->draw_transform().matrix().get(1, 1));
5017 // The surface_scale_child_no_scale can not apply contents scale, so it needs
5018 // to be scaled during draw.
5020 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5021 initial_child_scale
* initial_child_scale
,
5022 surface_no_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5024 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5025 initial_child_scale
* initial_child_scale
,
5026 surface_no_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5029 // TODO(sohanjg): Remove this test when ContentLayer is removed.
5030 TEST_F(LayerTreeHostCommonTest
,
5031 ContentsScaleForSurfaces_LayerTransformsDontAffectContentsScale
) {
5032 MockContentLayerClient delegate
;
5033 gfx::Transform identity_matrix
;
5035 gfx::Transform parent_scale_matrix
;
5036 SkMScalar initial_parent_scale
= 2.0;
5037 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
5039 gfx::Transform child_scale_matrix
;
5040 SkMScalar initial_child_scale
= 3.0;
5041 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
5043 scoped_refptr
<Layer
> root
= Layer::Create();
5044 root
->SetBounds(gfx::Size(100, 100));
5046 scoped_refptr
<ContentLayer
> parent
= CreateDrawableContentLayer(&delegate
);
5047 SetLayerPropertiesForTesting(parent
.get(),
5048 parent_scale_matrix
,
5051 gfx::Size(100, 100),
5055 scoped_refptr
<ContentLayer
> surface_scale
=
5056 CreateDrawableContentLayer(&delegate
);
5057 SetLayerPropertiesForTesting(surface_scale
.get(),
5060 gfx::PointF(2.f
, 2.f
),
5065 scoped_refptr
<ContentLayer
> surface_scale_child_scale
=
5066 CreateDrawableContentLayer(&delegate
);
5067 SetLayerPropertiesForTesting(surface_scale_child_scale
.get(),
5075 scoped_refptr
<NoScaleContentLayer
> surface_scale_child_no_scale
=
5076 CreateNoScaleDrawableContentLayer(&delegate
);
5077 SetLayerPropertiesForTesting(surface_scale_child_no_scale
.get(),
5085 scoped_refptr
<NoScaleContentLayer
> surface_no_scale
=
5086 CreateNoScaleDrawableContentLayer(&delegate
);
5087 SetLayerPropertiesForTesting(surface_no_scale
.get(),
5090 gfx::PointF(12.f
, 12.f
),
5095 scoped_refptr
<ContentLayer
> surface_no_scale_child_scale
=
5096 CreateDrawableContentLayer(&delegate
);
5097 SetLayerPropertiesForTesting(surface_no_scale_child_scale
.get(),
5105 scoped_refptr
<NoScaleContentLayer
> surface_no_scale_child_no_scale
=
5106 CreateNoScaleDrawableContentLayer(&delegate
);
5107 SetLayerPropertiesForTesting(surface_no_scale_child_no_scale
.get(),
5115 root
->AddChild(parent
);
5117 parent
->AddChild(surface_scale
);
5118 parent
->AddChild(surface_no_scale
);
5120 surface_scale
->SetForceRenderSurface(true);
5121 surface_scale
->AddChild(surface_scale_child_scale
);
5122 surface_scale
->AddChild(surface_scale_child_no_scale
);
5124 surface_no_scale
->SetForceRenderSurface(true);
5125 surface_no_scale
->AddChild(surface_no_scale_child_scale
);
5126 surface_no_scale
->AddChild(surface_no_scale_child_no_scale
);
5128 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5129 host
->SetRootLayer(root
);
5131 RenderSurfaceLayerList render_surface_layer_list
;
5133 SkMScalar device_scale_factor
= 5.0;
5134 SkMScalar page_scale_factor
= 7.0;
5135 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5136 root
.get(), root
->bounds(), &render_surface_layer_list
);
5137 inputs
.device_scale_factor
= device_scale_factor
;
5138 inputs
.page_scale_factor
= page_scale_factor
;
5139 inputs
.page_scale_application_layer
= root
.get();
5140 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5142 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5144 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5146 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_no_scale
);
5147 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5148 surface_scale_child_scale
);
5149 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_scale_child_no_scale
);
5150 EXPECT_CONTENTS_SCALE_EQ(device_scale_factor
* page_scale_factor
,
5151 surface_no_scale_child_scale
);
5152 EXPECT_CONTENTS_SCALE_EQ(1.f
, surface_no_scale_child_no_scale
);
5154 // The parent is scaled up during draw, since its contents are not scaled by
5155 // the transform hierarchy.
5156 EXPECT_FLOAT_EQ(initial_parent_scale
,
5157 parent
->draw_transform().matrix().get(0, 0));
5158 EXPECT_FLOAT_EQ(initial_parent_scale
,
5159 parent
->draw_transform().matrix().get(1, 1));
5161 // The child surface is not scaled up during draw since its subtree is scaled
5162 // by the transform hierarchy.
5165 surface_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5168 surface_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5170 // The surface_scale's RenderSurface is not scaled during draw, so the layer
5171 // needs to be scaled when drawing into its surface.
5172 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
5173 surface_scale
->draw_transform().matrix().get(0, 0));
5174 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
,
5175 surface_scale
->draw_transform().matrix().get(1, 1));
5177 // The surface_scale_child_scale is not scaled when drawing into its surface,
5178 // since its content bounds are scaled by the transform hierarchy.
5180 initial_child_scale
* initial_child_scale
* initial_parent_scale
,
5181 surface_scale_child_scale
->draw_transform().matrix().get(0, 0));
5183 initial_child_scale
* initial_child_scale
* initial_parent_scale
,
5184 surface_scale_child_scale
->draw_transform().matrix().get(1, 1));
5186 // The surface_scale_child_no_scale is scaled by the device scale, page scale
5187 // and transform hierarchy.
5189 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5190 initial_child_scale
* initial_child_scale
,
5191 surface_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5193 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5194 initial_child_scale
* initial_child_scale
,
5195 surface_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5197 // The child surface is not scaled up during draw since its subtree is scaled
5198 // by the transform hierarchy.
5201 surface_no_scale
->render_surface()->draw_transform().matrix().get(0, 0));
5204 surface_no_scale
->render_surface()->draw_transform().matrix().get(1, 1));
5206 // The surface_no_scale layer has a fixed contents scale of 1, so it needs to
5207 // be scaled by the device and page scale factors. Its surface is already
5208 // scaled by the transform hierarchy so those don't need to scale the layer's
5210 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
*
5211 device_scale_factor
* page_scale_factor
,
5212 surface_no_scale
->draw_transform().matrix().get(0, 0));
5213 EXPECT_FLOAT_EQ(initial_parent_scale
* initial_child_scale
*
5214 device_scale_factor
* page_scale_factor
,
5215 surface_no_scale
->draw_transform().matrix().get(1, 1));
5217 // The surface_no_scale_child_scale has its contents scaled by the page and
5218 // device scale factors, but needs to be scaled by the transform hierarchy
5221 initial_parent_scale
* initial_child_scale
* initial_child_scale
,
5222 surface_no_scale_child_scale
->draw_transform().matrix().get(0, 0));
5224 initial_parent_scale
* initial_child_scale
* initial_child_scale
,
5225 surface_no_scale_child_scale
->draw_transform().matrix().get(1, 1));
5227 // The surface_no_scale_child_no_scale needs to be scaled by the device and
5228 // page scale factors and by any transform heirarchy below its target surface.
5230 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5231 initial_child_scale
* initial_child_scale
,
5232 surface_no_scale_child_no_scale
->draw_transform().matrix().get(0, 0));
5234 device_scale_factor
* page_scale_factor
* initial_parent_scale
*
5235 initial_child_scale
* initial_child_scale
,
5236 surface_no_scale_child_no_scale
->draw_transform().matrix().get(1, 1));
5239 TEST_F(LayerTreeHostCommonTest
, IdealScaleForAnimatingLayer
) {
5240 MockContentLayerClient delegate
;
5241 gfx::Transform identity_matrix
;
5243 gfx::Transform parent_scale_matrix
;
5244 SkMScalar initial_parent_scale
= 1.75;
5245 parent_scale_matrix
.Scale(initial_parent_scale
, initial_parent_scale
);
5247 gfx::Transform child_scale_matrix
;
5248 SkMScalar initial_child_scale
= 1.25;
5249 child_scale_matrix
.Scale(initial_child_scale
, initial_child_scale
);
5251 scoped_refptr
<Layer
> root
= Layer::Create();
5252 root
->SetBounds(gfx::Size(100, 100));
5254 scoped_refptr
<FakePictureLayer
> parent
=
5255 CreateDrawablePictureLayer(&delegate
);
5256 SetLayerPropertiesForTesting(parent
.get(),
5257 parent_scale_matrix
,
5260 gfx::Size(100, 100),
5264 scoped_refptr
<FakePictureLayer
> child_scale
=
5265 CreateDrawablePictureLayer(&delegate
);
5266 SetLayerPropertiesForTesting(child_scale
.get(),
5269 gfx::PointF(2.f
, 2.f
),
5274 root
->AddChild(parent
);
5276 parent
->AddChild(child_scale
);
5278 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5279 host
->SetRootLayer(root
);
5282 RenderSurfaceLayerList render_surface_layer_list
;
5283 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5284 root
.get(), root
->bounds(), &render_surface_layer_list
);
5285 inputs
.can_adjust_raster_scales
= true;
5286 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5288 EXPECT_IDEAL_SCALE_EQ(initial_parent_scale
, parent
);
5289 // Animating layers compute ideal scale in the same way as when
5291 EXPECT_IDEAL_SCALE_EQ(initial_child_scale
* initial_parent_scale
,
5296 // TODO(sohanjg): Remove this test when ContentLayer is removed.
5297 TEST_F(LayerTreeHostCommonTest
,
5298 ChangeInContentBoundsOrScaleTriggersPushProperties
) {
5299 MockContentLayerClient delegate
;
5300 scoped_refptr
<Layer
> root
= Layer::Create();
5301 scoped_refptr
<Layer
> child
= CreateDrawableContentLayer(&delegate
);
5302 root
->AddChild(child
);
5304 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5305 host
->SetRootLayer(root
);
5307 gfx::Transform identity_matrix
;
5308 SetLayerPropertiesForTesting(root
.get(),
5312 gfx::Size(100, 100),
5315 SetLayerPropertiesForTesting(child
.get(),
5319 gfx::Size(100, 100),
5323 root
->reset_needs_push_properties_for_testing();
5324 child
->reset_needs_push_properties_for_testing();
5326 // This will change both layers' content bounds.
5327 ExecuteCalculateDrawProperties(root
.get());
5328 EXPECT_TRUE(root
->needs_push_properties());
5329 EXPECT_TRUE(child
->needs_push_properties());
5331 root
->reset_needs_push_properties_for_testing();
5332 child
->reset_needs_push_properties_for_testing();
5334 // This will change only the child layer's contents scale and content bounds,
5335 // since the root layer is not a ContentsScalingLayer.
5336 ExecuteCalculateDrawProperties(root
.get(), 2.f
);
5337 EXPECT_FALSE(root
->needs_push_properties());
5338 EXPECT_TRUE(child
->needs_push_properties());
5340 root
->reset_needs_push_properties_for_testing();
5341 child
->reset_needs_push_properties_for_testing();
5343 // This will not change either layer's contents scale or content bounds.
5344 ExecuteCalculateDrawProperties(root
.get(), 2.f
);
5345 EXPECT_FALSE(root
->needs_push_properties());
5346 EXPECT_FALSE(child
->needs_push_properties());
5349 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceTransformsInHighDPI
) {
5350 MockContentLayerClient delegate
;
5351 gfx::Transform identity_matrix
;
5353 scoped_refptr
<FakePictureLayer
> parent
=
5354 CreateDrawablePictureLayer(&delegate
);
5355 SetLayerPropertiesForTesting(parent
.get(),
5363 scoped_refptr
<FakePictureLayer
> child
= CreateDrawablePictureLayer(&delegate
);
5364 SetLayerPropertiesForTesting(child
.get(),
5367 gfx::PointF(2.f
, 2.f
),
5372 gfx::Transform replica_transform
;
5373 replica_transform
.Scale(1.0, -1.0);
5374 scoped_refptr
<FakePictureLayer
> replica
=
5375 CreateDrawablePictureLayer(&delegate
);
5376 SetLayerPropertiesForTesting(replica
.get(),
5379 gfx::PointF(2.f
, 2.f
),
5384 // This layer should end up in the same surface as child, with the same draw
5385 // and screen space transforms.
5386 scoped_refptr
<FakePictureLayer
> duplicate_child_non_owner
=
5387 CreateDrawablePictureLayer(&delegate
);
5388 SetLayerPropertiesForTesting(duplicate_child_non_owner
.get(),
5396 parent
->AddChild(child
);
5397 child
->AddChild(duplicate_child_non_owner
);
5398 child
->SetReplicaLayer(replica
.get());
5400 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5401 host
->SetRootLayer(parent
);
5403 RenderSurfaceLayerList render_surface_layer_list
;
5405 float device_scale_factor
= 1.5f
;
5406 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5407 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
5408 inputs
.device_scale_factor
= device_scale_factor
;
5409 inputs
.can_adjust_raster_scales
= true;
5410 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5412 // We should have two render surfaces. The root's render surface and child's
5413 // render surface (it needs one because it has a replica layer).
5414 EXPECT_EQ(2u, render_surface_layer_list
.size());
5416 gfx::Transform expected_parent_transform
;
5417 expected_parent_transform
.Scale(device_scale_factor
, device_scale_factor
);
5418 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
5419 parent
->screen_space_transform());
5420 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_parent_transform
,
5421 parent
->draw_transform());
5423 gfx::Transform expected_draw_transform
;
5424 expected_draw_transform
.Scale(device_scale_factor
, device_scale_factor
);
5425 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_draw_transform
,
5426 child
->draw_transform());
5428 gfx::Transform expected_screen_space_transform
;
5429 expected_screen_space_transform
.Scale(device_scale_factor
,
5430 device_scale_factor
);
5431 expected_screen_space_transform
.Translate(child
->position().x(),
5432 child
->position().y());
5433 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_screen_space_transform
,
5434 child
->screen_space_transform());
5436 gfx::Transform expected_duplicate_child_draw_transform
=
5437 child
->draw_transform();
5438 EXPECT_TRANSFORMATION_MATRIX_EQ(child
->draw_transform(),
5439 duplicate_child_non_owner
->draw_transform());
5440 EXPECT_TRANSFORMATION_MATRIX_EQ(
5441 child
->screen_space_transform(),
5442 duplicate_child_non_owner
->screen_space_transform());
5443 EXPECT_EQ(child
->drawable_content_rect(),
5444 duplicate_child_non_owner
->drawable_content_rect());
5445 EXPECT_EQ(child
->content_bounds(),
5446 duplicate_child_non_owner
->content_bounds());
5448 gfx::Transform expected_render_surface_draw_transform
;
5449 expected_render_surface_draw_transform
.Translate(
5450 device_scale_factor
* child
->position().x(),
5451 device_scale_factor
* child
->position().y());
5452 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_render_surface_draw_transform
,
5453 child
->render_surface()->draw_transform());
5455 gfx::Transform expected_surface_draw_transform
;
5456 expected_surface_draw_transform
.Translate(device_scale_factor
* 2.f
,
5457 device_scale_factor
* 2.f
);
5458 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform
,
5459 child
->render_surface()->draw_transform());
5461 gfx::Transform expected_surface_screen_space_transform
;
5462 expected_surface_screen_space_transform
.Translate(device_scale_factor
* 2.f
,
5463 device_scale_factor
* 2.f
);
5464 EXPECT_TRANSFORMATION_MATRIX_EQ(
5465 expected_surface_screen_space_transform
,
5466 child
->render_surface()->screen_space_transform());
5468 gfx::Transform expected_replica_draw_transform
;
5469 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
5470 expected_replica_draw_transform
.matrix().set(0, 3, 6.0);
5471 expected_replica_draw_transform
.matrix().set(1, 3, 6.0);
5472 EXPECT_TRANSFORMATION_MATRIX_EQ(
5473 expected_replica_draw_transform
,
5474 child
->render_surface()->replica_draw_transform());
5476 gfx::Transform expected_replica_screen_space_transform
;
5477 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
5478 expected_replica_screen_space_transform
.matrix().set(0, 3, 6.0);
5479 expected_replica_screen_space_transform
.matrix().set(1, 3, 6.0);
5480 EXPECT_TRANSFORMATION_MATRIX_EQ(
5481 expected_replica_screen_space_transform
,
5482 child
->render_surface()->replica_screen_space_transform());
5483 EXPECT_TRANSFORMATION_MATRIX_EQ(
5484 expected_replica_screen_space_transform
,
5485 child
->render_surface()->replica_screen_space_transform());
5488 TEST_F(LayerTreeHostCommonTest
,
5489 RenderSurfaceTransformsInHighDPIAccurateScaleZeroPosition
) {
5490 MockContentLayerClient delegate
;
5491 gfx::Transform identity_matrix
;
5493 scoped_refptr
<FakePictureLayer
> parent
=
5494 CreateDrawablePictureLayer(&delegate
);
5495 SetLayerPropertiesForTesting(parent
.get(),
5503 scoped_refptr
<FakePictureLayer
> child
= CreateDrawablePictureLayer(&delegate
);
5504 SetLayerPropertiesForTesting(child
.get(),
5512 gfx::Transform replica_transform
;
5513 replica_transform
.Scale(1.0, -1.0);
5514 scoped_refptr
<FakePictureLayer
> replica
=
5515 CreateDrawablePictureLayer(&delegate
);
5516 SetLayerPropertiesForTesting(replica
.get(),
5524 parent
->AddChild(child
);
5525 child
->SetReplicaLayer(replica
.get());
5527 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5528 host
->SetRootLayer(parent
);
5530 float device_scale_factor
= 1.7f
;
5532 RenderSurfaceLayerList render_surface_layer_list
;
5533 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5534 parent
.get(), parent
->bounds(), &render_surface_layer_list
);
5535 inputs
.device_scale_factor
= device_scale_factor
;
5536 inputs
.can_adjust_raster_scales
= true;
5537 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5539 // We should have two render surfaces. The root's render surface and child's
5540 // render surface (it needs one because it has a replica layer).
5541 EXPECT_EQ(2u, render_surface_layer_list
.size());
5543 gfx::Transform identity_transform
;
5544 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5545 child
->render_surface()->draw_transform());
5546 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_transform
,
5547 child
->render_surface()->draw_transform());
5548 EXPECT_TRANSFORMATION_MATRIX_EQ(
5549 identity_transform
, child
->render_surface()->screen_space_transform());
5551 gfx::Transform expected_replica_draw_transform
;
5552 expected_replica_draw_transform
.matrix().set(1, 1, -1.0);
5553 EXPECT_TRANSFORMATION_MATRIX_EQ(
5554 expected_replica_draw_transform
,
5555 child
->render_surface()->replica_draw_transform());
5557 gfx::Transform expected_replica_screen_space_transform
;
5558 expected_replica_screen_space_transform
.matrix().set(1, 1, -1.0);
5559 EXPECT_TRANSFORMATION_MATRIX_EQ(
5560 expected_replica_screen_space_transform
,
5561 child
->render_surface()->replica_screen_space_transform());
5564 TEST_F(LayerTreeHostCommonTest
, SubtreeSearch
) {
5565 scoped_refptr
<Layer
> root
= Layer::Create();
5566 scoped_refptr
<Layer
> child
= Layer::Create();
5567 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5568 scoped_refptr
<Layer
> mask_layer
= Layer::Create();
5569 scoped_refptr
<Layer
> replica_layer
= Layer::Create();
5571 grand_child
->SetReplicaLayer(replica_layer
.get());
5572 child
->AddChild(grand_child
.get());
5573 child
->SetMaskLayer(mask_layer
.get());
5574 root
->AddChild(child
.get());
5576 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5577 host
->SetRootLayer(root
);
5579 int nonexistent_id
= -1;
5580 EXPECT_EQ(root
.get(),
5581 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), root
->id()));
5582 EXPECT_EQ(child
.get(),
5583 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), child
->id()));
5586 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), grand_child
->id()));
5589 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), mask_layer
->id()));
5591 replica_layer
.get(),
5592 LayerTreeHostCommon::FindLayerInSubtree(root
.get(), replica_layer
->id()));
5594 0, LayerTreeHostCommon::FindLayerInSubtree(root
.get(), nonexistent_id
));
5597 TEST_F(LayerTreeHostCommonTest
, TransparentChildRenderSurfaceCreation
) {
5598 scoped_refptr
<Layer
> root
= Layer::Create();
5599 scoped_refptr
<Layer
> child
= Layer::Create();
5600 scoped_refptr
<LayerWithForcedDrawsContent
> grand_child
=
5601 make_scoped_refptr(new LayerWithForcedDrawsContent());
5603 const gfx::Transform identity_matrix
;
5604 SetLayerPropertiesForTesting(root
.get(),
5608 gfx::Size(100, 100),
5611 SetLayerPropertiesForTesting(child
.get(),
5618 SetLayerPropertiesForTesting(grand_child
.get(),
5626 root
->AddChild(child
);
5627 child
->AddChild(grand_child
);
5628 child
->SetOpacity(0.5f
);
5630 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5631 host
->SetRootLayer(root
);
5633 ExecuteCalculateDrawProperties(root
.get());
5635 EXPECT_FALSE(child
->render_surface());
5638 TEST_F(LayerTreeHostCommonTest
, OpacityAnimatingOnPendingTree
) {
5639 FakeImplProxy proxy
;
5640 TestSharedBitmapManager shared_bitmap_manager
;
5641 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5642 host_impl
.CreatePendingTree();
5643 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5645 const gfx::Transform identity_matrix
;
5646 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
5647 gfx::PointF(), gfx::Size(100, 100), true, false,
5649 root
->SetDrawsContent(true);
5651 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5652 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
5653 gfx::PointF(), gfx::Size(50, 50), true, false,
5655 child
->SetDrawsContent(true);
5656 child
->SetOpacity(0.0f
);
5658 // Add opacity animation.
5659 AddOpacityTransitionToController(
5660 child
->layer_animation_controller(), 10.0, 0.0f
, 1.0f
, false);
5662 root
->AddChild(child
.Pass());
5663 root
->SetHasRenderSurface(true);
5665 LayerImplList render_surface_layer_list
;
5666 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5667 root
.get(), root
->bounds(), &render_surface_layer_list
);
5668 inputs
.can_adjust_raster_scales
= true;
5669 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5671 // We should have one render surface and two layers. The child
5672 // layer should be included even though it is transparent.
5673 ASSERT_EQ(1u, render_surface_layer_list
.size());
5674 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5677 using LCDTextTestParam
= std::tr1::tuple
<bool, bool, bool>;
5679 : public LayerTreeHostCommonTestBase
,
5680 public testing::TestWithParam
<LCDTextTestParam
> {
5682 void SetUp() override
{
5683 can_use_lcd_text_
= std::tr1::get
<0>(GetParam());
5684 layers_always_allowed_lcd_text_
= std::tr1::get
<1>(GetParam());
5686 root_
= Layer::Create();
5687 child_
= Layer::Create();
5688 grand_child_
= Layer::Create();
5689 child_
->AddChild(grand_child_
.get());
5690 root_
->AddChild(child_
.get());
5692 root_
->SetContentsOpaque(true);
5693 child_
->SetContentsOpaque(true);
5694 grand_child_
->SetContentsOpaque(true);
5696 gfx::Transform identity_matrix
;
5697 SetLayerPropertiesForTesting(root_
.get(),
5704 SetLayerPropertiesForTesting(child_
.get(),
5711 SetLayerPropertiesForTesting(grand_child_
.get(),
5719 child_
->SetForceRenderSurface(std::tr1::get
<2>(GetParam()));
5721 host_
= CreateFakeLayerTreeHost();
5722 host_
->SetRootLayer(root_
);
5725 bool can_use_lcd_text_
;
5726 bool layers_always_allowed_lcd_text_
;
5727 scoped_ptr
<FakeLayerTreeHost
> host_
;
5728 scoped_refptr
<Layer
> root_
;
5729 scoped_refptr
<Layer
> child_
;
5730 scoped_refptr
<Layer
> grand_child_
;
5733 TEST_P(LCDTextTest
, CanUseLCDText
) {
5734 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
5735 bool expect_not_lcd_text
= layers_always_allowed_lcd_text_
;
5737 // Case 1: Identity transform.
5738 gfx::Transform identity_matrix
;
5739 ExecuteCalculateDrawProperties(root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5740 layers_always_allowed_lcd_text_
);
5741 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5742 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
5743 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
5745 // Case 2: Integral translation.
5746 gfx::Transform integral_translation
;
5747 integral_translation
.Translate(1.0, 2.0);
5748 child_
->SetTransform(integral_translation
);
5749 ExecuteCalculateDrawProperties(root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5750 layers_always_allowed_lcd_text_
);
5751 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5752 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
5753 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
5755 // Case 3: Non-integral translation.
5756 gfx::Transform non_integral_translation
;
5757 non_integral_translation
.Translate(1.5, 2.5);
5758 child_
->SetTransform(non_integral_translation
);
5759 ExecuteCalculateDrawProperties(root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5760 layers_always_allowed_lcd_text_
);
5761 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5762 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
5763 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
5765 // Case 4: Rotation.
5766 gfx::Transform rotation
;
5767 rotation
.Rotate(10.0);
5768 child_
->SetTransform(rotation
);
5769 ExecuteCalculateDrawProperties(root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5770 layers_always_allowed_lcd_text_
);
5771 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5772 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
5773 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
5776 gfx::Transform scale
;
5777 scale
.Scale(2.0, 2.0);
5778 child_
->SetTransform(scale
);
5779 ExecuteCalculateDrawProperties(root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5780 layers_always_allowed_lcd_text_
);
5781 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5782 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
5783 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
5786 gfx::Transform skew
;
5788 child_
->SetTransform(skew
);
5789 ExecuteCalculateDrawProperties(root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5790 layers_always_allowed_lcd_text_
);
5791 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5792 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
5793 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
5795 // Case 7: Translucent.
5796 child_
->SetTransform(identity_matrix
);
5797 child_
->SetOpacity(0.5f
);
5798 ExecuteCalculateDrawProperties(root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5799 layers_always_allowed_lcd_text_
);
5800 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5801 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
5802 EXPECT_EQ(expect_not_lcd_text
, grand_child_
->can_use_lcd_text());
5804 // Case 8: Sanity check: restore transform and opacity.
5805 child_
->SetTransform(identity_matrix
);
5806 child_
->SetOpacity(1.f
);
5807 ExecuteCalculateDrawProperties(root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5808 layers_always_allowed_lcd_text_
);
5809 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5810 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
5811 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
5813 // Case 9: Non-opaque content.
5814 child_
->SetContentsOpaque(false);
5815 ExecuteCalculateDrawProperties(root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5816 layers_always_allowed_lcd_text_
);
5817 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5818 EXPECT_EQ(expect_not_lcd_text
, child_
->can_use_lcd_text());
5819 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
5821 // Case 10: Sanity check: restore content opaqueness.
5822 child_
->SetContentsOpaque(true);
5823 ExecuteCalculateDrawProperties(root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5824 layers_always_allowed_lcd_text_
);
5825 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5826 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
5827 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
5830 TEST_P(LCDTextTest
, CanUseLCDTextWithAnimation
) {
5831 bool expect_lcd_text
= can_use_lcd_text_
|| layers_always_allowed_lcd_text_
;
5833 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
5834 ExecuteCalculateDrawProperties(root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5835 layers_always_allowed_lcd_text_
);
5836 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5837 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
5838 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
5840 // Add opacity animation.
5841 child_
->SetOpacity(0.9f
);
5842 AddOpacityTransitionToController(
5843 child_
->layer_animation_controller(), 10.0, 0.9f
, 0.1f
, false);
5845 ExecuteCalculateDrawProperties(root_
.get(), 1.f
, 1.f
, NULL
, can_use_lcd_text_
,
5846 layers_always_allowed_lcd_text_
);
5847 // Text AA should not be adjusted while animation is active.
5848 // Make sure LCD text AA setting remains unchanged.
5849 EXPECT_EQ(expect_lcd_text
, root_
->can_use_lcd_text());
5850 EXPECT_EQ(expect_lcd_text
, child_
->can_use_lcd_text());
5851 EXPECT_EQ(expect_lcd_text
, grand_child_
->can_use_lcd_text());
5854 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest
,
5856 testing::Combine(testing::Bool(),
5860 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayer
) {
5861 FakeImplProxy proxy
;
5862 TestSharedBitmapManager shared_bitmap_manager
;
5863 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5864 host_impl
.CreatePendingTree();
5865 const gfx::Transform identity_matrix
;
5867 scoped_refptr
<Layer
> root
= Layer::Create();
5868 SetLayerPropertiesForTesting(root
.get(),
5875 root
->SetIsDrawable(true);
5877 scoped_refptr
<Layer
> child
= Layer::Create();
5878 SetLayerPropertiesForTesting(child
.get(),
5885 child
->SetIsDrawable(true);
5887 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5888 SetLayerPropertiesForTesting(grand_child
.get(),
5895 grand_child
->SetIsDrawable(true);
5896 grand_child
->SetHideLayerAndSubtree(true);
5898 child
->AddChild(grand_child
);
5899 root
->AddChild(child
);
5901 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
5902 host
->SetRootLayer(root
);
5904 RenderSurfaceLayerList render_surface_layer_list
;
5905 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
5906 root
.get(), root
->bounds(), &render_surface_layer_list
);
5907 inputs
.can_adjust_raster_scales
= true;
5908 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5910 // We should have one render surface and two layers. The grand child has
5912 ASSERT_EQ(1u, render_surface_layer_list
.size());
5913 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5914 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
5915 EXPECT_EQ(child
->id(), root
->render_surface()->layer_list().at(1)->id());
5918 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_SingleLayerImpl
) {
5919 FakeImplProxy proxy
;
5920 TestSharedBitmapManager shared_bitmap_manager
;
5921 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5922 host_impl
.CreatePendingTree();
5923 const gfx::Transform identity_matrix
;
5925 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
5926 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
5927 gfx::PointF(), gfx::Size(50, 50), true, false,
5929 root
->SetDrawsContent(true);
5931 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
5932 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
5933 gfx::PointF(), gfx::Size(40, 40), true, false,
5935 child
->SetDrawsContent(true);
5937 scoped_ptr
<LayerImpl
> grand_child
=
5938 LayerImpl::Create(host_impl
.pending_tree(), 3);
5939 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
5940 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
5941 true, false, false);
5942 grand_child
->SetDrawsContent(true);
5943 grand_child
->SetHideLayerAndSubtree(true);
5945 child
->AddChild(grand_child
.Pass());
5946 root
->AddChild(child
.Pass());
5947 root
->SetHasRenderSurface(true);
5949 LayerImplList render_surface_layer_list
;
5950 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
5951 root
.get(), root
->bounds(), &render_surface_layer_list
);
5952 inputs
.can_adjust_raster_scales
= true;
5953 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
5955 // We should have one render surface and two layers. The grand child has
5957 ASSERT_EQ(1u, render_surface_layer_list
.size());
5958 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
5959 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
5960 EXPECT_EQ(2, root
->render_surface()->layer_list().at(1)->id());
5963 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayers
) {
5964 FakeImplProxy proxy
;
5965 TestSharedBitmapManager shared_bitmap_manager
;
5966 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
5967 host_impl
.CreatePendingTree();
5968 const gfx::Transform identity_matrix
;
5970 scoped_refptr
<Layer
> root
= Layer::Create();
5971 SetLayerPropertiesForTesting(root
.get(),
5978 root
->SetIsDrawable(true);
5980 scoped_refptr
<Layer
> child
= Layer::Create();
5981 SetLayerPropertiesForTesting(child
.get(),
5988 child
->SetIsDrawable(true);
5989 child
->SetHideLayerAndSubtree(true);
5991 scoped_refptr
<Layer
> grand_child
= Layer::Create();
5992 SetLayerPropertiesForTesting(grand_child
.get(),
5999 grand_child
->SetIsDrawable(true);
6001 child
->AddChild(grand_child
);
6002 root
->AddChild(child
);
6004 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6005 host
->SetRootLayer(root
);
6007 RenderSurfaceLayerList render_surface_layer_list
;
6008 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6009 root
.get(), root
->bounds(), &render_surface_layer_list
);
6010 inputs
.can_adjust_raster_scales
= true;
6011 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6013 // We should have one render surface and one layers. The child has
6014 // hidden itself and the grand child.
6015 ASSERT_EQ(1u, render_surface_layer_list
.size());
6016 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6017 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6020 TEST_F(LayerTreeHostCommonTest
, SubtreeHidden_TwoLayersImpl
) {
6021 FakeImplProxy proxy
;
6022 TestSharedBitmapManager shared_bitmap_manager
;
6023 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6024 host_impl
.CreatePendingTree();
6025 const gfx::Transform identity_matrix
;
6027 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.pending_tree(), 1);
6028 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, gfx::Point3F(),
6029 gfx::PointF(), gfx::Size(50, 50), true, false,
6031 root
->SetDrawsContent(true);
6033 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.pending_tree(), 2);
6034 SetLayerPropertiesForTesting(child
.get(), identity_matrix
, gfx::Point3F(),
6035 gfx::PointF(), gfx::Size(40, 40), true, false,
6037 child
->SetDrawsContent(true);
6038 child
->SetHideLayerAndSubtree(true);
6040 scoped_ptr
<LayerImpl
> grand_child
=
6041 LayerImpl::Create(host_impl
.pending_tree(), 3);
6042 SetLayerPropertiesForTesting(grand_child
.get(), identity_matrix
,
6043 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
6044 true, false, false);
6045 grand_child
->SetDrawsContent(true);
6047 child
->AddChild(grand_child
.Pass());
6048 root
->AddChild(child
.Pass());
6050 LayerImplList render_surface_layer_list
;
6051 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6052 root
.get(), root
->bounds(), &render_surface_layer_list
);
6053 inputs
.can_adjust_raster_scales
= true;
6054 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6056 // We should have one render surface and one layers. The child has
6057 // hidden itself and the grand child.
6058 ASSERT_EQ(1u, render_surface_layer_list
.size());
6059 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6060 EXPECT_EQ(1, root
->render_surface()->layer_list().at(0)->id());
6063 void EmptyCopyOutputCallback(scoped_ptr
<CopyOutputResult
> result
) {}
6065 TEST_F(LayerTreeHostCommonTest
, SubtreeHiddenWithCopyRequest
) {
6066 FakeImplProxy proxy
;
6067 TestSharedBitmapManager shared_bitmap_manager
;
6068 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6069 host_impl
.CreatePendingTree();
6070 const gfx::Transform identity_matrix
;
6072 scoped_refptr
<Layer
> root
= Layer::Create();
6073 SetLayerPropertiesForTesting(root
.get(),
6080 root
->SetIsDrawable(true);
6082 scoped_refptr
<Layer
> copy_grand_parent
= Layer::Create();
6083 SetLayerPropertiesForTesting(copy_grand_parent
.get(),
6090 copy_grand_parent
->SetIsDrawable(true);
6092 scoped_refptr
<Layer
> copy_parent
= Layer::Create();
6093 SetLayerPropertiesForTesting(copy_parent
.get(),
6100 copy_parent
->SetIsDrawable(true);
6101 copy_parent
->SetForceRenderSurface(true);
6103 scoped_refptr
<Layer
> copy_layer
= Layer::Create();
6104 SetLayerPropertiesForTesting(copy_layer
.get(),
6111 copy_layer
->SetIsDrawable(true);
6113 scoped_refptr
<Layer
> copy_child
= Layer::Create();
6114 SetLayerPropertiesForTesting(copy_child
.get(),
6121 copy_child
->SetIsDrawable(true);
6123 scoped_refptr
<Layer
> copy_grand_parent_sibling_before
= Layer::Create();
6124 SetLayerPropertiesForTesting(copy_grand_parent_sibling_before
.get(),
6131 copy_grand_parent_sibling_before
->SetIsDrawable(true);
6133 scoped_refptr
<Layer
> copy_grand_parent_sibling_after
= Layer::Create();
6134 SetLayerPropertiesForTesting(copy_grand_parent_sibling_after
.get(),
6141 copy_grand_parent_sibling_after
->SetIsDrawable(true);
6143 copy_layer
->AddChild(copy_child
);
6144 copy_parent
->AddChild(copy_layer
);
6145 copy_grand_parent
->AddChild(copy_parent
);
6146 root
->AddChild(copy_grand_parent_sibling_before
);
6147 root
->AddChild(copy_grand_parent
);
6148 root
->AddChild(copy_grand_parent_sibling_after
);
6150 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6151 host
->SetRootLayer(root
);
6153 // Hide the copy_grand_parent and its subtree. But make a copy request in that
6154 // hidden subtree on copy_layer.
6155 copy_grand_parent
->SetHideLayerAndSubtree(true);
6156 copy_grand_parent_sibling_before
->SetHideLayerAndSubtree(true);
6157 copy_grand_parent_sibling_after
->SetHideLayerAndSubtree(true);
6158 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6159 base::Bind(&EmptyCopyOutputCallback
)));
6160 EXPECT_TRUE(copy_layer
->HasCopyRequest());
6162 RenderSurfaceLayerList render_surface_layer_list
;
6163 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6164 root
.get(), root
->bounds(), &render_surface_layer_list
);
6165 inputs
.can_adjust_raster_scales
= true;
6166 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6168 EXPECT_TRUE(root
->draw_properties().layer_or_descendant_has_copy_request
);
6169 EXPECT_TRUE(copy_grand_parent
->draw_properties().
6170 layer_or_descendant_has_copy_request
);
6171 EXPECT_TRUE(copy_parent
->draw_properties().
6172 layer_or_descendant_has_copy_request
);
6173 EXPECT_TRUE(copy_layer
->draw_properties().
6174 layer_or_descendant_has_copy_request
);
6175 EXPECT_FALSE(copy_child
->draw_properties().
6176 layer_or_descendant_has_copy_request
);
6177 EXPECT_FALSE(copy_grand_parent_sibling_before
->draw_properties().
6178 layer_or_descendant_has_copy_request
);
6179 EXPECT_FALSE(copy_grand_parent_sibling_after
->draw_properties().
6180 layer_or_descendant_has_copy_request
);
6182 // We should have three render surfaces, one for the root, one for the parent
6183 // since it owns a surface, and one for the copy_layer.
6184 ASSERT_EQ(3u, render_surface_layer_list
.size());
6185 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
6186 EXPECT_EQ(copy_parent
->id(), render_surface_layer_list
.at(1)->id());
6187 EXPECT_EQ(copy_layer
->id(), render_surface_layer_list
.at(2)->id());
6189 // The root render surface should have 2 contributing layers. The
6190 // copy_grand_parent is hidden along with its siblings, but the copy_parent
6191 // will appear since something in its subtree needs to be drawn for a copy
6193 ASSERT_EQ(2u, root
->render_surface()->layer_list().size());
6194 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6195 EXPECT_EQ(copy_parent
->id(),
6196 root
->render_surface()->layer_list().at(1)->id());
6198 // Nothing actually draws into the copy parent, so only the copy_layer will
6199 // appear in its list, since it needs to be drawn for the copy request.
6200 ASSERT_EQ(1u, copy_parent
->render_surface()->layer_list().size());
6201 EXPECT_EQ(copy_layer
->id(),
6202 copy_parent
->render_surface()->layer_list().at(0)->id());
6204 // The copy_layer's render surface should have two contributing layers.
6205 ASSERT_EQ(2u, copy_layer
->render_surface()->layer_list().size());
6206 EXPECT_EQ(copy_layer
->id(),
6207 copy_layer
->render_surface()->layer_list().at(0)->id());
6208 EXPECT_EQ(copy_child
->id(),
6209 copy_layer
->render_surface()->layer_list().at(1)->id());
6212 TEST_F(LayerTreeHostCommonTest
, ClippedOutCopyRequest
) {
6213 FakeImplProxy proxy
;
6214 TestSharedBitmapManager shared_bitmap_manager
;
6215 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6216 host_impl
.CreatePendingTree();
6217 const gfx::Transform identity_matrix
;
6219 scoped_refptr
<Layer
> root
= Layer::Create();
6220 SetLayerPropertiesForTesting(root
.get(),
6227 root
->SetIsDrawable(true);
6229 scoped_refptr
<Layer
> copy_parent
= Layer::Create();
6230 SetLayerPropertiesForTesting(copy_parent
.get(),
6237 copy_parent
->SetIsDrawable(true);
6238 copy_parent
->SetMasksToBounds(true);
6240 scoped_refptr
<Layer
> copy_layer
= Layer::Create();
6241 SetLayerPropertiesForTesting(copy_layer
.get(),
6248 copy_layer
->SetIsDrawable(true);
6250 scoped_refptr
<Layer
> copy_child
= Layer::Create();
6251 SetLayerPropertiesForTesting(copy_child
.get(),
6258 copy_child
->SetIsDrawable(true);
6260 copy_layer
->AddChild(copy_child
);
6261 copy_parent
->AddChild(copy_layer
);
6262 root
->AddChild(copy_parent
);
6264 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6265 host
->SetRootLayer(root
);
6267 copy_layer
->RequestCopyOfOutput(CopyOutputRequest::CreateRequest(
6268 base::Bind(&EmptyCopyOutputCallback
)));
6269 EXPECT_TRUE(copy_layer
->HasCopyRequest());
6271 RenderSurfaceLayerList render_surface_layer_list
;
6272 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6273 root
.get(), root
->bounds(), &render_surface_layer_list
);
6274 inputs
.can_adjust_raster_scales
= true;
6275 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6277 // We should have one render surface, as the others are clipped out.
6278 ASSERT_EQ(1u, render_surface_layer_list
.size());
6279 EXPECT_EQ(root
->id(), render_surface_layer_list
.at(0)->id());
6281 // The root render surface should only have 1 contributing layer, since the
6282 // other layers are empty/clipped away.
6283 ASSERT_EQ(1u, root
->render_surface()->layer_list().size());
6284 EXPECT_EQ(root
->id(), root
->render_surface()->layer_list().at(0)->id());
6287 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInsideSurface
) {
6288 FakeImplProxy proxy
;
6289 TestSharedBitmapManager shared_bitmap_manager
;
6290 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6291 host_impl
.CreatePendingTree();
6292 const gfx::Transform identity_matrix
;
6294 scoped_refptr
<Layer
> root
= Layer::Create();
6295 SetLayerPropertiesForTesting(root
.get(),
6302 root
->SetIsDrawable(true);
6304 // The surface is moved slightly outside of the viewport.
6305 scoped_refptr
<Layer
> surface
= Layer::Create();
6306 SetLayerPropertiesForTesting(surface
.get(),
6309 gfx::PointF(-10, -20),
6313 surface
->SetForceRenderSurface(true);
6315 scoped_refptr
<Layer
> surface_child
= Layer::Create();
6316 SetLayerPropertiesForTesting(surface_child
.get(),
6323 surface_child
->SetIsDrawable(true);
6325 surface
->AddChild(surface_child
);
6326 root
->AddChild(surface
);
6328 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6329 host
->SetRootLayer(root
);
6331 RenderSurfaceLayerList render_surface_layer_list
;
6332 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
6333 root
.get(), root
->bounds(), &render_surface_layer_list
);
6334 inputs
.can_adjust_raster_scales
= true;
6335 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6337 // The visible_content_rect for the |surface_child| should not be clipped by
6339 EXPECT_EQ(gfx::Rect(50, 50).ToString(),
6340 surface_child
->visible_content_rect().ToString());
6343 TEST_F(LayerTreeHostCommonTest
, TransformedClipParent
) {
6344 // Ensure that a transform between the layer and its render surface is not a
6345 // problem. Constructs the following layer tree.
6347 // root (a render surface)
6349 // + clip_parent (scaled)
6350 // + intervening_clipping_layer
6353 // The render surface should be resized correctly and the clip child should
6354 // inherit the right clip rect.
6355 scoped_refptr
<Layer
> root
= Layer::Create();
6356 scoped_refptr
<Layer
> render_surface
= Layer::Create();
6357 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6358 scoped_refptr
<Layer
> intervening
= Layer::Create();
6359 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6360 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6362 root
->AddChild(render_surface
);
6363 render_surface
->AddChild(clip_parent
);
6364 clip_parent
->AddChild(intervening
);
6365 intervening
->AddChild(clip_child
);
6367 clip_child
->SetClipParent(clip_parent
.get());
6369 intervening
->SetMasksToBounds(true);
6370 clip_parent
->SetMasksToBounds(true);
6372 render_surface
->SetForceRenderSurface(true);
6374 gfx::Transform scale_transform
;
6375 scale_transform
.Scale(2, 2);
6377 gfx::Transform identity_transform
;
6379 SetLayerPropertiesForTesting(root
.get(),
6386 SetLayerPropertiesForTesting(render_surface
.get(),
6393 SetLayerPropertiesForTesting(clip_parent
.get(),
6396 gfx::PointF(1.f
, 1.f
),
6400 SetLayerPropertiesForTesting(intervening
.get(),
6403 gfx::PointF(1.f
, 1.f
),
6407 SetLayerPropertiesForTesting(clip_child
.get(),
6410 gfx::PointF(1.f
, 1.f
),
6415 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6416 host
->SetRootLayer(root
);
6418 ExecuteCalculateDrawProperties(root
.get());
6420 ASSERT_TRUE(root
->render_surface());
6421 ASSERT_TRUE(render_surface
->render_surface());
6423 // Ensure that we've inherited our clip parent's clip and weren't affected
6424 // by the intervening clip layer.
6425 ASSERT_EQ(gfx::Rect(1, 1, 20, 20).ToString(),
6426 clip_parent
->clip_rect().ToString());
6427 ASSERT_EQ(clip_parent
->clip_rect().ToString(),
6428 clip_child
->clip_rect().ToString());
6429 ASSERT_EQ(gfx::Rect(3, 3, 10, 10).ToString(),
6430 intervening
->clip_rect().ToString());
6432 // Ensure that the render surface reports a content rect that has been grown
6433 // to accomodate for the clip child.
6434 ASSERT_EQ(gfx::Rect(5, 5, 16, 16).ToString(),
6435 render_surface
->render_surface()->content_rect().ToString());
6437 // The above check implies the two below, but they nicely demonstrate that
6438 // we've grown, despite the intervening layer's clip.
6439 ASSERT_TRUE(clip_parent
->clip_rect().Contains(
6440 render_surface
->render_surface()->content_rect()));
6441 ASSERT_FALSE(intervening
->clip_rect().Contains(
6442 render_surface
->render_surface()->content_rect()));
6445 TEST_F(LayerTreeHostCommonTest
, ClipParentWithInterveningRenderSurface
) {
6446 // Ensure that intervening render surfaces are not a problem in the basic
6447 // case. In the following tree, both render surfaces should be resized to
6448 // accomodate for the clip child, despite an intervening clip.
6450 // root (a render surface)
6451 // + clip_parent (masks to bounds)
6452 // + render_surface1 (sets opacity)
6453 // + intervening (masks to bounds)
6454 // + render_surface2 (also sets opacity)
6457 scoped_refptr
<Layer
> root
= Layer::Create();
6458 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6459 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6460 scoped_refptr
<Layer
> intervening
= Layer::Create();
6461 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6462 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6463 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6465 root
->AddChild(clip_parent
);
6466 clip_parent
->AddChild(render_surface1
);
6467 render_surface1
->AddChild(intervening
);
6468 intervening
->AddChild(render_surface2
);
6469 render_surface2
->AddChild(clip_child
);
6471 clip_child
->SetClipParent(clip_parent
.get());
6473 intervening
->SetMasksToBounds(true);
6474 clip_parent
->SetMasksToBounds(true);
6476 render_surface1
->SetForceRenderSurface(true);
6477 render_surface2
->SetForceRenderSurface(true);
6479 gfx::Transform translation_transform
;
6480 translation_transform
.Translate(2, 2);
6482 gfx::Transform identity_transform
;
6483 SetLayerPropertiesForTesting(root
.get(),
6490 SetLayerPropertiesForTesting(clip_parent
.get(),
6491 translation_transform
,
6493 gfx::PointF(1.f
, 1.f
),
6497 SetLayerPropertiesForTesting(render_surface1
.get(),
6504 SetLayerPropertiesForTesting(intervening
.get(),
6507 gfx::PointF(1.f
, 1.f
),
6511 SetLayerPropertiesForTesting(render_surface2
.get(),
6518 SetLayerPropertiesForTesting(clip_child
.get(),
6521 gfx::PointF(-10.f
, -10.f
),
6526 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6527 host
->SetRootLayer(root
);
6529 ExecuteCalculateDrawProperties(root
.get());
6531 EXPECT_TRUE(root
->render_surface());
6532 EXPECT_TRUE(render_surface1
->render_surface());
6533 EXPECT_TRUE(render_surface2
->render_surface());
6535 // Since the render surfaces could have expanded, they should not clip (their
6536 // bounds would no longer be reliable). We should resort to layer clipping
6538 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6539 render_surface1
->render_surface()->clip_rect().ToString());
6540 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6541 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6542 render_surface2
->render_surface()->clip_rect().ToString());
6543 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
6545 // NB: clip rects are in target space.
6546 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6547 render_surface1
->clip_rect().ToString());
6548 EXPECT_TRUE(render_surface1
->is_clipped());
6550 // This value is inherited from the clipping ancestor layer, 'intervening'.
6551 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6552 render_surface2
->clip_rect().ToString());
6553 EXPECT_TRUE(render_surface2
->is_clipped());
6555 // The content rects of both render surfaces should both have expanded to
6556 // contain the clip child.
6557 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6558 render_surface1
->render_surface()->content_rect().ToString());
6559 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6560 render_surface2
->render_surface()->content_rect().ToString());
6562 // The clip child should have inherited the clip parent's clip (projected to
6563 // the right space, of course), and should have the correctly sized visible
6565 EXPECT_EQ(gfx::Rect(-1, -1, 40, 40).ToString(),
6566 clip_child
->clip_rect().ToString());
6567 EXPECT_EQ(gfx::Rect(9, 9, 40, 40).ToString(),
6568 clip_child
->visible_content_rect().ToString());
6569 EXPECT_TRUE(clip_child
->is_clipped());
6572 TEST_F(LayerTreeHostCommonTest
, ClipParentScrolledInterveningLayer
) {
6573 // Ensure that intervening render surfaces are not a problem, even if there
6574 // is a scroll involved. Note, we do _not_ have to consider any other sort
6577 // root (a render surface)
6578 // + clip_parent (masks to bounds)
6579 // + render_surface1 (sets opacity)
6580 // + intervening (masks to bounds AND scrolls)
6581 // + render_surface2 (also sets opacity)
6584 scoped_refptr
<Layer
> root
= Layer::Create();
6585 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6586 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6587 scoped_refptr
<Layer
> intervening
= Layer::Create();
6588 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6589 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6590 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6592 root
->AddChild(clip_parent
);
6593 clip_parent
->AddChild(render_surface1
);
6594 render_surface1
->AddChild(intervening
);
6595 intervening
->AddChild(render_surface2
);
6596 render_surface2
->AddChild(clip_child
);
6598 clip_child
->SetClipParent(clip_parent
.get());
6600 intervening
->SetMasksToBounds(true);
6601 clip_parent
->SetMasksToBounds(true);
6602 intervening
->SetScrollClipLayerId(clip_parent
->id());
6603 intervening
->SetScrollOffset(gfx::ScrollOffset(3, 3));
6605 render_surface1
->SetForceRenderSurface(true);
6606 render_surface2
->SetForceRenderSurface(true);
6608 gfx::Transform translation_transform
;
6609 translation_transform
.Translate(2, 2);
6611 gfx::Transform identity_transform
;
6612 SetLayerPropertiesForTesting(root
.get(),
6619 SetLayerPropertiesForTesting(clip_parent
.get(),
6620 translation_transform
,
6622 gfx::PointF(1.f
, 1.f
),
6626 SetLayerPropertiesForTesting(render_surface1
.get(),
6633 SetLayerPropertiesForTesting(intervening
.get(),
6636 gfx::PointF(1.f
, 1.f
),
6640 SetLayerPropertiesForTesting(render_surface2
.get(),
6647 SetLayerPropertiesForTesting(clip_child
.get(),
6650 gfx::PointF(-10.f
, -10.f
),
6655 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6656 host
->SetRootLayer(root
);
6658 ExecuteCalculateDrawProperties(root
.get());
6660 EXPECT_TRUE(root
->render_surface());
6661 EXPECT_TRUE(render_surface1
->render_surface());
6662 EXPECT_TRUE(render_surface2
->render_surface());
6664 // Since the render surfaces could have expanded, they should not clip (their
6665 // bounds would no longer be reliable). We should resort to layer clipping
6667 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6668 render_surface1
->render_surface()->clip_rect().ToString());
6669 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6670 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6671 render_surface2
->render_surface()->clip_rect().ToString());
6672 EXPECT_FALSE(render_surface2
->render_surface()->is_clipped());
6674 // NB: clip rects are in target space.
6675 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6676 render_surface1
->clip_rect().ToString());
6677 EXPECT_TRUE(render_surface1
->is_clipped());
6679 // This value is inherited from the clipping ancestor layer, 'intervening'.
6680 EXPECT_EQ(gfx::Rect(2, 2, 3, 3).ToString(),
6681 render_surface2
->clip_rect().ToString());
6682 EXPECT_TRUE(render_surface2
->is_clipped());
6684 // The content rects of both render surfaces should both have expanded to
6685 // contain the clip child.
6686 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6687 render_surface1
->render_surface()->content_rect().ToString());
6688 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6689 render_surface2
->render_surface()->content_rect().ToString());
6691 // The clip child should have inherited the clip parent's clip (projected to
6692 // the right space, of course), and should have the correctly sized visible
6694 EXPECT_EQ(gfx::Rect(2, 2, 40, 40).ToString(),
6695 clip_child
->clip_rect().ToString());
6696 EXPECT_EQ(gfx::Rect(12, 12, 40, 40).ToString(),
6697 clip_child
->visible_content_rect().ToString());
6698 EXPECT_TRUE(clip_child
->is_clipped());
6701 TEST_F(LayerTreeHostCommonTest
, DescendantsOfClipChildren
) {
6702 // Ensures that descendants of the clip child inherit the correct clip.
6704 // root (a render surface)
6705 // + clip_parent (masks to bounds)
6706 // + intervening (masks to bounds)
6710 scoped_refptr
<Layer
> root
= Layer::Create();
6711 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6712 scoped_refptr
<Layer
> intervening
= Layer::Create();
6713 scoped_refptr
<Layer
> clip_child
= Layer::Create();
6714 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
6715 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6717 root
->AddChild(clip_parent
);
6718 clip_parent
->AddChild(intervening
);
6719 intervening
->AddChild(clip_child
);
6720 clip_child
->AddChild(child
);
6722 clip_child
->SetClipParent(clip_parent
.get());
6724 intervening
->SetMasksToBounds(true);
6725 clip_parent
->SetMasksToBounds(true);
6727 gfx::Transform identity_transform
;
6728 SetLayerPropertiesForTesting(root
.get(),
6735 SetLayerPropertiesForTesting(clip_parent
.get(),
6742 SetLayerPropertiesForTesting(intervening
.get(),
6749 SetLayerPropertiesForTesting(clip_child
.get(),
6756 SetLayerPropertiesForTesting(child
.get(),
6764 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6765 host
->SetRootLayer(root
);
6767 ExecuteCalculateDrawProperties(root
.get());
6769 EXPECT_TRUE(root
->render_surface());
6771 // Neither the clip child nor its descendant should have inherited the clip
6772 // from |intervening|.
6773 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6774 clip_child
->clip_rect().ToString());
6775 EXPECT_TRUE(clip_child
->is_clipped());
6776 EXPECT_EQ(gfx::Rect(0, 0, 40, 40).ToString(),
6777 child
->visible_content_rect().ToString());
6778 EXPECT_TRUE(child
->is_clipped());
6781 TEST_F(LayerTreeHostCommonTest
,
6782 SurfacesShouldBeUnaffectedByNonDescendantClipChildren
) {
6783 // Ensures that non-descendant clip children in the tree do not affect
6786 // root (a render surface)
6787 // + clip_parent (masks to bounds)
6788 // + render_surface1
6790 // + render_surface2
6793 // In this example render_surface2 should be unaffected by clip_child.
6794 scoped_refptr
<Layer
> root
= Layer::Create();
6795 scoped_refptr
<Layer
> clip_parent
= Layer::Create();
6796 scoped_refptr
<Layer
> render_surface1
= Layer::Create();
6797 scoped_refptr
<LayerWithForcedDrawsContent
> clip_child
=
6798 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6799 scoped_refptr
<Layer
> render_surface2
= Layer::Create();
6800 scoped_refptr
<LayerWithForcedDrawsContent
> non_clip_child
=
6801 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6803 root
->AddChild(clip_parent
);
6804 clip_parent
->AddChild(render_surface1
);
6805 render_surface1
->AddChild(clip_child
);
6806 clip_parent
->AddChild(render_surface2
);
6807 render_surface2
->AddChild(non_clip_child
);
6809 clip_child
->SetClipParent(clip_parent
.get());
6811 clip_parent
->SetMasksToBounds(true);
6812 render_surface1
->SetMasksToBounds(true);
6814 gfx::Transform identity_transform
;
6815 SetLayerPropertiesForTesting(root
.get(),
6822 SetLayerPropertiesForTesting(clip_parent
.get(),
6829 SetLayerPropertiesForTesting(render_surface1
.get(),
6836 SetLayerPropertiesForTesting(render_surface2
.get(),
6843 SetLayerPropertiesForTesting(clip_child
.get(),
6850 SetLayerPropertiesForTesting(non_clip_child
.get(),
6858 render_surface1
->SetForceRenderSurface(true);
6859 render_surface2
->SetForceRenderSurface(true);
6861 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6862 host
->SetRootLayer(root
);
6864 ExecuteCalculateDrawProperties(root
.get());
6866 EXPECT_TRUE(root
->render_surface());
6867 EXPECT_TRUE(render_surface1
->render_surface());
6868 EXPECT_TRUE(render_surface2
->render_surface());
6870 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6871 render_surface1
->clip_rect().ToString());
6872 EXPECT_TRUE(render_surface1
->is_clipped());
6874 // The render surface should not clip (it has unclipped descendants), instead
6875 // it should rely on layer clipping.
6876 EXPECT_EQ(gfx::Rect(0, 0, 0, 0).ToString(),
6877 render_surface1
->render_surface()->clip_rect().ToString());
6878 EXPECT_FALSE(render_surface1
->render_surface()->is_clipped());
6880 // That said, it should have grown to accomodate the unclipped descendant.
6881 EXPECT_EQ(gfx::Rect(-1, 1, 6, 4).ToString(),
6882 render_surface1
->render_surface()->content_rect().ToString());
6884 // This render surface should clip. It has no unclipped descendants.
6885 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6886 render_surface2
->clip_rect().ToString());
6887 EXPECT_TRUE(render_surface2
->render_surface()->is_clipped());
6889 // It also shouldn't have grown to accomodate the clip child.
6890 EXPECT_EQ(gfx::Rect(0, 0, 5, 5).ToString(),
6891 render_surface2
->render_surface()->content_rect().ToString());
6893 // Sanity check our num_unclipped_descendants values.
6894 EXPECT_EQ(1, render_surface1
->num_unclipped_descendants());
6895 EXPECT_EQ(0, render_surface2
->num_unclipped_descendants());
6898 TEST_F(LayerTreeHostCommonTest
, CanRenderToSeparateSurface
) {
6899 FakeImplProxy proxy
;
6900 TestSharedBitmapManager shared_bitmap_manager
;
6901 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
6902 scoped_ptr
<LayerImpl
> root
=
6903 LayerImpl::Create(host_impl
.active_tree(), 12345);
6904 scoped_ptr
<LayerImpl
> child1
=
6905 LayerImpl::Create(host_impl
.active_tree(), 123456);
6906 scoped_ptr
<LayerImpl
> child2
=
6907 LayerImpl::Create(host_impl
.active_tree(), 1234567);
6908 scoped_ptr
<LayerImpl
> child3
=
6909 LayerImpl::Create(host_impl
.active_tree(), 12345678);
6911 gfx::Transform identity_matrix
;
6912 gfx::Point3F transform_origin
;
6913 gfx::PointF position
;
6914 gfx::Size
bounds(100, 100);
6915 SetLayerPropertiesForTesting(root
.get(), identity_matrix
, transform_origin
,
6916 position
, bounds
, true, false, true);
6917 root
->SetDrawsContent(true);
6919 // This layer structure normally forces render surface due to preserves3d
6921 SetLayerPropertiesForTesting(child1
.get(), identity_matrix
, transform_origin
,
6922 position
, bounds
, false, true, true);
6923 child1
->SetDrawsContent(true);
6924 SetLayerPropertiesForTesting(child2
.get(), identity_matrix
, transform_origin
,
6925 position
, bounds
, true, false, false);
6926 child2
->SetDrawsContent(true);
6927 SetLayerPropertiesForTesting(child3
.get(), identity_matrix
, transform_origin
,
6928 position
, bounds
, true, false, false);
6929 child3
->SetDrawsContent(true);
6931 child2
->Set3dSortingContextId(1);
6932 child3
->Set3dSortingContextId(1);
6934 child2
->AddChild(child3
.Pass());
6935 child1
->AddChild(child2
.Pass());
6936 root
->AddChild(child1
.Pass());
6939 LayerImplList render_surface_layer_list
;
6940 FakeLayerTreeHostImpl::RecursiveUpdateNumChildren(root
.get());
6941 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6942 root
.get(), root
->bounds(), &render_surface_layer_list
);
6943 inputs
.can_render_to_separate_surface
= true;
6944 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6946 EXPECT_EQ(2u, render_surface_layer_list
.size());
6950 LayerImplList render_surface_layer_list
;
6951 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
6952 root
.get(), root
->bounds(), &render_surface_layer_list
);
6953 inputs
.can_render_to_separate_surface
= false;
6954 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
6956 EXPECT_EQ(1u, render_surface_layer_list
.size());
6960 TEST_F(LayerTreeHostCommonTest
, DoNotIncludeBackfaceInvisibleSurfaces
) {
6961 scoped_refptr
<Layer
> root
= Layer::Create();
6962 scoped_refptr
<Layer
> render_surface
= Layer::Create();
6963 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
6964 make_scoped_refptr(new LayerWithForcedDrawsContent
);
6966 root
->AddChild(render_surface
);
6967 render_surface
->AddChild(child
);
6969 gfx::Transform identity_transform
;
6970 SetLayerPropertiesForTesting(root
.get(),
6977 SetLayerPropertiesForTesting(render_surface
.get(),
6984 SetLayerPropertiesForTesting(child
.get(),
6992 root
->SetShouldFlattenTransform(false);
6993 root
->Set3dSortingContextId(1);
6994 render_surface
->SetDoubleSided(false);
6995 render_surface
->SetForceRenderSurface(true);
6997 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
6998 host
->SetRootLayer(root
);
7000 ExecuteCalculateDrawProperties(root
.get());
7002 EXPECT_EQ(2u, render_surface_layer_list()->size());
7004 render_surface_layer_list()->at(0)
7005 ->render_surface()->layer_list().size());
7007 render_surface_layer_list()->at(1)
7008 ->render_surface()->layer_list().size());
7010 gfx::Transform rotation_transform
= identity_transform
;
7011 rotation_transform
.RotateAboutXAxis(180.0);
7013 render_surface
->SetTransform(rotation_transform
);
7015 ExecuteCalculateDrawProperties(root
.get());
7017 EXPECT_EQ(1u, render_surface_layer_list()->size());
7019 render_surface_layer_list()->at(0)
7020 ->render_surface()->layer_list().size());
7023 TEST_F(LayerTreeHostCommonTest
, ClippedByScrollParent
) {
7024 // Checks that the simple case (being clipped by a scroll parent that would
7025 // have been processed before you anyhow) results in the right clips.
7028 // + scroll_parent_border
7029 // | + scroll_parent_clip
7030 // | + scroll_parent
7033 scoped_refptr
<Layer
> root
= Layer::Create();
7034 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7035 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7036 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7037 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7038 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7039 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7041 root
->AddChild(scroll_child
);
7043 root
->AddChild(scroll_parent_border
);
7044 scroll_parent_border
->AddChild(scroll_parent_clip
);
7045 scroll_parent_clip
->AddChild(scroll_parent
);
7047 scroll_parent_clip
->SetMasksToBounds(true);
7049 scroll_child
->SetScrollParent(scroll_parent
.get());
7051 gfx::Transform identity_transform
;
7052 SetLayerPropertiesForTesting(root
.get(),
7059 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7066 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7073 SetLayerPropertiesForTesting(scroll_parent
.get(),
7080 SetLayerPropertiesForTesting(scroll_child
.get(),
7088 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7089 host
->SetRootLayer(root
);
7091 ExecuteCalculateDrawProperties(root
.get());
7093 EXPECT_TRUE(root
->render_surface());
7095 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7096 scroll_child
->clip_rect().ToString());
7097 EXPECT_TRUE(scroll_child
->is_clipped());
7100 TEST_F(LayerTreeHostCommonTest
, SingularTransformSubtreesDoNotDraw
) {
7101 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
7102 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7103 scoped_refptr
<LayerWithForcedDrawsContent
> parent
=
7104 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7105 scoped_refptr
<LayerWithForcedDrawsContent
> child
=
7106 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7108 root
->AddChild(parent
);
7109 parent
->AddChild(child
);
7111 gfx::Transform identity_transform
;
7112 SetLayerPropertiesForTesting(root
.get(),
7119 root
->SetForceRenderSurface(true);
7120 SetLayerPropertiesForTesting(parent
.get(),
7127 parent
->SetForceRenderSurface(true);
7128 SetLayerPropertiesForTesting(child
.get(),
7135 child
->SetForceRenderSurface(true);
7137 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7138 host
->SetRootLayer(root
);
7140 ExecuteCalculateDrawProperties(root
.get());
7142 EXPECT_EQ(3u, render_surface_layer_list()->size());
7144 gfx::Transform singular_transform
;
7145 singular_transform
.Scale3d(
7146 SkDoubleToMScalar(1.0), SkDoubleToMScalar(1.0), SkDoubleToMScalar(0.0));
7148 child
->SetTransform(singular_transform
);
7150 ExecuteCalculateDrawProperties(root
.get());
7152 EXPECT_EQ(2u, render_surface_layer_list()->size());
7154 // Ensure that the entire subtree under a layer with singular transform does
7155 // not get rendered.
7156 parent
->SetTransform(singular_transform
);
7157 child
->SetTransform(identity_transform
);
7159 ExecuteCalculateDrawProperties(root
.get());
7161 EXPECT_EQ(1u, render_surface_layer_list()->size());
7164 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollParent
) {
7165 // Checks that clipping by a scroll parent that follows you in paint order
7166 // still results in correct clipping.
7170 // + scroll_parent_border
7171 // + scroll_parent_clip
7174 scoped_refptr
<Layer
> root
= Layer::Create();
7175 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7176 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7177 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7178 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7179 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7180 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7182 root
->AddChild(scroll_parent_border
);
7183 scroll_parent_border
->AddChild(scroll_parent_clip
);
7184 scroll_parent_clip
->AddChild(scroll_parent
);
7186 root
->AddChild(scroll_child
);
7188 scroll_parent_clip
->SetMasksToBounds(true);
7190 scroll_child
->SetScrollParent(scroll_parent
.get());
7192 gfx::Transform identity_transform
;
7193 SetLayerPropertiesForTesting(root
.get(),
7200 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7207 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7214 SetLayerPropertiesForTesting(scroll_parent
.get(),
7221 SetLayerPropertiesForTesting(scroll_child
.get(),
7229 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7230 host
->SetRootLayer(root
);
7232 ExecuteCalculateDrawProperties(root
.get());
7234 EXPECT_TRUE(root
->render_surface());
7236 EXPECT_EQ(gfx::Rect(0, 0, 30, 30).ToString(),
7237 scroll_child
->clip_rect().ToString());
7238 EXPECT_TRUE(scroll_child
->is_clipped());
7241 TEST_F(LayerTreeHostCommonTest
, ClippedByOutOfOrderScrollGrandparent
) {
7242 // Checks that clipping by a scroll parent and scroll grandparent that follow
7243 // you in paint order still results in correct clipping.
7247 // + scroll_parent_border
7248 // | + scroll_parent_clip
7249 // | + scroll_parent
7250 // + scroll_grandparent_border
7251 // + scroll_grandparent_clip
7252 // + scroll_grandparent
7254 scoped_refptr
<Layer
> root
= Layer::Create();
7255 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7256 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7257 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7258 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7260 scoped_refptr
<Layer
> scroll_grandparent_border
= Layer::Create();
7261 scoped_refptr
<Layer
> scroll_grandparent_clip
= Layer::Create();
7262 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_grandparent
=
7263 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7265 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7266 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7268 root
->AddChild(scroll_child
);
7270 root
->AddChild(scroll_parent_border
);
7271 scroll_parent_border
->AddChild(scroll_parent_clip
);
7272 scroll_parent_clip
->AddChild(scroll_parent
);
7274 root
->AddChild(scroll_grandparent_border
);
7275 scroll_grandparent_border
->AddChild(scroll_grandparent_clip
);
7276 scroll_grandparent_clip
->AddChild(scroll_grandparent
);
7278 scroll_parent_clip
->SetMasksToBounds(true);
7279 scroll_grandparent_clip
->SetMasksToBounds(true);
7281 scroll_child
->SetScrollParent(scroll_parent
.get());
7282 scroll_parent_border
->SetScrollParent(scroll_grandparent
.get());
7284 gfx::Transform identity_transform
;
7285 SetLayerPropertiesForTesting(root
.get(),
7292 SetLayerPropertiesForTesting(scroll_grandparent_border
.get(),
7299 SetLayerPropertiesForTesting(scroll_grandparent_clip
.get(),
7306 SetLayerPropertiesForTesting(scroll_grandparent
.get(),
7313 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7320 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7327 SetLayerPropertiesForTesting(scroll_parent
.get(),
7334 SetLayerPropertiesForTesting(scroll_child
.get(),
7342 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7343 host
->SetRootLayer(root
);
7345 ExecuteCalculateDrawProperties(root
.get());
7347 EXPECT_TRUE(root
->render_surface());
7349 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7350 scroll_child
->clip_rect().ToString());
7351 EXPECT_TRUE(scroll_child
->is_clipped());
7353 // Despite the fact that we visited the above layers out of order to get the
7354 // correct clip, the layer lists should be unaffected.
7355 EXPECT_EQ(3u, root
->render_surface()->layer_list().size());
7356 EXPECT_EQ(scroll_child
.get(),
7357 root
->render_surface()->layer_list().at(0).get());
7358 EXPECT_EQ(scroll_parent
.get(),
7359 root
->render_surface()->layer_list().at(1).get());
7360 EXPECT_EQ(scroll_grandparent
.get(),
7361 root
->render_surface()->layer_list().at(2).get());
7364 TEST_F(LayerTreeHostCommonTest
, OutOfOrderClippingRequiresRSLLSorting
) {
7365 // Ensures that even if we visit layers out of order, we still produce a
7366 // correctly ordered render surface layer list.
7369 // + scroll_parent_border
7370 // + scroll_parent_clip
7372 // + render_surface1
7373 // + scroll_grandparent_border
7374 // + scroll_grandparent_clip
7375 // + scroll_grandparent
7376 // + render_surface2
7378 scoped_refptr
<LayerWithForcedDrawsContent
> root
=
7379 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7381 scoped_refptr
<Layer
> scroll_parent_border
= Layer::Create();
7382 scoped_refptr
<Layer
> scroll_parent_clip
= Layer::Create();
7383 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_parent
=
7384 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7385 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface1
=
7386 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7388 scoped_refptr
<Layer
> scroll_grandparent_border
= Layer::Create();
7389 scoped_refptr
<Layer
> scroll_grandparent_clip
= Layer::Create();
7390 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_grandparent
=
7391 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7392 scoped_refptr
<LayerWithForcedDrawsContent
> render_surface2
=
7393 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7395 scoped_refptr
<LayerWithForcedDrawsContent
> scroll_child
=
7396 make_scoped_refptr(new LayerWithForcedDrawsContent
);
7398 root
->AddChild(scroll_child
);
7400 root
->AddChild(scroll_parent_border
);
7401 scroll_parent_border
->AddChild(scroll_parent_clip
);
7402 scroll_parent_clip
->AddChild(scroll_parent
);
7403 scroll_parent
->AddChild(render_surface2
);
7405 root
->AddChild(scroll_grandparent_border
);
7406 scroll_grandparent_border
->AddChild(scroll_grandparent_clip
);
7407 scroll_grandparent_clip
->AddChild(scroll_grandparent
);
7408 scroll_grandparent
->AddChild(render_surface1
);
7410 scroll_parent_clip
->SetMasksToBounds(true);
7411 scroll_grandparent_clip
->SetMasksToBounds(true);
7413 scroll_child
->SetScrollParent(scroll_parent
.get());
7414 scroll_parent_border
->SetScrollParent(scroll_grandparent
.get());
7416 render_surface1
->SetForceRenderSurface(true);
7417 render_surface2
->SetForceRenderSurface(true);
7419 gfx::Transform identity_transform
;
7420 SetLayerPropertiesForTesting(root
.get(),
7427 SetLayerPropertiesForTesting(scroll_grandparent_border
.get(),
7434 SetLayerPropertiesForTesting(scroll_grandparent_clip
.get(),
7441 SetLayerPropertiesForTesting(scroll_grandparent
.get(),
7448 SetLayerPropertiesForTesting(render_surface1
.get(),
7455 SetLayerPropertiesForTesting(scroll_parent_border
.get(),
7462 SetLayerPropertiesForTesting(scroll_parent_clip
.get(),
7469 SetLayerPropertiesForTesting(scroll_parent
.get(),
7476 SetLayerPropertiesForTesting(render_surface2
.get(),
7483 SetLayerPropertiesForTesting(scroll_child
.get(),
7491 scoped_ptr
<FakeLayerTreeHost
> host(CreateFakeLayerTreeHost());
7492 host
->SetRootLayer(root
);
7494 RenderSurfaceLayerList render_surface_layer_list
;
7495 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
7499 &render_surface_layer_list
);
7501 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7503 EXPECT_TRUE(root
->render_surface());
7505 EXPECT_EQ(gfx::Rect(0, 0, 20, 20).ToString(),
7506 scroll_child
->clip_rect().ToString());
7507 EXPECT_TRUE(scroll_child
->is_clipped());
7509 // Despite the fact that we had to process the layers out of order to get the
7510 // right clip, our render_surface_layer_list's order should be unaffected.
7511 EXPECT_EQ(3u, render_surface_layer_list
.size());
7512 EXPECT_EQ(root
.get(), render_surface_layer_list
.at(0));
7513 EXPECT_EQ(render_surface2
.get(), render_surface_layer_list
.at(1));
7514 EXPECT_EQ(render_surface1
.get(), render_surface_layer_list
.at(2));
7515 EXPECT_TRUE(render_surface_layer_list
.at(0)->render_surface());
7516 EXPECT_TRUE(render_surface_layer_list
.at(1)->render_surface());
7517 EXPECT_TRUE(render_surface_layer_list
.at(2)->render_surface());
7520 TEST_F(LayerTreeHostCommonTest
, DoNotClobberSorting
) {
7521 // We rearrange layer list contributions if we have to visit children out of
7522 // order, but it should be a 'stable' rearrangement. That is, the layer list
7523 // additions for a single layer should not be reordered, though their position
7524 // wrt to the contributions due to a sibling may vary.
7530 // + scroll_parent_border
7531 // + scroll_parent_clip
7534 FakeImplProxy proxy
;
7535 TestSharedBitmapManager shared_bitmap_manager
;
7536 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7537 host_impl
.CreatePendingTree();
7538 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7539 scoped_ptr
<LayerImpl
> scroll_parent_border
=
7540 LayerImpl::Create(host_impl
.active_tree(), 2);
7541 scoped_ptr
<LayerImpl
> scroll_parent_clip
=
7542 LayerImpl::Create(host_impl
.active_tree(), 3);
7543 scoped_ptr
<LayerImpl
> scroll_parent
=
7544 LayerImpl::Create(host_impl
.active_tree(), 4);
7545 scoped_ptr
<LayerImpl
> scroll_child
=
7546 LayerImpl::Create(host_impl
.active_tree(), 5);
7547 scoped_ptr
<LayerImpl
> bottom_content
=
7548 LayerImpl::Create(host_impl
.active_tree(), 6);
7549 scoped_ptr
<LayerImpl
> top_content
=
7550 LayerImpl::Create(host_impl
.active_tree(), 7);
7552 scroll_parent_clip
->SetMasksToBounds(true);
7554 scroll_child
->SetScrollParent(scroll_parent
.get());
7555 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children(new std::set
<LayerImpl
*>);
7556 scroll_children
->insert(scroll_child
.get());
7557 scroll_parent
->SetScrollChildren(scroll_children
.release());
7559 scroll_child
->SetDrawsContent(true);
7560 scroll_parent
->SetDrawsContent(true);
7561 top_content
->SetDrawsContent(true);
7562 bottom_content
->SetDrawsContent(true);
7564 gfx::Transform identity_transform
;
7565 gfx::Transform top_transform
;
7566 top_transform
.Translate3d(0.0, 0.0, 5.0);
7567 gfx::Transform bottom_transform
;
7568 bottom_transform
.Translate3d(0.0, 0.0, 3.0);
7570 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7571 gfx::PointF(), gfx::Size(50, 50), true, false,
7573 SetLayerPropertiesForTesting(scroll_parent_border
.get(), identity_transform
,
7574 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7575 true, false, false);
7576 SetLayerPropertiesForTesting(scroll_parent_clip
.get(), identity_transform
,
7577 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7578 true, false, false);
7579 SetLayerPropertiesForTesting(scroll_parent
.get(), identity_transform
,
7580 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7581 true, false, false);
7582 SetLayerPropertiesForTesting(scroll_child
.get(), identity_transform
,
7583 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7584 true, false, false);
7585 SetLayerPropertiesForTesting(top_content
.get(), top_transform
, gfx::Point3F(),
7586 gfx::PointF(), gfx::Size(50, 50), false, true,
7588 SetLayerPropertiesForTesting(bottom_content
.get(), bottom_transform
,
7589 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50),
7592 scroll_child
->SetShouldFlattenTransform(false);
7593 scroll_child
->Set3dSortingContextId(1);
7595 scroll_child
->AddChild(top_content
.Pass());
7596 scroll_child
->AddChild(bottom_content
.Pass());
7597 root
->AddChild(scroll_child
.Pass());
7599 scroll_parent_clip
->AddChild(scroll_parent
.Pass());
7600 scroll_parent_border
->AddChild(scroll_parent_clip
.Pass());
7601 root
->AddChild(scroll_parent_border
.Pass());
7603 LayerImplList render_surface_layer_list
;
7604 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7605 root
.get(), root
->bounds(), &render_surface_layer_list
);
7607 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7609 EXPECT_TRUE(root
->render_surface());
7611 // If we don't sort by depth and let the layers get added in the order they
7612 // would normally be visited in, then layers 6 and 7 will be out of order. In
7613 // other words, although we've had to shift 5, 6, and 7 to appear before 4
7614 // in the list (because of the scroll parent relationship), this should not
7615 // have an effect on the the order of 5, 6, and 7 (which had been reordered
7616 // due to layer sorting).
7617 EXPECT_EQ(4u, root
->render_surface()->layer_list().size());
7618 EXPECT_EQ(5, root
->render_surface()->layer_list().at(0)->id());
7619 EXPECT_EQ(6, root
->render_surface()->layer_list().at(1)->id());
7620 EXPECT_EQ(7, root
->render_surface()->layer_list().at(2)->id());
7621 EXPECT_EQ(4, root
->render_surface()->layer_list().at(3)->id());
7624 TEST_F(LayerTreeHostCommonTest
, ScrollCompensationWithRounding
) {
7625 // This test verifies that a scrolling layer that gets snapped to
7626 // integer coordinates doesn't move a fixed position child.
7633 FakeImplProxy proxy
;
7634 TestSharedBitmapManager shared_bitmap_manager
;
7635 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7636 host_impl
.CreatePendingTree();
7637 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7638 scoped_ptr
<LayerImpl
> container
=
7639 LayerImpl::Create(host_impl
.active_tree(), 2);
7640 LayerImpl
* container_layer
= container
.get();
7641 scoped_ptr
<LayerImpl
> scroller
=
7642 LayerImpl::Create(host_impl
.active_tree(), 3);
7643 LayerImpl
* scroll_layer
= scroller
.get();
7644 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
7645 LayerImpl
* fixed_layer
= fixed
.get();
7647 container
->SetIsContainerForFixedPositionLayers(true);
7649 LayerPositionConstraint constraint
;
7650 constraint
.set_is_fixed_position(true);
7651 fixed
->SetPositionConstraint(constraint
);
7653 scroller
->SetScrollClipLayer(container
->id());
7655 gfx::Transform identity_transform
;
7656 gfx::Transform container_transform
;
7657 container_transform
.Translate3d(10.0, 20.0, 0.0);
7658 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
7660 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7661 gfx::PointF(), gfx::Size(50, 50), true, false,
7663 SetLayerPropertiesForTesting(container
.get(), container_transform
,
7664 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7665 true, false, false);
7666 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
7667 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30),
7668 true, false, false);
7669 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
7670 gfx::PointF(), gfx::Size(50, 50), true, false,
7673 scroller
->AddChild(fixed
.Pass());
7674 container
->AddChild(scroller
.Pass());
7675 root
->AddChild(container
.Pass());
7677 // Rounded to integers already.
7679 gfx::Vector2dF
scroll_delta(3.0, 5.0);
7680 scroll_layer
->SetScrollDelta(scroll_delta
);
7682 LayerImplList render_surface_layer_list
;
7683 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7684 root
.get(), root
->bounds(), &render_surface_layer_list
);
7685 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7687 EXPECT_TRANSFORMATION_MATRIX_EQ(
7688 container_layer
->draw_properties().screen_space_transform
,
7689 fixed_layer
->draw_properties().screen_space_transform
);
7691 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7693 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
7694 .screen_space_transform
.To2dTranslation(),
7695 container_offset
- scroll_delta
);
7698 // Scroll delta requiring rounding.
7700 gfx::Vector2dF
scroll_delta(4.1f
, 8.1f
);
7701 scroll_layer
->SetScrollDelta(scroll_delta
);
7703 gfx::Vector2dF
rounded_scroll_delta(4.f
, 8.f
);
7705 LayerImplList render_surface_layer_list
;
7706 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7707 root
.get(), root
->bounds(), &render_surface_layer_list
);
7708 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7710 EXPECT_TRANSFORMATION_MATRIX_EQ(
7711 container_layer
->draw_properties().screen_space_transform
,
7712 fixed_layer
->draw_properties().screen_space_transform
);
7714 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7716 EXPECT_VECTOR_EQ(scroll_layer
->draw_properties()
7717 .screen_space_transform
.To2dTranslation(),
7718 container_offset
- rounded_scroll_delta
);
7721 // Scale is applied earlier in the tree.
7723 gfx::Transform scaled_container_transform
= container_transform
;
7724 scaled_container_transform
.Scale3d(3.0, 3.0, 1.0);
7725 container_layer
->SetTransform(scaled_container_transform
);
7727 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
7728 scroll_layer
->SetScrollDelta(scroll_delta
);
7730 LayerImplList render_surface_layer_list
;
7731 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7732 root
.get(), root
->bounds(), &render_surface_layer_list
);
7733 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7735 EXPECT_TRANSFORMATION_MATRIX_EQ(
7736 container_layer
->draw_properties().screen_space_transform
,
7737 fixed_layer
->draw_properties().screen_space_transform
);
7739 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7742 container_layer
->SetTransform(container_transform
);
7745 // Scale is applied on the scroll layer itself.
7747 gfx::Transform scale_transform
;
7748 scale_transform
.Scale3d(3.0, 3.0, 1.0);
7749 scroll_layer
->SetTransform(scale_transform
);
7751 gfx::Vector2dF
scroll_delta(4.5f
, 8.5f
);
7752 scroll_layer
->SetScrollDelta(scroll_delta
);
7754 LayerImplList render_surface_layer_list
;
7755 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7756 root
.get(), root
->bounds(), &render_surface_layer_list
);
7757 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7760 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7763 scroll_layer
->SetTransform(identity_transform
);
7767 TEST_F(LayerTreeHostCommonTest
,
7768 ScrollCompensationMainScrollOffsetFractionalPart
) {
7769 // This test verifies that a scrolling layer that has fractional scroll offset
7770 // from main doesn't move a fixed position child.
7777 FakeImplProxy proxy
;
7778 TestSharedBitmapManager shared_bitmap_manager
;
7779 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7780 host_impl
.CreatePendingTree();
7781 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
7782 scoped_ptr
<LayerImpl
> container
=
7783 LayerImpl::Create(host_impl
.active_tree(), 2);
7784 LayerImpl
* container_layer
= container
.get();
7785 scoped_ptr
<LayerImpl
> scroller
=
7786 LayerImpl::Create(host_impl
.active_tree(), 3);
7787 LayerImpl
* scroll_layer
= scroller
.get();
7788 scoped_ptr
<LayerImpl
> fixed
= LayerImpl::Create(host_impl
.active_tree(), 4);
7789 LayerImpl
* fixed_layer
= fixed
.get();
7791 container
->SetIsContainerForFixedPositionLayers(true);
7793 LayerPositionConstraint constraint
;
7794 constraint
.set_is_fixed_position(true);
7795 fixed
->SetPositionConstraint(constraint
);
7797 scroller
->SetScrollClipLayer(container
->id());
7799 gfx::Transform identity_transform
;
7800 gfx::Transform container_transform
;
7801 container_transform
.Translate3d(10.0, 20.0, 0.0);
7802 gfx::Vector2dF container_offset
= container_transform
.To2dTranslation();
7804 SetLayerPropertiesForTesting(root
.get(), identity_transform
, gfx::Point3F(),
7805 gfx::PointF(), gfx::Size(50, 50), true, false,
7807 SetLayerPropertiesForTesting(container
.get(), container_transform
,
7808 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40),
7809 true, false, false);
7810 SetLayerPropertiesForTesting(scroller
.get(), identity_transform
,
7811 gfx::Point3F(), gfx::PointF(0.0, 0.0),
7812 gfx::Size(30, 30), true, false, false);
7814 gfx::ScrollOffset
scroll_offset(3.3, 4.2);
7815 gfx::Vector2dF
main_scroll_fractional_part(0.3f
, 0.2f
);
7816 gfx::Vector2dF
scroll_delta(0.1f
, 0.4f
);
7817 // Blink only uses the integer part of the scroll_offset for fixed
7819 SetLayerPropertiesForTesting(fixed
.get(), identity_transform
, gfx::Point3F(),
7820 gfx::PointF(3.0f
, 4.0f
), gfx::Size(50, 50), true,
7822 scroll_layer
->SetScrollOffset(scroll_offset
);
7823 scroll_layer
->SetScrollDelta(scroll_delta
);
7824 scroll_layer
->SetScrollCompensationAdjustment(main_scroll_fractional_part
);
7826 scroller
->AddChild(fixed
.Pass());
7827 container
->AddChild(scroller
.Pass());
7828 root
->AddChild(container
.Pass());
7830 LayerImplList render_surface_layer_list
;
7831 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
7832 root
.get(), root
->bounds(), &render_surface_layer_list
);
7833 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
7835 EXPECT_TRANSFORMATION_MATRIX_EQ(
7836 container_layer
->draw_properties().screen_space_transform
,
7837 fixed_layer
->draw_properties().screen_space_transform
);
7839 fixed_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7842 gfx::ScrollOffset effective_scroll_offset
=
7843 ScrollOffsetWithDelta(scroll_offset
, scroll_delta
);
7844 gfx::Vector2d rounded_effective_scroll_offset
=
7845 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset
));
7847 scroll_layer
->draw_properties().screen_space_transform
.To2dTranslation(),
7848 container_offset
- rounded_effective_scroll_offset
);
7851 class AnimationScaleFactorTrackingLayerImpl
: public LayerImpl
{
7853 static scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> Create(
7854 LayerTreeImpl
* tree_impl
,
7856 return make_scoped_ptr(
7857 new AnimationScaleFactorTrackingLayerImpl(tree_impl
, id
));
7860 ~AnimationScaleFactorTrackingLayerImpl() override
{}
7863 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl
* tree_impl
,
7865 : LayerImpl(tree_impl
, id
) {
7866 SetDrawsContent(true);
7870 TEST_F(LayerTreeHostCommonTest
, MaximumAnimationScaleFactor
) {
7871 FakeImplProxy proxy
;
7872 TestSharedBitmapManager shared_bitmap_manager
;
7873 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
7874 gfx::Transform identity_matrix
;
7875 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_parent
=
7876 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 1);
7877 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> parent
=
7878 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 2);
7879 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> child
=
7880 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 3);
7881 scoped_ptr
<AnimationScaleFactorTrackingLayerImpl
> grand_child
=
7882 AnimationScaleFactorTrackingLayerImpl::Create(host_impl
.active_tree(), 4);
7884 AnimationScaleFactorTrackingLayerImpl
* parent_raw
= parent
.get();
7885 AnimationScaleFactorTrackingLayerImpl
* child_raw
= child
.get();
7886 AnimationScaleFactorTrackingLayerImpl
* grand_child_raw
= grand_child
.get();
7888 child
->AddChild(grand_child
.Pass());
7889 parent
->AddChild(child
.Pass());
7890 grand_parent
->AddChild(parent
.Pass());
7892 SetLayerPropertiesForTesting(grand_parent
.get(), identity_matrix
,
7893 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
7895 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
7896 gfx::PointF(), gfx::Size(1, 2), true, false,
7898 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
7899 gfx::PointF(), gfx::Size(1, 2), true, false,
7902 SetLayerPropertiesForTesting(grand_child_raw
, identity_matrix
, gfx::Point3F(),
7903 gfx::PointF(), gfx::Size(1, 2), true, false,
7906 ExecuteCalculateDrawProperties(grand_parent
.get());
7908 // No layers have animations.
7910 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7912 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7913 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7915 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7917 TransformOperations translation
;
7918 translation
.AppendTranslate(1.f
, 2.f
, 3.f
);
7920 AddAnimatedTransformToLayer(
7921 parent_raw
, 1.0, TransformOperations(), translation
);
7923 // No layers have scale-affecting animations.
7925 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7927 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7928 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7930 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7932 TransformOperations scale
;
7933 scale
.AppendScale(5.f
, 4.f
, 3.f
);
7935 AddAnimatedTransformToLayer(child_raw
, 1.0, TransformOperations(), scale
);
7936 ExecuteCalculateDrawProperties(grand_parent
.get());
7938 // Only |child| has a scale-affecting animation.
7940 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7942 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7943 EXPECT_EQ(5.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7945 5.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7947 AddAnimatedTransformToLayer(
7948 grand_parent
.get(), 1.0, TransformOperations(), scale
);
7949 ExecuteCalculateDrawProperties(grand_parent
.get());
7951 // |grand_parent| and |child| have scale-affecting animations.
7953 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7955 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7956 // We don't support combining animated scales from two nodes; 0.f means
7957 // that the maximum scale could not be computed.
7958 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7960 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7962 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
7963 ExecuteCalculateDrawProperties(grand_parent
.get());
7965 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
7967 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7969 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7970 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7972 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7974 grand_parent
->layer_animation_controller()->AbortAnimations(
7975 Animation::Transform
);
7976 parent_raw
->layer_animation_controller()->AbortAnimations(
7977 Animation::Transform
);
7978 child_raw
->layer_animation_controller()->AbortAnimations(
7979 Animation::Transform
);
7981 TransformOperations perspective
;
7982 perspective
.AppendPerspective(10.f
);
7984 AddAnimatedTransformToLayer(
7985 child_raw
, 1.0, TransformOperations(), perspective
);
7986 ExecuteCalculateDrawProperties(grand_parent
.get());
7988 // |child| has a scale-affecting animation but computing the maximum of this
7989 // animation is not supported.
7991 grand_parent
->draw_properties().maximum_animation_contents_scale
);
7993 parent_raw
->draw_properties().maximum_animation_contents_scale
);
7994 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
7996 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
7998 child_raw
->layer_animation_controller()->AbortAnimations(
7999 Animation::Transform
);
8001 gfx::Transform scale_matrix
;
8002 scale_matrix
.Scale(1.f
, 2.f
);
8003 grand_parent
->SetTransform(scale_matrix
);
8004 parent_raw
->SetTransform(scale_matrix
);
8005 AddAnimatedTransformToLayer(parent_raw
, 1.0, TransformOperations(), scale
);
8006 ExecuteCalculateDrawProperties(grand_parent
.get());
8008 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
8009 // animation with maximum scale 5.f.
8011 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8013 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8015 child_raw
->draw_properties().maximum_animation_contents_scale
);
8018 grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8020 gfx::Transform perspective_matrix
;
8021 perspective_matrix
.ApplyPerspectiveDepth(2.f
);
8022 child_raw
->SetTransform(perspective_matrix
);
8023 ExecuteCalculateDrawProperties(grand_parent
.get());
8025 // |child| has a transform that's neither a translation nor a scale.
8027 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8029 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8030 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8032 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8034 parent_raw
->SetTransform(perspective_matrix
);
8035 ExecuteCalculateDrawProperties(grand_parent
.get());
8037 // |parent| and |child| have transforms that are neither translations nor
8040 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8042 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8043 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8045 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8047 parent_raw
->SetTransform(identity_matrix
);
8048 child_raw
->SetTransform(identity_matrix
);
8049 grand_parent
->SetTransform(perspective_matrix
);
8051 ExecuteCalculateDrawProperties(grand_parent
.get());
8053 // |grand_parent| has a transform that's neither a translation nor a scale.
8055 grand_parent
->draw_properties().maximum_animation_contents_scale
);
8057 parent_raw
->draw_properties().maximum_animation_contents_scale
);
8058 EXPECT_EQ(0.f
, child_raw
->draw_properties().maximum_animation_contents_scale
);
8060 0.f
, grand_child_raw
->draw_properties().maximum_animation_contents_scale
);
8063 static int membership_id(LayerImpl
* layer
) {
8064 return layer
->draw_properties().last_drawn_render_surface_layer_list_id
;
8067 static void GatherDrawnLayers(LayerImplList
* rsll
,
8068 std::set
<LayerImpl
*>* drawn_layers
) {
8069 for (LayerIterator
<LayerImpl
> it
= LayerIterator
<LayerImpl
>::Begin(rsll
),
8070 end
= LayerIterator
<LayerImpl
>::End(rsll
);
8073 LayerImpl
* layer
= *it
;
8074 if (it
.represents_itself())
8075 drawn_layers
->insert(layer
);
8077 if (!it
.represents_contributing_render_surface())
8080 if (layer
->mask_layer())
8081 drawn_layers
->insert(layer
->mask_layer());
8082 if (layer
->replica_layer() && layer
->replica_layer()->mask_layer())
8083 drawn_layers
->insert(layer
->replica_layer()->mask_layer());
8087 TEST_F(LayerTreeHostCommonTest
, RenderSurfaceLayerListMembership
) {
8088 FakeImplProxy proxy
;
8089 TestSharedBitmapManager shared_bitmap_manager
;
8090 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
8091 gfx::Transform identity_matrix
;
8093 scoped_ptr
<LayerImpl
> grand_parent
=
8094 LayerImpl::Create(host_impl
.active_tree(), 1);
8095 scoped_ptr
<LayerImpl
> parent
= LayerImpl::Create(host_impl
.active_tree(), 3);
8096 scoped_ptr
<LayerImpl
> child
= LayerImpl::Create(host_impl
.active_tree(), 5);
8097 scoped_ptr
<LayerImpl
> grand_child1
=
8098 LayerImpl::Create(host_impl
.active_tree(), 7);
8099 scoped_ptr
<LayerImpl
> grand_child2
=
8100 LayerImpl::Create(host_impl
.active_tree(), 9);
8102 LayerImpl
* grand_parent_raw
= grand_parent
.get();
8103 LayerImpl
* parent_raw
= parent
.get();
8104 LayerImpl
* child_raw
= child
.get();
8105 LayerImpl
* grand_child1_raw
= grand_child1
.get();
8106 LayerImpl
* grand_child2_raw
= grand_child2
.get();
8108 child
->AddChild(grand_child1
.Pass());
8109 child
->AddChild(grand_child2
.Pass());
8110 parent
->AddChild(child
.Pass());
8111 grand_parent
->AddChild(parent
.Pass());
8113 SetLayerPropertiesForTesting(grand_parent_raw
, identity_matrix
,
8114 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8116 SetLayerPropertiesForTesting(parent_raw
, identity_matrix
, gfx::Point3F(),
8117 gfx::PointF(), gfx::Size(1, 2), true, false,
8120 SetLayerPropertiesForTesting(child_raw
, identity_matrix
, gfx::Point3F(),
8121 gfx::PointF(), gfx::Size(1, 2), true, false,
8124 SetLayerPropertiesForTesting(grand_child1_raw
, identity_matrix
,
8125 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8126 true, false, false);
8128 SetLayerPropertiesForTesting(grand_child2_raw
, identity_matrix
,
8129 gfx::Point3F(), gfx::PointF(), gfx::Size(1, 2),
8130 true, false, false);
8132 // Start with nothing being drawn.
8133 ExecuteCalculateDrawProperties(grand_parent_raw
);
8134 int member_id
= render_surface_layer_list_count();
8136 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8137 EXPECT_NE(member_id
, membership_id(parent_raw
));
8138 EXPECT_NE(member_id
, membership_id(child_raw
));
8139 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8140 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8142 std::set
<LayerImpl
*> expected
;
8143 std::set
<LayerImpl
*> actual
;
8144 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8145 EXPECT_EQ(expected
, actual
);
8147 // If we force render surface, but none of the layers are in the layer list,
8148 // then this layer should not appear in RSLL.
8149 grand_child1_raw
->SetHasRenderSurface(true);
8151 ExecuteCalculateDrawProperties(grand_parent_raw
);
8152 member_id
= render_surface_layer_list_count();
8154 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8155 EXPECT_NE(member_id
, membership_id(parent_raw
));
8156 EXPECT_NE(member_id
, membership_id(child_raw
));
8157 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8158 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8162 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8163 EXPECT_EQ(expected
, actual
);
8165 // However, if we say that this layer also draws content, it will appear in
8167 grand_child1_raw
->SetDrawsContent(true);
8169 ExecuteCalculateDrawProperties(grand_parent_raw
);
8170 member_id
= render_surface_layer_list_count();
8172 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8173 EXPECT_NE(member_id
, membership_id(parent_raw
));
8174 EXPECT_NE(member_id
, membership_id(child_raw
));
8175 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
8176 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8179 expected
.insert(grand_child1_raw
);
8182 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8183 EXPECT_EQ(expected
, actual
);
8185 // Now child is forced to have a render surface, and one if its children draws
8187 grand_child1_raw
->SetDrawsContent(false);
8188 grand_child1_raw
->SetHasRenderSurface(false);
8189 child_raw
->SetHasRenderSurface(true);
8190 grand_child2_raw
->SetDrawsContent(true);
8192 ExecuteCalculateDrawProperties(grand_parent_raw
);
8193 member_id
= render_surface_layer_list_count();
8195 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8196 EXPECT_NE(member_id
, membership_id(parent_raw
));
8197 EXPECT_NE(member_id
, membership_id(child_raw
));
8198 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8199 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8202 expected
.insert(grand_child2_raw
);
8205 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8206 EXPECT_EQ(expected
, actual
);
8208 // Add a mask layer to child.
8209 child_raw
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6).Pass());
8211 ExecuteCalculateDrawProperties(grand_parent_raw
);
8212 member_id
= render_surface_layer_list_count();
8214 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8215 EXPECT_NE(member_id
, membership_id(parent_raw
));
8216 EXPECT_NE(member_id
, membership_id(child_raw
));
8217 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8218 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8219 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8222 expected
.insert(grand_child2_raw
);
8223 expected
.insert(child_raw
->mask_layer());
8226 expected
.insert(grand_child2_raw
);
8227 expected
.insert(child_raw
->mask_layer());
8230 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8231 EXPECT_EQ(expected
, actual
);
8233 // Add replica mask layer.
8234 scoped_ptr
<LayerImpl
> replica_layer
=
8235 LayerImpl::Create(host_impl
.active_tree(), 20);
8236 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 21));
8237 child_raw
->SetReplicaLayer(replica_layer
.Pass());
8239 ExecuteCalculateDrawProperties(grand_parent_raw
);
8240 member_id
= render_surface_layer_list_count();
8242 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8243 EXPECT_NE(member_id
, membership_id(parent_raw
));
8244 EXPECT_NE(member_id
, membership_id(child_raw
));
8245 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8246 EXPECT_EQ(member_id
, membership_id(child_raw
->replica_layer()->mask_layer()));
8247 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8248 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8251 expected
.insert(grand_child2_raw
);
8252 expected
.insert(child_raw
->mask_layer());
8253 expected
.insert(child_raw
->replica_layer()->mask_layer());
8256 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8257 EXPECT_EQ(expected
, actual
);
8259 child_raw
->TakeReplicaLayer();
8261 // With nothing drawing, we should have no layers.
8262 grand_child2_raw
->SetDrawsContent(false);
8264 ExecuteCalculateDrawProperties(grand_parent_raw
);
8265 member_id
= render_surface_layer_list_count();
8267 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8268 EXPECT_NE(member_id
, membership_id(parent_raw
));
8269 EXPECT_NE(member_id
, membership_id(child_raw
));
8270 EXPECT_NE(member_id
, membership_id(child_raw
->mask_layer()));
8271 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8272 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8276 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8277 EXPECT_EQ(expected
, actual
);
8279 // Child itself draws means that we should have the child and the mask in the
8281 child_raw
->SetDrawsContent(true);
8283 ExecuteCalculateDrawProperties(grand_parent_raw
);
8284 member_id
= render_surface_layer_list_count();
8286 EXPECT_NE(member_id
, membership_id(grand_parent_raw
));
8287 EXPECT_NE(member_id
, membership_id(parent_raw
));
8288 EXPECT_EQ(member_id
, membership_id(child_raw
));
8289 EXPECT_EQ(member_id
, membership_id(child_raw
->mask_layer()));
8290 EXPECT_NE(member_id
, membership_id(grand_child1_raw
));
8291 EXPECT_NE(member_id
, membership_id(grand_child2_raw
));
8294 expected
.insert(child_raw
);
8295 expected
.insert(child_raw
->mask_layer());
8297 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8298 EXPECT_EQ(expected
, actual
);
8300 child_raw
->TakeMaskLayer();
8302 // Now everyone's a member!
8303 grand_parent_raw
->SetDrawsContent(true);
8304 parent_raw
->SetDrawsContent(true);
8305 child_raw
->SetDrawsContent(true);
8306 grand_child1_raw
->SetDrawsContent(true);
8307 grand_child2_raw
->SetDrawsContent(true);
8309 ExecuteCalculateDrawProperties(grand_parent_raw
);
8310 member_id
= render_surface_layer_list_count();
8312 EXPECT_EQ(member_id
, membership_id(grand_parent_raw
));
8313 EXPECT_EQ(member_id
, membership_id(parent_raw
));
8314 EXPECT_EQ(member_id
, membership_id(child_raw
));
8315 EXPECT_EQ(member_id
, membership_id(grand_child1_raw
));
8316 EXPECT_EQ(member_id
, membership_id(grand_child2_raw
));
8319 expected
.insert(grand_parent_raw
);
8320 expected
.insert(parent_raw
);
8321 expected
.insert(child_raw
);
8322 expected
.insert(grand_child1_raw
);
8323 expected
.insert(grand_child2_raw
);
8326 GatherDrawnLayers(render_surface_layer_list_impl(), &actual
);
8327 EXPECT_EQ(expected
, actual
);
8330 TEST_F(LayerTreeHostCommonTest
, DrawPropertyScales
) {
8331 FakeImplProxy proxy
;
8332 TestSharedBitmapManager shared_bitmap_manager
;
8333 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
8335 scoped_ptr
<LayerImpl
> root
= LayerImpl::Create(host_impl
.active_tree(), 1);
8336 LayerImpl
* root_layer
= root
.get();
8337 scoped_ptr
<LayerImpl
> child1
= LayerImpl::Create(host_impl
.active_tree(), 2);
8338 LayerImpl
* child1_layer
= child1
.get();
8339 scoped_ptr
<LayerImpl
> child2
= LayerImpl::Create(host_impl
.active_tree(), 3);
8340 LayerImpl
* child2_layer
= child2
.get();
8342 root
->AddChild(child1
.Pass());
8343 root
->AddChild(child2
.Pass());
8344 root
->SetHasRenderSurface(true);
8346 gfx::Transform identity_matrix
, scale_transform_child1
,
8347 scale_transform_child2
;
8348 scale_transform_child1
.Scale(2, 3);
8349 scale_transform_child2
.Scale(4, 5);
8351 SetLayerPropertiesForTesting(root_layer
, identity_matrix
, gfx::Point3F(),
8352 gfx::PointF(), gfx::Size(1, 1), true, false,
8354 SetLayerPropertiesForTesting(child1_layer
, scale_transform_child1
,
8355 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8358 child1_layer
->SetMaskLayer(
8359 LayerImpl::Create(host_impl
.active_tree(), 4).Pass());
8361 scoped_ptr
<LayerImpl
> replica_layer
=
8362 LayerImpl::Create(host_impl
.active_tree(), 5);
8363 replica_layer
->SetHasRenderSurface(true);
8364 replica_layer
->SetMaskLayer(LayerImpl::Create(host_impl
.active_tree(), 6));
8365 child1_layer
->SetReplicaLayer(replica_layer
.Pass());
8366 child1_layer
->SetHasRenderSurface(true);
8368 ExecuteCalculateDrawProperties(root_layer
);
8370 TransformOperations scale
;
8371 scale
.AppendScale(5.f
, 8.f
, 3.f
);
8373 AddAnimatedTransformToLayer(child2_layer
, 1.0, TransformOperations(), scale
);
8374 SetLayerPropertiesForTesting(child2_layer
, scale_transform_child2
,
8375 gfx::Point3F(), gfx::PointF(), gfx::Size(), true,
8378 ExecuteCalculateDrawProperties(root_layer
);
8380 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().ideal_contents_scale
);
8381 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8383 3.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8384 EXPECT_FLOAT_EQ(3.f
,
8385 child1_layer
->replica_layer()
8388 .ideal_contents_scale
);
8389 EXPECT_FLOAT_EQ(5.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8392 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8394 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8395 EXPECT_FLOAT_EQ(0.f
,
8396 child1_layer
->mask_layer()
8398 .maximum_animation_contents_scale
);
8399 EXPECT_FLOAT_EQ(0.f
,
8400 child1_layer
->replica_layer()
8403 .maximum_animation_contents_scale
);
8405 8.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8407 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8408 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().page_scale_factor
);
8410 1.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8411 EXPECT_FLOAT_EQ(1.f
,
8412 child1_layer
->replica_layer()
8415 .page_scale_factor
);
8416 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().page_scale_factor
);
8418 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().device_scale_factor
);
8419 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().device_scale_factor
);
8421 1.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8422 EXPECT_FLOAT_EQ(1.f
,
8423 child1_layer
->replica_layer()
8426 .device_scale_factor
);
8427 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().device_scale_factor
);
8429 // Changing page-scale would affect ideal_contents_scale and
8430 // maximum_animation_contents_scale.
8432 float page_scale_factor
= 3.f
;
8433 float device_scale_factor
= 1.0f
;
8434 std::vector
<LayerImpl
*> render_surface_layer_list
;
8435 gfx::Size device_viewport_size
=
8436 gfx::Size(root_layer
->bounds().width() * device_scale_factor
,
8437 root_layer
->bounds().height() * device_scale_factor
);
8438 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
8439 root_layer
, device_viewport_size
, &render_surface_layer_list
);
8441 inputs
.page_scale_factor
= page_scale_factor
;
8442 inputs
.can_adjust_raster_scales
= true;
8443 inputs
.page_scale_application_layer
= root_layer
;
8444 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8446 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().ideal_contents_scale
);
8447 EXPECT_FLOAT_EQ(9.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8449 9.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8450 EXPECT_FLOAT_EQ(9.f
,
8451 child1_layer
->replica_layer()
8454 .ideal_contents_scale
);
8455 EXPECT_FLOAT_EQ(15.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8458 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8460 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8461 EXPECT_FLOAT_EQ(0.f
,
8462 child1_layer
->mask_layer()
8464 .maximum_animation_contents_scale
);
8465 EXPECT_FLOAT_EQ(0.f
,
8466 child1_layer
->replica_layer()
8469 .maximum_animation_contents_scale
);
8471 24.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8473 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8474 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().page_scale_factor
);
8476 3.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8477 EXPECT_FLOAT_EQ(3.f
,
8478 child1_layer
->replica_layer()
8481 .page_scale_factor
);
8482 EXPECT_FLOAT_EQ(3.f
, child2_layer
->draw_properties().page_scale_factor
);
8484 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().device_scale_factor
);
8485 EXPECT_FLOAT_EQ(1.f
, child1_layer
->draw_properties().device_scale_factor
);
8487 1.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8488 EXPECT_FLOAT_EQ(1.f
,
8489 child1_layer
->replica_layer()
8492 .device_scale_factor
);
8493 EXPECT_FLOAT_EQ(1.f
, child2_layer
->draw_properties().device_scale_factor
);
8495 // Changing device-scale would affect ideal_contents_scale and
8496 // maximum_animation_contents_scale.
8498 device_scale_factor
= 4.0f
;
8499 inputs
.device_scale_factor
= device_scale_factor
;
8500 inputs
.can_adjust_raster_scales
= true;
8501 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8503 EXPECT_FLOAT_EQ(4.f
, root_layer
->draw_properties().ideal_contents_scale
);
8504 EXPECT_FLOAT_EQ(36.f
, child1_layer
->draw_properties().ideal_contents_scale
);
8506 36.f
, child1_layer
->mask_layer()->draw_properties().ideal_contents_scale
);
8507 EXPECT_FLOAT_EQ(36.f
,
8508 child1_layer
->replica_layer()
8511 .ideal_contents_scale
);
8512 EXPECT_FLOAT_EQ(60.f
, child2_layer
->draw_properties().ideal_contents_scale
);
8515 0.f
, root_layer
->draw_properties().maximum_animation_contents_scale
);
8517 0.f
, child1_layer
->draw_properties().maximum_animation_contents_scale
);
8518 EXPECT_FLOAT_EQ(0.f
,
8519 child1_layer
->mask_layer()
8521 .maximum_animation_contents_scale
);
8522 EXPECT_FLOAT_EQ(0.f
,
8523 child1_layer
->replica_layer()
8526 .maximum_animation_contents_scale
);
8528 96.f
, child2_layer
->draw_properties().maximum_animation_contents_scale
);
8530 EXPECT_FLOAT_EQ(1.f
, root_layer
->draw_properties().page_scale_factor
);
8531 EXPECT_FLOAT_EQ(3.f
, child1_layer
->draw_properties().page_scale_factor
);
8533 3.f
, child1_layer
->mask_layer()->draw_properties().page_scale_factor
);
8534 EXPECT_FLOAT_EQ(3.f
,
8535 child1_layer
->replica_layer()
8538 .page_scale_factor
);
8539 EXPECT_FLOAT_EQ(3.f
, child2_layer
->draw_properties().page_scale_factor
);
8541 EXPECT_FLOAT_EQ(4.f
, root_layer
->draw_properties().device_scale_factor
);
8542 EXPECT_FLOAT_EQ(4.f
, child1_layer
->draw_properties().device_scale_factor
);
8544 4.f
, child1_layer
->mask_layer()->draw_properties().device_scale_factor
);
8545 EXPECT_FLOAT_EQ(4.f
,
8546 child1_layer
->replica_layer()
8549 .device_scale_factor
);
8550 EXPECT_FLOAT_EQ(4.f
, child2_layer
->draw_properties().device_scale_factor
);
8553 TEST_F(LayerTreeHostCommonTest
, VisibleContentRectInChildRenderSurface
) {
8554 scoped_refptr
<Layer
> root
= Layer::Create();
8555 SetLayerPropertiesForTesting(root
.get(),
8559 gfx::Size(768 / 2, 3000),
8562 root
->SetIsDrawable(true);
8564 scoped_refptr
<Layer
> clip
= Layer::Create();
8565 SetLayerPropertiesForTesting(clip
.get(),
8569 gfx::Size(768 / 2, 10000),
8572 clip
->SetMasksToBounds(true);
8574 scoped_refptr
<Layer
> content
= Layer::Create();
8575 SetLayerPropertiesForTesting(content
.get(),
8579 gfx::Size(768 / 2, 10000),
8582 content
->SetIsDrawable(true);
8583 content
->SetForceRenderSurface(true);
8585 root
->AddChild(clip
);
8586 clip
->AddChild(content
);
8588 FakeLayerTreeHostClient
client(FakeLayerTreeHostClient::DIRECT_3D
);
8589 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&client
);
8590 host
->SetRootLayer(root
);
8592 gfx::Size
device_viewport_size(768, 582);
8593 RenderSurfaceLayerList render_surface_layer_list
;
8594 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
8595 host
->root_layer(), device_viewport_size
, &render_surface_layer_list
);
8596 inputs
.device_scale_factor
= 2.f
;
8597 inputs
.page_scale_factor
= 1.f
;
8598 inputs
.page_scale_application_layer
= NULL
;
8599 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8601 // Layers in the root render surface have their visible content rect clipped
8603 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root
->visible_content_rect());
8605 // Layers drawing to a child render surface should still have their visible
8606 // content rect clipped by the viewport.
8607 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content
->visible_content_rect());
8610 TEST_F(LayerTreeHostCommonTest
, BoundsDeltaAffectVisibleContentRect
) {
8611 FakeImplProxy proxy
;
8612 TestSharedBitmapManager shared_bitmap_manager
;
8613 FakeLayerTreeHostImpl
host_impl(&proxy
, &shared_bitmap_manager
);
8615 // Set two layers: the root layer clips it's child,
8616 // the child draws its content.
8618 gfx::Size root_size
= gfx::Size(300, 500);
8620 // Sublayer should be bigger than the root enlarged by bounds_delta.
8621 gfx::Size sublayer_size
= gfx::Size(300, 1000);
8623 // Device viewport accomidated the root and the top controls.
8624 gfx::Size device_viewport_size
= gfx::Size(300, 600);
8625 gfx::Transform identity_matrix
;
8627 host_impl
.active_tree()->SetRootLayer(
8628 LayerImpl::Create(host_impl
.active_tree(), 1));
8630 LayerImpl
* root
= host_impl
.active_tree()->root_layer();
8631 SetLayerPropertiesForTesting(root
,
8640 root
->SetContentBounds(root_size
);
8641 root
->SetMasksToBounds(true);
8643 root
->AddChild(LayerImpl::Create(host_impl
.active_tree(), 2));
8645 LayerImpl
* sublayer
= root
->child_at(0);
8646 SetLayerPropertiesForTesting(sublayer
,
8655 sublayer
->SetContentBounds(sublayer_size
);
8656 sublayer
->SetDrawsContent(true);
8658 LayerImplList layer_impl_list
;
8659 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
8660 root
, device_viewport_size
, &layer_impl_list
);
8662 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8664 EXPECT_EQ(gfx::Rect(root_size
), sublayer
->visible_content_rect());
8666 root
->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0));
8668 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
8670 gfx::Rect
affected_by_delta(0, 0, root_size
.width(),
8671 root_size
.height() + 50);
8672 EXPECT_EQ(affected_by_delta
, sublayer
->visible_content_rect());