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